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"
53 #include "AliEMCALTracker.h"
55 ClassImp(AliEMCALTracker)
57 //------------------------------------------------------------------------------
59 AliEMCALTracker::AliEMCALTracker()
62 fTrackCorrMode(kTrackCorrNone),
78 // Default constructor.
79 // Initializes al simple data members to default values,
80 // and all collections to NULL.
81 // Output file name is set to a default value.
85 //------------------------------------------------------------------------------
87 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
89 fNPropSteps(copy.fNPropSteps),
90 fTrackCorrMode(copy.fTrackCorrMode),
94 fCutAlphaMin(copy.fCutAlphaMin),
95 fCutAlphaMax(copy.fCutAlphaMax),
96 fCutAngle(copy.fCutAngle),
97 fMaxDist(copy.fMaxDist),
100 fTracks((TObjArray*)copy.fTracks->Clone()),
101 fClusters((TObjArray*)copy.fClusters->Clone()),
102 fMatches((TList*)copy.fMatches->Clone()),
107 // Besides copying all parameters, duplicates all collections.
111 //------------------------------------------------------------------------------
113 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
116 // Assignment operator.
117 // Besides copying all parameters, duplicates all collections.
123 fCutAlphaMin = copy.fCutAlphaMin;
124 fCutAlphaMax = copy.fCutAlphaMax;
125 fCutAngle = copy.fCutAngle;
126 fMaxDist = copy.fMaxDist;
128 fTracks = (TObjArray*)copy.fTracks->Clone();
129 fClusters = (TObjArray*)copy.fClusters->Clone();
130 fMatches = (TList*)copy.fMatches->Clone();
137 //------------------------------------------------------------------------------
139 TTree* AliEMCALTracker::SearchTrueMatches()
141 if (!fClusters) return 0;
142 if (fClusters->IsEmpty()) return 0;
143 if (!fTracks) return 0;
144 if (fTracks->IsEmpty()) return 0;
146 TTree *outTree = new TTree("tree", "True matches from event");
147 Int_t indexT, indexC, label;
148 outTree->Branch("indexC", &indexC, "indexC/I");
149 outTree->Branch("indexT", &indexT, "indexT/I");
150 outTree->Branch("label", &label , "label/I");
153 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
154 Int_t it, nTracks = fTracks->GetEntries();
156 for (ic = 0; ic < nClusters; ic++) {
157 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
158 label = cluster->Label();
159 indexC = cluster->Index();
160 for (it = 0; it < nTracks; it++) {
161 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
162 if (TMath::Abs(track->GetSeedLabel()) != label) continue;
163 dist = CheckPair(track, cluster);
164 if (dist <= fMaxDist) {
165 indexT = track->GetSeedIndex();
174 //------------------------------------------------------------------------------
176 void AliEMCALTracker::Clear(Option_t* option)
180 // Deletes all objects in arrays and the arrays themselves
184 Bool_t clearTracks = opt.Contains("TRACKS");
185 Bool_t clearClusters = opt.Contains("CLUSTERS");
186 Bool_t clearMatches = opt.Contains("MATCHES");
187 if (opt.Contains("ALL")) {
189 clearClusters = kTRUE;
190 clearMatches = kTRUE;
193 if (fTracks != 0x0 && clearTracks) {
198 if (fClusters != 0x0 && clearClusters) {
203 if (fMatches != 0x0 && clearMatches) {
210 //------------------------------------------------------------------------------
212 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
215 // Load EMCAL clusters in the form of AliEMCALRecPoint,
216 // from simulation temporary files.
217 // (When included in reconstruction chain, this method is used automatically)
222 TBranch *branch = cTree->GetBranch("EMCALECARP");
224 AliError("Can't get the branch with the EMCAL clusters");
228 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
229 branch->SetAddress(&clusters);
232 Int_t nClusters = (Int_t)clusters->GetEntries();
233 fClusters = new TObjArray(0);
234 for (Int_t i = 0; i < nClusters; i++) {
235 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
236 if (!cluster) continue;
237 if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
238 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
239 fClusters->AddLast(matchCluster);
242 branch->SetAddress(0);
245 if (fClusters->IsEmpty())
246 AliWarning("No clusters collected");
248 AliInfo(Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
253 //------------------------------------------------------------------------------
255 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
258 // Load EMCAL clusters in the form of AliESDCaloClusters,
259 // from an AliESD object.
262 // make sure that tracks/clusters collections are empty
265 Int_t start = esd->GetFirstEMCALCluster();
266 Int_t nClustersEMC = esd->GetNumberOfEMCALClusters();
267 Int_t end = start + nClustersEMC;
269 fClusters = new TObjArray(0);
272 for (i = start; i < end; i++) {
273 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
274 if (!cluster) continue;
275 if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
276 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
277 fClusters->AddLast(matchCluster);
279 if (fClusters->IsEmpty())
280 AliWarning("No clusters collected");
282 AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
287 //------------------------------------------------------------------------------
289 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
297 Int_t nTracks = esd->GetNumberOfTracks();
298 fTracks = new TObjArray(0);
303 for (i = 0; i < nTracks; i++) {
304 AliESDtrack *esdTrack = esd->GetTrack(i);
305 // set by default the value corresponding to "no match"
306 esdTrack->SetEMCALcluster(kUnmatched);
307 // if (esdTrack->GetLabel() < 0) continue;
308 // if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
310 for (j = 0; j < 3; j++) {
311 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
313 if (isKink) continue;
314 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
315 track->SetMass(0.13957018);
316 // check alpha and reject the tracks which fall outside EMCAL acceptance
317 alpha = track->GetAlpha() * TMath::RadToDeg();
318 if (alpha > -155.0 && alpha < 67.0) {
322 // if (!PropagateToEMCAL(track)) {
326 track->SetSeedIndex(i);
327 track->SetSeedLabel(esdTrack->GetLabel());
328 fTracks->AddLast(track);
330 if (fTracks->IsEmpty()) {
331 AliWarning("No tracks collected");
334 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
339 //------------------------------------------------------------------------------
341 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
344 // Main operation method.
345 // Gets external AliESD containing tracks to be matched.
346 // After executing match finding, stores in the same ESD object all infos
347 // and releases the object for further reconstruction steps.
350 // Note: should always return 0=OK, because otherwise all tracking
351 // is aborted for this event
354 AliError("NULL ESD passed");
359 // if cluster array is empty, cluster are collected
360 // from the passed ESD, and work is done with ESDCaloClusters
361 Int_t okLoadClusters, nClusters;
362 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
363 okLoadClusters = LoadClusters(esd);
365 nClusters = fClusters->GetEntries();
368 // collect ESD tracks
369 Int_t okLoadTracks = LoadTracks(esd), nTracks;
370 if (okLoadTracks) return 3;
371 nTracks = fTracks->GetEntries();
374 // each track is propagated to the "R" position of each cluster.
375 // The closest cluster is assigned as match.
376 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
377 Int_t nMatches = CreateMatches();
379 AliInfo(Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
383 AliInfo(Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
387 // when more than 1 track share the same matched cluster, only the closest one is kept.
388 Int_t nRemoved = SolveCompetitions();
389 AliInfo(Form("Removed %d duplicate matches", nRemoved));
390 if (nRemoved >= nMatches) {
391 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
396 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
397 Int_t nSaved = 0, trackID, nGood = 0, nFake = 0;
398 TListIter iter(fMatches);
399 AliEMCALMatch *match = 0;
400 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
401 if (!match->CanBeSaved()) continue;
402 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
403 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
404 trackID = track->GetSeedIndex();
405 AliESDtrack *esdTrack = esd->GetTrack(trackID);
406 if (!esdTrack) continue;
407 if (TMath::Abs(esdTrack->GetLabel()) == cluster->Label()) {
408 esdTrack->SetEMCALcluster(cluster->Index());
412 esdTrack->SetEMCALcluster(-cluster->Index());
418 AliEMCALTrack *track = 0;
419 TObjArrayIter tracks(fTracks);
420 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
421 trackID = track->GetSeedIndex();
422 clusterID = track->GetMatchedClusterIndex();
423 AliESDtrack *esdTrack = esd->GetTrack(trackID);
424 if (!esdTrack) continue;
426 esdTrack->SetEMCALcluster(kUnmatched);
429 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
430 if (!cluster) continue;
431 if (esdTrack->GetLabel() == cluster->Label()) {
433 esdTrack->SetEMCALcluster(cluster->Index());
436 esdTrack->SetEMCALcluster(-cluster->Index());
442 AliInfo(Form("Saved %d matches [%d good + %d fake]", nSaved, nGood, nFake));
447 //------------------------------------------------------------------------------
449 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
452 // Set track correction mode
453 // gest the choice in string format and converts into
460 if (!opt.CompareTo("NONE")) {
461 fTrackCorrMode = kTrackCorrNone;
463 else if (!opt.CompareTo("MMB")) {
464 fTrackCorrMode = kTrackCorrMMB;
466 else if (!opt.CompareTo("FIXED")) {
467 fTrackCorrMode = kTrackCorrFixed;
470 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
475 //------------------------------------------------------------------------------
477 Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
481 // Given two angles in radiants, it converts them in the range 0-2pi
482 // then computes their true difference, i.e. if the difference a1-a2
483 // results to be larger than 180 degrees, it returns 360 - diff.
486 if (angle1 < 0.0) angle1 += TMath::TwoPi();
487 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
488 if (angle2 < 0.0) angle2 += TMath::TwoPi();
489 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
491 Double_t diff = TMath::Abs(angle1 - angle2);
492 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
494 if (angle2 > angle1) diff = -diff;
499 //------------------------------------------------------------------------------
501 Double_t AliEMCALTracker::CheckPair
502 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
505 // Given a track and a cluster,
506 // propagates the first to the radius of the second.
507 // Then, checks the propagation point against all cuts.
508 // If at least a cut is not passed, a valuer equal to
509 // twice the maximum allowed distance is passed (so the value returned
510 // will not be taken into account when creating matches)
514 Bool_t isTrue = kFALSE;
515 // if (tr->GetSeedLabel() == cl->Label()) {
519 // copy track into temporary variable
520 AliEMCALTrack *tr = new AliEMCALTrack(*track);
522 Double_t distance = 2.0 * fMaxDist;
524 // check against cut on difference 'alpha - phi'
525 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
526 phi = AngleDiff(phi, tr->GetAlpha());
527 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
529 // try to propagate to cluster radius
530 // (return the 'distance' value if it fails)
531 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
534 Double_t rt = TMath::Sqrt(x*x + y*y);
535 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
537 if (fTrackCorrMode == kTrackCorrMMB) {
538 Double_t pos1[3], pos2[3], param[6];
545 MeanMaterialBudget(pos1, pos2, param);
546 rho = param[0]*param[4];
549 else if (fTrackCorrMode == kTrackCorrFixed) {
560 cout.setf(ios::fixed);
562 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
563 for (i = 0; i < fNPropSteps; i++) {
564 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
565 if (!tr->PropagateTo(r, x0, rho)) return distance;
567 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
569 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
572 // when no steps are used, no correction makes sense
573 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
574 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)) return distance;
576 Bool_t propOK = kFALSE;
577 cout << "START" << endl;
578 Double_t dist, rCHK, bestDist = 10000000.0;
579 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
580 if (!tr->PropagateTo(rTMP)) continue;
583 rCHK = TMath::Sqrt(x*x + y*y);
584 dist = TMath::Abs(rCHK - rc);
585 cout << rCHK << " vs. " << rc << endl;
587 if (TMath::Abs(rCHK - rc) < 0.01) break;
589 cout << "STOP" << endl;
590 if (!propOK) return distance;
594 // get global propagation of track at end of propagation
598 TVector3 vc(cl->X(), cl->Y(), cl->Z());
599 TVector3 vt(x, y, z);
600 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
601 // check: where is the track?
602 Double_t r, phiT, phiC;
603 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
604 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
605 phiC = vc.Phi() * TMath::RadToDeg();
606 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
608 if (angle > fCutAngle) {
609 //cout << "angle" << endl;
613 // compute differences wr to each coordinate
615 if (TMath::Abs(x) > fCutX) {
616 //cout << "cut X" << endl;
620 if (TMath::Abs(y) > fCutY) {
621 //cout << "cut Y" << endl;
625 if (TMath::Abs(z) > fCutZ) {
626 //cout << "cut Z" << endl;
630 // compute true distance
631 distance = TMath::Sqrt(x*x + y*y + z*z);
632 //Double_t temp = CheckPairV2(tr, cl);
633 //if (temp < distance) return temp; else
635 // delete temporary object
641 //------------------------------------------------------------------------------
643 Double_t AliEMCALTracker::CheckPairV2
644 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
647 // Given a track and a cluster,
648 // propagates the first to the radius of the second.
649 // Then, checks the propagation point against all cuts.
650 // If at least a cut is not passed, a valuer equal to
651 // twice the maximum allowed distance is passed (so the value returned
652 // will not be taken into account when creating matches)
656 // Bool_t isTrue = kFALSE;
657 // if (tr->GetSeedLabel() == cl->Label()) {
659 // cout << "TRUE MATCH!!!" << endl;
662 Double_t distance = 2.0 * fMaxDist;
665 if (fTrackCorrMode == kTrackCorrMMB) {
666 Double_t pos1[3], pos2[3], param[6];
674 MeanMaterialBudget(pos1, pos2, param);
675 rho = param[0]*param[4];
678 else if (fTrackCorrMode == kTrackCorrFixed) {
687 // check against cut on difference 'alpha - phi'
688 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
689 phi = AngleDiff(phi, tr->GetAlpha());
690 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
692 // get cluster position and put them into a vector
693 TVector3 vc(cl->X(), cl->Y(), cl->Z());
694 // rotate the vector in order to put all clusters on a plane intersecting
695 // vertically the X axis; the angle depends on the sector
696 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
697 if (clusterPhi < 0.0) clusterPhi += 360.0;
698 if (clusterPhi < 100.0) {
701 else if (clusterPhi < 120.0) {
704 else if (clusterPhi < 140.0) {
707 else if (clusterPhi < 160.0) {
710 else if (clusterPhi < 180.0) {
716 vc.RotateZ(clusterRot * TMath::DegToRad());
717 // generate a track from the ESD track selected
718 AliEMCALTrack *track = new AliEMCALTrack(*tr);
719 // compute the 'phi' coordinate of the intersection point to
723 track->GetYAt(vc.X(), track->GetBz(), y);
724 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
725 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
727 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
728 // compute phi difference
729 Double_t dphi = trackPhi - clusterPhi;
730 if (TMath::Abs(dphi) > 180.0) {
731 dphi = 360.0 - TMath::Abs(dphi);
732 if (clusterPhi > trackPhi) dphi = -dphi;
734 // propagate track to the X position of rotated cluster
735 // and get the vector of X, Y, Z in the local ref. frame of the track
736 track->PropagateTo(vc.X(), x0, rho);
737 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
738 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
739 TVector3 vdiff = vt-vc;
741 // compute differences wr to each coordinate
742 if (vdiff.X() > fCutX) return distance;
743 if (vdiff.Y() > fCutY) return distance;
744 if (vdiff.Z() > fCutZ) return distance;
746 // compute true distance
747 distance = vdiff.Mag();
751 //------------------------------------------------------------------------------
753 Double_t AliEMCALTracker::CheckPairV3
754 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
757 // Given a track and a cluster,
758 // propagates the first to the radius of the second.
759 // Then, checks the propagation point against all cuts.
760 // If at least a cut is not passed, a valuer equal to
761 // twice the maximum allowed distance is passed (so the value returned
762 // will not be taken into account when creating matches)
765 AliEMCALTrack tr(*track);
768 Double_t distance = 2.0 * fMaxDist;
770 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
771 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
772 Double_t x[3], x1[3], x2[3];
774 // get initial track position
777 // evaluate the EMCAL sector number
779 if (phi < 0.0) phi += TMath::TwoPi();
780 sector = (Int_t)(phi / sectorWidth);
781 alpha = ((Double_t)sector + 0.5) * sectorWidth;
782 // evaluate the corresponding X for track propagation
783 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
784 tgtXnum = cl->Y() - slope * cl->X();
785 tgtXden = TMath::Sqrt(1.0 + slope*slope);
786 xprop = TMath::Abs(tgtXnum / tgtXden);
788 // propagate by small steps
791 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
792 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
793 rho = param[0]*param[4];
795 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
796 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
798 // get propagated position at the end
800 dx = TMath::Abs(x[0] - cl->X());
801 dy = TMath::Abs(x[1] - cl->Y());
802 dz = TMath::Abs(x[2] - cl->Z());
803 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
805 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
810 //------------------------------------------------------------------------------
812 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
815 // Propagates the track to the proximity of the EMCAL surface
818 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
819 Double_t x1[3], x2[3];
821 // get initial track position
824 // propagate by small steps
825 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
826 // to compute material budget, take current position and
827 // propagated hypothesis without energy loss
830 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
831 MeanMaterialBudget(x1, x2, param);
832 rho = param[0]*param[4];
834 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
840 //------------------------------------------------------------------------------
842 Int_t AliEMCALTracker::CreateMatches()
845 // Creation of matches between tracks and clusters.
846 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
847 // If it finds a cluster close enough to its propagation to EMCAL,
848 // which passes all cuts, its index is stored.
849 // If many clusters are found which satisfy the criteria described above,
850 // only the closest one is stored.
851 // At this level, it is possible that two tracks share the same cluster.
854 // if matches collection is already present, it is deleted
859 fMatches = new TList;
861 // initialize counters and indexes
863 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
864 Int_t it, nTracks = fTracks->GetEntries();
866 // external loop on clusters, internal loop on tracks
868 for (ic = 0; ic < nClusters; ic++) {
869 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
870 for (it = 0; it < nTracks; it++) {
871 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
872 dist = CheckPair(track, cluster);
873 //cout << dist << endl;
874 if (dist <= fMaxDist) {
875 AliEMCALMatch *candidate = new AliEMCALMatch;
876 candidate->SetIndexT(it);
877 candidate->SetIndexC(ic);
878 candidate->SetDistance(dist);
879 candidate->SetPt(track->GetSignedPt());
880 fMatches->Add(candidate);
887 // loop on clusters and tracks
889 Double_t dist, distBest;
890 for (it = 0; it < nTracks; it++) {
891 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
892 if (!track) continue;
895 for (ic = 0; ic < nClusters; ic++) {
896 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
897 if (!cluster) continue;
898 dist = CheckPair(track, cluster);
899 if (dist < distBest) {
905 track->SetMatchedClusterIndex(icBest);
906 track->SetMatchedClusterDist(distBest);
910 track->SetMatchedClusterIndex(-1);
918 //------------------------------------------------------------------------------
920 Int_t AliEMCALTracker::SolveCompetitions()
924 // The match list is sorted from the best to the worst match, w.r. to the
925 // distance between track prolongation and cluster position.
926 // Based on this criterion, starting from the first (best) match, a flag
927 // is set to both the involved track and cluster, and all matches containing
928 // an already used track or cluster are removed, leaving only the best match
932 // sort matches with respect to track-cluster distance
933 fMatches->Sort(kSortAscending);
935 // keep track of eliminated matches
938 // initialize flags to check repetitions
939 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
940 Int_t it, nTracks = fTracks->GetEntries();
941 Bool_t *usedC = new Bool_t[nClusters];
942 Bool_t *usedT = new Bool_t[nTracks];
943 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
944 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
947 TListIter iter(fMatches);
948 AliEMCALMatch *match = 0;
949 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
950 ic = match->GetIndexC();
951 it = match->GetIndexT();
952 if (!usedT[it] && !usedC[ic]) {
955 match->CanBeSaved() = kTRUE;
963 Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
964 AliEMCALTrack *track1 = 0, *track2 = 0;
965 for (it1 = 0; it1 < nTracks; it1++) {
966 track1 = (AliEMCALTrack*)fTracks->At(it1);
967 if (!track1) continue;
968 if (track1->GetMatchedClusterIndex() < 0) continue;
969 for (it2 = it1+1; it2 < nTracks; it2++) {
970 track2 = (AliEMCALTrack*)fTracks->At(it2);
971 if (!track2) continue;
972 if (track2->GetMatchedClusterIndex() < 0) continue;
973 if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
975 if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
976 track2->SetMatchedClusterIndex(-1);
978 else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
979 track1->SetMatchedClusterIndex(-1);
991 //------------------------------------------------------------------------------
993 void AliEMCALTracker::UnloadClusters()
996 // Free memory from all arrays
997 // This method is called after the local tracking step
998 // so we can safely delete everything
1004 //------------------------------------------------------------------------------
1006 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1008 fLabel(recPoint->GetPrimaryIndex()),
1014 // Translates an AliEMCALRecPoint object into the internal format.
1015 // Index of passed cluster in its native array must be specified.
1018 recPoint->GetGlobalPosition(clpos);
1025 //------------------------------------------------------------------------------
1027 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1029 fLabel(caloCluster->GetLabel()),
1035 // Translates an AliESDCaloCluster object into the internal format.
1036 // Index of passed cluster in its native array must be specified.
1039 caloCluster->GetPosition(clpos);
1041 fX = (Double_t)clpos[0];
1042 fY = (Double_t)clpos[1];
1043 fZ = (Double_t)clpos[2];
1046 //------------------------------------------------------------------------------
1048 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1051 // Tracks compared wrt their distance from matched point
1054 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1056 Double_t thisDist = fPt;//fDistance;
1057 Double_t thatDist = that->fPt;//that->GetDistance();
1059 if (thisDist > thatDist) return 1;
1060 else if (thisDist < thatDist) return -1;
1064 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1066 fCanBeSaved(kFALSE),
1072 //default constructor
1076 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1078 fCanBeSaved(copy.fCanBeSaved),
1079 fIndexC(copy.fIndexC),
1080 fIndexT(copy.fIndexT),
1081 fDistance(copy.fDistance),