Bug fixed for conversion to same float value for start/end timestamps
[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 //__________________________________________________________________________
ea94c18b 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
ea94c18b 139 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
96ebe67e 140 MakeTrackCandidates(clusterStore);
141
142 // Stop tracking if no candidate found
ea94c18b 143 if (fRecTracksPtr->GetEntriesFast() == 0) return;
96ebe67e 144
ea94c18b 145 // Follow tracks in stations(1..) 3, 2 and 1
96ebe67e 146 FollowTracks(clusterStore);
147
b709ac13 148 // Complement the reconstructed tracks
96ebe67e 149 if (AliMUONReconstructor::GetRecoParam()->ComplementTracks()) ComplementTracks(clusterStore);
150
ea94c18b 151 // Improve the reconstructed tracks
3304fa09 152 if (AliMUONReconstructor::GetRecoParam()->ImproveTracks()) ImproveTracks();
96ebe67e 153
ea94c18b 154 // Remove double tracks
155 RemoveDoubleTracks();
96ebe67e 156
ea94c18b 157 // Fill AliMUONTrack data members
158 Finalize();
96ebe67e 159
160 // Add tracks to MUON data container
161 for (Int_t i=0; i<fNRecTracks; ++i)
162 {
163 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
164 trackStore.Add(*track);
165 }
ea94c18b 166}
167
168 //__________________________________________________________________________
96ebe67e 169TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(const AliMUONVClusterStore& clusterStore, Int_t station)
8d0843c6 170{
96ebe67e 171 /// To make the list of segments in station(0..) "Station" from the list of clusters to be reconstructed.
208f139e 172 /// Return a new TClonesArray of segments.
173 /// It is the responsibility of the user to delete it afterward.
96ebe67e 174 AliDebug(1,Form("Enter MakeSegmentsPerStation (1..) %d",station+1));
208f139e 175
96ebe67e 176 AliMUONVCluster *cluster1, *cluster2;
208f139e 177 AliMUONObjectPair *segment;
22ccc301 178 Double_t bendingSlope = 0, impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
208f139e 179 Int_t ch1 = 2 * station;
8d0843c6 180 Int_t ch2 = ch1 + 1;
7ec3b9cf 181
96ebe67e 182 // Create iterators to loop over clusters in both chambers
183 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
184 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
185
208f139e 186 // list of segments
96ebe67e 187 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", 100);
7ec3b9cf 188 segments->SetOwner(kTRUE);
189
96ebe67e 190 // Loop over clusters in the first chamber of the station
191 while ( ( cluster1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
192
193 // reset cluster iterator of chamber 2
194 nextInCh2.Reset();
195
196 // Loop over clusters in the second chamber of the station
197 while ( ( cluster2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
198
199 // bending slope
200 bendingSlope = (cluster1->GetY() - cluster2->GetY()) / (cluster1->GetZ() - cluster2->GetZ());
201
202 // impact parameter
203 impactParam = cluster1->GetY() - cluster1->GetZ() * bendingSlope;
204
205 // absolute value of bending momentum
206 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
207
22ccc301 208 // check for bending momentum within tolerances
3304fa09 209 if ((bendingMomentum < AliMUONReconstructor::GetRecoParam()->GetMaxBendingMomentum()) &&
96ebe67e 210 (bendingMomentum > AliMUONReconstructor::GetRecoParam()->GetMinBendingMomentum())) {
211
212 // make new segment
213 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(cluster1, cluster2, kFALSE, kFALSE);
214
215 // Printout for debug
216 if (AliLog::GetGlobalDebugLevel() > 1) {
7ec3b9cf 217 cout << "segmentIndex(0...): " << segments->GetLast() << endl;
218 segment->Dump();
96ebe67e 219 cout << "Cluster in first chamber" << endl;
220 cluster1->Print();
221 cout << "Cluster in second chamber" << endl;
222 cluster2->Print();
7ec3b9cf 223 }
96ebe67e 224
8d0843c6 225 }
96ebe67e 226
227 }
228
229 }
230
231 // Printout for debug
232 AliDebug(1,Form("Station: %d NSegments: %d ", station+1, segments->GetEntriesFast()));
233
208f139e 234 return segments;
8d0843c6 235}
236
ea94c18b 237 //__________________________________________________________________________
238void AliMUONVTrackReconstructor::RemoveIdenticalTracks()
239{
240 /// To remove identical tracks:
96ebe67e 241 /// Tracks are considered identical if they have all their clusters in common.
242 /// One keeps the track with the larger number of clusters if need be
ea94c18b 243 AliMUONTrack *track1, *track2, *trackToRemove;
96ebe67e 244 Int_t clustersInCommon, nClusters1, nClusters2;
ea94c18b 245 Bool_t removedTrack1;
246 // Loop over first track of the pair
247 track1 = (AliMUONTrack*) fRecTracksPtr->First();
248 while (track1) {
249 removedTrack1 = kFALSE;
96ebe67e 250 nClusters1 = track1->GetNClusters();
ea94c18b 251 // Loop over second track of the pair
252 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
253 while (track2) {
96ebe67e 254 nClusters2 = track2->GetNClusters();
255 // number of clusters in common between two tracks
256 clustersInCommon = track1->ClustersInCommon(track2);
ea94c18b 257 // check for identical tracks
96ebe67e 258 if ((clustersInCommon == nClusters1) || (clustersInCommon == nClusters2)) {
ea94c18b 259 // decide which track to remove
96ebe67e 260 if (nClusters2 > nClusters1) {
ea94c18b 261 // remove track1 and continue the first loop with the track next to track1
262 trackToRemove = track1;
263 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
264 fRecTracksPtr->Remove(trackToRemove);
265 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
266 fNRecTracks--;
267 removedTrack1 = kTRUE;
268 break;
269 } else {
270 // remove track2 and continue the second loop with the track next to track2
271 trackToRemove = track2;
272 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
273 fRecTracksPtr->Remove(trackToRemove);
274 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
275 fNRecTracks--;
276 }
277 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
278 } // track2
279 if (removedTrack1) continue;
280 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
281 } // track1
282 return;
283}
284
285 //__________________________________________________________________________
286void AliMUONVTrackReconstructor::RemoveDoubleTracks()
287{
288 /// To remove double tracks:
96ebe67e 289 /// Tracks are considered identical if more than half of the clusters of the track
290 /// which has the smaller number of clusters are in common with the other track.
291 /// Among two identical tracks, one keeps the track with the larger number of clusters
ea94c18b 292 /// or, if these numbers are equal, the track with the minimum chi2.
293 AliMUONTrack *track1, *track2, *trackToRemove;
96ebe67e 294 Int_t clustersInCommon, nClusters1, nClusters2;
ea94c18b 295 Bool_t removedTrack1;
296 // Loop over first track of the pair
297 track1 = (AliMUONTrack*) fRecTracksPtr->First();
298 while (track1) {
299 removedTrack1 = kFALSE;
96ebe67e 300 nClusters1 = track1->GetNClusters();
ea94c18b 301 // Loop over second track of the pair
302 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
303 while (track2) {
96ebe67e 304 nClusters2 = track2->GetNClusters();
305 // number of clusters in common between two tracks
306 clustersInCommon = track1->ClustersInCommon(track2);
ea94c18b 307 // check for identical tracks
96ebe67e 308 if (((nClusters1 < nClusters2) && (2 * clustersInCommon > nClusters1)) || (2 * clustersInCommon > nClusters2)) {
ea94c18b 309 // decide which track to remove
96ebe67e 310 if ((nClusters1 > nClusters2) || ((nClusters1 == nClusters2) && (track1->GetGlobalChi2() <= track2->GetGlobalChi2()))) {
ea94c18b 311 // remove track2 and continue the second loop with the track next to track2
312 trackToRemove = track2;
313 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
314 fRecTracksPtr->Remove(trackToRemove);
315 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
316 fNRecTracks--;
317 } else {
318 // else remove track1 and continue the first loop with the track next to track1
319 trackToRemove = track1;
320 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
321 fRecTracksPtr->Remove(trackToRemove);
322 fRecTracksPtr->Compress(); // this is essential to retrieve the TClonesArray afterwards
323 fNRecTracks--;
324 removedTrack1 = kTRUE;
325 break;
326 }
327 } else track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
328 } // track2
329 if (removedTrack1) continue;
330 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
331 } // track1
332 return;
333}
334
335 //__________________________________________________________________________
1fef78c8 336void AliMUONVTrackReconstructor::AskForNewClustersInStation(const AliMUONTrackParam &trackParam,
337 AliMUONVClusterStore& clusterStore, Int_t station)
338{
339 /// Ask the clustering to reconstruct new clusters around the track candidate position
340 /// in the 2 chambers of the given station
341
342 // maximum shift of the searching area due to distance between detection elements and the track slope
343 static const Double_t kgMaxShift = 2.; // 2 cm
344
345 // extrapolate track parameters to the second chamber of the station
346 AliMUONTrackParam extrapTrackParam(trackParam);
347 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(2*station+1));
348
349 // build the searching area
350 TVector2 position(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
351 TVector2 dimensions(AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() + kgMaxShift,
352 AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack() + kgMaxShift);
353 AliMpArea area2(position, dimensions);
354
355 // ask to cluterize in the given area of the given chamber
356 fClusterServer.Clusterize(2*station+1, clusterStore, area2);
357
358 // extrapolate track parameters to the first chamber of the station
359 AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(2*station));
360
361 // build the searching area
362 position.Set(extrapTrackParam.GetNonBendingCoor(), extrapTrackParam.GetBendingCoor());
363// dimensions.Set(AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() + kgMaxShift,
364// AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack() + kgMaxShift);
365 AliMpArea area1(position, dimensions);
366
367 // ask to cluterize in the given area of the given chamber
368 fClusterServer.Clusterize(2*station, clusterStore, area1);
369}
370
371 //__________________________________________________________________________
96ebe67e 372Double_t AliMUONVTrackReconstructor::TryOneCluster(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster,
1fef78c8 373 AliMUONTrackParam &trackParamAtCluster, Bool_t updatePropagator)
ea94c18b 374{
96ebe67e 375/// Test the compatibility between the track and the cluster (using trackParam's covariance matrix):
ea94c18b 376/// return the corresponding Chi2
96ebe67e 377/// return trackParamAtCluster
ea94c18b 378
96ebe67e 379 // extrapolate track parameters and covariances at the z position of the tested cluster
380 trackParamAtCluster = trackParam;
381 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtCluster, cluster->GetZ(), updatePropagator);
ea94c18b 382
96ebe67e 383 // set pointer to cluster into trackParamAtCluster
384 trackParamAtCluster.SetClusterPtr(cluster);
ea94c18b 385
96ebe67e 386 // Set differences between trackParam and cluster in the bending and non bending directions
387 Double_t dX = cluster->GetX() - trackParamAtCluster.GetNonBendingCoor();
388 Double_t dY = cluster->GetY() - trackParamAtCluster.GetBendingCoor();
ea94c18b 389
019df241 390 // Calculate errors and covariances
96ebe67e 391 const TMatrixD& kParamCov = trackParamAtCluster.GetCovariances();
392 Double_t sigmaX2 = kParamCov(0,0) + cluster->GetErrX2();
393 Double_t sigmaY2 = kParamCov(2,2) + cluster->GetErrY2();
019df241 394
395 // Compute chi2
96ebe67e 396 return dX * dX / sigmaX2 + dY * dY / sigmaY2;
019df241 397
398}
399
400 //__________________________________________________________________________
96ebe67e 401Bool_t AliMUONVTrackReconstructor::TryOneClusterFast(const AliMUONTrackParam &trackParam, AliMUONVCluster* cluster)
019df241 402{
96ebe67e 403/// Test the compatibility between the track and the cluster within a wide fix window
019df241 404/// assuming linear propagation of the track:
405/// return kTRUE if they are compatibles
406
96ebe67e 407 Double_t dZ = cluster->GetZ() - trackParam.GetZ();
408 Double_t dX = cluster->GetX() - (trackParam.GetNonBendingCoor() + trackParam.GetNonBendingSlope() * dZ);
409 Double_t dY = cluster->GetY() - (trackParam.GetBendingCoor() + trackParam.GetBendingSlope() * dZ);
019df241 410
3304fa09 411 if (TMath::Abs(dX) > AliMUONReconstructor::GetRecoParam()->GetMaxNonBendingDistanceToTrack() ||
412 TMath::Abs(dY) > AliMUONReconstructor::GetRecoParam()->GetMaxBendingDistanceToTrack()) return kFALSE;
019df241 413
414 return kTRUE;
415
416}
417
418 //__________________________________________________________________________
96ebe67e 419Double_t AliMUONVTrackReconstructor::TryTwoClustersFast(const AliMUONTrackParam &trackParamAtCluster1, AliMUONVCluster* cluster2,
420 AliMUONTrackParam &trackParamAtCluster2)
019df241 421{
96ebe67e 422/// Test the compatibility between the track and the 2 clusters together (using trackParam's covariance matrix)
423/// assuming linear propagation between the two clusters:
424/// return the corresponding Chi2 accounting for covariances between the 2 clusters
425/// return trackParamAtCluster2
019df241 426
96ebe67e 427 // extrapolate linearly track parameters and covariances at the z position of the second cluster
428 trackParamAtCluster2 = trackParamAtCluster1;
429 AliMUONTrackExtrap::LinearExtrapToZ(&trackParamAtCluster2, cluster2->GetZ());
019df241 430
96ebe67e 431 // set pointer to cluster2 into trackParamAtCluster2
432 trackParamAtCluster2.SetClusterPtr(cluster2);
019df241 433
96ebe67e 434 // Set differences between track and clusters in the bending and non bending directions
435 AliMUONVCluster* cluster1 = trackParamAtCluster1.GetClusterPtr();
436 Double_t dX1 = cluster1->GetX() - trackParamAtCluster1.GetNonBendingCoor();
437 Double_t dX2 = cluster2->GetX() - trackParamAtCluster2.GetNonBendingCoor();
438 Double_t dY1 = cluster1->GetY() - trackParamAtCluster1.GetBendingCoor();
439 Double_t dY2 = cluster2->GetY() - trackParamAtCluster2.GetBendingCoor();
019df241 440
441 // Calculate errors and covariances
96ebe67e 442 const TMatrixD& kParamCov1 = trackParamAtCluster1.GetCovariances();
443 const TMatrixD& kParamCov2 = trackParamAtCluster2.GetCovariances();
444 Double_t dZ = trackParamAtCluster2.GetZ() - trackParamAtCluster1.GetZ();
445 Double_t sigma2X1 = kParamCov1(0,0) + cluster1->GetErrX2();
446 Double_t sigma2X2 = kParamCov2(0,0) + cluster2->GetErrX2();
019df241 447 Double_t covX1X2 = kParamCov1(0,0) + dZ * kParamCov1(0,1);
96ebe67e 448 Double_t sigma2Y1 = kParamCov1(2,2) + cluster1->GetErrY2();
449 Double_t sigma2Y2 = kParamCov2(2,2) + cluster2->GetErrY2();
019df241 450 Double_t covY1Y2 = kParamCov1(2,2) + dZ * kParamCov1(2,3);
451
452 // Compute chi2
453 Double_t detX = sigma2X1 * sigma2X2 - covX1X2 * covX1X2;
454 Double_t detY = sigma2Y1 * sigma2Y2 - covY1Y2 * covY1Y2;
455 if (detX == 0. || detY == 0.) return 1.e10;
456 return (dX1 * dX1 * sigma2X2 + dX2 * dX2 * sigma2X1 - 2. * dX1 * dX2 * covX1X2) / detX
457 + (dY1 * dY1 * sigma2Y2 + dY2 * dY2 * sigma2Y1 - 2. * dY1 * dY2 * covY1Y2) / detY;
458
459}
460
461 //__________________________________________________________________________
96ebe67e 462Bool_t AliMUONVTrackReconstructor::FollowLinearTrackInStation(AliMUONTrack &trackCandidate, const AliMUONVClusterStore& clusterStore,
463 Int_t nextStation)
019df241 464{
96ebe67e 465 /// Follow trackCandidate in station(0..) nextStation assuming linear propagation, and search for compatible cluster(s)
019df241 466 /// Keep all possibilities or only the best one(s) according to the flag fgkTrackAllTracks:
467 /// kTRUE: duplicate "trackCandidate" if there are several possibilities and add the new tracks at the end of
468 /// fRecTracksPtr to avoid conficts with other track candidates at this current stage of the tracking procedure.
469 /// Remove the obsolete "trackCandidate" at the end.
96ebe67e 470 /// kFALSE: add only the best cluster(s) to the "trackCandidate". Try to add a couple of clusters in priority.
471 /// return kTRUE if new cluster(s) have been found (otherwise return kFALSE)
019df241 472 AliDebug(1,Form("Enter FollowLinearTrackInStation(1..) %d", nextStation+1));
473
474 // Order the chamber according to the propagation direction (tracking starts with chamber 2):
475 // - nextStation == station(1...) 5 => forward propagation
476 // - nextStation < station(1...) 5 => backward propagation
477 Int_t ch1, ch2;
478 if (nextStation==4) {
479 ch1 = 2*nextStation+1;
480 ch2 = 2*nextStation;
ea94c18b 481 } else {
019df241 482 ch1 = 2*nextStation;
483 ch2 = 2*nextStation+1;
ea94c18b 484 }
485
96ebe67e 486 Double_t chi2WithOneCluster = 1.e10;
487 Double_t chi2WithTwoClusters = 1.e10;
488 Double_t maxChi2WithOneCluster = 2. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
489 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
490 Double_t maxChi2WithTwoClusters = 4. * AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking() *
491 AliMUONReconstructor::GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
492 Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
493 Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
494 Bool_t foundOneCluster = kFALSE;
495 Bool_t foundTwoClusters = kFALSE;
019df241 496 AliMUONTrack *newTrack = 0x0;
96ebe67e 497 AliMUONVCluster *clusterCh1, *clusterCh2;
498 AliMUONTrackParam extrapTrackParamAtCluster1;
499 AliMUONTrackParam extrapTrackParamAtCluster2;
500 AliMUONTrackParam bestTrackParamAtCluster1;
501 AliMUONTrackParam bestTrackParamAtCluster2;
502
503 Int_t nClusters = clusterStore.GetSize();
504 Bool_t *clusterCh1Used = new Bool_t[nClusters];
505 for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
506 Int_t iCluster1;
019df241 507
508 // Get track parameters
96ebe67e 509 AliMUONTrackParam trackParam(*(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First());
019df241 510
511 // Add MCS effect
512 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
513
514 // Printout for debuging
515 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 516 cout << "FollowLinearTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
019df241 517 }
518
96ebe67e 519 // Create iterators to loop over clusters in both chambers
520 TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
521 TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
522
523 // look for candidates in chamber 2
524 while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
019df241 525
96ebe67e 526 // try to add the current cluster fast
527 if (!TryOneClusterFast(trackParam, clusterCh2)) continue;
019df241 528
96ebe67e 529 // try to add the current cluster accuratly
530 extrapTrackParamAtCluster2 = trackParam;
531 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster2, clusterCh2->GetZ());
532 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster2, clusterCh2, extrapTrackParamAtCluster2);
019df241 533
96ebe67e 534 // if good chi2 then try to attach a cluster in the other chamber too
535 if (chi2WithOneCluster < maxChi2WithOneCluster) {
536 Bool_t foundSecondCluster = kFALSE;
019df241 537
538 // Printout for debuging
539 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 540 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch2+1
541 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
542 cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
019df241 543 }
544
545 // add MCS effect
96ebe67e 546 AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(),1.);
019df241 547
96ebe67e 548 // reset cluster iterator of chamber 1
549 nextInCh1.Reset();
550 iCluster1 = -1;
551
552 // look for second candidates in chamber 1
553 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
554 iCluster1++;
019df241 555
96ebe67e 556 // try to add the current cluster fast
557 if (!TryOneClusterFast(extrapTrackParamAtCluster2, clusterCh1)) continue;
019df241 558
96ebe67e 559 // try to add the current cluster in addition to the one found in the previous chamber
560 chi2WithTwoClusters = TryTwoClustersFast(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
019df241 561
96ebe67e 562 // if good chi2 then consider to add the 2 clusters to the "trackCandidate"
563 if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
564 foundSecondCluster = kTRUE;
565 foundTwoClusters = kTRUE;
019df241 566
567 // Printout for debuging
568 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 569 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
570 << " (Chi2 = " << chi2WithTwoClusters << ")" << endl;
019df241 571 }
572
3304fa09 573 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
96ebe67e 574 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
019df241 575 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 576 extrapTrackParamAtCluster1.SetRemovable(kTRUE);
577 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
578 extrapTrackParamAtCluster2.SetRemovable(kTRUE);
579 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
580 newTrack->GetTrackParamAtCluster()->Sort();
019df241 581 fNRecTracks++;
582
96ebe67e 583 // Tag clusterCh1 as used
584 clusterCh1Used[iCluster1] = kTRUE;
019df241 585
586 // Printout for debuging
587 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 588 cout << "FollowLinearTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
019df241 589 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
590 }
591
96ebe67e 592 } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
593 // keep track of the best couple of clusters
594 bestChi2WithTwoClusters = chi2WithTwoClusters;
595 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
596 bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
019df241 597 }
598
599 }
600
601 }
602
96ebe67e 603 // if no cluster found in chamber1 then consider to add clusterCh2 only
604 if (!foundSecondCluster) {
605 foundOneCluster = kTRUE;
019df241 606
3304fa09 607 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
96ebe67e 608 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 609 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 610 extrapTrackParamAtCluster2.SetRemovable(kFALSE);
611 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster2,*clusterCh2);
612 newTrack->GetTrackParamAtCluster()->Sort();
019df241 613 fNRecTracks++;
614
615 // Printout for debuging
616 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 617 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch2+1 << endl;
019df241 618 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
619 }
620
96ebe67e 621 } else if (!foundTwoClusters && chi2WithOneCluster < bestChi2WithOneCluster) {
622 // keep track of the best cluster except if a couple of clusters has already been found
623 bestChi2WithOneCluster = chi2WithOneCluster;
624 bestTrackParamAtCluster1 = extrapTrackParamAtCluster2;
019df241 625 }
626
627 }
628
629 }
630
631 }
632
633 // look for candidates in chamber 1 not already attached to a track
96ebe67e 634 // if we want to keep all possible tracks or if no good couple of clusters has been found
635 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks() || !foundTwoClusters) {
019df241 636
637 // Printout for debuging
638 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 639 cout << "FollowLinearTrackInStation: look for single cluster in chamber(1..): " << ch1+1 << endl;
019df241 640 }
641
642 //Extrapolate trackCandidate to chamber "ch2"
643 AliMUONTrackExtrap::LinearExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(ch2));
644
645 // add MCS effect for next step
646 AliMUONTrackExtrap::AddMCSEffect(&trackParam,AliMUONConstants::ChamberThicknessInX0(),1.);
647
96ebe67e 648 // reset cluster iterator of chamber 1
649 nextInCh1.Reset();
650 iCluster1 = -1;
651
652 // look for second candidates in chamber 1
653 while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
654 iCluster1++;
019df241 655
96ebe67e 656 if (clusterCh1Used[iCluster1]) continue; // Skip clusters already used
019df241 657
96ebe67e 658 // try to add the current cluster fast
659 if (!TryOneClusterFast(trackParam, clusterCh1)) continue;
019df241 660
96ebe67e 661 // try to add the current cluster accuratly
662 extrapTrackParamAtCluster1 = trackParam;
663 AliMUONTrackExtrap::LinearExtrapToZ(&extrapTrackParamAtCluster1, clusterCh1->GetZ());
664 chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCluster1, clusterCh1, extrapTrackParamAtCluster1);
019df241 665
96ebe67e 666 // if good chi2 then consider to add clusterCh1
667 // We do not try to attach a cluster in the other chamber too since it has already been done above
668 if (chi2WithOneCluster < maxChi2WithOneCluster) {
669 foundOneCluster = kTRUE;
019df241 670
671 // Printout for debuging
672 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 673 cout << "FollowLinearTrackInStation: found one cluster in chamber(1..): " << ch1+1
674 << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
019df241 675 }
676
3304fa09 677 if (AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
96ebe67e 678 // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new cluster
019df241 679 newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
96ebe67e 680 extrapTrackParamAtCluster1.SetRemovable(kFALSE);
681 newTrack->AddTrackParamAtCluster(extrapTrackParamAtCluster1,*clusterCh1);
682 newTrack->GetTrackParamAtCluster()->Sort();
019df241 683 fNRecTracks++;
684
685 // Printout for debuging
686 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 687 cout << "FollowLinearTrackInStation: added one cluster in chamber(1..): " << ch1+1 << endl;
019df241 688 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
689 }
690
96ebe67e 691 } else if (chi2WithOneCluster < bestChi2WithOneCluster) {
692 // keep track of the best cluster except if a couple of clusters has already been found
693 bestChi2WithOneCluster = chi2WithOneCluster;
694 bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
019df241 695 }
696
697 }
698
699 }
700
701 }
702
703 // fill out the best track if required else clean up the fRecTracksPtr array
3304fa09 704 if (!AliMUONReconstructor::GetRecoParam()->TrackAllTracks()) {
96ebe67e 705 if (foundTwoClusters) {
706 bestTrackParamAtCluster1.SetRemovable(kTRUE);
707 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
708 bestTrackParamAtCluster2.SetRemovable(kTRUE);
709 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster2,*(bestTrackParamAtCluster2.GetClusterPtr()));
710 trackCandidate.GetTrackParamAtCluster()->Sort();
019df241 711
712 // Printout for debuging
713 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 714 cout << "FollowLinearTrackInStation: added the two best clusters in station(1..): " << nextStation+1 << endl;
019df241 715 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
716 }
717
96ebe67e 718 } else if (foundOneCluster) {
719 bestTrackParamAtCluster1.SetRemovable(kFALSE);
720 trackCandidate.AddTrackParamAtCluster(bestTrackParamAtCluster1,*(bestTrackParamAtCluster1.GetClusterPtr()));
721 trackCandidate.GetTrackParamAtCluster()->Sort();
019df241 722
723 // Printout for debuging
724 if ((AliLog::GetDebugLevel("MUON","AliMUONVTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
96ebe67e 725 cout << "FollowLinearTrackInStation: added the best cluster in chamber(1..): " << bestTrackParamAtCluster1.GetClusterPtr()->GetChamberId()+1 << endl;
019df241 726 if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
727 }
728
dd230855 729 } else {
96ebe67e 730 delete [] clusterCh1Used;
dd230855 731 return kFALSE;
732 }
019df241 733
96ebe67e 734 } else if (foundOneCluster || foundTwoClusters) {
019df241 735
736 // remove obsolete track
737 fRecTracksPtr->Remove(&trackCandidate);
738 fNRecTracks--;
739
dd230855 740 } else {
96ebe67e 741 delete [] clusterCh1Used;
dd230855 742 return kFALSE;
743 }
ea94c18b 744
96ebe67e 745 delete [] clusterCh1Used;
019df241 746 return kTRUE;
ea94c18b 747
748}
749
750 //__________________________________________________________________________
7ec3b9cf 751void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(AliMUONVTrackStore& trackStore,
752 const AliMUONVTriggerTrackStore& triggerTrackStore,
753 const AliMUONVTriggerStore& triggerStore,
754 const AliMUONTrackHitPattern& trackHitPattern)
8d0843c6 755{
756 /// Try to match track from tracking system with trigger track
b709ac13 757 AliCodeTimerAuto("");
fda59e58 758
683cb6c5 759 trackHitPattern.ExecuteValidation(trackStore, triggerTrackStore, triggerStore);
8d0843c6 760}
761
ea94c18b 762 //__________________________________________________________________________
763void AliMUONVTrackReconstructor::EventReconstructTrigger(const AliMUONTriggerCircuit& circuit,
764 const AliMUONVTriggerStore& triggerStore,
765 AliMUONVTriggerTrackStore& triggerTrackStore)
8d0843c6 766{
71a2d3aa 767 /// To make the trigger tracks from Local Trigger
7ec3b9cf 768 AliDebug(1, "");
b709ac13 769 AliCodeTimerAuto("");
7ec3b9cf 770
771 AliMUONGlobalTrigger* globalTrigger = triggerStore.Global();
e6b25a6e 772
7ec3b9cf 773 UChar_t gloTrigPat = 0;
e6b25a6e 774
7ec3b9cf 775 if (globalTrigger)
776 {
777 gloTrigPat = globalTrigger->GetGlobalResponse();
e6b25a6e 778 }
779
7ec3b9cf 780 TIter next(triggerStore.CreateIterator());
781 AliMUONLocalTrigger* locTrg(0x0);
8d0843c6 782
e6b25a6e 783 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
784 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
7cf63da6 785
7ec3b9cf 786 AliMUONTriggerTrack triggerTrack;
787
788 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
789 {
790 Bool_t xTrig=kFALSE;
791 Bool_t yTrig=kFALSE;
792
32ab62c9 793 Int_t localBoardId = locTrg->LoCircuit();
7ec3b9cf 794 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
795 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
796 else xTrig=kTRUE; // trigger in X
797 if (locTrg->LoTrigY()==1 &&
798 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
799 else yTrig = kTRUE; // trigger in Y
800
801 if (xTrig && yTrig)
802 { // make Trigger Track if trigger in X and Y
8b0baca4 803
32ab62c9 804 Float_t y11 = circuit.GetY11Pos(localBoardId, locTrg->LoStripX());
7ec3b9cf 805 // need first to convert deviation to [0-30]
806 // (see AliMUONLocalTriggerBoard::LocalTrigger)
807 Int_t deviation = locTrg->LoDev();
808 Int_t sign = 0;
809 if ( !locTrg->LoSdev() && deviation ) sign=-1;
810 if ( !locTrg->LoSdev() && !deviation ) sign= 0;
811 if ( locTrg->LoSdev() == 1 ) sign=+1;
812 deviation *= sign;
813 deviation += 15;
814 Int_t stripX21 = locTrg->LoStripX()+deviation+1;
32ab62c9 815 Float_t y21 = circuit.GetY21Pos(localBoardId, stripX21);
816 Float_t x11 = circuit.GetX11Pos(localBoardId, locTrg->LoStripY());
7ec3b9cf 817
818 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %f %f %f \n",locTrg->LoCircuit(),
819 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
820
821 Float_t thetax = TMath::ATan2( x11 , z11 );
822 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
823
824 triggerTrack.SetX11(x11);
825 triggerTrack.SetY11(y11);
826 triggerTrack.SetThetax(thetax);
827 triggerTrack.SetThetay(thetay);
828 triggerTrack.SetGTPattern(gloTrigPat);
32ab62c9 829 triggerTrack.SetLoTrgNum(localBoardId);
7ec3b9cf 830
831 triggerTrackStore.Add(triggerTrack);
832 } // board is fired
e6b25a6e 833 } // end of loop on Local Trigger
8d0843c6 834}
ea94c18b 835