AliPhysics  879ce3b (879ce3b)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
AliTrackContainer.cxx
Go to the documentation of this file.
1 //
2 // Container with name, TClonesArray and cuts for particles
3 //
4 // Author: M. Verweij, S. Aiola
5 
6 #include <TClonesArray.h>
7 
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10 #include "AliVCuts.h"
11 #include "AliESDtrack.h"
12 
13 #include "AliTLorentzVector.h"
16 #include "AliTrackContainer.h"
17 
19 
20 TString AliTrackContainer::fgDefTrackCutsPeriod = "";
21 
22 //________________________________________________________________________
25  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
26  fListOfCuts(0),
27  fSelectionModeAny(kFALSE),
28  fAODFilterBits(0),
29  fTrackCutsPeriod(),
30  fEmcalTrackSelection(0),
31  fFilteredTracks(0),
32  fTrackTypes(5000)
33 {
34  // Default constructor.
35 
36  fClassName = "AliVTrack";
37  fMassHypothesis = 0.139;
38 }
39 
40 //________________________________________________________________________
41 AliTrackContainer::AliTrackContainer(const char *name, const char *period):
43  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
44  fListOfCuts(0),
45  fSelectionModeAny(kFALSE),
46  fAODFilterBits(0),
47  fTrackCutsPeriod(period),
48  fEmcalTrackSelection(0),
49  fFilteredTracks(0),
50  fTrackTypes(5000)
51 {
52  // Standard constructor.
53 
54  fClassName = "AliVTrack";
55 
57  AliInfo(Form("Default track cuts period is %s", AliTrackContainer::fgDefTrackCutsPeriod.Data()));
59  }
60  fMassHypothesis = 0.139;
61 }
62 
63 //________________________________________________________________________
64 void AliTrackContainer::SetArray(AliVEvent *event)
65 {
66  // Get array from event.
67 
69 
73  }
74  else {
76 
77  AliInfo("Using custom track cuts");
78 
79  if (fLoadedClass) {
80  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
81  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
83  }
84  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
85  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
87  }
88  else {
89  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
90  }
91  }
92 
94  if (fSelectionModeAny) {
96  }
97  else {
99  }
100 
102  }
103  }
104  else {
105  if (!fTrackCutsPeriod.IsNull()) {
106  AliInfo(Form("Using track cuts %d for period %s", fTrackFilterType, fTrackCutsPeriod.Data()));
107  }
108  else {
109  AliInfo(Form("Using track cuts %d (no data period was provided!)", fTrackFilterType));
110  }
111 
112  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
113  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
115  }
116  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
117  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
119  }
120  else {
121  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
122  }
123  }
124  }
125 }
126 
127 //________________________________________________________________________
129 {
130  fTrackTypes.Reset(kUndefined);
131  if (fEmcalTrackSelection) {
133 
134  const TClonesArray* trackBitmaps = fEmcalTrackSelection->GetAcceptedTrackBitmaps();
135  TIter nextBitmap(trackBitmaps);
136  TBits* bits = 0;
137  Int_t i = 0;
138  while ((bits = static_cast<TBits*>(nextBitmap()))) {
139  if (i >= fTrackTypes.GetSize()) fTrackTypes.Set((i+1)*2);
140  AliVTrack* vTrack = static_cast<AliVTrack*>(fFilteredTracks->At(i));
141  if (!vTrack) {
142  fTrackTypes[i] = kRejected;
143  }
145  if (bits->FirstSetBit() == 0) {
147  }
148  else if (bits->FirstSetBit() == 1) {
149  if ((vTrack->GetStatus()&AliVTrack::kITSrefit) != 0) {
151  }
152  else {
154  }
155  }
156  }
157  i++;
158  }
159  }
160  else {
162  }
163 }
164 
165 //________________________________________________________________________
166 AliVTrack* AliTrackContainer::GetTrack(Int_t i) const
167 {
168  //Get i^th jet in array
169 
170  if (i == -1) i = fCurrentID;
171  if (i < 0 || i >= fFilteredTracks->GetEntriesFast()) return 0;
172  AliVTrack *vp = static_cast<AliVTrack*>(fFilteredTracks->At(i));
173  return vp;
174 }
175 
176 //________________________________________________________________________
178 {
179  //return pointer to particle if particle is accepted
180 
181  if (i == -1) i = fCurrentID;
182  if (AcceptTrack(i)) {
183  return GetTrack(i);
184  }
185  else {
186  AliDebug(2,"Track not accepted.");
187  return 0;
188  }
189 }
190 
191 //________________________________________________________________________
193 {
194  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
195 
196  if (i >= 0) fCurrentID = i;
197 
198  const Int_t n = GetNEntries();
199 
200  AliVTrack *p = 0;
201  do {
202  fCurrentID++;
203  if (fCurrentID >= n) break;
205  } while (!p);
206 
207  return p;
208 }
209 
210 //________________________________________________________________________
212 {
213  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
214 
215  if (i >= 0) fCurrentID = i;
216 
217  const Int_t n = GetNEntries();
218  AliVTrack *p = 0;
219  do {
220  fCurrentID++;
221  if (fCurrentID >= n) break;
222  p = GetTrack(fCurrentID);
223  } while (!p);
224 
225  return p;
226 }
227 
228 //________________________________________________________________________
229 Bool_t AliTrackContainer::GetMomentum(TLorentzVector &mom, const AliVTrack* part, Double_t mass)
230 {
231  if (part) {
232  if (mass < 0) mass = part->M();
233  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
234  return kTRUE;
235  }
236  else {
237  mom.SetPtEtaPhiM(0, 0, 0, 0);
238  return kFALSE;
239  }
240 }
241 
242 //________________________________________________________________________
243 Bool_t AliTrackContainer::GetMomentum(TLorentzVector &mom, const AliVTrack* part)
244 {
245  return GetMomentum(mom,part,fMassHypothesis);
246 }
247 
248 //________________________________________________________________________
249 Bool_t AliTrackContainer::GetMomentum(TLorentzVector &mom, Int_t i)
250 {
251  //Get momentum of the i^th particle in array
252 
253  Double_t mass = fMassHypothesis;
254 
255  if (i == -1) i = fCurrentID;
256  AliVTrack *vp = GetTrack(i);
257  if (vp) {
258  if (mass < 0) mass = vp->M();
259 
260  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
261  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
262  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
263  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
264  }
265  else {
266  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
267  }
268  return kTRUE;
269  }
270  else {
271  mom.SetPtEtaPhiM(0, 0, 0, 0);
272  return kFALSE;
273  }
274 }
275 
276 //________________________________________________________________________
277 Bool_t AliTrackContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
278 {
279  //Get momentum of the i^th particle in array
280 
281  Double_t mass = fMassHypothesis;
282 
283  AliVTrack *vp = GetNextTrack(i);
284  if (vp) {
285  if (mass < 0) mass = vp->M();
286 
287  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
289  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
290  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
291  }
292  else {
293  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
294  }
295  return kTRUE;
296  }
297  else {
298  mom.SetPtEtaPhiM(0, 0, 0, 0);
299  return kFALSE;
300  }
301 }
302 
303 //________________________________________________________________________
304 Bool_t AliTrackContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
305 {
306  //Get momentum of the i^th particle in array
307 
308  Double_t mass = fMassHypothesis;
309 
310  if (i == -1) i = fCurrentID;
311  AliVTrack *vp = GetAcceptTrack(i);
312  if (vp) {
313  if (mass < 0) mass = vp->M();
314 
315  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
316  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
317  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
318  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
319  }
320  else {
321  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
322  }
323 
324  return kTRUE;
325  }
326  else {
327  mom.SetPtEtaPhiM(0, 0, 0, 0);
328  return kFALSE;
329  }
330 }
331 
332 //________________________________________________________________________
333 Bool_t AliTrackContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
334 {
335  //Get momentum of the i^th particle in array
336 
337  Double_t mass = fMassHypothesis;
338 
339  AliVTrack *vp = GetNextAcceptTrack(i);
340  if (vp) {
341  if (mass < 0) mass = vp->M();
342 
343  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
345  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
346  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
347  }
348  else {
349  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
350  }
351 
352  return kTRUE;
353  }
354  else {
355  mom.SetPtEtaPhiM(0, 0, 0, 0);
356  return kFALSE;
357  }
358 }
359 
360 //________________________________________________________________________
361 Bool_t AliTrackContainer::AcceptTrack(const AliVTrack *vp)
362 {
363  // Return true if vp is accepted.
364  Bool_t r = ApplyTrackCuts(vp);
365  if (!r) return kFALSE;
366 
367  AliTLorentzVector mom;
368 
369  Int_t id = fFilteredTracks->IndexOf(vp);
370  if (id >= 0) {
371  GetMomentum(mom, id);
372  }
373  else {
374  GetMomentum(mom, vp);
375  }
376 
377  return ApplyKinematicCuts(mom);
378 }
379 
380 //________________________________________________________________________
382 {
383  // Return true if vp is accepted.
384  Bool_t r = ApplyTrackCuts(GetTrack(i));
385  if (!r) return kFALSE;
386 
387  AliTLorentzVector mom;
388  GetMomentum(mom, i);
389 
390  return ApplyKinematicCuts(mom);
391 }
392 
393 //________________________________________________________________________
394 Bool_t AliTrackContainer::ApplyTrackCuts(const AliVTrack* vp)
395 {
396  // Return true if i^th particle is accepted.
397 
398  return ApplyParticleCuts(vp);
399 }
400 
401 //________________________________________________________________________
402 void AliTrackContainer::SetClassName(const char *clname)
403 {
404  // Set the class name
405 
406  TClass cls(clname);
407  if (cls.InheritsFrom("AliVTrack")) fClassName = clname;
408  else AliError(Form("Unable to set class name %s for a AliTrackContainer, it must inherits from AliVTrack!",clname));
409 }
410 
411 //________________________________________________________________________
413 {
414  if (!fListOfCuts) {
415  fListOfCuts = new TObjArray;
416  fListOfCuts->SetOwner(true);
417  }
418  fListOfCuts->Add(cuts);
419 }
420 
421 //________________________________________________________________________
423 {
424  if (!fListOfCuts) return 0;
425  return fListOfCuts->GetEntries();
426 }
427 
428 //________________________________________________________________________
429 AliVCuts* AliTrackContainer::GetTrackCuts(Int_t icut)
430 {
431  if (!fListOfCuts) return NULL;
432  if (icut < fListOfCuts->GetEntries()) {
433  return static_cast<AliVCuts *>(fListOfCuts->At(icut));
434  }
435  return NULL;
436 }
437 
438 //________________________________________________________________________
439 const char* AliTrackContainer::GetTitle() const
440 {
441  static TString trackString;
442 
443  if (GetMinPt() == 0) {
444  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
445  }
446  else if (GetMinPt() < 1.0) {
447  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
448  }
449  else {
450  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
451  }
452 
453  return trackString.Data();
454 }
Interface for virtual track selection.
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom, Int_t i=-1)
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
TObjArray * fFilteredTracks
track selection object
void SetClassName(const char *clname)
virtual Bool_t ApplyTrackCuts(const AliVTrack *vp)
static TString fgDefTrackCutsPeriod
Double_t mass
virtual Bool_t AcceptTrack(const AliVTrack *vp)
virtual Bool_t GetNextMomentum(TLorentzVector &mom, Int_t i=-1)
virtual void SetArray(AliVEvent *event)
const TClonesArray * GetAcceptedTrackBitmaps() const
Implement virtual track selection for AOD analysis.
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp)
virtual AliVTrack * GetNextAcceptTrack(Int_t i=-1)
AliVCuts * GetTrackCuts(Int_t icut)
AliEmcalTrackSelection * fEmcalTrackSelection
TClass * fLoadedClass
reject reason bit map for the last call to an accept object function
ETrackFilterType_t fTrackFilterType
default period string used to generate track cuts
void SetArray(AliVEvent *event)
Declaration of class AliEmcalTrackSelectionESD.
Double_t GetMinPt() const
Int_t GetNumberOfCutObjects() const
TArrayC fTrackTypes
tracks filtered using fEmcalTrackSelection
TObjArray * fListOfCuts
void AddTrackCuts(AliVCuts *cuts)
Implement virtual track selection for AOD analysis.
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
const TString & GetArrayName() const
virtual AliVTrack * GetTrack(Int_t i=-1) const
TObjArray * GetAcceptedTracks(const TClonesArray *const tracks)
virtual Bool_t GetMomentum(TLorentzVector &mom, const AliVTrack *part, Double_t mass)
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i)
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
void AddTrackCuts(AliVCuts *cuts)
const char * GetTitle() const
virtual AliVTrack * GetAcceptTrack(Int_t i=-1)
TClonesArray * fClArray
Int_t GetNEntries() const
Int_t fCurrentID
TClonesArray.
Implementation of virtual track selection for ESDs.
virtual AliVTrack * GetNextTrack(Int_t i=-1)