]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVTrackReconstructor.cxx
Adding classes AliMUONVCluster, AliMUONRawClusterV2 (Philippe P., Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONVTrackReconstructor.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 /// \class AliMUONVTrackReconstructor
20 /// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
21 ///
22 /// This class contains as data:
23 /// * a pointer to the array of hits to be reconstructed (the event)
24 /// * a pointer to the array of reconstructed tracks
25 ///
26 /// It contains as methods, among others:
27 /// * EventReconstruct to build the muon tracks
28 /// * EventReconstructTrigger to build the trigger tracks
29 ///
30 /// Several options and adjustable parameters are available for both Kalman and Original
31 /// tracking algorithms (hard coded for the moment in AliMUONVTrackReconstructor.cxx):
32 /// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
33 ///   attached to the track candidate and to select good tracks.
34 /// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
35 ///   are made assuming linear propagation between stations 4 and 5.
36 /// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
37 ///   new clusters pass the quality cut, either we consider all the possibilities
38 ///   (duplicating tracks) or we attach only the best cluster.
39 /// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
40 ///   lost during the tracking by removing the worst of the 2 clusters attached in the
41 ///   previous station.
42 /// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
43 ///   of the tracks at the end of the tracking by removing clusters that do not pass
44 ///   new quality cut (within the limit that we must keep at least one cluster per
45 ///   the station).
46 /// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
47 ///   quality of the tracks.
48 ///
49 ///  \author Philippe Pillot
50 //-----------------------------------------------------------------------------
51
52 #include "AliMUONVTrackReconstructor.h"
53
54 #include "AliMUONConstants.h"
55 #include "AliMUONRawCluster.h"
56 #include "AliMUONHitForRec.h"
57 #include "AliMUONObjectPair.h"
58 #include "AliMUONTriggerTrack.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMUONLocalTrigger.h"
61 #include "AliMUONGlobalTrigger.h"
62 #include "AliMUONTrack.h"
63 #include "AliMUONTrackParam.h"
64 #include "AliMUONTrackExtrap.h"
65 #include "AliMUONTrackHitPattern.h"
66 #include "AliMUONVTrackStore.h"
67 #include "AliMUONVClusterStore.h"
68 #include "AliMUONRawCluster.h"
69 #include "AliMUONVTriggerStore.h"
70 #include "AliMUONVTriggerTrackStore.h"
71 #include "AliMpDEManager.h"
72
73 #include "AliLog.h"
74 #include "AliCodeTimer.h"
75 #include "AliTracker.h"
76
77 #include <TClonesArray.h>
78 #include <TMath.h>
79 #include <TMatrixD.h>
80
81 #include <Riostream.h>
82
83 /// \cond CLASSIMP
84 ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
85 /// \endcond
86
87
88 //************* Defaults parameters for reconstruction
89 const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
90 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
91 const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
92 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceBending    = 2.;
93 const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceNonBending = 2.;
94
95 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForTracking = 6.0;
96 const Bool_t   AliMUONVTrackReconstructor::fgkMakeTrackCandidatesFast = kFALSE;
97 const Bool_t   AliMUONVTrackReconstructor::fgkTrackAllTracks = kTRUE;
98 const Bool_t   AliMUONVTrackReconstructor::fgkRecoverTracks = kTRUE;
99 const Bool_t   AliMUONVTrackReconstructor::fgkComplementTracks = kTRUE;
100 const Bool_t   AliMUONVTrackReconstructor::fgkImproveTracks = kTRUE;
101 const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForImprovement = 5.0;
102
103
104   //__________________________________________________________________________
105 AliMUONVTrackReconstructor::AliMUONVTrackReconstructor()
106   : TObject(),
107     fMinBendingMomentum(fgkDefaultMinBendingMomentum),
108     fMaxBendingMomentum(fgkDefaultMaxBendingMomentum),
109     fMaxNormChi2MatchTrigger(fgkDefaultMaxNormChi2MatchTrigger),
110     fHitsForRecPtr(0x0),
111     fNHitsForRec(0),
112     fNHitsForRecPerChamber(0x0),
113     fIndexOfFirstHitForRecPerChamber(0x0),
114     fRecTracksPtr(0x0),
115     fNRecTracks(0)
116 {
117   /// Constructor for class AliMUONVTrackReconstructor
118   fNHitsForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
119   fIndexOfFirstHitForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
120
121   // Memory allocation for the TClonesArray of hits for reconstruction
122   // Is 10000 the right size ????
123   fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
124   
125   // Memory allocation for the TClonesArray of reconstructed tracks
126   fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
127   
128   // set the magnetic field for track extrapolations
129   const AliMagF* kField = AliTracker::GetFieldMap();
130   if (!kField) AliFatal("No field available");
131   AliMUONTrackExtrap::SetField(kField);
132 }
133
134   //__________________________________________________________________________
135 AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
136 {
137   /// Destructor for class AliMUONVTrackReconstructor
138   delete [] fNHitsForRecPerChamber;
139   delete [] fIndexOfFirstHitForRecPerChamber;
140   delete fHitsForRecPtr;
141   delete fRecTracksPtr;
142 }
143
144   //__________________________________________________________________________
145 void AliMUONVTrackReconstructor::ResetHitsForRec()
146 {
147   /// To reset the TClonesArray of HitsForRec,
148   /// and the number of HitForRec and the index of the first HitForRec per chamber
149   if (fHitsForRecPtr) fHitsForRecPtr->Clear("C");
150   fNHitsForRec = 0;
151   for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
152     fNHitsForRecPerChamber[ch] = 0;
153     fIndexOfFirstHitForRecPerChamber[ch] = 0;
154   }
155 }
156
157   //__________________________________________________________________________
158 void AliMUONVTrackReconstructor::ResetTracks()
159 {
160   /// To reset the TClonesArray of reconstructed tracks
161   if (fRecTracksPtr) fRecTracksPtr->Clear("C");
162   fNRecTracks = 0;
163   return;
164 }
165
166   //__________________________________________________________________________
167 void AliMUONVTrackReconstructor::EventReconstruct(const AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
168 {
169   /// To reconstruct one event
170   AliDebug(1,"");
171   AliCodeTimerAuto("");
172   
173   ResetTracks();
174   ResetHitsForRec();
175   AddHitsForRecFromRawClusters(clusterStore);
176   MakeTracks();
177
178   // Add tracks to MUON data container 
179   for (Int_t i=0; i<fNRecTracks; ++i) 
180   {
181     AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
182     trackStore.Add(*track);
183   }
184 }
185
186   //__________________________________________________________________________
187 void AliMUONVTrackReconstructor::AddHitsForRecFromRawClusters(const AliMUONVClusterStore& clusterStore)
188 {
189   /// Build internal array of hit for rec from clusterStore
190   
191   TIter next(clusterStore.CreateIterator());
192   AliMUONRawCluster* clus(0x0);
193   Int_t iclus(0);
194   
195   while ( ( clus = static_cast<AliMUONRawCluster*>(next()) ) )
196   {
197     // new AliMUONHitForRec from raw cluster
198     // and increment number of AliMUONHitForRec's (total and in chamber)
199     AliMUONHitForRec* hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
200     fNHitsForRec++;
201     // more information into HitForRec
202     hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
203     hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
204     //  original raw cluster
205     Int_t ch = AliMpDEManager::GetChamberId(clus->GetDetElemId());
206     hitForRec->SetChamberNumber(ch);
207     hitForRec->SetHitNumber(iclus);
208     // Z coordinate of the raw cluster (cm)
209     hitForRec->SetZ(clus->GetZ());
210     if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
211       cout << "Chamber " << ch <<" raw cluster  " << iclus << " : " << endl;
212       clus->Print("full");
213       cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
214       hitForRec->Print("full");
215     }
216     ++iclus;
217   } // end of chamber loop
218   
219   SortHitsForRecWithIncreasingChamber(); 
220   
221   AliDebug(1,"End of AddHitsForRecFromRawClusters");
222   
223   if (AliLog::GetGlobalDebugLevel() > 0) 
224   {
225     AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
226     for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) 
227     {
228       AliDebug(1, Form("Chamber(0...): %d",ch));
229       AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
230       AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
231       for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
232            hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
233            hit++) {
234         AliDebug(1, Form("HitForRec index(0...): %d",hit));
235         ((*fHitsForRecPtr)[hit])->Dump();
236       }
237     }
238   }
239 }
240
241   //__________________________________________________________________________
242 void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
243 {
244   /// Sort HitsForRec's in increasing order with respect to chamber number.
245   /// Uses the function "Compare".
246   /// Update the information for HitsForRec per chamber too.
247   Int_t ch, nhits, prevch;
248   fHitsForRecPtr->Sort();
249   for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
250     fNHitsForRecPerChamber[ch] = 0;
251     fIndexOfFirstHitForRecPerChamber[ch] = 0;
252   }
253   prevch = 0; // previous chamber
254   nhits = 0; // number of hits in current chamber
255   // Loop over HitsForRec
256   for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
257     // chamber number (0...)
258     ch = ((AliMUONHitForRec*)  ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
259     // increment number of hits in current chamber
260     (fNHitsForRecPerChamber[ch])++;
261     // update index of first HitForRec in current chamber
262     // if chamber number different from previous one
263     if (ch != prevch) {
264       fIndexOfFirstHitForRecPerChamber[ch] = hit;
265       prevch = ch;
266     }
267   }
268   return;
269 }
270
271   //__________________________________________________________________________
272 void AliMUONVTrackReconstructor::MakeTracks()
273 {
274   /// To make the tracks from the list of segments and points in all stations
275   AliDebug(1,"Enter MakeTracks");
276   // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
277   MakeTrackCandidates();
278   if (fRecTracksPtr->GetEntriesFast() == 0) return;
279   // Follow tracks in stations(1..) 3, 2 and 1
280   FollowTracks();
281   // Complement the reconstructed tracks
282   if (fgkComplementTracks) ComplementTracks();
283   // Improve the reconstructed tracks
284   if (fgkImproveTracks) ImproveTracks();
285   // Remove double tracks
286   RemoveDoubleTracks();
287   // Fill AliMUONTrack data members
288   Finalize();
289 }
290
291   //__________________________________________________________________________
292 TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
293 {
294   /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
295   /// Return a new TClonesArray of segments.
296   /// It is the responsibility of the user to delete it afterward.
297   AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
298   
299   AliMUONHitForRec *hit1Ptr, *hit2Ptr;
300   AliMUONObjectPair *segment;
301   Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
302                                                                      // first and second chambers (0...) in the station
303   Int_t ch1 = 2 * station;
304   Int_t ch2 = ch1 + 1;
305   
306   // list of segments
307   TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
308   segments->SetOwner(kTRUE);
309   
310   // Loop over HitForRec's in the first chamber of the station
311   for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
312        hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
313        hit1++) 
314   {
315     // pointer to the HitForRec
316     hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
317     // Loop over HitsForRec's in the second chamber of the station
318     for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
319          hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
320          hit2++) 
321     {
322       // pointer to the HitForRec
323       hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
324       if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. ) 
325       {
326         // bending slope
327         bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
328         // impact parameter
329         impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
330         // absolute value of bending momentum
331         bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
332       } else 
333       {
334         AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
335         continue;
336       }   
337       // check for bending momentum within tolerances
338       if ((bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum)) 
339       {
340         // make new segment
341         segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
342         if (AliLog::GetGlobalDebugLevel() > 1) {
343           cout << "segmentIndex(0...): " << segments->GetLast() << endl;
344           segment->Dump();
345           cout << "HitForRec in first chamber" << endl;
346           hit1Ptr->Dump();
347           cout << "HitForRec in second chamber" << endl;
348           hit2Ptr->Dump();
349         }
350       }
351     } //for (Int_t hit2
352   } // for (Int_t hit1...
353   AliDebug(1,Form("Station: %d  NSegments:  %d ", station, segments->GetEntriesFast()));
354   return segments;
355 }
356
357   //__________________________________________________________________________
358 void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
359 {
360   /// To remove identical tracks:
361   /// Tracks are considered identical if they have all their hits in common.
362   /// One keeps the track with the larger number of hits if need be
363   AliMUONTrack *track1, *track2, *trackToRemove;
364   Int_t hitsInCommon, nHits1, nHits2;
365   Bool_t removedTrack1;
366   // Loop over first track of the pair
367   track1 = (AliMUONTrack*) fRecTracksPtr->First();
368   while (track1) {
369     removedTrack1 = kFALSE;
370     nHits1 = track1->GetNTrackHits();
371     // Loop over second track of the pair
372     track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
373     while (track2) {
374       nHits2 = track2->GetNTrackHits();
375       // number of hits in common between two tracks
376       hitsInCommon = track1->HitsInCommon(track2);
377       // check for identical tracks
378       if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
379         // decide which track to remove
380         if (nHits2 > nHits1) {
381           // remove track1 and continue the first loop with the track next to track1
382           trackToRemove = track1;
383           track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
384           fRecTracksPtr->Remove(trackToRemove);
385           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
386           fNRecTracks--;
387           removedTrack1 = kTRUE;
388           break;
389         } else {
390           // remove track2 and continue the second loop with the track next to track2
391           trackToRemove = track2;
392           track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
393           fRecTracksPtr->Remove(trackToRemove);
394           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
395           fNRecTracks--;
396         }
397       } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
398     } // track2
399     if (removedTrack1) continue;
400     track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
401   } // track1
402   return;
403 }
404
405   //__________________________________________________________________________
406 void AliMUONVTrackReconstructor::RemoveDoubleTracks()
407 {
408   /// To remove double tracks:
409   /// Tracks are considered identical if more than half of the hits of the track
410   /// which has the smaller number of hits are in common with the other track.
411   /// Among two identical tracks, one keeps the track with the larger number of hits
412   /// or, if these numbers are equal, the track with the minimum chi2.
413   AliMUONTrack *track1, *track2, *trackToRemove;
414   Int_t hitsInCommon, nHits1, nHits2;
415   Bool_t removedTrack1;
416   // Loop over first track of the pair
417   track1 = (AliMUONTrack*) fRecTracksPtr->First();
418   while (track1) {
419     removedTrack1 = kFALSE;
420     nHits1 = track1->GetNTrackHits();
421     // Loop over second track of the pair
422     track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
423     while (track2) {
424       nHits2 = track2->GetNTrackHits();
425       // number of hits in common between two tracks
426       hitsInCommon = track1->HitsInCommon(track2);
427       // check for identical tracks
428       if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
429         // decide which track to remove
430         if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
431           // remove track2 and continue the second loop with the track next to track2
432           trackToRemove = track2;
433           track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
434           fRecTracksPtr->Remove(trackToRemove);
435           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
436           fNRecTracks--;
437         } else {
438           // else remove track1 and continue the first loop with the track next to track1
439           trackToRemove = track1;
440           track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
441           fRecTracksPtr->Remove(trackToRemove);
442           fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
443           fNRecTracks--;
444           removedTrack1 = kTRUE;
445           break;
446         }
447       } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
448     } // track2
449     if (removedTrack1) continue;
450     track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
451   } // track1
452   return;
453 }
454
455   //__________________________________________________________________________
456 Double_t AliMUONVTrackReconstructor::TryOneHitForRec(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec,
457                                                      AliMUONTrackParam &trackParamAtHit, Bool_t updatePropagator)
458 {
459 /// Test the compatibility between the track and the hitForRec (using trackParam's covariance matrix):
460 /// return the corresponding Chi2
461 /// return trackParamAtHit
462   
463   // extrapolate track parameters and covariances at the z position of the tested hit
464   trackParamAtHit = trackParam;
465   AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtHit, hitForRec->GetZ(), updatePropagator);
466   
467   // set pointer to hit into trackParamAtHit
468   trackParamAtHit.SetHitForRecPtr(hitForRec);
469   
470   // Set differences between trackParam and hitForRec in the bending and non bending directions
471   Double_t dX = hitForRec->GetNonBendingCoor() - trackParamAtHit.GetNonBendingCoor();
472   Double_t dY = hitForRec->GetBendingCoor() - trackParamAtHit.GetBendingCoor();
473   
474   // Calculate errors and covariances
475   const TMatrixD& kParamCov = trackParamAtHit.GetCovariances();
476   Double_t sigma2X = kParamCov(0,0) + hitForRec->GetNonBendingReso2();
477   Double_t sigma2Y = kParamCov(2,2) + hitForRec->GetBendingReso2();
478   
479   // Compute chi2
480   return dX * dX / sigma2X + dY * dY / sigma2Y;
481   
482 }
483
484   //__________________________________________________________________________
485 Bool_t AliMUONVTrackReconstructor::TryOneHitForRecFast(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec)
486 {
487 /// Test the compatibility between the track and the hitForRec within a wide fix window
488 /// assuming linear propagation of the track:
489 /// return kTRUE if they are compatibles
490   
491   Double_t dZ = hitForRec->GetZ() - trackParam.GetZ();
492   Double_t dX = hitForRec->GetNonBendingCoor() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
493   Double_t dY = hitForRec->GetBendingCoor() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
494   
495   if (TMath::Abs(dX) > fgkMaxTrackingDistanceNonBending || TMath::Abs(dY) > fgkMaxTrackingDistanceBending) return kFALSE;
496   
497   return kTRUE;
498   
499 }
500
501   //__________________________________________________________________________
502 Double_t AliMUONVTrackReconstructor::TryTwoHitForRecFast(const AliMUONTrackParam &trackParamAtHit1, AliMUONHitForRec* hitForRec2,
503                                                          AliMUONTrackParam &trackParamAtHit2)
504 {
505 /// Test the compatibility between the track and the 2 hitForRec together (using trackParam's covariance matrix)
506 /// assuming linear propagation between the two hits:
507 /// return the corresponding Chi2 accounting for covariances between the 2 hitForRec
508 /// return trackParamAtHit1 & 2
509   
510   // extrapolate linearly track parameters at the z position of the second hit
511   trackParamAtHit2 = trackParamAtHit1;
512   AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtHit2, hitForRec2->GetZ());
513   
514   // set pointer to hit2 into trackParamAtHit2
515   trackParamAtHit2.SetHitForRecPtr(hitForRec2);
516   
517   // Set differences between track and hitForRec in the bending and non bending directions
518   AliMUONHitForRec* hitForRec1 = trackParamAtHit1.GetHitForRecPtr();
519   Double_t dX1 = hitForRec1->GetNonBendingCoor() - trackParamAtHit1.GetNonBendingCoor();
520   Double_t dX2 = hitForRec2->GetNonBendingCoor() - trackParamAtHit2.GetNonBendingCoor();
521   Double_t dY1 = hitForRec1->GetBendingCoor() - trackParamAtHit1.GetBendingCoor();
522   Double_t dY2 = hitForRec2->GetBendingCoor() - trackParamAtHit2.GetBendingCoor();
523   
524   // Calculate errors and covariances
525   const TMatrixD& kParamCov1 = trackParamAtHit1.GetCovariances();
526   const TMatrixD& kParamCov2 = trackParamAtHit2.GetCovariances();
527   Double_t dZ = trackParamAtHit2.GetZ() - trackParamAtHit1.GetZ();
528   Double_t sigma2X1 = kParamCov1(0,0) + hitForRec1->GetNonBendingReso2();
529   Double_t sigma2X2 = kParamCov2(0,0) + hitForRec2->GetNonBendingReso2();
530   Double_t covX1X2  = kParamCov1(0,0) + dZ * kParamCov1(0,1);
531   Double_t sigma2Y1 = kParamCov1(2,2) + hitForRec1->GetBendingReso2();
532   Double_t sigma2Y2 = kParamCov2(2,2) + hitForRec2->GetBendingReso2();
533   Double_t covY1Y2  = kParamCov1(2,2) + dZ * kParamCov1(2,3);
534   
535   // Compute chi2
536   Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
537   Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
538   if (detX == 0. || detY == 0.) return 1.e10;
539   return   (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
540          + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
541   
542 }
543
544   //__________________________________________________________________________
545 Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, Int_t nextStation)
546 {
547   /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible HitForRec(s)
548   /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
549   /// kTRUE:  duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
550   ///         fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
551   ///         Remove the obsolete "trackCandidate" at the end.
552   /// kFALSE: add only the best hit(s) to the "trackCandidate". Try to add a couple of hits in priority.
553   /// return kTRUE if new hits have been found (otherwise return kFALSE)
554   AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
555   
556   // Order the chamber according to the propagation direction (tracking starts with chamber 2):
557   // - nextStation == station(1...) 5 => forward propagation
558   // - nextStation < station(1...) 5 => backward propagation
559   Int_t ch1, ch2;
560   if (nextStation==4) {
561     ch1 = 2*nextStation+1;
562     ch2 = 2*nextStation;
563   } else {
564     ch1 = 2*nextStation;
565     ch2 = 2*nextStation+1;
566   }
567   
568   Double_t chi2WithOneHitForRec = 1.e10;
569   Double_t chi2WithTwoHitForRec = 1.e10;
570   Double_t maxChi2WithOneHitForRec = 2. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 2 because 2 quantities in chi2
571   Double_t maxChi2WithTwoHitForRec = 4. * fgkSigmaToCutForTracking * fgkSigmaToCutForTracking; // 4 because 4 quantities in chi2
572   Double_t bestChi2WithOneHitForRec = maxChi2WithOneHitForRec;
573   Double_t bestChi2WithTwoHitForRec = maxChi2WithTwoHitForRec;
574   Bool_t foundOneHit = kFALSE;
575   Bool_t foundTwoHits = kFALSE;
576   AliMUONTrack *newTrack = 0x0;
577   AliMUONHitForRec *hitForRecCh1, *hitForRecCh2;
578   AliMUONTrackParam extrapTrackParamAtHit1;
579   AliMUONTrackParam extrapTrackParamAtHit2;
580   AliMUONTrackParam bestTrackParamAtHit1;
581   AliMUONTrackParam bestTrackParamAtHit2;
582   Bool_t *hitForRecCh1Used = new Bool_t[fNHitsForRecPerChamber[ch1]];
583   for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) hitForRecCh1Used[hit1] = kFALSE;
584   
585   // Get track parameters
586   AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtHit()->First());
587   
588   // Add MCS effect
589   AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
590   
591   // Printout for debuging
592   if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
593     cout << "FollowLinearTrackInStation: look for hits in chamber(1..): " << ch2+1 << endl;
594   }
595   
596   // look for candidates in chamber 2 
597   for (Int_t hit2 = 0; hit2 < fNHitsForRecPerChamber[ch2]; hit2++) {
598     
599     hitForRecCh2 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch2]+hit2);
600     
601     // try to add the current hit fast
602     if (!TryOneHitForRecFast(trackParam, hitForRecCh2)) continue;
603     
604     // try to add the current hit accuratly
605     extrapTrackParamAtHit2 = trackParam;
606     AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit2, hitForRecCh2->GetZ());
607     chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit2, hitForRecCh2, extrapTrackParamAtHit2);
608     
609     // if good chi2 then try to attach a hitForRec in the other chamber too
610     if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
611       Bool_t foundSecondHit = kFALSE;
612       
613       // Printout for debuging
614       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
615         cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch2+1
616              << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
617         cout << "                      look for second hits in chamber(1..): " << ch1+1 << " ..." << endl;
618       }
619       
620       // add MCS effect
621       AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtHit2,AliMUONConstants::ChamberThicknessInX0(),1.);
622       
623       for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
624         
625         hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
626         
627         // try to add the current hit fast
628         if (!TryOneHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1)) continue;
629         
630         // try to add the current hit in addition to the one found on the previous chamber
631         chi2WithTwoHitForRec = TryTwoHitForRecFast(extrapTrackParamAtHit2, hitForRecCh1, extrapTrackParamAtHit1);
632         
633         // if good chi2 then consider to add the 2 hitForRec to the "trackCandidate"
634         if (chi2WithTwoHitForRec < maxChi2WithTwoHitForRec) {
635           foundSecondHit = kTRUE;
636           foundTwoHits = kTRUE;
637           
638           // Printout for debuging
639           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
640             cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
641                  << " (Chi2 = " << chi2WithTwoHitForRec << ")" << endl;
642           }
643           
644           if (fgkTrackAllTracks) {
645             // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
646             newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
647             extrapTrackParamAtHit1.SetRemovable(kTRUE);
648             newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
649             extrapTrackParamAtHit2.SetRemovable(kTRUE);
650             newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
651             newTrack->GetTrackParamAtHit()->Sort();
652             fNRecTracks++;
653             
654             // Tag hitForRecCh1 as used
655             hitForRecCh1Used[hit1] = kTRUE;
656             
657             // Printout for debuging
658             if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
659               cout << "FollowLinearTrackInStation: added two hits in station(1..): " << nextStation+1 << endl;
660               if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
661             }
662             
663           } else if (chi2WithTwoHitForRec < bestChi2WithTwoHitForRec) {
664             // keep track of the best couple of hits
665             bestChi2WithTwoHitForRec = chi2WithTwoHitForRec;
666             bestTrackParamAtHit1 = extrapTrackParamAtHit1;
667             bestTrackParamAtHit2 = extrapTrackParamAtHit2;
668           }
669           
670         }
671         
672       }
673       
674       // if no hitForRecCh1 found then consider to add hitForRecCh2 only
675       if (!foundSecondHit) {
676         foundOneHit = kTRUE;
677         
678         if (fgkTrackAllTracks) {
679           // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
680           newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
681           extrapTrackParamAtHit2.SetRemovable(kFALSE);
682           newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit2,hitForRecCh2);
683           newTrack->GetTrackParamAtHit()->Sort();
684           fNRecTracks++;
685           
686           // Printout for debuging
687           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
688             cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch2+1 << endl;
689             if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
690           }
691           
692         } else if (!foundTwoHits && chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
693           // keep track of the best single hitForRec except if a couple of hits has already been found
694           bestChi2WithOneHitForRec = chi2WithOneHitForRec;
695           bestTrackParamAtHit1 = extrapTrackParamAtHit2;
696         }
697         
698       }
699       
700     }
701     
702   }
703   
704   // look for candidates in chamber 1 not already attached to a track
705   // if we want to keep all possible tracks or if no good couple of hitForRec has been found
706   if (fgkTrackAllTracks || !foundTwoHits) {
707     
708     // Printout for debuging
709     if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
710       cout << "FollowLinearTrackInStation: look for single hits in chamber(1..): " << ch1+1 << endl;
711     }
712     
713     //Extrapolate trackCandidate to chamber "ch2"
714     AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
715     
716     // add MCS effect for next step
717     AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
718       
719     for (Int_t hit1 = 0; hit1 < fNHitsForRecPerChamber[ch1]; hit1++) {
720       
721       hitForRecCh1 = (AliMUONHitForRec*) fHitsForRecPtr->UncheckedAt(fIndexOfFirstHitForRecPerChamber[ch1]+hit1);
722       
723       if (hitForRecCh1Used[hit1]) continue; // Skip hitForRec already used
724       
725       // try to add the current hit fast
726       if (!TryOneHitForRecFast(trackParam, hitForRecCh1)) continue;
727         
728       // try to add the current hit accuratly
729       extrapTrackParamAtHit1 = trackParam;
730       AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtHit1, hitForRecCh1->GetZ());
731       chi2WithOneHitForRec = TryOneHitForRec(extrapTrackParamAtHit1, hitForRecCh1, extrapTrackParamAtHit1);
732     
733       // if good chi2 then consider to add hitForRecCh1
734       // We do not try to attach a hitForRec in the other chamber too since it has already been done above
735       if (chi2WithOneHitForRec < maxChi2WithOneHitForRec) {
736         foundOneHit = kTRUE;
737         
738         // Printout for debuging
739         if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
740           cout << "FollowLinearTrackInStation: found one hit in chamber(1..): " << ch1+1
741                << " (Chi2 = " << chi2WithOneHitForRec << ")" << endl;
742         }
743         
744         if (fgkTrackAllTracks) {
745           // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new hitForRec's
746           newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
747           extrapTrackParamAtHit1.SetRemovable(kFALSE);
748           newTrack->AddTrackParamAtHit(&extrapTrackParamAtHit1,hitForRecCh1);
749           newTrack->GetTrackParamAtHit()->Sort();
750           fNRecTracks++;
751           
752           // Printout for debuging
753           if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
754             cout << "FollowLinearTrackInStation: added one hit in chamber(1..): " << ch1+1 << endl;
755             if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
756           }
757           
758         } else if (chi2WithOneHitForRec < bestChi2WithOneHitForRec) {
759           // keep track of the best single hitForRec except if a couple of hits has already been found
760           bestChi2WithOneHitForRec = chi2WithOneHitForRec;
761           bestTrackParamAtHit1 = extrapTrackParamAtHit1;
762         }
763         
764       }
765       
766     }
767     
768   }
769   
770   // fill out the best track if required else clean up the fRecTracksPtr array
771   if (!fgkTrackAllTracks) {
772     if (foundTwoHits) {
773       bestTrackParamAtHit1.SetRemovable(kTRUE);
774       trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
775       bestTrackParamAtHit2.SetRemovable(kTRUE);
776       trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit2,bestTrackParamAtHit2.GetHitForRecPtr());
777       trackCandidate.GetTrackParamAtHit()->Sort();
778       
779       // Printout for debuging
780       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
781         cout << "FollowLinearTrackInStation: added the two best hits in station(1..): " << nextStation+1 << endl;
782         if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
783       }
784       
785     } else if (foundOneHit) {
786       bestTrackParamAtHit1.SetRemovable(kFALSE);
787       trackCandidate.AddTrackParamAtHit(&bestTrackParamAtHit1,bestTrackParamAtHit1.GetHitForRecPtr());
788       trackCandidate.GetTrackParamAtHit()->Sort();
789       
790       // Printout for debuging
791       if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
792         cout << "FollowLinearTrackInStation: added the best hit in chamber(1..): " << bestTrackParamAtHit1.GetHitForRecPtr()->GetChamberNumber()+1 << endl;
793         if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
794       }
795       
796     } else {
797       delete [] hitForRecCh1Used;
798       return kFALSE;
799     }
800     
801   } else if (foundOneHit || foundTwoHits) {
802     
803     // remove obsolete track
804     fRecTracksPtr->Remove(&trackCandidate);
805     fNRecTracks--;
806     
807   } else {
808     delete [] hitForRecCh1Used;  
809     return kFALSE;
810   }
811   
812   delete [] hitForRecCh1Used;
813   return kTRUE;
814   
815 }
816
817   //__________________________________________________________________________
818 void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
819                                                            const AliMUONVTriggerTrackStore& triggerTrackStore,
820                                                            const AliMUONVTriggerStore& triggerStore,
821                                                            const AliMUONTrackHitPattern& trackHitPattern)
822 {
823   /// Try to match track from tracking system with trigger track
824   AliCodeTimerAuto("");
825   
826   static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
827   
828   Int_t matchTrigger;
829   Int_t loTrgNum(-1);
830   Double_t distTriggerTrack[3];
831   Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
832
833   TIter itTrack(trackStore.CreateIterator());
834   AliMUONTrack* track;
835   
836   while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
837   {
838     matchTrigger = 0;
839     chi2MatchTrigger = 0.;
840     loTrgNum = -1;
841     Int_t doubleMatch=-1; // Check if track matches 2 trigger tracks
842     Double_t doubleChi2 = -1.;
843     
844     AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last())));
845     AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
846     
847     xTrack = trackParam.GetNonBendingCoor();
848     yTrack = trackParam.GetBendingCoor();
849     ySlopeTrack = trackParam.GetBendingSlope();
850     minChi2MatchTrigger = 999.;
851     
852     AliMUONTriggerTrack *triggerTrack;
853     TIter itTriggerTrack(triggerTrackStore.CreateIterator());
854     while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
855     {
856       distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
857       distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
858       distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
859       chi2 = 0.;
860       for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
861       chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
862       if (chi2 < fMaxNormChi2MatchTrigger) 
863       {
864         Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
865         if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger) 
866         {
867           if(isDoubleTrack)
868           {
869             doubleMatch = loTrgNum;
870             doubleChi2 = chi2MatchTrigger;
871           }
872           minChi2MatchTrigger = chi2;
873           chi2MatchTrigger = chi2;
874           loTrgNum = triggerTrack->GetLoTrgNum();
875           AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
876           matchTrigger=1;
877           if(locTrg->LoLpt()>0)matchTrigger=2;
878           if(locTrg->LoHpt()>0)matchTrigger=3;
879         }
880         else if(isDoubleTrack) 
881         {
882           doubleMatch = triggerTrack->GetLoTrgNum();
883           doubleChi2 = chi2;
884         }
885       }
886     }
887     if(doubleMatch>=0)
888     { // If two trigger tracks match, select the one passing more trigger cuts
889       AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
890       AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
891       if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
892       {
893         if(locTrg1->LoHpt()>0)matchTrigger=3;
894         else matchTrigger=2;
895         loTrgNum = doubleMatch;
896         chi2MatchTrigger=doubleChi2;
897       }
898     }
899     
900     track->SetMatchTrigger(matchTrigger);
901     track->SetLoTrgNum(loTrgNum);
902     track->SetChi2MatchTrigger(chi2MatchTrigger);
903     
904     AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
905     
906     if (locTrg)
907     {    
908       track->SetLocalTrigger(locTrg->LoCircuit(),
909                              locTrg->LoStripX(),
910                              locTrg->LoStripY(),
911                              locTrg->LoDev(),
912                              locTrg->LoLpt(),
913                              locTrg->LoHpt());
914     }    
915   }  
916   
917   trackHitPattern.GetHitPattern(trackStore,triggerStore);
918 }
919
920   //__________________________________________________________________________
921 void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
922                                                          const AliMUONVTriggerStore& triggerStore,
923                                                          AliMUONVTriggerTrackStore& triggerTrackStore)
924 {
925   /// To make the trigger tracks from Local Trigger
926   AliDebug(1, "");
927   AliCodeTimerAuto("");
928   
929   AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
930   
931   UChar_t gloTrigPat = 0;
932
933   if (globalTrigger)
934   {
935     gloTrigPat = globalTrigger->GetGlobalResponse();
936   }
937   
938   TIter next(triggerStore.CreateIterator());
939   AliMUONLocalTrigger* locTrg(0x0);
940
941   Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
942   Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
943       
944   AliMUONTriggerTrack triggerTrack;
945   
946   while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
947   {
948     Bool_t xTrig=kFALSE;
949     Bool_t yTrig=kFALSE;
950     
951     Int_t localBoardId = locTrg->LoCircuit();
952     if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 && 
953          locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
954     else xTrig=kTRUE;                         // trigger in X
955     if (locTrg->LoTrigY()==1 && 
956         locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
957     else yTrig = kTRUE;                          // trigger in Y
958     
959     if (xTrig && yTrig) 
960     { // make Trigger Track if trigger in X and Y
961       
962       Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX()); 
963       // need first to convert deviation to [0-30] 
964       // (see AliMUONLocalTriggerBoard::LocalTrigger)
965       Int_t deviation = locTrg->LoDev(); 
966       Int_t sign = 0;
967       if ( !locTrg->LoSdev() &&  deviation ) sign=-1;
968       if ( !locTrg->LoSdev() && !deviation ) sign= 0;
969       if (  locTrg->LoSdev() == 1 )          sign=+1;
970       deviation *= sign;
971       deviation += 15;
972       Int_t stripX21 = locTrg->LoStripX()+deviation+1;
973       Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);       
974       Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
975       
976       AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
977                        locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
978       
979       Float_t thetax = TMath::ATan2( x11 , z11 );
980       Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
981       
982       triggerTrack.SetX11(x11);
983       triggerTrack.SetY11(y11);
984       triggerTrack.SetThetax(thetax);
985       triggerTrack.SetThetay(thetay);
986       triggerTrack.SetGTPattern(gloTrigPat);
987       triggerTrack.SetLoTrgNum(localBoardId);
988       
989       triggerTrackStore.Add(triggerTrack);
990     } // board is fired 
991   } // end of loop on Local Trigger
992 }
993