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