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::kEMCALClusterv1) 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::kEMCALClusterv1) 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){
532 // try to propagate to cluster radius
533 // (return the 'distance' value if it fails)
534 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
537 Double_t rt = TMath::Sqrt(x*x + y*y);
538 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
540 if (fTrackCorrMode == kTrackCorrMMB) {
541 Double_t pos1[3], pos2[3], param[6];
548 MeanMaterialBudget(pos1, pos2, param);
549 rho = param[0]*param[4];
552 else if (fTrackCorrMode == kTrackCorrFixed) {
563 cout.setf(ios::fixed);
565 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
566 for (i = 0; i < fNPropSteps; i++) {
567 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
568 if (!tr->PropagateTo(r, x0, rho)){
573 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
575 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
578 // when no steps are used, no correction makes sense
579 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
580 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
585 Bool_t propOK = kFALSE;
586 cout << "START" << endl;
587 Double_t dist, rCHK, bestDist = 10000000.0;
588 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
589 if (!tr->PropagateTo(rTMP)) continue;
592 rCHK = TMath::Sqrt(x*x + y*y);
593 dist = TMath::Abs(rCHK - rc);
594 cout << rCHK << " vs. " << rc << endl;
596 if (TMath::Abs(rCHK - rc) < 0.01) break;
598 cout << "STOP" << endl;
599 if (!propOK) return distance;
603 // get global propagation of track at end of propagation
607 TVector3 vc(cl->X(), cl->Y(), cl->Z());
608 TVector3 vt(x, y, z);
609 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
610 // check: where is the track?
611 Double_t r, phiT, phiC;
612 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
613 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
614 phiC = vc.Phi() * TMath::RadToDeg();
615 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
617 if (angle > fCutAngle) {
618 //cout << "angle" << endl;
623 // compute differences wr to each coordinate
625 if (TMath::Abs(x) > fCutX) {
626 //cout << "cut X" << endl;
631 if (TMath::Abs(y) > fCutY) {
632 //cout << "cut Y" << endl;
637 if (TMath::Abs(z) > fCutZ) {
638 //cout << "cut Z" << endl;
643 // compute true distance
644 distance = TMath::Sqrt(x*x + y*y + z*z);
645 //Double_t temp = CheckPairV2(tr, cl);
646 //if (temp < distance) return temp; else
648 // delete temporary object
654 //------------------------------------------------------------------------------
656 Double_t AliEMCALTracker::CheckPairV2
657 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
660 // Given a track and a cluster,
661 // propagates the first to the radius of the second.
662 // Then, checks the propagation point against all cuts.
663 // If at least a cut is not passed, a valuer equal to
664 // twice the maximum allowed distance is passed (so the value returned
665 // will not be taken into account when creating matches)
669 // Bool_t isTrue = kFALSE;
670 // if (tr->GetSeedLabel() == cl->Label()) {
672 // cout << "TRUE MATCH!!!" << endl;
675 Double_t distance = 2.0 * fMaxDist;
678 if (fTrackCorrMode == kTrackCorrMMB) {
679 Double_t pos1[3], pos2[3], param[6];
687 MeanMaterialBudget(pos1, pos2, param);
688 rho = param[0]*param[4];
691 else if (fTrackCorrMode == kTrackCorrFixed) {
700 // check against cut on difference 'alpha - phi'
701 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
702 phi = AngleDiff(phi, tr->GetAlpha());
703 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
705 // get cluster position and put them into a vector
706 TVector3 vc(cl->X(), cl->Y(), cl->Z());
707 // rotate the vector in order to put all clusters on a plane intersecting
708 // vertically the X axis; the angle depends on the sector
709 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
710 if (clusterPhi < 0.0) clusterPhi += 360.0;
711 if (clusterPhi < 100.0) {
714 else if (clusterPhi < 120.0) {
717 else if (clusterPhi < 140.0) {
720 else if (clusterPhi < 160.0) {
723 else if (clusterPhi < 180.0) {
729 vc.RotateZ(clusterRot * TMath::DegToRad());
730 // generate a track from the ESD track selected
731 AliEMCALTrack *track = new AliEMCALTrack(*tr);
732 // compute the 'phi' coordinate of the intersection point to
736 track->GetYAt(vc.X(), track->GetBz(), y);
737 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
738 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
740 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
741 // compute phi difference
742 Double_t dphi = trackPhi - clusterPhi;
743 if (TMath::Abs(dphi) > 180.0) {
744 dphi = 360.0 - TMath::Abs(dphi);
745 if (clusterPhi > trackPhi) dphi = -dphi;
747 // propagate track to the X position of rotated cluster
748 // and get the vector of X, Y, Z in the local ref. frame of the track
749 track->PropagateTo(vc.X(), x0, rho);
750 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
751 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
752 TVector3 vdiff = vt-vc;
754 // compute differences wr to each coordinate
756 if (vdiff.X() > fCutX) return distance;
757 if (vdiff.Y() > fCutY) return distance;
758 if (vdiff.Z() > fCutZ) return distance;
760 // compute true distance
761 distance = vdiff.Mag();
765 //------------------------------------------------------------------------------
767 Double_t AliEMCALTracker::CheckPairV3
768 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
771 // Given a track and a cluster,
772 // propagates the first to the radius of the second.
773 // Then, checks the propagation point against all cuts.
774 // If at least a cut is not passed, a valuer equal to
775 // twice the maximum allowed distance is passed (so the value returned
776 // will not be taken into account when creating matches)
779 AliEMCALTrack tr(*track);
782 Double_t distance = 2.0 * fMaxDist;
784 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
785 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
786 Double_t x[3], x1[3], x2[3];
788 // get initial track position
791 // evaluate the EMCAL sector number
793 if (phi < 0.0) phi += TMath::TwoPi();
794 sector = (Int_t)(phi / sectorWidth);
795 alpha = ((Double_t)sector + 0.5) * sectorWidth;
796 // evaluate the corresponding X for track propagation
797 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
798 tgtXnum = cl->Y() - slope * cl->X();
799 tgtXden = TMath::Sqrt(1.0 + slope*slope);
800 xprop = TMath::Abs(tgtXnum / tgtXden);
802 // propagate by small steps
805 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
806 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
807 rho = param[0]*param[4];
809 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
810 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
812 // get propagated position at the end
814 dx = TMath::Abs(x[0] - cl->X());
815 dy = TMath::Abs(x[1] - cl->Y());
816 dz = TMath::Abs(x[2] - cl->Z());
817 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
819 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
824 //------------------------------------------------------------------------------
826 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
829 // Propagates the track to the proximity of the EMCAL surface
832 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
833 Double_t x1[3], x2[3];
835 // get initial track position
838 // propagate by small steps
839 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
840 // to compute material budget, take current position and
841 // propagated hypothesis without energy loss
844 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
845 MeanMaterialBudget(x1, x2, param);
846 rho = param[0]*param[4];
848 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
854 //------------------------------------------------------------------------------
856 Int_t AliEMCALTracker::CreateMatches()
859 // Creation of matches between tracks and clusters.
860 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
861 // If it finds a cluster close enough to its propagation to EMCAL,
862 // which passes all cuts, its index is stored.
863 // If many clusters are found which satisfy the criteria described above,
864 // only the closest one is stored.
865 // At this level, it is possible that two tracks share the same cluster.
868 // if matches collection is already present, it is deleted
873 fMatches = new TList;
875 // initialize counters and indexes
877 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
878 Int_t it, nTracks = fTracks->GetEntries();
880 // external loop on clusters, internal loop on tracks
882 for (ic = 0; ic < nClusters; ic++) {
883 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
884 for (it = 0; it < nTracks; it++) {
885 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
886 dist = CheckPair(track, cluster);
887 //cout << dist << endl;
888 if (dist <= fMaxDist) {
889 AliEMCALMatch *candidate = new AliEMCALMatch;
890 candidate->SetIndexT(it);
891 candidate->SetIndexC(ic);
892 candidate->SetDistance(dist);
893 candidate->SetPt(track->GetSignedPt());
894 fMatches->Add(candidate);
901 // loop on clusters and tracks
903 Double_t dist, distBest;
904 for (it = 0; it < nTracks; it++) {
905 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
906 if (!track) continue;
909 for (ic = 0; ic < nClusters; ic++) {
910 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
911 if (!cluster) continue;
912 dist = CheckPair(track, cluster);
913 if (dist < distBest) {
919 track->SetMatchedClusterIndex(icBest);
920 track->SetMatchedClusterDist(distBest);
924 track->SetMatchedClusterIndex(-1);
932 //------------------------------------------------------------------------------
934 Int_t AliEMCALTracker::SolveCompetitions()
938 // The match list is sorted from the best to the worst match, w.r. to the
939 // distance between track prolongation and cluster position.
940 // Based on this criterion, starting from the first (best) match, a flag
941 // is set to both the involved track and cluster, and all matches containing
942 // an already used track or cluster are removed, leaving only the best match
946 // sort matches with respect to track-cluster distance
947 fMatches->Sort(kSortAscending);
949 // keep track of eliminated matches
952 // initialize flags to check repetitions
953 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
954 Int_t it, nTracks = fTracks->GetEntries();
955 Bool_t *usedC = new Bool_t[nClusters];
956 Bool_t *usedT = new Bool_t[nTracks];
957 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
958 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
961 TListIter iter(fMatches);
962 AliEMCALMatch *match = 0;
963 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
964 ic = match->GetIndexC();
965 it = match->GetIndexT();
966 if (!usedT[it] && !usedC[ic]) {
969 match->CanBeSaved() = kTRUE;
977 Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
978 AliEMCALTrack *track1 = 0, *track2 = 0;
979 for (it1 = 0; it1 < nTracks; it1++) {
980 track1 = (AliEMCALTrack*)fTracks->At(it1);
981 if (!track1) continue;
982 if (track1->GetMatchedClusterIndex() < 0) continue;
983 for (it2 = it1+1; it2 < nTracks; it2++) {
984 track2 = (AliEMCALTrack*)fTracks->At(it2);
985 if (!track2) continue;
986 if (track2->GetMatchedClusterIndex() < 0) continue;
987 if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
989 if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
990 track2->SetMatchedClusterIndex(-1);
992 else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
993 track1->SetMatchedClusterIndex(-1);
1005 //------------------------------------------------------------------------------
1007 void AliEMCALTracker::UnloadClusters()
1010 // Free memory from all arrays
1011 // This method is called after the local tracking step
1012 // so we can safely delete everything
1018 //------------------------------------------------------------------------------
1020 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1022 fLabel(recPoint->GetPrimaryIndex()),
1028 // Translates an AliEMCALRecPoint object into the internal format.
1029 // Index of passed cluster in its native array must be specified.
1032 recPoint->GetGlobalPosition(clpos);
1039 //------------------------------------------------------------------------------
1041 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1043 fLabel(caloCluster->GetLabel()),
1049 // Translates an AliESDCaloCluster object into the internal format.
1050 // Index of passed cluster in its native array must be specified.
1053 caloCluster->GetPosition(clpos);
1055 fX = (Double_t)clpos[0];
1056 fY = (Double_t)clpos[1];
1057 fZ = (Double_t)clpos[2];
1060 //------------------------------------------------------------------------------
1062 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1065 // Tracks compared wrt their distance from matched point
1068 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1070 Double_t thisDist = fPt;//fDistance;
1071 Double_t thatDist = that->fPt;//that->GetDistance();
1073 if (thisDist > thatDist) return 1;
1074 else if (thisDist < thatDist) return -1;
1078 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1080 fCanBeSaved(kFALSE),
1086 //default constructor
1090 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1092 fCanBeSaved(copy.fCanBeSaved),
1093 fIndexC(copy.fIndexC),
1094 fIndexT(copy.fIndexT),
1095 fDistance(copy.fDistance),