AliRoot Core  edcc906 (edcc906)
AliEMCALTracker.cxx
Go to the documentation of this file.
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 #include <Riostream.h>
17 #include <iomanip>
18 
19 #include <TFile.h>
20 #include <TTree.h>
21 #include <TList.h>
22 #include <TString.h>
23 #include <TVector3.h>
24 #include <TClonesArray.h>
25 #include <TGeoMatrix.h>
26 
27 #include "AliLog.h"
28 #include "AliESDEvent.h"
29 #include "AliESDtrack.h"
30 #include "AliESDCaloCluster.h"
31 #include "AliEMCALRecPoint.h"
32 #include "AliRunLoader.h"
33 #include "AliEMCALTrack.h"
34 #include "AliEMCALLoader.h"
35 #include "AliEMCALGeometry.h"
36 #include "AliEMCALReconstructor.h"
37 #include "AliEMCALRecParam.h"
38 #include "AliCDBEntry.h"
39 #include "AliCDBManager.h"
40 #include "AliEMCALReconstructor.h"
41 #include "AliEMCALRecoUtilsBase.h"
42 
43 #include "AliEMCALTracker.h"
44 
46 ClassImp(AliEMCALTracker) ;
48 
55 //------------------------------------------------------------------------------
57  AliTracker(),
58  fCutPt(0),
59  fCutNITS(0),
60  fCutNTPC(50),
61  fStep(20),
62  fTrackCorrMode(kTrackCorrMMB),
63  fEMCalSurfaceDistance(440),
64  fClusterWindow(50),
65  fCutEta(0.025),
66  fCutPhi(0.05),
67  fITSTrackSA(kFALSE),
68  fTrackInITS(kFALSE),
69  fTracks(0),
70  fClusters(0),
71  fGeom(0)
72 {
74 }
75 
80 //------------------------------------------------------------------------------
82  AliTracker(),
83  fCutPt(copy.fCutPt),
84  fCutNITS(copy.fCutNITS),
85  fCutNTPC(copy.fCutNTPC),
86  fStep(copy.fStep),
90  fCutEta(copy.fCutEta),
91  fCutPhi(copy.fCutPhi),
92  fITSTrackSA(copy.fITSTrackSA),
93  fTrackInITS(copy.fTrackInITS),
94  fTracks((TObjArray*)copy.fTracks->Clone()),
95  fClusters((TObjArray*)copy.fClusters->Clone()),
96  fGeom(copy.fGeom)
97 {
98 }
99 
103 //------------------------------------------------------------------------------
105 {
106  if (&source == this) return *this;
107 
108  new (this) AliEMCALTracker(source);
109  return *this;
110 }
111 
115 //------------------------------------------------------------------------------
117 {
118  // Check if the instance of AliEMCALRecParam exists,
120 
121  if (!recParam)
122  {
123  AliFatal("Reconstruction parameters for EMCAL not set!");
124  return; // not needed, but for coverity.
125  }
126 
127  fCutEta = recParam->GetMthCutEta();
128  fCutPhi = recParam->GetMthCutPhi();
129  fStep = recParam->GetExtrapolateStep();
130  fCutPt = recParam->GetTrkCutPt();
131  fCutNITS = recParam->GetTrkCutNITS(); // Not used?
132  fCutNTPC = recParam->GetTrkCutNTPC();
133  fTrackInITS = recParam->GetTrkInITS();
134 }
135 
140 //------------------------------------------------------------------------------
141 void AliEMCALTracker::Clear(Option_t* option)
142 {
143  TString opt(option);
144  Bool_t clearTracks = opt.Contains("TRACKS");
145  Bool_t clearClusters = opt.Contains("CLUSTERS");
146  if (opt.Contains("ALL"))
147  {
148  clearTracks = kTRUE;
149  clearClusters = kTRUE;
150  }
151 
152  // fTracks is a collection of esdTrack
153  // When clearing this array, the linked objects should not be deleted
154  if (fTracks != 0x0 && clearTracks)
155  {
156  fTracks->Clear();
157  delete fTracks;
158  fTracks = 0;
159  }
160 
161  if (fClusters != 0x0 && clearClusters)
162  {
163  fClusters->Delete();
164  delete fClusters;
165  fClusters = 0;
166  }
167 }
168 
174 //------------------------------------------------------------------------------
175 Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
176 {
177  Clear("CLUSTERS");
178 
179  cTree->SetBranchStatus("*",0); //disable all branches
180  cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
181 
182  TBranch *branch = cTree->GetBranch("EMCALECARP");
183  if (!branch)
184  {
185  AliError("Can't get the branch with the EMCAL clusters");
186  return 1;
187  }
188 
189  TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
190  branch->SetAddress(&clusters);
191 
192  //cTree->GetEvent(0);
193  branch->GetEntry(0);
194 
195  Int_t nClusters = (Int_t)clusters->GetEntries();
196  if (fClusters) fClusters->Delete();
197  else fClusters = new TObjArray(0);
198 
199  for (Int_t i = 0; i < nClusters; i++)
200  {
201  AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
202  if (!cluster) continue;
203 
204  AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
205  fClusters->AddLast(matchCluster);
206  }
207 
208  branch->SetAddress(0);
209  clusters->Delete();
210  delete clusters;
211 
212  AliDebug(1,Form("Collected %d RecPoints from Tree", fClusters->GetEntries()));
213 
214  return 0;
215 }
216 
220 //
221 //------------------------------------------------------------------------------
223 {
224  // make sure that tracks/clusters collections are empty
225  Clear("CLUSTERS");
226  fClusters = new TObjArray(0);
227 
228  Int_t nClusters = esd->GetNumberOfCaloClusters();
229  for (Int_t i=0; i<nClusters; i++)
230  {
231  AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
232  if (!cluster || !cluster->IsEMCAL()) continue ;
233 
234  AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
235  fClusters->AddLast(matchCluster);
236  }
237 
238  AliDebug(1,Form("Collected %d clusters from ESD", fClusters->GetEntries()));
239  return 0;
240 }
241 
249 //------------------------------------------------------------------------------
251 {
252  // In case of runs without TPC but ITS on,
253  // do matching with different cuts
254  UInt_t mask1 = esd->GetESDRun()->GetDetectorsInDAQ();
255  UInt_t mask2 = esd->GetESDRun()->GetDetectorsInReco();
256  Bool_t desc1 = (mask1 >> 3) & 0x1;
257  Bool_t desc2 = (mask2 >> 3) & 0x1;
258 
259  if (desc1==0 || desc2==0)
260  {
261  // AliError(Form("TPC not in DAQ/RECO: %u (%u)/%u (%u)",
262  // mask1, esd->GetESDRun()->GetDetectorsInReco(),
263  // mask2, esd->GetESDRun()->GetDetectorsInDAQ()));
264  fITSTrackSA = kTRUE;
265  }
266 
267  Clear("TRACKS");
268  fTracks = new TObjArray(0);
269 
270  Int_t nTracks = esd->GetNumberOfTracks();
271  //printf("N tracks %d\n",nTracks);
272 
273  for (Int_t i = 0; i < nTracks; i++)
274  {
275  AliESDtrack *esdTrack = esd->GetTrack(i);
276 
277  // Set by default the value corresponding to "no match"
278  esdTrack->SetEMCALcluster(kUnmatched);
280 
281  //
282  // Select tracks depending on status bit
283  // and number of clusters.
284  //
285  if ( esdTrack->Pt() < fCutPt ) continue;
286 
287  // When there are TPC tracks, select them depeding on the fit bit
288  // Take TPCout and if requested ITSout (default)
289  if ( !fITSTrackSA )
290  {
291  Int_t nClustersITS = esdTrack->GetITSclusters(0);
292  Int_t nClustersTPC = esdTrack->GetTPCclusters(0);
293 
294  ULong_t status = esdTrack->GetStatus();
295 
296  //Bool_t tpcIn = (status&AliESDtrack::kTPCin )==AliESDtrack::kTPCin ;
297  //Bool_t itsIn = (status&AliESDtrack::kITSin )==AliESDtrack::kITSin ;
298  Bool_t tpcOut = (status&AliESDtrack::kTPCout)==AliESDtrack::kTPCout;
299  Bool_t itsOut = (status&AliESDtrack::kITSout)==AliESDtrack::kITSout;
300 
301  // Check ITSout bit, if requested
302  if ( fTrackInITS )
303  {
304  // if(nClustersITS > 0) // fCutNITS?
305  // printf("ITS clusters %d, Cut %2.0f, kITSin? %d, kITSout? %d - select %d\n",
306  // nClustersITS,fCutNITS,itsIn,itsOut,fTrackInITS);
307 
308  if ( !itsOut || nClustersITS <= 0 ) continue; // fCutNITS
309  }
310 
311  // if(nClustersTPC > 0)
312  // printf("TPC clusters %d, Cut %2.0f, kTPCin? %d; kTPCout? %d\n",
313  // nClustersTPC,fCutNTPC,tpcIn,tpcOut);
314 
315  if ( !tpcOut || nClustersTPC < fCutNTPC ) continue;
316 
317  } // Do not match with ITS SA track
318 
319  //printf("\t accepted!\n");
320 
321  //
322  // Loose geometric cut
323  //
324  if ( TMath::Abs(esdTrack->Eta()) > 0.9 ) continue;
325 
326  // Save some time and memory in case of no DCal present
327 
328  if(fGeom->GetNumberOfSuperModules() < 13)
329  {
330  Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
331  if ( phi <= 10 || phi >= 250 ) continue;
332  }
333 
334  fTracks->AddLast(esdTrack);
335  }
336 
337  AliDebug(1,Form("Collected %d tracks", fTracks->GetEntries()));
338  return 0;
339 }
340 
346 //------------------------------------------------------------------------------
348 {
349  TString opt(option);
350  opt.ToUpper();
351 
352  if ( !opt.CompareTo("NONE") )
354  else if ( !opt.CompareTo("MMB") )
356  else
357  AliError("Unrecognized option");
358 }
359 
368 //------------------------------------------------------------------------------
370 {
371  if (!esd)
372  {
373  AliError("NULL ESD passed");
374  return 1;
375  }
376 
378 
379  // step 1: collect clusters
380  Int_t okLoadClusters = 0;
381  if (!fClusters || (fClusters && fClusters->IsEmpty()))
382  okLoadClusters = LoadClusters(esd);
383 
384  Int_t nClusters = fClusters->GetEntries();
385 
386  // step 2: collect ESD tracks
387  Int_t nTracks, okLoadTracks;
388  okLoadTracks = LoadTracks(esd);
389  nTracks = fTracks->GetEntries();
390 
391  AliDebug(5,Form("Propagate back %d tracks ok %d, for %d clusters ok %d",
392  nTracks,okLoadTracks,nClusters,okLoadClusters));
393 
394  // step 3: for each track, find the closest cluster as matched within residual cuts
395  Int_t index=-1;
396  for (Int_t it = 0; it < nTracks; it++)
397  {
398  AliESDtrack *track = (AliESDtrack*)fTracks->At(it);
399  index = FindMatchedCluster(track);
400  if (index>-1)
401  {
402  AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(index);
403  track->SetEMCALcluster(cluster->Index());
405  }
406  }
407 
408  return 0;
409 }
410 
415 //------------------------------------------------------------------------------
417 {
418  Float_t maxEta=fCutEta;
419  Float_t maxPhi=fCutPhi;
420  Int_t index = -1;
421 
422  // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
423  // Otherwise use the TPCInner point
424  AliExternalTrackParam *trkParam = 0;
425 
426  if (!fITSTrackSA)
427  {
428  const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
429 
430  if (friendTrack && friendTrack->GetTPCOut())
431  trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
432  else if (track->GetInnerParam())
433  trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
434  }
435  else
436  trkParam = new AliExternalTrackParam(*track);
437 
438  if (!trkParam) return index;
439 
440  AliExternalTrackParam trkParamTmp(*trkParam);
441  Float_t eta, phi, pt;
442  if (!AliEMCALRecoUtilsBase::ExtrapolateTrackToEMCalSurface(&trkParamTmp, fEMCalSurfaceDistance, track->GetMass(kTRUE), fStep, eta, phi, pt))
443  {
444  if (fITSTrackSA) delete trkParam;
445  return index;
446  }
447 
448  track->SetTrackPhiEtaPtOnEMCal(phi,eta,pt);
449 
450  if ( TMath::Abs(eta) > 0.75 )
451  {
452  if (fITSTrackSA) delete trkParam;
453  return index;
454  }
455 
456  // Save some time and memory in case of no DCal present
457  if ( fGeom->GetNumberOfSuperModules() < 13 &&
458  ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad()))
459  {
460  if (fITSTrackSA) delete trkParam;
461  return index;
462  }
463 
464  //Perform extrapolation
465  Double_t trkPos[3];
466  trkParamTmp.GetXYZ(trkPos);
467  Int_t nclusters = fClusters->GetEntries();
468  for (Int_t ic=0; ic<nclusters; ic++)
469  {
471 
472  Float_t clsPos[3] = {static_cast<Float_t>(cluster->X()),
473  static_cast<Float_t>(cluster->Y()),
474  static_cast<Float_t>(cluster->Z())};
475 
476  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));
477  //printf("\n dR=%f,wind=%f\n",dR,fClusterWindow); //MARCEL
478 
479  if (dR > fClusterWindow) continue;
480 
481  AliExternalTrackParam trkParTmp(trkParamTmp);
482 
483  Float_t tmpEta, tmpPhi;
484  if (!AliEMCALRecoUtilsBase::ExtrapolateTrackToPosition(&trkParTmp, clsPos,track->GetMass(kTRUE), 5, tmpEta, tmpPhi)) continue;
485 
486  if (TMath::Abs(tmpPhi)<TMath::Abs(maxPhi) && TMath::Abs(tmpEta)<TMath::Abs(maxEta))
487  {
488  maxPhi=tmpPhi;
489  maxEta=tmpEta;
490  index=ic;
491  }
492  }
493 
494  if (fITSTrackSA) delete trkParam;
495 
496  return index;
497 }
498 
504 //------------------------------------------------------------------------------
506 {
507  Clear();
508 }
509 
514 //------------------------------------------------------------------------------
516  fIndex(index),
517  fX(0.),
518  fY(0.),
519  fZ(0.)
520 {
521  TVector3 clpos;
522  recPoint->GetGlobalPosition(clpos);
523 
524  fX = clpos.X();
525  fY = clpos.Y();
526  fZ = clpos.Z();
527 }
528 
533 //------------------------------------------------------------------------------
535  fIndex(index),
536  fX(0.),
537  fY(0.),
538  fZ(0.)
539 {
540  Float_t clpos[3]= {0., 0., 0.};
541  caloCluster->GetPosition(clpos);
542 
543  fX = (Double_t)clpos[0];
544  fY = (Double_t)clpos[1];
545  fZ = (Double_t)clpos[2];
546 }
AliESDCaloCluster * GetCaloCluster(Int_t i) const
Definition: AliESDEvent.h:500
void SetStatus(ULong_t flags)
Definition: AliESDtrack.h:72
Bool_t fTrackInITS
Requiere ITS refit with AliVTrack::kITSout.
Double_t fCutNITS
Minimum number of track hits in the ITS.
UShort_t GetTPCclusters(Int_t *idx) const
const AliExternalTrackParam * GetInnerParam() const
Definition: AliESDtrack.h:132
Float_t fEMCalSurfaceDistance
EMCal surface distance.
ULong_t GetStatus() const
Definition: AliESDtrack.h:82
Double_t fX
Global X position.
#define TObjArray
Bool_t GetXYZ(Double_t *p) const
Double_t fCutPhi
cut on phi difference
static const AliEMCALRecParam * GetRecParam()
Use MeanMaterialBudget() function to evaluate correction.
Float_t fStep
Length of each step in propagation.
Steer EMCal-Track matching.
void SetTrackPhiEtaPtOnEMCal(Double_t phi, Double_t eta, Double_t pt)
Definition: AliESDtrack.h:416
virtual Int_t LoadClusters(TTree *)
UInt_t GetDetectorsInDAQ() const
Definition: AliESDRun.h:82
Bool_t fITSTrackSA
If no TPC, use ITS Tracks.
Double_t fZ
Global Z position.
void ResetStatus(ULong_t flags)
Definition: AliESDtrack.h:73
Double_t fCutNTPC
Minimum number of track hits in the TPC.
Do not correct for energy loss.
Int_t GetNumberOfSuperModules(void) const
Double_t fY
Global Y position.
AliTPCfastTrack * track
ETrackCorr fTrackCorrMode
Material budget correction mode.
Container of reconstruction parameters.
Double_t GetExtrapolateStep() const
Char_t GetITSclusters(Int_t *idx) const
Double_t GetMthCutPhi() const
AliEMCALTracker & operator=(const AliEMCALTracker &source)
TObjArray * fTracks
! Collection of tracks
virtual void Clear(Option_t *option="ALL")
Double_t fCutEta
cut on eta difference
TObjArray * fClusters
! Collection of EMCAL clusters (ESDCaloCluster or EMCALRecPoint)
const AliExternalTrackParam * GetTPCOut() const
Int_t fIndex
Index of cluster in its native container (ESD or TClonesArray)
virtual void UnloadClusters()
EMCal rec_points object.
Double_t GetMthCutEta() const
static Bool_t ExtrapolateTrackToPosition(AliExternalTrackParam *trkParam, const Float_t *clsPos, Double_t mass, Double_t step, Float_t &tmpEta, Float_t &tmpPhi)
Double_t GetMass(Bool_t tpcOnly=kFALSE) const
Definition: AliESDtrack.h:98
Calorimeter cluster data container.
#define AliFatal(message)
Definition: AliLog.h:640
Bool_t IsEMCAL() const
void SetEMCALcluster(Int_t index)
Definition: AliESDtrack.h:409
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
virtual void GetGlobalPosition(TVector3 &gpos) const
AliEMCALMatchCluster(Int_t ID, AliEMCALRecPoint *recPoint)
Bool_t GetTrkInITS() const
Double_t GetTrkCutNITS() const
Int_t FindMatchedCluster(AliESDtrack *track)
Int_t GetNumberOfTracks() const
Definition: AliESDEvent.h:536
AliESDtrack * GetTrack(Int_t i) const
Definition: AliESDEvent.h:405
virtual Int_t PropagateBack(AliESDEvent *esd)
UInt_t GetDetectorsInReco() const
Definition: AliESDRun.h:83
const AliESDRun * GetESDRun() const
Definition: AliESDEvent.h:135
const AliESDfriendTrack * GetFriendTrack() const
Definition: AliESDtrack.h:59
Int_t LoadTracks(AliESDEvent *esd)
static Bool_t ExtrapolateTrackToEMCalSurface(AliVTrack *track, Double_t emcalR=440, Double_t mass=0.1396, Double_t step=20, Double_t minpT=0.35, Bool_t useMassForTracking=kFALSE, Bool_t useDCA=kFALSE)
Double_t GetTrkCutPt() const
Int_t GetNumberOfCaloClusters() const
Definition: AliESDEvent.h:557
#define AliError(message)
Definition: AliLog.h:591
static AliEMCALGeometry * GetInstance()
AliEMCALGeometry * fGeom
! EMCAL geometry
Double_t fCutPt
Minimum pT cut on tracks.
void GetPosition(Float_t *x) const
Double_t GetTrkCutNTPC() const
void SetTrackCorrectionMode(Option_t *option)
Double_t fClusterWindow
Select clusters in the window to be matched to tracks.