1 //========================================================================
2 // Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
4 // Author: The ALICE Off-line Project.
5 // Contributors are mentioned in the code where appropriate.
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 //========================================================================
16 // Class AliEMCALTracker
17 // -----------------------
18 // Implementation of the track matching method between barrel tracks and
20 // Besides algorithm implementation, some cuts are required to be set
21 // in order to define, for each track, an acceptance window where clusters
22 // are searched to find best match (if any).
23 // The class accepts as input an ESD container, and works directly on it,
24 // simply setting, for each of its tracks, the fEMCALindex flag, for each
25 // track which is matched to a cluster.
26 // In order to use method, one must launch PropagateBack().
28 // ------------------------------------------------------------------------
29 // author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
30 //=========================================================================
32 #include <Riostream.h>
40 #include <TClonesArray.h>
41 #include <TGeoMatrix.h>
44 #include "AliESDEvent.h"
45 #include "AliESDtrack.h"
46 #include "AliESDCaloCluster.h"
47 #include "AliEMCALRecPoint.h"
48 #include "AliRunLoader.h"
49 #include "AliEMCALTrack.h"
50 #include "AliEMCALLoader.h"
51 #include "AliEMCALGeometry.h"
52 #include "AliEMCALReconstructor.h"
53 #include "AliEMCALRecParam.h"
54 #include "AliCDBEntry.h"
55 #include "AliCDBManager.h"
57 #include "AliEMCALTracker.h"
59 ClassImp(AliEMCALTracker)
62 //------------------------------------------------------------------------------
64 AliEMCALTracker::AliEMCALTracker()
67 fTrackCorrMode(kTrackCorrNone),
83 // Default constructor.
84 // Initializes al simple data members to default values,
85 // and all collections to NULL.
86 // Output file name is set to a default value.
91 //------------------------------------------------------------------------------
93 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
95 fNPropSteps(copy.fNPropSteps),
96 fTrackCorrMode(copy.fTrackCorrMode),
100 fCutAlphaMin(copy.fCutAlphaMin),
101 fCutAlphaMax(copy.fCutAlphaMax),
102 fCutAngle(copy.fCutAngle),
103 fMaxDist(copy.fMaxDist),
106 fTracks((TObjArray*)copy.fTracks->Clone()),
107 fClusters((TObjArray*)copy.fClusters->Clone()),
108 fMatches((TList*)copy.fMatches->Clone()),
113 // Besides copying all parameters, duplicates all collections.
117 //------------------------------------------------------------------------------
119 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
122 // Assignment operator.
123 // Besides copying all parameters, duplicates all collections.
129 fCutAlphaMin = copy.fCutAlphaMin;
130 fCutAlphaMax = copy.fCutAlphaMax;
131 fCutAngle = copy.fCutAngle;
132 fMaxDist = copy.fMaxDist;
134 fTracks = (TObjArray*)copy.fTracks->Clone();
135 fClusters = (TObjArray*)copy.fClusters->Clone();
136 fMatches = (TList*)copy.fMatches->Clone();
143 //------------------------------------------------------------------------------
145 void AliEMCALTracker::InitParameters()
148 // Retrieve initialization parameters
151 // Check if the instance of AliEMCALRecParam exists,
152 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
154 AliFatal("Reconstruction parameters for EMCAL not set!");
157 fCutX = recParam->GetTrkCutX();
158 fCutY = recParam->GetTrkCutY();
159 fCutZ = recParam->GetTrkCutZ();
160 fMaxDist = recParam->GetTrkCutR();
161 fCutAngle = recParam->GetTrkCutAngle();
162 fCutAlphaMin = recParam->GetTrkCutAlphaMin();
163 fCutAlphaMax = recParam->GetTrkCutAlphaMax();
167 //------------------------------------------------------------------------------
169 TTree* AliEMCALTracker::SearchTrueMatches()
171 //Search through the list of
172 //track match candidates and clusters
173 //and look for true matches
176 if (!fClusters) return 0;
177 if (fClusters->IsEmpty()) return 0;
178 if (!fTracks) return 0;
179 if (fTracks->IsEmpty()) return 0;
181 TTree *outTree = new TTree("tree", "True matches from event");
182 Int_t indexT, indexC, label;
183 outTree->Branch("indexC", &indexC, "indexC/I");
184 outTree->Branch("indexT", &indexT, "indexT/I");
185 outTree->Branch("label", &label , "label/I");
188 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
189 Int_t it, nTracks = fTracks->GetEntries();
191 for (ic = 0; ic < nClusters; ic++) {
192 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
193 label = cluster->Label();
194 indexC = cluster->Index();
195 for (it = 0; it < nTracks; it++) {
196 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
197 if (TMath::Abs(track->GetSeedLabel()) != label) continue;
198 dist = CheckPair(track, cluster);
199 if (dist <= fMaxDist) {
200 indexT = track->GetSeedIndex();
209 //------------------------------------------------------------------------------
211 void AliEMCALTracker::Clear(Option_t* option)
215 // Deletes all objects in arrays and the arrays themselves
219 Bool_t clearTracks = opt.Contains("TRACKS");
220 Bool_t clearClusters = opt.Contains("CLUSTERS");
221 Bool_t clearMatches = opt.Contains("MATCHES");
222 if (opt.Contains("ALL")) {
224 clearClusters = kTRUE;
225 clearMatches = kTRUE;
228 if (fTracks != 0x0 && clearTracks) {
233 if (fClusters != 0x0 && clearClusters) {
238 if (fMatches != 0x0 && clearMatches) {
245 //------------------------------------------------------------------------------
247 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
250 // Load EMCAL clusters in the form of AliEMCALRecPoint,
251 // from simulation temporary files.
252 // (When included in reconstruction chain, this method is used automatically)
257 TBranch *branch = cTree->GetBranch("EMCALECARP");
259 AliError("Can't get the branch with the EMCAL clusters");
263 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
264 branch->SetAddress(&clusters);
267 Int_t nClusters = (Int_t)clusters->GetEntries();
268 fClusters = new TObjArray(0);
269 for (Int_t i = 0; i < nClusters; i++) {
270 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
271 if (!cluster) continue;
272 if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
273 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
274 fClusters->AddLast(matchCluster);
277 branch->SetAddress(0);
280 if (fClusters->IsEmpty())
281 AliWarning("No clusters collected");
283 AliInfo(Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
288 //------------------------------------------------------------------------------
290 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
293 // Load EMCAL clusters in the form of AliESDCaloClusters,
294 // from an AliESD object.
297 // make sure that tracks/clusters collections are empty
300 Int_t start = esd->GetFirstEMCALCluster();
301 Int_t nClustersEMC = esd->GetNumberOfEMCALClusters();
302 Int_t end = start + nClustersEMC;
304 fClusters = new TObjArray(0);
307 for (i = start; i < end; i++) {
308 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
309 if (!cluster) continue;
310 if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
311 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
312 fClusters->AddLast(matchCluster);
314 if (fClusters->IsEmpty())
315 AliWarning("No clusters collected");
317 AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
322 //------------------------------------------------------------------------------
324 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
332 Int_t nTracks = esd->GetNumberOfTracks();
333 fTracks = new TObjArray(0);
338 for (i = 0; i < nTracks; i++) {
339 AliESDtrack *esdTrack = esd->GetTrack(i);
340 // set by default the value corresponding to "no match"
341 esdTrack->SetEMCALcluster(kUnmatched);
342 // if (esdTrack->GetLabel() < 0) continue;
343 // if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
345 for (j = 0; j < 3; j++) {
346 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
348 if (isKink) continue;
349 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
350 track->SetMass(0.13957018);
351 // check alpha and reject the tracks which fall outside EMCAL acceptance
352 alpha = track->GetAlpha() * TMath::RadToDeg();
353 if (alpha > -155.0 && alpha < 67.0) {
357 // if (!PropagateToEMCAL(track)) {
361 track->SetSeedIndex(i);
362 track->SetSeedLabel(esdTrack->GetLabel());
363 fTracks->AddLast(track);
365 if (fTracks->IsEmpty()) {
366 AliWarning("No tracks collected");
369 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
374 //------------------------------------------------------------------------------
376 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
379 // Main operation method.
380 // Gets external AliESD containing tracks to be matched.
381 // After executing match finding, stores in the same ESD object all infos
382 // and releases the object for further reconstruction steps.
385 // Note: should always return 0=OK, because otherwise all tracking
386 // is aborted for this event
389 AliError("NULL ESD passed");
394 // if cluster array is empty, cluster are collected
395 // from the passed ESD, and work is done with ESDCaloClusters
396 Int_t okLoadClusters, nClusters;
397 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
398 okLoadClusters = LoadClusters(esd);
400 nClusters = fClusters->GetEntries();
403 // collect ESD tracks
404 Int_t okLoadTracks = LoadTracks(esd), nTracks;
405 if (okLoadTracks) return 3;
406 nTracks = fTracks->GetEntries();
409 // each track is propagated to the "R" position of each cluster.
410 // The closest cluster is assigned as match.
411 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
412 Int_t nMatches = CreateMatches();
414 AliInfo(Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
418 AliInfo(Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
422 // when more than 1 track share the same matched cluster, only the closest one is kept.
423 Int_t nRemoved = SolveCompetitions();
424 AliInfo(Form("Removed %d duplicate matches", nRemoved));
425 if (nRemoved >= nMatches) {
426 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
431 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
432 Int_t nSaved = 0, trackID, nGood = 0, nFake = 0;
433 TListIter iter(fMatches);
434 AliEMCALMatch *match = 0;
435 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
436 if (!match->CanBeSaved()) continue;
437 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
438 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
439 trackID = track->GetSeedIndex();
440 AliESDtrack *esdTrack = esd->GetTrack(trackID);
441 if (!esdTrack) continue;
442 if (TMath::Abs(esdTrack->GetLabel()) == cluster->Label()) {
443 esdTrack->SetEMCALcluster(cluster->Index());
447 esdTrack->SetEMCALcluster(-cluster->Index());
453 AliEMCALTrack *track = 0;
454 TObjArrayIter tracks(fTracks);
455 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
456 trackID = track->GetSeedIndex();
457 clusterID = track->GetMatchedClusterIndex();
458 AliESDtrack *esdTrack = esd->GetTrack(trackID);
459 if (!esdTrack) continue;
461 esdTrack->SetEMCALcluster(kUnmatched);
464 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
465 if (!cluster) continue;
466 if (esdTrack->GetLabel() == cluster->Label()) {
468 esdTrack->SetEMCALcluster(cluster->Index());
471 esdTrack->SetEMCALcluster(-cluster->Index());
477 AliInfo(Form("Saved %d matches [%d good + %d fake]", nSaved, nGood, nFake));
482 //------------------------------------------------------------------------------
484 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
487 // Set track correction mode
488 // gest the choice in string format and converts into
495 if (!opt.CompareTo("NONE")) {
496 fTrackCorrMode = kTrackCorrNone;
498 else if (!opt.CompareTo("MMB")) {
499 fTrackCorrMode = kTrackCorrMMB;
501 else if (!opt.CompareTo("FIXED")) {
502 fTrackCorrMode = kTrackCorrFixed;
505 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
510 //------------------------------------------------------------------------------
512 Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
516 // Given two angles in radiants, it converts them in the range 0-2pi
517 // then computes their true difference, i.e. if the difference a1-a2
518 // results to be larger than 180 degrees, it returns 360 - diff.
521 if (angle1 < 0.0) angle1 += TMath::TwoPi();
522 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
523 if (angle2 < 0.0) angle2 += TMath::TwoPi();
524 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
526 Double_t diff = TMath::Abs(angle1 - angle2);
527 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
529 if (angle2 > angle1) diff = -diff;
534 //------------------------------------------------------------------------------
536 Double_t AliEMCALTracker::CheckPair
537 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
540 // Given a track and a cluster,
541 // propagates the first to the radius of the second.
542 // Then, checks the propagation point against all cuts.
543 // If at least a cut is not passed, a valuer equal to
544 // twice the maximum allowed distance is passed (so the value returned
545 // will not be taken into account when creating matches)
549 Bool_t isTrue = kFALSE;
550 // if (tr->GetSeedLabel() == cl->Label()) {
554 // copy track into temporary variable
555 AliEMCALTrack *tr = new AliEMCALTrack(*track);
557 Double_t distance = 2.0 * fMaxDist;
559 // check against cut on difference 'alpha - phi'
560 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
561 phi = AngleDiff(phi, tr->GetAlpha());
562 if (phi < fCutAlphaMin || phi > fCutAlphaMax){
567 // try to propagate to cluster radius
568 // (return the 'distance' value if it fails)
569 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
572 Double_t rt = TMath::Sqrt(x*x + y*y);
573 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
575 if (fTrackCorrMode == kTrackCorrMMB) {
576 Double_t pos1[3], pos2[3], param[6];
583 MeanMaterialBudget(pos1, pos2, param);
584 rho = param[0]*param[4];
587 else if (fTrackCorrMode == kTrackCorrFixed) {
598 cout.setf(ios::fixed);
600 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
601 for (i = 0; i < fNPropSteps; i++) {
602 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
603 if (!tr->PropagateTo(r, x0, rho)){
608 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
610 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
613 // when no steps are used, no correction makes sense
614 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
615 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
620 Bool_t propOK = kFALSE;
621 cout << "START" << endl;
622 Double_t dist, rCHK, bestDist = 10000000.0;
623 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
624 if (!tr->PropagateTo(rTMP)) continue;
627 rCHK = TMath::Sqrt(x*x + y*y);
628 dist = TMath::Abs(rCHK - rc);
629 cout << rCHK << " vs. " << rc << endl;
631 if (TMath::Abs(rCHK - rc) < 0.01) break;
633 cout << "STOP" << endl;
634 if (!propOK) return distance;
638 // get global propagation of track at end of propagation
642 TVector3 vc(cl->X(), cl->Y(), cl->Z());
643 TVector3 vt(x, y, z);
644 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
645 // check: where is the track?
646 Double_t r, phiT, phiC;
647 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
648 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
649 phiC = vc.Phi() * TMath::RadToDeg();
650 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
652 if (angle > fCutAngle) {
653 //cout << "angle" << endl;
658 // compute differences wr to each coordinate
660 if (TMath::Abs(x) > fCutX) {
661 //cout << "cut X" << endl;
666 if (TMath::Abs(y) > fCutY) {
667 //cout << "cut Y" << endl;
672 if (TMath::Abs(z) > fCutZ) {
673 //cout << "cut Z" << endl;
678 // compute true distance
679 distance = TMath::Sqrt(x*x + y*y + z*z);
680 //Double_t temp = CheckPairV2(tr, cl);
681 //if (temp < distance) return temp; else
683 // delete temporary object
689 //------------------------------------------------------------------------------
691 Double_t AliEMCALTracker::CheckPairV2
692 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
695 // Given a track and a cluster,
696 // propagates the first to the radius of the second.
697 // Then, checks the propagation point against all cuts.
698 // If at least a cut is not passed, a valuer equal to
699 // twice the maximum allowed distance is passed (so the value returned
700 // will not be taken into account when creating matches)
704 // Bool_t isTrue = kFALSE;
705 // if (tr->GetSeedLabel() == cl->Label()) {
707 // cout << "TRUE MATCH!!!" << endl;
710 Double_t distance = 2.0 * fMaxDist;
713 if (fTrackCorrMode == kTrackCorrMMB) {
714 Double_t pos1[3], pos2[3], param[6];
722 MeanMaterialBudget(pos1, pos2, param);
723 rho = param[0]*param[4];
726 else if (fTrackCorrMode == kTrackCorrFixed) {
735 // check against cut on difference 'alpha - phi'
736 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
737 phi = AngleDiff(phi, tr->GetAlpha());
738 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
740 // get cluster position and put them into a vector
741 TVector3 vc(cl->X(), cl->Y(), cl->Z());
742 // rotate the vector in order to put all clusters on a plane intersecting
743 // vertically the X axis; the angle depends on the sector
744 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
745 if (clusterPhi < 0.0) clusterPhi += 360.0;
746 if (clusterPhi < 100.0) {
749 else if (clusterPhi < 120.0) {
752 else if (clusterPhi < 140.0) {
755 else if (clusterPhi < 160.0) {
758 else if (clusterPhi < 180.0) {
764 vc.RotateZ(clusterRot * TMath::DegToRad());
765 // generate a track from the ESD track selected
766 AliEMCALTrack *track = new AliEMCALTrack(*tr);
767 // compute the 'phi' coordinate of the intersection point to
771 track->GetYAt(vc.X(), track->GetBz(), y);
772 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
773 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
775 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
776 // compute phi difference
777 Double_t dphi = trackPhi - clusterPhi;
778 if (TMath::Abs(dphi) > 180.0) {
779 dphi = 360.0 - TMath::Abs(dphi);
780 if (clusterPhi > trackPhi) dphi = -dphi;
782 // propagate track to the X position of rotated cluster
783 // and get the vector of X, Y, Z in the local ref. frame of the track
784 track->PropagateTo(vc.X(), x0, rho);
785 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
786 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
787 TVector3 vdiff = vt-vc;
789 // compute differences wr to each coordinate
791 if (vdiff.X() > fCutX) return distance;
792 if (vdiff.Y() > fCutY) return distance;
793 if (vdiff.Z() > fCutZ) return distance;
795 // compute true distance
796 distance = vdiff.Mag();
800 //------------------------------------------------------------------------------
802 Double_t AliEMCALTracker::CheckPairV3
803 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
806 // Given a track and a cluster,
807 // propagates the first to the radius of the second.
808 // Then, checks the propagation point against all cuts.
809 // If at least a cut is not passed, a valuer equal to
810 // twice the maximum allowed distance is passed (so the value returned
811 // will not be taken into account when creating matches)
814 AliEMCALTrack tr(*track);
817 Double_t distance = 2.0 * fMaxDist;
819 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
820 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
821 Double_t x[3], x1[3], x2[3];
823 // get initial track position
826 // evaluate the EMCAL sector number
828 if (phi < 0.0) phi += TMath::TwoPi();
829 sector = (Int_t)(phi / sectorWidth);
830 alpha = ((Double_t)sector + 0.5) * sectorWidth;
831 // evaluate the corresponding X for track propagation
832 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
833 tgtXnum = cl->Y() - slope * cl->X();
834 tgtXden = TMath::Sqrt(1.0 + slope*slope);
835 xprop = TMath::Abs(tgtXnum / tgtXden);
837 // propagate by small steps
840 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
841 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
842 rho = param[0]*param[4];
844 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
845 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
847 // get propagated position at the end
849 dx = TMath::Abs(x[0] - cl->X());
850 dy = TMath::Abs(x[1] - cl->Y());
851 dz = TMath::Abs(x[2] - cl->Z());
852 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
854 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
859 //------------------------------------------------------------------------------
861 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
864 // Propagates the track to the proximity of the EMCAL surface
867 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
868 Double_t x1[3], x2[3];
870 // get initial track position
873 // propagate by small steps
874 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
875 // to compute material budget, take current position and
876 // propagated hypothesis without energy loss
879 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
880 MeanMaterialBudget(x1, x2, param);
881 rho = param[0]*param[4];
883 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
889 //------------------------------------------------------------------------------
891 Int_t AliEMCALTracker::CreateMatches()
894 // Creation of matches between tracks and clusters.
895 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
896 // If it finds a cluster close enough to its propagation to EMCAL,
897 // which passes all cuts, its index is stored.
898 // If many clusters are found which satisfy the criteria described above,
899 // only the closest one is stored.
900 // At this level, it is possible that two tracks share the same cluster.
903 // if matches collection is already present, it is deleted
908 fMatches = new TList;
910 // initialize counters and indexes
912 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
913 Int_t it, nTracks = fTracks->GetEntries();
915 // external loop on clusters, internal loop on tracks
917 for (ic = 0; ic < nClusters; ic++) {
918 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
919 for (it = 0; it < nTracks; it++) {
920 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
921 dist = CheckPair(track, cluster);
922 //cout << dist << endl;
923 if (dist <= fMaxDist) {
924 AliEMCALMatch *candidate = new AliEMCALMatch;
925 candidate->SetIndexT(it);
926 candidate->SetIndexC(ic);
927 candidate->SetDistance(dist);
928 candidate->SetPt(track->GetSignedPt());
929 fMatches->Add(candidate);
936 // loop on clusters and tracks
938 Double_t dist, distBest;
939 for (it = 0; it < nTracks; it++) {
940 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
941 if (!track) continue;
944 for (ic = 0; ic < nClusters; ic++) {
945 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
946 if (!cluster) continue;
947 dist = CheckPair(track, cluster);
948 if (dist < distBest) {
954 track->SetMatchedClusterIndex(icBest);
955 track->SetMatchedClusterDist(distBest);
959 track->SetMatchedClusterIndex(-1);
967 //------------------------------------------------------------------------------
969 Int_t AliEMCALTracker::SolveCompetitions()
973 // The match list is sorted from the best to the worst match, w.r. to the
974 // distance between track prolongation and cluster position.
975 // Based on this criterion, starting from the first (best) match, a flag
976 // is set to both the involved track and cluster, and all matches containing
977 // an already used track or cluster are removed, leaving only the best match
981 // sort matches with respect to track-cluster distance
982 fMatches->Sort(kSortAscending);
984 // keep track of eliminated matches
987 // initialize flags to check repetitions
988 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
989 Int_t it, nTracks = fTracks->GetEntries();
990 Bool_t *usedC = new Bool_t[nClusters];
991 Bool_t *usedT = new Bool_t[nTracks];
992 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
993 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
996 TListIter iter(fMatches);
997 AliEMCALMatch *match = 0;
998 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
999 ic = match->GetIndexC();
1000 it = match->GetIndexT();
1001 if (!usedT[it] && !usedC[ic]) {
1004 match->CanBeSaved() = kTRUE;
1012 Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
1013 AliEMCALTrack *track1 = 0, *track2 = 0;
1014 for (it1 = 0; it1 < nTracks; it1++) {
1015 track1 = (AliEMCALTrack*)fTracks->At(it1);
1016 if (!track1) continue;
1017 if (track1->GetMatchedClusterIndex() < 0) continue;
1018 for (it2 = it1+1; it2 < nTracks; it2++) {
1019 track2 = (AliEMCALTrack*)fTracks->At(it2);
1020 if (!track2) continue;
1021 if (track2->GetMatchedClusterIndex() < 0) continue;
1022 if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
1024 if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
1025 track2->SetMatchedClusterIndex(-1);
1027 else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
1028 track1->SetMatchedClusterIndex(-1);
1040 //------------------------------------------------------------------------------
1042 void AliEMCALTracker::UnloadClusters()
1045 // Free memory from all arrays
1046 // This method is called after the local tracking step
1047 // so we can safely delete everything
1053 //------------------------------------------------------------------------------
1055 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1057 fLabel(recPoint->GetPrimaryIndex()),
1063 // Translates an AliEMCALRecPoint object into the internal format.
1064 // Index of passed cluster in its native array must be specified.
1067 recPoint->GetGlobalPosition(clpos);
1074 //------------------------------------------------------------------------------
1076 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1078 fLabel(caloCluster->GetLabel()),
1084 // Translates an AliESDCaloCluster object into the internal format.
1085 // Index of passed cluster in its native array must be specified.
1088 caloCluster->GetPosition(clpos);
1090 fX = (Double_t)clpos[0];
1091 fY = (Double_t)clpos[1];
1092 fZ = (Double_t)clpos[2];
1095 //------------------------------------------------------------------------------
1097 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1100 // Tracks compared wrt their distance from matched point
1103 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1105 Double_t thisDist = fPt;//fDistance;
1106 Double_t thatDist = that->fPt;//that->GetDistance();
1108 if (thisDist > thatDist) return 1;
1109 else if (thisDist < thatDist) return -1;
1113 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1115 fCanBeSaved(kFALSE),
1121 //default constructor
1125 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1127 fCanBeSaved(copy.fCanBeSaved),
1128 fIndexC(copy.fIndexC),
1129 fIndexT(copy.fIndexT),
1130 fDistance(copy.fDistance),