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>
45 #include "AliESDtrack.h"
46 #include "AliKalmanTrack.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 // Clears all specified arrays and the containers themselves.
184 Bool_t doDelete = opt.Contains("DELETE");
185 Bool_t clearTracks = opt.Contains("TRACKS");
186 Bool_t clearClusters = opt.Contains("CLUSTERS");
187 Bool_t clearMatches = opt.Contains("MATCHES");
188 if (opt.Contains("ALL")) {
190 clearClusters = kTRUE;
191 clearMatches = kTRUE;
194 if (fTracks != 0x0 && clearTracks) {
199 if (!fTracks->IsEmpty()) fTracks->Delete();
204 if (fClusters != 0x0 && clearClusters) {
209 if (!fClusters->IsEmpty()) fClusters->Delete();
214 if (fMatches != 0x0 && clearMatches) {
219 if (!fMatches->IsEmpty()) fMatches->Delete();
226 //------------------------------------------------------------------------------
228 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
231 // Load EMCAL clusters in the form of AliEMCALRecPoint,
232 // from simulation temporary files.
233 // (When included in reconstruction chain, this method is used automatically)
238 TBranch *branch = cTree->GetBranch("EMCALECARP");
240 AliError("Can't get the branch with the EMCAL clusters");
244 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
245 branch->SetAddress(&clusters);
248 Int_t nClusters = (Int_t)clusters->GetEntries();
249 fClusters = new TObjArray(0);
250 for (Int_t i = 0; i < nClusters; i++) {
251 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
252 if (!cluster) continue;
253 if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
254 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
255 fClusters->AddLast(matchCluster);
257 if (fClusters->IsEmpty()) {
258 AliError("No clusters collected");
262 branch->SetAddress(0);
266 AliInfo(Form("Collected %d clusters", fClusters->GetEntries()));
271 //------------------------------------------------------------------------------
273 Int_t AliEMCALTracker::LoadClusters(AliESD *esd)
276 // Load EMCAL clusters in the form of AliESDCaloClusters,
277 // from an AliESD object.
280 // make sure that tracks/clusters collections are empty
283 Int_t start = esd->GetFirstEMCALCluster();
284 Int_t nClustersEMC = esd->GetNumberOfEMCALClusters();
285 Int_t end = start + nClustersEMC;
287 fClusters = new TObjArray(0);
290 for (i = start; i < end; i++) {
291 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
292 if (!cluster) continue;
293 if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
294 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
295 fClusters->AddLast(matchCluster);
297 if (fClusters->IsEmpty()) {
298 AliError("No clusters collected");
302 AliInfo(Form("Collected %d clusters", fClusters->GetEntries()));
307 //------------------------------------------------------------------------------
309 Int_t AliEMCALTracker::LoadTracks(AliESD *esd)
317 Int_t nTracks = esd->GetNumberOfTracks();
318 fTracks = new TObjArray(0);
323 for (i = 0; i < nTracks; i++) {
324 AliESDtrack *esdTrack = esd->GetTrack(i);
325 // set by default the value corresponding to "no match"
326 esdTrack->SetEMCALcluster(kUnmatched);
327 // if (esdTrack->GetLabel() < 0) continue;
328 // if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
330 for (j = 0; j < 3; j++) {
331 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
333 if (isKink) continue;
334 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
335 track->SetMass(0.13957018);
336 // check alpha and reject the tracks which fall outside EMCAL acceptance
337 alpha = track->GetAlpha() * TMath::RadToDeg();
338 if (alpha > -155.0 && alpha < 67.0) {
342 // if (!PropagateToEMCAL(track)) {
346 track->SetSeedIndex(i);
347 track->SetSeedLabel(esdTrack->GetLabel());
348 fTracks->AddLast(track);
350 if (fTracks->IsEmpty()) {
351 AliError("No tracks collected");
355 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
360 //------------------------------------------------------------------------------
362 Int_t AliEMCALTracker::PropagateBack(AliESD* esd)
365 // Main operation method.
366 // Gets external AliESD containing tracks to be matched.
367 // After executing match finding, stores in the same ESD object all infos
368 // and releases the object for further reconstruction steps.
372 AliError("NULL ESD passed");
377 // if cluster array is empty, cluster are collected
378 // from the passed ESD, and work is done with ESDCaloClusters
379 Int_t okLoadClusters, nClusters;
380 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
381 okLoadClusters = LoadClusters(esd);
382 if (okLoadClusters) return 2;
384 nClusters = fClusters->GetEntries();
387 // collect ESD tracks
388 Int_t okLoadTracks = LoadTracks(esd), nTracks;
389 if (okLoadTracks) return 3;
390 nTracks = fTracks->GetEntries();
393 // each track is propagated to the "R" position of each cluster.
394 // The closest cluster is assigned as match.
395 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
396 Int_t nMatches = CreateMatches();
398 AliInfo(Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
402 AliInfo(Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
406 // when more than 1 track share the same matched cluster, only the closest one is kept.
407 Int_t nRemoved = SolveCompetitions();
408 AliInfo(Form("Removed %d duplicate matches", nRemoved));
409 if (nRemoved >= nMatches) {
410 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
415 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
416 Int_t nSaved = 0, trackID, nGood = 0, nFake = 0;
417 TListIter iter(fMatches);
418 AliEMCALMatch *match = 0;
419 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
420 if (!match->CanBeSaved()) continue;
421 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
422 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
423 trackID = track->GetSeedIndex();
424 AliESDtrack *esdTrack = esd->GetTrack(trackID);
425 if (!esdTrack) continue;
426 if (TMath::Abs(esdTrack->GetLabel()) == cluster->Label()) {
427 esdTrack->SetEMCALcluster(cluster->Index());
431 esdTrack->SetEMCALcluster(-cluster->Index());
437 AliEMCALTrack *track = 0;
438 TObjArrayIter tracks(fTracks);
439 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
440 trackID = track->GetSeedIndex();
441 clusterID = track->GetMatchedClusterIndex();
442 AliESDtrack *esdTrack = esd->GetTrack(trackID);
443 if (!esdTrack) continue;
445 esdTrack->SetEMCALcluster(kUnmatched);
448 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
449 if (!cluster) continue;
450 if (esdTrack->GetLabel() == cluster->Label()) {
452 esdTrack->SetEMCALcluster(cluster->Index());
455 esdTrack->SetEMCALcluster(-cluster->Index());
461 AliInfo(Form("Saved %d matches [%d good + %d fake]", nSaved, nGood, nFake));
466 //------------------------------------------------------------------------------
468 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
471 // Set track correction mode
472 // gest the choice in string format and converts into
479 if (!opt.CompareTo("NONE")) {
480 fTrackCorrMode = kTrackCorrNone;
482 else if (!opt.CompareTo("MMB")) {
483 fTrackCorrMode = kTrackCorrMMB;
485 else if (!opt.CompareTo("FIXED")) {
486 fTrackCorrMode = kTrackCorrFixed;
489 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
494 //------------------------------------------------------------------------------
496 Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
500 // Given two angles in radiants, it converts them in the range 0-2pi
501 // then computes their true difference, i.e. if the difference a1-a2
502 // results to be larger than 180 degrees, it returns 360 - diff.
505 if (angle1 < 0.0) angle1 += TMath::TwoPi();
506 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
507 if (angle2 < 0.0) angle2 += TMath::TwoPi();
508 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
510 Double_t diff = TMath::Abs(angle1 - angle2);
511 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
513 if (angle2 > angle1) diff = -diff;
518 //------------------------------------------------------------------------------
520 Double_t AliEMCALTracker::CheckPair
521 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
524 // Given a track and a cluster,
525 // propagates the first to the radius of the second.
526 // Then, checks the propagation point against all cuts.
527 // If at least a cut is not passed, a valuer equal to
528 // twice the maximum allowed distance is passed (so the value returned
529 // will not be taken into account when creating matches)
533 Bool_t isTrue = kFALSE;
534 // if (tr->GetSeedLabel() == cl->Label()) {
538 // copy track into temporary variable
539 AliEMCALTrack *tr = new AliEMCALTrack(*track);
541 Double_t distance = 2.0 * fMaxDist;
543 // check against cut on difference 'alpha - phi'
544 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
545 phi = AngleDiff(phi, tr->GetAlpha());
546 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
548 // try to propagate to cluster radius
549 // (return the 'distance' value if it fails)
550 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
553 Double_t rt = TMath::Sqrt(x*x + y*y);
554 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
556 if (fTrackCorrMode == kTrackCorrMMB) {
557 Double_t pos1[3], pos2[3], param[6];
564 AliKalmanTrack::MeanMaterialBudget(pos1, pos2, param);
568 else if (fTrackCorrMode == kTrackCorrFixed) {
579 cout.setf(ios::fixed);
581 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
582 for (i = 0; i < fNPropSteps; i++) {
583 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
584 if (!tr->PropagateTo(r, x0, rho)) return distance;
586 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
588 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
591 // when no steps are used, no correction makes sense
592 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
593 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)) return distance;
595 Bool_t propOK = kFALSE;
596 cout << "START" << endl;
597 Double_t dist, rCHK, bestDist = 10000000.0;
598 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
599 if (!tr->PropagateTo(rTMP)) continue;
602 rCHK = TMath::Sqrt(x*x + y*y);
603 dist = TMath::Abs(rCHK - rc);
604 cout << rCHK << " vs. " << rc << endl;
606 if (TMath::Abs(rCHK - rc) < 0.01) break;
608 cout << "STOP" << endl;
609 if (!propOK) return distance;
613 // get global propagation of track at end of propagation
617 TVector3 vc(cl->X(), cl->Y(), cl->Z());
618 TVector3 vt(x, y, z);
619 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
620 // check: where is the track?
621 Double_t r, phiT, phiC;
622 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
623 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
624 phiC = vc.Phi() * TMath::RadToDeg();
625 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
627 if (angle > fCutAngle) {
628 //cout << "angle" << endl;
632 // compute differences wr to each coordinate
634 if (TMath::Abs(x) > fCutX) {
635 //cout << "cut X" << endl;
639 if (TMath::Abs(y) > fCutY) {
640 //cout << "cut Y" << endl;
644 if (TMath::Abs(z) > fCutZ) {
645 //cout << "cut Z" << endl;
649 // compute true distance
650 distance = TMath::Sqrt(x*x + y*y + z*z);
651 //Double_t temp = CheckPairV2(tr, cl);
652 //if (temp < distance) return temp; else
654 // delete temporary object
660 //------------------------------------------------------------------------------
662 Double_t AliEMCALTracker::CheckPairV2
663 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
666 // Given a track and a cluster,
667 // propagates the first to the radius of the second.
668 // Then, checks the propagation point against all cuts.
669 // If at least a cut is not passed, a valuer equal to
670 // twice the maximum allowed distance is passed (so the value returned
671 // will not be taken into account when creating matches)
675 // Bool_t isTrue = kFALSE;
676 // if (tr->GetSeedLabel() == cl->Label()) {
678 // cout << "TRUE MATCH!!!" << endl;
681 Double_t distance = 2.0 * fMaxDist;
684 if (fTrackCorrMode == kTrackCorrMMB) {
685 Double_t pos1[3], pos2[3], param[6];
693 AliKalmanTrack::MeanMaterialBudget(pos1, pos2, param);
697 else if (fTrackCorrMode == kTrackCorrFixed) {
706 // check against cut on difference 'alpha - phi'
707 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
708 phi = AngleDiff(phi, tr->GetAlpha());
709 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
711 // get cluster position and put them into a vector
712 TVector3 vc(cl->X(), cl->Y(), cl->Z());
713 // rotate the vector in order to put all clusters on a plane intersecting
714 // vertically the X axis; the angle depends on the sector
715 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
716 if (clusterPhi < 0.0) clusterPhi += 360.0;
717 if (clusterPhi < 100.0) {
720 else if (clusterPhi < 120.0) {
723 else if (clusterPhi < 140.0) {
726 else if (clusterPhi < 160.0) {
729 else if (clusterPhi < 180.0) {
735 vc.RotateZ(clusterRot * TMath::DegToRad());
736 // generate a track from the ESD track selected
737 AliEMCALTrack *track = new AliEMCALTrack(*tr);
738 // compute the 'phi' coordinate of the intersection point to
742 track->GetYAt(vc.X(), track->GetBz(), y);
743 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
744 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
746 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
747 // compute phi difference
748 Double_t dphi = trackPhi - clusterPhi;
749 if (TMath::Abs(dphi) > 180.0) {
750 dphi = 360.0 - TMath::Abs(dphi);
751 if (clusterPhi > trackPhi) dphi = -dphi;
753 // propagate track to the X position of rotated cluster
754 // and get the vector of X, Y, Z in the local ref. frame of the track
755 track->PropagateTo(vc.X(), x0, rho);
756 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
757 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
758 TVector3 vdiff = vt-vc;
760 // compute differences wr to each coordinate
761 if (vdiff.X() > fCutX) return distance;
762 if (vdiff.Y() > fCutY) return distance;
763 if (vdiff.Z() > fCutZ) return distance;
765 // compute true distance
766 distance = vdiff.Mag();
770 //------------------------------------------------------------------------------
772 Double_t AliEMCALTracker::CheckPairV3
773 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
776 // Given a track and a cluster,
777 // propagates the first to the radius of the second.
778 // Then, checks the propagation point against all cuts.
779 // If at least a cut is not passed, a valuer equal to
780 // twice the maximum allowed distance is passed (so the value returned
781 // will not be taken into account when creating matches)
784 AliEMCALTrack tr(*track);
787 Double_t distance = 2.0 * fMaxDist;
789 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
790 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, d, x0, rho, bz;
791 Double_t x[3], x1[3], x2[3];
793 // get initial track position
796 // evaluate the EMCAL sector number
798 if (phi < 0.0) phi += TMath::TwoPi();
799 sector = (Int_t)(phi / sectorWidth);
800 alpha = ((Double_t)sector + 0.5) * sectorWidth;
801 // evaluate the corresponding X for track propagation
802 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
803 tgtXnum = cl->Y() - slope * cl->X();
804 tgtXden = TMath::Sqrt(1.0 + slope*slope);
805 xprop = TMath::Abs(tgtXnum / tgtXden);
807 // propagate by small steps
810 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
811 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
815 if (!tr.PropagateTo(xprop, d*rho/x0, x0)) return distance;
816 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
818 // get propagated position at the end
820 dx = TMath::Abs(x[0] - cl->X());
821 dy = TMath::Abs(x[1] - cl->Y());
822 dz = TMath::Abs(x[2] - cl->Z());
823 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
825 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
830 //------------------------------------------------------------------------------
832 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
835 // Propagates the track to the proximity of the EMCAL surface
838 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], d, x0, rho, bz;
839 Double_t x1[3], x2[3];
841 // get initial track position
844 // propagate by small steps
845 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
846 // to compute material budget, take current position and
847 // propagated hypothesis without energy loss
850 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
851 AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
855 if (!tr->PropagateTo(xtemp, d*rho/x0, x0)) return kFALSE;
861 //------------------------------------------------------------------------------
863 Int_t AliEMCALTracker::CreateMatches()
866 // Creation of matches between tracks and clusters.
867 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
868 // If it finds a cluster close enough to its propagation to EMCAL,
869 // which passes all cuts, its index is stored.
870 // If many clusters are found which satisfy the criteria described above,
871 // only the closest one is stored.
872 // At this level, it is possible that two tracks share the same cluster.
875 // if matches collection is already present, it is deleted
880 fMatches = new TList;
882 // initialize counters and indexes
884 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
885 Int_t it, nTracks = fTracks->GetEntries();
887 // external loop on clusters, internal loop on tracks
889 for (ic = 0; ic < nClusters; ic++) {
890 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
891 for (it = 0; it < nTracks; it++) {
892 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
893 dist = CheckPair(track, cluster);
894 //cout << dist << endl;
895 if (dist <= fMaxDist) {
896 AliEMCALMatch *candidate = new AliEMCALMatch;
897 candidate->SetIndexT(it);
898 candidate->SetIndexC(ic);
899 candidate->SetDistance(dist);
900 candidate->SetPt(track->GetPt());
901 fMatches->Add(candidate);
908 // loop on clusters and tracks
910 Double_t dist, distBest;
911 for (it = 0; it < nTracks; it++) {
912 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
913 if (!track) continue;
916 for (ic = 0; ic < nClusters; ic++) {
917 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
918 if (!cluster) continue;
919 dist = CheckPair(track, cluster);
920 if (dist < distBest) {
926 track->SetMatchedClusterIndex(icBest);
927 track->SetMatchedClusterDist(distBest);
931 track->SetMatchedClusterIndex(-1);
939 //------------------------------------------------------------------------------
941 Int_t AliEMCALTracker::SolveCompetitions()
945 // The match list is sorted from the best to the worst match, w.r. to the
946 // distance between track prolongation and cluster position.
947 // Based on this criterion, starting from the first (best) match, a flag
948 // is set to both the involved track and cluster, and all matches containing
949 // an already used track or cluster are removed, leaving only the best match
953 // sort matches with respect to track-cluster distance
954 fMatches->Sort(kSortAscending);
956 // keep track of eliminated matches
959 // initialize flags to check repetitions
960 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
961 Int_t it, nTracks = fTracks->GetEntries();
962 Bool_t *usedC = new Bool_t[nClusters];
963 Bool_t *usedT = new Bool_t[nTracks];
964 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
965 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
968 TListIter iter(fMatches);
969 AliEMCALMatch *match = 0;
970 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
971 ic = match->GetIndexC();
972 it = match->GetIndexT();
973 if (!usedT[it] && !usedC[ic]) {
976 match->CanBeSaved() = kTRUE;
984 Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
985 AliEMCALTrack *track1 = 0, *track2 = 0;
986 for (it1 = 0; it1 < nTracks; it1++) {
987 track1 = (AliEMCALTrack*)fTracks->At(it1);
988 if (!track1) continue;
989 if (track1->GetMatchedClusterIndex() < 0) continue;
990 for (it2 = it1+1; it2 < nTracks; it2++) {
991 track2 = (AliEMCALTrack*)fTracks->At(it2);
992 if (!track2) continue;
993 if (track2->GetMatchedClusterIndex() < 0) continue;
994 if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
996 if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
997 track2->SetMatchedClusterIndex(-1);
999 else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
1000 track1->SetMatchedClusterIndex(-1);
1009 //------------------------------------------------------------------------------
1011 void AliEMCALTracker::UnloadClusters()
1014 // Free memory from clusters
1020 //------------------------------------------------------------------------------
1022 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1024 fLabel(recPoint->GetPrimaryIndex()),
1030 // Translates an AliEMCALRecPoint object into the internal format.
1031 // Index of passed cluster in its native array must be specified.
1034 recPoint->GetGlobalPosition(clpos);
1041 //------------------------------------------------------------------------------
1043 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1045 fLabel(caloCluster->GetLabel()),
1051 // Translates an AliESDCaloCluster object into the internal format.
1052 // Index of passed cluster in its native array must be specified.
1055 caloCluster->GetPosition(clpos);
1057 fX = (Double_t)clpos[0];
1058 fY = (Double_t)clpos[1];
1059 fZ = (Double_t)clpos[2];
1062 //------------------------------------------------------------------------------
1064 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1067 // Tracks compared wrt their distance from matched point
1070 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1072 Double_t thisDist = fPt;//fDistance;
1073 Double_t thatDist = that->fPt;//that->GetDistance();
1075 if (thisDist > thatDist) return 1;
1076 else if (thisDist < thatDist) return -1;
1080 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1082 fCanBeSaved(kFALSE),
1088 //default constructor
1092 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1094 fCanBeSaved(copy.fCanBeSaved),
1095 fIndexC(copy.fIndexC),
1096 fIndexT(copy.fIndexT),
1097 fDistance(copy.fDistance),