]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackReconstructor.cxx
Save pythia default decay table at first initialization. Reload at each
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackReconstructor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /*
16 $Log$
17 Revision 1.9  2001/03/12 17:45:48  hristov
18 Changes needed on Sun with CC 5.0
19
20 Revision 1.8  2001/01/26 22:05:41  morsch
21 Unresolved conflicts resolved.
22
23 Revision 1.7  2001/01/26 21:54:46  morsch
24 Use access functions to AliMUONHit member data.
25
26
27 Revision 1.6  2001/01/26 20:00:53  hristov
28 Major upgrade of AliRoot code
29
30 Revision 1.4  2000/12/21 22:14:38  morsch
31 Clean-up of coding rule violations.
32
33 Revision 1.3  2000/10/02 21:28:09  fca
34 Removal of useless dependecies via forward declarations
35
36 Revision 1.2  2000/06/15 07:58:49  morsch
37 Code from MUON-dev joined
38
39 Revision 1.1.2.7  2000/06/09 22:06:29  morsch
40 Some coding rule violations corrected. Will soon be obsolete.
41
42 Revision 1.1.2.6  2000/05/02 07:15:29  morsch
43 Put back TH1.h and TH2.h includes.
44
45 Revision 1.1.2.5  2000/02/17 18:12:43  morsch
46 Corrections in trackf_read_spoint causing segmentation violations in previous version (I. Chevrot)
47 New histos (I. Chevrot)
48
49 Revision 1.1.2.4  2000/02/15 18:01:08  morsch
50 Log messages
51
52 Revision 1.1.2.3  2000/02/15 17:59:01  morsch
53 Log message added
54
55 Revision 1.1.2.2  2000/02/15 18:54:56  morsch
56 Reference between track contributing to reconstructed hit and particle corrected  
57 */
58
59 #include "AliCallf77.h" 
60 #include "AliMUONTrackReconstructor.h" 
61 #include "AliRun.h"
62 #include "AliMUON.h"
63 #include "AliMC.h"
64
65 #include "AliMUONHit.h"
66 #include "AliMUONPadHit.h"
67 #include "AliMUONDigit.h"
68 #include "AliMUONRawCluster.h"
69 #include "AliMUONReconstHit.h"
70
71 #include "AliPDG.h"
72
73 #include <TRandom.h> 
74 #include <TFile.h> 
75 #include <TH1.h>
76 #include <TH2.h>  
77 #include <TTree.h> 
78 #include <TParticle.h> 
79 #include <TMinuit.h>
80 #include <iostream.h>
81
82 #ifndef WIN32 
83 # define reco_init       reco_init_
84 # define cutpxz          cutpxz_
85 # define sigmacut        sigmacut_
86 # define xpreci          xpreci_
87 # define ypreci          ypreci_
88 # define reconstmuon     reconstmuon_
89 # define reconstmuon2    reconstmuon2_
90 # define trackf_read_geant     trackf_read_geant_
91 # define trackf_read_fit     trackf_read_fit_
92 # define trackf_read_spoint     trackf_read_spoint_
93 # define chfill          chfill_
94 # define chfill2         chfill2_
95 # define chf1            chf1_
96 # define chfnt           chfnt_
97 # define hist_create     hist_create_
98 # define hist_closed     hist_closed_
99 # define rndm            rndm_
100 # define fcn             fcn_
101 # define trackf_fit      trackf_fit_
102 # define prec_fit        prec_fit_
103 # define fcnfit          fcnfit_
104 # define reco_term       reco_term_
105 #else 
106 # define reco_init       RECO_INIT
107 # define cutpxz          CUTPXZ
108 # define sigmacut        SIGMACUT
109 # define xpreci          XPRECI
110 # define ypreci          YPRECI
111 # define reconstmuon     RECONSTMUON
112 # define reconstmuon2    RECONSTMUON2
113 # define trackf_read_geant     TRACKF_READ_GEANT
114 # define trackf_read_fit     TRACKF_READ_FIT
115 # define trackf_read_spoint     TRACKF_READ_SPOINT
116 # define chfill          CHFILL
117 # define chfill2         CHFILL2
118 # define chf1            CHF1
119 # define chfnt           CHFNT
120 # define hist_create     HIST_CREATE
121 # define hist_closed     HIST_CLOSED
122 # define rndm            RNDM
123 # define fcn             FCN
124 # define trackf_fit      TRACKF_FIT
125 # define prec_fit        PREC_FIT
126 # define fcnfit          FCNFIT
127 # define reco_term       RECO_TERM
128 #endif 
129
130 extern "C"
131 {
132 void type_of_call reco_init(Double_t &, Double_t &, Double_t &);
133 void type_of_call reco_term();
134 void type_of_call cutpxz(Double_t &);
135 void type_of_call sigmacut(Double_t &);
136 void type_of_call xpreci(Double_t &);
137 void type_of_call ypreci(Double_t &);
138 void type_of_call reconstmuon(Int_t &, Int_t &, Int_t &, Int_t &, Int_t &);
139 void type_of_call reconstmuon2(Int_t &, Int_t &, Int_t &);
140 void type_of_call trackf_read_fit(Int_t &, Int_t &, Int_t &, Int_t *, Double_t *, Double_t *);
141 void type_of_call trackf_read_geant(Int_t *, Double_t *, Double_t *, Double_t *, Int_t *, Int_t *, Double_t *, Double_t *, Double_t *, Double_t *,Int_t &, Double_t *, Double_t *, Double_t *, Int_t &, Int_t &, Double_t *, Double_t *, Double_t *, Double_t *); 
142 void type_of_call trackf_read_spoint(Int_t *, Double_t *, Double_t *, Double_t *, Int_t *, Int_t *, Double_t *, Double_t *, Double_t *, Double_t *,Int_t &, Double_t *, Double_t *, Double_t *, Int_t &, Int_t &, Double_t *, Double_t *, Double_t *, Double_t *); 
143 void type_of_call chfill(Int_t &, Float_t &, Float_t &, Float_t &);
144 void type_of_call chfill2(Int_t &, Float_t &, Float_t &, Float_t &);
145 void type_of_call chf1(Int_t &, Float_t &, Float_t &);
146 void type_of_call chfnt(Int_t &, Int_t &, Int_t *, Int_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *);
147 void type_of_call hist_create();
148 void type_of_call hist_closed();
149 void type_of_call fcnf(Int_t &, Double_t *, Double_t &, Double_t *, Int_t);
150 void type_of_call fcn(Int_t &, Double_t *, Double_t &, Double_t *, Int_t &, Int_t &);
151 void type_of_call trackf_fit(Int_t &, Double_t *, Double_t *, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &);
152 void type_of_call prec_fit(Double_t &, Double_t &, Double_t &, Double_t &, Double_t&, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &);
153 void type_of_call fcnfitf(Int_t &, Double_t *, Double_t &, Double_t *, Int_t);
154 void type_of_call fcnfit(Int_t &, Double_t *, Double_t &, Double_t *, Int_t &, Int_t &);
155 Float_t type_of_call rndm() {return gRandom->Rndm();}
156 void type_of_call fit_trace(Float_t &, Float_t &, Float_t &, Float_t &, Float_t &, Float_t &, Int_t &, Int_t &, Int_t &, Int_t &);
157 }
158
159 static TTree *gAliNtupleGlobal;
160 static TFile *gAliFileGlobal;
161 static TTree *gAliTreeK1;
162 static TTree *gAliTrH1;
163 static TClonesArray *gAliHits2;        //List of hits for one track only
164 static TClonesArray *gAliParticles2;   //List of particles in the Kine tree
165
166
167 // variables of the tracking ntuple 
168 struct { 
169   Int_t ievr;           // number of event 
170   Int_t ntrackr;        // number of tracks per event
171   Int_t istatr[500];    // 1 = good muon, 2 = ghost, 0 = something else
172   Int_t isignr[500];    // sign of the track
173   Float_t pxr[500];     // x momentum of the reconstructed track
174   Float_t pyr[500];     // y momentum of the reconstructed track
175   Float_t pzr[500];     // z momentum of the reconstructed track
176   Float_t zvr[500];     // z vertex 
177   Float_t chi2r[500];   // chi2 of the fit of the track with the field map
178   Float_t pxv[500];     // x momentum at vertex
179   Float_t pyv[500];     // y momentum at vertex
180   Float_t pzv[500];     // z momentum at vertex
181 } NtupleSt;
182
183 ClassImp(AliMUONTrackReconstructor)
184
185 //___________________________________________________
186 AliMUONTrackReconstructor::AliMUONTrackReconstructor()
187 {
188 // Constructor
189 //
190    fSPxzCut   = 3.0;
191    fSSigmaCut = 4.0;
192    fSXPrec    = 0.01; 
193    fSYPrec    = 0.144;
194 }
195
196 //_____________________________________________________________________________
197 void AliMUONTrackReconstructor::Reconst2(Int_t &ifit, Int_t &idebug, Int_t &nev)
198 {
199 //
200 //
201     reconstmuon2(ifit,idebug,nev);
202 }
203
204 //_____________________________________________________________________________
205 void AliMUONTrackReconstructor::Reconst(Int_t &ifit, Int_t &idebug, Int_t bgdEvent, Int_t &nev, Int_t &idres, Int_t &ireadgeant, Option_t *option,Text_t *filename)
206 {
207   //
208   // open kine and hits tree of background file for reconstruction of geant hits 
209   // call tracking fortran program
210   static Bool_t first=kTRUE;
211   static TFile *pFile;
212   const char *addBackground = strstr(option,"Add");
213   
214   if (addBackground ) { // only in case of background with geant hits 
215     if(first) {
216       fFileName=filename;
217       cout<<"filename  "<<fFileName<<endl;
218       pFile=new TFile(fFileName);
219       cout<<"I have opened "<<fFileName<<" file "<<endl;
220       gAliHits2     = new TClonesArray("AliMUONHit",1000);
221       gAliParticles2 = new TClonesArray("TParticle",1000);
222       first=kFALSE;
223     }
224     pFile->cd();
225     if(gAliHits2) gAliHits2->Clear();
226     if(gAliParticles2) gAliParticles2->Clear();
227     if(gAliTrH1) delete gAliTrH1;
228     gAliTrH1=0;
229     if(gAliTreeK1) delete gAliTreeK1;
230     gAliTreeK1=0;
231     // Get Hits Tree header from file
232     char treeName[20];
233     sprintf(treeName,"TreeH%d",bgdEvent);
234     gAliTrH1 = (TTree*)gDirectory->Get(treeName);
235     //     printf("gAliTrH1 %p of treename %s for event %d \n",gAliTrH1,treeName,bgdEvent);
236     if (!gAliTrH1) {
237       printf("ERROR: cannot find Hits Tree for event:%d\n",bgdEvent);
238     }
239     // set branch addresses
240     TBranch *branch;
241     char branchname[30];
242     AliMUON *pMUON  = (AliMUON*) gAlice->GetModule("MUON");  
243     sprintf(branchname,"%s",pMUON->GetName());       
244     if (gAliTrH1 && gAliHits2) {
245       branch = gAliTrH1->GetBranch(branchname);
246       if (branch) branch->SetAddress(&gAliHits2);
247     }
248     gAliTrH1->GetEntries();
249     // get the Kine tree
250     sprintf(treeName,"TreeK%d",bgdEvent);
251     gAliTreeK1 = (TTree*)gDirectory->Get(treeName);
252     if (!gAliTreeK1) {
253       printf("ERROR: cannot find Kine Tree for event:%d\n",bgdEvent);
254     }
255     // set branch addresses
256     if (gAliTreeK1) 
257       gAliTreeK1->SetBranchAddress("Particles", &gAliParticles2);
258     gAliTreeK1->GetEvent(0);
259     
260     // get back to the first file
261     TTree *treeK = gAlice->TreeK();
262     TFile *file1 = 0;
263     if (treeK) file1 = treeK->GetCurrentFile();
264     file1->cd();
265     
266   } // end if addBackground
267   
268   // call tracking fortran program
269   reconstmuon(ifit,idebug,nev,idres,ireadgeant);
270 }
271
272 //________________________________________________________________________________
273 void AliMUONTrackReconstructor::Init(Double_t &seff, Double_t &sb0, Double_t &sbl3)
274 {
275   //
276   // introduce in fortran program somme parameters and cuts for tracking 
277   // create output file "reconst.root" (histos + ntuple)
278   cutpxz(fSPxzCut);          // Pxz cut (GeV/c) to begin the track finding
279   sigmacut(fSSigmaCut);      // Number of sigmas delimiting the searching areas
280   xpreci(fSXPrec);           // Chamber precision in X (cm) 
281   ypreci(fSYPrec);           // Chamber precision in Y (cm)
282   reco_init(seff,sb0,sbl3);
283 }
284
285 //__________________________________________
286 void AliMUONTrackReconstructor::FinishEvent()
287 {
288    // Finish
289    // TTree *treeK = gAlice->TreeK();
290    // TFile *file1 = 0;
291    // if (treeK) file1 = treeK->GetCurrentFile();
292    // file1->cd();
293 }
294
295 //_____________________________________
296 void AliMUONTrackReconstructor::Close()
297 {
298   //
299   // write histos and ntuple to "reconst.root" file
300     reco_term();
301 }
302
303 //________________________________________________________
304 void chfill(Int_t &id, Float_t &x, Float_t &y, Float_t &w)
305 {
306   //
307   // fill histo like hfill in fortran
308     char name[5];
309     sprintf(name,"h%d",id);
310     TH1F *h1 = (TH1F*) gDirectory->Get(name);
311     h1->Fill(x);
312 }
313
314 //_________________________________________________________
315 void chfill2(Int_t &id, Float_t &x, Float_t &y, Float_t &w)
316 {
317   //
318   // fill histo like hfill2 in fortran
319     char name[5];
320     sprintf(name,"h%d",id);
321     TH2F *h2 = (TH2F*) gDirectory->Get(name);
322     h2->Fill(x,y,w);
323 }
324
325 //__________________________________________
326 void chf1(Int_t &id, Float_t &x, Float_t &w)
327 {
328   //
329   // fill histo like hf1 in fortran
330     char name[5];
331     sprintf(name,"h%d",id);
332     TH1F *h1 = (TH1F*) gDirectory->Get(name);
333     h1->Fill(x,w);
334 }
335
336 //_________________
337 void hist_create()
338 {
339   //
340   // Create an output file ("reconst.root")
341   // Create some histograms and an ntuple
342
343     gAliFileGlobal = new TFile("reconst.root","RECREATE","Ntuple - reconstruction");
344
345    gAliNtupleGlobal = new TTree("ntuple","Reconst ntuple");
346    gAliNtupleGlobal->Branch("ievr",&NtupleSt.ievr,"ievr/I");
347    gAliNtupleGlobal->Branch("ntrackr",&NtupleSt.ntrackr,"ntrackr/I");
348    gAliNtupleGlobal->Branch("istatr",&NtupleSt.istatr[0],"istatr[500]/I");
349    gAliNtupleGlobal->Branch("isignr",&NtupleSt.isignr[0],"isignr[500]/I");
350    gAliNtupleGlobal->Branch("pxr",&NtupleSt.pxr[0],"pxr[500]/F");
351    gAliNtupleGlobal->Branch("pyr",&NtupleSt.pyr[0],"pyr[500]/F");
352    gAliNtupleGlobal->Branch("pzr",&NtupleSt.pzr[0],"pzr[500]/F");
353    gAliNtupleGlobal->Branch("zvr",&NtupleSt.zvr[0],"zvr[500]/F");
354    gAliNtupleGlobal->Branch("chi2r",&NtupleSt.chi2r[0],"chi2r[500]/F");
355    gAliNtupleGlobal->Branch("pxv",&NtupleSt.pxv[0],"pxv[500]/F");
356    gAliNtupleGlobal->Branch("pyv",&NtupleSt.pyv[0],"pyv[500]/F");
357    gAliNtupleGlobal->Branch("pzv",&NtupleSt.pzv[0],"pzv[500]/F");
358
359    // test aliroot
360
361   new TH1F("h100","particule id du hit geant",20,0.,20.);
362   new TH1F("h101","position en x du hit geant",100,-200.,200.);
363   new TH1F("h102","position en y du hit geant",100,-200.,200.);
364   new TH1F("h103","chambre de tracking concernee",15,0.,14.);
365   new TH1F("h104","moment ptot du hit geant",50,0.,100.);
366   new TH1F("h105","px au vertex",50,0.,20.);
367   new TH1F("h106","py au vertex",50,0.,20.);
368   new TH1F("h107","pz au vertex",50,0.,20.);
369   new TH1F("h108","position zv",50,-15.,15.);
370   new TH1F("h109","position en x du hit reconstruit",100,-300.,300.);
371   new TH1F("h110","position en y du hit reconstruit",100,-300.,300.);
372   new TH1F("h111","delta x station 1",100,-0.3,0.3);
373   new TH1F("h112","delta x station 2",100,-0.3,0.3);
374   new TH1F("h113","delta x station 3",100,-0.3,0.3);
375   new TH1F("h114","delta x station 4",100,-0.5,0.5);
376   new TH1F("h115","delta x station 5",100,-0.5,0.5);
377   new TH1F("h116","delta x station 1",100,-2,2);
378   new TH1F("h117","delta x station 2",100,-2,2);
379   new TH1F("h121","delta y station 1",100,-0.04,0.04);
380   new TH1F("h122","delta y station 2",100,-0.04,0.04);
381   new TH1F("h123","delta y station 3",100,-0.04,0.04);
382   new TH1F("h124","delta y station 4",100,-0.04,0.04);
383   new TH1F("h125","delta y station 5",100,-0.04,0.04);
384
385   /*  char hname[30];
386       char hname1[30];
387       for (int i=0;i<10;i++) {
388       sprintf(hname,"deltax%d",i);
389       sprintf(hname1,"h12%d",i);
390       new TH1F(hname1,hname ,100,-0.4,0.4);
391       sprintf(hname,"deltay%d",i);
392       sprintf(hname1,"h13%d",i);
393       new TH1F(hname1,hname ,100,-0.4,0.4);
394       }
395   */
396   new TH2F("h2000","VAR X st. 5",30,3.0,183.0,100,0.,25.);
397   new TH2F("h2001","VAR Y st. 5",30,3.0,183.0,100,0.,25.);
398
399   new TH2F("h2500","P vs X HHIT",30,3.0,183.0,200,0.,200.);
400   new TH2F("h2501","P vs X HHIT**2",30,3.0,183.0,200,0.,5000.);
401   new TH2F("h2502","P vs X EPH2 st. 5",30,3.0,183.0,100,0.,0.000005);
402   new TH2F("h2503","P vs X EAL2 st. 5",30,3.0,183.0,100,0.,0.01);
403   //new TH2F("h2504","P vs X EXM2 st. 5",30,3.0,183.0,100,0.,1.5);
404   new TH2F("h2504","P vs X EXM2 st. 5",30,3.0,183.0,100,0.,0.1);
405   new TH2F("h2505","P vs X EYM2 st. 5",30,3.0,183.0,100,0.,30.);
406
407   new TH2F("h2507","P vs X EPH st. 5",30,3.0,183.0,100,0.,0.003);
408   new TH2F("h2508","P vs X EAL st. 5",30,3.0,183.0,100,0.,0.3);
409   //new TH2F("h2509","P vs X EXM st. 5",30,3.0,183.0,100,0.,1.5);
410   new TH2F("h2509","P vs X EXM st. 5",30,3.0,183.0,100,0.,0.4);
411   new TH2F("h2510","P vs X EYM st. 5",30,3.0,183.0,100,0.,30.);
412
413   new TH2F("h2511","P vs X EPH cut st. 5",30,3.0,183.0,100,0.,0.01);
414   new TH2F("h2512","P vs X EAL cut st. 5",30,3.0,183.0,100,0.,0.3);
415   //new TH2F("h2513","P vs X EXM cut st. 5",30,3.0,183.0,100,0.,1.5);
416   new TH2F("h2513","P vs X EXM cut st. 5",30,3.0,183.0,100,0.,0.4);
417   new TH2F("h2514","P vs X EYM cut st. 5",30,3.0,183.0,100,0.,30.);
418   // 4
419   new TH2F("h2400","P vs X HHIT",30,3.0,183.0,200,0.,200.);
420   new TH2F("h2401","P vs X HHIT**2",30,3.0,183.0,200,0.,5000.);
421   new TH2F("h2402","P vs X EPH2 st. 4",30,3.0,183.0,100,0.,0.000005);
422   new TH2F("h2403","P vs X EAL2 st. 4",30,3.0,183.0,100,0.,0.05);
423   //new TH2F("h2404","P vs X EXM2 st. 4",30,3.0,183.0,100,0.,1.5);
424   new TH2F("h2404","P vs X EXM2 st. 4",30,3.0,183.0,100,0.,0.1);
425   new TH2F("h2405","P vs X EYM2 st. 4",30,3.0,183.0,100,0.,30.);
426
427   new TH2F("h2407","P vs X EPH st. 4",30,3.0,183.0,100,0.,0.003);
428   new TH2F("h2408","P vs X EAL st. 4",30,3.0,183.0,100,0.,0.3);
429   //new TH2F("h2409","P vs X EXM st. 4",30,3.0,183.0,100,0.,1.5);
430   new TH2F("h2409","P vs X EXM st. 4",30,3.0,183.0,100,0.,0.1);
431   new TH2F("h2410","P vs X EYM st. 4",30,3.0,183.0,100,0.,30.);
432
433   new TH2F("h2411","P vs X EPH cut st. 4",30,3.0,183.0,100,0.,0.01);
434   new TH2F("h2412","P vs X EAL cut st. 4",30,3.0,183.0,100,0.,0.3);
435   //new TH2F("h2413","P vs X EXM cut st. 4",30,3.0,183.0,100,0.,1.5);
436   new TH2F("h2413","P vs X EXM cut st. 4",30,3.0,183.0,100,0.,0.1);
437   new TH2F("h2414","P vs X EYM cut st. 4",30,3.0,183.0,100,0.,30.);
438   // 3
439   new TH1F("h2301","P2",30,3.0,183.0);
440   new TH2F("h2302","P2 vs X EPH2 st. 3",30,3.0,183.0,100,0.,0.0006);
441   new TH2F("h2303","P2 vs X EAL2 st. 3",30,3.0,183.0,100,0.,0.0005);
442   //new TH2F("h2304","P2 vs X EXM2 st. 3",30,3.0,183.0,100,0.,1.5);
443   new TH2F("h2304","P2 vs X EXM2 st. 3",30,3.0,183.0,100,0.,2.);
444   new TH2F("h2305","P2 vs X EYM2 st. 3",30,3.0,183.0,100,0.,3.);
445
446   new TH2F("h2307","P vs X EPH2 st. 3",30,3.0,183.0,100,0.,0.0006);
447   new TH2F("h2308","P vs X EAL2 st. 3",30,3.0,183.0,100,0.,0.005);
448   //new TH2F("h2309","P vs X EXM2 st. 3",30,3.0,183.0,100,0.,1.5);
449   new TH2F("h2309","P vs X EXM2 st. 3",30,3.0,183.0,100,0.,2.);
450   new TH2F("h2310","P vs X EYM2 st. 3",30,3.0,183.0,100,0.,3.);
451
452   new TH2F("h2311","P vs X EPH cut st. 3",30,3.0,183.0,100,0.,0.06);
453   new TH2F("h2312","P vs X EAL cut st. 3",30,3.0,183.0,100,0.,0.05);
454   //new TH2F("h2313","P vs X EXM cut st. 3",30,3.0,183.0,100,0.,1.5);
455   new TH2F("h2313","P vs X EXM cut st. 3",30,3.0,183.0,100,0.,6.);
456   new TH2F("h2314","P vs X EYM cut st. 3",30,3.0,183.0,100,0.,7.);
457
458   new TH2F("h2315","P2 vs X EPH cut st. 3",30,3.0,183.0,100,0.,0.06);
459   new TH2F("h2316","P2 vs X EAL cut st. 3",30,3.0,183.0,100,0.,0.05);
460   //new TH2F("h2317","P2 vs X EXM cut st. 3",30,3.0,183.0,100,0.,1.5);
461   new TH2F("h2317","P2 vs X EXM cut st. 3",30,3.0,183.0,100,0.,6.);
462   new TH2F("h2318","P2 vs X EYM cut st. 3",30,3.0,183.0,100,0.,7.);
463   
464   // 2
465   new TH1F("h2201","P2",30,3.0,183.0);
466   new TH2F("h2202","P2 vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
467   new TH2F("h2203","P2 vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
468   //new TH2F("h2204","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
469   new TH2F("h2204","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
470   new TH2F("h2205","P2 vs X EYM2 st. 2",30,3.0,183.0,100,0.,5.);
471
472   new TH2F("h2207","P vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
473   new TH2F("h2208","P vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
474   //new TH2F("h2209","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
475   new TH2F("h2209","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
476   new TH2F("h2210","P vs X EYM2 st. 2",30,3.0,183.0,100,0.,5.);
477
478   new TH2F("h2211","P vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.05);
479   new TH2F("h2212","P vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
480   //new TH2F("h2213","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
481   new TH2F("h2213","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
482   new TH2F("h2214","P vs X EYM cut st. 2",30,3.0,183.0,100,0.,10.);
483
484   new TH2F("h2215","P2 vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.05);
485   new TH2F("h2216","P2 vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
486   //new TH2F("h2217","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
487   new TH2F("h2217","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
488   new TH2F("h2218","P2 vs X EYM cut st. 2",30,3.0,183.0,100,0.,10.);
489
490   // 1
491   new TH2F("h2102","P2 vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
492   new TH2F("h2103","P2 vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
493   //new TH2F("h2104","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
494   new TH2F("h2104","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
495   new TH2F("h2105","P2 vs X EYM2 st. 2",30,3.0,183.0,100,0.,7.);
496
497   new TH2F("h2107","P vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
498   new TH2F("h2108","P vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
499   //new TH2F("h2109","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
500   new TH2F("h2109","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
501   new TH2F("h2110","P vs X EYM2 st. 2",30,3.0,183.0,100,0.,7.);
502
503   new TH2F("h2111","P vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.1);
504   new TH2F("h2112","P vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
505   //new TH2F("h2113","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
506   new TH2F("h2113","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
507   new TH2F("h2114","P vs X EYM cut st. 2",30,3.0,183.0,100,0.,11.);
508
509   new TH2F("h2115","P2 vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.1);
510   new TH2F("h2116","P2 vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
511   //new TH2F("h2117","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
512   new TH2F("h2117","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
513   new TH2F("h2118","P2 vs X EYM cut st. 2",30,3.0,183.0,100,0.,11.);
514
515   // 2,3,4,5
516   new TH1F("h2701","P2 fit 2",30,3.0,183.0);
517   new TH2F("h2702","P2 vs X EPH2 st. 1 fit 2",30,3.0,183.0,100,0.,0.0006);
518   new TH2F("h2703","P2 vs X EAL2 st. 1 fit 2",30,3.0,183.0,100,0.,0.005);
519   // new TH2F("h2704","P2 vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
520   new TH2F("h2704","P2 vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,2.);
521   new TH2F("h2705","P2 vs X EYM2 st. 1 fit 2",30,3.0,183.0,100,0.,3.);
522
523   new TH2F("h2707","P vs X EPH2 st. 1 fit 2",30,3.0,183.0,100,0.,0.0006);
524   new TH2F("h2708","P vs X EAL2 st. 1 fit 2",30,3.0,183.0,100,0.,0.005);
525   //new TH2F("h2709","P vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
526   new TH2F("h2709","P vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,2.);
527   new TH2F("h2710","P vs X EYM2 st. 1 fit 2",30,3.0,183.0,100,0.,3.);
528
529   new TH2F("h2711","P vs X EPH cut st. 1 fit 2",30,3.0,183.0,100,0.,0.07);
530   new TH2F("h2712","P vs X EAL cut st. 1 fit 2",30,3.0,183.0,100,0.,0.2);
531   //new TH2F("h2713","P vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
532   new TH2F("h2713","P vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,6.);
533   new TH2F("h2714","P vs X EYM cut st. 1 fit 2",30,3.0,183.0,100,0.,7.);
534
535   new TH2F("h2715","P2 vs X EPH cut st. 1 fit 2",30,3.0,183.0,100,0.,0.07);
536   new TH2F("h2716","P2 vs X EAL cut st. 1 fit 2",30,3.0,183.0,100,0.,0.2);
537   //new TH2F("h2717","P2 vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
538   new TH2F("h2717","P2 vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,6.);
539   new TH2F("h2718","P2 vs X EYM cut st. 1 fit 2",30,3.0,183.0,100,0.,7.);
540
541   // 1,3,4,5
542   new TH1F("h2801","P2 fit 1",30,3.0,183.0);
543   new TH2F("h2802","P2 vs X EPH2 st. 2 fit 1",30,3.0,183.0,100,0.,0.0006);
544   new TH2F("h2803","P2 vs X EAL2 st. 2 fit 1",30,3.0,183.0,100,0.,0.005);
545   //new TH2F("h2804","P2 vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
546   new TH2F("h2804","P2 vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,2.);
547   new TH2F("h2805","P2 vs X EYM2 st. 2 fit 1",30,3.0,183.0,100,0.,3.);
548
549   new TH2F("h2807","P vs X EPH2 st. 2 fit 1",30,3.0,183.0,100,0.,0.0006);
550   new TH2F("h2808","P vs X EAL2 st. 2 fit 1",30,3.0,183.0,100,0.,0.005);
551   //new TH2F("h2809","P vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
552   new TH2F("h2809","P vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,2.);
553   new TH2F("h2810","P vs X EYM2 st. 2 fit 1",30,3.0,183.0,100,0.,3.);
554
555   new TH2F("h2811","P vs X EPH cut st. 2 fit 1",30,3.0,183.0,100,0.,0.05);
556   new TH2F("h2812","P vs X EAL cut st. 2 fit 1",30,3.0,183.0,100,0.,0.2);
557   //new TH2F("h2813","P vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
558   new TH2F("h2813","P vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,5.);
559   new TH2F("h2814","P vs X EYM cut st. 2 fit 1",30,3.0,183.0,100,0.,7.);
560
561   new TH2F("h2815","P2 vs X EPH cut st. 2 fit 1",30,3.0,183.0,100,0.,0.05);
562   new TH2F("h2816","P2 vs X EAL cut st. 2 fit 1",30,3.0,183.0,100,0.,0.2);
563   //new TH2F("h2817","P2 vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
564   new TH2F("h2817","P2 vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,5.);
565   new TH2F("h2818","P2 vs X EYM cut st. 2 fit 1",30,3.0,183.0,100,0.,7.);
566
567
568   new TH2F("h1111","dx vs x station 1",30,-250.,250.,30,-0.5,0.5);
569   new TH2F("h1112","dx vs x station 2",30,-250.,250.,30,-0.5,0.5);
570   new TH2F("h1113","dx vs x station 3",30,-250.,250.,30,-0.5,0.5);
571   new TH2F("h1114","dx vs x station 4",30,-250.,250.,30,-0.5,0.5);
572   new TH2F("h1115","dx vs x station 5",30,-250.,250.,30,-0.5,0.5);
573   new TH2F("h1121","dy vs y station 1",30,-250.,250.,30,-0.04,0.04);
574   new TH2F("h1122","dy vs y station 2",30,-250.,250.,30,-0.04,0.04);
575   new TH2F("h1123","dy vs y station 3",30,-250.,250.,30,-0.04,0.04);
576   new TH2F("h1124","dy vs y station 4",30,-250.,250.,30,-0.04,0.04);
577   new TH2F("h1125","dy vs y station 5",30,-250.,250.,30,-0.04,0.04);
578
579   // fin de test
580
581   new TH1F("h500","Acceptance en H st. 4",500,0.,500.);
582   new TH1F("h600","Acceptance en H st. 5",500,0.,500.);
583   new TH1F("h700","X vertex track found",200,-10.,10.);
584   new TH1F("h701","Y vertex track found",200,-10.,10.);
585   new TH1F("h800","Rap. muon gen.",100,0.,5.);
586   new TH1F("h801","Rap. muon gen. recons.",100,0.,5.);
587   new TH1F("h802","Rap. muon gen. ghost ",100,0.,5.);
588   new TH1F("h900","Pt muon gen.",100,0.,20.);
589   new TH1F("h901","Pt muon gen. recons.",100,0.,20.);
590   new TH1F("h902","Pt muon gen. ghost",100,0.,20.);
591   new TH1F("h910","phi muon gen.",100,-10.,10.);
592   new TH1F("h911","phi muon gen. recons.",100,-10.,10.);
593   new TH1F("h912","phi muon gen. ghost",100,-10.,10.);
594   new TH2F("h1001","Y VS X hit st. 1",300,-300.,300.,300,-300.,300.);
595   new TH2F("h1002","Y VS X hit st. 2",300,-300.,300.,300,-300.,300.);
596   new TH2F("h1003","Y VS X hit st. 3",300,-300.,300.,300,-300.,300.);
597   new TH2F("h1004","Y VS X hit st. 4",300,-300.,300.,300,-300.,300.);
598   new TH2F("h1005","Y VS X hit st. 5",300,-300.,300.,300,-300.,300.);
599   //  Histos variance dans 4      
600   new TH2F("h11","VAR X st. 4",30,3.0,183.0,100,0.,2.);
601   new TH2F("h12","VAR Y st. 4",30,3.0,183.0,100,0.,600.);
602   new TH2F("h13","VAR PHI st. 4",30,3.0,183.0,100,0.,0.0001);
603   new TH2F("h14","VAR ALM st. 4",30,3.0,183.0,100,0.,0.05);
604   new TH1F("h15","P",30,3.0,183.0);
605   new TH1F("h411","VAR X st. 4",100,-1.42,1.42);
606   new TH1F("h412","VAR Y st. 4",100,-25.,25.);
607   new TH1F("h413","VAR PHI st. 4",100,-0.01,0.01);
608   new TH1F("h414","VAR ALM st. 4",100,-0.23,0.23);
609   // histo2
610   new TH2F("h211","histo2-VAR X st. 4",30,3.0,183.0,100,0.,2.);
611   new TH2F("h212","histo2-VAR Y st. 4",30,3.0,183.0,100,0.,600.);
612   new TH1F("h213","histo2-VAR X st. 4",100,-1.42,1.42);
613   new TH1F("h214","histo2-VAR Y st. 4",100,-25.,25.);
614   new TH1F("h215","histo2-P",30,3.0,183.0);
615
616   //  Histos variance dans 2      
617   new TH2F("h21","VAR X st. 2",30,3.0,183.0,100,0.,3.);
618   new TH2F("h22","VAR Y st. 2",30,3.0,183.0,100,0.,7.);
619   new TH2F("h23","VAR PHI st. 2",30,3.0,183.0,100,0.,0.006);
620   new TH2F("h24","VAR ALM st. 2",30,3.0,183.0,100,0.,0.005);
621   new TH1F("h25","P",30,3.0,183.0);
622   new TH1F("h421","VAR X st. 2",100,-1.72,1.72);
623   new TH1F("h422","VAR Y st. 2",100,-2.7,2.7);
624   new TH1F("h423","VAR PHI st. 2",100,-0.08,0.08);
625   new TH1F("h424","VAR ALM st. 2",100,-0.072,0.072);
626   // histo2
627   new TH2F("h221","histo2-VAR X st. 2",30,3.0,183.0,100,0.,3.);
628   new TH2F("h222","histo2-VAR Y st. 2",30,3.0,183.0,100,0.,7.);
629   new TH1F("h223","histo2-VAR X st. 2",100,-1.72,1.72);
630   new TH1F("h224","histo2-VAR Y st. 2",100,-2.7,2.7);
631   new TH1F("h225","histo2-P",30,3.0,183.0);
632
633   //  Histos variance dans 1      
634   new TH2F("h31","VAR X st. 1",30,3.0,183.0,100,0.,2.);
635   new TH2F("h32","VAR Y st. 1",30,3.0,183.0,100,0.,0.5);
636   new TH2F("h33","VAR PHI st. 1",30,3.0,183.0,100,0.,0.006);
637   new TH2F("h34","VAR ALM st. 1",30,3.0,183.0,100,0.,0.005);
638   new TH1F("h35","P",30,3.0,183.0);
639   new TH1F("h431","VAR X st. 1",100,-1.42,1.42);
640   new TH1F("h432","VAR Y st. 1",100,-0.72,0.72);
641   new TH1F("h433","VAR PHI st. 1",100,-0.08,0.08);
642   new TH1F("h434","VAR ALM st. 1",100,-0.072,0.072);
643   //  Histos variance dans 1      
644   new TH2F("h41","VAR X st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,4.);
645   new TH2F("h42","VAR Y st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,20.);
646   new TH2F("h43","VAR PHI st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,0.005);
647   new TH2F("h44","VAR ALM st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,0.005);
648   new TH1F("h45","P",30,3.0,183.0);
649   new TH1F("h441","VAR X st. 1 fit 5,4,3,2,V",100,-2.,2.);
650   new TH1F("h442","VAR Y st. 1 fit 5,4,3,2,V",100,-4.5,4.5);
651   new TH1F("h443","VAR PHI st. 1 fit 5,4,3,2,V",100,-0.072,0.072);
652   new TH1F("h444","VAR ALM st. 1 fit 5,4,3,2,V",100,-0.072,0.072);
653   // histo2
654   new TH2F("h241","histo2-VAR X st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,4.);
655   new TH2F("h242","histo2-VAR Y st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,20.);
656   new TH1F("h243","histo2-VAR X st. 1 fit 5,4,3,2,V",100,-2.,2.);
657   new TH1F("h244","histo2-VAR Y st. 1 fit 5,4,3,2,V",100,-4.5,4.5);
658   new TH1F("h245","histo2-P",30,3.0,183.0);
659
660   //  Histos variance dans 2      
661   new TH2F("h51","VAR X st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.5);
662   new TH2F("h52","VAR Y st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,2.);
663   new TH2F("h53","VAR PHI st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.005);
664   new TH2F("h54","VAR ALM st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.01);
665   new TH1F("h55","P",30,3.0,183.0);
666   new TH1F("h451","VAR X st. 2 fit 5,4,3,1,V",100,-0.72,0.72);
667   new TH1F("h452","VAR Y st. 2 fit 5,4,3,1,V",100,-1.42,1.42);
668   new TH1F("h453","VAR PHI st. 2 fit 5,4,3,1,V",100,-0.072,0.072);
669   new TH1F("h454","VAR ALM st. 2 fit 5,4,3,1,V",100,-0.1,0.1);
670   new TH1F("h999","PTOT",30,3.0,183.0);
671   // histo2
672   new TH2F("h251","histo2-VAR X st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.5);
673   new TH2F("h252","histo2-VAR Y st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,2.);
674   new TH1F("h253","histo2-VAR X st. 2 fit 5,4,3,1,V",100,-0.72,0.72);
675   new TH1F("h254","histo2-VAR Y st. 2 fit 5,4,3,1,V",100,-1.42,1.42);
676   new TH1F("h255","histo2-P",30,3.0,183.0);
677   //  Histos variance dans 3      
678   new TH2F("h61","VAR X st. 3 fit 4,5,V",30,3.0,183.0,100,0.,5.);
679   new TH2F("h62","VAR Y st. 3 fit 4,5,V",30,3.0,183.0,100,0.,2.);
680   new TH2F("h63","VAR PHI st. 3 fit 4,5,V",30,3.0,183.0,100,0.,0.0006);
681   new TH2F("h64","VAR ALM st. 3 fit 4,5,V",30,3.0,183.0,100,0.,0.0006);
682   new TH1F("h65","P",30,3.0,183.0);
683   new TH1F("h461","VAR X st. 3 fit 4,5,V",100,-2.25,2.25);
684   new TH1F("h462","VAR Y st. 3 fit 4,5,V",100,-1.42,1.42);
685   new TH1F("h463","VAR PHI st. 3 fit 4,5,V",100,-0.024,0.024);
686   new TH1F("h464","VAR ALM st. 3 fit 4,5,V",100,-0.024,0.024);
687   // histo2
688   new TH2F("h261","histo2-VAR X st. 3 fit 4,5,V",30,3.0,183.0,100,0.,5.);
689   new TH2F("h262","histo2-VAR Y st. 3 fit 4,5,V",30,3.0,183.0,100,0.,2.);
690   new TH1F("h263","histo2-VAR X st. 3 fit 4,5,V",100,-2.25,2.25);
691   new TH1F("h264","histo2-VAR Y st. 3 fit 4,5,V",100,-1.42,1.42);
692   new TH1F("h265","Phisto2-",30,3.0,183.0);
693   // Histos dx,dy distribution between chambers inside stations
694   new TH1F("h71","DX in st. ID-70",100,-5.,5.);
695   new TH1F("h81","DY in st. ID-80",100,-5.,5.);
696   new TH1F("h72","DX in st. ID-70",100,-5.,5.);
697   new TH1F("h82","DY in st. ID-80",100,-5.,5.);
698   new TH1F("h73","DX in st. ID-70",100,-5.,5.);
699   new TH1F("h83","DY in st. ID-80",100,-5.,5.);
700   new TH1F("h74","DX in st. ID-70",100,-5.,5.);
701   new TH1F("h84","DY in st. ID-80",100,-5.,5.);
702   new TH1F("h75","DX in st. ID-70",100,-5.,5.);
703   new TH1F("h85","DY in st. ID-80",100,-5.,5.);
704 }
705
706 //_____________________________________________________________________________
707 void chfnt(Int_t &ievr, Int_t &ntrackr, Int_t *istatr, Int_t *isignr, Float_t *pxr, Float_t *pyr, Float_t *pzr, Float_t *zvr, Float_t *chi2r,  Float_t *pxv, Float_t *pyv, Float_t *pzv)
708 {
709   //
710   // fill the ntuple 
711     NtupleSt.ievr = ievr;
712     NtupleSt.ntrackr = ntrackr;
713     for (Int_t i=0; i<500; i++) {
714         NtupleSt.istatr[i] = istatr[i];
715         NtupleSt.isignr[i] = isignr[i]; 
716         NtupleSt.pxr[i]    = pxr[i]; 
717         NtupleSt.pyr[i]    = pyr[i];
718         NtupleSt.pzr[i]    = pzr[i];
719         NtupleSt.zvr[i]    = zvr[i];
720         NtupleSt.chi2r[i]  = chi2r[i];
721         NtupleSt.pxv[i]    = pxv[i]; 
722         NtupleSt.pyv[i]    = pyv[i];
723         NtupleSt.pzv[i]    = pzv[i];
724     }
725     gAliNtupleGlobal->Fill();   
726 }
727
728 //________________
729 void hist_closed()
730 {
731   //
732   // write histos and ntuple to "reconst.root" file
733   gAliFileGlobal->Write();
734 }
735
736 //________________________________________________________________________
737 void trackf_read_fit(Int_t &ievr, Int_t &nev, Int_t &nhittot1, Int_t *izch, Double_t *xgeant, Double_t *ygeant) 
738 {
739
740   // introduce aliroot variables in fortran common 
741   // tracking study from geant hits 
742   //
743
744   AliMUON *pMUON  = (AliMUON*) gAlice->GetModule("MUON");
745   TTree *treeH = gAlice->TreeH();
746   Int_t ntracks = (Int_t)treeH->GetEntries();
747   cout<<"ntrack="<<ntracks<<endl;
748
749   nhittot1 = 0;
750
751 //  Loop over tracks
752   for (Int_t track=0; track<ntracks;track++) {
753       gAlice->ResetHits();
754       treeH->GetEvent(track);
755       
756       if (pMUON)  {
757
758 //  Loop over hits
759           for(AliMUONHit* mHit=(AliMUONHit*)pMUON->FirstHit(-1); 
760               mHit;
761               mHit=(AliMUONHit*)pMUON->NextHit()) 
762           {
763               if (mHit->Chamber() > 10) continue;
764               Int_t ftrack = mHit->Track();
765               Int_t id = gAlice->Particle(ftrack)->GetPdgCode();
766               
767               if (id==kMuonPlus||id==kMuonMinus) {
768                   xgeant[nhittot1]   = mHit->Y();
769                   ygeant[nhittot1]   = mHit->X();
770                   izch[nhittot1]     = mHit->Chamber();
771 //                printf("id %d ch %d x %f y %f\n",id,izch[nhittot1],xgeant[nhittot1],ygeant[nhittot1]);  
772                   nhittot1++;
773               }
774           } // hit loop
775       } // if pMUON
776   } // track loop
777
778   ievr=nev;
779   gAliFileGlobal->cd();    
780 }
781
782 //______________________________________________________________________________
783 void trackf_read_geant(Int_t *itypg, Double_t *xtrg, Double_t *ytrg, Double_t *ptotg, Int_t *idg, Int_t *izch, Double_t *pvert1g, Double_t *pvert2g, Double_t *pvert3g, Double_t *zvertg, Int_t &nhittot1, Double_t *cx, Double_t *cy, Double_t *cz, Int_t &ievr,Int_t &nev,Double_t *xgeant, Double_t *ygeant, Double_t *clsize1, Double_t *clsize2) 
784 {
785   //
786   // introduce aliroot variables in fortran common 
787   // tracking study from geant hits 
788   //
789
790   AliMUON *pMUON  = (AliMUON*) gAlice->GetModule("MUON");
791   
792   //  TTree *treeK = gAlice->TreeK();
793   TTree *treeH = gAlice->TreeH();
794   Int_t ntracks = (Int_t)treeH->GetEntries();
795   cout<<"ntrack="<<ntracks<<endl;
796
797   Int_t maxidg = 0;
798   Int_t nres=0;
799   
800 //
801 //  Loop over tracks
802 //
803
804   for (Int_t track=0; track<ntracks;track++) {
805       gAlice->ResetHits();
806       treeH->GetEvent(track);
807       
808       if (pMUON)  {
809 //
810 //  Loop over hits
811 //
812           for(AliMUONHit* mHit=(AliMUONHit*)pMUON->FirstHit(-1); 
813               mHit;
814               mHit=(AliMUONHit*)pMUON->NextHit()) 
815           {
816               if (maxidg<=20000) {
817                 
818                 if (mHit->Chamber() > 10) continue;
819                 TParticle *particle;
820                 Int_t ftrack = mHit->Track();
821                 Int_t id = gAlice->Particle(ftrack)->GetPdgCode();
822
823 //              if (id==kMuonPlus||id==kMuonMinus) {
824                     
825                     // inversion de x et y car le champ est inverse dans le programme tracking
826                     xtrg[maxidg]   = 0;       
827                     ytrg[maxidg]   = 0;       
828                     xgeant[maxidg]   = mHit->Y();             // x-pos of hit
829                     ygeant[maxidg]   = mHit->X();             // y-pos of hit
830                     clsize1[maxidg]   = 0;     // cluster size on 1-st cathode
831                     clsize2[maxidg]   = 0;     // cluster size on 2-nd cathode
832                     cx[maxidg]     = mHit->Py();              // Px of hit
833                     cy[maxidg]     = mHit->Px();              // Py of hit
834                     cz[maxidg]     = mHit->Pz();              // Pz of hit
835                     izch[maxidg]   = mHit->Chamber();         
836                     /*      
837                     Int_t pdgtype  = Int_t(mHit->fParticle); // particle number
838                     itypg[maxidg]  = gMC->IdFromPDG(pdgtype);
839                     */
840                     itypg[maxidg] = 0;
841                     if (id==kMuonPlus) itypg[maxidg]  = 5;
842                     if (id==kMuonMinus) itypg[maxidg]  = 6;
843
844                     //printf("ich, itypg[maxidg] %d %d\n",izch[maxidg],itypg[maxidg]);
845
846                     ptotg[maxidg]  = mHit->Momentum();          // P of hit 
847                     
848                     particle = gAlice->Particle(ftrack);
849                     Float_t thet = particle->Theta();
850                     thet = thet*180./3.1416;
851                     
852                     //cout<<"chambre "<<izch[maxidg]<<"  ptot="<<ptotg[maxidg]<<"   theta="<<thet<<"   phi="<<mHit->fPhi<<" z="<<zz<<endl;          
853                     
854                     Int_t iparent = particle->GetFirstMother();
855                     if (iparent >= 0) {
856                         Int_t ip;
857                         while(1) {
858                             ip=gAlice->Particle(iparent)->GetFirstMother();
859                             if (ip < 0) {
860                                 break;
861                             } else {
862                                 iparent = ip;
863                             }
864                         }
865                     }
866                     //printf("iparent - %d\n",iparent);
867                     Int_t id1  = ftrack; // numero de la particule generee au vertex
868                     Int_t idum = track+1;
869                     Int_t id2 = gAlice->Particle(iparent)->GetPdgCode();
870
871                     if (id2==443) id2=114;
872                     else id2=116;
873                    
874                     if (id2==116) {
875                       nres++;
876                     }
877                     //printf("id2 %d\n",id2);
878                     idg[maxidg] = 30000*id1+10000*idum+id2;
879                     
880                     pvert1g[maxidg] = particle->Py();      // Px vertex
881                     pvert2g[maxidg] = particle->Px();      // Py vertex  
882                     pvert3g[maxidg] = particle->Pz();      // Pz vertex
883                     zvertg[maxidg]  = particle->Vz();      // z vertex 
884             
885                     //      cout<<"x="<<xgeant[maxidg]<<endl;
886                     //cout<<"y="<<ygeant[maxidg]<<endl;
887                     //cout<<"typ="<<itypg[maxidg]<<endl;
888
889                     maxidg ++;
890
891                 }
892               }
893           } // hit loop
894 //      } // if pMUON
895   } // track loop first file
896
897   if (gAliTrH1 && gAliHits2 ) { // if background file
898     ntracks =(Int_t)gAliTrH1->GetEntries();
899     printf("Trackf_read - 2-nd file - ntracks %d\n",ntracks);
900
901     //  Loop over tracks
902     for (Int_t track=0; track<ntracks; track++) {
903       
904       if (gAliHits2) gAliHits2->Clear();
905       gAliTrH1->GetEvent(track);
906
907       //  Loop over hits
908       AliMUONHit *mHit;
909       for (int i=0;i<gAliHits2->GetEntriesFast();i++) 
910         {
911           mHit=(AliMUONHit*) (*gAliHits2)[i];
912           if (mHit->Chamber() > 10) continue;
913           if (maxidg<=20000) {
914             
915             // inversion de x et y car le champ est inverse dans le programme tracking !!!!
916             xtrg[maxidg]   = 0;                    // only for reconstructed point
917             ytrg[maxidg]   = 0;                    // only for reconstructed point
918             xgeant[maxidg]   = mHit->Y();           // x-pos of hit
919             ygeant[maxidg]   = mHit->X();           // y-pos of hit
920             clsize1[maxidg]   = 0;           // cluster size on 1-st cathode
921             clsize2[maxidg]   = 0;           // cluster size on 2-nd cathode
922             cx[maxidg]     = mHit->Py();            // Px of hit
923             cy[maxidg]     = mHit->Px();            // Py of hit
924             cz[maxidg]     = mHit->Pz();            // Pz of hit
925             izch[maxidg]   = mHit->Chamber();       // chamber number
926             ptotg[maxidg]  = mHit->Momentum();      // P of hit 
927             
928             Int_t ftrack = mHit->Track();
929             Int_t id1  = ftrack;                   // track number 
930             Int_t idum = track+1;
931             
932             TClonesArray *fPartArray = gAliParticles2;
933 //          TParticle *Part=NULL;
934             Int_t id = ((TParticle*) fPartArray->UncheckedAt(ftrack))->GetPdgCode();
935             if (id==kMuonPlus||id==kMuonMinus) {
936                 if (id==kMuonPlus) itypg[maxidg]  = 5;
937                 else  itypg[maxidg]  = 6;
938             } else itypg[maxidg]=0;
939             
940             Int_t id2=0; // set parent to 0 for background !!
941             idg[maxidg] = 30000*id1+10000*idum+id2;
942             
943
944             pvert1g[maxidg] = 0;      // Px vertex
945             pvert2g[maxidg] = 0;      // Py vertex  
946             pvert3g[maxidg] = 0;      // Pz vertex
947             zvertg[maxidg]  = 0;      // z vertex 
948             maxidg ++;
949
950           } // check limits (maxidg)
951         } // hit loop 
952     } // track loop
953   } // if gAliTrH1
954
955   ievr = nev;
956   nhittot1 = maxidg ;
957   cout<<"nhittot1="<<nhittot1<<endl;
958
959   static Int_t nbres=0;
960   if (nres>=19) nbres++;
961   printf("nres, nbres %d %d \n",nres,nbres);
962
963   gAliFileGlobal->cd();      
964
965 }
966
967 //________________________________________________________________________
968 void trackf_read_spoint(Int_t *itypg, Double_t *xtrg, Double_t *ytrg, Double_t *ptotg, Int_t *idg, Int_t *izch, Double_t *pvert1g, Double_t *pvert2g, Double_t *pvert3g, Double_t *zvertg, Int_t &nhittot1, Double_t *cx, Double_t *cy, Double_t *cz, Int_t &ievr,Int_t &nev,Double_t *xgeant, Double_t *ygeant,Double_t *clsize1, Double_t *clsize2) 
969
970 {
971     //
972     // introduce aliroot variables in fortran common 
973     // tracking study from reconstructed points 
974     //
975     AliMUON *pMUON  = (AliMUON*) gAlice->GetModule("MUON");
976     
977     cout<<"numero de l'evenement "<<nev<<endl;
978     
979     TTree *treeR = gAlice->TreeR();
980     Int_t nent=(Int_t)treeR->GetEntries();
981     if (nev < 10) 
982         printf("Found %d entries in the tree (must be one per cathode per event! + 1empty)\n",
983                nent);
984 //
985     
986     Int_t mult1, mult2;
987     
988     if (pMUON) {
989         Int_t mpoi=0;
990         for (Int_t ich=0;ich<10;ich++) {
991             printf("chambre %d\n",ich+1);
992             TClonesArray *reconstPoints  = pMUON->RawClustAddress(ich);
993
994             pMUON->ResetRawClusters();
995             treeR->GetEvent(nent-1);
996             Int_t npoints = (Int_t) reconstPoints->GetEntries();
997             if (!npoints) continue;
998             printf("\n ch %d npoints = %d\n",ich+1,npoints);
999             //  Loop over reconstruted points
1000             for (Int_t ipoi=0; ipoi<npoints; ipoi++) {
1001                 printf("  point %d\n",ipoi);
1002                 AliMUONRawCluster* point = 
1003                     (AliMUONRawCluster*) reconstPoints->UncheckedAt(ipoi);
1004                 
1005                 mult1=point->fMultiplicity[0];
1006                 mult2=point->fMultiplicity[1];        
1007                 xtrg[mpoi]=(Double_t) point->fY[0];
1008                 ytrg[mpoi]=(Double_t) point->fX[0];
1009                 izch[mpoi]=ich+1;
1010                 Int_t itrack  = point->fTracks[1];
1011                 Int_t ihit    = point->fTracks[0];
1012                 xgeant[mpoi] = 0;
1013                 ygeant[mpoi] = 0;
1014                 clsize1[mpoi] = mult1;
1015                 clsize2[mpoi] = mult2;
1016                 Int_t id1, id2, idum;
1017                 id1=id2=idum=-1;
1018                 itypg[mpoi]=0;
1019                 ihit = ihit-1;
1020                 if (ihit >=0 && itrack >=0) {
1021                     gAlice->ResetHits();
1022                     gAlice->TreeH()->GetEvent(itrack);
1023                     TClonesArray *pMUONhits  = pMUON->Hits();
1024                     AliMUONHit* mHit;
1025                     mHit=(AliMUONHit*) (pMUONhits->UncheckedAt(ihit));
1026                     Int_t id = (Int_t) mHit->Particle();
1027                     xgeant[mpoi] = mHit->Y();          
1028                     ygeant[mpoi] = mHit->X(); 
1029                     if (id == kMuonPlus)  itypg[mpoi]=5;
1030                     if (id == kMuonMinus) itypg[mpoi]=6;
1031                     TParticle *particle;
1032                     particle = gAlice->Particle(mHit->Track());
1033                     TParticle* particleM=gAlice->Particle(particle->GetFirstMother());
1034                     Int_t iparent=particleM->GetPdgCode();
1035                     printf("\n Particle Id:%d %d \n", id, iparent);
1036                     if (iparent == 443) id2=114;
1037                     if (iparent == 553) id2=116;
1038                 }
1039                 id1=itrack;
1040                 idum=itrack+1;
1041                 idg[mpoi] = 30000*id1+10000*idum+id2;
1042                 mpoi++;
1043             } // loop over points
1044         } // loop over chamber
1045         ievr = nev;
1046         cout<<"evenement "<<ievr<<endl;
1047         nhittot1 = mpoi;
1048         cout<<"nhittot1="<<nhittot1<<endl;
1049         
1050         treeR->Reset();
1051
1052         gAliFileGlobal->cd();
1053
1054     } // if pMUON
1055 }
1056
1057 //____________________________________________________________________________
1058 void trackf_fit(Int_t &ivertex, Double_t *pest, Double_t *pstep, Double_t &pxzinv, Double_t &tphi, Double_t &talam, Double_t &xvert, Double_t &yvert)
1059 {
1060   //
1061   //  Fit a track candidate with the following input parameters: 
1062   //  INPUT :  IVERTEX  : vertex flag, if IVERTEX=1 (XVERT,YVERT) are free paramaters
1063   //                                   if IVERTEX=1 (XVERT,YVERT)=(0.,0.) 
1064   //           PEST(5)  : starting value of parameters (minuit)
1065   //           PSTEP(5) : step size for parameters (minuit)
1066   //  OUTPUT : PXZINV,TPHI,TALAM,XVERT,YVERT : fitted value of the parameters
1067
1068   static Double_t arglist[10];
1069   static Double_t c[5] = {0.4, 0.45, 0.45, 90., 90.};
1070   static Double_t b1, b2, epxz, efi, exs, exvert, eyvert;
1071   TString chname;
1072   Int_t ierflg = 0;
1073   
1074   TMinuit *gMinuit = new TMinuit(5);
1075   gMinuit->mninit(5,10,7);
1076   gMinuit->SetFCN(fcnf);  // constant m.f.
1077
1078   arglist[0] = -1;
1079   
1080   gMinuit->mnexcm("SET PRINT", arglist, 1, ierflg);
1081   //      gMinuit->mnseti('track fitting');
1082   
1083   gMinuit->mnparm(0, "invmom",  pest[0], pstep[0], -c[0], c[0], ierflg);
1084   gMinuit->mnparm(1, "azimuth", pest[1], pstep[1], -c[1], c[1], ierflg);
1085   gMinuit->mnparm(2, "deep",    pest[2], pstep[2], -c[2], c[2], ierflg);
1086   if (ivertex==1) {
1087     gMinuit->mnparm(3, "x ", pest[3], pstep[3], -c[3], c[3], ierflg);
1088     gMinuit->mnparm(4, "y ", pest[4], pstep[4], -c[4], c[4], ierflg);  
1089   }   
1090   
1091   gMinuit->mnexcm("SET NOGR", arglist, 0, ierflg);
1092   gMinuit->mnexcm("MINIMIZE", arglist, 0, ierflg);
1093   gMinuit->mnexcm("EXIT" , arglist, 0, ierflg);
1094   
1095   gMinuit->mnpout(0, chname, pxzinv, epxz, b1, b2, ierflg);
1096   gMinuit->mnpout(1, chname, tphi, efi, b1, b2, ierflg);
1097   gMinuit->mnpout(2, chname, talam, exs, b1, b2, ierflg);
1098   if (ivertex==1) {
1099     gMinuit->mnpout(3, chname, xvert, exvert, b1, b2, ierflg);
1100     gMinuit->mnpout(4, chname, yvert, eyvert, b1, b2, ierflg);
1101   }   
1102   
1103   delete gMinuit;
1104 }
1105            
1106 //________________________________________________________________________________
1107 void fcnf(Int_t &npar, Double_t *grad, Double_t &fval, Double_t *pest, Int_t iflag)
1108 {
1109   //
1110   // function called by trackf_fit
1111       Int_t futil = 0;
1112       fcn(npar,grad,fval,pest,iflag,futil);
1113 }
1114
1115 //____________________________________________________________________________
1116 void prec_fit(Double_t &pxzinv, Double_t &fis, Double_t &alams, Double_t &xvert, Double_t &yvert, Double_t &pxzinvf, Double_t &fif, Double_t &alf, Double_t &xvertf, Double_t &yvertf, Double_t &epxzinv, Double_t &efi, Double_t &exs, Double_t &exvert, Double_t &eyvert)
1117 {
1118   // 
1119   // minuit fits for tracking finding 
1120                                                                             
1121       static Double_t arglist[10];
1122       static Double_t c1[5] = {0.001, 0.001, 0.001, 1., 1.};
1123       static Double_t c2[5] = {0.5, 0.5, 0.5, 120., 120.};
1124       static Double_t emat[9];
1125       static Double_t b1, b2;
1126       Double_t fmin, fedm, errdef; 
1127       Int_t npari, nparx, istat;
1128
1129       TString chname;
1130       Int_t ierflg = 0;
1131       
1132       TMinuit *gMinuit = new TMinuit(5);
1133       gMinuit->mninit(5,10,7);
1134       gMinuit->SetFCN(fcnfitf);
1135
1136       arglist[0] = -1.;
1137       gMinuit->mnexcm("SET PRINT", arglist, 1, ierflg);
1138       
1139       //      gMinuit->mnseti('track fitting');
1140
1141       gMinuit->mnparm(0,"invmom",   pxzinv, c1[0], -c2[0], c2[0], ierflg); // 0.003, 0.5
1142       gMinuit->mnparm(1,"azimuth ", fis,    c1[1], -c2[1], c2[1], ierflg);
1143       gMinuit->mnparm(2,"deep    ", alams,  c1[2], -c2[2], c2[2], ierflg);
1144       gMinuit->mnparm(3,"xvert",    xvert,  c1[3], -c2[3], c2[3], ierflg);
1145       gMinuit->mnparm(4,"yvert",    yvert,  c1[4], -c2[4], c2[4], ierflg);
1146
1147       gMinuit->mnexcm("SET NOGR", arglist, 0, ierflg);
1148       arglist[0] = 2.;
1149       gMinuit->mnexcm("MINIMIZE", arglist, 0, ierflg);
1150       gMinuit->mnexcm("EXIT", arglist, 0, ierflg);
1151  
1152       gMinuit->mnpout(0, chname, pxzinvf, epxzinv, b1, b2, ierflg);
1153       gMinuit->mnpout(1, chname, fif, efi, b1, b2, ierflg);
1154       gMinuit->mnpout(2, chname, alf, exs, b1, b2, ierflg);
1155       gMinuit->mnpout(3, chname, xvertf, exvert, b1, b2, ierflg);
1156       gMinuit->mnpout(4, chname, yvertf, eyvert, b1, b2, ierflg);
1157   
1158       gMinuit->mnemat(emat, 3);
1159       gMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);
1160
1161      delete gMinuit;
1162 }
1163
1164 //____________________________________________________________________
1165 void fcnfitf(Int_t &npar, Double_t *grad, Double_t &fval, Double_t *xval, Int_t iflag)
1166 {
1167   //
1168   // function called by prec_fit 
1169       Int_t futil = 0;
1170       fcnfit(npar,grad,fval,xval,iflag,futil);
1171 }