AliPhysics  f05a842 (f05a842)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalAodTrackFilterTask.cxx
Go to the documentation of this file.
1 //
2 // Class to filter Aod tracks
3 //
4 // Author: C.Loizides
5 
7 #include <TClonesArray.h>
8 #include <TRandom3.h>
9 #include <AliAODEvent.h>
10 #include <AliAODTrack.h>
11 #include <AliAnalysisManager.h>
12 #include <AliEMCALRecoUtils.h>
13 #include <AliLog.h>
14 
16 
17 //________________________________________________________________________
20  fTracksOutName("PicoTracks"),
21  fTracksInName("tracks"),
22  fIncludeNoITS(kTRUE),
23  fCutMaxFrShTPCClus(0),
24  fUseNegativeLabels(kTRUE),
25  fIsMC(kFALSE),
26  fDoPropagation(kFALSE),
27  fAttemptProp(kFALSE),
28  fAttemptPropMatch(kFALSE),
29  fKeepInvMassTag(kFALSE),
30  fDist(440),
31  fTrackEfficiency(0),
32  fTracksIn(0),
33  fTracksOut(0)
34 {
35  // Constructor.
36 
37  fAODfilterBits[0] = -1;
38  fAODfilterBits[1] = -1;
39 }
40 
41 //________________________________________________________________________
43  AliAnalysisTaskSE(name),
44  fTracksOutName("PicoTracks"),
45  fTracksInName("tracks"),
46  fIncludeNoITS(kTRUE),
47  fCutMaxFrShTPCClus(0),
48  fUseNegativeLabels(kTRUE),
49  fIsMC(kFALSE),
50  fDoPropagation(kFALSE),
51  fAttemptProp(kFALSE),
52  fAttemptPropMatch(kFALSE),
53  fKeepInvMassTag(kFALSE),
54  fDist(440),
55  fTrackEfficiency(0),
56  fTracksIn(0),
57  fTracksOut(0)
58 {
59  // Constructor.
60 
61  fAODfilterBits[0] = -1;
62  fAODfilterBits[1] = -1;
63  fBranchNames = "AOD:tracks";
64 }
65 
66 //________________________________________________________________________
68 {
69  // Destructor.
70 }
71 
72 //________________________________________________________________________
74 {
75  // Create my user objects.
76 
77  fTracksOut = new TClonesArray("AliAODTrack");
78  fTracksOut->SetName(fTracksOutName);
79 }
80 
81 //________________________________________________________________________
83 {
84  // Main loop, called for each event.
85 
86  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
87  if (!am) {
88  AliError("Manager zero, returning");
89  return;
90  }
91 
92  // retrieve tracks from input.
93  if (!fTracksIn) {
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 
105  // add tracks to event if not yet there
106  fTracksOut->Delete();
107  if (!(InputEvent()->FindListObject(fTracksOutName))) {
108  InputEvent()->AddObject(fTracksOut);
109  }
110 
111  // loop over tracks
112  const Int_t Ntracks = fTracksIn->GetEntriesFast();
113  for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
114 
115  AliAODTrack *track = static_cast<AliAODTrack*>(fTracksIn->At(iTracks));
116 
117  if (!track)
118  continue;
119  Int_t type = -1;
120  if (fAODfilterBits[0] < 0) {
121  if (track->IsHybridGlobalConstrainedGlobal())
122  type = 3;
123  else /*not a good track*/
124  continue;
125  } else {
126  if (track->TestFilterBit(fAODfilterBits[0])) {
127  type = 0;
128  } else if (fAODfilterBits[1]>-1 && track->TestFilterBit(fAODfilterBits[1])) {
129  if ((track->GetStatus()&AliVTrack::kITSrefit)==0) {
130  if (fIncludeNoITS)
131  type = 2;
132  else
133  continue;
134  } else {
135  type = 1;
136  }
137  }
138  else {/*not a good track*/
139  continue;
140  }
141  }
142 
143  if (fCutMaxFrShTPCClus > 0) {
144  Double_t frac = Double_t(track->GetTPCnclsS()) / Double_t(track->GetTPCncls());
145  if (frac > fCutMaxFrShTPCClus) {
146  continue;
147  }
148  }
149 
150  if (fTrackEfficiency) {
151  Double_t r = gRandom->Rndm();
152  if (fTrackEfficiency->Eval(track->Pt()) < r)
153  continue;
154  }
155 
156  AliAODTrack *newt = new ((*fTracksOut)[nacc]) AliAODTrack(*track);
157  newt->SetUniqueID(0);
158  newt->ResetBit(TObject::kHasUUID);
159  newt->ResetBit(TObject::kIsReferenced);
160 
161  Bool_t propthistrack = kFALSE;
162  if (fDoPropagation)
163  propthistrack = kTRUE;
164  else if (!newt->IsExtrapolatedToEMCAL()) {
165  if (fAttemptProp)
166  propthistrack = kTRUE;
167  else if (fAttemptPropMatch && newt->IsEMCAL())
168  propthistrack = kTRUE;
169  }
170  if (propthistrack)
171  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(newt,fDist);
172 
173  Int_t label = 0;
174  if (fIsMC) {
175  if (fUseNegativeLabels)
176  label = track->GetLabel();
177  else
178  label = TMath::Abs(track->GetLabel());
179  if (label == 0)
180  AliDebug(2,Form("Track %d with label==0", iTracks));
181  }
182  if(fKeepInvMassTag && !fIsMC && (track->GetLabel() == 1011000 ||
183  track->GetLabel() == 1012000 ||
184  track->GetLabel() == 1021000 ||
185  track->GetLabel() == 1022000 ||
186  track->GetLabel() == 1031000 ||
187  track->GetLabel() == 1032000)){
188  newt->SetLabel(track->GetLabel());
189  }
190  else
191  newt->SetLabel(label);
192  if (type==0) {
193  newt->SetBit(BIT(22),0);
194  newt->SetBit(BIT(23),0);
195  } else if (type==1) {
196  newt->SetBit(BIT(22),1);
197  newt->SetBit(BIT(23),0);
198  } else if (type==2) {
199  newt->SetBit(BIT(22),0);
200  newt->SetBit(BIT(23),1);
201  } else if (type==3) {
202  newt->SetBit(BIT(22),1);
203  newt->SetBit(BIT(23),1);
204  }
205  ++nacc;
206  }
207 }
double Double_t
Definition: External.C:58
TRandom * gRandom
TClonesArray * fTracksOut
track array in
int Int_t
Definition: External.C:63
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
ClassImp(AliEmcalAodTrackFilterTask) AliEmcalAodTrackFilterTask