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.
92 //------------------------------------------------------------------------------
94 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
96 fNPropSteps(copy.fNPropSteps),
97 fTrackCorrMode(copy.fTrackCorrMode),
101 fCutAlphaMin(copy.fCutAlphaMin),
102 fCutAlphaMax(copy.fCutAlphaMax),
103 fCutAngle(copy.fCutAngle),
104 fMaxDist(copy.fMaxDist),
107 fTracks((TObjArray*)copy.fTracks->Clone()),
108 fClusters((TObjArray*)copy.fClusters->Clone()),
109 fMatches((TList*)copy.fMatches->Clone()),
114 // Besides copying all parameters, duplicates all collections.
118 //------------------------------------------------------------------------------
120 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
123 // Assignment operator.
124 // Besides copying all parameters, duplicates all collections.
130 fCutAlphaMin = copy.fCutAlphaMin;
131 fCutAlphaMax = copy.fCutAlphaMax;
132 fCutAngle = copy.fCutAngle;
133 fMaxDist = copy.fMaxDist;
135 fTracks = (TObjArray*)copy.fTracks->Clone();
136 fClusters = (TObjArray*)copy.fClusters->Clone();
137 fMatches = (TList*)copy.fMatches->Clone();
144 //------------------------------------------------------------------------------
146 void AliEMCALTracker::InitParameters()
149 // Retrieve initialization parameters
152 // Check if the instance of AliEMCALRecParam exists,
153 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
155 AliFatal("Reconstruction parameters for EMCAL not set!");
158 fCutX = recParam->GetTrkCutX();
159 fCutY = recParam->GetTrkCutY();
160 fCutZ = recParam->GetTrkCutZ();
161 fMaxDist = recParam->GetTrkCutR();
162 fCutAngle = recParam->GetTrkCutAngle();
163 fCutAlphaMin = recParam->GetTrkCutAlphaMin();
164 fCutAlphaMax = recParam->GetTrkCutAlphaMax();
168 //------------------------------------------------------------------------------
170 TTree* AliEMCALTracker::SearchTrueMatches()
172 //Search through the list of
173 //track match candidates and clusters
174 //and look for true matches
177 if (!fClusters) return 0;
178 if (fClusters->IsEmpty()) return 0;
179 if (!fTracks) return 0;
180 if (fTracks->IsEmpty()) return 0;
182 TTree *outTree = new TTree("tree", "True matches from event");
183 Int_t indexT, indexC, label;
184 outTree->Branch("indexC", &indexC, "indexC/I");
185 outTree->Branch("indexT", &indexT, "indexT/I");
186 outTree->Branch("label", &label , "label/I");
189 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
190 Int_t it, nTracks = fTracks->GetEntries();
192 for (ic = 0; ic < nClusters; ic++) {
193 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
194 label = cluster->Label();
195 indexC = cluster->Index();
196 for (it = 0; it < nTracks; it++) {
197 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
198 if (TMath::Abs(track->GetSeedLabel()) != label) continue;
199 dist = CheckPair(track, cluster);
200 if (dist <= fMaxDist) {
201 indexT = track->GetSeedIndex();
210 //------------------------------------------------------------------------------
212 void AliEMCALTracker::Clear(Option_t* option)
216 // Deletes all objects in arrays and the arrays themselves
220 Bool_t clearTracks = opt.Contains("TRACKS");
221 Bool_t clearClusters = opt.Contains("CLUSTERS");
222 Bool_t clearMatches = opt.Contains("MATCHES");
223 if (opt.Contains("ALL")) {
225 clearClusters = kTRUE;
226 clearMatches = kTRUE;
229 if (fTracks != 0x0 && clearTracks) {
234 if (fClusters != 0x0 && clearClusters) {
239 if (fMatches != 0x0 && clearMatches) {
246 //------------------------------------------------------------------------------
248 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
251 // Load EMCAL clusters in the form of AliEMCALRecPoint,
252 // from simulation temporary files.
253 // (When included in reconstruction chain, this method is used automatically)
258 TBranch *branch = cTree->GetBranch("EMCALECARP");
260 AliError("Can't get the branch with the EMCAL clusters");
264 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
265 branch->SetAddress(&clusters);
268 Int_t nClusters = (Int_t)clusters->GetEntries();
269 fClusters = new TObjArray(0);
270 for (Int_t i = 0; i < nClusters; i++) {
271 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
272 if (!cluster) continue;
273 if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
274 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
275 fClusters->AddLast(matchCluster);
278 branch->SetAddress(0);
281 if (fClusters->IsEmpty())
282 AliWarning("No clusters collected");
284 AliInfo(Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
289 //------------------------------------------------------------------------------
291 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
294 // Load EMCAL clusters in the form of AliESDCaloClusters,
295 // from an AliESD object.
298 // make sure that tracks/clusters collections are empty
301 Int_t start = esd->GetFirstEMCALCluster();
302 Int_t nClustersEMC = esd->GetNumberOfEMCALClusters();
303 Int_t end = start + nClustersEMC;
305 fClusters = new TObjArray(0);
308 for (i = start; i < end; i++) {
309 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
310 if (!cluster) continue;
311 if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
312 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
313 fClusters->AddLast(matchCluster);
315 if (fClusters->IsEmpty())
316 AliWarning("No clusters collected");
318 AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
323 //------------------------------------------------------------------------------
325 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
333 Int_t nTracks = esd->GetNumberOfTracks();
334 fTracks = new TObjArray(0);
339 for (i = 0; i < nTracks; i++) {
340 AliESDtrack *esdTrack = esd->GetTrack(i);
341 // set by default the value corresponding to "no match"
342 esdTrack->SetEMCALcluster(kUnmatched);
343 // if (esdTrack->GetLabel() < 0) continue;
344 // if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
346 for (j = 0; j < 3; j++) {
347 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
349 if (isKink) continue;
350 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
351 track->SetMass(0.13957018);
352 // check alpha and reject the tracks which fall outside EMCAL acceptance
353 alpha = track->GetAlpha() * TMath::RadToDeg();
354 if (alpha > -155.0 && alpha < 67.0) {
358 // if (!PropagateToEMCAL(track)) {
362 track->SetSeedIndex(i);
363 track->SetSeedLabel(esdTrack->GetLabel());
364 fTracks->AddLast(track);
366 if (fTracks->IsEmpty()) {
367 AliWarning("No tracks collected");
370 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
375 //------------------------------------------------------------------------------
377 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
380 // Main operation method.
381 // Gets external AliESD containing tracks to be matched.
382 // After executing match finding, stores in the same ESD object all infos
383 // and releases the object for further reconstruction steps.
386 // Note: should always return 0=OK, because otherwise all tracking
387 // is aborted for this event
390 AliError("NULL ESD passed");
395 // if cluster array is empty, cluster are collected
396 // from the passed ESD, and work is done with ESDCaloClusters
397 Int_t okLoadClusters, nClusters;
398 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
399 okLoadClusters = LoadClusters(esd);
401 nClusters = fClusters->GetEntries();
404 // collect ESD tracks
405 Int_t okLoadTracks = LoadTracks(esd), nTracks;
406 if (okLoadTracks) return 3;
407 nTracks = fTracks->GetEntries();
410 // each track is propagated to the "R" position of each cluster.
411 // The closest cluster is assigned as match.
412 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
413 Int_t nMatches = CreateMatches();
415 AliInfo(Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
419 AliInfo(Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
423 // when more than 1 track share the same matched cluster, only the closest one is kept.
424 Int_t nRemoved = SolveCompetitions();
425 AliInfo(Form("Removed %d duplicate matches", nRemoved));
426 if (nRemoved >= nMatches) {
427 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
432 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
433 Int_t nSaved = 0, trackID, nGood = 0, nFake = 0;
434 TListIter iter(fMatches);
435 AliEMCALMatch *match = 0;
436 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
437 if (!match->CanBeSaved()) continue;
438 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
439 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
440 trackID = track->GetSeedIndex();
441 AliESDtrack *esdTrack = esd->GetTrack(trackID);
442 if (!esdTrack) continue;
443 if (TMath::Abs(esdTrack->GetLabel()) == cluster->Label()) {
444 esdTrack->SetEMCALcluster(cluster->Index());
448 esdTrack->SetEMCALcluster(-cluster->Index());
454 AliEMCALTrack *track = 0;
455 TObjArrayIter tracks(fTracks);
456 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
457 trackID = track->GetSeedIndex();
458 clusterID = track->GetMatchedClusterIndex();
459 AliESDtrack *esdTrack = esd->GetTrack(trackID);
460 if (!esdTrack) continue;
462 esdTrack->SetEMCALcluster(kUnmatched);
465 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
466 if (!cluster) continue;
467 if (esdTrack->GetLabel() == cluster->Label()) {
469 esdTrack->SetEMCALcluster(cluster->Index());
472 esdTrack->SetEMCALcluster(-cluster->Index());
478 AliInfo(Form("Saved %d matches [%d good + %d fake]", nSaved, nGood, nFake));
483 //------------------------------------------------------------------------------
485 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
488 // Set track correction mode
489 // gest the choice in string format and converts into
496 if (!opt.CompareTo("NONE")) {
497 fTrackCorrMode = kTrackCorrNone;
499 else if (!opt.CompareTo("MMB")) {
500 fTrackCorrMode = kTrackCorrMMB;
502 else if (!opt.CompareTo("FIXED")) {
503 fTrackCorrMode = kTrackCorrFixed;
506 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
511 //------------------------------------------------------------------------------
513 Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
517 // Given two angles in radiants, it converts them in the range 0-2pi
518 // then computes their true difference, i.e. if the difference a1-a2
519 // results to be larger than 180 degrees, it returns 360 - diff.
522 if (angle1 < 0.0) angle1 += TMath::TwoPi();
523 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
524 if (angle2 < 0.0) angle2 += TMath::TwoPi();
525 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
527 Double_t diff = TMath::Abs(angle1 - angle2);
528 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
530 if (angle2 > angle1) diff = -diff;
535 //------------------------------------------------------------------------------
537 Double_t AliEMCALTracker::CheckPair
538 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
541 // Given a track and a cluster,
542 // propagates the first to the radius of the second.
543 // Then, checks the propagation point against all cuts.
544 // If at least a cut is not passed, a valuer equal to
545 // twice the maximum allowed distance is passed (so the value returned
546 // will not be taken into account when creating matches)
550 Bool_t isTrue = kFALSE;
551 // if (tr->GetSeedLabel() == cl->Label()) {
555 // copy track into temporary variable
556 AliEMCALTrack *tr = new AliEMCALTrack(*track);
558 Double_t distance = 2.0 * fMaxDist;
560 // check against cut on difference 'alpha - phi'
561 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
562 phi = AngleDiff(phi, tr->GetAlpha());
563 if (phi < fCutAlphaMin || phi > fCutAlphaMax){
568 // try to propagate to cluster radius
569 // (return the 'distance' value if it fails)
570 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
573 Double_t rt = TMath::Sqrt(x*x + y*y);
574 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
576 if (fTrackCorrMode == kTrackCorrMMB) {
577 Double_t pos1[3], pos2[3], param[6];
584 MeanMaterialBudget(pos1, pos2, param);
585 rho = param[0]*param[4];
588 else if (fTrackCorrMode == kTrackCorrFixed) {
599 cout.setf(ios::fixed);
601 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
602 for (i = 0; i < fNPropSteps; i++) {
603 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
604 if (!tr->PropagateTo(r, x0, rho)){
609 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
611 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
614 // when no steps are used, no correction makes sense
615 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
616 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
621 Bool_t propOK = kFALSE;
622 cout << "START" << endl;
623 Double_t dist, rCHK, bestDist = 10000000.0;
624 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
625 if (!tr->PropagateTo(rTMP)) continue;
628 rCHK = TMath::Sqrt(x*x + y*y);
629 dist = TMath::Abs(rCHK - rc);
630 cout << rCHK << " vs. " << rc << endl;
632 if (TMath::Abs(rCHK - rc) < 0.01) break;
634 cout << "STOP" << endl;
635 if (!propOK) return distance;
639 // get global propagation of track at end of propagation
643 TVector3 vc(cl->X(), cl->Y(), cl->Z());
644 TVector3 vt(x, y, z);
645 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
646 // check: where is the track?
647 Double_t r, phiT, phiC;
648 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
649 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
650 phiC = vc.Phi() * TMath::RadToDeg();
651 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
653 if (angle > fCutAngle) {
654 //cout << "angle" << endl;
659 // compute differences wr to each coordinate
661 if (TMath::Abs(x) > fCutX) {
662 //cout << "cut X" << endl;
667 if (TMath::Abs(y) > fCutY) {
668 //cout << "cut Y" << endl;
673 if (TMath::Abs(z) > fCutZ) {
674 //cout << "cut Z" << endl;
679 // compute true distance
680 distance = TMath::Sqrt(x*x + y*y + z*z);
681 //Double_t temp = CheckPairV2(tr, cl);
682 //if (temp < distance) return temp; else
684 // delete temporary object
690 //------------------------------------------------------------------------------
692 Double_t AliEMCALTracker::CheckPairV2
693 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
696 // Given a track and a cluster,
697 // propagates the first to the radius of the second.
698 // Then, checks the propagation point against all cuts.
699 // If at least a cut is not passed, a valuer equal to
700 // twice the maximum allowed distance is passed (so the value returned
701 // will not be taken into account when creating matches)
705 // Bool_t isTrue = kFALSE;
706 // if (tr->GetSeedLabel() == cl->Label()) {
708 // cout << "TRUE MATCH!!!" << endl;
711 Double_t distance = 2.0 * fMaxDist;
714 if (fTrackCorrMode == kTrackCorrMMB) {
715 Double_t pos1[3], pos2[3], param[6];
723 MeanMaterialBudget(pos1, pos2, param);
724 rho = param[0]*param[4];
727 else if (fTrackCorrMode == kTrackCorrFixed) {
736 // check against cut on difference 'alpha - phi'
737 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
738 phi = AngleDiff(phi, tr->GetAlpha());
739 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
741 // get cluster position and put them into a vector
742 TVector3 vc(cl->X(), cl->Y(), cl->Z());
743 // rotate the vector in order to put all clusters on a plane intersecting
744 // vertically the X axis; the angle depends on the sector
745 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
746 if (clusterPhi < 0.0) clusterPhi += 360.0;
747 if (clusterPhi < 100.0) {
750 else if (clusterPhi < 120.0) {
753 else if (clusterPhi < 140.0) {
756 else if (clusterPhi < 160.0) {
759 else if (clusterPhi < 180.0) {
765 vc.RotateZ(clusterRot * TMath::DegToRad());
766 // generate a track from the ESD track selected
767 AliEMCALTrack *track = new AliEMCALTrack(*tr);
768 // compute the 'phi' coordinate of the intersection point to
772 track->GetYAt(vc.X(), track->GetBz(), y);
773 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
774 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
776 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
777 // compute phi difference
778 Double_t dphi = trackPhi - clusterPhi;
779 if (TMath::Abs(dphi) > 180.0) {
780 dphi = 360.0 - TMath::Abs(dphi);
781 if (clusterPhi > trackPhi) dphi = -dphi;
783 // propagate track to the X position of rotated cluster
784 // and get the vector of X, Y, Z in the local ref. frame of the track
785 track->PropagateTo(vc.X(), x0, rho);
786 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
787 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
788 TVector3 vdiff = vt-vc;
790 // compute differences wr to each coordinate
792 if (vdiff.X() > fCutX) return distance;
793 if (vdiff.Y() > fCutY) return distance;
794 if (vdiff.Z() > fCutZ) return distance;
796 // compute true distance
797 distance = vdiff.Mag();
801 //------------------------------------------------------------------------------
803 Double_t AliEMCALTracker::CheckPairV3
804 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
807 // Given a track and a cluster,
808 // propagates the first to the radius of the second.
809 // Then, checks the propagation point against all cuts.
810 // If at least a cut is not passed, a valuer equal to
811 // twice the maximum allowed distance is passed (so the value returned
812 // will not be taken into account when creating matches)
815 AliEMCALTrack tr(*track);
818 Double_t distance = 2.0 * fMaxDist;
820 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
821 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
822 Double_t x[3], x1[3], x2[3];
824 // get initial track position
827 // evaluate the EMCAL sector number
829 if (phi < 0.0) phi += TMath::TwoPi();
830 sector = (Int_t)(phi / sectorWidth);
831 alpha = ((Double_t)sector + 0.5) * sectorWidth;
832 // evaluate the corresponding X for track propagation
833 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
834 tgtXnum = cl->Y() - slope * cl->X();
835 tgtXden = TMath::Sqrt(1.0 + slope*slope);
836 xprop = TMath::Abs(tgtXnum / tgtXden);
838 // propagate by small steps
841 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
842 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
843 rho = param[0]*param[4];
845 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
846 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
848 // get propagated position at the end
850 dx = TMath::Abs(x[0] - cl->X());
851 dy = TMath::Abs(x[1] - cl->Y());
852 dz = TMath::Abs(x[2] - cl->Z());
853 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
855 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
860 //------------------------------------------------------------------------------
862 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
865 // Propagates the track to the proximity of the EMCAL surface
868 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
869 Double_t x1[3], x2[3];
871 // get initial track position
874 // propagate by small steps
875 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
876 // to compute material budget, take current position and
877 // propagated hypothesis without energy loss
880 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
881 MeanMaterialBudget(x1, x2, param);
882 rho = param[0]*param[4];
884 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
890 //------------------------------------------------------------------------------
892 Int_t AliEMCALTracker::CreateMatches()
895 // Creation of matches between tracks and clusters.
896 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
897 // If it finds a cluster close enough to its propagation to EMCAL,
898 // which passes all cuts, its index is stored.
899 // If many clusters are found which satisfy the criteria described above,
900 // only the closest one is stored.
901 // At this level, it is possible that two tracks share the same cluster.
904 // if matches collection is already present, it is deleted
909 fMatches = new TList;
911 // initialize counters and indexes
913 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
914 Int_t it, nTracks = fTracks->GetEntries();
916 // external loop on clusters, internal loop on tracks
918 for (ic = 0; ic < nClusters; ic++) {
919 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
920 for (it = 0; it < nTracks; it++) {
921 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
922 dist = CheckPair(track, cluster);
923 //cout << dist << endl;
924 if (dist <= fMaxDist) {
925 AliEMCALMatch *candidate = new AliEMCALMatch;
926 candidate->SetIndexT(it);
927 candidate->SetIndexC(ic);
928 candidate->SetDistance(dist);
929 candidate->SetPt(track->GetSignedPt());
930 fMatches->Add(candidate);
937 // loop on clusters and tracks
939 Double_t dist, distBest;
940 for (it = 0; it < nTracks; it++) {
941 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
942 if (!track) continue;
945 for (ic = 0; ic < nClusters; ic++) {
946 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
947 if (!cluster) continue;
948 dist = CheckPair(track, cluster);
949 if (dist < distBest) {
955 track->SetMatchedClusterIndex(icBest);
956 track->SetMatchedClusterDist(distBest);
960 track->SetMatchedClusterIndex(-1);
968 //------------------------------------------------------------------------------
970 Int_t AliEMCALTracker::SolveCompetitions()
974 // The match list is sorted from the best to the worst match, w.r. to the
975 // distance between track prolongation and cluster position.
976 // Based on this criterion, starting from the first (best) match, a flag
977 // is set to both the involved track and cluster, and all matches containing
978 // an already used track or cluster are removed, leaving only the best match
982 // sort matches with respect to track-cluster distance
983 fMatches->Sort(kSortAscending);
985 // keep track of eliminated matches
988 // initialize flags to check repetitions
989 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
990 Int_t it, nTracks = fTracks->GetEntries();
991 Bool_t *usedC = new Bool_t[nClusters];
992 Bool_t *usedT = new Bool_t[nTracks];
993 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
994 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
997 TListIter iter(fMatches);
998 AliEMCALMatch *match = 0;
999 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
1000 ic = match->GetIndexC();
1001 it = match->GetIndexT();
1002 if (!usedT[it] && !usedC[ic]) {
1005 match->CanBeSaved() = kTRUE;
1013 Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
1014 AliEMCALTrack *track1 = 0, *track2 = 0;
1015 for (it1 = 0; it1 < nTracks; it1++) {
1016 track1 = (AliEMCALTrack*)fTracks->At(it1);
1017 if (!track1) continue;
1018 if (track1->GetMatchedClusterIndex() < 0) continue;
1019 for (it2 = it1+1; it2 < nTracks; it2++) {
1020 track2 = (AliEMCALTrack*)fTracks->At(it2);
1021 if (!track2) continue;
1022 if (track2->GetMatchedClusterIndex() < 0) continue;
1023 if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
1025 if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
1026 track2->SetMatchedClusterIndex(-1);
1028 else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
1029 track1->SetMatchedClusterIndex(-1);
1041 //------------------------------------------------------------------------------
1043 void AliEMCALTracker::UnloadClusters()
1046 // Free memory from all arrays
1047 // This method is called after the local tracking step
1048 // so we can safely delete everything
1054 //------------------------------------------------------------------------------
1056 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1058 fLabel(recPoint->GetPrimaryIndex()),
1064 // Translates an AliEMCALRecPoint object into the internal format.
1065 // Index of passed cluster in its native array must be specified.
1068 recPoint->GetGlobalPosition(clpos);
1075 //------------------------------------------------------------------------------
1077 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1079 fLabel(caloCluster->GetLabel()),
1085 // Translates an AliESDCaloCluster object into the internal format.
1086 // Index of passed cluster in its native array must be specified.
1089 caloCluster->GetPosition(clpos);
1091 fX = (Double_t)clpos[0];
1092 fY = (Double_t)clpos[1];
1093 fZ = (Double_t)clpos[2];
1096 //------------------------------------------------------------------------------
1098 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1101 // Tracks compared wrt their distance from matched point
1104 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1106 Double_t thisDist = fPt;//fDistance;
1107 Double_t thatDist = that->fPt;//that->GetDistance();
1109 if (thisDist > thatDist) return 1;
1110 else if (thisDist < thatDist) return -1;
1114 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1116 fCanBeSaved(kFALSE),
1122 //default constructor
1126 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1128 fCanBeSaved(copy.fCanBeSaved),
1129 fIndexC(copy.fIndexC),
1130 fIndexT(copy.fIndexT),
1131 fDistance(copy.fDistance),