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"
56 #include "AliEMCALReconstructor.h"
58 #include "AliEMCALTracker.h"
60 ClassImp(AliEMCALTracker)
63 //------------------------------------------------------------------------------
65 AliEMCALTracker::AliEMCALTracker()
68 fTrackCorrMode(kTrackCorrNone),
86 // Default constructor.
87 // Initializes al simple data members to default values,
88 // and all collections to NULL.
89 // Output file name is set to a default value.
94 //------------------------------------------------------------------------------
96 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
98 fNPropSteps(copy.fNPropSteps),
99 fTrackCorrMode(copy.fTrackCorrMode),
103 fCutAlphaMin(copy.fCutAlphaMin),
104 fCutAlphaMax(copy.fCutAlphaMax),
105 fCutAngle(copy.fCutAngle),
106 fMaxDist(copy.fMaxDist),
107 fCutNITS(copy.fCutNITS),
108 fCutNTPC(copy.fCutNTPC),
111 fTracks((TObjArray*)copy.fTracks->Clone()),
112 fClusters((TObjArray*)copy.fClusters->Clone()),
113 fMatches((TList*)copy.fMatches->Clone()),
118 // Besides copying all parameters, duplicates all collections.
122 //------------------------------------------------------------------------------
124 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
127 // Assignment operator.
128 // Besides copying all parameters, duplicates all collections.
134 fCutAlphaMin = copy.fCutAlphaMin;
135 fCutAlphaMax = copy.fCutAlphaMax;
136 fCutAngle = copy.fCutAngle;
137 fMaxDist = copy.fMaxDist;
138 fCutNITS = copy.fCutNITS;
139 fCutNTPC = copy.fCutNTPC;
141 fTracks = (TObjArray*)copy.fTracks->Clone();
142 fClusters = (TObjArray*)copy.fClusters->Clone();
143 fMatches = (TList*)copy.fMatches->Clone();
150 //------------------------------------------------------------------------------
152 void AliEMCALTracker::InitParameters()
155 // Retrieve initialization parameters
158 // Check if the instance of AliEMCALRecParam exists,
159 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
162 AliFatal("Reconstruction parameters for EMCAL not set!");
165 fCutX = recParam->GetTrkCutX();
166 fCutY = recParam->GetTrkCutY();
167 fCutZ = recParam->GetTrkCutZ();
168 fMaxDist = recParam->GetTrkCutR();
169 fCutAngle = recParam->GetTrkCutAngle();
170 fCutAlphaMin = recParam->GetTrkCutAlphaMin();
171 fCutAlphaMax = recParam->GetTrkCutAlphaMax();
172 fCutNITS = recParam->GetTrkCutNITS();
173 fCutNTPC = recParam->GetTrkCutNTPC();
178 //------------------------------------------------------------------------------
180 TTree* AliEMCALTracker::SearchTrueMatches()
182 //Search through the list of
183 //track match candidates and clusters
184 //and look for true matches
187 if (!fClusters) return 0;
188 if (fClusters->IsEmpty()) return 0;
189 if (!fTracks) return 0;
190 if (fTracks->IsEmpty()) return 0;
192 TTree *outTree = new TTree("tree", "True matches from event");
193 Int_t indexT, indexC, label;
194 outTree->Branch("indexC", &indexC, "indexC/I");
195 outTree->Branch("indexT", &indexT, "indexT/I");
196 outTree->Branch("label", &label , "label/I");
199 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
200 Int_t it, nTracks = fTracks->GetEntries();
202 for (ic = 0; ic < nClusters; ic++) {
203 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
204 label = cluster->Label();
205 indexC = cluster->Index();
206 for (it = 0; it < nTracks; it++) {
207 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
208 if (TMath::Abs(track->GetSeedLabel()) != label) continue;
209 dist = CheckPair(track, cluster);
210 if (dist <= fMaxDist) {
211 indexT = track->GetSeedIndex();
220 //------------------------------------------------------------------------------
222 void AliEMCALTracker::Clear(Option_t* option)
226 // Deletes all objects in arrays and the arrays themselves
230 Bool_t clearTracks = opt.Contains("TRACKS");
231 Bool_t clearClusters = opt.Contains("CLUSTERS");
232 Bool_t clearMatches = opt.Contains("MATCHES");
233 if (opt.Contains("ALL")) {
235 clearClusters = kTRUE;
236 clearMatches = kTRUE;
239 if (fTracks != 0x0 && clearTracks) {
244 if (fClusters != 0x0 && clearClusters) {
249 if (fMatches != 0x0 && clearMatches) {
256 //------------------------------------------------------------------------------
258 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
261 // Load EMCAL clusters in the form of AliEMCALRecPoint,
262 // from simulation temporary files.
263 // (When included in reconstruction chain, this method is used automatically)
268 cTree->SetBranchStatus("*",0); //disable all branches
269 cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
271 TBranch *branch = cTree->GetBranch("EMCALECARP");
273 AliError("Can't get the branch with the EMCAL clusters");
277 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
278 branch->SetAddress(&clusters);
280 //cTree->GetEvent(0);
282 Int_t nClusters = (Int_t)clusters->GetEntries();
283 if(fClusters) fClusters->Delete();
284 else fClusters = new TObjArray(0);
285 for (Int_t i = 0; i < nClusters; i++) {
286 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
287 if (!cluster) continue;
288 if (cluster->GetClusterType() != AliVCluster::kEMCALClusterv1) continue;
289 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
290 fClusters->AddLast(matchCluster);
293 branch->SetAddress(0);
296 if (fClusters->IsEmpty())
297 AliDebug(1,"No clusters collected");
299 AliDebug(1,Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
304 //------------------------------------------------------------------------------
306 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
309 // Load EMCAL clusters in the form of AliESDCaloClusters,
310 // from an AliESD object.
313 // make sure that tracks/clusters collections are empty
317 Int_t nClustersEMC = esd->GetNumberOfCaloClusters();
318 Int_t end = start + nClustersEMC;
320 fClusters = new TObjArray(0);
323 for (i = start; i < end; i++) {
324 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
325 if (!cluster) continue;
326 if (!cluster->IsEMCAL()) continue ;
327 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
328 fClusters->AddLast(matchCluster);
330 if (fClusters->IsEmpty())
331 AliDebug(1,"No clusters collected");
333 AliDebug(1,Form("Collected %d clusters from ESD", fClusters->GetEntries()));
338 //------------------------------------------------------------------------------
340 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
348 Int_t nTracks = esd->GetNumberOfTracks();
349 fTracks = new TObjArray(0);
352 Bool_t isKink=kFALSE;
354 for (i = 0; i < nTracks; i++) {
355 AliESDtrack *esdTrack = esd->GetTrack(i);
356 // set by default the value corresponding to "no match"
357 esdTrack->SetEMCALcluster(kUnmatched);
358 // if (esdTrack->GetLabel() < 0) continue;
359 // if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
361 for (j = 0; j < 3; j++) {
362 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
364 if (isKink) continue;
365 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
366 track->SetMass(0.13957018);
367 // check alpha and reject the tracks which fall outside EMCAL acceptance
368 alpha = track->GetAlpha() * TMath::RadToDeg();
369 if (alpha > -155.0 && alpha < 67.0) {
373 // if (!PropagateToEMCAL(track)) {
377 track->SetSeedIndex(i);
378 track->SetSeedLabel(esdTrack->GetLabel());
379 fTracks->AddLast(track);
381 if (fTracks->IsEmpty()) {
382 AliDebug(1,"No tracks collected");
385 AliDebug(1,Form("Collected %d tracks", fTracks->GetEntries()));
390 //------------------------------------------------------------------------------
392 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
395 // Main operation method.
396 // Gets external AliESD containing tracks to be matched.
397 // After executing match finding, stores in the same ESD object all infos
398 // and releases the object for further reconstruction steps.
401 // Note: should always return 0=OK, because otherwise all tracking
402 // is aborted for this event
405 AliError("NULL ESD passed");
410 // if cluster array is empty, cluster are collected
411 // from the passed ESD, and work is done with ESDCaloClusters
412 Int_t okLoadClusters, nClusters;
413 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
414 okLoadClusters = LoadClusters(esd);
416 nClusters = fClusters->GetEntries();
419 // collect ESD tracks
420 Int_t okLoadTracks = LoadTracks(esd), nTracks;
421 if (okLoadTracks) return 3;
422 nTracks = fTracks->GetEntries();
425 // each track is propagated to the "R" position of each cluster.
426 // The closest cluster is assigned as match.
427 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
428 Int_t nMatches = CreateMatches();
430 AliDebug(1,Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
434 AliDebug(1,Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
438 // when more than 1 track share the same matched cluster, only the closest one is kept.
439 Int_t nRemoved = SolveCompetitions();
440 AliDebug(1,Form("Removed %d duplicate matches", nRemoved));
441 if (nRemoved >= nMatches) {
442 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
447 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
448 Int_t nSaved = 0, trackID;
449 TListIter iter(fMatches);
450 AliEMCALMatch *match = 0;
451 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
452 if (!match->CanBeSaved()) continue;
453 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
454 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
455 trackID = track->GetSeedIndex();
456 AliESDtrack *esdTrack = esd->GetTrack(trackID);
457 if (!esdTrack) continue;
459 // cut on its and tpc track hits
460 if(esdTrack->GetNcls(0)<=fCutNITS)continue;
461 if(esdTrack->GetNcls(1)<=fCutNTPC)continue;
463 esdTrack->SetEMCALcluster(cluster->Index());
467 AliEMCALTrack *track = 0;
468 TObjArrayIter tracks(fTracks);
469 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
470 trackID = track->GetSeedIndex();
471 clusterID = track->GetMatchedClusterIndex();
472 AliESDtrack *esdTrack = esd->GetTrack(trackID);
473 if (!esdTrack) continue;
475 esdTrack->SetEMCALcluster(kUnmatched);
478 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
479 if (!cluster) continue;
481 esdTrack->SetEMCALcluster(cluster->Index());
486 AliDebug(1,Form("Saved %d matches", nSaved));
491 //------------------------------------------------------------------------------
493 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
496 // Set track correction mode
497 // gest the choice in string format and converts into
504 if (!opt.CompareTo("NONE")) {
505 fTrackCorrMode = kTrackCorrNone;
507 else if (!opt.CompareTo("MMB")) {
508 fTrackCorrMode = kTrackCorrMMB;
510 else if (!opt.CompareTo("FIXED")) {
511 fTrackCorrMode = kTrackCorrFixed;
514 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
519 //------------------------------------------------------------------------------
521 Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
525 // Given two angles in radiants, it converts them in the range 0-2pi
526 // then computes their true difference, i.e. if the difference a1-a2
527 // results to be larger than 180 degrees, it returns 360 - diff.
530 if (angle1 < 0.0) angle1 += TMath::TwoPi();
531 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
532 if (angle2 < 0.0) angle2 += TMath::TwoPi();
533 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
535 Double_t diff = TMath::Abs(angle1 - angle2);
536 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
538 if (angle2 > angle1) diff = -diff;
543 //------------------------------------------------------------------------------
545 Double_t AliEMCALTracker::CheckPair
546 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
549 // Given a track and a cluster,
550 // propagates the first to the radius of the second.
551 // Then, checks the propagation point against all cuts.
552 // If at least a cut is not passed, a valuer equal to
553 // twice the maximum allowed distance is passed (so the value returned
554 // will not be taken into account when creating matches)
558 //Bool_t isTrue = kFALSE;
559 // if (tr->GetSeedLabel() == cl->Label()) {
563 // copy track into temporary variable
564 AliEMCALTrack *tr = new AliEMCALTrack(*track);
566 Double_t distance = 2.0 * fMaxDist;
568 // check against cut on difference 'alpha - phi'
569 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
570 phi = AngleDiff(phi, tr->GetAlpha());
571 if (phi < fCutAlphaMin || phi > fCutAlphaMax){
576 // try to propagate to cluster radius
577 // (return the 'distance' value if it fails)
578 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
581 Double_t rt = TMath::Sqrt(x*x + y*y);
582 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
584 if (fTrackCorrMode == kTrackCorrMMB) {
585 Double_t pos1[3], pos2[3], param[6];
592 MeanMaterialBudget(pos1, pos2, param);
593 rho = param[0]*param[4];
596 else if (fTrackCorrMode == kTrackCorrFixed) {
607 cout.setf(ios::fixed);
609 //if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
610 for (i = 0; i < fNPropSteps; i++) {
611 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
612 if (!tr->PropagateTo(r, x0, rho)){
617 // if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
619 //if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
622 // when no steps are used, no correction makes sense
623 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
624 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
629 Bool_t propOK = kFALSE;
630 cout << "START" << endl;
631 Double_t dist, rCHK, bestDist = 10000000.0;
632 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
633 if (!tr->PropagateTo(rTMP)) continue;
636 rCHK = TMath::Sqrt(x*x + y*y);
637 dist = TMath::Abs(rCHK - rc);
638 cout << rCHK << " vs. " << rc << endl;
640 if (TMath::Abs(rCHK - rc) < 0.01) break;
642 cout << "STOP" << endl;
643 if (!propOK) return distance;
647 // get global propagation of track at end of propagation
651 TVector3 vc(cl->X(), cl->Y(), cl->Z());
652 TVector3 vt(x, y, z);
653 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
654 // check: where is the track?
655 // Double_t r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
656 // Double_t phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
657 // Double_t phiC = vc.Phi() * TMath::RadToDeg();
658 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
660 if (angle > fCutAngle) {
661 //cout << "angle" << endl;
666 // compute differences wr to each coordinate
668 if (TMath::Abs(x) > fCutX) {
669 //cout << "cut X" << endl;
674 if (TMath::Abs(y) > fCutY) {
675 //cout << "cut Y" << endl;
680 if (TMath::Abs(z) > fCutZ) {
681 //cout << "cut Z" << endl;
686 // compute true distance
687 distance = TMath::Sqrt(x*x + y*y + z*z);
688 //Double_t temp = CheckPairV2(tr, cl);
689 //if (temp < distance) return temp; else
691 // delete temporary object
697 //------------------------------------------------------------------------------
699 Double_t AliEMCALTracker::CheckPairV2
700 (AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
703 // Given a track and a cluster,
704 // propagates the first to the radius of the second.
705 // Then, checks the propagation point against all cuts.
706 // If at least a cut is not passed, a valuer equal to
707 // twice the maximum allowed distance is passed (so the value returned
708 // will not be taken into account when creating matches)
712 // Bool_t isTrue = kFALSE;
713 // if (tr->GetSeedLabel() == cl->Label()) {
715 // cout << "TRUE MATCH!!!" << endl;
718 Double_t distance = 2.0 * fMaxDist;
720 Double_t x0=0., rho=0.;
721 if (fTrackCorrMode == kTrackCorrMMB) {
722 Double_t pos1[3], pos2[3], param[6];
730 MeanMaterialBudget(pos1, pos2, param);
731 rho = param[0]*param[4];
734 else if (fTrackCorrMode == kTrackCorrFixed) {
743 // check against cut on difference 'alpha - phi'
744 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
745 phi = AngleDiff(phi, tr->GetAlpha());
746 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
748 // get cluster position and put them into a vector
749 TVector3 vc(cl->X(), cl->Y(), cl->Z());
750 // rotate the vector in order to put all clusters on a plane intersecting
751 // vertically the X axis; the angle depends on the sector
752 Double_t clusterRot=0., clusterPhi = vc.Phi() * TMath::RadToDeg();
753 if (clusterPhi < 0.0) clusterPhi += 360.0;
754 if (clusterPhi < 100.0) {
757 else if (clusterPhi < 120.0) {
760 else if (clusterPhi < 140.0) {
763 else if (clusterPhi < 160.0) {
766 else if (clusterPhi < 180.0) {
772 vc.RotateZ(clusterRot * TMath::DegToRad());
773 // generate a track from the ESD track selected
774 AliEMCALTrack *track = new AliEMCALTrack(*tr);
775 // compute the 'phi' coordinate of the intersection point to
779 track->GetYAt(vc.X(), track->GetBz(), y);
780 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
781 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
783 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
784 // compute phi difference
785 Double_t dphi = trackPhi - clusterPhi;
786 if (TMath::Abs(dphi) > 180.0) {
787 dphi = 360.0 - TMath::Abs(dphi);
788 if (clusterPhi > trackPhi) dphi = -dphi;
790 // propagate track to the X position of rotated cluster
791 // and get the vector of X, Y, Z in the local ref. frame of the track
792 track->PropagateTo(vc.X(), x0, rho);
793 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
794 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
795 TVector3 vdiff = vt-vc;
797 // compute differences wr to each coordinate
799 if (vdiff.X() > fCutX) return distance;
800 if (vdiff.Y() > fCutY) return distance;
801 if (vdiff.Z() > fCutZ) return distance;
803 // compute true distance
804 distance = vdiff.Mag();
808 //------------------------------------------------------------------------------
810 Double_t AliEMCALTracker::CheckPairV3
811 (AliEMCALTrack *track, AliEMCALMatchCluster *cl)
814 // Given a track and a cluster,
815 // propagates the first to the radius of the second.
816 // Then, checks the propagation point against all cuts.
817 // If at least a cut is not passed, a valuer equal to
818 // twice the maximum allowed distance is passed (so the value returned
819 // will not be taken into account when creating matches)
822 AliEMCALTrack tr(*track);
825 Double_t distance = 2.0 * fMaxDist;
826 Double_t dx=0., dy=0., dz=0.;
827 Double_t phi=0., alpha=0., slope=0., tgtXnum=0., tgtXden=0., sectorWidth = 20.0 * TMath::DegToRad();
828 Double_t xcurr=0., xprop=0., param[6] = {0., 0., 0., 0., 0., 0.}, x0=0., rho=0., bz=0.;
829 Double_t x[3]= {0., 0., 0.}, x1[3]= {0., 0., 0.}, x2[3]= {0., 0., 0.};
831 // get initial track position
834 // evaluate the EMCAL sector number
836 if (phi < 0.0) phi += TMath::TwoPi();
837 sector = (Int_t)(phi / sectorWidth);
838 alpha = ((Double_t)sector + 0.5) * sectorWidth;
839 // evaluate the corresponding X for track propagation
840 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
841 tgtXnum = cl->Y() - slope * cl->X();
842 tgtXden = TMath::Sqrt(1.0 + slope*slope);
843 xprop = TMath::Abs(tgtXnum / tgtXden);
845 // propagate by small steps
848 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
849 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
850 rho = param[0]*param[4];
852 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
853 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
855 // get propagated position at the end
857 dx = TMath::Abs(x[0] - cl->X());
858 dy = TMath::Abs(x[1] - cl->Y());
859 dz = TMath::Abs(x[2] - cl->Z());
860 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
862 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
867 //------------------------------------------------------------------------------
869 Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
872 // Propagates the track to the proximity of the EMCAL surface
875 Double_t xcurr=0., xtemp=0., xprop = 438.0, step = 10.0, param[6]= {0., 0., 0., 0., 0., 0.}, x0=0., rho=0., bz=0.;
876 Double_t x1[3]= {0., 0., 0.}, x2[3]= {0., 0., 0.};
878 // get initial track position
881 // propagate by small steps
882 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
883 // to compute material budget, take current position and
884 // propagated hypothesis without energy loss
887 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
888 MeanMaterialBudget(x1, x2, param);
889 rho = param[0]*param[4];
891 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
897 //------------------------------------------------------------------------------
899 Int_t AliEMCALTracker::CreateMatches()
902 // Creation of matches between tracks and clusters.
903 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
904 // If it finds a cluster close enough to its propagation to EMCAL,
905 // which passes all cuts, its index is stored.
906 // If many clusters are found which satisfy the criteria described above,
907 // only the closest one is stored.
908 // At this level, it is possible that two tracks share the same cluster.
911 // if matches collection is already present, it is deleted
916 fMatches = new TList;
918 // initialize counters and indexes
920 Int_t ic=0, nClusters = (Int_t)fClusters->GetEntries();
921 Int_t it=0, nTracks = fTracks->GetEntries();
923 // external loop on clusters, internal loop on tracks
925 for (ic = 0; ic < nClusters; ic++) {
926 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
927 for (it = 0; it < nTracks; it++) {
928 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
929 dist = CheckPair(track, cluster);
930 //cout << dist << endl;
931 if (dist <= fMaxDist) {
932 AliEMCALMatch *candidate = new AliEMCALMatch;
933 candidate->SetIndexT(it);
934 candidate->SetIndexC(ic);
935 candidate->SetDistance(dist);
936 candidate->SetPt(track->GetSignedPt());
937 fMatches->Add(candidate);
946 //------------------------------------------------------------------------------
948 Int_t AliEMCALTracker::SolveCompetitions()
952 // The match list is sorted from the best to the worst match, w.r. to the
953 // distance between track prolongation and cluster position.
954 // Based on this criterion, starting from the first (best) match, a flag
955 // is set to both the involved track and cluster, and all matches containing
956 // an already used track or cluster are removed, leaving only the best match
960 // sort matches with respect to track-cluster distance
961 fMatches->Sort(kSortAscending);
963 // keep track of eliminated matches
966 // initialize flags to check repetitions
967 Int_t ic=0, nClusters = (Int_t)fClusters->GetEntries();
968 Int_t it=0, nTracks = fTracks->GetEntries();
969 Bool_t *usedC = new Bool_t[nClusters];
970 Bool_t *usedT = new Bool_t[nTracks];
971 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
972 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
975 TListIter iter(fMatches);
976 AliEMCALMatch *match = 0;
977 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
978 ic = match->GetIndexC();
979 it = match->GetIndexT();
980 if (!usedT[it] && !usedC[ic]) {
983 match->CanBeSaved() = kTRUE;
996 //------------------------------------------------------------------------------
998 void AliEMCALTracker::UnloadClusters()
1001 // Free memory from all arrays
1002 // This method is called after the local tracking step
1003 // so we can safely delete everything
1009 //------------------------------------------------------------------------------
1011 TVector3 AliEMCALTracker::FindExtrapolationPoint(Double_t x,Double_t y,Double_t z, AliESDtrack *track)
1013 //Method to determine extrapolation point of track at location x,y,z
1014 AliEMCALTrack *tr = new AliEMCALTrack(*track);
1015 TVector3 error(-100.,-100.,-100.);
1016 if (!tr->PropagateToGlobal(x,y,z, 0.0, 0.0)) {
1019 Double_t pos[3]= {0., 0., 0.};
1021 TVector3 ExTrPos(pos[0],pos[1],pos[2]);
1026 //------------------------------------------------------------------------------
1028 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1030 fLabel(recPoint->GetPrimaryIndex()), //wrong! fixed below
1036 // Translates an AliEMCALRecPoint object into the internal format.
1037 // Index of passed cluster in its native array must be specified.
1040 recPoint->GetGlobalPosition(clpos);
1046 //AliEMCALRecPoint stores the track labels in the parents
1047 //list, sorted according to the fractional contribution to the
1048 //RecPoint. The zeroth parent gave the highest contribution
1049 Int_t multparent = 0;
1050 Int_t *parents = recPoint->GetParents(multparent);
1052 fLabel = parents[0];
1058 //------------------------------------------------------------------------------
1060 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1062 fLabel(caloCluster->GetLabel()),
1068 // Translates an AliESDCaloCluster object into the internal format.
1069 // Index of passed cluster in its native array must be specified.
1071 Float_t clpos[3]= {0., 0., 0.};
1072 caloCluster->GetPosition(clpos);
1074 fX = (Double_t)clpos[0];
1075 fY = (Double_t)clpos[1];
1076 fZ = (Double_t)clpos[2];
1079 //------------------------------------------------------------------------------
1081 Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1084 // Tracks compared wrt their distance from matched point
1087 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1089 Double_t thisDist = fPt;//fDistance;
1090 Double_t thatDist = that->fPt;//that->GetDistance();
1092 if (thisDist > thatDist) return 1;
1093 else if (thisDist < thatDist) return -1;
1097 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1099 fCanBeSaved(kFALSE),
1105 //default constructor
1109 AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1111 fCanBeSaved(copy.fCanBeSaved),
1112 fIndexC(copy.fIndexC),
1113 fIndexT(copy.fIndexT),
1114 fDistance(copy.fDistance),