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