#95494: Change AliLog message in AliAltroRawStreamV3.cxx (additional reduction of...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTracker.cxx
CommitLineData
fe17d4cb 1//========================================================================
2// Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
3//
4// Author: The ALICE Off-line Project.
5// Contributors are mentioned in the code where appropriate.
6//
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//========================================================================
15//
16// Class AliEMCALTracker
17// -----------------------
18// Implementation of the track matching method between barrel tracks and
19// EMCAL clusters.
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().
27//
28// ------------------------------------------------------------------------
29// author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
5970dfe2 30// Revised by Rongrong 2010-05-31 (rongrong.ma@cern.ch)
fe17d4cb 31//=========================================================================
32
33#include <Riostream.h>
34#include <iomanip>
35
36#include <TFile.h>
37#include <TTree.h>
fe17d4cb 38#include <TList.h>
39#include <TString.h>
40#include <TVector3.h>
41#include <TClonesArray.h>
c61f0e70 42#include <TGeoMatrix.h>
fe17d4cb 43
44#include "AliLog.h"
af885e0f 45#include "AliESDEvent.h"
fe17d4cb 46#include "AliESDtrack.h"
89ffc0b0 47#include "AliESDCaloCluster.h"
fe17d4cb 48#include "AliEMCALRecPoint.h"
49#include "AliRunLoader.h"
50#include "AliEMCALTrack.h"
51#include "AliEMCALLoader.h"
c61f0e70 52#include "AliEMCALGeometry.h"
8ba062b1 53#include "AliEMCALReconstructor.h"
54#include "AliEMCALRecParam.h"
55#include "AliCDBEntry.h"
56#include "AliCDBManager.h"
3e3faf55 57#include "AliEMCALReconstructor.h"
ee602376 58#include "AliEMCALRecoUtils.h"
c61f0e70 59
fe17d4cb 60#include "AliEMCALTracker.h"
61
0267cfa6 62using std::cerr;
63using std::endl;
fe17d4cb 64ClassImp(AliEMCALTracker)
8ba062b1 65
fe17d4cb 66//
67//------------------------------------------------------------------------------
68//
69AliEMCALTracker::AliEMCALTracker()
8fc351e3 70: AliTracker(),
71 fCutPt(0),
72 fCutNITS(0),
73 fCutNTPC(50),
da34fafe 74 fStep(20),
8fc351e3 75 fTrackCorrMode(kTrackCorrMMB),
76 fClusterWindow(50),
77 fCutEta(0.025),
78 fCutPhi(0.05),
79 fTracks(0),
80 fClusters(0),
81 fGeom(0)
fe17d4cb 82{
5970dfe2 83 //
84 // Default constructor.
85 // Initializes all simple data members to default values,
86 // and all collections to NULL.
87 // Output file name is set to a default value.
88 //
0832a2bf 89 InitParameters();
fe17d4cb 90}
91//
92//------------------------------------------------------------------------------
93//
94AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
95 : AliTracker(),
5970dfe2 96 fCutPt(copy.fCutPt),
dcd86c5d 97 fCutNITS(copy.fCutNITS),
98 fCutNTPC(copy.fCutNTPC),
5970dfe2 99 fStep(copy.fStep),
100 fTrackCorrMode(copy.fTrackCorrMode),
8fc351e3 101 fClusterWindow(copy.fClusterWindow),
5970dfe2 102 fCutEta(copy.fCutEta),
103 fCutPhi(copy.fCutPhi),
fe17d4cb 104 fTracks((TObjArray*)copy.fTracks->Clone()),
105 fClusters((TObjArray*)copy.fClusters->Clone()),
c61f0e70 106 fGeom(copy.fGeom)
fe17d4cb 107{
5970dfe2 108 //
109 // Copy constructor
110 // Besides copying all parameters, duplicates all collections.
111 //
fe17d4cb 112}
113//
114//------------------------------------------------------------------------------
115//
f1d9131f 116AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& source)
117{ // assignment operator; use copy ctor
118 if (&source == this) return *this;
5970dfe2 119
f1d9131f 120 new (this) AliEMCALTracker(source);
121 return *this;
fe17d4cb 122}
123//
124//------------------------------------------------------------------------------
125//
8ba062b1 126void AliEMCALTracker::InitParameters()
127{
5970dfe2 128 //
129 // Retrieve initialization parameters
130 //
8ba062b1 131
132 // Check if the instance of AliEMCALRecParam exists,
3e3faf55 133 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
3a2a23e1 134
ba6de5ea 135 if(!recParam){
136 AliFatal("Reconstruction parameters for EMCAL not set!");
8ba062b1 137 }
41f05b8c 138 else{
5970dfe2 139
140 fCutEta = recParam->GetMthCutEta();
141 fCutPhi = recParam->GetMthCutPhi();
8fc351e3 142 fStep = recParam->GetExtrapolateStep();
5970dfe2 143 fCutPt = recParam->GetTrkCutPt();
8fc351e3 144 fCutNITS = recParam->GetTrkCutNITS();
145 fCutNTPC = recParam->GetTrkCutNTPC();
41f05b8c 146 }
3e3faf55 147
8ba062b1 148}
5970dfe2 149
c61f0e70 150//
151//------------------------------------------------------------------------------
152//
fe17d4cb 153void AliEMCALTracker::Clear(Option_t* option)
154{
155 //
156 // Clearing method
044225d9 157 // Deletes all objects in arrays and the arrays themselves
fe17d4cb 158 //
159
160 TString opt(option);
161 Bool_t clearTracks = opt.Contains("TRACKS");
162 Bool_t clearClusters = opt.Contains("CLUSTERS");
fe17d4cb 163 if (opt.Contains("ALL")) {
164 clearTracks = kTRUE;
165 clearClusters = kTRUE;
fe17d4cb 166 }
167
5970dfe2 168 //fTracks is a collection of esdTrack
169 //When clearing this array, the linked objects should not be deleted
fe17d4cb 170 if (fTracks != 0x0 && clearTracks) {
5970dfe2 171 fTracks->Clear();
044225d9 172 delete fTracks;
173 fTracks = 0;
fe17d4cb 174 }
175 if (fClusters != 0x0 && clearClusters) {
044225d9 176 fClusters->Delete();
177 delete fClusters;
178 fClusters = 0;
fe17d4cb 179 }
fe17d4cb 180}
181//
182//------------------------------------------------------------------------------
183//
184Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
185{
186 //
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)
190 //
191
192 Clear("CLUSTERS");
193
bce21ea7 194 cTree->SetBranchStatus("*",0); //disable all branches
195 cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
196
fe17d4cb 197 TBranch *branch = cTree->GetBranch("EMCALECARP");
198 if (!branch) {
c61f0e70 199 AliError("Can't get the branch with the EMCAL clusters");
fe17d4cb 200 return 1;
201 }
202
9596d957 203 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
fe17d4cb 204 branch->SetAddress(&clusters);
fe17d4cb 205
bce21ea7 206 //cTree->GetEvent(0);
207 branch->GetEntry(0);
9596d957 208 Int_t nClusters = (Int_t)clusters->GetEntries();
bce21ea7 209 if(fClusters) fClusters->Delete();
210 else fClusters = new TObjArray(0);
fe17d4cb 211 for (Int_t i = 0; i < nClusters; i++) {
212 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
213 if (!cluster) continue;
fe17d4cb 214 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
215 fClusters->AddLast(matchCluster);
216 }
3d9e8b15 217
2ad4424e 218 branch->SetAddress(0);
219 clusters->Delete();
220 delete clusters;
221
5970dfe2 222 AliInfo(Form("Collected %d RecPoints from Tree", fClusters->GetEntries()));
fe17d4cb 223
224 return 0;
225}
226//
227//------------------------------------------------------------------------------
228//
af885e0f 229Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
fe17d4cb 230{
5970dfe2 231 //
232 // Load EMCAL clusters in the form of AliESDCaloClusters,
233 // from an AliESD object.
234 //
235
236 // make sure that tracks/clusters collections are empty
237 Clear("CLUSTERS");
238 fClusters = new TObjArray(0);
239
240 Int_t nClusters = esd->GetNumberOfCaloClusters();
241 for (Int_t i=0; i<nClusters; i++)
242 {
243 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
244 if (!cluster || !cluster->IsEMCAL()) continue ;
245 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
246 fClusters->AddLast(matchCluster);
247 }
248
249 AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
250 return 0;
fe17d4cb 251}
252//
253//------------------------------------------------------------------------------
254//
af885e0f 255Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
fe17d4cb 256{
5970dfe2 257 //
258 // Load ESD tracks.
259 //
fe17d4cb 260
5970dfe2 261 Clear("TRACKS");
262 fTracks = new TObjArray(0);
fe17d4cb 263
5970dfe2 264 Int_t nTracks = esd->GetNumberOfTracks();
8fc351e3 265 //Bool_t isKink=kFALSE;
5970dfe2 266 for (Int_t i = 0; i < nTracks; i++)
267 {
268 AliESDtrack *esdTrack = esd->GetTrack(i);
269 // set by default the value corresponding to "no match"
270 esdTrack->SetEMCALcluster(kUnmatched);
8fc351e3 271 esdTrack->ResetStatus(AliESDtrack::kEMCALmatch);
5970dfe2 272
273 //Select good quaulity tracks
274 if(esdTrack->Pt()<fCutPt) continue;
275 if(esdTrack->GetNcls(1)<fCutNTPC)continue;
276
5970dfe2 277 //Loose geometric cut
278 Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
d874f457 279 if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
5970dfe2 280
281 fTracks->AddLast(esdTrack);
282 }
283
284 AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
285 return 0;
286}
287//
288//------------------------------------------------------------------------------
289//
290void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
291{
292 //
293 // Set track correction mode
294 // gest the choice in string format and converts into
295 // internal enum
296 //
297
298 TString opt(option);
299 opt.ToUpper();
300
301 if (!opt.CompareTo("NONE"))
302 {
303 fTrackCorrMode = kTrackCorrNone;
304 }
305 else if (!opt.CompareTo("MMB"))
306 {
307 fTrackCorrMode = kTrackCorrMMB;
308 }
309 else
310 {
311 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
312 }
fe17d4cb 313}
314//
315//------------------------------------------------------------------------------
316//
af885e0f 317Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
fe17d4cb 318{
319 //
320 // Main operation method.
321 // Gets external AliESD containing tracks to be matched.
322 // After executing match finding, stores in the same ESD object all infos
323 // and releases the object for further reconstruction steps.
324 //
3d9e8b15 325 //
326 // Note: should always return 0=OK, because otherwise all tracking
327 // is aborted for this event
5970dfe2 328
fe17d4cb 329 if (!esd) {
330 AliError("NULL ESD passed");
331 return 1;
332 }
333
5970dfe2 334 // step 1: collect clusters
c61f0e70 335 Int_t okLoadClusters, nClusters;
fe17d4cb 336 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
fe17d4cb 337 okLoadClusters = LoadClusters(esd);
fe17d4cb 338 }
c61f0e70 339 nClusters = fClusters->GetEntries();
5970dfe2 340
341 // step 2: collect ESD tracks
342 Int_t nTracks, okLoadTracks;
343 okLoadTracks = LoadTracks(esd);
c61f0e70 344 nTracks = fTracks->GetEntries();
fe17d4cb 345
5970dfe2 346 // step 3: for each track, find the closest cluster as matched within residual cuts
347 Int_t index=-1;
348 for (Int_t it = 0; it < nTracks; it++)
349 {
350 AliESDtrack *track = (AliESDtrack*)fTracks->At(it);
351 index = FindMatchedCluster(track);
352 if (index>-1)
353 {
354 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(index);
355 track->SetEMCALcluster(cluster->Index());
952d023a 356 track->SetStatus(AliESDtrack::kEMCALmatch);
5970dfe2 357 }
358 }
fe17d4cb 359
360 return 0;
361}
fe17d4cb 362
363//
364//------------------------------------------------------------------------------
365//
5970dfe2 366Int_t AliEMCALTracker::FindMatchedCluster(AliESDtrack *track)
367{
368 //
369 // For each track, extrapolate it to all the clusters
370 // Find the closest one as matched if the residuals (dEta, dPhi) satisfy the cuts
371 //
17773e2e 372
ee602376 373 Float_t maxEta=fCutEta;
374 Float_t maxPhi=fCutPhi;
5970dfe2 375 Int_t index = -1;
376
377 // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
378 // Otherwise use the TPCInner point
8108ab9e 379 AliExternalTrackParam *trkParam = 0;
5970dfe2 380 const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
381 if(friendTrack && friendTrack->GetTPCOut())
382 trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
383 else
384 trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
385 if(!trkParam) return index;
386
8fc351e3 387
388 AliExternalTrackParam trkParamTmp(*trkParam);
ee602376 389 Float_t eta, phi;
da25bc37 390 if(!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&trkParamTmp, 430., track->GetMass(kTRUE), fStep, eta, phi)) return index;
ed15417e 391 track->SetTrackPhiEtaOnEMCal(phi,eta);
8fc351e3 392 if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad()) return index;
393
5970dfe2 394 //Perform extrapolation
395 Double_t trkPos[3];
8fc351e3 396 trkParamTmp.GetXYZ(trkPos);
5970dfe2 397 Int_t nclusters = fClusters->GetEntries();
398 for(Int_t ic=0; ic<nclusters; ic++)
399 {
5970dfe2 400 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
8fc351e3 401 Float_t clsPos[3] = {cluster->X(),cluster->Y(),cluster->Z()};
402 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));
403 if(dR > fClusterWindow) continue;
404
405 AliExternalTrackParam trkParTmp(trkParamTmp);
406
ee602376 407 Float_t tmpEta, tmpPhi;
da25bc37 408 if(!AliEMCALRecoUtils::ExtrapolateTrackToPosition(&trkParTmp, clsPos,track->GetMass(kTRUE), 5, tmpEta, tmpPhi)) continue;
5970dfe2 409 if(TMath::Abs(tmpPhi)<TMath::Abs(maxPhi) && TMath::Abs(tmpEta)<TMath::Abs(maxEta))
410 {
411 maxPhi=tmpPhi;
412 maxEta=tmpEta;
413 index=ic;
414 }
5970dfe2 415 }
416 return index;
fe17d4cb 417}
5970dfe2 418
fe17d4cb 419//
420//------------------------------------------------------------------------------
421//
422void AliEMCALTracker::UnloadClusters()
423{
424 //
044225d9 425 // Free memory from all arrays
426 // This method is called after the local tracking step
427 // so we can safely delete everything
fe17d4cb 428 //
429
044225d9 430 Clear();
fe17d4cb 431}
04475328 432
433//
434//------------------------------------------------------------------------------
435//
fe17d4cb 436AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
437 : fIndex(index),
fe17d4cb 438 fX(0.),
439 fY(0.),
440 fZ(0.)
441{
442 //
443 // Translates an AliEMCALRecPoint object into the internal format.
444 // Index of passed cluster in its native array must be specified.
445 //
446 TVector3 clpos;
447 recPoint->GetGlobalPosition(clpos);
448
449 fX = clpos.X();
450 fY = clpos.Y();
451 fZ = clpos.Z();
452}
453//
454//------------------------------------------------------------------------------
455//
456AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
457 : fIndex(index),
fe17d4cb 458 fX(0.),
459 fY(0.),
460 fZ(0.)
461{
462 //
463 // Translates an AliESDCaloCluster object into the internal format.
464 // Index of passed cluster in its native array must be specified.
465 //
53e430a3 466 Float_t clpos[3]= {0., 0., 0.};
7592dfc4 467 caloCluster->GetPosition(clpos);
fe17d4cb 468
469 fX = (Double_t)clpos[0];
470 fY = (Double_t)clpos[1];
471 fZ = (Double_t)clpos[2];
472}