]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONEventReconstructor.cxx
8ecd49ad75abf8e81222733ddacd3ba9a1344813
[u/mrichter/AliRoot.git] / MUON / AliMUONEventReconstructor.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 /* $Id$ */
17
18 ////////////////////////////////////
19 //
20 // MUON event reconstructor in ALICE
21 //
22 // This class contains as data:
23 // * the parameters for the event reconstruction
24 // * a pointer to the array of hits to be reconstructed (the event)
25 // * a pointer to the array of segments made with these hits inside each station
26 // * a pointer to the array of reconstructed tracks
27 //
28 // It contains as methods, among others:
29 // * MakeEventToBeReconstructed to build the array of hits to be reconstructed
30 // * MakeSegments to build the segments
31 // * MakeTracks to build the tracks
32 //
33 ////////////////////////////////////
34
35 #include <stdlib.h>
36 #include <Riostream.h>
37 #include <TDirectory.h>
38 #include <TFile.h>
39 #include <TMatrixD.h> //AZ
40
41 #include "AliMUONEventReconstructor.h"
42 #include "AliMUON.h"
43 #include "AliMUONConstants.h"
44 #include "AliMUONHit.h"
45 #include "AliMUONHitForRec.h"
46 #include "AliMUONTriggerTrack.h"
47 #include "AliMUONTriggerCircuit.h"
48 #include "AliMUONRawCluster.h"
49 #include "AliMUONLocalTrigger.h"
50 #include "AliMUONGlobalTrigger.h"
51 #include "AliMUONRecoEvent.h"
52 #include "AliMUONSegment.h"
53 #include "AliMUONTrack.h"
54 #include "AliMUONTrackHit.h"
55 #include "AliMagF.h"
56 #include "AliRun.h" // for gAlice
57 #include "AliRunLoader.h"
58 #include "AliLoader.h"
59 #include "AliMUONTrackK.h" //AZ
60 #include "AliMC.h"
61 #include "AliLog.h"
62 #include "AliTrackReference.h"
63
64 //************* Defaults parameters for reconstruction
65 const Double_t AliMUONEventReconstructor::fgkDefaultMinBendingMomentum = 3.0;
66 const Double_t AliMUONEventReconstructor::fgkDefaultMaxBendingMomentum = 500.0;
67 const Double_t AliMUONEventReconstructor::fgkDefaultMaxChi2 = 100.0;
68 const Double_t AliMUONEventReconstructor::fgkDefaultMaxSigma2Distance = 16.0;
69 const Double_t AliMUONEventReconstructor::fgkDefaultBendingResolution = 0.01;
70 const Double_t AliMUONEventReconstructor::fgkDefaultNonBendingResolution = 0.144;
71 const Double_t AliMUONEventReconstructor::fgkDefaultChamberThicknessInX0 = 0.03;
72 // Simple magnetic field:
73 // Value taken from macro MUONtracking.C: 0.7 T, hence 7 kG
74 // Length and Position from reco_muon.F, with opposite sign:
75 // Length = ZMAGEND-ZCOIL
76 // Position = (ZMAGEND+ZCOIL)/2
77 // to be ajusted differently from real magnetic field ????
78 const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBValue = 7.0;
79 const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBLength = 428.0;
80 const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBPosition = 1019.0;
81 const Int_t    AliMUONEventReconstructor::fgkDefaultRecTrackRefHits = 0;
82 const Double_t AliMUONEventReconstructor::fgkDefaultEfficiency = 0.95;
83
84 const Int_t    AliMUONEventReconstructor::fgkDefaultPrintLevel = -1;
85
86 ClassImp(AliMUONEventReconstructor) // Class implementation in ROOT context
87
88   //__________________________________________________________________________
89 AliMUONEventReconstructor::AliMUONEventReconstructor(AliLoader* loader)
90   : TObject()
91 {
92   // Constructor for class AliMUONEventReconstructor
93   SetReconstructionParametersToDefaults();
94   fTrackMethod = 1; //AZ - tracking method (1-default, 2-Kalman)
95   // Memory allocation for the TClonesArray of hits for reconstruction
96   // Is 10000 the right size ????
97   fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
98   fNHitsForRec = 0; // really needed or GetEntriesFast sufficient ????
99   // Memory allocation for the TClonesArray's of segments in stations
100   // Is 2000 the right size ????
101   for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
102     fSegmentsPtr[st] = new TClonesArray("AliMUONSegment", 2000);
103     fNSegments[st] = 0; // really needed or GetEntriesFast sufficient ????
104   }
105   // Memory allocation for the TClonesArray of reconstructed tracks
106   // Is 10 the right size ????
107   fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
108   fNRecTracks = 0; // really needed or GetEntriesFast sufficient ????
109 // trigger tracks
110   fRecTriggerTracksPtr = new TClonesArray("AliMUONTriggerTrack", 10);
111   fNRecTriggerTracks = 0; // really needed or GetEntriesFast sufficient ????
112   // Memory allocation for the TClonesArray of hits on reconstructed tracks
113   // Is 100 the right size ????
114   //AZ fRecTrackHitsPtr = new TClonesArray("AliMUONTrack", 100);
115   fRecTrackHitsPtr = new TClonesArray("AliMUONTrackHit", 100);
116   fNRecTrackHits = 0; // really needed or GetEntriesFast sufficient ????
117
118   // Sign of fSimpleBValue according to sign of Bx value at (50,50,-950).
119   Float_t b[3], x[3];
120   x[0] = 50.; x[1] = 50.; x[2] = -950.;
121   gAlice->Field()->Field(x, b);
122   fSimpleBValue = TMath::Sign(fSimpleBValue,(Double_t) b[0]);
123   fSimpleBPosition = TMath::Sign(fSimpleBPosition,(Double_t) x[2]);
124   // See how to get fSimple(BValue, BLength, BPosition)
125   // automatically calculated from the actual magnetic field ????
126
127   if (fPrintLevel >= 0) {
128     cout << "AliMUONEventReconstructor constructed with defaults" << endl; Dump();
129     cout << endl << "Magnetic field from root file:" << endl;
130     gAlice->Field()->Dump();
131     cout << endl;
132   }
133   
134   // Initializions for track ref. background events
135   fBkgTrackRefFile = 0;
136   fBkgTrackRefTK = 0;
137   fBkgTrackRefParticles = 0;
138   fBkgTrackRefTTR = 0;
139   fBkgTrackRefEventNumber = -1;
140   
141   // Initialize to 0 pointers to RecoEvent, tree and tree file
142   fRecoEvent = 0;
143   fEventTree = 0;
144   fTreeFile  = 0;
145  
146   // initialize loader's
147   fLoader = loader;
148
149   // initialize container
150   fMUONData  = new AliMUONData(fLoader,"MUON","MUON");
151
152    // Loading AliRun master
153   AliRunLoader* runloader = fLoader->GetRunLoader();
154   if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
155   gAlice = runloader->GetAliRun();
156
157   return;
158 }
159   //__________________________________________________________________________
160 AliMUONEventReconstructor::AliMUONEventReconstructor (const AliMUONEventReconstructor& rhs)
161   : TObject(rhs)
162 {
163 // Protected copy constructor
164
165   AliFatal("Not implemented.");
166 }
167
168 AliMUONEventReconstructor & 
169 AliMUONEventReconstructor::operator=(const AliMUONEventReconstructor& rhs)
170 {
171 // Protected assignement operator
172
173   if (this == &rhs) return *this;
174
175   AliFatal("Not implemented.");
176     
177   return *this;  
178 }
179
180   //__________________________________________________________________________
181 AliMUONEventReconstructor::~AliMUONEventReconstructor(void)
182 {
183   // Destructor for class AliMUONEventReconstructor
184   if (fTreeFile) {
185      fTreeFile->Close();
186      delete fTreeFile;
187   }
188 //  if (fEventTree) delete fEventTree;
189   if (fRecoEvent) delete fRecoEvent;
190   delete fHitsForRecPtr; // Correct destruction of everything ???? or delete [] ????
191   for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
192     delete fSegmentsPtr[st]; // Correct destruction of everything ????
193   return;
194 }
195
196   //__________________________________________________________________________
197 void AliMUONEventReconstructor::SetReconstructionParametersToDefaults(void)
198 {
199   // Set reconstruction parameters to default values
200   // Would be much more convenient with a structure (or class) ????
201   fMinBendingMomentum = fgkDefaultMinBendingMomentum;
202   fMaxBendingMomentum = fgkDefaultMaxBendingMomentum;
203   fMaxChi2 = fgkDefaultMaxChi2;
204   fMaxSigma2Distance = fgkDefaultMaxSigma2Distance;
205
206   AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON");
207   // ******** Parameters for making HitsForRec
208   // minimum radius,
209   // like in TRACKF_STAT:
210   // 2 degrees for stations 1 and 2, or ch(0...) from 0 to 3;
211   // 30 cm for stations 3 to 5, or ch(0...) from 4 to 9
212   for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
213     if (ch < 4) fRMin[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
214                   2.0 * TMath::Pi() / 180.0;
215     else fRMin[ch] = 30.0;
216     // maximum radius at 10 degrees and Z of chamber
217     fRMax[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
218                   10.0 * TMath::Pi() / 180.0;
219   }
220
221   // ******** Parameters for making segments
222   // should be parametrized ????
223   // according to interval between chambers in a station ????
224   // Maximum distance in non bending plane
225   // 5 * 0.22 just to remember the way it was made in TRACKF_STAT
226   // SIGCUT*DYMAX(IZ)
227   for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
228     fSegmentMaxDistNonBending[st] = 5. * 0.22;
229   // Maximum distance in bending plane:
230   // values from TRACKF_STAT, corresponding to (J psi 20cm),
231   // scaled to the real distance between chambers in a station
232   fSegmentMaxDistBending[0] = TMath::Abs( 1.5 *
233     ((&(pMUON->Chamber(1)))->Z() - (&(pMUON->Chamber(0)))->Z()) / 20.0);
234   fSegmentMaxDistBending[1] = TMath::Abs( 1.5 *
235     ((&(pMUON->Chamber(3)))->Z() - (&(pMUON->Chamber(2)))->Z()) / 20.0);
236   fSegmentMaxDistBending[2] = TMath::Abs( 3.0 *
237     ((&(pMUON->Chamber(5)))->Z() - (&(pMUON->Chamber(4)))->Z()) / 20.0);
238   fSegmentMaxDistBending[3] = TMath::Abs( 6.0 *
239     ((&(pMUON->Chamber(7)))->Z() - (&(pMUON->Chamber(6)))->Z()) / 20.0);
240   fSegmentMaxDistBending[4] = TMath::Abs( 6.0 *
241     ((&(pMUON->Chamber(9)))->Z() - (&(pMUON->Chamber(8)))->Z()) / 20.0);
242   
243   fBendingResolution = fgkDefaultBendingResolution;
244   fNonBendingResolution = fgkDefaultNonBendingResolution;
245   fChamberThicknessInX0 = fgkDefaultChamberThicknessInX0;
246   fSimpleBValue = fgkDefaultSimpleBValue;
247   fSimpleBLength = fgkDefaultSimpleBLength;
248   fSimpleBPosition = fgkDefaultSimpleBPosition;
249   fRecTrackRefHits = fgkDefaultRecTrackRefHits;
250   fEfficiency = fgkDefaultEfficiency;
251   fPrintLevel = fgkDefaultPrintLevel;
252   return;
253 }
254
255 //__________________________________________________________________________
256 Double_t AliMUONEventReconstructor::GetImpactParamFromBendingMomentum(Double_t BendingMomentum) const
257 {
258   // Returns impact parameter at vertex in bending plane (cm),
259   // from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
260   // using simple values for dipole magnetic field.
261   // The sign of "BendingMomentum" is the sign of the charge.
262   return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
263           BendingMomentum);
264 }
265
266 //__________________________________________________________________________
267 Double_t AliMUONEventReconstructor::GetBendingMomentumFromImpactParam(Double_t ImpactParam) const
268 {
269   // Returns signed bending momentum in bending plane (GeV/c),
270   // the sign being the sign of the charge for particles moving forward in Z,
271   // from the impact parameter "ImpactParam" at vertex in bending plane (cm),
272   // using simple values for dipole magnetic field.
273   return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
274           ImpactParam);
275 }
276
277 //__________________________________________________________________________
278 void AliMUONEventReconstructor::SetBkgTrackRefFile(Text_t *BkgTrackRefFileName)
279 {
280   // Set background file ... for track ref. hits
281   // Must be called after having loaded the firts signal event
282   if (fPrintLevel >= 0) {
283     cout << "Enter SetBkgTrackRefFile with BkgTrackRefFileName ``"
284          << BkgTrackRefFileName << "''" << endl;}
285   if (strlen(BkgTrackRefFileName)) {
286     // BkgTrackRefFileName not empty: try to open the file
287     if (fPrintLevel >= 2) {cout << "Before File(Bkg)" << endl; gDirectory->Dump();}
288     fBkgTrackRefFile = new TFile(BkgTrackRefFileName);
289     if (fPrintLevel >= 2) {cout << "After File(Bkg)" << endl; gDirectory->Dump();}
290     if (fBkgTrackRefFile-> IsOpen()) {
291       if (fPrintLevel >= 0) {
292         cout << "Background for Track ref. hits in file: ``" << BkgTrackRefFileName
293              << "'' successfully opened" << endl;}
294     }
295     else {
296       cout << "Background for Track Ref. hits in file: " << BkgTrackRefFileName << endl;
297       cout << "NOT FOUND: EXIT" << endl;
298       exit(0); // right instruction for exit ????
299     }
300     // Arrays for "particles" and "hits"
301     fBkgTrackRefParticles = new TClonesArray("TParticle", 200);
302     // Event number to -1 for initialization
303     fBkgTrackRefEventNumber = -1;
304     // Back to the signal file:
305     // first signal event must have been loaded previously,
306     // otherwise, Segmentation violation at the next instruction
307     // How is it possible to do smething better ????
308     ((gAlice->TreeK())->GetCurrentFile())->cd();
309     if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
310   }
311   return;
312 }
313
314 //__________________________________________________________________________
315 void AliMUONEventReconstructor::NextBkgTrackRefEvent(void)
316 {
317   // Get next event in background file for track ref. hits
318   // Goes back to event number 0 when end of file is reached
319   char treeName[20];
320   if (fPrintLevel >= 0) {
321     cout << "Enter NextBkgTrackRefEvent" << endl;}
322   // Clean previous event
323   if(fBkgTrackRefTK) delete fBkgTrackRefTK;
324   fBkgTrackRefTK = NULL;
325   if(fBkgTrackRefParticles) fBkgTrackRefParticles->Clear();
326   if(fBkgTrackRefTTR) delete fBkgTrackRefTTR;
327   fBkgTrackRefTTR = NULL;
328   // Increment event number
329   fBkgTrackRefEventNumber++;
330   // Get access to Particles and Hits for event from background file
331   if (fPrintLevel >= 2) {cout << "Before cd(Bkg)" << endl; gDirectory->Dump();}
332   fBkgTrackRefFile->cd();
333   if (fPrintLevel >= 2) {cout << "After cd(Bkg)" << endl; gDirectory->Dump();}
334   // Particles: TreeK for event and branch "Particles"
335   sprintf(treeName, "TreeK%d", fBkgTrackRefEventNumber);
336   fBkgTrackRefTK = (TTree*)gDirectory->Get(treeName);
337   if (!fBkgTrackRefTK) {
338     if (fPrintLevel >= 0) {
339       cout << "Cannot find Kine Tree for background event: " <<
340         fBkgTrackRefEventNumber << endl;
341       cout << "Goes back to event 0" << endl;
342     }
343     fBkgTrackRefEventNumber = 0;
344     sprintf(treeName, "TreeK%d", fBkgTrackRefEventNumber);
345     fBkgTrackRefTK = (TTree*)gDirectory->Get(treeName);
346     if (!fBkgTrackRefTK) {
347                 AliError(Form("cannot find Kine Tree for background event: %d",fBkgTrackRefEventNumber));
348         exit(0);
349     }
350   }
351   if (fBkgTrackRefTK) 
352     fBkgTrackRefTK->SetBranchAddress("Particles", &fBkgTrackRefParticles);
353   fBkgTrackRefTK->GetEvent(0); // why event 0 ???? necessary ????
354   // Hits: TreeH for event and branch "MUON"
355   sprintf(treeName, "TreeTR%d", fBkgTrackRefEventNumber);
356   fBkgTrackRefTTR = (TTree*)gDirectory->Get(treeName);
357   if (!fBkgTrackRefTTR) {
358           AliError(Form("cannot find Hits Tree for background event: %d",fBkgTrackRefEventNumber));
359       exit(0);
360   }
361   fBkgTrackRefTTR->GetEntries(); // necessary ????
362   // Back to the signal file
363   ((gAlice->TreeK())->GetCurrentFile())->cd();
364   if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
365   return;
366 }
367
368 //__________________________________________________________________________
369 void AliMUONEventReconstructor::EventReconstruct(void)
370 {
371   // To reconstruct one event
372   if (fPrintLevel >= 1) cout << "enter EventReconstruct" << endl;
373   MakeEventToBeReconstructed();
374   MakeSegments();
375   MakeTracks();
376   if (fMUONData->IsTriggerTrackBranchesInTree()) 
377     ValidateTracksWithTrigger(); 
378
379   // Add tracks to MUON data container 
380   for(Int_t i=0; i<GetNRecTracks(); i++) {
381     AliMUONTrack * track = (AliMUONTrack*) GetRecTracksPtr()->At(i);
382     fMUONData->AddRecTrack(*track);
383   }
384
385   return;
386 }
387
388 //__________________________________________________________________________
389 void AliMUONEventReconstructor::EventReconstructTrigger(void)
390 {
391   // To reconstruct one event
392   if (fPrintLevel >= 1) cout << "enter EventReconstructTrigger" << endl;
393   MakeTriggerTracks();  
394   return;
395 }
396
397   //__________________________________________________________________________
398 void AliMUONEventReconstructor::ResetHitsForRec(void)
399 {
400   // To reset the array and the number of HitsForRec,
401   // and also the number of HitsForRec
402   // and the index of the first HitForRec per chamber
403   if (fHitsForRecPtr) fHitsForRecPtr->Clear();
404   fNHitsForRec = 0;
405   for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++)
406     fNHitsForRecPerChamber[ch] = fIndexOfFirstHitForRecPerChamber[ch] = 0;
407   return;
408 }
409
410   //__________________________________________________________________________
411 void AliMUONEventReconstructor::ResetSegments(void)
412 {
413   // To reset the TClonesArray of segments and the number of Segments
414   // for all stations
415   for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
416     if (fSegmentsPtr[st]) fSegmentsPtr[st]->Clear();
417     fNSegments[st] = 0;
418   }
419   return;
420 }
421
422   //__________________________________________________________________________
423 void AliMUONEventReconstructor::ResetTracks(void)
424 {
425   // To reset the TClonesArray of reconstructed tracks
426   if (fRecTracksPtr) fRecTracksPtr->Delete();
427   // Delete in order that the Track destructors are called,
428   // hence the space for the TClonesArray of pointers to TrackHit's is freed
429   fNRecTracks = 0;
430   return;
431 }
432
433   //__________________________________________________________________________
434 void AliMUONEventReconstructor::ResetTriggerTracks(void)
435 {
436   // To reset the TClonesArray of reconstructed trigger tracks
437     if (fRecTriggerTracksPtr) fRecTriggerTracksPtr->Delete();
438   // Delete in order that the Track destructors are called,
439   // hence the space for the TClonesArray of pointers to TrackHit's is freed
440     fNRecTriggerTracks = 0;
441   return;
442 }
443
444   //__________________________________________________________________________
445 void AliMUONEventReconstructor::ResetTrackHits(void)
446 {
447   // To reset the TClonesArray of hits on reconstructed tracks
448   if (fRecTrackHitsPtr) fRecTrackHitsPtr->Clear();
449   fNRecTrackHits = 0;
450   return;
451 }
452
453   //__________________________________________________________________________
454 void AliMUONEventReconstructor::MakeEventToBeReconstructed(void)
455 {
456   // To make the list of hits to be reconstructed,
457   // either from the track ref. hits or from the raw clusters
458   // according to the parameter set for the reconstructor
459 //   TString evfoldname = AliConfig::GetDefaultEventFolderName();//to be interfaced properly
460   
461 //   AliRunLoader* rl = AliRunLoader::GetRunLoader(evfoldname);
462 //   if (rl == 0x0)
463 //    {
464 //      Error("MakeEventToBeReconstructed",
465 //            "Can not find Run Loader in Event Folder named %s.",
466 //            evfoldname.Data());
467 //      return;
468 //    }
469 //   AliLoader* gime = rl->GetLoader("MUONLoader");
470 //   if (gime == 0x0)
471 //    {
472 //      Error("MakeEventToBeReconstructed","Can not get MUON Loader from Run Loader.");
473 //      return;
474 //    }
475   AliRunLoader *runLoader = fLoader->GetRunLoader();
476
477   if (fPrintLevel >= 1) cout << "enter MakeEventToBeReconstructed" << endl;
478   ResetHitsForRec();
479   if (fRecTrackRefHits == 1) {
480     // Reconstruction from track ref. hits
481     // Back to the signal file
482     TTree* treeTR = runLoader->TreeTR();
483     if (treeTR == 0x0)
484       {
485         Int_t retval = runLoader->LoadTrackRefs("READ");
486         if ( retval)
487           {
488             AliError("Error occured while loading hits.");
489             return;
490           }
491         treeTR = runLoader->TreeTR();
492         if (treeTR == 0x0)
493           {
494             AliError("Can not get TreeTR");
495             return;
496           }
497       }
498     
499     AddHitsForRecFromTrackRef(treeTR,1);
500     
501     // Background hits
502     AddHitsForRecFromTrackRef(fBkgTrackRefTTR,0);
503     // Sort HitsForRec in increasing order with respect to chamber number
504     SortHitsForRecWithIncreasingChamber();
505   }
506   else {
507     // Reconstruction from raw clusters
508     // AliMUON *MUON  = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
509     // Security on MUON ????
510     // TreeR assumed to be be "prepared" in calling function
511     // by "MUON->GetTreeR(nev)" ????
512     TTree *treeR = fLoader->TreeR();
513     fMUONData->SetTreeAddress("RC");
514     AddHitsForRecFromRawClusters(treeR);
515     // No sorting: it is done automatically in the previous function
516   }
517   if (fPrintLevel >= 10) {
518     cout << "end of MakeEventToBeReconstructed" << endl;
519     cout << "NHitsForRec: " << fNHitsForRec << endl;
520     for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
521       cout << "chamber(0...): " << ch
522            << "  NHitsForRec: " << fNHitsForRecPerChamber[ch]
523            << "  index(first HitForRec): " << fIndexOfFirstHitForRecPerChamber[ch]
524            << endl;
525       for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
526            hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
527            hit++) {
528         cout << "HitForRec index(0...): " << hit << endl;
529         ((*fHitsForRecPtr)[hit])->Dump();
530       }
531     }
532   }
533   return;
534 }
535
536   //__________________________________________________________________________
537 void AliMUONEventReconstructor::AddHitsForRecFromTrackRef(TTree *TTR, Int_t signal)
538 {
539   // To add to the list of hits for reconstruction
540   // the signal hits from a track reference tree TreeTR.
541   TClonesArray *listOfTrackRefs = NULL;
542   AliTrackReference *trackRef;
543   
544   Int_t track = 0;
545   if (fPrintLevel >= 2)
546     cout << "enter AddHitsForRecFromTrackRef with TTR: " << TTR << endl;
547   if (TTR == NULL) return;
548   
549   listOfTrackRefs = CleanTrackRefs(TTR);
550
551   Int_t ntracks = listOfTrackRefs->GetEntriesFast();
552
553   if (fPrintLevel >= 2)
554     cout << "ntracks: " << ntracks << endl;
555
556   for (Int_t index = 0; index < ntracks; index++) {
557     trackRef = (AliTrackReference*) listOfTrackRefs->At(index);
558     track =  trackRef->GetTrack();
559     
560     NewHitForRecFromTrackRef(trackRef,track,signal);
561   } // end of track ref.
562   
563   listOfTrackRefs->Delete();
564   delete listOfTrackRefs;
565   return;
566 }
567
568
569   //__________________________________________________________________________
570 AliMUONHitForRec* AliMUONEventReconstructor::NewHitForRecFromTrackRef(AliTrackReference* Hit, Int_t TrackNumber, Int_t Signal)
571 {
572   // To make a new hit for reconstruction from a track ref. hit pointed to by "Hit",
573   // with  the track numbered "TrackNumber",
574   // either from signal ("Signal" = 1) or background ("Signal" = 0) event.
575   // Selects hits in tracking (not trigger) chambers.
576   // Takes into account the efficiency (fEfficiency)
577   // and the smearing from resolution (fBendingResolution and fNonBendingResolution).
578   // Adds a condition on the radius between RMin and RMax
579   // to better simulate the real chambers.
580   // Returns the pointer to the new hit for reconstruction,
581   // or NULL in case of inefficiency or non tracking chamber or bad radius.
582   // No condition on at most 20 cm from a muon from a resonance
583   // like in Fortran TRACKF_STAT.
584   AliMUONHitForRec* hitForRec;
585   Double_t bendCoor, nonBendCoor, radius;
586   Int_t chamber = AliMUONConstants::ChamberNumber(Hit->Z()); // chamber(0...)
587   if (chamber < 0) return NULL;
588   // only in tracking chambers (fChamber starts at 1)
589   if (chamber >= fgkMaxMuonTrackingChambers) return NULL;
590   // only if hit is efficient (keep track for checking ????)
591   if (gRandom->Rndm() > fEfficiency) return NULL;
592   // only if radius between RMin and RMax
593   bendCoor = Hit->Y();
594   nonBendCoor = Hit->X();
595   radius = TMath::Sqrt((bendCoor * bendCoor) + (nonBendCoor * nonBendCoor));
596   // This cut is not needed with a realistic chamber geometry !!!!
597 //   if ((radius < fRMin[chamber]) || (radius > fRMax[chamber])) return NULL;
598   // new AliMUONHitForRec from track ref. hit and increment number of AliMUONHitForRec's
599   hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(Hit);
600   fNHitsForRec++;
601   // add smearing from resolution
602   hitForRec->SetBendingCoor(bendCoor + gRandom->Gaus(0., fBendingResolution));
603   hitForRec->SetNonBendingCoor(nonBendCoor
604                                + gRandom->Gaus(0., fNonBendingResolution));
605 //   // !!!! without smearing
606 //   hitForRec->SetBendingCoor(bendCoor);
607 //   hitForRec->SetNonBendingCoor(nonBendCoor);
608   // more information into HitForRec
609   //  resolution: angular effect to be added here ????
610   hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
611   hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
612   //   track ref. info
613   hitForRec->SetTTRTrack(TrackNumber);
614   hitForRec->SetTrackRefSignal(Signal);
615   if (fPrintLevel >= 10) {
616     cout << "track: " << TrackNumber << endl;
617     Hit->Dump();
618     cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
619     hitForRec->Dump();}
620   return hitForRec;
621 }
622   //__________________________________________________________________________
623 TClonesArray* AliMUONEventReconstructor::CleanTrackRefs(TTree *treeTR)
624 {
625   // Make hits from track ref..  
626   // Re-calculate hits parameters because two AliTrackReferences are recorded for
627   // each chamber (one when particle is entering + one when particle is leaving 
628   // the sensitive volume) 
629  
630   AliTrackReference *trackReference;
631   Float_t x1, y1, z1, pX1, pY1, pZ1;
632   Float_t x2, y2, z2, pX2, pY2, pZ2;
633   Int_t track1, track2;
634   Int_t nRec = 0;
635   Float_t maxGasGap = 1.; // cm 
636   Int_t iHit1 = 0;
637   Int_t iHitMin = 0;
638  
639   AliTrackReference *trackReferenceNew = new AliTrackReference();
640   
641   TClonesArray* trackRefs = new TClonesArray("AliTrackReference", 10);
642   TClonesArray* cleanTrackRefs = new TClonesArray("AliTrackReference", 10);
643
644   if (treeTR == NULL) return NULL;
645   TBranch* branch = treeTR->GetBranch("MUON");
646   if (branch == NULL) return NULL;
647   branch->SetAddress(&trackRefs);
648
649   Int_t nTrack = (Int_t)treeTR->GetEntries();
650   for (Int_t iTrack  = 0; iTrack < nTrack; iTrack++) {
651     treeTR->GetEntry(iTrack);
652     iHitMin = 0;
653     iHit1 = 0;
654     while (iHit1 < trackRefs->GetEntries()) {
655       trackReference = (AliTrackReference*)trackRefs->At(iHit1);
656       x1 = trackReference->X();
657       y1 = trackReference->Y();
658       z1 = trackReference->Z();
659       pX1 = trackReference->Px();
660       pY1 = trackReference->Py();
661       pZ1 = trackReference->Pz();
662       track1 = trackReference->GetTrack();
663       nRec = 1;
664       iHitMin = iHit1+1;
665       for (Int_t iHit2 = iHit1+1; iHit2 < trackRefs->GetEntries(); iHit2++) {
666         trackReference = (AliTrackReference*)trackRefs->At(iHit2);
667         x2 = trackReference->X();
668         y2 = trackReference->Y();
669         z2 = trackReference->Z();
670         pX2 = trackReference->Px();
671         pY2 = trackReference->Py();
672         pZ2 = trackReference->Pz();
673         track2 = trackReference->GetTrack();
674         if (track2 == track1 && TMath::Abs(z2-z1) < maxGasGap ) {
675           nRec++;
676           x1 += x2;
677           y1 += y2;
678           z1 += z2;                             
679           pX1 += pX2;
680           pY1 += pY2;
681           pZ1 += pZ2;
682           iHitMin = iHit2+1;
683         }
684         
685       } // for iHit2
686       x1 /= (Float_t)nRec;
687       y1 /= (Float_t)nRec;
688       z1 /= (Float_t)nRec;
689       pX1 /= (Float_t)nRec;
690       pY1 /= (Float_t)nRec;
691       pZ1 /= (Float_t)nRec;
692       trackReferenceNew->SetPosition(x1,y1,z1);
693       trackReferenceNew->SetMomentum(pX1,pY1,pZ1);
694       trackReferenceNew->SetTrack(track1);
695       {new ((*cleanTrackRefs)[cleanTrackRefs->GetEntriesFast()]) AliTrackReference(*trackReferenceNew);}       
696       iHit1 = iHitMin;
697     } // while iHit1
698   } // for track
699
700   trackRefs->Delete();
701   delete trackRefs;
702   delete trackReferenceNew;
703   return cleanTrackRefs;
704  
705 }
706   //__________________________________________________________________________
707 void AliMUONEventReconstructor::SortHitsForRecWithIncreasingChamber()
708 {
709   // Sort HitsForRec's in increasing order with respect to chamber number.
710   // Uses the function "Compare".
711   // Update the information for HitsForRec per chamber too.
712   Int_t ch, nhits, prevch;
713   fHitsForRecPtr->Sort();
714   for (ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
715     fNHitsForRecPerChamber[ch] = 0;
716     fIndexOfFirstHitForRecPerChamber[ch] = 0;
717   }
718   prevch = 0; // previous chamber
719   nhits = 0; // number of hits in current chamber
720   // Loop over HitsForRec
721   for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
722     // chamber number (0...)
723     ch = ((AliMUONHitForRec*)  ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
724     // increment number of hits in current chamber
725     (fNHitsForRecPerChamber[ch])++;
726     // update index of first HitForRec in current chamber
727     // if chamber number different from previous one
728     if (ch != prevch) {
729       fIndexOfFirstHitForRecPerChamber[ch] = hit;
730       prevch = ch;
731     }
732   }
733   return;
734 }
735
736 //   //__________________________________________________________________________
737 // void AliMUONEventReconstructor::AddHitsForRecFromCathodeCorrelations(TTree* TC)
738 // {
739 //   // OLD VERSION WHEN ONE ONE WAS USING SO CALLED CATHODE CORRELATIONS
740 //   // To add to the list of hits for reconstruction
741 //   // the (cathode correlated) raw clusters
742 //   // No condition added, like in Fortran TRACKF_STAT,
743 //   // on the radius between RMin and RMax.
744 //   AliMUONHitForRec *hitForRec;
745 //   if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromCathodeCorrelations" << endl;
746 //   AliMUON *MUON  = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
747 //   // Security on MUON ????
748 //   // Loop over tracking chambers
749 //   for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
750 //     // number of HitsForRec to 0 for the chamber
751 //     fNHitsForRecPerChamber[ch] = 0;
752 //     // index of first HitForRec for the chamber
753 //     if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
754 //     else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
755 //     TClonesArray *reconst_hits  = MUON->ReconstHitsAddress(ch);
756 //     MUON->ResetReconstHits();
757 //     TC->GetEvent();
758 //     Int_t ncor = (Int_t)reconst_hits->GetEntries();
759 //     // Loop over (cathode correlated) raw clusters
760 //     for (Int_t cor = 0; cor < ncor; cor++) {
761 //       AliMUONReconstHit * mCor = 
762 //      (AliMUONReconstHit*) reconst_hits->UncheckedAt(cor);
763 //       // new AliMUONHitForRec from (cathode correlated) raw cluster
764 //       // and increment number of AliMUONHitForRec's (total and in chamber)
765 //       hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(mCor);
766 //       fNHitsForRec++;
767 //       (fNHitsForRecPerChamber[ch])++;
768 //       // more information into HitForRec
769 //       hitForRec->SetChamberNumber(ch);
770 //       hitForRec->SetHitNumber(cor);
771 //       // Z coordinate of the chamber (cm) with sign opposite to TRACKREF sign
772 //       // could (should) be more exact from chamber geometry ???? 
773 //       hitForRec->SetZ(-(&(MUON->Chamber(ch)))->Z());
774 //       if (fPrintLevel >= 10) {
775 //      cout << "chamber (0...): " << ch <<
776 //        " cathcorrel (0...): " << cor << endl;
777 //      mCor->Dump();
778 //      cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
779 //      hitForRec->Dump();}
780 //     } // end of cluster loop
781 //   } // end of chamber loop
782 //   return;
783 // }
784
785   //__________________________________________________________________________
786 void AliMUONEventReconstructor::AddHitsForRecFromRawClusters(TTree* TR)
787 {
788   // To add to the list of hits for reconstruction all the raw clusters
789   // No condition added, like in Fortran TRACKF_STAT,
790   // on the radius between RMin and RMax.
791   AliMUONHitForRec *hitForRec;
792   AliMUONRawCluster *clus;
793   Int_t iclus, nclus, nTRentries;
794   TClonesArray *rawclusters;
795   if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromRawClusters" << endl;
796
797 //   TString evfoldname = AliConfig::GetDefaultEventFolderName();//to be interfaced properly
798 //   AliRunLoader* rl = AliRunLoader::GetRunLoader(evfoldname);
799 //   if (rl == 0x0)
800 //    {
801 //      Error("MakeEventToBeReconstructed",
802 //            "Can not find Run Loader in Event Folder named %s.",
803 //            evfoldname.Data());
804 //      return;
805 //    }
806 //   AliLoader* gime = rl->GetLoader("MUONLoader");
807 //   if (gime == 0x0)
808 //    {
809 //      Error("MakeEventToBeReconstructed","Can not get MUON Loader from Run Loader.");
810 //      return;
811 //    }
812 //    // Loading AliRun master
813 //   rl->LoadgAlice();
814 //   gAlice = rl->GetAliRun();
815
816   // Loading MUON subsystem
817   //  AliMUON * pMUON = (AliMUON *) gAlice->GetDetector("MUON");
818
819   nTRentries = Int_t(TR->GetEntries());
820   if (nTRentries != 1) {
821     AliError(Form("nTRentries = %d not equal to 1 ",nTRentries));
822     exit(0);
823   }
824   fLoader->TreeR()->GetEvent(0); // only one entry  
825
826   // Loop over tracking chambers
827   for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
828     // number of HitsForRec to 0 for the chamber
829     fNHitsForRecPerChamber[ch] = 0;
830     // index of first HitForRec for the chamber
831     if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
832     else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
833     rawclusters =fMUONData->RawClusters(ch);
834 //     pMUON->ResetRawClusters();
835 //     TR->GetEvent((Int_t) (TR->GetEntries()) - 1); // to be checked ????
836     nclus = (Int_t) (rawclusters->GetEntries());
837     // Loop over (cathode correlated) raw clusters
838     for (iclus = 0; iclus < nclus; iclus++) {
839       clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
840       // new AliMUONHitForRec from raw cluster
841       // and increment number of AliMUONHitForRec's (total and in chamber)
842       hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
843       fNHitsForRec++;
844       (fNHitsForRecPerChamber[ch])++;
845       // more information into HitForRec
846       //  resolution: info should be already in raw cluster and taken from it ????
847       hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
848       hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
849       //  original raw cluster
850       hitForRec->SetChamberNumber(ch);
851       hitForRec->SetHitNumber(iclus);
852       // Z coordinate of the raw cluster (cm)
853       hitForRec->SetZ(clus->GetZ(0));
854       if (fPrintLevel >= 10) {
855         cout << "chamber (0...): " << ch <<
856           " raw cluster (0...): " << iclus << endl;
857         clus->Dump();
858         cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
859         hitForRec->Dump();}
860     } // end of cluster loop
861   } // end of chamber loop
862   SortHitsForRecWithIncreasingChamber(); //AZ 
863   return;
864 }
865
866   //__________________________________________________________________________
867 void AliMUONEventReconstructor::MakeSegments(void)
868 {
869   // To make the list of segments in all stations,
870   // from the list of hits to be reconstructed
871   if (fPrintLevel >= 1) cout << "enter MakeSegments" << endl;
872   ResetSegments();
873   // Loop over stations
874   Int_t nb = (fTrackMethod == 2) ? 3 : 0; //AZ
875   //AZ for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
876   for (Int_t st = nb; st < fgkMaxMuonTrackingStations; st++) //AZ
877     MakeSegmentsPerStation(st); 
878   if (fPrintLevel >= 10) {
879     cout << "end of MakeSegments" << endl;
880     for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
881       cout << "station(0...): " << st
882            << "  Segments: " << fNSegments[st]
883            << endl;
884       for (Int_t seg = 0;
885            seg < fNSegments[st];
886            seg++) {
887         cout << "Segment index(0...): " << seg << endl;
888         ((*fSegmentsPtr[st])[seg])->Dump();
889       }
890     }
891   }
892   return;
893 }
894
895   //__________________________________________________________________________
896 void AliMUONEventReconstructor::MakeSegmentsPerStation(Int_t Station)
897 {
898   // To make the list of segments in station number "Station" (0...)
899   // from the list of hits to be reconstructed.
900   // Updates "fNSegments"[Station].
901   // Segments in stations 4 and 5 are sorted
902   // according to increasing absolute value of "impact parameter"
903   AliMUONHitForRec *hit1Ptr, *hit2Ptr;
904   AliMUONSegment *segment;
905   Bool_t last2st;
906   Double_t bendingSlope, distBend, distNonBend, extBendCoor, extNonBendCoor,
907       impactParam = 0., maxImpactParam = 0., minImpactParam = 0.; // =0 to avoid compilation warnings.
908   if (fPrintLevel >= 1)
909     cout << "enter MakeSegmentsPerStation (0...) " << Station << endl;
910   // first and second chambers (0...) in the station
911   Int_t ch1 = 2 * Station;
912   Int_t ch2 = ch1 + 1;
913   // variable true for stations downstream of the dipole:
914   // Station(0..4) equal to 3 or 4
915   if ((Station == 3) || (Station == 4)) {
916     last2st = kTRUE;
917     // maximum impact parameter (cm) according to fMinBendingMomentum...
918     maxImpactParam =
919       TMath::Abs(GetImpactParamFromBendingMomentum(fMinBendingMomentum));
920     // minimum impact parameter (cm) according to fMaxBendingMomentum...
921     minImpactParam =
922       TMath::Abs(GetImpactParamFromBendingMomentum(fMaxBendingMomentum));
923   }
924   else last2st = kFALSE;
925   // extrapolation factor from Z of first chamber to Z of second chamber
926   // dZ to be changed to take into account fine structure of chambers ????
927   Double_t extrapFact;
928   // index for current segment
929   Int_t segmentIndex = 0;
930   // Loop over HitsForRec in the first chamber of the station
931   for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
932        hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
933        hit1++) {
934     // pointer to the HitForRec
935     hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
936     // extrapolation,
937     // on the straight line joining the HitForRec to the vertex (0,0,0),
938     // to the Z of the second chamber of the station
939     // Loop over HitsForRec in the second chamber of the station
940     for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
941          hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
942          hit2++) {
943       // pointer to the HitForRec
944       hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
945       // absolute values of distances, in bending and non bending planes,
946       // between the HitForRec in the second chamber
947       // and the previous extrapolation
948       extrapFact = hit2Ptr->GetZ()/ hit1Ptr->GetZ();
949       extBendCoor = extrapFact * hit1Ptr->GetBendingCoor();
950       extNonBendCoor = extrapFact * hit1Ptr->GetNonBendingCoor();
951       distBend = TMath::Abs(hit2Ptr->GetBendingCoor() - extBendCoor);
952       distNonBend = TMath::Abs(hit2Ptr->GetNonBendingCoor() - extNonBendCoor);
953       if (last2st) {
954         // bending slope
955         bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) /
956           (hit1Ptr->GetZ() - hit2Ptr->GetZ());
957         // absolute value of impact parameter
958         impactParam =
959           TMath::Abs(hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope);
960       }
961       // check for distances not too large,
962       // and impact parameter not too big if stations downstream of the dipole.
963       // Conditions "distBend" and "impactParam" correlated for these stations ????
964       if ((distBend < fSegmentMaxDistBending[Station]) &&
965           (distNonBend < fSegmentMaxDistNonBending[Station]) &&
966           (!last2st || (impactParam < maxImpactParam)) &&
967           (!last2st || (impactParam > minImpactParam))) {
968         // make new segment
969         segment = new ((*fSegmentsPtr[Station])[segmentIndex])
970           AliMUONSegment(hit1Ptr, hit2Ptr);
971         // update "link" to this segment from the hit in the first chamber
972         if (hit1Ptr->GetNSegments() == 0)
973           hit1Ptr->SetIndexOfFirstSegment(segmentIndex);
974         hit1Ptr->SetNSegments(hit1Ptr->GetNSegments() + 1);
975         if (fPrintLevel >= 10) {
976           cout << "segmentIndex(0...): " << segmentIndex
977                << "  distBend: " << distBend
978                << "  distNonBend: " << distNonBend
979                << endl;
980           segment->Dump();
981           cout << "HitForRec in first chamber" << endl;
982           hit1Ptr->Dump();
983           cout << "HitForRec in second chamber" << endl;
984           hit2Ptr->Dump();
985         };
986         // increment index for current segment
987         segmentIndex++;
988       }
989     } //for (Int_t hit2
990   } // for (Int_t hit1...
991   fNSegments[Station] = segmentIndex;
992   // Sorting according to "impact parameter" if station(1..5) 4 or 5,
993   // i.e. Station(0..4) 3 or 4, using the function "Compare".
994   // After this sorting, it is impossible to use
995   // the "fNSegments" and "fIndexOfFirstSegment"
996   // of the HitForRec in the first chamber to explore all segments formed with it.
997   // Is this sorting really needed ????
998   if ((Station == 3) || (Station == 4)) (fSegmentsPtr[Station])->Sort();
999   if (fPrintLevel >= 1) cout << "Station: " << Station << "  NSegments: "
1000                              << fNSegments[Station] << endl;
1001   return;
1002 }
1003
1004   //__________________________________________________________________________
1005 void AliMUONEventReconstructor::MakeTracks(void)
1006 {
1007   // To make the tracks,
1008   // from the list of segments and points in all stations
1009   if (fPrintLevel >= 1) cout << "enter MakeTracks" << endl;
1010   // The order may be important for the following Reset's
1011   ResetTracks();
1012   ResetTrackHits();
1013   if (fTrackMethod == 2) { //AZ - Kalman filter
1014     MakeTrackCandidatesK();
1015     if (fRecTracksPtr->GetEntriesFast() == 0) return;
1016     // Follow tracks in stations(1..) 3, 2 and 1
1017     FollowTracksK();
1018     // Remove double tracks
1019     RemoveDoubleTracksK();
1020     // Propagate tracks to the vertex thru absorber
1021     GoToVertex();
1022     // Fill AliMUONTrack data members
1023     FillMUONTrack();
1024   } else { 
1025     // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
1026     MakeTrackCandidates();
1027     // Follow tracks in stations(1..) 3, 2 and 1
1028     FollowTracks();
1029     // Remove double tracks
1030     RemoveDoubleTracks();
1031     UpdateTrackParamAtHit();
1032     UpdateHitForRecAtHit();
1033   }
1034   return;
1035 }
1036
1037   //__________________________________________________________________________
1038 void AliMUONEventReconstructor::ValidateTracksWithTrigger(void)
1039 {
1040   // Try to match track from tracking system with trigger track
1041   AliMUONTrack *track;
1042   TClonesArray *recTriggerTracks;
1043   
1044   fMUONData->ResetRecTriggerTracks();
1045   fMUONData->SetTreeAddress("RL");
1046   fMUONData->GetRecTriggerTracks();
1047   recTriggerTracks = fMUONData->RecTriggerTracks();
1048
1049   track = (AliMUONTrack*) fRecTracksPtr->First();
1050   while (track) {
1051     track->MatchTriggerTrack(recTriggerTracks);
1052     track = (AliMUONTrack*) fRecTracksPtr->After(track);
1053   }
1054
1055 }
1056
1057   //__________________________________________________________________________
1058 Bool_t AliMUONEventReconstructor::MakeTriggerTracks(void)
1059 {
1060     // To make the trigger tracks from Local Trigger
1061     if (fPrintLevel >= 1) cout << "enter MakeTriggerTracks" << endl;
1062     //    ResetTriggerTracks();
1063     
1064     Int_t nTRentries;
1065     Long_t gloTrigPat;
1066     TClonesArray *localTrigger;
1067     TClonesArray *globalTrigger;
1068     AliMUONLocalTrigger *locTrg;
1069     AliMUONGlobalTrigger *gloTrg;
1070     AliMUONTriggerCircuit *circuit;
1071     AliMUONTriggerTrack *recTriggerTrack = 0;
1072
1073     TTree* treeR = fLoader->TreeR();
1074     
1075     // Loading MUON subsystem
1076     AliMUON * pMUON = (AliMUON *) gAlice->GetDetector("MUON");
1077     
1078     nTRentries = Int_t(treeR->GetEntries());
1079      
1080     treeR->GetEvent(0); // only one entry  
1081
1082     if (!(fMUONData->IsTriggerBranchesInTree())) {
1083       AliWarning(Form("Trigger information is not avalaible, nTRentries = %d not equal to 1",nTRentries));
1084       return kFALSE;
1085     }
1086
1087     fMUONData->SetTreeAddress("TC");
1088     fMUONData->GetTrigger();
1089
1090     // global trigger for trigger pattern
1091     gloTrigPat = 0;
1092     globalTrigger = fMUONData->GlobalTrigger(); 
1093     gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);      
1094     if (gloTrg) {
1095       if (gloTrg->SinglePlusLpt())  gloTrigPat|= 0x1;
1096       if (gloTrg->SinglePlusHpt())  gloTrigPat|= 0x2;
1097       if (gloTrg->SinglePlusApt())  gloTrigPat|= 0x4;
1098       
1099       if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
1100       if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
1101       if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
1102       
1103       if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
1104       if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
1105       if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
1106       
1107       if (gloTrg->PairUnlikeLpt())  gloTrigPat|= 0x200;
1108       if (gloTrg->PairUnlikeHpt())  gloTrigPat|= 0x400;
1109       if (gloTrg->PairUnlikeApt())  gloTrigPat|= 0x800;
1110       
1111       if (gloTrg->PairLikeLpt())    gloTrigPat|= 0x1000;
1112       if (gloTrg->PairLikeHpt())    gloTrigPat|= 0x2000;
1113       if (gloTrg->PairLikeApt())    gloTrigPat|= 0x4000;
1114     }
1115
1116  
1117
1118     // local trigger for tracking 
1119     localTrigger = fMUONData->LocalTrigger();    
1120     Int_t nlocals = (Int_t) (localTrigger->GetEntries());
1121     Float_t z11 = ( &(pMUON->Chamber(10)) )->Z();
1122     Float_t z21 = ( &(pMUON->Chamber(12)) )->Z();
1123
1124     for (Int_t i=0; i<nlocals; i++) { // loop on Local Trigger
1125       locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(i);      
1126       circuit = &(pMUON->TriggerCircuit(locTrg->LoCircuit()));
1127       Float_t y11 = circuit->GetY11Pos(locTrg->LoStripX()); 
1128       Int_t stripX21 = locTrg->LoStripX()+locTrg->LoDev()+1;
1129       Float_t y21 = circuit->GetY21Pos(stripX21);       
1130       Float_t x11 = circuit->GetX11Pos(locTrg->LoStripY());
1131       Float_t thetax = TMath::ATan2( x11 , z11 );
1132       Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
1133
1134       recTriggerTrack = new AliMUONTriggerTrack(x11,y11,thetax,thetay,gloTrigPat,this);
1135       // since static statement does not work, set gloTrigPat for each track
1136
1137       //        fNRecTriggerTracks++;
1138       fMUONData->AddRecTriggerTrack(*recTriggerTrack);
1139     } // end of loop on Local Trigger
1140     return kTRUE;    
1141 }
1142
1143   //__________________________________________________________________________
1144 Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithTwoSegments(AliMUONSegment *BegSegment)
1145 {
1146   // To make track candidates with two segments in stations(1..) 4 and 5,
1147   // the first segment being pointed to by "BegSegment".
1148   // Returns the number of such track candidates.
1149   Int_t endStation, iEndSegment, nbCan2Seg;
1150   AliMUONSegment *endSegment;
1151   AliMUONSegment *extrapSegment = NULL;
1152   AliMUONTrack *recTrack;
1153   Double_t mcsFactor;
1154   if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesWithTwoSegments" << endl;
1155   // Station for the end segment
1156   endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
1157   // multiple scattering factor corresponding to one chamber
1158   mcsFactor = 0.0136 /
1159     GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
1160   mcsFactor     = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1161   // linear extrapolation to end station
1162   // number of candidates with 2 segments to 0
1163   nbCan2Seg = 0;
1164   // Loop over segments in the end station
1165   for (iEndSegment = 0; iEndSegment < fNSegments[endStation]; iEndSegment++) {
1166     // pointer to segment
1167     endSegment = (AliMUONSegment*) ((*fSegmentsPtr[endStation])[iEndSegment]);
1168     // test compatibility between current segment and "extrapSegment"
1169     // 4 because 4 quantities in chi2
1170     extrapSegment =
1171       BegSegment->CreateSegmentFromLinearExtrapToStation(endSegment->GetZ(), mcsFactor);
1172     if ((endSegment->
1173          NormalizedChi2WithSegment(extrapSegment,
1174                                    fMaxSigma2Distance)) <= 4.0) {
1175       // both segments compatible:
1176       // make track candidate from "begSegment" and "endSegment"
1177       if (fPrintLevel >= 2)
1178         cout << "TrackCandidate with Segment " << iEndSegment <<
1179           " in Station(0..) " << endStation << endl;
1180       // flag for both segments in one track:
1181       // to be done in track constructor ????
1182       BegSegment->SetInTrack(kTRUE);
1183       endSegment->SetInTrack(kTRUE);
1184       recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1185         AliMUONTrack(BegSegment, endSegment, this);
1186       fNRecTracks++;
1187       if (fPrintLevel >= 10) recTrack->RecursiveDump();
1188       // increment number of track candidates with 2 segments
1189       nbCan2Seg++;
1190     }
1191   } // for (iEndSegment = 0;...
1192   delete extrapSegment; // should not delete HitForRec's it points to !!!!
1193   return nbCan2Seg;
1194 }
1195
1196   //__________________________________________________________________________
1197 Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithOneSegmentAndOnePoint(AliMUONSegment *BegSegment)
1198 {
1199   // To make track candidates with one segment and one point
1200   // in stations(1..) 4 and 5,
1201   // the segment being pointed to by "BegSegment".
1202   Int_t ch, ch1, ch2, endStation, iHit, iHitMax, iHitMin, nbCan1Seg1Hit;
1203   AliMUONHitForRec *extrapHitForRec= NULL;
1204   AliMUONHitForRec *hit;
1205   AliMUONTrack *recTrack;
1206   Double_t mcsFactor;
1207   if (fPrintLevel >= 1)
1208     cout << "enter MakeTrackCandidatesWithOneSegmentAndOnePoint" << endl;
1209   // station for the end point
1210   endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
1211   // multiple scattering factor corresponding to one chamber
1212   mcsFactor = 0.0136 /
1213     GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
1214   mcsFactor     = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1215   // first and second chambers(0..) in the end station
1216   ch1 = 2 * endStation;
1217   ch2 = ch1 + 1;
1218   // number of candidates to 0
1219   nbCan1Seg1Hit = 0;
1220   // Loop over chambers of the end station
1221   for (ch = ch2; ch >= ch1; ch--) {
1222     // limits for the hit index in the loop
1223     iHitMin = fIndexOfFirstHitForRecPerChamber[ch];
1224     iHitMax = iHitMin + fNHitsForRecPerChamber[ch];
1225     // Loop over HitForRec's in the chamber
1226     for (iHit = iHitMin; iHit < iHitMax; iHit++) {
1227       // pointer to HitForRec
1228       hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
1229       // test compatibility between current HitForRec and "extrapHitForRec"
1230       // 2 because 2 quantities in chi2
1231       // linear extrapolation to chamber
1232       extrapHitForRec =
1233         BegSegment->CreateHitForRecFromLinearExtrapToChamber( hit->GetZ(), mcsFactor);
1234       if ((hit->
1235            NormalizedChi2WithHitForRec(extrapHitForRec,
1236                                        fMaxSigma2Distance)) <= 2.0) {
1237         // both HitForRec's compatible:
1238         // make track candidate from begSegment and current HitForRec
1239         if (fPrintLevel >= 2)
1240           cout << "TrackCandidate with HitForRec " << iHit <<
1241             " in Chamber(0..) " << ch << endl;
1242         // flag for beginning segments in one track:
1243         // to be done in track constructor ????
1244         BegSegment->SetInTrack(kTRUE);
1245         recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1246           AliMUONTrack(BegSegment, hit, this);
1247         // the right place to eliminate "double counting" ???? how ????
1248         fNRecTracks++;
1249         if (fPrintLevel >= 10) recTrack->RecursiveDump();
1250         // increment number of track candidates
1251         nbCan1Seg1Hit++;
1252       }
1253     } // for (iHit = iHitMin;...
1254     delete extrapHitForRec;
1255     extrapHitForRec = NULL;
1256   } // for (ch = ch2;...
1257   return nbCan1Seg1Hit;
1258 }
1259
1260   //__________________________________________________________________________
1261 void AliMUONEventReconstructor::MakeTrackCandidates(void)
1262 {
1263   // To make track candidates
1264   // with at least 3 aligned points in stations(1..) 4 and 5
1265   // (two Segment's or one Segment and one HitForRec)
1266   Int_t begStation, iBegSegment, nbCan1Seg1Hit, nbCan2Seg;
1267   AliMUONSegment *begSegment;
1268   if (fPrintLevel >= 1) cout << "enter MakeTrackCandidates" << endl;
1269   // Loop over stations(1..) 5 and 4 for the beginning segment
1270   for (begStation = 4; begStation > 2; begStation--) {
1271     // Loop over segments in the beginning station
1272     for (iBegSegment = 0; iBegSegment < fNSegments[begStation]; iBegSegment++) {
1273       // pointer to segment
1274       begSegment = (AliMUONSegment*) ((*fSegmentsPtr[begStation])[iBegSegment]);
1275       if (fPrintLevel >= 2)
1276         cout << "look for TrackCandidate's with Segment " << iBegSegment <<
1277           " in Station(0..) " << begStation << endl;
1278       // Look for track candidates with two segments,
1279       // "begSegment" and all compatible segments in other station.
1280       // Only for beginning station(1..) 5
1281       // because candidates with 2 segments have to looked for only once.
1282       if (begStation == 4)
1283         nbCan2Seg = MakeTrackCandidatesWithTwoSegments(begSegment);
1284       // Look for track candidates with one segment and one point,
1285       // "begSegment" and all compatible HitForRec's in other station.
1286       // Only if "begSegment" does not belong already to a track candidate.
1287       // Is that a too strong condition ????
1288       if (!(begSegment->GetInTrack()))
1289         nbCan1Seg1Hit = MakeTrackCandidatesWithOneSegmentAndOnePoint(begSegment);
1290     } // for (iBegSegment = 0;...
1291   } // for (begStation = 4;...
1292   return;
1293 }
1294
1295   //__________________________________________________________________________
1296 void AliMUONEventReconstructor::FollowTracks(void)
1297 {
1298   // Follow tracks in stations(1..) 3, 2 and 1
1299   // too long: should be made more modular !!!!
1300   AliMUONHitForRec *bestHit, *extrapHit, *hit;
1301   AliMUONSegment *bestSegment, *extrapSegment, *segment;
1302   AliMUONTrack *track, *nextTrack;
1303   AliMUONTrackParam *trackParam1, trackParam[2], trackParamVertex;
1304   // -1 to avoid compilation warnings
1305   Int_t ch = -1, chInStation, chBestHit = -1, iHit, iSegment, station, trackIndex; 
1306   Double_t bestChi2, chi2, dZ1, dZ2, dZ3, maxSigma2Distance, mcsFactor;
1307   Double_t bendingMomentum, chi2Norm = 0.;
1308   AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
1309   // local maxSigma2Distance, for easy increase in testing
1310   maxSigma2Distance = fMaxSigma2Distance;
1311   if (fPrintLevel >= 2)
1312     cout << "enter FollowTracks" << endl;
1313   // Loop over track candidates
1314   track = (AliMUONTrack*) fRecTracksPtr->First();
1315   trackIndex = -1;
1316   while (track) {
1317     // Follow function for each track candidate ????
1318     trackIndex++;
1319     nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
1320     if (fPrintLevel >= 2)
1321       cout << "FollowTracks: track candidate(0..): " << trackIndex << endl;
1322     // Fit track candidate
1323     track->SetFitMCS(0); // without multiple Coulomb scattering
1324     track->SetFitNParam(3); // with 3 parameters (X = Y = 0)
1325     track->SetFitStart(0); // from parameters at vertex
1326     track->Fit();
1327     if (fPrintLevel >= 10) {
1328       cout << "FollowTracks: track candidate(0..): " << trackIndex
1329            << " after fit in stations(0..) 3 and 4" << endl;
1330       track->RecursiveDump();
1331     }
1332     // Loop over stations(1..) 3, 2 and 1
1333     // something SPECIAL for stations 2 and 1 for majority 3 coincidence ????
1334     // otherwise: majority coincidence 2 !!!!
1335     for (station = 2; station >= 0; station--) {
1336       // Track parameters at first track hit (smallest Z)
1337       trackParam1 = ((AliMUONTrackHit*)
1338                      (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1339       // extrapolation to station
1340       trackParam1->ExtrapToStation(station, trackParam);
1341       extrapSegment = new AliMUONSegment(); //  empty segment
1342       // multiple scattering factor corresponding to one chamber
1343       // and momentum in bending plane (not total)
1344       mcsFactor = 0.0136 * trackParam1->GetInverseBendingMomentum();
1345       mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1346       // Z difference from previous station
1347       dZ1 = (&(pMUON->Chamber(2 * station)))->Z() -
1348         (&(pMUON->Chamber(2 * station + 2)))->Z();
1349       // Z difference between the two previous stations
1350       dZ2 = (&(pMUON->Chamber(2 * station + 2)))->Z() -
1351         (&(pMUON->Chamber(2 * station + 4)))->Z();
1352       // Z difference between the two chambers in the previous station
1353       dZ3 = (&(pMUON->Chamber(2 * station)))->Z() -
1354         (&(pMUON->Chamber(2 * station + 1)))->Z();
1355       extrapSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1356       extrapSegment->
1357         SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1358       extrapSegment->UpdateFromStationTrackParam
1359         (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1360          trackParam1->GetInverseBendingMomentum());
1361       bestChi2 = 5.0;
1362       bestSegment = NULL;
1363       if (fPrintLevel >= 10) {
1364         cout << "FollowTracks: track candidate(0..): " << trackIndex
1365              << " Look for segment in station(0..): " << station << endl;
1366       }
1367       // Loop over segments in station
1368       for (iSegment = 0; iSegment < fNSegments[station]; iSegment++) {
1369         // Look for best compatible Segment in station
1370         // should consider all possibilities ????
1371         // multiple scattering ????
1372         // separation in 2 functions: Segment and HitForRec ????
1373         segment = (AliMUONSegment*) ((*fSegmentsPtr[station])[iSegment]);
1374         // correction of corrected segment (fBendingCoor and fNonBendingCoor)
1375         // according to real Z value of "segment" and slopes of "extrapSegment"
1376         (&(trackParam[0]))->ExtrapToZ(segment->GetZ());
1377         (&(trackParam[1]))->ExtrapToZ(segment->GetZ());
1378         extrapSegment->SetBendingCoor((&(trackParam[0]))->GetBendingCoor());
1379         extrapSegment->SetNonBendingCoor((&(trackParam[0]))->GetNonBendingCoor());
1380         extrapSegment->SetBendingSlope((&(trackParam[0]))->GetBendingSlope());
1381         extrapSegment->SetNonBendingSlope((&(trackParam[0]))->GetNonBendingSlope());
1382         chi2 = segment->
1383           NormalizedChi2WithSegment(extrapSegment, maxSigma2Distance);
1384         if (chi2 < bestChi2) {
1385           // update best Chi2 and Segment if better found
1386           bestSegment = segment;
1387           bestChi2 = chi2;
1388         }
1389       }
1390       if (bestSegment) {
1391         // best segment found: add it to track candidate
1392         (&(trackParam[0]))->ExtrapToZ(bestSegment->GetZ());
1393         (&(trackParam[1]))->ExtrapToZ(bestSegment->GetZ());
1394         track->AddSegment(bestSegment);
1395         // set track parameters at these two TrakHit's
1396         track->SetTrackParamAtHit(track->GetNTrackHits() - 2, &(trackParam[0]));
1397         track->SetTrackParamAtHit(track->GetNTrackHits() - 1, &(trackParam[1]));
1398         if (fPrintLevel >= 10) {
1399           cout << "FollowTracks: track candidate(0..): " << trackIndex
1400                << " Added segment in station(0..): " << station << endl;
1401           track->RecursiveDump();
1402         }
1403       }
1404       else {
1405         // No best segment found:
1406         // Look for best compatible HitForRec in station:
1407         // should consider all possibilities ????
1408         // multiple scattering ???? do about like for extrapSegment !!!!
1409         extrapHit = new AliMUONHitForRec(); //  empty hit
1410         bestChi2 = 3.0;
1411         bestHit = NULL;
1412         if (fPrintLevel >= 10) {
1413           cout << "FollowTracks: track candidate(0..): " << trackIndex
1414                << " Segment not found, look for hit in station(0..): " << station
1415                << endl;
1416         }
1417         // Loop over chambers of the station
1418         for (chInStation = 0; chInStation < 2; chInStation++) {
1419           ch = 2 * station + chInStation;
1420           for (iHit = fIndexOfFirstHitForRecPerChamber[ch];
1421                iHit < fIndexOfFirstHitForRecPerChamber[ch] +
1422                  fNHitsForRecPerChamber[ch];
1423                iHit++) {
1424             hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
1425             // coordinates of extrapolated hit
1426             (&(trackParam[chInStation]))->ExtrapToZ(hit->GetZ());
1427             extrapHit->
1428               SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1429             extrapHit->
1430               SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
1431             // resolutions from "extrapSegment"
1432             extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1433             extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
1434             // Loop over hits in the chamber
1435             // condition for hit not already in segment ????
1436             chi2 = hit->NormalizedChi2WithHitForRec(extrapHit, maxSigma2Distance);
1437             if (chi2 < bestChi2) {
1438               // update best Chi2 and HitForRec if better found
1439               bestHit = hit;
1440               bestChi2 = chi2;
1441               chBestHit = chInStation;
1442             }
1443           }
1444         }
1445         if (bestHit) {
1446           // best hit found: add it to track candidate
1447           (&(trackParam[chBestHit]))->ExtrapToZ(bestHit->GetZ());
1448           track->AddHitForRec(bestHit);
1449           // set track parameters at this TrackHit
1450           track->SetTrackParamAtHit(track->GetNTrackHits() - 1,
1451                                     &(trackParam[chBestHit]));
1452           if (fPrintLevel >= 10) {
1453             cout << "FollowTracks: track candidate(0..): " << trackIndex
1454                  << " Added hit in station(0..): " << station << endl;
1455             track->RecursiveDump();
1456           }
1457         }
1458         else {
1459           // Remove current track candidate
1460           // and corresponding TrackHit's, ...
1461           track->Remove();
1462           delete extrapSegment;
1463           delete extrapHit;
1464           break; // stop the search for this candidate:
1465           // exit from the loop over station
1466         }
1467         delete extrapHit;
1468       }
1469       delete extrapSegment;
1470       // Sort track hits according to increasing Z
1471       track->GetTrackHitsPtr()->Sort();
1472       // Update track parameters at first track hit (smallest Z)
1473       trackParam1 = ((AliMUONTrackHit*)
1474                      (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1475       bendingMomentum = 0.;
1476       if (TMath::Abs(trackParam1->GetInverseBendingMomentum()) > 0.)
1477         bendingMomentum = TMath::Abs(1/(trackParam1->GetInverseBendingMomentum()));
1478       // Track removed if bendingMomentum not in window [min, max]
1479       if ((bendingMomentum < fMinBendingMomentum) || (bendingMomentum > fMaxBendingMomentum)) {
1480         track->Remove();
1481         break; // stop the search for this candidate:
1482         // exit from the loop over station 
1483       }
1484       // Track fit
1485       // with multiple Coulomb scattering if all stations
1486       if (station == 0) track->SetFitMCS(1);
1487       // without multiple Coulomb scattering if not all stations
1488       else track->SetFitMCS(0);
1489       track->SetFitNParam(5);  // with 5 parameters (momentum and position)
1490       track->SetFitStart(1);  // from parameters at first hit
1491       track->Fit();
1492       Double_t numberOfDegFree = (2.0 * track->GetNTrackHits() - 5);
1493       if (numberOfDegFree > 0) {
1494         chi2Norm =  track->GetFitFMin() / numberOfDegFree;
1495       } else {
1496         chi2Norm = 1.e10;
1497       }
1498       // Track removed if normalized chi2 too high
1499       if (chi2Norm > fMaxChi2) {
1500         track->Remove();
1501         break; // stop the search for this candidate:
1502         // exit from the loop over station 
1503       }
1504       if (fPrintLevel >= 10) {
1505         cout << "FollowTracks: track candidate(0..): " << trackIndex
1506              << " after fit from station(0..): " << station << " to 4" << endl;
1507         track->RecursiveDump();
1508       }
1509       // Track extrapolation to the vertex through the absorber (Branson)
1510       // after going through the first station
1511       if (station == 0) {
1512         trackParamVertex = *trackParam1;
1513         (&trackParamVertex)->ExtrapToVertex(0.,0.,0.);
1514         track->SetTrackParamAtVertex(&trackParamVertex);
1515         if (fPrintLevel >= 1) {
1516           cout << "FollowTracks: track candidate(0..): " << trackIndex
1517                << " after extrapolation to vertex" << endl;
1518           track->RecursiveDump();
1519         }
1520       }
1521     } // for (station = 2;...
1522     // go really to next track
1523     track = nextTrack;
1524   } // while (track)
1525   // Compression of track array (necessary after Remove ????)
1526   fRecTracksPtr->Compress();
1527   return;
1528 }
1529
1530   //__________________________________________________________________________
1531 void AliMUONEventReconstructor::RemoveDoubleTracks(void)
1532 {
1533   // To remove double tracks.
1534   // Tracks are considered identical
1535   // if they have at least half of their hits in common.
1536   // Among two identical tracks, one keeps the track with the larger number of hits
1537   // or, if these numbers are equal, the track with the minimum Chi2.
1538   AliMUONTrack *track1, *track2, *trackToRemove;
1539   Bool_t identicalTracks;
1540   Int_t hitsInCommon, nHits1, nHits2;
1541   identicalTracks = kTRUE;
1542   while (identicalTracks) {
1543     identicalTracks = kFALSE;
1544     // Loop over first track of the pair
1545     track1 = (AliMUONTrack*) fRecTracksPtr->First();
1546     while (track1 && (!identicalTracks)) {
1547       nHits1 = track1->GetNTrackHits();
1548       // Loop over second track of the pair
1549       track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1550       while (track2 && (!identicalTracks)) {
1551         nHits2 = track2->GetNTrackHits();
1552         // number of hits in common between two tracks
1553         hitsInCommon = track1->HitsInCommon(track2);
1554         // check for identical tracks
1555         if ((4 * hitsInCommon) >= (nHits1 + nHits2)) {
1556           identicalTracks = kTRUE;
1557           // decide which track to remove
1558           if (nHits1 > nHits2) trackToRemove = track2;
1559           else if (nHits1 < nHits2) trackToRemove = track1;
1560           else if ((track1->GetFitFMin()) < (track2->GetFitFMin()))
1561             trackToRemove = track2;
1562           else trackToRemove = track1;
1563           // remove it
1564           trackToRemove->Remove();
1565         }
1566         track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
1567       } // track2
1568       track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1569     } // track1
1570   }
1571   return;
1572 }
1573
1574   //__________________________________________________________________________
1575 void AliMUONEventReconstructor::UpdateTrackParamAtHit()
1576 {
1577   // Set track parameters after track fitting. Fill fTrackParamAtHit of AliMUONTrack's
1578   AliMUONTrack *track;
1579   AliMUONTrackHit *trackHit;
1580   AliMUONTrackParam *trackParam;
1581   track = (AliMUONTrack*) fRecTracksPtr->First();
1582   while (track) {
1583     trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->First();
1584     while (trackHit) {
1585       trackParam = trackHit->GetTrackParam();
1586       track->AddTrackParamAtHit(trackParam);
1587       trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->After(trackHit); 
1588     } // trackHit    
1589     track = (AliMUONTrack*) fRecTracksPtr->After(track);
1590   } // track
1591   return;
1592 }
1593
1594   //__________________________________________________________________________
1595 void AliMUONEventReconstructor::UpdateHitForRecAtHit()
1596 {
1597   // Set cluster parameterss after track fitting. Fill fHitForRecAtHit of AliMUONTrack's
1598   AliMUONTrack *track;
1599   AliMUONTrackHit *trackHit;
1600   AliMUONHitForRec *hitForRec;
1601   track = (AliMUONTrack*) fRecTracksPtr->First();
1602   while (track) {
1603     trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->First();
1604     while (trackHit) {
1605       hitForRec = trackHit->GetHitForRecPtr();
1606       track->AddHitForRecAtHit(hitForRec);
1607       trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->After(trackHit); 
1608     } // trackHit    
1609     track = (AliMUONTrack*) fRecTracksPtr->After(track);
1610   } // track
1611   return;
1612 }
1613
1614   //__________________________________________________________________________
1615 void AliMUONEventReconstructor::FillMUONTrack()
1616 {
1617   // Set track parameters at hits for Kalman track. Fill fTrackParamAtHit of AliMUONTrack's
1618   AliMUONTrackK *track;
1619   track = (AliMUONTrackK*) fRecTracksPtr->First();
1620   while (track) {
1621     track->FillMUONTrack();
1622     track = (AliMUONTrackK*) fRecTracksPtr->After(track);
1623   } 
1624   return;
1625 }
1626
1627   //__________________________________________________________________________
1628 void AliMUONEventReconstructor::EventDump(void)
1629 {
1630   // Dump reconstructed event (track parameters at vertex and at first hit),
1631   // and the particle parameters
1632
1633   AliMUONTrack *track;
1634   AliMUONTrackParam *trackParam, *trackParam1;
1635   Double_t bendingSlope, nonBendingSlope, pYZ;
1636   Double_t pX, pY, pZ, x, y, z, c;
1637   Int_t np, trackIndex, nTrackHits;
1638  
1639   if (fPrintLevel >= 1) cout << "****** enter EventDump ******" << endl;
1640   if (fPrintLevel >= 1) {
1641     cout << " Number of Reconstructed tracks :" <<  fNRecTracks << endl; 
1642   }
1643   fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
1644   // Loop over reconstructed tracks
1645   for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
1646     if (fTrackMethod != 1) continue; //AZ - skip the rest for now
1647     if (fPrintLevel >= 1)
1648       cout << " track number: " << trackIndex << endl;
1649     // function for each track for modularity ????
1650     track = (AliMUONTrack*) ((*fRecTracksPtr)[trackIndex]);
1651     nTrackHits = track->GetNTrackHits();
1652     if (fPrintLevel >= 1)
1653       cout << " number of track hits: " << nTrackHits << endl;
1654     // track parameters at Vertex
1655     trackParam = track->GetTrackParamAtVertex();
1656     x = trackParam->GetNonBendingCoor();
1657     y = trackParam->GetBendingCoor();
1658     z = trackParam->GetZ();
1659     bendingSlope = trackParam->GetBendingSlope();
1660     nonBendingSlope = trackParam->GetNonBendingSlope();
1661     pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
1662     pZ = pYZ/TMath::Sqrt(1+bendingSlope*bendingSlope);
1663     pX = pZ * nonBendingSlope;
1664     pY = pZ * bendingSlope;
1665     c = TMath::Sign(1.0, trackParam->GetInverseBendingMomentum());
1666     if (fPrintLevel >= 1)
1667       printf(" track parameters at Vertex z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1668              z, x, y, pX, pY, pZ, c);
1669
1670     // track parameters at first hit
1671     trackParam1 = ((AliMUONTrackHit*)
1672                    (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1673     x = trackParam1->GetNonBendingCoor();
1674     y = trackParam1->GetBendingCoor();
1675     z = trackParam1->GetZ();
1676     bendingSlope = trackParam1->GetBendingSlope();
1677     nonBendingSlope = trackParam1->GetNonBendingSlope();
1678     pYZ = 1/TMath::Abs(trackParam1->GetInverseBendingMomentum());
1679     pZ = pYZ/TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
1680     pX = pZ * nonBendingSlope;
1681     pY = pZ * bendingSlope;
1682     c = TMath::Sign(1.0, trackParam1->GetInverseBendingMomentum());
1683     if (fPrintLevel >= 1)
1684       printf(" track parameters at z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1685              z, x, y, pX, pY, pZ, c);
1686   }
1687   // informations about generated particles
1688   np = gAlice->GetMCApp()->GetNtrack();
1689   printf(" **** number of generated particles: %d  \n", np);
1690   
1691 //    for (Int_t iPart = 0; iPart < np; iPart++) {
1692 //      p = gAlice->Particle(iPart);
1693 //      printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
1694 //         iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());    
1695 //    }
1696   return;
1697 }
1698
1699
1700 //__________________________________________________________________________
1701 void AliMUONEventReconstructor::EventDumpTrigger(void)
1702 {
1703   // Dump reconstructed trigger event 
1704   // and the particle parameters
1705     
1706   AliMUONTriggerTrack *triggertrack ;
1707   Int_t nTriggerTracks = fMUONData->RecTriggerTracks()->GetEntriesFast();
1708  
1709   if (fPrintLevel >= 1) {
1710     cout << "****** enter EventDumpTrigger ******" << endl;
1711     cout << " Number of Reconstructed tracks :" <<  nTriggerTracks << endl;
1712   }
1713   // Loop over reconstructed tracks
1714   for (Int_t trackIndex = 0; trackIndex < nTriggerTracks; trackIndex++) {
1715     triggertrack = (AliMUONTriggerTrack*)fMUONData->RecTriggerTracks()->At(trackIndex);
1716       printf(" trigger track number %i x11=%f y11=%f thetax=%f thetay=%f \n",
1717              trackIndex,
1718              triggertrack->GetX11(),triggertrack->GetY11(),
1719              triggertrack->GetThetax(),triggertrack->GetThetay());      
1720   } 
1721 }
1722
1723 //__________________________________________________________________________
1724 void AliMUONEventReconstructor::FillEvent()
1725 {
1726 // Create a new AliMUONRecoEvent, fill its track list, then add it as a
1727 // leaf in the Event branch of TreeRecoEvent tree
1728    cout << "Enter FillEvent() ...\n";
1729
1730    if (!fRecoEvent) {
1731       fRecoEvent = new AliMUONRecoEvent();
1732    } else {
1733       fRecoEvent->Clear();
1734    }
1735    //save current directory
1736    TDirectory *current =  gDirectory;
1737    if (!fTreeFile)  fTreeFile  = new TFile("tree_reco.root", "RECREATE");
1738    if (!fEventTree) fEventTree = new TTree("TreeRecoEvent", "MUON reconstructed events");
1739    //AZif (fRecoEvent->MakeDumpTracks(fRecTracksPtr)) {
1740    if (fRecoEvent->MakeDumpTracks(fMuons, fRecTracksPtr, this)) { //AZ
1741       if (fPrintLevel > 1) fRecoEvent->EventInfo();
1742       TBranch *branch = fEventTree->GetBranch("Event");
1743       if (!branch) branch = fEventTree->Branch("Event", "AliMUONRecoEvent", &fRecoEvent, 64000);
1744       branch->SetAutoDelete();
1745       fTreeFile->cd();
1746       fEventTree->Fill();
1747       fTreeFile->Write();
1748    }
1749    // restore directory
1750    current->cd();
1751 }
1752
1753 //__________________________________________________________________________
1754 void AliMUONEventReconstructor::MakeTrackCandidatesK(void)
1755 {
1756   // To make initial tracks for Kalman filter from the list of segments
1757   Int_t istat, iseg;
1758   AliMUONSegment *segment;
1759   AliMUONTrackK *trackK;
1760
1761   if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesK" << endl;
1762   // Reset the TClonesArray of reconstructed tracks
1763   if (fRecTracksPtr) fRecTracksPtr->Delete();
1764   // Delete in order that the Track destructors are called,
1765   // hence the space for the TClonesArray of pointers to TrackHit's is freed
1766   fNRecTracks = 0;
1767
1768   AliMUONTrackK a(this, fHitsForRecPtr); // bad idea ???
1769   // Loop over stations(1...) 5 and 4
1770   for (istat=4; istat>=3; istat--) {
1771     // Loop over segments in the station
1772     for (iseg=0; iseg<fNSegments[istat]; iseg++) {
1773       // Transform segments to tracks and evaluate covariance matrix
1774       segment = (AliMUONSegment*) ((*fSegmentsPtr[istat])[iseg]);
1775       trackK = new ((*fRecTracksPtr)[fNRecTracks]) AliMUONTrackK(segment);
1776       fNRecTracks++;
1777     } // for (iseg=0;...)
1778   } // for (istat=4;...)
1779   return;
1780 }
1781
1782 //__________________________________________________________________________
1783 void AliMUONEventReconstructor::FollowTracksK(void)
1784 {
1785   // Follow tracks using Kalman filter
1786   Bool_t ok;
1787   Int_t icand, ichamBeg = 0, ichamEnd, chamBits;
1788   Double_t zDipole1, zDipole2;
1789   AliMUONTrackK *trackK;
1790   AliMUONHitForRec *hit;
1791   AliMUONRawCluster *clus;
1792   TClonesArray *rawclusters;
1793   clus = 0; rawclusters = 0;
1794
1795   //AZ(z->-z) zDipole1 = GetSimpleBPosition() - GetSimpleBLength()/2;
1796   //AZ(z->-z) zDipole2 = zDipole1 + GetSimpleBLength();
1797   zDipole1 = GetSimpleBPosition() + GetSimpleBLength()/2;
1798   zDipole2 = zDipole1 - GetSimpleBLength();
1799
1800   // Print hits
1801   trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[0]);
1802   if (trackK->DebugLevel() > 0) {
1803     for (Int_t i1=0; i1<fNHitsForRec; i1++) {
1804       hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[i1]);
1805       //if (hit->GetTTRTrack() > 1 || hit->GetTrackRefSignal() == 0) continue;
1806       printf(" Hit # %d %10.4f %10.4f %10.4f",
1807              hit->GetChamberNumber(), hit->GetBendingCoor(),
1808              hit->GetNonBendingCoor(), hit->GetZ());
1809       if (fRecTrackRefHits) {
1810         // from track ref hits
1811         printf(" %3d %3d \n", hit->GetTrackRefSignal(), hit->GetTTRTrack());
1812       } else {
1813         // from raw clusters
1814         rawclusters = fMUONData->RawClusters(hit->GetChamberNumber());
1815         clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->
1816                                                  GetHitNumber());
1817         printf("%3d", clus->GetTrack(1)-1);
1818         if (clus->GetTrack(2) != 0) printf("%3d \n", clus->GetTrack(2)-1);
1819         else printf("\n");
1820       } // if (fRecTrackRefHits)
1821     }
1822   } // if (trackK->DebugLevel() > 0)
1823
1824   icand = -1;
1825   Int_t nSeeds;
1826   nSeeds = fNRecTracks; // starting number of seeds
1827   // Loop over track candidates
1828   while (icand < fNRecTracks-1) {
1829     icand ++;
1830     if (trackK->DebugLevel()>0) cout << " *** Kalman track candidate No. " << icand << endl;
1831     trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
1832     if (trackK->GetRecover() < 0) continue; // failed track
1833
1834     // Discard candidate which will produce the double track
1835     /*
1836     if (icand > 0) {
1837       ok = CheckCandidateK(icand,nSeeds);
1838       if (!ok) {
1839         trackK->SetRecover(-1); // mark candidate to be removed
1840         continue;
1841       }
1842     }
1843     */
1844
1845     ok = kTRUE;
1846     if (trackK->GetRecover() == 0) hit = (AliMUONHitForRec*) 
1847                                    trackK->GetHitOnTrack()->Last(); // last hit
1848     //else hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[1]; // 2'nd hit
1849     else hit = trackK->GetHitLastOk(); // hit where track stopped
1850     if (hit) ichamBeg = hit->GetChamberNumber();
1851     ichamEnd = 0;
1852     // Check propagation direction
1853     if (hit == NULL) ichamBeg = ichamEnd;
1854     //AZ(z->-z) else if (trackK->GetTrackDir() > 0) {
1855     else if (trackK->GetTrackDir() < 0) {
1856       ichamEnd = 9; // forward propagation
1857       ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
1858       if (ok) {
1859         ichamBeg = ichamEnd;
1860         ichamEnd = 6; // backward propagation
1861         // Change weight matrix and zero fChi2 for backpropagation
1862         trackK->StartBack();
1863         //AZ trackK->SetTrackDir(-1);
1864         trackK->SetTrackDir(1);
1865         ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
1866         ichamBeg = ichamEnd;
1867         ichamEnd = 0;
1868       }
1869     } else {
1870       if (trackK->GetBPFlag()) {
1871         // backpropagation
1872         ichamEnd = 6; // backward propagation
1873         // Change weight matrix and zero fChi2 for backpropagation
1874         trackK->StartBack();
1875         ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
1876         ichamBeg = ichamEnd;
1877         ichamEnd = 0;
1878       }
1879     }
1880
1881     if (ok) {
1882       //AZ trackK->SetTrackDir(-1);
1883       trackK->SetTrackDir(1);
1884       trackK->SetBPFlag(kFALSE);
1885       ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
1886     }
1887     if (!ok) { trackK->SetRecover(-1); continue; } // mark candidate to be removed
1888
1889     // Apply smoother
1890     if (trackK->GetRecover() >= 0) {
1891       ok = trackK->Smooth();
1892       if (!ok) trackK->SetRecover(-1); // mark candidate to be removed
1893     }
1894
1895     // Majority 3 of 4 in first 2 stations
1896     if (!ok) continue;
1897     chamBits = 0;
1898     Double_t chi2_max = 0;
1899     for (Int_t i=0; i<trackK->GetNTrackHits(); i++) {
1900       hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[i];
1901       chamBits |= BIT(hit->GetChamberNumber());
1902       if (trackK->GetChi2PerPoint(i) > chi2_max) chi2_max = trackK->GetChi2PerPoint(i);
1903     }
1904     if (!((chamBits&3)==3 || (chamBits>>2&3)==3) && chi2_max > 25) {
1905       //trackK->Recover();
1906       trackK->SetRecover(-1); //mark candidate to be removed
1907       continue;
1908     }
1909     if (ok) trackK->SetTrackQuality(0); // compute "track quality"
1910   } // while
1911
1912   for (Int_t i=0; i<fNRecTracks; i++) {
1913     trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
1914     if (trackK->GetRecover() < 0) fRecTracksPtr->RemoveAt(i);
1915   }
1916
1917   // Compress TClonesArray
1918   fRecTracksPtr->Compress();
1919   fNRecTracks = fRecTracksPtr->GetEntriesFast();
1920   return;
1921 }
1922
1923 //__________________________________________________________________________
1924 Bool_t AliMUONEventReconstructor::CheckCandidateK(Int_t icand, Int_t nSeeds) const
1925 {
1926   // Discards track candidate if it will produce the double track (having
1927   // the same seed segment hits as hits of a good track found before)
1928   AliMUONTrackK *track1, *track2;
1929   AliMUONHitForRec *hit1, *hit2, *hit;
1930
1931   track1 = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
1932   hit1 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[0]; // 1'st hit
1933   hit2 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[1]; // 2'nd hit
1934
1935   for (Int_t i=0; i<icand; i++) {
1936     track2 = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
1937     //if (track2->GetRecover() < 0) continue;
1938     if (track2->GetRecover() < 0 && icand >= nSeeds) continue;
1939
1940     if (track1->GetStartSegment() == track2->GetStartSegment()) {
1941       return kFALSE;
1942     } else {
1943       Int_t nSame = 0;
1944       for (Int_t j=0; j<track2->GetNTrackHits(); j++) {
1945         hit = (AliMUONHitForRec*) (*track2->GetHitOnTrack())[j];
1946         if (hit == hit1 || hit == hit2) {
1947           nSame++;
1948           if (nSame == 2) return kFALSE;
1949         }
1950       } // for (Int_t j=0;
1951     }
1952   } // for (Int_t i=0;
1953   return kTRUE;
1954 }
1955
1956 //__________________________________________________________________________
1957 void AliMUONEventReconstructor::RemoveDoubleTracksK(void)
1958 {
1959   // Removes double tracks (sharing more than half of their hits). Keeps
1960   // the track with higher quality
1961   AliMUONTrackK *track1, *track2, *trackToKill;
1962
1963   // Sort tracks according to their quality
1964   fRecTracksPtr->Sort();
1965
1966   // Loop over first track of the pair
1967   track1 = (AliMUONTrackK*) fRecTracksPtr->First();
1968   Int_t debug = track1->DebugLevel();
1969   while (track1) {
1970     // Loop over second track of the pair
1971     track2 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
1972     while (track2) {
1973       // Check whether or not to keep track2
1974       if (!track2->KeepTrack(track1)) {
1975         if (debug >= 0) cout << " Killed track: " << 1/(*track2->GetTrackParameters())(4,0) <<
1976           " " << track2->GetTrackQuality() << endl;
1977         trackToKill = track2;
1978         track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
1979         trackToKill->Kill();
1980         fRecTracksPtr->Compress();
1981       } else track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
1982     } // track2
1983     track1 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
1984   } // track1
1985
1986   fNRecTracks = fRecTracksPtr->GetEntriesFast();
1987   if (debug >= 0) cout << " Number of Kalman tracks: " << fNRecTracks << endl;
1988 }
1989
1990 //__________________________________________________________________________
1991 void AliMUONEventReconstructor::GoToVertex(void)
1992 {
1993   // Propagates track to the vertex thru absorber
1994   // (using Branson correction for now)
1995
1996   Double_t zVertex;
1997   zVertex = 0;
1998   for (Int_t i=0; i<fNRecTracks; i++) {
1999     //((AliMUONTrackK*)(*fRecTracksPtr)[i])->Branson();
2000     ((AliMUONTrackK*)(*fRecTracksPtr)[i])->SetTrackQuality(1); // compute Chi2
2001     //((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToZ(zVertex); // w/out absorber
2002     ((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToVertex(1); // with absorber
2003   }
2004 }
2005
2006 //__________________________________________________________________________
2007 void AliMUONEventReconstructor::SetTrackMethod(Int_t iTrackMethod)
2008 {
2009   // Set track method and recreate track container if necessary
2010   
2011   fTrackMethod = iTrackMethod == 2 ? 2 : 1;
2012   if (fTrackMethod == 2) {
2013     if (fRecTracksPtr) delete fRecTracksPtr;
2014     fRecTracksPtr = new TClonesArray("AliMUONTrackK", 10);
2015     cout << " *** Tracking with the Kalman filter *** " << endl;
2016   } else cout << " *** Traditional tracking *** " << endl;
2017
2018 }