New LinkDef (cmake)
[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
81#include "AliLog.h"
b709ac13 82#include "AliCodeTimer.h"
ea94c18b 83#include "AliTracker.h"
8d0843c6 84
4889d34c 85#include <TClonesArray.h>
86#include <TMath.h>
ea94c18b 87#include <TMatrixD.h>
1fef78c8 88#include <TVector2.h>
ea94c18b 89
90#include <Riostream.h>
4889d34c 91
78649106 92/// \cond CLASSIMP
8d0843c6 93ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
78649106 94/// \endcond
8d0843c6 95
ea94c18b 96 //__________________________________________________________________________
a0dc65b4 97AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(const AliMUONRecoParam* recoParam,
98 AliMUONVClusterServer* clusterServer)
99: TObject(),
100fRecTracksPtr(0x0),
101fNRecTracks(0),
102fClusterServer(clusterServer),
5a240757 103fkRecoParam(recoParam)
8d0843c6 104{
105 /// Constructor for class AliMUONVTrackReconstructor
b1fea02e 106 /// WARNING: if clusterServer=0x0, no clusterization will be possible at this level
ea94c18b 107
108 // Memory allocation for the TClonesArray of reconstructed tracks
96ebe67e 109 fRecTracksPtr = new TClonesArray("AliMUONTrack", 100);
7ec3b9cf 110
208f139e 111 // set the magnetic field for track extrapolations
f7a1cc68 112 AliMUONTrackExtrap::SetField();
8d0843c6 113}
114
115 //__________________________________________________________________________
ea94c18b 116AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor()
8d0843c6 117{
118 /// Destructor for class AliMUONVTrackReconstructor
ea94c18b 119 delete fRecTracksPtr;
8d0843c6 120}
121
ea94c18b 122 //__________________________________________________________________________
ea94c18b 123void AliMUONVTrackReconstructor::ResetTracks()
124{
125 /// To reset the TClonesArray of reconstructed tracks
126 if (fRecTracksPtr) fRecTracksPtr->Clear("C");
127 fNRecTracks = 0;
128 return;
129}
130
131 //__________________________________________________________________________
1fef78c8 132void AliMUONVTrackReconstructor::EventReconstruct(AliMUONVClusterStore& clusterStore, AliMUONVTrackStore& trackStore)
ea94c18b 133{
134 /// To reconstruct one event
135 AliDebug(1,"");
b709ac13 136 AliCodeTimerAuto("");
ea94c18b 137
96ebe67e 138 // Reset array of tracks
ea94c18b 139 ResetTracks();
2060b217 140
9bf6860b 141 // Look for candidates from clusters in stations(1..) 4 and 5
96ebe67e 142 MakeTrackCandidates(clusterStore);
143
9bf6860b 144 // Look for extra candidates from clusters in stations(1..) 4 and 5
a0dc65b4 145 if (GetRecoParam()->MakeMoreTrackCandidates()) MakeMoreTrackCandidates(clusterStore);
9bf6860b 146
96ebe67e 147 // Stop tracking if no candidate found
ea94c18b 148 if (fRecTracksPtr->GetEntriesFast() == 0) return;
96ebe67e 149
ea94c18b 150 // Follow tracks in stations(1..) 3, 2 and 1
96ebe67e 151 FollowTracks(clusterStore);
152
b709ac13 153 // Complement the reconstructed tracks
a0dc65b4 154 if (GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
96ebe67e 155
ea94c18b 156 // Improve the reconstructed tracks
a0dc65b4 157 if (GetRecoParam()->ImproveTracks()) ImproveTracks();
96ebe67e 158
c59f70b9 159 // Remove connected tracks
160 if (GetRecoParam()->RemoveConnectedTracksInSt12()) RemoveConnectedTracks(kFALSE);
161 else RemoveConnectedTracks(kTRUE);
96ebe67e 162
ea94c18b 163 // Fill AliMUONTrack data members
164 Finalize();
96ebe67e 165
166 // Add tracks to MUON data container
167 for (Int_t i=0; i<fNRecTracks; ++i)
168 {
169 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
7332f213 170 track->SetUniqueID(i+1);
96ebe67e 171 trackStore.Add(*track);
172 }
ea94c18b 173}
174
175 //__________________________________________________________________________
9bf6860b 176TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsBetweenChambers(const AliMUONVClusterStore& clusterStore, Int_t ch1, Int_t ch2)
8d0843c6 177{
9bf6860b 178 /// To make the list of segments from the list of clusters in the 2 given chambers.
208f139e 179 /// Return a new TClonesArray of segments.
180 /// It is the responsibility of the user to delete it afterward.
9bf6860b 181 AliDebug(1,Form("Enter MakeSegmentsBetweenChambers (1..) %d-%d", ch1+1, ch2+1));
208f139e 182
96ebe67e 183 AliMUONVCluster *cluster1, *cluster2;
208f139e 184 AliMUONObjectPair *segment;
9bf6860b 185 Double_t nonBendingSlope = 0, bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
7ec3b9cf 186
96ebe67e 187 // Create iterators to loop over clusters in both chambers
188 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
189 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
190
208f139e 191 // list of segments
96ebe67e 192 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
7ec3b9cf 193
96ebe67e 194 // Loop over clusters in the first chamber of the station
195 while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
196
197 // reset cluster iterator of chamber 2
198 nextInCh2.Reset();
199
200 // Loop over clusters in the second chamber of the station
201 while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
202
9bf6860b 203 // non bending slope
204 nonBendingSlope = (cluster1->GetX() - cluster2->GetX()) / (cluster1->GetZ() - cluster2->GetZ());
205
9f093251 206 // check if non bending slope is within tolerances
a0dc65b4 207 if (TMath::Abs(nonBendingSlope) > GetRecoParam()->GetMaxNonBendingSlope()) continue;
9f093251 208
96ebe67e 209 // bending slope
210 bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
211
9f093251 212 // check the bending momentum of the bending slope depending if the field is ON or OFF
213 if (AliMUONTrackExtrap::IsFieldON()) {
214
215 // impact parameter
216 impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
217
218 // absolute value of bending momentum
219 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
220
221 // check if bending momentum is within tolerances
a0dc65b4 222 if (bendingMomentum < GetRecoParam()->GetMinBendingMomentum() ||
223 bendingMomentum > GetRecoParam()->GetMaxBendingMomentum()) continue;
96ebe67e 224
9f093251 225 } else {
226
227 // check if non bending slope is within tolerances
a0dc65b4 228 if (TMath::Abs(bendingSlope) > GetRecoParam()->GetMaxBendingSlope()) continue;
9f093251 229
230 }
231 // make new segment
232 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
233
234 // Printout for debug
235 if (AliLog::GetGlobalDebugLevel() > 1) {
236 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
237 segment->Dump();
238 cout << "Cluster in first chamber" << endl;
239 cluster1->Print();
240 cout << "Cluster in second chamber" << endl;
241 cluster2->Print();
8d0843c6 242 }
96ebe67e 243
244 }
245
246 }
247
248 // Printout for debug
9bf6860b 249 AliDebug(1,Form("chambers%d-%d: NSegments = %d ", ch1+1, ch2+1, segments->GetEntriesFast()));
96ebe67e 250
208f139e 251 return segments;
8d0843c6 252}
253
ea94c18b 254 //__________________________________________________________________________
255void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
256{
257 /// To remove identical tracks:
96ebe67e 258 /// Tracks are considered identical if they have all their clusters in common.
259 /// One keeps the track with the larger number of clusters if need be
ea94c18b 260 AliMUONTrack *track1, *track2, *trackToRemove;
96ebe67e 261 Int_t clustersInCommon, nClusters1, nClusters2;
ea94c18b 262 Bool_t removedTrack1;
263 // Loop over first track of the pair
264 track1 = (AliMUONTrack*) fRecTracksPtr->First();
265 while (track1) {
266 removedTrack1 = kFALSE;
96ebe67e 267 nClusters1 = track1->GetNClusters();
ea94c18b 268 // Loop over second track of the pair
269 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
270 while (track2) {
96ebe67e 271 nClusters2 = track2->GetNClusters();
272 // number of clusters in common between two tracks
273 clustersInCommon = track1->ClustersInCommon(track2);
ea94c18b 274 // check for identical tracks
96ebe67e 275 if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
ea94c18b 276 // decide which track to remove
96ebe67e 277 if (nClusters2 > nClusters1) {
ea94c18b 278 // remove track1 and continue the first loop with the track next to track1
279 trackToRemove = track1;
280 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
281 fRecTracksPtr->Remove(trackToRemove);
282 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
283 fNRecTracks--;
284 removedTrack1 = kTRUE;
285 break;
286 } else {
287 // remove track2 and continue the second loop with the track next to track2
288 trackToRemove = track2;
289 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
290 fRecTracksPtr->Remove(trackToRemove);
291 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
292 fNRecTracks--;
293 }
294 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
295 } // track2
296 if (removedTrack1) continue;
297 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
298 } // track1
299 return;
300}
301
302 //__________________________________________________________________________
303void AliMUONVTrackReconstructor::RemoveDoubleTracks()
304{
305 /// To remove double tracks:
96ebe67e 306 /// Tracks are considered identical if more than half of the clusters of the track
307 /// which has the smaller number of clusters are in common with the other track.
308 /// Among two identical tracks, one keeps the track with the larger number of clusters
ea94c18b 309 /// or, if these numbers are equal, the track with the minimum chi2.
310 AliMUONTrack *track1, *track2, *trackToRemove;
96ebe67e 311 Int_t clustersInCommon, nClusters1, nClusters2;
ea94c18b 312 Bool_t removedTrack1;
313 // Loop over first track of the pair
314 track1 = (AliMUONTrack*) fRecTracksPtr->First();
315 while (track1) {
316 removedTrack1 = kFALSE;
96ebe67e 317 nClusters1 = track1->GetNClusters();
ea94c18b 318 // Loop over second track of the pair
319 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
320 while (track2) {
96ebe67e 321 nClusters2 = track2->GetNClusters();
322 // number of clusters in common between two tracks
323 clustersInCommon = track1->ClustersInCommon(track2);
ea94c18b 324 // check for identical tracks
96ebe67e 325 if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
ea94c18b 326 // decide which track to remove
96ebe67e 327 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
ea94c18b 328 // remove track2 and continue the second loop with the track next to track2
329 trackToRemove = track2;
330 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
331 fRecTracksPtr->Remove(trackToRemove);
c59f70b9 332 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
333 fNRecTracks--;
334 } else {
335 // else remove track1 and continue the first loop with the track next to track1
336 trackToRemove = track1;
337 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
338 fRecTracksPtr->Remove(trackToRemove);
339 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
340 fNRecTracks--;
341 removedTrack1 = kTRUE;
342 break;
343 }
344 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
345 } // track2
346 if (removedTrack1) continue;
347 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
348 } // track1
349 return;
350}
351
352 //__________________________________________________________________________
353void AliMUONVTrackReconstructor::RemoveConnectedTracks(Bool_t inSt345)
354{
355 /// To remove double tracks:
356 /// Tracks are considered identical if they share 1 cluster or more.
357 /// If inSt345=kTRUE only stations 3, 4 and 5 are considered.
358 /// Among two identical tracks, one keeps the track with the larger number of clusters
359 /// or, if these numbers are equal, the track with the minimum chi2.
360 AliMUONTrack *track1, *track2, *trackToRemove;
361 Int_t clustersInCommon, nClusters1, nClusters2;
362 Bool_t removedTrack1;
363 // Loop over first track of the pair
364 track1 = (AliMUONTrack*) fRecTracksPtr->First();
365 while (track1) {
366 removedTrack1 = kFALSE;
367 nClusters1 = track1->GetNClusters();
368 // Loop over second track of the pair
369 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
370 while (track2) {
371 nClusters2 = track2->GetNClusters();
372 // number of clusters in common between two tracks
373 clustersInCommon = track1->ClustersInCommon(track2, inSt345);
374 // check for identical tracks
375 if (clustersInCommon > 0) {
376 // decide which track to remove
377 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
378 // remove track2 and continue the second loop with the track next to track2
379 trackToRemove = track2;
380 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
381 fRecTracksPtr->Remove(trackToRemove);
ea94c18b 382 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
383 fNRecTracks--;
384 } else {
385 // else remove track1 and continue the first loop with the track next to track1
386 trackToRemove = track1;
387 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
388 fRecTracksPtr->Remove(trackToRemove);
389 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
390 fNRecTracks--;
391 removedTrack1 = kTRUE;
392 break;
393 }
394 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
395 } // track2
396 if (removedTrack1) continue;
397 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
398 } // track1
399 return;
400}
401
402 //__________________________________________________________________________
9bf6860b 403void AliMUONVTrackReconstructor::AskForNewClustersInChamber(const AliMUONTrackParam &trackParam,
404 AliMUONVClusterStore& clusterStore, Int_t chamber)
1fef78c8 405{
406 /// Ask the clustering to reconstruct new clusters around the track candidate position
1fef78c8 407
9bf6860b 408 // check if the current chamber is useable
a0dc65b4 409 if (!fClusterServer || !GetRecoParam()->UseChamber(chamber)) return;
1fef78c8 410
9bf6860b 411 // maximum distance between the center of the chamber and a detection element
412 // (accounting for the inclination of the chamber)
b89ac3d6 413 static const Double_t kMaxDZ = 15.; // 15 cm
1fef78c8 414
9bf6860b 415 // extrapolate track parameters to the chamber
416 AliMUONTrackParam extrapTrackParam(trackParam);
417 AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(chamber));
418
419 // build the searching area using the track resolution and the maximum-distance-to-track value
420 const TMatrixD& kParamCov = extrapTrackParam.GetCovariances();
b89ac3d6 421 Double_t errX2 = kParamCov(0,0) + kMaxDZ * kMaxDZ * kParamCov(1,1) + 2. * kMaxDZ * TMath::Abs(kParamCov(0,1));
422 Double_t errY2 = kParamCov(2,2) + kMaxDZ * kMaxDZ * kParamCov(3,3) + 2. * kMaxDZ * TMath::Abs(kParamCov(2,3));
423 Double_t dX = TMath::Abs(trackParam.GetNonBendingSlope()) * kMaxDZ +
a0dc65b4 424 GetRecoParam()->GetMaxNonBendingDistanceToTrack() +
425 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2);
b89ac3d6 426 Double_t dY = TMath::Abs(trackParam.GetBendingSlope()) * kMaxDZ +
a0dc65b4 427 GetRecoParam()->GetMaxBendingDistanceToTrack() +
428 GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2);
9bf6860b 429 TVector2 dimensions(dX, dY);
1fef78c8 430 TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
9bf6860b 431 AliMpArea area(position, dimensions);
1fef78c8 432
433 // ask to cluterize in the given area of the given chamber
35be7ed7 434 fClusterServer->Clusterize(chamber, clusterStore, area, GetRecoParam());
1fef78c8 435
9bf6860b 436}
437
438 //__________________________________________________________________________
439void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
440 AliMUONVClusterStore& clusterStore, Int_t station)
441{
442 /// Ask the clustering to reconstruct new clusters around the track candidate position
443 /// in the 2 chambers of the given station
444 AskForNewClustersInChamber(trackParam, clusterStore, 2*station+1);
445 AskForNewClustersInChamber(trackParam, clusterStore, 2*station);
1fef78c8 446}
447
448 //__________________________________________________________________________
96ebe67e 449Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
1fef78c8 450 AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
ea94c18b 451{
96ebe67e 452/// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
ea94c18b 453/// return the corresponding Chi2
96ebe67e 454/// return trackParamAtCluster
ea94c18b 455
96ebe67e 456 // extrapolate track parameters and covariances at the z position of the tested cluster
457 trackParamAtCluster = trackParam;
458 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator);
ea94c18b 459
96ebe67e 460 // set pointer to cluster into trackParamAtCluster
461 trackParamAtCluster.SetClusterPtr(cluster);
ea94c18b 462
96ebe67e 463 // Set differences between trackParam and cluster in the bending and non bending directions
464 Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
465 Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
ea94c18b 466
019df241 467 // Calculate errors and covariances
96ebe67e 468 const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
469 Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
470 Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
019df241 471
472 // Compute chi2
96ebe67e 473 return dX * dX / sigmaX2 + dY * dY / sigmaY2;
019df241 474
475}
476
477 //__________________________________________________________________________
5a240757 478Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, const AliMUONVCluster* cluster)
019df241 479{
9bf6860b 480/// Test the compatibility between the track and the cluster
481/// given the track resolution + the maximum-distance-to-track value
482/// and assuming linear propagation of the track:
019df241 483/// return kTRUE if they are compatibles
484
96ebe67e 485 Double_t dZ = cluster->GetZ() - trackParam.GetZ();
486 Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
487 Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
9bf6860b 488 const TMatrixD& kParamCov = trackParam.GetCovariances();
489 Double_t errX2 = kParamCov(0,0) + dZ * dZ * kParamCov(1,1) + 2. * dZ * kParamCov(0,1);
490 Double_t errY2 = kParamCov(2,2) + dZ * dZ * kParamCov(3,3) + 2. * dZ * kParamCov(2,3);
491
a0dc65b4 492 Double_t dXmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errX2) +
493 GetRecoParam()->GetMaxNonBendingDistanceToTrack();
494 Double_t dYmax = GetRecoParam()->GetSigmaCutForTracking() * TMath::Sqrt(errY2) +
495 GetRecoParam()->GetMaxBendingDistanceToTrack();
019df241 496
9bf6860b 497 if (TMath::Abs(dX) > dXmax || TMath::Abs(dY) > dYmax) return kFALSE;
019df241 498
499 return kTRUE;
500
501}
502
503 //__________________________________________________________________________
96ebe67e 504Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
505 AliMUONTrackParam &trackParamAtCluster2)
019df241 506{
96ebe67e 507/// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
508/// assuming linear propagation between the two clusters:
509/// return the corresponding Chi2 accounting for covariances between the 2 clusters
510/// return trackParamAtCluster2
019df241 511
96ebe67e 512 // extrapolate linearly track parameters and covariances at the z position of the second cluster
513 trackParamAtCluster2 = trackParamAtCluster1;
514 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
019df241 515
96ebe67e 516 // set pointer to cluster2 into trackParamAtCluster2
517 trackParamAtCluster2.SetClusterPtr(cluster2);
019df241 518
96ebe67e 519 // Set differences between track and clusters in the bending and non bending directions
520 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
521 Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
522 Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
523 Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
524 Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
019df241 525
526 // Calculate errors and covariances
96ebe67e 527 const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
528 const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
529 Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
530 Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
531 Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
019df241 532 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
96ebe67e 533 Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
534 Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
019df241 535 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
536
537 // Compute chi2
538 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
539 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
540 if (detX == 0. || detY == 0.) return 1.e10;
541 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
542 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
543
544}
545
546 //__________________________________________________________________________
9bf6860b 547Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInChamber(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
548 Int_t nextChamber)
549{
550 /// Follow trackCandidate in chamber(0..) nextChamber assuming linear propagation, and search for compatible cluster(s)
551 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
552 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
553 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
554 /// Remove the obsolete "trackCandidate" at the end.
555 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
556 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
557 AliDebug(1,Form("Enter FollowLinearTrackInChamber(1..) %d", nextChamber+1));
558
559 Double_t chi2WithOneCluster = 1.e10;
a0dc65b4 560 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
561 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
9bf6860b 562 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
563 Bool_t foundOneCluster = kFALSE;
564 AliMUONTrack *newTrack = 0x0;
565 AliMUONVCluster *cluster;
566 AliMUONTrackParam trackParam;
567 AliMUONTrackParam extrapTrackParamAtCluster;
568 AliMUONTrackParam bestTrackParamAtCluster;
569
570 // Get track parameters according to the propagation direction
571 if (nextChamber > 7) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
572 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
573
574 // Printout for debuging
575 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
576 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
577 trackParam.GetParameters().Print();
578 trackParam.GetCovariances().Print();
579 }
580
581 // Add MCS effect
582 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
583
584 // Printout for debuging
585 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
586 cout << "FollowLinearTrackInChamber: look for cluster in chamber(1..): " << nextChamber+1 << endl;
587 }
588
589 // Create iterators to loop over clusters in chamber
590 TIter next(clusterStore.CreateChamberIterator(nextChamber,nextChamber));
591
592 // look for candidates in chamber
593 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
594
595 // try to add the current cluster fast
596 if (!TryOneClusterFast(trackParam, cluster)) continue;
597
598 // try to add the current cluster accuratly
599 extrapTrackParamAtCluster = trackParam;
600 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster, cluster->GetZ());
601 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster, cluster, extrapTrackParamAtCluster);
602
603 // if good chi2 then consider to add cluster
604 if (chi2WithOneCluster < maxChi2WithOneCluster) {
605 foundOneCluster = kTRUE;
606
607 // Printout for debuging
608 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
609 cout << "FollowLinearTrackInChamber: found one cluster in chamber(1..): " << nextChamber+1
610 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
611 cluster->Print();
612 }
613
a0dc65b4 614 if (GetRecoParam()->TrackAllTracks()) {
9bf6860b 615 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
616 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 617 if (GetRecoParam()->RequestStation(nextChamber/2))
9bf6860b 618 extrapTrackParamAtCluster.SetRemovable(kFALSE);
619 else extrapTrackParamAtCluster.SetRemovable(kTRUE);
620 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster,*cluster);
621 fNRecTracks++;
622
623 // Printout for debuging
624 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
625 cout << "FollowLinearTrackInChamber: added one cluster in chamber(1..): " << nextChamber+1 << endl;
626 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
627 }
628
629 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
630 // keep track of the best cluster
631 bestChi2WithOneCluster = chi2WithOneCluster;
632 bestTrackParamAtCluster = extrapTrackParamAtCluster;
633 }
634
635 }
636
637 }
638
639 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 640 if (!GetRecoParam()->TrackAllTracks()) {
9bf6860b 641 if (foundOneCluster) {
a0dc65b4 642 if (GetRecoParam()->RequestStation(nextChamber/2))
9bf6860b 643 bestTrackParamAtCluster.SetRemovable(kFALSE);
644 else bestTrackParamAtCluster.SetRemovable(kTRUE);
645 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster,*(bestTrackParamAtCluster.GetClusterPtr()));
646
647 // Printout for debuging
648 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
649 cout << "FollowLinearTrackInChamber: added the best cluster in chamber(1..): " << bestTrackParamAtCluster.GetClusterPtr()->GetChamberId()+1 << endl;
650 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
651 }
652
653 } else return kFALSE;
654
655 } else if (foundOneCluster) {
656
657 // remove obsolete track
658 fRecTracksPtr->Remove(&trackCandidate);
659 fNRecTracks--;
660
661 } else return kFALSE;
662
663 return kTRUE;
664
665}
666
667//__________________________________________________________________________
96ebe67e 668Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
669 Int_t nextStation)
019df241 670{
96ebe67e 671 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
019df241 672 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
673 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
674 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
675 /// Remove the obsolete "trackCandidate" at the end.
96ebe67e 676 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
677 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
019df241 678 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
679
680 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
681 // - nextStation == station(1...) 5 => forward propagation
682 // - nextStation < station(1...) 5 => backward propagation
683 Int_t ch1, ch2;
684 if (nextStation==4) {
685 ch1 = 2*nextStation+1;
686 ch2 = 2*nextStation;
ea94c18b 687 } else {
019df241 688 ch1 = 2*nextStation;
689 ch2 = 2*nextStation+1;
ea94c18b 690 }
691
96ebe67e 692 Double_t chi2WithOneCluster = 1.e10;
693 Double_t chi2WithTwoClusters = 1.e10;
a0dc65b4 694 Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
695 GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
696 Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
697 GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
96ebe67e 698 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
699 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
700 Bool_t foundOneCluster = kFALSE;
701 Bool_t foundTwoClusters = kFALSE;
019df241 702 AliMUONTrack *newTrack = 0x0;
96ebe67e 703 AliMUONVCluster *clusterCh1, *clusterCh2;
7332f213 704 AliMUONTrackParam trackParam;
96ebe67e 705 AliMUONTrackParam extrapTrackParamAtCluster1;
706 AliMUONTrackParam extrapTrackParamAtCluster2;
707 AliMUONTrackParam bestTrackParamAtCluster1;
708 AliMUONTrackParam bestTrackParamAtCluster2;
709
710 Int_t nClusters = clusterStore.GetSize();
711 Bool_t *clusterCh1Used = new Bool_t[nClusters];
712 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
713 Int_t iCluster1;
019df241 714
7332f213 715 // Get track parameters according to the propagation direction
716 if (nextStation==4) trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
717 else trackParam = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
019df241 718
9bf6860b 719 // Printout for debuging
720 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
721 cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
722 trackParam.GetParameters().Print();
723 trackParam.GetCovariances().Print();
724 }
725
019df241 726 // Add MCS effect
727 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
728
729 // Printout for debuging
730 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 731 cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
019df241 732 }
733
96ebe67e 734 // Create iterators to loop over clusters in both chambers
735 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
736 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
737
738 // look for candidates in chamber 2
739 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
019df241 740
96ebe67e 741 // try to add the current cluster fast
742 if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
019df241 743
96ebe67e 744 // try to add the current cluster accuratly
745 extrapTrackParamAtCluster2 = trackParam;
746 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
747 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
019df241 748
96ebe67e 749 // if good chi2 then try to attach a cluster in the other chamber too
750 if (chi2WithOneCluster < maxChi2WithOneCluster) {
751 Bool_t foundSecondCluster = kFALSE;
019df241 752
753 // Printout for debuging
754 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 755 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
756 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
9bf6860b 757 clusterCh2->Print();
96ebe67e 758 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
019df241 759 }
760
761 // add MCS effect
96ebe67e 762 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
019df241 763
96ebe67e 764 // reset cluster iterator of chamber 1
765 nextInCh1.Reset();
766 iCluster1 = -1;
767
768 // look for second candidates in chamber 1
769 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
770 iCluster1++;
019df241 771
96ebe67e 772 // try to add the current cluster fast
773 if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
019df241 774
96ebe67e 775 // try to add the current cluster in addition to the one found in the previous chamber
776 chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
019df241 777
96ebe67e 778 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
779 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
780 foundSecondCluster = kTRUE;
781 foundTwoClusters = kTRUE;
019df241 782
783 // Printout for debuging
784 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 785 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
9bf6860b 786 << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
787 clusterCh1->Print();
019df241 788 }
789
a0dc65b4 790 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 791 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
019df241 792 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 793 extrapTrackParamAtCluster1.SetRemovable(kTRUE);
794 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
795 extrapTrackParamAtCluster2.SetRemovable(kTRUE);
796 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
019df241 797 fNRecTracks++;
798
96ebe67e 799 // Tag clusterCh1 as used
800 clusterCh1Used[iCluster1] = kTRUE;
019df241 801
802 // Printout for debuging
803 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 804 cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
019df241 805 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
806 }
807
96ebe67e 808 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
809 // keep track of the best couple of clusters
810 bestChi2WithTwoClusters = chi2WithTwoClusters;
811 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
812 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
019df241 813 }
814
815 }
816
817 }
818
96ebe67e 819 // if no cluster found in chamber1 then consider to add clusterCh2 only
820 if (!foundSecondCluster) {
821 foundOneCluster = kTRUE;
019df241 822
a0dc65b4 823 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 824 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 825 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 826 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 827 extrapTrackParamAtCluster2.SetRemovable(kFALSE);
828 else extrapTrackParamAtCluster2.SetRemovable(kTRUE);
96ebe67e 829 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
019df241 830 fNRecTracks++;
831
832 // Printout for debuging
833 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 834 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
019df241 835 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
836 }
837
96ebe67e 838 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
839 // keep track of the best cluster except if a couple of clusters has already been found
840 bestChi2WithOneCluster = chi2WithOneCluster;
841 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
019df241 842 }
843
844 }
845
846 }
847
848 }
849
850 // look for candidates in chamber 1 not already attached to a track
96ebe67e 851 // if we want to keep all possible tracks or if no good couple of clusters has been found
a0dc65b4 852 if (GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
019df241 853
854 // Printout for debuging
855 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 856 cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
019df241 857 }
858
859 //Extrapolate trackCandidate to chamber "ch2"
860 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
861
862 // add MCS effect for next step
863 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
9bf6860b 864
96ebe67e 865 // reset cluster iterator of chamber 1
866 nextInCh1.Reset();
867 iCluster1 = -1;
868
869 // look for second candidates in chamber 1
870 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
871 iCluster1++;
019df241 872
96ebe67e 873 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
019df241 874
96ebe67e 875 // try to add the current cluster fast
876 if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
9bf6860b 877
96ebe67e 878 // try to add the current cluster accuratly
879 extrapTrackParamAtCluster1 = trackParam;
880 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
881 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
9bf6860b 882
96ebe67e 883 // if good chi2 then consider to add clusterCh1
884 // We do not try to attach a cluster in the other chamber too since it has already been done above
885 if (chi2WithOneCluster < maxChi2WithOneCluster) {
886 foundOneCluster = kTRUE;
019df241 887
888 // Printout for debuging
889 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 890 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
891 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
9bf6860b 892 clusterCh1->Print();
019df241 893 }
894
a0dc65b4 895 if (GetRecoParam()->TrackAllTracks()) {
96ebe67e 896 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 897 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
a0dc65b4 898 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 899 extrapTrackParamAtCluster1.SetRemovable(kFALSE);
900 else extrapTrackParamAtCluster1.SetRemovable(kTRUE);
96ebe67e 901 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
019df241 902 fNRecTracks++;
903
904 // Printout for debuging
905 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 906 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
019df241 907 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
908 }
909
96ebe67e 910 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
911 // keep track of the best cluster except if a couple of clusters has already been found
912 bestChi2WithOneCluster = chi2WithOneCluster;
913 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
019df241 914 }
915
916 }
917
918 }
919
920 }
921
922 // fill out the best track if required else clean up the fRecTracksPtr array
a0dc65b4 923 if (!GetRecoParam()->TrackAllTracks()) {
96ebe67e 924 if (foundTwoClusters) {
925 bestTrackParamAtCluster1.SetRemovable(kTRUE);
926 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
927 bestTrackParamAtCluster2.SetRemovable(kTRUE);
928 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
019df241 929
930 // Printout for debuging
931 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 932 cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
019df241 933 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
934 }
935
96ebe67e 936 } else if (foundOneCluster) {
a0dc65b4 937 if (GetRecoParam()->RequestStation(nextStation))
9bf6860b 938 bestTrackParamAtCluster1.SetRemovable(kFALSE);
939 else bestTrackParamAtCluster1.SetRemovable(kTRUE);
96ebe67e 940 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
019df241 941
942 // Printout for debuging
943 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 944 cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
019df241 945 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
946 }
947
dd230855 948 } else {
96ebe67e 949 delete [] clusterCh1Used;
dd230855 950 return kFALSE;
951 }
019df241 952
96ebe67e 953 } else if (foundOneCluster || foundTwoClusters) {
019df241 954
955 // remove obsolete track
956 fRecTracksPtr->Remove(&trackCandidate);
957 fNRecTracks--;
958
dd230855 959 } else {
96ebe67e 960 delete [] clusterCh1Used;
dd230855 961 return kFALSE;
962 }
ea94c18b 963
96ebe67e 964 delete [] clusterCh1Used;
019df241 965 return kTRUE;
ea94c18b 966
967}
968
7332f213 969//__________________________________________________________________________
970void AliMUONVTrackReconstructor::ImproveTracks()
971{
972 /// Improve tracks by removing clusters with local chi2 highter than the defined cut
973 /// Recompute track parameters and covariances at the remaining clusters
974 AliDebug(1,"Enter ImproveTracks");
975
976 AliMUONTrack *track, *nextTrack;
977
7332f213 978 track = (AliMUONTrack*) fRecTracksPtr->First();
979 while (track) {
980
981 // prepare next track in case the actual track is suppressed
982 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track);
983
984 ImproveTrack(*track);
985
986 // remove track if improvement failed
987 if (!track->IsImproved()) {
988 fRecTracksPtr->Remove(track);
989 fNRecTracks--;
990 }
991
992 track = nextTrack;
993 }
994
995 // compress the array in case of some tracks have been removed
996 fRecTracksPtr->Compress();
997
998}
999
1000//__________________________________________________________________________
1001void AliMUONVTrackReconstructor::Finalize()
1002{
1003 /// Recompute track parameters and covariances at each attached cluster from those at the first one
2e2d0c44 1004 /// Set the label pointing to the corresponding MC track
7332f213 1005
1006 AliMUONTrack *track;
1007
1008 track = (AliMUONTrack*) fRecTracksPtr->First();
1009 while (track) {
1010
1011 FinalizeTrack(*track);
1012
2e2d0c44 1013 track->FindMCLabel();
1014
7332f213 1015 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1016
1017 }
1018
1019}
1020
1021//__________________________________________________________________________
7ec3b9cf 1022void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
1023 const AliMUONVTriggerTrackStore& triggerTrackStore,
1024 const AliMUONVTriggerStore& triggerStore,
1025 const AliMUONTrackHitPattern& trackHitPattern)
8d0843c6 1026{
1027 /// Try to match track from tracking system with trigger track
b709ac13 1028 AliCodeTimerAuto("");
fda59e58 1029
683cb6c5 1030 trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
8d0843c6 1031}
1032
ea94c18b 1033 //__________________________________________________________________________
1034void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
1035 const AliMUONVTriggerStore& triggerStore,
1036 AliMUONVTriggerTrackStore& triggerTrackStore)
8d0843c6 1037{
71a2d3aa 1038 /// To make the trigger tracks from Local Trigger
7ec3b9cf 1039 AliDebug(1, "");
b709ac13 1040 AliCodeTimerAuto("");
7ec3b9cf 1041
1042 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
e6b25a6e 1043
7ec3b9cf 1044 UChar_t gloTrigPat = 0;
e6b25a6e 1045
7ec3b9cf 1046 if (globalTrigger)
1047 {
1048 gloTrigPat = globalTrigger->GetGlobalResponse();
e6b25a6e 1049 }
1050
7ec3b9cf 1051 TIter next(triggerStore.CreateIterator());
1052 AliMUONLocalTrigger* locTrg(0x0);
8d0843c6 1053
e6b25a6e 1054 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
1055 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
7cf63da6 1056
7ec3b9cf 1057 AliMUONTriggerTrack triggerTrack;
1058
1059 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
1060 {
d72d7b9e 1061 Bool_t xTrig=locTrg->IsTrigX();
1062 Bool_t yTrig=locTrg->IsTrigY();
7ec3b9cf 1063
32ab62c9 1064 Int_t localBoardId = locTrg->LoCircuit();
7ec3b9cf 1065
1066 if (xTrig && yTrig)
1067 { // make Trigger Track if trigger in X and Y
8b0baca4 1068
32ab62c9 1069 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
7ec3b9cf 1070 // need first to convert deviation to [0-30]
1071 // (see AliMUONLocalTriggerBoard::LocalTrigger)
d72d7b9e 1072 Int_t deviation = locTrg->GetDeviation();
7ec3b9cf 1073 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
32ab62c9 1074 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
1075 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
7ec3b9cf 1076
1077 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
1078 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
1079
1080 Float_t thetax = TMath::ATan2( x11 , z11 );
1081 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
1082
1083 triggerTrack.SetX11(x11);
1084 triggerTrack.SetY11(y11);
1085 triggerTrack.SetThetax(thetax);
1086 triggerTrack.SetThetay(thetay);
1087 triggerTrack.SetGTPattern(gloTrigPat);
32ab62c9 1088 triggerTrack.SetLoTrgNum(localBoardId);
7ec3b9cf 1089
1090 triggerTrackStore.Add(triggerTrack);
1091 } // board is fired
e6b25a6e 1092 } // end of loop on Local Trigger
8d0843c6 1093}
ea94c18b 1094