DQM histogram ranges updated. Added new methods. More details in class description...
[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
3d1463c8 18//-----------------------------------------------------------------------------
c4ee792d 19/// \class AliMUONVTrackReconstructor
06ca6d7b 20/// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
21///
96ebe67e 22/// This class contains as data a pointer to the array of reconstructed tracks
06ca6d7b 23///
24/// It contains as methods, among others:
25/// * EventReconstruct to build the muon tracks
26/// * EventReconstructTrigger to build the trigger tracks
96ebe67e 27/// * ValidateTracksWithTrigger to match tracker/trigger tracks
06ca6d7b 28///
96ebe67e 29/// Several options and adjustable parameters are available for both KALMAN and ORIGINAL
ad3c6eda 30/// tracking algorithms. They can be changed through the AliMUONRecoParam object
31/// set in the reconstruction macro or read from the CDB
32/// (see methods in AliMUONRecoParam.h file for details)
96ebe67e 33///
34/// Main parameters and options are:
dfb547bf 35/// - *fgkSigmaToCutForTracking* : quality cut used to select new clusters to be
36/// attached to the track candidate and to select good tracks.
019df241 37/// - *fgkMakeTrackCandidatesFast* : if this flag is set to 'true', the track candidates
38/// are made assuming linear propagation between stations 4 and 5.
dfb547bf 39/// - *fgkTrackAllTracks* : according to the value of this flag, in case that several
40/// new clusters pass the quality cut, either we consider all the possibilities
41/// (duplicating tracks) or we attach only the best cluster.
42/// - *fgkRecoverTracks* : if this flag is set to 'true', we try to recover the tracks
43/// lost during the tracking by removing the worst of the 2 clusters attached in the
44/// previous station.
45/// - *fgkImproveTracks* : if this flag is set to 'true', we try to improve the quality
46/// of the tracks at the end of the tracking by removing clusters that do not pass
3304fa09 47/// new quality cut (the track is removed is it does not contain enough cluster anymore).
48/// - *fgkComplementTracks* : if this flag is set to 'true', we try to improve the quality
49/// of the tracks at the end of the tracking by adding potentially missing clusters
50/// (we may have 2 clusters in the same chamber because of the overlapping of detection
51/// elements, which is not handle by the tracking algorithm).
dfb547bf 52/// - *fgkSigmaToCutForImprovement* : quality cut used when we try to improve the
53/// quality of the tracks.
54///
c4ee792d 55/// \author Philippe Pillot
3d1463c8 56//-----------------------------------------------------------------------------
8d0843c6 57
8d0843c6 58#include "AliMUONVTrackReconstructor.h"
7ec3b9cf 59
8d0843c6 60#include "AliMUONConstants.h"
208f139e 61#include "AliMUONObjectPair.h"
8d0843c6 62#include "AliMUONTriggerTrack.h"
e1a10d41 63#include "AliMUONTriggerCircuit.h"
8d0843c6 64#include "AliMUONLocalTrigger.h"
65#include "AliMUONGlobalTrigger.h"
8d0843c6 66#include "AliMUONTrack.h"
37827b29 67#include "AliMUONTrackParam.h"
68#include "AliMUONTrackExtrap.h"
7771752e 69#include "AliMUONTrackHitPattern.h"
7ec3b9cf 70#include "AliMUONVTrackStore.h"
71#include "AliMUONVClusterStore.h"
2060b217 72#include "AliMUONVCluster.h"
1fef78c8 73#include "AliMUONVClusterServer.h"
7ec3b9cf 74#include "AliMUONVTriggerStore.h"
75#include "AliMUONVTriggerTrackStore.h"
5a240757 76#include "AliMUONRecoParam.h"
77
ea94c18b 78#include "AliMpDEManager.h"
1fef78c8 79#include "AliMpArea.h"
ea94c18b 80
bdfb6eef 81#include "AliMpDDLStore.h"
82#include "AliMpVSegmentation.h"
83#include "AliMpSegmentation.h"
84#include "AliMpPad.h"
85
ea94c18b 86#include "AliLog.h"
b709ac13 87#include "AliCodeTimer.h"
ea94c18b 88#include "AliTracker.h"
8d0843c6 89
4889d34c 90#include <TClonesArray.h>
91#include <TMath.h>
ea94c18b 92#include <TMatrixD.h>
1fef78c8 93#include <TVector2.h>
ea94c18b 94
95#include <Riostream.h>
4889d34c 96
78649106 97/// \cond CLASSIMP
8d0843c6 98ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
78649106 99/// \endcond
8d0843c6 100
ea94c18b 101 //__________________________________________________________________________
a0dc65b4 102AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(const AliMUONRecoParam* recoParam,
103 AliMUONVClusterServer* clusterServer)
104: TObject(),
105fRecTracksPtr(0x0),
106fNRecTracks(0),
107fClusterServer(clusterServer),
6b191dea 108fkRecoParam(recoParam),
4663da9f 109fMaxMCSAngle2(0x0)
8d0843c6 110{
111 /// Constructor for class AliMUONVTrackReconstructor
b1fea02e 112 /// WARNING: if clusterServer=0x0, no clusterization will be possible at this level
ea94c18b 113
114 // Memory allocation for the TClonesArray of reconstructed tracks
96ebe67e 115 fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
7ec3b9cf 116
208f139e 117 // set the magnetic field for track extrapolations
f7a1cc68 118 AliMUONTrackExtrap::SetField();
6b191dea 119
120 // set the maximum MCS angle in chamber from the minimum acceptable momentum
121 AliMUONTrackParam param;
122 Double_t inverseBendingP = (GetRecoParam()->GetMinBendingMomentum() > 0.) ? 1./GetRecoParam()->GetMinBendingMomentum() : 1.;
123 param.SetInverseBendingMomentum(inverseBendingP);
4663da9f 124 fMaxMCSAngle2 = new Double_t [AliMUONConstants::NTrackingCh()];
125 for (Int_t iCh=0; iCh<AliMUONConstants::NTrackingCh(); iCh++)
126 fMaxMCSAngle2[iCh] = AliMUONTrackExtrap::GetMCSAngle2(param, AliMUONConstants::ChamberThicknessInX0(iCh), 1.);
6b191dea 127
8d0843c6 128}
129
130 //__________________________________________________________________________
ea94c18b 131AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
8d0843c6 132{
133 /// Destructor for class AliMUONVTrackReconstructor
ea94c18b 134 delete fRecTracksPtr;
4663da9f 135 delete[] fMaxMCSAngle2;
8d0843c6 136}
137
ea94c18b 138 //__________________________________________________________________________
ea94c18b 139void AliMUONVTrackReconstructor::ResetTracks()
140{
141 /// To reset the TClonesArray of reconstructed tracks
142 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
143 fNRecTracks = 0;
144 return;
145}
146
147 //__________________________________________________________________________
1fef78c8 148void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
ea94c18b 149{
150 /// To reconstruct one event
151 AliDebug(1,"");
99c136e1 152 AliCodeTimerAuto("",0);
ea94c18b 153
96ebe67e 154 // Reset array of tracks
ea94c18b 155 ResetTracks();
2060b217 156
89c8d66d 157 // Look for candidates from clusters in stations(1..) 4 and 5 (abort in case of failure)
158 if (!MakeTrackCandidates(clusterStore)) return;
96ebe67e 159
89c8d66d 160 // Look for extra candidates from clusters in stations(1..) 4 and 5 (abort in case of failure)
161 if (GetRecoParam()->MakeMoreTrackCandidates()) {
162 if (!MakeMoreTrackCandidates(clusterStore)) return;
163 }
9bf6860b 164
96ebe67e 165 // Stop tracking if no candidate found
ea94c18b 166 if (fRecTracksPtr->GetEntriesFast() == 0) return;
96ebe67e 167
89c8d66d 168 // Follow tracks in stations(1..) 3, 2 and 1 (abort in case of failure)
169 if (!FollowTracks(clusterStore)) return;
96ebe67e 170
b709ac13 171 // Complement the reconstructed tracks
89c8d66d 172 if (GetRecoParam()->ComplementTracks()) {
173 if (ComplementTracks(clusterStore)) RemoveIdenticalTracks();
174 }
96ebe67e 175
ea94c18b 176 // Improve the reconstructed tracks
a0dc65b4 177 if (GetRecoParam()->ImproveTracks()) ImproveTracks();
96ebe67e 178
c59f70b9 179 // Remove connected tracks
5c15a68b 180 RemoveConnectedTracks(3, 4, kFALSE);
181 RemoveConnectedTracks(2, 2, kFALSE);
182 if (GetRecoParam()->RemoveConnectedTracksInSt12()) RemoveConnectedTracks(0, 1, kFALSE);
96ebe67e 183
ea94c18b 184 // Fill AliMUONTrack data members
185 Finalize();
5c15a68b 186 if (!GetRecoParam()->RemoveConnectedTracksInSt12()) TagConnectedTracks(0, 1, kTRUE);
96ebe67e 187
188 // Add tracks to MUON data container
5c15a68b 189 for (Int_t i=0; i<fNRecTracks; ++i)
96ebe67e 190 {
191 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
4ea3f013 192 if (track->GetGlobalChi2() < AliMUONTrack::MaxChi2()) {
193 track->SetUniqueID(i+1);
194 trackStore.Add(*track);
195 } else AliWarning("problem occur somewhere during track refitting --> discard track");
96ebe67e 196 }
ea94c18b 197}
198
6b191dea 199//__________________________________________________________________________
200Bool_t AliMUONVTrackReconstructor::IsAcceptable(AliMUONTrackParam &trackParam)
201{
202 /// Return kTRUE if the track is within given limits on momentum/angle/origin
203
204 const TMatrixD& kParamCov = trackParam.GetCovariances();
205 Int_t chamber = trackParam.GetClusterPtr()->GetChamberId();
206 Double_t z = trackParam.GetZ();
207 Double_t sigmaCut = GetRecoParam()->GetSigmaCutForTracking();
208
209 // MCS dipersion
210 Double_t angleMCS2 = 0.;
6b191dea 211 Double_t impactMCS2 = 0.;
4663da9f 212 if (AliMUONTrackExtrap::IsFieldON() && chamber < 6) {
213
214 // track momentum is known
215 for (Int_t iCh=0; iCh<=chamber; iCh++) {
216 Double_t localMCS2 = AliMUONTrackExtrap::GetMCSAngle2(trackParam, AliMUONConstants::ChamberThicknessInX0(iCh), 1.);
217 angleMCS2 += localMCS2;
218 impactMCS2 += AliMUONConstants::DefaultChamberZ(chamber) * AliMUONConstants::DefaultChamberZ(chamber) * localMCS2;
219 }
220
221 } else {
222
223 // track momentum is unknown
224 for (Int_t iCh=0; iCh<=chamber; iCh++) {
225 angleMCS2 += fMaxMCSAngle2[iCh];
226 impactMCS2 += AliMUONConstants::DefaultChamberZ(chamber) * AliMUONConstants::DefaultChamberZ(chamber) * fMaxMCSAngle2[iCh];
227 }
228
229 }
6b191dea 230
231 // ------ track selection in non bending direction ------
232 if (GetRecoParam()->SelectOnTrackSlope()) {
233
234 // check if non bending slope is within tolerances
4663da9f 235 Double_t nonBendingSlopeErr = TMath::Sqrt(kParamCov(1,1) + angleMCS2);
6b191dea 236 if ((TMath::Abs(trackParam.GetNonBendingSlope()) - sigmaCut * nonBendingSlopeErr) > GetRecoParam()->GetMaxNonBendingSlope()) return kFALSE;
237
238 } else {
239
240 // or check if non bending impact parameter is within tolerances
241 Double_t nonBendingImpactParam = TMath::Abs(trackParam.GetNonBendingCoor() - z * trackParam.GetNonBendingSlope());
242 Double_t nonBendingImpactParamErr = TMath::Sqrt(kParamCov(0,0) + z * z * kParamCov(1,1) - 2. * z * kParamCov(0,1) + impactMCS2);
243 if ((nonBendingImpactParam - sigmaCut * nonBendingImpactParamErr) > (3. * GetRecoParam()->GetNonBendingVertexDispersion())) return kFALSE;
244
245 }
246
247 // ------ track selection in bending direction ------
248 if (AliMUONTrackExtrap::IsFieldON()) { // depending whether the field is ON or OFF
249
250 // check if bending momentum is within tolerances
251 Double_t bendingMomentum = TMath::Abs(1. / trackParam.GetInverseBendingMomentum());
252 Double_t bendingMomentumErr = TMath::Sqrt(kParamCov(4,4)) * bendingMomentum * bendingMomentum;
253 if (chamber < 6 && (bendingMomentum + sigmaCut * bendingMomentumErr) < GetRecoParam()->GetMinBendingMomentum()) return kFALSE;
254 else if ((bendingMomentum + 3. * bendingMomentumErr) < GetRecoParam()->GetMinBendingMomentum()) return kFALSE;
255
256 } else {
257
258 if (GetRecoParam()->SelectOnTrackSlope()) {
259
260 // check if bending slope is within tolerances
4663da9f 261 Double_t bendingSlopeErr = TMath::Sqrt(kParamCov(3,3) + angleMCS2);
6b191dea 262 if ((TMath::Abs(trackParam.GetBendingSlope()) - sigmaCut * bendingSlopeErr) > GetRecoParam()->GetMaxBendingSlope()) return kFALSE;
263
264 } else {
265
266 // or check if bending impact parameter is within tolerances
267 Double_t bendingImpactParam = TMath::Abs(trackParam.GetBendingCoor() - z * trackParam.GetBendingSlope());
268 Double_t bendingImpactParamErr = TMath::Sqrt(kParamCov(2,2) + z * z * kParamCov(3,3) - 2. * z * kParamCov(2,3) + impactMCS2);
269 if ((bendingImpactParam - sigmaCut * bendingImpactParamErr) > (3. * GetRecoParam()->GetBendingVertexDispersion())) return kFALSE;
270
271 }
272
273 }
274
275 return kTRUE;
276
277}
278
279//__________________________________________________________________________
9bf6860b 280TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliMUONVClusterStore& clusterStore, Int_t ch1, Int_t ch2)
8d0843c6 281{
9bf6860b 282 /// To make the list of segments from the list of clusters in the 2 given chambers.
208f139e 283 /// Return a new TClonesArray of segments.
284 /// It is the responsibility of the user to delete it afterward.
9bf6860b 285 AliDebug(1,Form("Enter MakeSegmentsBetweenChambers (1..) %d-%d", ch1+1, ch2+1));
99c136e1 286 AliCodeTimerAuto("",0);
208f139e 287
96ebe67e 288 AliMUONVCluster *cluster1, *cluster2;
208f139e 289 AliMUONObjectPair *segment;
6b191dea 290 Double_t z1 = 0., z2 = 0., dZ = 0.;
291 Double_t nonBendingSlope = 0., nonBendingSlopeErr = 0., nonBendingImpactParam = 0., nonBendingImpactParamErr = 0.;
292 Double_t bendingSlope = 0., bendingSlopeErr = 0., bendingImpactParam = 0., bendingImpactParamErr = 0., bendingImpactParamErr2 = 0.;
293 Double_t bendingMomentum = 0., bendingMomentumErr = 0.;
294 Double_t bendingVertexDispersion2 = GetRecoParam()->GetBendingVertexDispersion() * GetRecoParam()->GetBendingVertexDispersion();
4663da9f 295 Double_t angleMCS2 = 0.; // maximum angular dispersion**2 due to MCS in chamber
296 Double_t impactMCS2 = 0.; // maximum impact parameter dispersion**2 due to MCS in chamber
297 for (Int_t iCh=0; iCh<=ch1; iCh++) {
298 angleMCS2 += fMaxMCSAngle2[iCh];
299 impactMCS2 += AliMUONConstants::DefaultChamberZ(iCh) * AliMUONConstants::DefaultChamberZ(iCh) * fMaxMCSAngle2[iCh];
300 }
6b191dea 301 Double_t sigmaCut = GetRecoParam()->GetSigmaCutForTracking();
7ec3b9cf 302
96ebe67e 303 // Create iterators to loop over clusters in both chambers
304 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
305 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
306
208f139e 307 // list of segments
96ebe67e 308 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
7ec3b9cf 309
96ebe67e 310 // Loop over clusters in the first chamber of the station
311 while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
6b191dea 312 z1 = cluster1->GetZ();
96ebe67e 313
314 // reset cluster iterator of chamber 2
315 nextInCh2.Reset();
316
317 // Loop over clusters in the second chamber of the station
318 while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
6b191dea 319 z2 = cluster2->GetZ();
320 dZ = z1 - z2;
96ebe67e 321
6b191dea 322 // ------ track selection in non bending direction ------
323 nonBendingSlope = (cluster1->GetX() - cluster2->GetX()) / dZ;
324 if (GetRecoParam()->SelectOnTrackSlope()) {
9f093251 325
6b191dea 326 // check if non bending slope is within tolerances
4663da9f 327 nonBendingSlopeErr = TMath::Sqrt((cluster1->GetErrX2() + cluster2->GetErrX2()) / dZ / dZ + angleMCS2);
6b191dea 328 if ((TMath::Abs(nonBendingSlope) - sigmaCut * nonBendingSlopeErr) > GetRecoParam()->GetMaxNonBendingSlope()) continue;
9f093251 329
6b191dea 330 } else {
331
332 // or check if non bending impact parameter is within tolerances
333 nonBendingImpactParam = TMath::Abs(cluster1->GetX() - cluster1->GetZ() * nonBendingSlope);
334 nonBendingImpactParamErr = TMath::Sqrt((z1 * z1 * cluster2->GetErrX2() + z2 * z2 * cluster1->GetErrX2()) / dZ / dZ + impactMCS2);
335 if ((nonBendingImpactParam - sigmaCut * nonBendingImpactParamErr) > (3. * GetRecoParam()->GetNonBendingVertexDispersion())) continue;
336
337 }
338
339 // ------ track selection in bending direction ------
340 bendingSlope = (cluster1->GetY() - cluster2->GetY()) / dZ;
341 if (AliMUONTrackExtrap::IsFieldON()) { // depending whether the field is ON or OFF
9f093251 342
343 // check if bending momentum is within tolerances
6b191dea 344 bendingImpactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
345 bendingImpactParamErr2 = (z1 * z1 * cluster2->GetErrY2() + z2 * z2 * cluster1->GetErrY2()) / dZ / dZ + impactMCS2;
346 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(bendingImpactParam));
347 bendingMomentumErr = TMath::Sqrt((bendingVertexDispersion2 + bendingImpactParamErr2) /
348 bendingImpactParam / bendingImpactParam + 0.01) * bendingMomentum;
349 if ((bendingMomentum + 3. * bendingMomentumErr) < GetRecoParam()->GetMinBendingMomentum()) continue;
96ebe67e 350
9f093251 351 } else {
352
6b191dea 353 if (GetRecoParam()->SelectOnTrackSlope()) {
354
355 // check if bending slope is within tolerances
4663da9f 356 bendingSlopeErr = TMath::Sqrt((cluster1->GetErrY2() + cluster2->GetErrY2()) / dZ / dZ + angleMCS2);
6b191dea 357 if ((TMath::Abs(bendingSlope) - sigmaCut * bendingSlopeErr) > GetRecoParam()->GetMaxBendingSlope()) continue;
358
359 } else {
360
361 // or check if bending impact parameter is within tolerances
362 bendingImpactParam = TMath::Abs(cluster1->GetY() - cluster1->GetZ() * bendingSlope);
363 bendingImpactParamErr = TMath::Sqrt((z1 * z1 * cluster2->GetErrY2() + z2 * z2 * cluster1->GetErrY2()) / dZ / dZ + impactMCS2);
364 if ((bendingImpactParam - sigmaCut * bendingImpactParamErr) > (3. * GetRecoParam()->GetBendingVertexDispersion())) continue;
365
366 }
367
9f093251 368 }
6b191dea 369
9f093251 370 // make new segment
371 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
372
373 // Printout for debug
374 if (AliLog::GetGlobalDebugLevel() > 1) {
375 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
376 segment->Dump();
377 cout << "Cluster in first chamber" << endl;
378 cluster1->Print();
379 cout << "Cluster in second chamber" << endl;
380 cluster2->Print();
8d0843c6 381 }
96ebe67e 382
383 }
384
385 }
386
387 // Printout for debug
9bf6860b 388 AliDebug(1,Form("chambers%d-%d: NSegments = %d ", ch1+1, ch2+1, segments->GetEntriesFast()));
96ebe67e 389
208f139e 390 return segments;
8d0843c6 391}
392
ea94c18b 393 //__________________________________________________________________________
89c8d66d 394void AliMUONVTrackReconstructor::RemoveUsedSegments(TClonesArray& segments)
395{
396 /// To remove pairs of clusters already attached to a track
397 AliDebug(1,"Enter RemoveUsedSegments");
398 Int_t nSegments = segments.GetEntriesFast();
399 Int_t nTracks = fRecTracksPtr->GetEntriesFast();
400 AliMUONObjectPair *segment;
401 AliMUONTrack *track;
402 AliMUONVCluster *cluster, *cluster1, *cluster2;
403 Bool_t foundCluster1, foundCluster2, removeSegment;
404
405 // Loop over segments
406 for (Int_t iSegment=0; iSegment<nSegments; iSegment++) {
407 segment = (AliMUONObjectPair*) segments.UncheckedAt(iSegment);
408
409 cluster1 = (AliMUONVCluster*) segment->First();
410 cluster2 = (AliMUONVCluster*) segment->Second();
411 removeSegment = kFALSE;
412
413 // Loop over tracks
414 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
415 track = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack);
416
417 // skip empty slot
418 if (!track) continue;
419
420 foundCluster1 = kFALSE;
421 foundCluster2 = kFALSE;
422
423 // Loop over clusters
424 Int_t nClusters = track->GetNClusters();
425 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
426 cluster = ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iCluster))->GetClusterPtr();
427
428 // check if both clusters are in that track
429 if (cluster == cluster1) foundCluster1 = kTRUE;
430 else if (cluster == cluster2) foundCluster2 = kTRUE;
431
432 if (foundCluster1 && foundCluster2) {
433 removeSegment = kTRUE;
434 break;
435 }
436
437 }
438
439 if (removeSegment) break;
440
441 }
442
443 if (removeSegment) segments.RemoveAt(iSegment);
444
445 }
446
447 segments.Compress();
448
449 // Printout for debug
450 AliDebug(1,Form("NSegments = %d ", segments.GetEntriesFast()));
451}
452
453 //__________________________________________________________________________
ea94c18b 454void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
455{
456 /// To remove identical tracks:
96ebe67e 457 /// Tracks are considered identical if they have all their clusters in common.
458 /// One keeps the track with the larger number of clusters if need be
89c8d66d 459 AliMUONTrack *track1, *track2;
460 Int_t nTracks = fRecTracksPtr->GetEntriesFast();
96ebe67e 461 Int_t clustersInCommon, nClusters1, nClusters2;
ea94c18b 462 // Loop over first track of the pair
89c8d66d 463 for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
464 track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
465 // skip empty slot
466 if (!track1) continue;
96ebe67e 467 nClusters1 = track1->GetNClusters();
ea94c18b 468 // Loop over second track of the pair
89c8d66d 469 for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
470 track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
471 // skip empty slot
472 if (!track2) continue;
96ebe67e 473 nClusters2 = track2->GetNClusters();
474 // number of clusters in common between two tracks
475 clustersInCommon = track1->ClustersInCommon(track2);
ea94c18b 476 // check for identical tracks
96ebe67e 477 if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
ea94c18b 478 // decide which track to remove
96ebe67e 479 if (nClusters2 > nClusters1) {
ea94c18b 480 // remove track1 and continue the first loop with the track next to track1
89c8d66d 481 fRecTracksPtr->RemoveAt(iTrack1);
ea94c18b 482 fNRecTracks--;
ea94c18b 483 break;
484 } else {
485 // remove track2 and continue the second loop with the track next to track2
89c8d66d 486 fRecTracksPtr->RemoveAt(iTrack2);
ea94c18b 487 fNRecTracks--;
488 }
89c8d66d 489 }
ea94c18b 490 } // track2
ea94c18b 491 } // track1
89c8d66d 492 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
ea94c18b 493}
494
495 //__________________________________________________________________________
496void AliMUONVTrackReconstructor::RemoveDoubleTracks()
497{
498 /// To remove double tracks:
96ebe67e 499 /// Tracks are considered identical if more than half of the clusters of the track
500 /// which has the smaller number of clusters are in common with the other track.
501 /// Among two identical tracks, one keeps the track with the larger number of clusters
ea94c18b 502 /// or, if these numbers are equal, the track with the minimum chi2.
89c8d66d 503 AliMUONTrack *track1, *track2;
504 Int_t nTracks = fRecTracksPtr->GetEntriesFast();
505 Int_t clustersInCommon2, nClusters1, nClusters2;
ea94c18b 506 // Loop over first track of the pair
89c8d66d 507 for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
508 track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
509 // skip empty slot
510 if (!track1) continue;
96ebe67e 511 nClusters1 = track1->GetNClusters();
ea94c18b 512 // Loop over second track of the pair
89c8d66d 513 for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
514 track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
515 // skip empty slot
516 if (!track2) continue;
96ebe67e 517 nClusters2 = track2->GetNClusters();
518 // number of clusters in common between two tracks
89c8d66d 519 clustersInCommon2 = 2 * track1->ClustersInCommon(track2);
ea94c18b 520 // check for identical tracks
89c8d66d 521 if (clustersInCommon2 > nClusters1 || clustersInCommon2 > nClusters2) {
ea94c18b 522 // decide which track to remove
96ebe67e 523 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
ea94c18b 524 // remove track2 and continue the second loop with the track next to track2
89c8d66d 525 fRecTracksPtr->RemoveAt(iTrack2);
c59f70b9 526 fNRecTracks--;
527 } else {
528 // else remove track1 and continue the first loop with the track next to track1
89c8d66d 529 fRecTracksPtr->RemoveAt(iTrack1);
c59f70b9 530 fNRecTracks--;
c59f70b9 531 break;
532 }
89c8d66d 533 }
c59f70b9 534 } // track2
c59f70b9 535 } // track1
89c8d66d 536 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
c59f70b9 537}
538
539 //__________________________________________________________________________
5c15a68b 540void AliMUONVTrackReconstructor::RemoveConnectedTracks(Int_t stMin, Int_t stMax, Bool_t all)
c59f70b9 541{
5c15a68b 542 /// Find and remove tracks sharing 1 cluster or more in station(s) [stMin, stMax].
543 /// For each couple of connected tracks, one removes the one with the smallest
544 /// number of clusters or with the highest chi2 value in case of equality.
545 /// If all=kTRUE: both tracks are removed.
546
547 // tag the tracks to be removed
548 TagConnectedTracks(stMin, stMax, all);
549
550 // remove them
551 Int_t nTracks = fRecTracksPtr->GetEntriesFast();
552 for (Int_t i = 0; i < nTracks; i++) {
553 if (((AliMUONTrack*) fRecTracksPtr->UncheckedAt(i))->IsConnected()) {
554 fRecTracksPtr->RemoveAt(i);
555 fNRecTracks--;
556 }
557 }
558
559 // remove holes in the array if any
560 fRecTracksPtr->Compress();
561}
562
563 //__________________________________________________________________________
564void AliMUONVTrackReconstructor::TagConnectedTracks(Int_t stMin, Int_t stMax, Bool_t all)
565{
566 /// Find and tag tracks sharing 1 cluster or more in station(s) [stMin, stMax].
567 /// For each couple of connected tracks, one tags the one with the smallest
568 /// number of clusters or with the highest chi2 value in case of equality.
569 /// If all=kTRUE: both tracks are tagged.
570
571 AliMUONTrack *track1, *track2;
572 Int_t nClusters1, nClusters2;
573 Int_t nTracks = fRecTracksPtr->GetEntriesFast();
574
575 // reset the tags
576 for (Int_t i = 0; i < nTracks; i++) ((AliMUONTrack*) fRecTracksPtr->UncheckedAt(i))->Connected(kFALSE);
577
c59f70b9 578 // Loop over first track of the pair
5c15a68b 579 for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
580 track1 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack1);
581
c59f70b9 582 // Loop over second track of the pair
5c15a68b 583 for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
584 track2 = (AliMUONTrack*) fRecTracksPtr->UncheckedAt(iTrack2);
585
586 // check for connected tracks and tag them
587 if (track1->ClustersInCommon(track2, stMin, stMax) > 0) {
588
589 if (all) {
590
591 // tag both tracks
592 track1->Connected();
593 track2->Connected();
594
595 } else {
596
597 // tag only the worst track
598 nClusters1 = track1->GetNClusters();
599 nClusters2 = track2->GetNClusters();
600 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
601 track2->Connected();
602 } else {
603 track1->Connected();
604 }
605
606 }
607
608 }
609
610 }
611
612 }
613
ea94c18b 614}
615
616 //__________________________________________________________________________
9bf6860b 617void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackParam &trackParam,
618 AliMUONVClusterStore& clusterStore, Int_t chamber)
1fef78c8 619{
620 /// Ask the clustering to reconstruct new clusters around the track candidate position
1fef78c8 621
9bf6860b 622 // check if the current chamber is useable
a0dc65b4 623 if (!fClusterServer || !GetRecoParam()->UseChamber(chamber)) return;
1fef78c8 624
9bf6860b 625 // maximum distance between the center of the chamber and a detection element
626 // (accounting for the inclination of the chamber)
b89ac3d6 627 static const Double_t kMaxDZ = 15.; // 15 cm
1fef78c8 628
9bf6860b 629 // extrapolate track parameters to the chamber
630 AliMUONTrackParam extrapTrackParam(trackParam);
4ea3f013 631 if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(chamber))) return;
9bf6860b 632
6b191dea 633 // build the searching area using the track and chamber resolutions and the maximum-distance-to-track value
9bf6860b 634 const TMatrixD& kParamCov = extrapTrackParam.GetCovariances();
6b191dea 635 Double_t errX2 = kParamCov(0,0) + kMaxDZ * kMaxDZ * kParamCov(1,1) + 2. * kMaxDZ * TMath::Abs(kParamCov(0,1)) +
636 GetRecoParam()->GetDefaultNonBendingReso(chamber) * GetRecoParam()->GetDefaultNonBendingReso(chamber);
637 Double_t errY2 = kParamCov(2,2) + kMaxDZ * kMaxDZ * kParamCov(3,3) + 2. * kMaxDZ * TMath::Abs(kParamCov(2,3)) +
638 GetRecoParam()->GetDefaultBendingReso(chamber) * GetRecoParam()->GetDefaultBendingReso(chamber);
b89ac3d6 639 Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * kMaxDZ +
a0dc65b4 640 GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
6b191dea 641 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(2. * errX2);
b89ac3d6 642 Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * kMaxDZ +
a0dc65b4 643 GetRecoParam()->GetMaxBendingDistanceToTrack() +
6b191dea 644 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(2. * errY2);
6e97fbb8 645 AliMpArea area(extrapTrackParam.GetNonBendingCoor(),
646 extrapTrackParam.GetBendingCoor(),
647 dX, dY);
1fef78c8 648
649 // ask to cluterize in the given area of the given chamber
35be7ed7 650 fClusterServer->Clusterize(chamber, clusterStore, area, GetRecoParam());
1fef78c8 651
9bf6860b 652}
653
654 //__________________________________________________________________________
655void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
656 AliMUONVClusterStore& clusterStore, Int_t station)
657{
658 /// Ask the clustering to reconstruct new clusters around the track candidate position
659 /// in the 2 chambers of the given station
660 AskForNewClustersInChamber(trackParam, clusterStore, 2*station+1);
661 AskForNewClustersInChamber(trackParam, clusterStore, 2*station);
1fef78c8 662}
663
664 //__________________________________________________________________________
96ebe67e 665Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
1fef78c8 666 AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
ea94c18b 667{
96ebe67e 668/// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
ea94c18b 669/// return the corresponding Chi2
96ebe67e 670/// return trackParamAtCluster
ea94c18b 671
96ebe67e 672 // extrapolate track parameters and covariances at the z position of the tested cluster
4ea3f013 673 // and set pointer to cluster into trackParamAtCluster
96ebe67e 674 trackParamAtCluster = trackParam;
96ebe67e 675 trackParamAtCluster.SetClusterPtr(cluster);
4ea3f013 676 if (!AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator))
677 return 2.*AliMUONTrack::MaxChi2();
ea94c18b 678
96ebe67e 679 // Set differences between trackParam and cluster in the bending and non bending directions
680 Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
681 Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
ea94c18b 682
019df241 683 // Calculate errors and covariances
96ebe67e 684 const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
685 Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
686 Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
6b191dea 687 Double_t covXY = kParamCov(0,2);
688 Double_t det = sigmaX2 * sigmaY2 - covXY * covXY;
019df241 689
690 // Compute chi2
4ea3f013 691 if (det == 0.) return 2.*AliMUONTrack::MaxChi2();
6b191dea 692 return (dX * dX * sigmaY2 + dY * dY * sigmaX2 - 2. * dX * dY * covXY) / det;
019df241 693
694}
695
696 //__________________________________________________________________________
5a240757 697Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, const AliMUONVCluster* cluster)
019df241 698{
9bf6860b 699/// Test the compatibility between the track and the cluster
6b191dea 700/// given the track and cluster resolutions + the maximum-distance-to-track value
9bf6860b 701/// and assuming linear propagation of the track:
019df241 702/// return kTRUE if they are compatibles
703
96ebe67e 704 Double_t dZ = cluster->GetZ() - trackParam.GetZ();
705 Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
706 Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
9bf6860b 707 const TMatrixD& kParamCov = trackParam.GetCovariances();
6b191dea 708 Double_t errX2 = kParamCov(0,0) + dZ * dZ * kParamCov(1,1) + 2. * dZ * kParamCov(0,1) + cluster->GetErrX2();
709 Double_t errY2 = kParamCov(2,2) + dZ * dZ * kParamCov(3,3) + 2. * dZ * kParamCov(2,3) + cluster->GetErrY2();
9bf6860b 710
6b191dea 711 Double_t dXmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(2. * errX2) +
a0dc65b4 712 GetRecoParam()->GetMaxNonBendingDistanceToTrack();
6b191dea 713 Double_t dYmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(2. * errY2) +
a0dc65b4 714 GetRecoParam()->GetMaxBendingDistanceToTrack();
019df241 715
9bf6860b 716 if (TMath::Abs(dX) > dXmax || TMath::Abs(dY) > dYmax) return kFALSE;
019df241 717
718 return kTRUE;
719
720}
721
722 //__________________________________________________________________________
96ebe67e 723Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
724 AliMUONTrackParam &trackParamAtCluster2)
019df241 725{
96ebe67e 726/// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
727/// assuming linear propagation between the two clusters:
728/// return the corresponding Chi2 accounting for covariances between the 2 clusters
729/// return trackParamAtCluster2
019df241 730
96ebe67e 731 // extrapolate linearly track parameters and covariances at the z position of the second cluster
732 trackParamAtCluster2 = trackParamAtCluster1;
3fe6651e 733 AliMUONTrackExtrap::LinearExtrapToZCov(&trackParamAtCluster2, cluster2->GetZ());
019df241 734
96ebe67e 735 // set pointer to cluster2 into trackParamAtCluster2
736 trackParamAtCluster2.SetClusterPtr(cluster2);
019df241 737
96ebe67e 738 // Set differences between track and clusters in the bending and non bending directions
739 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
740 Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
741 Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
742 Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
743 Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
019df241 744
745 // Calculate errors and covariances
96ebe67e 746 const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
747 const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
748 Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
749 Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
750 Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
019df241 751 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
96ebe67e 752 Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
753 Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
019df241 754 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
755
756 // Compute chi2
757 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
758 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
4ea3f013 759 if (detX == 0. || detY == 0.) return 2.*AliMUONTrack::MaxChi2();
019df241 760 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
761 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
762
763}
764
765 //__________________________________________________________________________
9bf6860b 766Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
767 Int_t nextChamber)
768{
769 /// Follow trackCandidate in chamber(0..) nextChamber assuming linear propagation, and search for compatible cluster(s)
770 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
771 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
772 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
773 /// Remove the obsolete "trackCandidate" at the end.
774 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
775 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
776 AliDebug(1,Form("Enter FollowLinearTrackInChamber(1..) %d", nextChamber+1));
777
4ea3f013 778 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
a0dc65b4 779 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
780 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
9bf6860b 781 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
782 Bool_t foundOneCluster = kFALSE;
783 AliMUONTrack *newTrack = 0x0;
784 AliMUONVCluster *cluster;
785 AliMUONTrackParam trackParam;
786 AliMUONTrackParam extrapTrackParamAtCluster;
787 AliMUONTrackParam bestTrackParamAtCluster;
788
789 // Get track parameters according to the propagation direction
790 if (nextChamber > 7) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
791 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
792
793 // Printout for debuging
794 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
795 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
796 trackParam.GetParameters().Print();
797 trackParam.GetCovariances().Print();
798 }
799
800 // Add MCS effect
4663da9f 801 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(trackParam.GetClusterPtr()->GetChamberId()),-1.);
9bf6860b 802
803 // Printout for debuging
804 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
805 cout << "FollowLinearTrackInChamber: look for cluster in chamber(1..): " << nextChamber+1 << endl;
806 }
807
808 // Create iterators to loop over clusters in chamber
809 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
810
811 // look for candidates in chamber
812 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
813
814 // try to add the current cluster fast
815 if (!TryOneClusterFast(trackParam, cluster)) continue;
816
817 // try to add the current cluster accuratly
818 extrapTrackParamAtCluster = trackParam;
3fe6651e 819 AliMUONTrackExtrap::LinearExtrapToZCov(&extrapTrackParamAtCluster, cluster->GetZ());
9bf6860b 820 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster, cluster, extrapTrackParamAtCluster);
821
822 // if good chi2 then consider to add cluster
823 if (chi2WithOneCluster < maxChi2WithOneCluster) {
824 foundOneCluster = kTRUE;
825
826 // Printout for debuging
827 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
828 cout << "FollowLinearTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
829 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
830 cluster->Print();
831 }
832
a0dc65b4 833 if (GetRecoParam()->TrackAllTracks()) {
9bf6860b 834 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
835 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 836 if (GetRecoParam()->RequestStation(nextChamber/2))
9bf6860b 837 extrapTrackParamAtCluster.SetRemovable(kFALSE);
838 else extrapTrackParamAtCluster.SetRemovable(kTRUE);
839 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster,*cluster);
89c8d66d 840 newTrack->SetGlobalChi2(trackCandidate.GetGlobalChi2()+chi2WithOneCluster);
9bf6860b 841 fNRecTracks++;
842
843 // Printout for debuging
844 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
845 cout << "FollowLinearTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
846 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
847 }
848
849 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
850 // keep track of the best cluster
851 bestChi2WithOneCluster = chi2WithOneCluster;
852 bestTrackParamAtCluster = extrapTrackParamAtCluster;
853 }
854
855 }
856
857 }
858
859 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 860 if (!GetRecoParam()->TrackAllTracks()) {
9bf6860b 861 if (foundOneCluster) {
a0dc65b4 862 if (GetRecoParam()->RequestStation(nextChamber/2))
9bf6860b 863 bestTrackParamAtCluster.SetRemovable(kFALSE);
864 else bestTrackParamAtCluster.SetRemovable(kTRUE);
865 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
89c8d66d 866 trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithOneCluster);
9bf6860b 867
868 // Printout for debuging
869 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
870 cout << "FollowLinearTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
871 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
872 }
873
874 } else return kFALSE;
875
876 } else if (foundOneCluster) {
877
878 // remove obsolete track
879 fRecTracksPtr->Remove(&trackCandidate);
880 fNRecTracks--;
881
882 } else return kFALSE;
883
884 return kTRUE;
885
886}
887
888//__________________________________________________________________________
96ebe67e 889Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
890 Int_t nextStation)
019df241 891{
96ebe67e 892 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
019df241 893 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
894 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
895 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
896 /// Remove the obsolete "trackCandidate" at the end.
96ebe67e 897 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
898 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
019df241 899 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
900
901 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
902 // - nextStation == station(1...) 5 => forward propagation
903 // - nextStation < station(1...) 5 => backward propagation
904 Int_t ch1, ch2;
905 if (nextStation==4) {
906 ch1 = 2*nextStation+1;
907 ch2 = 2*nextStation;
ea94c18b 908 } else {
019df241 909 ch1 = 2*nextStation;
910 ch2 = 2*nextStation+1;
ea94c18b 911 }
912
4ea3f013 913 Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
914 Double_t chi2WithTwoClusters = AliMUONTrack::MaxChi2();
a0dc65b4 915 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
916 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
917 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
918 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
96ebe67e 919 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
920 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
921 Bool_t foundOneCluster = kFALSE;
922 Bool_t foundTwoClusters = kFALSE;
019df241 923 AliMUONTrack *newTrack = 0x0;
96ebe67e 924 AliMUONVCluster *clusterCh1, *clusterCh2;
7332f213 925 AliMUONTrackParam trackParam;
96ebe67e 926 AliMUONTrackParam extrapTrackParamAtCluster1;
927 AliMUONTrackParam extrapTrackParamAtCluster2;
928 AliMUONTrackParam bestTrackParamAtCluster1;
929 AliMUONTrackParam bestTrackParamAtCluster2;
930
931 Int_t nClusters = clusterStore.GetSize();
932 Bool_t *clusterCh1Used = new Bool_t[nClusters];
933 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
934 Int_t iCluster1;
019df241 935
7332f213 936 // Get track parameters according to the propagation direction
937 if (nextStation==4) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
938 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
019df241 939
9bf6860b 940 // Printout for debuging
941 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
942 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
943 trackParam.GetParameters().Print();
944 trackParam.GetCovariances().Print();
945 }
946
019df241 947 // Add MCS effect
4663da9f 948 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(trackParam.GetClusterPtr()->GetChamberId()),-1.);
019df241 949
950 // Printout for debuging
951 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 952 cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
019df241 953 }
954
96ebe67e 955 // Create iterators to loop over clusters in both chambers
956 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
957 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
958
959 // look for candidates in chamber 2
960 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
019df241 961
96ebe67e 962 // try to add the current cluster fast
963 if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
019df241 964
96ebe67e 965 // try to add the current cluster accuratly
966 extrapTrackParamAtCluster2 = trackParam;
3fe6651e 967 AliMUONTrackExtrap::LinearExtrapToZCov(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
96ebe67e 968 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
019df241 969
96ebe67e 970 // if good chi2 then try to attach a cluster in the other chamber too
971 if (chi2WithOneCluster < maxChi2WithOneCluster) {
972 Bool_t foundSecondCluster = kFALSE;
019df241 973
974 // Printout for debuging
975 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 976 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
977 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
9bf6860b 978 clusterCh2->Print();
96ebe67e 979 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
019df241 980 }
981
982 // add MCS effect
4663da9f 983 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
019df241 984
96ebe67e 985 // reset cluster iterator of chamber 1
986 nextInCh1.Reset();
987 iCluster1 = -1;
988
989 // look for second candidates in chamber 1
990 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
991 iCluster1++;
019df241 992
96ebe67e 993 // try to add the current cluster fast
994 if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
019df241 995
96ebe67e 996 // try to add the current cluster in addition to the one found in the previous chamber
997 chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
019df241 998
96ebe67e 999 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
1000 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
1001 foundSecondCluster = kTRUE;
1002 foundTwoClusters = kTRUE;
019df241 1003
1004 // Printout for debuging
1005 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1006 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
9bf6860b 1007 << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
1008 clusterCh1->Print();
019df241 1009 }
1010
a0dc65b4 1011 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 1012 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
019df241 1013 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 1014 extrapTrackParamAtCluster1.SetRemovable(kTRUE);
1015 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
1016 extrapTrackParamAtCluster2.SetRemovable(kTRUE);
1017 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
89c8d66d 1018 newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithTwoClusters);
019df241 1019 fNRecTracks++;
1020
96ebe67e 1021 // Tag clusterCh1 as used
1022 clusterCh1Used[iCluster1] = kTRUE;
019df241 1023
1024 // Printout for debuging
1025 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1026 cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
019df241 1027 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1028 }
1029
96ebe67e 1030 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
1031 // keep track of the best couple of clusters
1032 bestChi2WithTwoClusters = chi2WithTwoClusters;
1033 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
1034 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
019df241 1035 }
1036
1037 }
1038
1039 }
1040
96ebe67e 1041 // if no cluster found in chamber1 then consider to add clusterCh2 only
1042 if (!foundSecondCluster) {
1043 foundOneCluster = kTRUE;
019df241 1044
a0dc65b4 1045 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 1046 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 1047 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 1048 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 1049 extrapTrackParamAtCluster2.SetRemovable(kFALSE);
1050 else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
96ebe67e 1051 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
89c8d66d 1052 newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithOneCluster);
019df241 1053 fNRecTracks++;
1054
1055 // Printout for debuging
1056 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1057 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
019df241 1058 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1059 }
1060
96ebe67e 1061 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
1062 // keep track of the best cluster except if a couple of clusters has already been found
1063 bestChi2WithOneCluster = chi2WithOneCluster;
1064 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
019df241 1065 }
1066
1067 }
1068
1069 }
1070
1071 }
1072
1073 // look for candidates in chamber 1 not already attached to a track
96ebe67e 1074 // if we want to keep all possible tracks or if no good couple of clusters has been found
a0dc65b4 1075 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
019df241 1076
1077 // Printout for debuging
1078 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1079 cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
019df241 1080 }
1081
1082 //Extrapolate trackCandidate to chamber "ch2"
3fe6651e 1083 AliMUONTrackExtrap::LinearExtrapToZCov(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
019df241 1084
1085 // add MCS effect for next step
4663da9f 1086 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
9bf6860b 1087
96ebe67e 1088 // reset cluster iterator of chamber 1
1089 nextInCh1.Reset();
1090 iCluster1 = -1;
1091
1092 // look for second candidates in chamber 1
1093 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
1094 iCluster1++;
019df241 1095
96ebe67e 1096 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
019df241 1097
96ebe67e 1098 // try to add the current cluster fast
1099 if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
9bf6860b 1100
96ebe67e 1101 // try to add the current cluster accuratly
1102 extrapTrackParamAtCluster1 = trackParam;
3fe6651e 1103 AliMUONTrackExtrap::LinearExtrapToZCov(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
96ebe67e 1104 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
9bf6860b 1105
96ebe67e 1106 // if good chi2 then consider to add clusterCh1
1107 // We do not try to attach a cluster in the other chamber too since it has already been done above
1108 if (chi2WithOneCluster < maxChi2WithOneCluster) {
1109 foundOneCluster = kTRUE;
019df241 1110
1111 // Printout for debuging
1112 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1113 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
1114 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
9bf6860b 1115 clusterCh1->Print();
019df241 1116 }
1117
a0dc65b4 1118 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 1119 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 1120 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 1121 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 1122 extrapTrackParamAtCluster1.SetRemovable(kFALSE);
1123 else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
96ebe67e 1124 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
89c8d66d 1125 newTrack->SetGlobalChi2(newTrack->GetGlobalChi2()+chi2WithOneCluster);
019df241 1126 fNRecTracks++;
1127
1128 // Printout for debuging
1129 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1130 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
019df241 1131 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1132 }
1133
96ebe67e 1134 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
1135 // keep track of the best cluster except if a couple of clusters has already been found
1136 bestChi2WithOneCluster = chi2WithOneCluster;
1137 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
019df241 1138 }
1139
1140 }
1141
1142 }
1143
1144 }
1145
1146 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 1147 if (!GetRecoParam()->TrackAllTracks()) {
96ebe67e 1148 if (foundTwoClusters) {
1149 bestTrackParamAtCluster1.SetRemovable(kTRUE);
1150 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
1151 bestTrackParamAtCluster2.SetRemovable(kTRUE);
1152 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
89c8d66d 1153 trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithTwoClusters);
019df241 1154
1155 // Printout for debuging
1156 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1157 cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
019df241 1158 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1159 }
1160
96ebe67e 1161 } else if (foundOneCluster) {
a0dc65b4 1162 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 1163 bestTrackParamAtCluster1.SetRemovable(kFALSE);
1164 else bestTrackParamAtCluster1.SetRemovable(kTRUE);
96ebe67e 1165 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
89c8d66d 1166 trackCandidate.SetGlobalChi2(trackCandidate.GetGlobalChi2()+bestChi2WithOneCluster);
019df241 1167
1168 // Printout for debuging
1169 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 1170 cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
019df241 1171 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
1172 }
1173
dd230855 1174 } else {
96ebe67e 1175 delete [] clusterCh1Used;
dd230855 1176 return kFALSE;
1177 }
019df241 1178
96ebe67e 1179 } else if (foundOneCluster || foundTwoClusters) {
019df241 1180
1181 // remove obsolete track
1182 fRecTracksPtr->Remove(&trackCandidate);
1183 fNRecTracks--;
1184
dd230855 1185 } else {
96ebe67e 1186 delete [] clusterCh1Used;
dd230855 1187 return kFALSE;
1188 }
ea94c18b 1189
96ebe67e 1190 delete [] clusterCh1Used;
019df241 1191 return kTRUE;
ea94c18b 1192
1193}
1194
7332f213 1195//__________________________________________________________________________
1196void AliMUONVTrackReconstructor::ImproveTracks()
1197{
1198 /// Improve tracks by removing clusters with local chi2 highter than the defined cut
1199 /// Recompute track parameters and covariances at the remaining clusters
1200 AliDebug(1,"Enter ImproveTracks");
1201
1202 AliMUONTrack *track, *nextTrack;
1203
7332f213 1204 track = (AliMUONTrack*) fRecTracksPtr->First();
1205 while (track) {
1206
1207 // prepare next track in case the actual track is suppressed
1208 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
1209
1210 ImproveTrack(*track);
1211
1212 // remove track if improvement failed
1213 if (!track->IsImproved()) {
1214 fRecTracksPtr->Remove(track);
1215 fNRecTracks--;
1216 }
1217
1218 track = nextTrack;
1219 }
1220
1221 // compress the array in case of some tracks have been removed
1222 fRecTracksPtr->Compress();
1223
1224}
1225
1226//__________________________________________________________________________
1227void AliMUONVTrackReconstructor::Finalize()
1228{
5c15a68b 1229 /// Recompute track parameters and covariances at each attached cluster
2e2d0c44 1230 /// Set the label pointing to the corresponding MC track
4ea3f013 1231 /// Remove the track if finalization failed
7332f213 1232
4ea3f013 1233 AliMUONTrack *track, *nextTrack;
1234 Bool_t trackRemoved = kFALSE;
7332f213 1235
1236 track = (AliMUONTrack*) fRecTracksPtr->First();
1237 while (track) {
1238
4ea3f013 1239 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
7332f213 1240
4ea3f013 1241 if (FinalizeTrack(*track)) track->FindMCLabel();
1242 else {
1243 fRecTracksPtr->Remove(track);
1244 fNRecTracks--;
1245 trackRemoved = kTRUE;
1246 }
2e2d0c44 1247
4ea3f013 1248 track = nextTrack;
7332f213 1249
1250 }
1251
4ea3f013 1252 // compress array of tracks if needed
1253 if (trackRemoved) fRecTracksPtr->Compress();
1254
7332f213 1255}
1256
1257//__________________________________________________________________________
7ec3b9cf 1258void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
1259 const AliMUONVTriggerTrackStore& triggerTrackStore,
1260 const AliMUONVTriggerStore& triggerStore,
1261 const AliMUONTrackHitPattern& trackHitPattern)
8d0843c6 1262{
1263 /// Try to match track from tracking system with trigger track
99c136e1 1264 AliCodeTimerAuto("",0);
fda59e58 1265
683cb6c5 1266 trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
8d0843c6 1267}
1268
ea94c18b 1269 //__________________________________________________________________________
1270void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
1271 const AliMUONVTriggerStore& triggerStore,
1272 AliMUONVTriggerTrackStore& triggerTrackStore)
8d0843c6 1273{
71a2d3aa 1274 /// To make the trigger tracks from Local Trigger
7ec3b9cf 1275 AliDebug(1, "");
99c136e1 1276 AliCodeTimerAuto("",0);
bdfb6eef 1277
7ec3b9cf 1278 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
e6b25a6e 1279
7ec3b9cf 1280 UChar_t gloTrigPat = 0;
e6b25a6e 1281
7ec3b9cf 1282 if (globalTrigger)
1283 {
1284 gloTrigPat = globalTrigger->GetGlobalResponse();
e6b25a6e 1285 }
1286
7ec3b9cf 1287 TIter next(triggerStore.CreateIterator());
1288 AliMUONLocalTrigger* locTrg(0x0);
8d0843c6 1289
bdfb6eef 1290 const Double_t kTrigNonBendReso = AliMUONConstants::TriggerNonBendingReso();
1291 const Double_t kTrigBendReso = AliMUONConstants::TriggerBendingReso();
1292 const Double_t kSqrt12 = TMath::Sqrt(12.);
7cf63da6 1293
7ec3b9cf 1294 AliMUONTriggerTrack triggerTrack;
bdfb6eef 1295 TMatrixD trigCov(3,3);
7ec3b9cf 1296
1297 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
1298 {
bdfb6eef 1299 if ( locTrg->IsTrigX() && locTrg->IsTrigY() )
7ec3b9cf 1300 { // make Trigger Track if trigger in X and Y
bdfb6eef 1301
1302 Int_t localBoardId = locTrg->LoCircuit();
1303
32ab62c9 1304 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
bdfb6eef 1305 Float_t z11 = circuit.GetZ11Pos(localBoardId, locTrg->LoStripX());
7ec3b9cf 1306 // need first to convert deviation to [0-30]
1307 // (see AliMUONLocalTriggerBoard::LocalTrigger)
d72d7b9e 1308 Int_t deviation = locTrg->GetDeviation();
7ec3b9cf 1309 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
32ab62c9 1310 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
bdfb6eef 1311 Float_t z21 = circuit.GetZ21Pos(localBoardId, stripX21);
32ab62c9 1312 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
7ec3b9cf 1313
bdfb6eef 1314 AliDebug(1, Form(" MakeTriggerTrack %3d %2d %2d %2d (%f %f %f) (%f %f)\n",locTrg->LoCircuit(),
1315 locTrg->LoStripX(),locTrg->LoStripX()+deviation+1,locTrg->LoStripY(),x11, y11, z11, y21, z21));
abc2458f 1316
bdfb6eef 1317
1318 Double_t deltaZ = z11 - z21;
7ec3b9cf 1319
bdfb6eef 1320 Float_t slopeX = x11/z11;
1321 Float_t slopeY = (y11-y21) / deltaZ;
1322
1323 Float_t sigmaX = circuit.GetX11Width(localBoardId, locTrg->LoStripY()) / kSqrt12;
1324 Float_t sigmaY = circuit.GetY11Width(localBoardId, locTrg->LoStripX()) / kSqrt12;
1325 Float_t sigmaY21 = circuit.GetY21Width(localBoardId, locTrg->LoStripX()) / kSqrt12;
1326
1327 trigCov.Zero();
1328 trigCov(0,0) = kTrigNonBendReso * kTrigNonBendReso + sigmaX * sigmaX;
1329 trigCov(1,1) = kTrigBendReso * kTrigBendReso + sigmaY * sigmaY;
1330 trigCov(2,2) =
1331 (2. * kTrigBendReso * kTrigBendReso + sigmaY * sigmaY + sigmaY21 * sigmaY21 ) / deltaZ / deltaZ;
1332 trigCov(1,2) = trigCov(2,1) = trigCov(1,1) / deltaZ;
1333
7ec3b9cf 1334 triggerTrack.SetX11(x11);
1335 triggerTrack.SetY11(y11);
bdfb6eef 1336 triggerTrack.SetZ11(z11);
1337 triggerTrack.SetZ21(z21);
1338 triggerTrack.SetSlopeX(slopeX);
1339 triggerTrack.SetSlopeY(slopeY);
7ec3b9cf 1340 triggerTrack.SetGTPattern(gloTrigPat);
32ab62c9 1341 triggerTrack.SetLoTrgNum(localBoardId);
bdfb6eef 1342 triggerTrack.SetCovariances(trigCov);
1343
7ec3b9cf 1344 triggerTrackStore.Add(triggerTrack);
1345 } // board is fired
e6b25a6e 1346 } // end of loop on Local Trigger
8d0843c6 1347}