AliPhysics  vAN-20150630 (513c479)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
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 //________________________________________________________________________
19  AliAnalysisTaskSE("AliEmcalAodTrackFilterTask"),
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  fDist(440),
30  fTrackEfficiency(0),
31  fTracksIn(0),
32  fTracksOut(0)
33 {
34  // Constructor.
35 
36  fAODfilterBits[0] = -1;
37  fAODfilterBits[1] = -1;
38 }
39 
40 //________________________________________________________________________
42  AliAnalysisTaskSE(name),
43  fTracksOutName("PicoTracks"),
44  fTracksInName("tracks"),
45  fIncludeNoITS(kTRUE),
46  fCutMaxFrShTPCClus(0),
47  fUseNegativeLabels(kTRUE),
48  fIsMC(kFALSE),
49  fDoPropagation(kFALSE),
50  fAttemptProp(kFALSE),
51  fAttemptPropMatch(kFALSE),
52  fDist(440),
53  fTrackEfficiency(0),
54  fTracksIn(0),
55  fTracksOut(0)
56 {
57  // Constructor.
58 
59  fAODfilterBits[0] = -1;
60  fAODfilterBits[1] = -1;
61  fBranchNames = "AOD:tracks";
62 }
63 
64 //________________________________________________________________________
66 {
67  // Destructor.
68 }
69 
70 //________________________________________________________________________
72 {
73  // Create my user objects.
74 
75  fTracksOut = new TClonesArray("AliAODTrack");
76  fTracksOut->SetName(fTracksOutName);
77 }
78 
79 //________________________________________________________________________
81 {
82  // Main loop, called for each event.
83 
84  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
85  if (!am) {
86  AliError("Manager zero, returning");
87  return;
88  }
89 
90  // retrieve tracks from input.
91  if (!fTracksIn) {
92  fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
93  if (!fTracksIn) {
94  AliError(Form("Could not retrieve tracks %s!", fTracksInName.Data()));
95  return;
96  }
97  if (!fTracksIn->GetClass()->GetBaseClass("AliVParticle")) {
98  AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTracksInName.Data()));
99  return;
100  }
101  }
102 
103  // add tracks to event if not yet there
104  fTracksOut->Delete();
105  if (!(InputEvent()->FindListObject(fTracksOutName))) {
106  InputEvent()->AddObject(fTracksOut);
107  }
108 
109  // loop over tracks
110  const Int_t Ntracks = fTracksIn->GetEntriesFast();
111  for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
112 
113  AliAODTrack *track = static_cast<AliAODTrack*>(fTracksIn->At(iTracks));
114 
115  if (!track)
116  continue;
117  Int_t type = -1;
118  if (fAODfilterBits[0] < 0) {
119  if (track->IsHybridGlobalConstrainedGlobal())
120  type = 3;
121  else /*not a good track*/
122  continue;
123  } else {
124  if (track->TestFilterBit(fAODfilterBits[0])) {
125  type = 0;
126  } else if (fAODfilterBits[1]>-1 && track->TestFilterBit(fAODfilterBits[1])) {
127  if ((track->GetStatus()&AliVTrack::kITSrefit)==0) {
128  if (fIncludeNoITS)
129  type = 2;
130  else
131  continue;
132  } else {
133  type = 1;
134  }
135  }
136  else {/*not a good track*/
137  continue;
138  }
139  }
140 
141  if (fCutMaxFrShTPCClus > 0) {
142  Double_t frac = Double_t(track->GetTPCnclsS()) / Double_t(track->GetTPCncls());
143  if (frac > fCutMaxFrShTPCClus) {
144  continue;
145  }
146  }
147 
148  if (fTrackEfficiency) {
149  Double_t r = gRandom->Rndm();
150  if (fTrackEfficiency->Eval(track->Pt()) < r)
151  continue;
152  }
153 
154  AliAODTrack *newt = new ((*fTracksOut)[nacc]) AliAODTrack(*track);
155  newt->SetUniqueID(0);
156  newt->ResetBit(TObject::kHasUUID);
157  newt->ResetBit(TObject::kIsReferenced);
158 
159  Bool_t propthistrack = kFALSE;
160  if (fDoPropagation)
161  propthistrack = kTRUE;
162  else if (!newt->IsExtrapolatedToEMCAL()) {
163  if (fAttemptProp)
164  propthistrack = kTRUE;
165  else if (fAttemptPropMatch && newt->IsEMCAL())
166  propthistrack = kTRUE;
167  }
168  if (propthistrack)
169  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(newt,fDist);
170 
171  Int_t label = 0;
172  if (fIsMC) {
173  if (fUseNegativeLabels)
174  label = track->GetLabel();
175  else
176  label = TMath::Abs(track->GetLabel());
177  if (label == 0)
178  AliDebug(2,Form("Track %d with label==0", iTracks));
179  }
180  newt->SetLabel(label);
181  if (type==0) {
182  newt->SetBit(BIT(22),0);
183  newt->SetBit(BIT(23),0);
184  } else if (type==1) {
185  newt->SetBit(BIT(22),1);
186  newt->SetBit(BIT(23),0);
187  } else if (type==2) {
188  newt->SetBit(BIT(22),0);
189  newt->SetBit(BIT(23),1);
190  } else if (type==3) {
191  newt->SetBit(BIT(22),1);
192  newt->SetBit(BIT(23),1);
193  }
194  ++nacc;
195  }
196 }
TClonesArray * fTracksOut
track array in
ClassImp(AliEmcalAodTrackFilterTask) AliEmcalAodTrackFilterTask