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 // Revised by Rongrong 2010-05-31 (rongrong.ma@cern.ch)
31 //=========================================================================
33 #include <Riostream.h>
41 #include <TClonesArray.h>
42 #include <TGeoMatrix.h>
45 #include "AliESDEvent.h"
46 #include "AliESDtrack.h"
47 #include "AliESDCaloCluster.h"
48 #include "AliEMCALRecPoint.h"
49 #include "AliRunLoader.h"
50 #include "AliEMCALTrack.h"
51 #include "AliEMCALLoader.h"
52 #include "AliEMCALGeometry.h"
53 #include "AliEMCALReconstructor.h"
54 #include "AliEMCALRecParam.h"
55 #include "AliCDBEntry.h"
56 #include "AliCDBManager.h"
57 #include "AliEMCALReconstructor.h"
58 #include "AliEMCALRecoUtils.h"
60 #include "AliEMCALTracker.h"
62 ClassImp(AliEMCALTracker)
65 //------------------------------------------------------------------------------
67 AliEMCALTracker::AliEMCALTracker()
73 fTrackCorrMode(kTrackCorrMMB),
82 // Default constructor.
83 // Initializes all simple data members to default values,
84 // and all collections to NULL.
85 // Output file name is set to a default value.
90 //------------------------------------------------------------------------------
92 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
95 fCutNITS(copy.fCutNITS),
96 fCutNTPC(copy.fCutNTPC),
98 fTrackCorrMode(copy.fTrackCorrMode),
99 fClusterWindow(copy.fClusterWindow),
100 fCutEta(copy.fCutEta),
101 fCutPhi(copy.fCutPhi),
102 fTracks((TObjArray*)copy.fTracks->Clone()),
103 fClusters((TObjArray*)copy.fClusters->Clone()),
108 // Besides copying all parameters, duplicates all collections.
112 //------------------------------------------------------------------------------
114 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
117 // Assignment operator.
118 // Besides copying all parameters, duplicates all collections.
121 fCutPt = copy.fCutPt;
122 fClusterWindow = copy.fClusterWindow;
123 fCutEta = copy.fCutEta;
124 fCutPhi = copy.fCutPhi;
126 fTrackCorrMode = copy.fTrackCorrMode;
128 fCutNITS = copy.fCutNITS;
129 fCutNTPC = copy.fCutNTPC;
131 fTracks = (TObjArray*)copy.fTracks->Clone();
132 fClusters = (TObjArray*)copy.fClusters->Clone();
138 //------------------------------------------------------------------------------
140 void AliEMCALTracker::InitParameters()
143 // Retrieve initialization parameters
146 // Check if the instance of AliEMCALRecParam exists,
147 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
150 AliFatal("Reconstruction parameters for EMCAL not set!");
154 fCutEta = recParam->GetMthCutEta();
155 fCutPhi = recParam->GetMthCutPhi();
156 fStep = recParam->GetExtrapolateStep();
157 fCutPt = recParam->GetTrkCutPt();
158 fCutNITS = recParam->GetTrkCutNITS();
159 fCutNTPC = recParam->GetTrkCutNTPC();
165 //------------------------------------------------------------------------------
167 void AliEMCALTracker::Clear(Option_t* option)
171 // Deletes all objects in arrays and the arrays themselves
175 Bool_t clearTracks = opt.Contains("TRACKS");
176 Bool_t clearClusters = opt.Contains("CLUSTERS");
177 if (opt.Contains("ALL")) {
179 clearClusters = kTRUE;
182 //fTracks is a collection of esdTrack
183 //When clearing this array, the linked objects should not be deleted
184 if (fTracks != 0x0 && clearTracks) {
189 if (fClusters != 0x0 && clearClusters) {
196 //------------------------------------------------------------------------------
198 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
201 // Load EMCAL clusters in the form of AliEMCALRecPoint,
202 // from simulation temporary files.
203 // (When included in reconstruction chain, this method is used automatically)
208 cTree->SetBranchStatus("*",0); //disable all branches
209 cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
211 TBranch *branch = cTree->GetBranch("EMCALECARP");
213 AliError("Can't get the branch with the EMCAL clusters");
217 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
218 branch->SetAddress(&clusters);
220 //cTree->GetEvent(0);
222 Int_t nClusters = (Int_t)clusters->GetEntries();
223 if(fClusters) fClusters->Delete();
224 else fClusters = new TObjArray(0);
225 for (Int_t i = 0; i < nClusters; i++) {
226 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
227 if (!cluster) continue;
228 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
229 fClusters->AddLast(matchCluster);
232 branch->SetAddress(0);
236 AliInfo(Form("Collected %d RecPoints from Tree", fClusters->GetEntries()));
241 //------------------------------------------------------------------------------
243 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
246 // Load EMCAL clusters in the form of AliESDCaloClusters,
247 // from an AliESD object.
250 // make sure that tracks/clusters collections are empty
252 fClusters = new TObjArray(0);
254 Int_t nClusters = esd->GetNumberOfCaloClusters();
255 for (Int_t i=0; i<nClusters; i++)
257 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
258 if (!cluster || !cluster->IsEMCAL()) continue ;
259 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
260 fClusters->AddLast(matchCluster);
263 AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
267 //------------------------------------------------------------------------------
269 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
276 fTracks = new TObjArray(0);
278 Int_t nTracks = esd->GetNumberOfTracks();
279 //Bool_t isKink=kFALSE;
280 for (Int_t i = 0; i < nTracks; i++)
282 AliESDtrack *esdTrack = esd->GetTrack(i);
283 // set by default the value corresponding to "no match"
284 esdTrack->SetEMCALcluster(kUnmatched);
285 esdTrack->ResetStatus(AliESDtrack::kEMCALmatch);
287 //Select good quaulity tracks
288 if(esdTrack->Pt()<fCutPt) continue;
289 if(esdTrack->GetNcls(1)<fCutNTPC)continue;
291 //Loose geometric cut
292 Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
293 if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
295 fTracks->AddLast(esdTrack);
298 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
302 //------------------------------------------------------------------------------
304 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
307 // Set track correction mode
308 // gest the choice in string format and converts into
315 if (!opt.CompareTo("NONE"))
317 fTrackCorrMode = kTrackCorrNone;
319 else if (!opt.CompareTo("MMB"))
321 fTrackCorrMode = kTrackCorrMMB;
325 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
329 //------------------------------------------------------------------------------
331 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
334 // Main operation method.
335 // Gets external AliESD containing tracks to be matched.
336 // After executing match finding, stores in the same ESD object all infos
337 // and releases the object for further reconstruction steps.
340 // Note: should always return 0=OK, because otherwise all tracking
341 // is aborted for this event
344 AliError("NULL ESD passed");
348 // step 1: collect clusters
349 Int_t okLoadClusters, nClusters;
350 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
351 okLoadClusters = LoadClusters(esd);
353 nClusters = fClusters->GetEntries();
355 // step 2: collect ESD tracks
356 Int_t nTracks, okLoadTracks;
357 okLoadTracks = LoadTracks(esd);
358 nTracks = fTracks->GetEntries();
360 // step 3: for each track, find the closest cluster as matched within residual cuts
362 for (Int_t it = 0; it < nTracks; it++)
364 AliESDtrack *track = (AliESDtrack*)fTracks->At(it);
365 index = FindMatchedCluster(track);
368 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(index);
369 track->SetEMCALcluster(cluster->Index());
370 track->SetStatus(AliESDtrack::kEMCALmatch);
378 //------------------------------------------------------------------------------
380 Int_t AliEMCALTracker::FindMatchedCluster(AliESDtrack *track)
383 // For each track, extrapolate it to all the clusters
384 // Find the closest one as matched if the residuals (dEta, dPhi) satisfy the cuts
387 Float_t maxEta=fCutEta;
388 Float_t maxPhi=fCutPhi;
391 // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
392 // Otherwise use the TPCInner point
393 AliExternalTrackParam *trkParam = 0;
394 const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
395 if(friendTrack && friendTrack->GetTPCOut())
396 trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
398 trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
399 if(!trkParam) return index;
402 AliExternalTrackParam trkParamTmp(*trkParam);
404 if(!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&trkParamTmp, 430., track->GetMass(), fStep, eta, phi)) return index;
405 if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad()) return index;
407 //Perform extrapolation
409 trkParamTmp.GetXYZ(trkPos);
410 Int_t nclusters = fClusters->GetEntries();
411 for(Int_t ic=0; ic<nclusters; ic++)
413 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
414 Float_t clsPos[3] = {cluster->X(),cluster->Y(),cluster->Z()};
415 Double_t dR = TMath::Sqrt(TMath::Power(trkPos[0]-clsPos[0],2)+TMath::Power(trkPos[1]-clsPos[1],2)+TMath::Power(trkPos[2]-clsPos[2],2));
416 if(dR > fClusterWindow) continue;
418 AliExternalTrackParam trkParTmp(trkParamTmp);
420 Float_t tmpEta, tmpPhi;
421 if(!AliEMCALRecoUtils::ExtrapolateTrackToPosition(&trkParTmp, clsPos,track->GetMass(), 5, tmpEta, tmpPhi)) continue;
422 if(TMath::Abs(tmpPhi)<TMath::Abs(maxPhi) && TMath::Abs(tmpEta)<TMath::Abs(maxEta))
433 //------------------------------------------------------------------------------
435 void AliEMCALTracker::UnloadClusters()
438 // Free memory from all arrays
439 // This method is called after the local tracking step
440 // so we can safely delete everything
447 //------------------------------------------------------------------------------
449 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
456 // Translates an AliEMCALRecPoint object into the internal format.
457 // Index of passed cluster in its native array must be specified.
460 recPoint->GetGlobalPosition(clpos);
467 //------------------------------------------------------------------------------
469 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
476 // Translates an AliESDCaloCluster object into the internal format.
477 // Index of passed cluster in its native array must be specified.
479 Float_t clpos[3]= {0., 0., 0.};
480 caloCluster->GetPosition(clpos);
482 fX = (Double_t)clpos[0];
483 fY = (Double_t)clpos[1];
484 fZ = (Double_t)clpos[2];