AliPhysics  vAN-20150924 (e816f45)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEmcalPicoTrackMaker.cxx
Go to the documentation of this file.
1 // $Id$
2 //
3 // Class to make PicoTracks in AOD/ESD events.
4 //
5 // Author: S.Aiola, C.Loizides
6 
7 #include <TClonesArray.h>
8 #include <TRandom3.h>
9 #include "AliAODEvent.h"
10 #include "AliAODTrack.h"
11 #include "AliAnalysisManager.h"
12 #include "AliESDtrack.h"
13 #include "AliESDtrackCuts.h"
14 #include "AliEmcalPicoTrackMaker.h"
15 #include "AliLog.h"
16 #include "AliPicoTrack.h"
17 #include "AliVTrack.h"
18 #include "AliAODMCParticle.h"
19 #include "AliNamedArrayI.h"
20 
22 
23 //________________________________________________________________________
25  AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
26  fTracksOutName("PicoTracks"),
27  fTracksInName("tracks"),
28  fMCParticlesName("mcparticles"),
29  fMinTrackPt(0),
30  fMaxTrackPt(1000),
31  fMinTrackEta(-10),
32  fMaxTrackEta(10),
33  fMinTrackPhi(-10),
34  fMaxTrackPhi(10),
35  fTrackEfficiency(1),
36  fCopyMCFlag(kFALSE),
37  fTracksIn(0),
38  fTracksOut(0),
39  fMCParticles(0),
40  fMCParticlesMap(0),
41  fInit(kFALSE)
42 {
43  // Constructor.
44 
45  fAODfilterBits[0] = -1;
46  fAODfilterBits[1] = -1;
47 }
48 
49 //________________________________________________________________________
51  AliAnalysisTaskSE(name),
52  fTracksOutName("PicoTracks"),
53  fTracksInName("tracks"),
54  fMCParticlesName("mcparticles"),
55  fMinTrackPt(0),
56  fMaxTrackPt(1000),
57  fMinTrackEta(-10),
58  fMaxTrackEta(10),
59  fMinTrackPhi(-10),
60  fMaxTrackPhi(10),
61  fTrackEfficiency(1),
62  fCopyMCFlag(kFALSE),
63  fTracksIn(0),
64  fTracksOut(0),
65  fMCParticles(0),
66  fMCParticlesMap(0),
67  fInit(kFALSE)
68 {
69  // Constructor.
70 
71  fAODfilterBits[0] = -1;
72  fAODfilterBits[1] = -1;
73  fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
74 }
75 
76 //________________________________________________________________________
78 {
79  // Destructor.
80 }
81 
82 //________________________________________________________________________
84 {
85  // Create my user objects.
86 }
87 
88 //________________________________________________________________________
90 {
91  // Main loop, called for each event.
92 
93  if (!fInit) {
94  fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
95  if (!fTracksIn) {
96  AliError(Form("Could not retrieve tracks %s!", fTracksInName.Data()));
97  return;
98  }
99  if (!fTracksIn->GetClass()->GetBaseClass("AliVParticle")) {
100  AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTracksInName.Data()));
101  return;
102  }
103 
104  fTracksOut = new TClonesArray("AliPicoTrack");
105  fTracksOut->SetName(fTracksOutName);
106 
107  // add tracks to event if not yet there
108  if (InputEvent()->FindListObject(fTracksOutName)) {
109  AliFatal(Form("Object %s already present in the event!",fTracksOutName.Data()));
110  }
111  else {
112  InputEvent()->AddObject(fTracksOut);
113  }
114 
115  if (fCopyMCFlag) {
116  fMCParticles = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fMCParticlesName));
117  if (!fMCParticles) {
118  AliError(Form("Could not retrieve MC particles %s!", fMCParticlesName.Data()));
119  }
120  if (!fMCParticles->GetClass()->GetBaseClass("AliVParticle")) {
121  AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fMCParticlesName.Data()));
122  fMCParticles = 0;
123  }
124 
125  TString mapName(fMCParticlesName);
126  mapName += "_Map";
127  fMCParticlesMap = dynamic_cast<AliNamedArrayI*>(InputEvent()->FindListObject(mapName));
128  }
129 
130  fInit = kTRUE;
131  }
132 
133  fTracksOut->Delete();
134 
135  // loop over tracks
136  const Int_t Ntracks = fTracksIn->GetEntriesFast();
137  for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
138 
139  AliVTrack *track = static_cast<AliVTrack*>(fTracksIn->At(iTracks));
140 
141  if (!track)
142  continue;
143 
144  if (track->Pt() > fMaxTrackPt || track->Pt() < fMinTrackPt)
145  continue;
146 
147  if (track->Eta() < fMinTrackEta || track->Eta() > fMaxTrackEta ||
148  track->Phi() < fMinTrackPhi || track->Phi() > fMaxTrackPhi)
149  continue;
150 
151  if (fTrackEfficiency < 1) {
152  Double_t r = gRandom->Rndm();
153  if (fTrackEfficiency < r)
154  continue;
155  }
156 
157  Bool_t isEmc = kFALSE;
158  if (TMath::Abs(track->GetTrackEtaOnEMCal()) < 0.75 &&
159  track->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
160  track->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
161  isEmc = kTRUE;
162 
163  AliPicoTrack *picotrack = new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(),
164  track->Eta(),
165  track->Phi(),
166  track->Charge(),
167  track->GetLabel(),
169  track->GetTrackEtaOnEMCal(),
170  track->GetTrackPhiOnEMCal(),
171  track->GetTrackPtOnEMCal(),
172  isEmc);
173  picotrack->SetTrack(track);
174 
175  if (fCopyMCFlag && track->GetLabel() != 0) {
176  AliVParticle *mcpart = GetMCParticle(TMath::Abs(track->GetLabel()));
177  if (mcpart) {
178  UInt_t mcFlag = mcpart->GetFlag();
179  picotrack->SetFlag(mcFlag);
180  Short_t genIndex = mcpart->GetGeneratorIndex();
181  picotrack->SetGeneratorIndex(genIndex);
182  }
183  }
184 
185  ++nacc;
186  }
187 }
188 
189 //________________________________________________________________________
190 AliVParticle* AliEmcalPicoTrackMaker::GetMCParticle(Int_t label)
191 {
192  if (!fMCParticles) return 0;
193  Int_t index = label;
194  if (fMCParticlesMap) index = fMCParticlesMap->At(label);
195  if (index < 0 || index >= fMCParticles->GetEntriesFast()) return 0;
196  AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index));
197  return part;
198 }
AliNamedArrayI * fMCParticlesMap
MC particle array.
TRandom * gRandom
Byte_t GetTrackType() const
Definition: AliPicoTrack.h:42
void SetTrack(AliVTrack *t)
Definition: AliPicoTrack.h:60
AliVParticle * GetMCParticle(Int_t label)
void SetFlag(UInt_t flag)
Definition: AliPicoTrack.h:69
TClonesArray * fTracksOut
track array in
void UserExec(Option_t *option)
TClonesArray * fMCParticles
track array out
Bool_t fInit
MC particle map.
ClassImp(AliEmcalPicoTrackMaker) AliEmcalPicoTrackMaker
void SetGeneratorIndex(Short_t i)
Definition: AliPicoTrack.h:96