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"
64 ClassImp(AliEMCALTracker)
67 //------------------------------------------------------------------------------
69 AliEMCALTracker::AliEMCALTracker() :
75 fTrackCorrMode(kTrackCorrMMB),
76 fEMCalSurfaceDistance(440),
86 // Default constructor.
87 // Initializes all 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) :
99 fCutNITS(copy.fCutNITS),
100 fCutNTPC(copy.fCutNTPC),
102 fTrackCorrMode(copy.fTrackCorrMode),
103 fEMCalSurfaceDistance(copy.fEMCalSurfaceDistance),
104 fClusterWindow(copy.fClusterWindow),
105 fCutEta(copy.fCutEta),
106 fCutPhi(copy.fCutPhi),
107 fITSTrackSA(copy.fITSTrackSA),
108 fTracks((TObjArray*)copy.fTracks->Clone()),
109 fClusters((TObjArray*)copy.fClusters->Clone()),
114 // Besides copying all parameters, duplicates all collections.
118 //------------------------------------------------------------------------------
120 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& source)
121 { // assignment operator; use copy ctor
122 if (&source == this) return *this;
124 new (this) AliEMCALTracker(source);
128 //------------------------------------------------------------------------------
130 void AliEMCALTracker::InitParameters()
133 // Retrieve initialization parameters
136 // Check if the instance of AliEMCALRecParam exists,
137 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
140 AliFatal("Reconstruction parameters for EMCAL not set!");
142 fCutEta = recParam->GetMthCutEta();
143 fCutPhi = recParam->GetMthCutPhi();
144 fStep = recParam->GetExtrapolateStep();
145 fCutPt = recParam->GetTrkCutPt();
146 fCutNITS = recParam->GetTrkCutNITS();
147 fCutNTPC = recParam->GetTrkCutNTPC();
151 //------------------------------------------------------------------------------
153 void AliEMCALTracker::Clear(Option_t* option)
157 // Deletes all objects in arrays and the arrays themselves
161 Bool_t clearTracks = opt.Contains("TRACKS");
162 Bool_t clearClusters = opt.Contains("CLUSTERS");
163 if (opt.Contains("ALL")) {
165 clearClusters = kTRUE;
168 //fTracks is a collection of esdTrack
169 //When clearing this array, the linked objects should not be deleted
170 if (fTracks != 0x0 && clearTracks) {
175 if (fClusters != 0x0 && clearClusters) {
182 //------------------------------------------------------------------------------
184 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
187 // Load EMCAL clusters in the form of AliEMCALRecPoint,
188 // from simulation temporary files.
189 // (When included in reconstruction chain, this method is used automatically)
194 cTree->SetBranchStatus("*",0); //disable all branches
195 cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
197 TBranch *branch = cTree->GetBranch("EMCALECARP");
199 AliError("Can't get the branch with the EMCAL clusters");
203 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
204 branch->SetAddress(&clusters);
206 //cTree->GetEvent(0);
208 Int_t nClusters = (Int_t)clusters->GetEntries();
209 if (fClusters) fClusters->Delete();
210 else fClusters = new TObjArray(0);
211 for (Int_t i = 0; i < nClusters; i++) {
212 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
213 if (!cluster) continue;
214 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
215 fClusters->AddLast(matchCluster);
218 branch->SetAddress(0);
222 AliDebug(1,Form("Collected %d RecPoints from Tree", fClusters->GetEntries()));
227 //------------------------------------------------------------------------------
229 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
232 // Load EMCAL clusters in the form of AliESDCaloClusters,
233 // from an AliESD object.
236 // make sure that tracks/clusters collections are empty
238 fClusters = new TObjArray(0);
240 Int_t nClusters = esd->GetNumberOfCaloClusters();
241 for (Int_t i=0; i<nClusters; i++) {
242 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
243 if (!cluster || !cluster->IsEMCAL()) continue ;
244 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
245 fClusters->AddLast(matchCluster);
248 AliDebug(1,Form("Collected %d clusters from ESD", fClusters->GetEntries()));
252 //------------------------------------------------------------------------------
254 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
260 UInt_t mask1 = esd->GetESDRun()->GetDetectorsInDAQ();
261 UInt_t mask2 = esd->GetESDRun()->GetDetectorsInReco();
262 Bool_t desc1 = (mask1 >> 3) & 0x1;
263 Bool_t desc2 = (mask2 >> 3) & 0x1;
264 if (desc1==0 || desc2==0) {
265 // AliError(Form("TPC not in DAQ/RECO: %u (%u)/%u (%u)",
266 // mask1, esd->GetESDRun()->GetDetectorsInReco(),
267 // mask2, esd->GetESDRun()->GetDetectorsInDAQ()));
272 fTracks = new TObjArray(0);
274 Int_t nTracks = esd->GetNumberOfTracks();
275 //Bool_t isKink=kFALSE;
276 for (Int_t i = 0; i < nTracks; i++) {
277 AliESDtrack *esdTrack = esd->GetTrack(i);
278 // set by default the value corresponding to "no match"
279 esdTrack->SetEMCALcluster(kUnmatched);
280 esdTrack->ResetStatus(AliESDtrack::kEMCALmatch);
282 //Select good quaulity tracks
283 if (esdTrack->Pt()<fCutPt) continue;
285 if (esdTrack->GetNcls(1)<fCutNTPC) continue;
287 //Loose geometric cut
288 Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
289 if (TMath::Abs(esdTrack->Eta())>0.9 || phi <= 10 || phi >= 250) continue;
290 fTracks->AddLast(esdTrack);
293 AliDebug(1,Form("Collected %d tracks", fTracks->GetEntries()));
297 //------------------------------------------------------------------------------
299 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
302 // Set track correction mode
303 // gest the choice in string format and converts into
310 if (!opt.CompareTo("NONE")) {
311 fTrackCorrMode = kTrackCorrNone;
312 } else if (!opt.CompareTo("MMB")) {
313 fTrackCorrMode = kTrackCorrMMB;
315 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
319 //------------------------------------------------------------------------------
321 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
324 // Main operation method.
325 // Gets external AliESD containing tracks to be matched.
326 // After executing match finding, stores in the same ESD object all infos
327 // and releases the object for further reconstruction steps.
330 // Note: should always return 0=OK, because otherwise all tracking
331 // is aborted for this event
335 AliError("NULL ESD passed");
339 // step 1: collect clusters
340 Int_t okLoadClusters = 0;
341 if (!fClusters || (fClusters && fClusters->IsEmpty()))
342 okLoadClusters = LoadClusters(esd);
344 Int_t nClusters = fClusters->GetEntries();
346 // step 2: collect ESD tracks
347 Int_t nTracks, okLoadTracks;
348 okLoadTracks = LoadTracks(esd);
349 nTracks = fTracks->GetEntries();
351 AliDebug(5,Form("Propagate back %d tracks ok %d, for %d clusters ok %d",
352 nTracks,okLoadTracks,nClusters,okLoadClusters));
354 // step 3: for each track, find the closest cluster as matched within residual cuts
356 for (Int_t it = 0; it < nTracks; it++)
358 AliESDtrack *track = (AliESDtrack*)fTracks->At(it);
359 index = FindMatchedCluster(track);
362 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(index);
363 track->SetEMCALcluster(cluster->Index());
364 track->SetStatus(AliESDtrack::kEMCALmatch);
372 //------------------------------------------------------------------------------
374 Int_t AliEMCALTracker::FindMatchedCluster(AliESDtrack *track)
377 // For each track, extrapolate it to all the clusters
378 // Find the closest one as matched if the residuals (dEta, dPhi) satisfy the cuts
381 Float_t maxEta=fCutEta;
382 Float_t maxPhi=fCutPhi;
385 // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
386 // Otherwise use the TPCInner point
387 AliExternalTrackParam *trkParam = 0;
391 const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
393 if (friendTrack && friendTrack->GetTPCOut())
394 trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
395 else if (track->GetInnerParam())
396 trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
399 trkParam = new AliExternalTrackParam(*track);
401 if (!trkParam) return index;
403 AliExternalTrackParam trkParamTmp(*trkParam);
404 Float_t eta, phi, pt;
405 if (!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&trkParamTmp, fEMCalSurfaceDistance, track->GetMass(kTRUE), fStep, eta, phi, pt))
407 if (fITSTrackSA) delete trkParam;
411 track->SetTrackPhiEtaPtOnEMCal(phi,eta,pt);
413 if (TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad())
415 if (fITSTrackSA) delete trkParam;
419 //Perform extrapolation
421 trkParamTmp.GetXYZ(trkPos);
422 Int_t nclusters = fClusters->GetEntries();
423 for (Int_t ic=0; ic<nclusters; ic++)
425 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
427 Float_t clsPos[3] = {static_cast<Float_t>(cluster->X()),
428 static_cast<Float_t>(cluster->Y()),
429 static_cast<Float_t>(cluster->Z())};
431 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));
432 //printf("\n dR=%f,wind=%f\n",dR,fClusterWindow); //MARCEL
434 if (dR > fClusterWindow) continue;
436 AliExternalTrackParam trkParTmp(trkParamTmp);
438 Float_t tmpEta, tmpPhi;
439 if (!AliEMCALRecoUtils::ExtrapolateTrackToPosition(&trkParTmp, clsPos,track->GetMass(kTRUE), 5, tmpEta, tmpPhi)) continue;
441 if (TMath::Abs(tmpPhi)<TMath::Abs(maxPhi) && TMath::Abs(tmpEta)<TMath::Abs(maxEta))
449 if (fITSTrackSA) delete trkParam;
455 //------------------------------------------------------------------------------
457 void AliEMCALTracker::UnloadClusters()
460 // Free memory from all arrays
461 // This method is called after the local tracking step
462 // so we can safely delete everything
469 //------------------------------------------------------------------------------
471 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint) :
478 // Translates an AliEMCALRecPoint object into the internal format.
479 // Index of passed cluster in its native array must be specified.
482 recPoint->GetGlobalPosition(clpos);
489 //------------------------------------------------------------------------------
491 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster) :
498 // Translates an AliESDCaloCluster object into the internal format.
499 // Index of passed cluster in its native array must be specified.
501 Float_t clpos[3]= {0., 0., 0.};
502 caloCluster->GetPosition(clpos);
504 fX = (Double_t)clpos[0];
505 fY = (Double_t)clpos[1];
506 fZ = (Double_t)clpos[2];