Updated Glauber MC distributions
[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"
43#include "AliAODTrack.h"
44#include "AliFlowTrack.h"
45#include "AliFlowTrackCuts.h"
46#include "AliLog.h"
47
48ClassImp(AliFlowTrackCuts)
49
50//-----------------------------------------------------------------------
51AliFlowTrackCuts::AliFlowTrackCuts():
52 AliFlowTrackSimpleCuts(),
53 fAliESDtrackCuts(new AliESDtrackCuts()),
54 fCutMCprocessType(kFALSE),
55 fMCprocessType(kPNoProcess),
56 fCutMCPID(kFALSE),
57 fMCPID(0),
58 fCutMCisPrimary(kFALSE),
59 fMCisPrimary(kFALSE),
957517fa 60 fCutRequireCharge(kFALSE),
61 fRequireCharge(kFALSE),
daf66719 62 fParamType(kESD_Global),
63 fParamMix(kPure),
daf66719 64 fCleanupTrack(kFALSE),
65 fTrack(NULL),
957517fa 66 fMCevent(NULL),
daf66719 67 fMCparticle(NULL)
68{
69 //constructor
70}
71
72//-----------------------------------------------------------------------
73AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
74 AliFlowTrackSimpleCuts(someCuts),
75 fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
76 fCutMCprocessType(someCuts.fCutMCprocessType),
77 fMCprocessType(someCuts.fMCprocessType),
78 fCutMCPID(someCuts.fCutMCPID),
79 fMCPID(someCuts.fMCPID),
80 fCutMCisPrimary(someCuts.fCutMCisPrimary),
81 fMCisPrimary(someCuts.fMCisPrimary),
957517fa 82 fCutRequireCharge(someCuts.fCutRequireCharge),
83 fRequireCharge(someCuts.fRequireCharge),
daf66719 84 fParamType(someCuts.fParamType),
85 fParamMix(someCuts.fParamMix),
daf66719 86 fCleanupTrack(kFALSE),
87 fTrack(NULL),
957517fa 88 fMCevent(NULL),
daf66719 89 fMCparticle(NULL)
90{
91 //copy constructor
92}
93
94//-----------------------------------------------------------------------
95AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
96{
97 //assignment
98 AliFlowTrackSimpleCuts::operator=(someCuts);
99 *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
100 fCutMCprocessType=someCuts.fCutMCprocessType;
101 fMCprocessType=someCuts.fMCprocessType;
102 fCutMCPID=someCuts.fCutMCPID;
103 fMCPID=someCuts.fMCPID;
104 fCutMCisPrimary=someCuts.fCutMCisPrimary;
105 fMCisPrimary=someCuts.fMCisPrimary;
957517fa 106 fCutRequireCharge=someCuts.fCutRequireCharge;
107 fRequireCharge=someCuts.fRequireCharge;
daf66719 108 fParamType=someCuts.fParamType;
109 fParamMix=someCuts.fParamMix;
110
daf66719 111 fCleanupTrack=kFALSE;
112 fTrack=NULL;
957517fa 113 fMCevent=NULL;
daf66719 114 fMCparticle=NULL;
115
116 return *this;
117}
118
119//-----------------------------------------------------------------------
120AliFlowTrackCuts::~AliFlowTrackCuts()
121{
122 //dtor
123 if (fCleanupTrack) delete fTrack;
124 delete fAliESDtrackCuts;
125}
126
127//-----------------------------------------------------------------------
128Bool_t AliFlowTrackCuts::IsSelected(TObject* obj)
129{
130 //check cuts
131 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
132 if (vparticle) return PassesCuts(vparticle);
133 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
134 if (flowtrack) return PassesCuts(flowtrack);
135 return kFALSE; //default when passed wrong type of object
136}
137
138//-----------------------------------------------------------------------
139Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
140{
141 //check cuts on a flowtracksimple
5559ce24 142
143 //clean up from last iteration
144 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 145 return AliFlowTrackSimpleCuts::PassesCuts(track);
146}
147
148//-----------------------------------------------------------------------
149Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
150{
151 //check cuts for an ESD vparticle
152
5559ce24 153 //clean up from last iteration
154 if (fCleanupTrack) delete fTrack; fTrack=NULL;
155
957517fa 156 //get the label and the mc particle
157 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(vparticle->GetLabel()));
daf66719 158 else fMCparticle=NULL;
159
957517fa 160 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 161 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
162 if (esdTrack)
163 HandleESDtrack(esdTrack);
164 else
957517fa 165 {
daf66719 166 HandleVParticle(vparticle);
957517fa 167 //now check if produced particle is MC
168 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
169 }
170
daf66719 171 //check the common cuts for the current particle (MC,AOD,ESD)
172 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) return kFALSE;}
173 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) return kFALSE;}
174 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) return kFALSE;}
957517fa 175 if (fCutRequireCharge) {if (fTrack->Charge() == 0) return kFALSE;}
176 if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) return kFALSE;}
177 if (fCutCharge && isMCparticle)
178 {
179 //in case of an MC particle the charge is stored in units of 1/3|e|
180 Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
181 return (charge==fCharge);
182 }
daf66719 183 //if(fCutPID) {if (fTrack->PID() != fPID) return kFALSE;}
184
957517fa 185 //when additionally MC info is required
daf66719 186 if (fCutMCisPrimary)
187 {
188 if (!fMCevent) {AliError("no MC info"); return kFALSE;}
957517fa 189 if (fMCevent->IsPhysicalPrimary(fTrack->GetLabel()) != fMCisPrimary) return kFALSE;
daf66719 190 }
191 if (fCutMCPID)
192 {
193 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
194 Int_t pdgCode = fMCparticle->PdgCode();
195 if (fMCPID != pdgCode) return kFALSE;
196 }
197 if ( fCutMCprocessType )
198 {
199 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
200 TParticle* particle = fMCparticle->Particle();
201 Int_t processID = particle->GetUniqueID();
202 if (processID != fMCprocessType ) return kFALSE;
203 }
204
205 //check all else for ESDs using aliesdtrackcuts
206 if (esdTrack && (fParamType!=kMC) ) return fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack));
207
208 return kTRUE; //true by default, if we didn't set any cuts
209}
210
211//-----------------------------------------------------------------------
212void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
213{
214 //handle the general case
daf66719 215 switch (fParamType)
216 {
217 case kMC:
218 fCleanupTrack = kFALSE;
219 fTrack = fMCparticle;
220 break;
221 default:
222 fCleanupTrack = kFALSE;
223 fTrack = track;
224 }
225}
226
227//-----------------------------------------------------------------------
228void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
229{
230 //handle esd track
daf66719 231 switch (fParamType)
232 {
233 case kESD_Global:
234 fTrack = track;
235 fCleanupTrack = kFALSE;
236 break;
237 case kESD_TPConly:
238 fTrack = new AliESDtrack();
239 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
240 fCleanupTrack = kTRUE;
957517fa 241 //recalculate the label and mc particle, they may differ as TPClabel != global label
242 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrack->GetLabel()));
243 else fMCparticle=NULL;
daf66719 244 break;
245 case kMC:
246 fCleanupTrack = kFALSE;
247 fTrack = fMCparticle;
248 break;
249 default:
250 fTrack = track;
251 fCleanupTrack = kFALSE;
252 }
253}
254
255//-----------------------------------------------------------------------
256AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
257{
258 //get standard cuts
259 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 260 cuts->SetName("standard TPConly cuts");
daf66719 261 delete cuts->fAliESDtrackCuts;
262 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 263 cuts->SetParamType(kESD_TPConly);
daf66719 264 return cuts;
265}
266
267//-----------------------------------------------------------------------
268AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
269{
270 //get standard cuts
271 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
272 cuts->SetName("standard global track cuts 2009");
273 delete cuts->fAliESDtrackCuts;
274 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
5559ce24 275 cuts->SetParamType(kESD_Global);
daf66719 276 return cuts;
277}
278
279//-----------------------------------------------------------------------
280AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
281{
282 //get a flow track constructed from whatever we applied cuts on
283 //caller is resposible for deletion
284 AliFlowTrack* flowtrack=NULL;
285 switch(fParamMix)
286 {
287 case kPure:
288 flowtrack = new AliFlowTrack(fTrack);
289 break;
290 case kTrackWithMCkine:
291 flowtrack = new AliFlowTrack(fMCparticle);
292 break;
293 case kTrackWithMCPID:
294 flowtrack = new AliFlowTrack(fTrack);
295 break;
296 default:
297 flowtrack = new AliFlowTrack(fTrack);
298 }
299 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
300 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
301 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
302 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
303 return flowtrack;
304}