]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowTasks/AliFlowTrackCuts.cxx
adds tracklets to flow cuts, fixes for MC analysis + other fixes.
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliFlowTrackCuts.cxx
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 /* $Id$ */ 
17
18 // AliFlowTrackCuts:
19 // ESD track cuts for flow framework 
20 //
21 // origin: Mikolaj Krzewicki (mikolaj.krzewicki@cern.ch)
22 //
23 // This class gurantees consistency of cut methods, trackparameter
24 // selection (global tracks, TPC only, etc..) and parameter mixing
25 // in the flow framework. Transparently handles different input types:
26 // ESD, MC, AOD.
27 // This class works in 2 steps: first the requested track parameters are
28 // constructed (to be set by SetParamType() ), then cuts are applied.
29 // the constructed track can be requested AFTER checking the cuts by
30 // calling GetTrack(), in this case the cut object stays in control,
31 // caller does not have to delete the track.
32 // Additionally caller can request an AliFlowTrack object to be constructed
33 // according the parameter mixing scenario requested by SetParamMix().
34 // AliFlowTrack is made using MakeFlowTrack() method, its an 'object factory'
35 // so caller needs to take care of the freshly created object.
36
37 #include <limits.h>
38 #include <float.h>
39 #include "AliMCEvent.h"
40 #include "AliVParticle.h"
41 #include "AliMCParticle.h"
42 #include "AliESDtrack.h"
43 #include "AliMultiplicity.h"
44 #include "AliAODTrack.h"
45 #include "AliFlowTrack.h"
46 #include "AliFlowTrackCuts.h"
47 #include "AliLog.h"
48
49 ClassImp(AliFlowTrackCuts)
50
51 //-----------------------------------------------------------------------
52 AliFlowTrackCuts::AliFlowTrackCuts():
53   AliFlowTrackSimpleCuts(),
54   fAliESDtrackCuts(new AliESDtrackCuts()),
55   fCutMCprocessType(kFALSE),
56   fMCprocessType(kPNoProcess),
57   fCutMCPID(kFALSE),
58   fMCPID(0),
59   fCutMCisPrimary(kFALSE),
60   fMCisPrimary(kFALSE),
61   fRequireCharge(kFALSE),
62   fFakesAreOK(kTRUE),
63   fParamType(kGlobal),
64   fParamMix(kPure),
65   fCleanupTrack(kFALSE),
66   fTrack(NULL),
67   fTrackPhi(0.),
68   fTrackEta(0.),
69   fTrackWeight(0.),
70   fTrackLabel(INT_MIN),
71   fMCevent(NULL),
72   fMCparticle(NULL)
73 {
74   //constructor 
75 }
76
77 //-----------------------------------------------------------------------
78 AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
79   AliFlowTrackSimpleCuts(someCuts),
80   fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
81   fCutMCprocessType(someCuts.fCutMCprocessType),
82   fMCprocessType(someCuts.fMCprocessType),
83   fCutMCPID(someCuts.fCutMCPID),
84   fMCPID(someCuts.fMCPID),
85   fCutMCisPrimary(someCuts.fCutMCisPrimary),
86   fMCisPrimary(someCuts.fMCisPrimary),
87   fRequireCharge(someCuts.fRequireCharge),
88   fFakesAreOK(someCuts.fFakesAreOK),
89   fParamType(someCuts.fParamType),
90   fParamMix(someCuts.fParamMix),
91   fCleanupTrack(kFALSE),
92   fTrack(NULL),
93   fTrackPhi(someCuts.fTrackPhi),
94   fTrackEta(someCuts.fTrackEta),
95   fTrackWeight(someCuts.fTrackWeight),
96   fTrackLabel(INT_MIN),
97   fMCevent(NULL),
98   fMCparticle(NULL)
99 {
100   //copy constructor
101 }
102
103 //-----------------------------------------------------------------------
104 AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
105 {
106   //assignment
107   AliFlowTrackSimpleCuts::operator=(someCuts);
108   *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
109   fCutMCprocessType=someCuts.fCutMCprocessType;
110   fMCprocessType=someCuts.fMCprocessType;
111   fCutMCPID=someCuts.fCutMCPID;
112   fMCPID=someCuts.fMCPID;
113   fCutMCisPrimary=someCuts.fCutMCisPrimary;
114   fMCisPrimary=someCuts.fMCisPrimary;
115   fRequireCharge=someCuts.fRequireCharge;
116   fFakesAreOK=someCuts.fFakesAreOK;
117   fParamType=someCuts.fParamType;
118   fParamMix=someCuts.fParamMix;
119
120   fCleanupTrack=kFALSE;
121   fTrack=NULL;
122   fTrackPhi=someCuts.fTrackPhi;
123   fTrackPhi=someCuts.fTrackPhi;
124   fTrackWeight=someCuts.fTrackWeight;
125   fTrackLabel=INT_MIN;
126   fMCevent=NULL;
127   fMCparticle=NULL;
128
129   return *this;
130 }
131
132 //-----------------------------------------------------------------------
133 AliFlowTrackCuts::~AliFlowTrackCuts()
134 {
135   //dtor
136   if (fCleanupTrack) delete fTrack;
137   delete fAliESDtrackCuts;
138 }
139
140 //-----------------------------------------------------------------------
141 Bool_t AliFlowTrackCuts::IsSelected(TObject* obj, Int_t id)
142 {
143   //check cuts
144   AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
145   if (vparticle) return PassesCuts(vparticle);
146   AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
147   if (flowtrack) return PassesCuts(flowtrack);
148   AliMultiplicity* tracklets = dynamic_cast<AliMultiplicity*>(obj);
149   if (tracklets) return PassesCuts(tracklets,id);
150   return kFALSE;  //default when passed wrong type of object
151 }
152
153 //-----------------------------------------------------------------------
154 Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
155 {
156   //check cuts on a flowtracksimple
157
158   //clean up from last iteration
159   if (fCleanupTrack) delete fTrack; fTrack = NULL;
160   return AliFlowTrackSimpleCuts::PassesCuts(track);
161 }
162
163 //-----------------------------------------------------------------------
164 Bool_t AliFlowTrackCuts::PassesCuts(AliMultiplicity* tracklet, Int_t id)
165 {
166   //check cuts on a tracklets
167
168   //clean up from last iteration
169   if (fCleanupTrack) delete fTrack; fTrack = NULL;
170   fMCparticle=NULL;
171
172   fTrackPhi = tracklet->GetPhi(id);
173   fTrackEta = tracklet->GetEta(id);
174   fTrackWeight = 1.0;
175   if (fCutEta) {if (  fTrackEta < fEtaMin || fTrackEta >= fEtaMax ) return kFALSE;}
176   if (fCutPhi) {if ( fTrackPhi < fPhiMin || fTrackPhi >= fPhiMax ) return kFALSE;}
177
178   //check MC info if available
179   fTrackLabel = tracklet->GetLabel(id,1); //TODO: this can be improved
180   if (!PassesMCcuts()) return kFALSE;
181   return kTRUE;
182 }
183
184 //-----------------------------------------------------------------------
185 Bool_t AliFlowTrackCuts::PassesMCcuts()
186 {
187   //check the MC info
188   if (!fMCevent) {AliError("no MC info"); return kFALSE;}
189   fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
190   if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
191
192   if (fCutMCisPrimary)
193   {
194     if (IsPhysicalPrimary() != fMCisPrimary) return kFALSE;
195   }
196   if (fCutMCPID)
197   {
198     Int_t pdgCode = fMCparticle->PdgCode();
199     if (fMCPID != pdgCode) return kFALSE;
200   }
201   if ( fCutMCprocessType )
202   {
203     TParticle* particle = fMCparticle->Particle();
204     Int_t processID = particle->GetUniqueID();
205     if (processID != fMCprocessType ) return kFALSE;
206   }
207   return kTRUE;
208 }
209
210 //-----------------------------------------------------------------------
211 Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
212 {
213   //check cuts for an ESD vparticle
214
215   ////////////////////////////////////////////////////////////////
216   //  start by preparing the track parameters to cut on //////////
217   ////////////////////////////////////////////////////////////////
218   //clean up from last iteration
219   if (fCleanupTrack) delete fTrack; fTrack=NULL; 
220
221   //get the label and the mc particle
222   fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
223   if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
224   else fMCparticle=NULL;
225
226   Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
227   AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
228   if (esdTrack)
229     HandleESDtrack(esdTrack);
230   else
231   {
232     HandleVParticle(vparticle);
233     //now check if produced particle is MC
234     isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
235   }
236   ////////////////////////////////////////////////////////////////
237   ////////////////////////////////////////////////////////////////
238
239   //check the common cuts for the current particle (MC,AOD,ESD)
240   if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) return kFALSE;}
241   if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) return kFALSE;}
242   if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) return kFALSE;}
243   if (fRequireCharge) {if (fTrack->Charge() == 0) return kFALSE;}
244   if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) return kFALSE;}
245   if (fCutCharge && isMCparticle)
246   { 
247     //in case of an MC particle the charge is stored in units of 1/3|e| 
248     Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
249     return (charge==fCharge);
250   }
251   //if(fCutPID) {if (fTrack->PID() != fPID) return kFALSE;}
252
253   //when additionally MC info is required
254   if (!PassesMCcuts()) return kFALSE;
255
256   //check all else for ESDs using aliesdtrackcuts
257   if (esdTrack && (fParamType!=kMC) ) return fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack));
258
259   return kTRUE; //true by default, if we didn't set any cuts
260 }
261
262 //-----------------------------------------------------------------------
263 void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
264 {
265   //handle the general case
266   switch (fParamType)
267   {
268     default:
269       fCleanupTrack = kFALSE;
270       fTrack = track;
271   }
272 }
273
274 //-----------------------------------------------------------------------
275 void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
276 {
277   //handle esd track
278   switch (fParamType)
279   {
280     case kGlobal:
281       fTrack = track;
282       fCleanupTrack = kFALSE;
283       break;
284     case kESD_TPConly:
285       fTrack = new AliESDtrack();
286       track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
287       fCleanupTrack = kTRUE;
288       //recalculate the label and mc particle, they may differ as TPClabel != global label
289       fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
290       if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
291       else fMCparticle=NULL;
292       break;
293     default:
294       fTrack = track;
295       fCleanupTrack = kFALSE;
296   }
297 }
298
299 //-----------------------------------------------------------------------
300 AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
301 {
302   //get standard cuts
303   AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
304   cuts->SetName("standard TPConly cuts");
305   delete cuts->fAliESDtrackCuts;
306   cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
307   cuts->SetParamType(kESD_TPConly);
308   return cuts;
309 }
310
311 //-----------------------------------------------------------------------
312 AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
313 {
314   //get standard cuts
315   AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
316   cuts->SetName("standard global track cuts 2009");
317   delete cuts->fAliESDtrackCuts;
318   cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
319   cuts->SetParamType(kGlobal);
320   return cuts;
321 }
322
323 //-----------------------------------------------------------------------
324 AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
325 {
326   //get a flow track constructed from whatever we applied cuts on
327   //caller is resposible for deletion
328   AliFlowTrack* flowtrack=NULL;
329   if (fParamType==kESD_SPDtracklet)
330   {
331     flowtrack = new AliFlowTrack();
332     flowtrack->SetPhi(fTrackPhi);
333     flowtrack->SetEta(fTrackEta);
334     flowtrack->SetSource(AliFlowTrack::kFromTracklet);
335   }
336   else
337   {
338     switch(fParamMix)
339     {
340       case kPure:
341         flowtrack = new AliFlowTrack(fTrack);
342         break;
343       case kTrackWithMCkine:
344         flowtrack = new AliFlowTrack(fMCparticle);
345         break;
346       case kTrackWithMCPID:
347         flowtrack = new AliFlowTrack(fTrack);
348         break;
349       default:
350         flowtrack = new AliFlowTrack(fTrack);
351     }
352     if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
353     else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
354     else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
355     else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
356   }
357   return flowtrack;
358 }
359
360 //-----------------------------------------------------------------------
361 Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
362 {
363   //check if current particle is a physical primary
364   return fMCevent->IsPhysicalPrimary(fTrackLabel);
365 }
366
367 //-----------------------------------------------------------------------
368 const char* AliFlowTrackCuts::GetParamTypeName(trackParameterType type) 
369 {
370   //return the name of the selected parameter type
371   switch (type)
372   {
373     case kMC:
374       return "MC";
375     case kGlobal:
376       return "ESD global";
377     case kESD_TPConly:
378       return "TPC only";
379     case kESD_SPDtracklet:
380         return "SPD tracklet";
381     default:
382         return "unknown";
383   }
384   return "unknown";
385 }