Fixes in wirting of raw data needed on big-endian platforms (Marco)
[u/mrichter/AliRoot.git] / MUON / AliMUONVTrackReconstructor.cxx
CommitLineData
8d0843c6 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////////////////////////////////////
06ca6d7b 19///
c4ee792d 20/// \class AliMUONVTrackReconstructor
06ca6d7b 21/// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
22///
23/// This class contains as data:
24/// * a pointer to the array of hits to be reconstructed (the event)
25/// * a pointer to the array of segments made with these hits inside each station
26/// * a pointer to the array of reconstructed tracks
27///
28/// It contains as methods, among others:
29/// * EventReconstruct to build the muon tracks
30/// * EventReconstructTrigger to build the trigger tracks
31///
c4ee792d 32/// \author Philippe Pillot
33///
8d0843c6 34////////////////////////////////////
35
8d0843c6 36#include "AliMUONVTrackReconstructor.h"
7ec3b9cf 37
8d0843c6 38#include "AliMUONConstants.h"
ea94c18b 39#include "AliMUONRawCluster.h"
8d0843c6 40#include "AliMUONHitForRec.h"
208f139e 41#include "AliMUONObjectPair.h"
8d0843c6 42#include "AliMUONTriggerTrack.h"
e1a10d41 43#include "AliMUONTriggerCircuit.h"
8d0843c6 44#include "AliMUONLocalTrigger.h"
45#include "AliMUONGlobalTrigger.h"
8d0843c6 46#include "AliMUONTrack.h"
37827b29 47#include "AliMUONTrackParam.h"
48#include "AliMUONTrackExtrap.h"
7771752e 49#include "AliMUONTrackHitPattern.h"
7ec3b9cf 50#include "AliMUONVTrackStore.h"
51#include "AliMUONVClusterStore.h"
52#include "AliMUONRawCluster.h"
7ec3b9cf 53#include "AliMUONVTriggerStore.h"
54#include "AliMUONVTriggerTrackStore.h"
ea94c18b 55#include "AliMpDEManager.h"
56
57#include "AliLog.h"
58#include "AliTracker.h"
8d0843c6 59
4889d34c 60#include <TClonesArray.h>
61#include <TMath.h>
ea94c18b 62#include <TMatrixD.h>
63
64#include <Riostream.h>
4889d34c 65
78649106 66/// \cond CLASSIMP
8d0843c6 67ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
78649106 68/// \endcond
8d0843c6 69
70//************* Defaults parameters for reconstruction
71const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
72const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
208f139e 73const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
8d0843c6 74
ea94c18b 75const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForTracking = 6.0;
76const Double_t AliMUONVTrackReconstructor::fgkSigmaToCutForImprovement = 4.0;
77const Bool_t AliMUONVTrackReconstructor::fgkTrackAllTracks = kTRUE;
78const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceBending = 2.;
79const Double_t AliMUONVTrackReconstructor::fgkMaxTrackingDistanceNonBending = 2.;
80const Bool_t AliMUONVTrackReconstructor::fgkRecoverTracks = kTRUE;
81const Bool_t AliMUONVTrackReconstructor::fgkImproveTracks = kTRUE;
82
83
84 //__________________________________________________________________________
7ec3b9cf 85AliMUONVTrackReconstructor::AliMUONVTrackReconstructor()
8d0843c6 86 : TObject(),
87 fMinBendingMomentum(fgkDefaultMinBendingMomentum),
88 fMaxBendingMomentum(fgkDefaultMaxBendingMomentum),
208f139e 89 fMaxNormChi2MatchTrigger(fgkDefaultMaxNormChi2MatchTrigger),
8d0843c6 90 fHitsForRecPtr(0x0),
91 fNHitsForRec(0),
92 fNHitsForRecPerChamber(0x0),
93 fIndexOfFirstHitForRecPerChamber(0x0),
8d0843c6 94 fRecTracksPtr(0x0),
7ec3b9cf 95 fNRecTracks(0)
8d0843c6 96{
97 /// Constructor for class AliMUONVTrackReconstructor
8d0843c6 98 fNHitsForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
99 fIndexOfFirstHitForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
100
8d0843c6 101 // Memory allocation for the TClonesArray of hits for reconstruction
102 // Is 10000 the right size ????
103 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
ea94c18b 104
105 // Memory allocation for the TClonesArray of reconstructed tracks
106 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
7ec3b9cf 107
208f139e 108 // set the magnetic field for track extrapolations
8d0843c6 109 const AliMagF* kField = AliTracker::GetFieldMap();
110 if (!kField) AliFatal("No field available");
37827b29 111 AliMUONTrackExtrap::SetField(kField);
8d0843c6 112}
113
114 //__________________________________________________________________________
ea94c18b 115AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
8d0843c6 116{
117 /// Destructor for class AliMUONVTrackReconstructor
8d0843c6 118 delete [] fNHitsForRecPerChamber;
119 delete [] fIndexOfFirstHitForRecPerChamber;
8d0843c6 120 delete fHitsForRecPtr;
ea94c18b 121 delete fRecTracksPtr;
8d0843c6 122}
123
ea94c18b 124 //__________________________________________________________________________
125void AliMUONVTrackReconstructor::ResetHitsForRec()
126{
127 /// To reset the TClonesArray of HitsForRec,
128 /// and the number of HitForRec and the index of the first HitForRec per chamber
129 if (fHitsForRecPtr) fHitsForRecPtr->Clear("C");
130 fNHitsForRec = 0;
131 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
132 fNHitsForRecPerChamber[ch] = 0;
133 fIndexOfFirstHitForRecPerChamber[ch] = 0;
134 }
135}
136
137 //__________________________________________________________________________
138void AliMUONVTrackReconstructor::ResetTracks()
139{
140 /// To reset the TClonesArray of reconstructed tracks
141 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
142 fNRecTracks = 0;
143 return;
144}
145
146 //__________________________________________________________________________
147void AliMUONVTrackReconstructor::EventReconstruct(const AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
148{
149 /// To reconstruct one event
150 AliDebug(1,"");
151
152 ResetTracks();
153 ResetHitsForRec();
154 AddHitsForRecFromRawClusters(clusterStore);
155 MakeTracks();
156
157 // Add tracks to MUON data container
158 for (Int_t i=0; i<fNRecTracks; ++i)
159 {
160 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
161 trackStore.Add(*track);
162 }
163}
164
165 //__________________________________________________________________________
166void AliMUONVTrackReconstructor::AddHitsForRecFromRawClusters(const AliMUONVClusterStore& clusterStore)
7ec3b9cf 167{
168 /// Build internal array of hit for rec from clusterStore
169
170 TIter next(clusterStore.CreateIterator());
171 AliMUONRawCluster* clus(0x0);
172 Int_t iclus(0);
173
174 while ( ( clus = static_cast<AliMUONRawCluster*>(next()) ) )
175 {
176 // new AliMUONHitForRec from raw cluster
177 // and increment number of AliMUONHitForRec's (total and in chamber)
178 AliMUONHitForRec* hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
179 fNHitsForRec++;
180 // more information into HitForRec
181 hitForRec->SetBendingReso2(clus->GetErrY() * clus->GetErrY());
182 hitForRec->SetNonBendingReso2(clus->GetErrX() * clus->GetErrX());
183 // original raw cluster
184 Int_t ch = AliMpDEManager::GetChamberId(clus->GetDetElemId());
185 hitForRec->SetChamberNumber(ch);
186 hitForRec->SetHitNumber(iclus);
187 // Z coordinate of the raw cluster (cm)
188 hitForRec->SetZ(clus->GetZ(0));
189 if (AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 3) {
190 cout << "Chamber " << ch <<" raw cluster " << iclus << " : " << endl;
191 clus->Print("full");
192 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
193 hitForRec->Print("full");
194 }
195 ++iclus;
196 } // end of chamber loop
197
198 SortHitsForRecWithIncreasingChamber();
199
200 AliDebug(1,"End of AddHitsForRecFromRawClusters");
201
202 if (AliLog::GetGlobalDebugLevel() > 0)
203 {
204 AliDebug(1, Form("NHitsForRec: %d",fNHitsForRec));
205 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++)
206 {
207 AliDebug(1, Form("Chamber(0...): %d",ch));
208 AliDebug(1, Form("NHitsForRec: %d", fNHitsForRecPerChamber[ch]));
209 AliDebug(1, Form("Index(first HitForRec): %d", fIndexOfFirstHitForRecPerChamber[ch]));
210 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
211 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
212 hit++) {
213 AliDebug(1, Form("HitForRec index(0...): %d",hit));
214 ((*fHitsForRecPtr)[hit])->Dump();
215 }
216 }
217 }
218}
219
8d0843c6 220 //__________________________________________________________________________
221void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
222{
223 /// Sort HitsForRec's in increasing order with respect to chamber number.
224 /// Uses the function "Compare".
225 /// Update the information for HitsForRec per chamber too.
226 Int_t ch, nhits, prevch;
227 fHitsForRecPtr->Sort();
228 for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
229 fNHitsForRecPerChamber[ch] = 0;
230 fIndexOfFirstHitForRecPerChamber[ch] = 0;
231 }
232 prevch = 0; // previous chamber
233 nhits = 0; // number of hits in current chamber
234 // Loop over HitsForRec
235 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
236 // chamber number (0...)
237 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
238 // increment number of hits in current chamber
239 (fNHitsForRecPerChamber[ch])++;
240 // update index of first HitForRec in current chamber
241 // if chamber number different from previous one
242 if (ch != prevch) {
243 fIndexOfFirstHitForRecPerChamber[ch] = hit;
244 prevch = ch;
245 }
246 }
247 return;
248}
249
250 //__________________________________________________________________________
ea94c18b 251void AliMUONVTrackReconstructor::MakeTracks()
252{
253 /// To make the tracks from the list of segments and points in all stations
254 AliDebug(1,"Enter MakeTracks");
255 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
256 MakeTrackCandidates();
257 if (fRecTracksPtr->GetEntriesFast() == 0) return;
258 // Follow tracks in stations(1..) 3, 2 and 1
259 FollowTracks();
260 // Improve the reconstructed tracks
261 if (fgkImproveTracks) ImproveTracks();
262 // Remove double tracks
263 RemoveDoubleTracks();
264 // Fill AliMUONTrack data members
265 Finalize();
266}
267
268 //__________________________________________________________________________
208f139e 269TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
8d0843c6 270{
208f139e 271 /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
272 /// Return a new TClonesArray of segments.
273 /// It is the responsibility of the user to delete it afterward.
274 AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
275
8d0843c6 276 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
208f139e 277 AliMUONObjectPair *segment;
22ccc301 278 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
7ec3b9cf 279 // first and second chambers (0...) in the station
208f139e 280 Int_t ch1 = 2 * station;
8d0843c6 281 Int_t ch2 = ch1 + 1;
7ec3b9cf 282
208f139e 283 // list of segments
284 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
7ec3b9cf 285 segments->SetOwner(kTRUE);
286
208f139e 287 // Loop over HitForRec's in the first chamber of the station
8d0843c6 288 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
289 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
7ec3b9cf 290 hit1++)
291 {
8d0843c6 292 // pointer to the HitForRec
293 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
208f139e 294 // Loop over HitsForRec's in the second chamber of the station
8d0843c6 295 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
7ec3b9cf 296 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
297 hit2++)
298 {
8d0843c6 299 // pointer to the HitForRec
300 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
7ec3b9cf 301 if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. )
302 {
22ccc301 303 // bending slope
208f139e 304 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
305 // impact parameter
306 impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
307 // absolute value of bending momentum
7ec3b9cf 308 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
309 } else
310 {
208f139e 311 AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
312 continue;
313 }
22ccc301 314 // check for bending momentum within tolerances
7ec3b9cf 315 if ((bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum))
316 {
317 // make new segment
318 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
319 if (AliLog::GetGlobalDebugLevel() > 1) {
320 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
321 segment->Dump();
322 cout << "HitForRec in first chamber" << endl;
323 hit1Ptr->Dump();
324 cout << "HitForRec in second chamber" << endl;
325 hit2Ptr->Dump();
326 }
8d0843c6 327 }
328 } //for (Int_t hit2
329 } // for (Int_t hit1...
208f139e 330 AliDebug(1,Form("Station: %d NSegments: %d ", station, segments->GetEntriesFast()));
331 return segments;
8d0843c6 332}
333
ea94c18b 334 //__________________________________________________________________________
335void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
336{
337 /// To remove identical tracks:
338 /// Tracks are considered identical if they have all their hits in common.
339 /// One keeps the track with the larger number of hits if need be
340 AliMUONTrack *track1, *track2, *trackToRemove;
341 Int_t hitsInCommon, nHits1, nHits2;
342 Bool_t removedTrack1;
343 // Loop over first track of the pair
344 track1 = (AliMUONTrack*) fRecTracksPtr->First();
345 while (track1) {
346 removedTrack1 = kFALSE;
347 nHits1 = track1->GetNTrackHits();
348 // Loop over second track of the pair
349 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
350 while (track2) {
351 nHits2 = track2->GetNTrackHits();
352 // number of hits in common between two tracks
353 hitsInCommon = track1->HitsInCommon(track2);
354 // check for identical tracks
355 if ((hitsInCommon == nHits1) || (hitsInCommon == nHits2)) {
356 // decide which track to remove
357 if (nHits2 > nHits1) {
358 // remove track1 and continue the first loop with the track next to track1
359 trackToRemove = track1;
360 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
361 fRecTracksPtr->Remove(trackToRemove);
362 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
363 fNRecTracks--;
364 removedTrack1 = kTRUE;
365 break;
366 } else {
367 // remove track2 and continue the second loop with the track next to track2
368 trackToRemove = track2;
369 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
370 fRecTracksPtr->Remove(trackToRemove);
371 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
372 fNRecTracks--;
373 }
374 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
375 } // track2
376 if (removedTrack1) continue;
377 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
378 } // track1
379 return;
380}
381
382 //__________________________________________________________________________
383void AliMUONVTrackReconstructor::RemoveDoubleTracks()
384{
385 /// To remove double tracks:
386 /// Tracks are considered identical if more than half of the hits of the track
387 /// which has the smaller number of hits are in common with the other track.
388 /// Among two identical tracks, one keeps the track with the larger number of hits
389 /// or, if these numbers are equal, the track with the minimum chi2.
390 AliMUONTrack *track1, *track2, *trackToRemove;
391 Int_t hitsInCommon, nHits1, nHits2;
392 Bool_t removedTrack1;
393 // Loop over first track of the pair
394 track1 = (AliMUONTrack*) fRecTracksPtr->First();
395 while (track1) {
396 removedTrack1 = kFALSE;
397 nHits1 = track1->GetNTrackHits();
398 // Loop over second track of the pair
399 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
400 while (track2) {
401 nHits2 = track2->GetNTrackHits();
402 // number of hits in common between two tracks
403 hitsInCommon = track1->HitsInCommon(track2);
404 // check for identical tracks
405 if (((nHits1 < nHits2) && (2 * hitsInCommon > nHits1)) || (2 * hitsInCommon > nHits2)) {
406 // decide which track to remove
407 if ((nHits1 > nHits2) || ((nHits1 == nHits2) && (track1->GetFitFMin() <= track2->GetFitFMin()))) {
408 // remove track2 and continue the second loop with the track next to track2
409 trackToRemove = track2;
410 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
411 fRecTracksPtr->Remove(trackToRemove);
412 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
413 fNRecTracks--;
414 } else {
415 // else remove track1 and continue the first loop with the track next to track1
416 trackToRemove = track1;
417 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
418 fRecTracksPtr->Remove(trackToRemove);
419 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
420 fNRecTracks--;
421 removedTrack1 = kTRUE;
422 break;
423 }
424 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
425 } // track2
426 if (removedTrack1) continue;
427 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
428 } // track1
429 return;
430}
431
432 //__________________________________________________________________________
433Double_t AliMUONVTrackReconstructor::TryOneHitForRec(const AliMUONTrackParam &trackParam, AliMUONHitForRec* hitForRec,
434 AliMUONTrackParam &trackParamAtHit, Bool_t updatePropagator)
435{
436/// Test the compatibility between the track and the hitForRec (using trackParam's covariance matrix):
437/// return the corresponding Chi2
438/// return trackParamAtHit
439
440 if (!trackParam.CovariancesExist()) AliWarning(" track parameter covariance matrix does not exist");
441
442 // extrapolate track parameters and covariances at the z position of the tested hit
443 if (&trackParam != &trackParamAtHit) {
444 trackParamAtHit = trackParam;
445 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtHit, hitForRec->GetZ(), updatePropagator);
446 }
447
448 // set pointer to hit into trackParamAtHit
449 trackParamAtHit.SetHitForRecPtr(hitForRec);
450
451 // Set differences between trackParam and hitForRec in the bending and non bending directions
452 TMatrixD dPos(2,1);
453 dPos(0,0) = hitForRec->GetNonBendingCoor() - trackParamAtHit.GetNonBendingCoor();
454 dPos(1,0) = hitForRec->GetBendingCoor() - trackParamAtHit.GetBendingCoor();
455
456 // quick test of hitForRec compatibility within a wide road of x*y = 10*1 cm2 to save computing time
457 if (TMath::Abs(dPos(0,0)) > fgkMaxTrackingDistanceNonBending ||
458 TMath::Abs(dPos(1,0)) > fgkMaxTrackingDistanceBending) return 1.e10;
459
460 // Set the error matrix from trackParam covariances and hitForRec resolution
461 const TMatrixD& kParamCov = trackParamAtHit.GetCovariances();
462 TMatrixD error(2,2);
463 error(0,0) = kParamCov(0,0) + hitForRec->GetNonBendingReso2();
464 error(0,1) = kParamCov(0,2);
465 error(1,0) = kParamCov(2,0);
466 error(1,1) = kParamCov(2,2) + hitForRec->GetBendingReso2();
467
468 // Invert the error matrix for Chi2 calculation
469 if (error.Determinant() != 0) {
470 error.Invert();
471 } else {
472 AliWarning(" Determinant error=0");
473 return 1.e10;
474 }
475
476 // Compute the Chi2 value
477 TMatrixD tmp(dPos,TMatrixD::kTransposeMult,error);
478 TMatrixD result(tmp,TMatrixD::kMult,dPos);
479
480 return result(0,0);
481
482}
483
484 //__________________________________________________________________________
7ec3b9cf 485void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
486 const AliMUONVTriggerTrackStore& triggerTrackStore,
487 const AliMUONVTriggerStore& triggerStore,
488 const AliMUONTrackHitPattern& trackHitPattern)
8d0843c6 489{
490 /// Try to match track from tracking system with trigger track
06ca6d7b 491 static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
208f139e 492
7771752e 493 Int_t matchTrigger;
7ec3b9cf 494 Int_t loTrgNum(-1);
8d0843c6 495 Double_t distTriggerTrack[3];
208f139e 496 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
7ec3b9cf 497
498 TIter itTrack(trackStore.CreateIterator());
499 AliMUONTrack* track;
8d0843c6 500
7ec3b9cf 501 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
502 {
423b32ca 503 matchTrigger = 0;
8d0843c6 504 chi2MatchTrigger = 0.;
c6ba19f7 505 loTrgNum = -1;
7771752e 506 Int_t doubleMatch=-1; // Check if track matches 2 trigger tracks
507 Double_t doubleChi2 = -1.;
7ec3b9cf 508
509 AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last())));
37827b29 510 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
8d0843c6 511
512 xTrack = trackParam.GetNonBendingCoor();
513 yTrack = trackParam.GetBendingCoor();
514 ySlopeTrack = trackParam.GetBendingSlope();
208f139e 515 minChi2MatchTrigger = 999.;
7ec3b9cf 516
517 AliMUONTriggerTrack *triggerTrack;
518 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
519 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
520 {
06ca6d7b 521 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
522 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
523 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
208f139e 524 chi2 = 0.;
525 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
526 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
7ec3b9cf 527 if (chi2 < fMaxNormChi2MatchTrigger)
528 {
529 Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
530 if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger)
531 {
532 if(isDoubleTrack)
533 {
534 doubleMatch = loTrgNum;
535 doubleChi2 = chi2MatchTrigger;
536 }
537 minChi2MatchTrigger = chi2;
538 chi2MatchTrigger = chi2;
539 loTrgNum = triggerTrack->GetLoTrgNum();
540 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
541 matchTrigger=1;
542 if(locTrg->LoLpt()>0)matchTrigger=2;
543 if(locTrg->LoHpt()>0)matchTrigger=3;
544 }
545 else if(isDoubleTrack)
546 {
547 doubleMatch = triggerTrack->GetLoTrgNum();
548 doubleChi2 = chi2;
549 }
8d0843c6 550 }
8d0843c6 551 }
7ec3b9cf 552 if(doubleMatch>=0)
553 { // If two trigger tracks match, select the one passing more trigger cuts
554 AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
555 AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
556 if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
557 {
558 if(locTrg1->LoHpt()>0)matchTrigger=3;
559 else matchTrigger=2;
560 loTrgNum = doubleMatch;
561 chi2MatchTrigger=doubleChi2;
562 }
7771752e 563 }
8d0843c6 564
565 track->SetMatchTrigger(matchTrigger);
c6ba19f7 566 track->SetLoTrgNum(loTrgNum);
8d0843c6 567 track->SetChi2MatchTrigger(chi2MatchTrigger);
7ec3b9cf 568
569 AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
570
571 if (locTrg)
572 {
573 track->SetLocalTrigger(locTrg->LoCircuit(),
574 locTrg->LoStripX(),
575 locTrg->LoStripY(),
576 locTrg->LoDev(),
577 locTrg->LoLpt(),
578 locTrg->LoHpt());
579 }
580 }
581
582 trackHitPattern.GetHitPattern(trackStore,triggerStore);
8d0843c6 583}
584
ea94c18b 585 //__________________________________________________________________________
586void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
587 const AliMUONVTriggerStore& triggerStore,
588 AliMUONVTriggerTrackStore& triggerTrackStore)
8d0843c6 589{
71a2d3aa 590 /// To make the trigger tracks from Local Trigger
7ec3b9cf 591 AliDebug(1, "");
592
593 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
e6b25a6e 594
7ec3b9cf 595 UChar_t gloTrigPat = 0;
e6b25a6e 596
7ec3b9cf 597 if (globalTrigger)
598 {
599 gloTrigPat = globalTrigger->GetGlobalResponse();
e6b25a6e 600 }
601
7ec3b9cf 602 TIter next(triggerStore.CreateIterator());
603 AliMUONLocalTrigger* locTrg(0x0);
8d0843c6 604
e6b25a6e 605 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
606 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
7cf63da6 607
7ec3b9cf 608 AliMUONTriggerTrack triggerTrack;
609
610 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
611 {
612 Bool_t xTrig=kFALSE;
613 Bool_t yTrig=kFALSE;
614
32ab62c9 615 Int_t localBoardId = locTrg->LoCircuit();
7ec3b9cf 616 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
617 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
618 else xTrig=kTRUE; // trigger in X
619 if (locTrg->LoTrigY()==1 &&
620 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
621 else yTrig = kTRUE; // trigger in Y
622
623 if (xTrig && yTrig)
624 { // make Trigger Track if trigger in X and Y
8b0baca4 625
32ab62c9 626 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
7ec3b9cf 627 // need first to convert deviation to [0-30]
628 // (see AliMUONLocalTriggerBoard::LocalTrigger)
629 Int_t deviation = locTrg->LoDev();
630 Int_t sign = 0;
631 if ( !locTrg->LoSdev() && deviation ) sign=-1;
632 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
633 if ( locTrg->LoSdev() == 1 ) sign=+1;
634 deviation *= sign;
635 deviation += 15;
636 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
32ab62c9 637 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
638 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
7ec3b9cf 639
640 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
641 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
642
643 Float_t thetax = TMath::ATan2( x11 , z11 );
644 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
645
646 triggerTrack.SetX11(x11);
647 triggerTrack.SetY11(y11);
648 triggerTrack.SetThetax(thetax);
649 triggerTrack.SetThetay(thetay);
650 triggerTrack.SetGTPattern(gloTrigPat);
32ab62c9 651 triggerTrack.SetLoTrgNum(localBoardId);
7ec3b9cf 652
653 triggerTrackStore.Add(triggerTrack);
654 } // board is fired
e6b25a6e 655 } // end of loop on Local Trigger
8d0843c6 656}
ea94c18b 657