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