Updates (Ch. Oppedisano)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliFlowTrackCuts.cxx
CommitLineData
daf66719 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)
5559ce24 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.
daf66719 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"
12b2b8bc 43#include "AliMultiplicity.h"
daf66719 44#include "AliAODTrack.h"
45#include "AliFlowTrack.h"
46#include "AliFlowTrackCuts.h"
47#include "AliLog.h"
48
49ClassImp(AliFlowTrackCuts)
50
51//-----------------------------------------------------------------------
52AliFlowTrackCuts::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),
957517fa 61 fRequireCharge(kFALSE),
127a5825 62 fFakesAreOK(kTRUE),
12b2b8bc 63 fParamType(kGlobal),
daf66719 64 fParamMix(kPure),
daf66719 65 fCleanupTrack(kFALSE),
66 fTrack(NULL),
12b2b8bc 67 fTrackPhi(0.),
68 fTrackEta(0.),
69 fTrackWeight(0.),
127a5825 70 fTrackLabel(INT_MIN),
957517fa 71 fMCevent(NULL),
daf66719 72 fMCparticle(NULL)
73{
74 //constructor
75}
76
77//-----------------------------------------------------------------------
78AliFlowTrackCuts::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),
957517fa 87 fRequireCharge(someCuts.fRequireCharge),
127a5825 88 fFakesAreOK(someCuts.fFakesAreOK),
daf66719 89 fParamType(someCuts.fParamType),
90 fParamMix(someCuts.fParamMix),
daf66719 91 fCleanupTrack(kFALSE),
92 fTrack(NULL),
12b2b8bc 93 fTrackPhi(someCuts.fTrackPhi),
94 fTrackEta(someCuts.fTrackEta),
95 fTrackWeight(someCuts.fTrackWeight),
127a5825 96 fTrackLabel(INT_MIN),
957517fa 97 fMCevent(NULL),
daf66719 98 fMCparticle(NULL)
99{
100 //copy constructor
101}
102
103//-----------------------------------------------------------------------
104AliFlowTrackCuts& 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;
957517fa 115 fRequireCharge=someCuts.fRequireCharge;
127a5825 116 fFakesAreOK=someCuts.fFakesAreOK;
daf66719 117 fParamType=someCuts.fParamType;
118 fParamMix=someCuts.fParamMix;
119
daf66719 120 fCleanupTrack=kFALSE;
121 fTrack=NULL;
12b2b8bc 122 fTrackPhi=someCuts.fTrackPhi;
123 fTrackPhi=someCuts.fTrackPhi;
124 fTrackWeight=someCuts.fTrackWeight;
127a5825 125 fTrackLabel=INT_MIN;
957517fa 126 fMCevent=NULL;
daf66719 127 fMCparticle=NULL;
128
129 return *this;
130}
131
132//-----------------------------------------------------------------------
133AliFlowTrackCuts::~AliFlowTrackCuts()
134{
135 //dtor
136 if (fCleanupTrack) delete fTrack;
137 delete fAliESDtrackCuts;
138}
139
140//-----------------------------------------------------------------------
12b2b8bc 141Bool_t AliFlowTrackCuts::IsSelected(TObject* obj, Int_t id)
daf66719 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);
12b2b8bc 148 AliMultiplicity* tracklets = dynamic_cast<AliMultiplicity*>(obj);
149 if (tracklets) return PassesCuts(tracklets,id);
daf66719 150 return kFALSE; //default when passed wrong type of object
151}
152
153//-----------------------------------------------------------------------
154Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
155{
156 //check cuts on a flowtracksimple
5559ce24 157
158 //clean up from last iteration
159 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 160 return AliFlowTrackSimpleCuts::PassesCuts(track);
161}
162
12b2b8bc 163//-----------------------------------------------------------------------
164Bool_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//-----------------------------------------------------------------------
185Bool_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
daf66719 210//-----------------------------------------------------------------------
211Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
212{
213 //check cuts for an ESD vparticle
214
127a5825 215 ////////////////////////////////////////////////////////////////
216 // start by preparing the track parameters to cut on //////////
217 ////////////////////////////////////////////////////////////////
5559ce24 218 //clean up from last iteration
219 if (fCleanupTrack) delete fTrack; fTrack=NULL;
220
957517fa 221 //get the label and the mc particle
127a5825 222 fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
223 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
daf66719 224 else fMCparticle=NULL;
225
957517fa 226 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 227 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
228 if (esdTrack)
229 HandleESDtrack(esdTrack);
230 else
957517fa 231 {
daf66719 232 HandleVParticle(vparticle);
957517fa 233 //now check if produced particle is MC
234 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
235 }
127a5825 236 ////////////////////////////////////////////////////////////////
237 ////////////////////////////////////////////////////////////////
238
daf66719 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;}
127a5825 243 if (fRequireCharge) {if (fTrack->Charge() == 0) return kFALSE;}
957517fa 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 }
daf66719 251 //if(fCutPID) {if (fTrack->PID() != fPID) return kFALSE;}
252
957517fa 253 //when additionally MC info is required
12b2b8bc 254 if (!PassesMCcuts()) return kFALSE;
daf66719 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//-----------------------------------------------------------------------
263void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
264{
265 //handle the general case
daf66719 266 switch (fParamType)
267 {
daf66719 268 default:
269 fCleanupTrack = kFALSE;
270 fTrack = track;
271 }
272}
273
274//-----------------------------------------------------------------------
275void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
276{
277 //handle esd track
daf66719 278 switch (fParamType)
279 {
12b2b8bc 280 case kGlobal:
daf66719 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;
957517fa 288 //recalculate the label and mc particle, they may differ as TPClabel != global label
127a5825 289 fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
290 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
957517fa 291 else fMCparticle=NULL;
daf66719 292 break;
daf66719 293 default:
294 fTrack = track;
295 fCleanupTrack = kFALSE;
296 }
297}
298
299//-----------------------------------------------------------------------
300AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
301{
302 //get standard cuts
303 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 304 cuts->SetName("standard TPConly cuts");
daf66719 305 delete cuts->fAliESDtrackCuts;
306 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 307 cuts->SetParamType(kESD_TPConly);
daf66719 308 return cuts;
309}
310
311//-----------------------------------------------------------------------
312AliFlowTrackCuts* 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);
12b2b8bc 319 cuts->SetParamType(kGlobal);
daf66719 320 return cuts;
321}
322
323//-----------------------------------------------------------------------
324AliFlowTrack* 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;
12b2b8bc 329 if (fParamType==kESD_SPDtracklet)
daf66719 330 {
12b2b8bc 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);
daf66719 356 }
daf66719 357 return flowtrack;
358}
127a5825 359
360//-----------------------------------------------------------------------
361Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
362{
363 //check if current particle is a physical primary
364 return fMCevent->IsPhysicalPrimary(fTrackLabel);
365}
12b2b8bc 366
367//-----------------------------------------------------------------------
368const 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}