Added rejection of pileup from SPD (ChiaraB)
[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>
9a0783cc 39#include "TParticle.h"
40#include "AliStack.h"
daf66719 41#include "AliMCEvent.h"
9a0783cc 42#include "AliESDEvent.h"
daf66719 43#include "AliVParticle.h"
44#include "AliMCParticle.h"
45#include "AliESDtrack.h"
12b2b8bc 46#include "AliMultiplicity.h"
daf66719 47#include "AliAODTrack.h"
48#include "AliFlowTrack.h"
49#include "AliFlowTrackCuts.h"
50#include "AliLog.h"
51
52ClassImp(AliFlowTrackCuts)
53
54//-----------------------------------------------------------------------
55AliFlowTrackCuts::AliFlowTrackCuts():
56 AliFlowTrackSimpleCuts(),
57 fAliESDtrackCuts(new AliESDtrackCuts()),
924b02b0 58 fQA(kFALSE),
daf66719 59 fCutMCprocessType(kFALSE),
60 fMCprocessType(kPNoProcess),
61 fCutMCPID(kFALSE),
62 fMCPID(0),
4cbcbead 63 fIgnoreSignInPID(kFALSE),
daf66719 64 fCutMCisPrimary(kFALSE),
65 fMCisPrimary(kFALSE),
957517fa 66 fRequireCharge(kFALSE),
127a5825 67 fFakesAreOK(kTRUE),
9a0783cc 68 fCutSPDtrackletDeltaPhi(kFALSE),
69 fSPDtrackletDeltaPhiMax(FLT_MAX),
70 fSPDtrackletDeltaPhiMin(-FLT_MAX),
12b2b8bc 71 fParamType(kGlobal),
daf66719 72 fParamMix(kPure),
daf66719 73 fCleanupTrack(kFALSE),
74 fTrack(NULL),
12b2b8bc 75 fTrackPhi(0.),
76 fTrackEta(0.),
77 fTrackWeight(0.),
127a5825 78 fTrackLabel(INT_MIN),
957517fa 79 fMCevent(NULL),
9a0783cc 80 fMCparticle(NULL),
81 fEvent(NULL)
daf66719 82{
83 //constructor
84}
85
86//-----------------------------------------------------------------------
ee242db3 87AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& that):
88 AliFlowTrackSimpleCuts(that),
89 fAliESDtrackCuts(new AliESDtrackCuts(*(that.fAliESDtrackCuts))),
90 fQA(that.fQA),
91 fCutMCprocessType(that.fCutMCprocessType),
92 fMCprocessType(that.fMCprocessType),
93 fCutMCPID(that.fCutMCPID),
94 fMCPID(that.fMCPID),
4cbcbead 95 fIgnoreSignInPID(that.fIgnoreSignInPID),
ee242db3 96 fCutMCisPrimary(that.fCutMCisPrimary),
97 fMCisPrimary(that.fMCisPrimary),
98 fRequireCharge(that.fRequireCharge),
99 fFakesAreOK(that.fFakesAreOK),
100 fCutSPDtrackletDeltaPhi(that.fCutSPDtrackletDeltaPhi),
101 fSPDtrackletDeltaPhiMax(that.fSPDtrackletDeltaPhiMax),
102 fSPDtrackletDeltaPhiMin(that.fSPDtrackletDeltaPhiMin),
103 fParamType(that.fParamType),
104 fParamMix(that.fParamMix),
daf66719 105 fCleanupTrack(kFALSE),
106 fTrack(NULL),
ee242db3 107 fTrackPhi(0.),
108 fTrackEta(0.),
109 fTrackWeight(0.),
127a5825 110 fTrackLabel(INT_MIN),
957517fa 111 fMCevent(NULL),
9a0783cc 112 fMCparticle(NULL),
113 fEvent(NULL)
daf66719 114{
115 //copy constructor
116}
117
118//-----------------------------------------------------------------------
ee242db3 119AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& that)
daf66719 120{
121 //assignment
ee242db3 122 AliFlowTrackSimpleCuts::operator=(that);
123 *fAliESDtrackCuts=*(that.fAliESDtrackCuts);
124 fQA=that.fQA;
125 fCutMCprocessType=that.fCutMCprocessType;
126 fMCprocessType=that.fMCprocessType;
127 fCutMCPID=that.fCutMCPID;
128 fMCPID=that.fMCPID;
4cbcbead 129 fIgnoreSignInPID=that.fIgnoreSignInPID,
ee242db3 130 fCutMCisPrimary=that.fCutMCisPrimary;
131 fMCisPrimary=that.fMCisPrimary;
132 fRequireCharge=that.fRequireCharge;
133 fFakesAreOK=that.fFakesAreOK;
134 fCutSPDtrackletDeltaPhi=that.fCutSPDtrackletDeltaPhi;
135 fSPDtrackletDeltaPhiMax=that.fSPDtrackletDeltaPhiMax;
136 fSPDtrackletDeltaPhiMin=that.fSPDtrackletDeltaPhiMin;
137 fParamType=that.fParamType;
138 fParamMix=that.fParamMix;
daf66719 139
daf66719 140 fCleanupTrack=kFALSE;
141 fTrack=NULL;
ee242db3 142 fTrackPhi=0.;
143 fTrackPhi=0.;
144 fTrackWeight=0.;
127a5825 145 fTrackLabel=INT_MIN;
957517fa 146 fMCevent=NULL;
daf66719 147 fMCparticle=NULL;
9a0783cc 148 fEvent=NULL;
daf66719 149
150 return *this;
151}
152
153//-----------------------------------------------------------------------
154AliFlowTrackCuts::~AliFlowTrackCuts()
155{
156 //dtor
157 if (fCleanupTrack) delete fTrack;
158 delete fAliESDtrackCuts;
159}
160
161//-----------------------------------------------------------------------
12b2b8bc 162Bool_t AliFlowTrackCuts::IsSelected(TObject* obj, Int_t id)
daf66719 163{
164 //check cuts
165 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
166 if (vparticle) return PassesCuts(vparticle);
167 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
168 if (flowtrack) return PassesCuts(flowtrack);
12b2b8bc 169 AliMultiplicity* tracklets = dynamic_cast<AliMultiplicity*>(obj);
170 if (tracklets) return PassesCuts(tracklets,id);
daf66719 171 return kFALSE; //default when passed wrong type of object
172}
173
174//-----------------------------------------------------------------------
175Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
176{
177 //check cuts on a flowtracksimple
5559ce24 178
179 //clean up from last iteration
180 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 181 return AliFlowTrackSimpleCuts::PassesCuts(track);
182}
183
184//-----------------------------------------------------------------------
12b2b8bc 185Bool_t AliFlowTrackCuts::PassesCuts(AliMultiplicity* tracklet, Int_t id)
186{
187 //check cuts on a tracklets
188
9a0783cc 189 //clean up from last iteration, and init label
12b2b8bc 190 if (fCleanupTrack) delete fTrack; fTrack = NULL;
191 fMCparticle=NULL;
9a0783cc 192 fTrackLabel=-1;
12b2b8bc 193
194 fTrackPhi = tracklet->GetPhi(id);
195 fTrackEta = tracklet->GetEta(id);
196 fTrackWeight = 1.0;
197 if (fCutEta) {if ( fTrackEta < fEtaMin || fTrackEta >= fEtaMax ) return kFALSE;}
198 if (fCutPhi) {if ( fTrackPhi < fPhiMin || fTrackPhi >= fPhiMax ) return kFALSE;}
199
200 //check MC info if available
9a0783cc 201 //if the 2 clusters have different label track cannot be good
202 //and should therefore not pass the mc cuts
203 Int_t label0 = tracklet->GetLabel(id,0);
204 Int_t label1 = tracklet->GetLabel(id,1);
205 fTrackLabel = (label0==label1)?tracklet->GetLabel(id,1):-1;
12b2b8bc 206 if (!PassesMCcuts()) return kFALSE;
207 return kTRUE;
208}
209
210//-----------------------------------------------------------------------
211Bool_t AliFlowTrackCuts::PassesMCcuts()
212{
213 //check the MC info
03d364db 214 if (!fMCevent) return kFALSE;
9a0783cc 215 if (fTrackLabel<0) return kFALSE;//otherwise AliCMevent prints a warning before returning NULL
12b2b8bc 216 fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
03d364db 217 if (!fMCparticle) {AliError("no MC track"); return kFALSE;}
12b2b8bc 218
219 if (fCutMCisPrimary)
220 {
9a0783cc 221 if (IsPhysicalPrimary(fMCevent,fTrackLabel) != fMCisPrimary) return kFALSE;
12b2b8bc 222 }
223 if (fCutMCPID)
224 {
225 Int_t pdgCode = fMCparticle->PdgCode();
4cbcbead 226 if (fIgnoreSignInPID)
227 {
228 if (TMath::Abs(fMCPID) != TMath::Abs(pdgCode)) return kFALSE;
229 }
230 else
231 {
232 if (fMCPID != pdgCode) return kFALSE;
233 }
12b2b8bc 234 }
235 if ( fCutMCprocessType )
236 {
237 TParticle* particle = fMCparticle->Particle();
238 Int_t processID = particle->GetUniqueID();
239 if (processID != fMCprocessType ) return kFALSE;
240 }
241 return kTRUE;
242}
243
244//-----------------------------------------------------------------------
daf66719 245Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
246{
247 //check cuts for an ESD vparticle
248
127a5825 249 ////////////////////////////////////////////////////////////////
250 // start by preparing the track parameters to cut on //////////
251 ////////////////////////////////////////////////////////////////
5559ce24 252 //clean up from last iteration
253 if (fCleanupTrack) delete fTrack; fTrack=NULL;
254
957517fa 255 //get the label and the mc particle
127a5825 256 fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
257 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
daf66719 258 else fMCparticle=NULL;
259
957517fa 260 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 261 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
262 if (esdTrack)
263 HandleESDtrack(esdTrack);
264 else
957517fa 265 {
daf66719 266 HandleVParticle(vparticle);
957517fa 267 //now check if produced particle is MC
268 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
269 }
127a5825 270 ////////////////////////////////////////////////////////////////
271 ////////////////////////////////////////////////////////////////
272
924b02b0 273 Bool_t pass=kTRUE;
9a0783cc 274 //check the common cuts for the current particle fTrack (MC,AOD,ESD)
924b02b0 275 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) pass=kFALSE;}
276 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) pass=kFALSE;}
277 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) pass=kFALSE;}
278 if (fRequireCharge) {if (fTrack->Charge() == 0) pass=kFALSE;}
279 if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) pass=kFALSE;}
957517fa 280 if (fCutCharge && isMCparticle)
281 {
282 //in case of an MC particle the charge is stored in units of 1/3|e|
283 Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
284 return (charge==fCharge);
285 }
924b02b0 286 //if(fCutPID) {if (fTrack->PID() != fPID) pass=kFALSE;}
daf66719 287
957517fa 288 //when additionally MC info is required
924b02b0 289 if (!PassesMCcuts()) pass=kFALSE;
daf66719 290
291 //check all else for ESDs using aliesdtrackcuts
924b02b0 292 if (esdTrack && (fParamType!=kMC) )
293 if (!fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack))) pass=kFALSE;
daf66719 294
924b02b0 295 return pass; //true by default, if we didn't set any cuts
daf66719 296}
297
298//-----------------------------------------------------------------------
299void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
300{
301 //handle the general case
daf66719 302 switch (fParamType)
303 {
daf66719 304 default:
305 fCleanupTrack = kFALSE;
306 fTrack = track;
307 }
308}
309
310//-----------------------------------------------------------------------
311void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
312{
313 //handle esd track
daf66719 314 switch (fParamType)
315 {
12b2b8bc 316 case kGlobal:
daf66719 317 fTrack = track;
318 fCleanupTrack = kFALSE;
319 break;
320 case kESD_TPConly:
321 fTrack = new AliESDtrack();
322 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
323 fCleanupTrack = kTRUE;
957517fa 324 //recalculate the label and mc particle, they may differ as TPClabel != global label
127a5825 325 fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
326 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
957517fa 327 else fMCparticle=NULL;
daf66719 328 break;
daf66719 329 default:
330 fTrack = track;
331 fCleanupTrack = kFALSE;
332 }
333}
334
335//-----------------------------------------------------------------------
336AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
337{
338 //get standard cuts
339 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 340 cuts->SetName("standard TPConly cuts");
daf66719 341 delete cuts->fAliESDtrackCuts;
342 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 343 cuts->SetParamType(kESD_TPConly);
daf66719 344 return cuts;
345}
346
347//-----------------------------------------------------------------------
348AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
349{
350 //get standard cuts
351 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
352 cuts->SetName("standard global track cuts 2009");
353 delete cuts->fAliESDtrackCuts;
354 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
12b2b8bc 355 cuts->SetParamType(kGlobal);
daf66719 356 return cuts;
357}
358
359//-----------------------------------------------------------------------
360AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
361{
362 //get a flow track constructed from whatever we applied cuts on
363 //caller is resposible for deletion
9a0783cc 364 //if construction fails return NULL
daf66719 365 AliFlowTrack* flowtrack=NULL;
12b2b8bc 366 if (fParamType==kESD_SPDtracklet)
daf66719 367 {
12b2b8bc 368 flowtrack = new AliFlowTrack();
9a0783cc 369 switch (fParamMix)
370 {
371 case kPure:
372 flowtrack->SetPhi(fTrackPhi);
373 flowtrack->SetEta(fTrackEta);
374 break;
375 case kTrackWithMCkine:
376 if (!fMCparticle) return NULL;
377 flowtrack->SetPhi( fMCparticle->Phi() );
378 flowtrack->SetEta( fMCparticle->Eta() );
379 flowtrack->SetPt( fMCparticle->Pt() );
380 break;
381 case kTrackWithMCpt:
382 if (!fMCparticle) return NULL;
383 flowtrack->SetPhi(fTrackPhi);
384 flowtrack->SetEta(fTrackEta);
385 flowtrack->SetPt(fMCparticle->Pt());
386 break;
387 default:
388 flowtrack->SetPhi(fTrackPhi);
389 flowtrack->SetEta(fTrackEta);
390 }
12b2b8bc 391 flowtrack->SetSource(AliFlowTrack::kFromTracklet);
392 }
393 else
394 {
395 switch(fParamMix)
396 {
397 case kPure:
398 flowtrack = new AliFlowTrack(fTrack);
399 break;
400 case kTrackWithMCkine:
401 flowtrack = new AliFlowTrack(fMCparticle);
402 break;
403 case kTrackWithMCPID:
404 flowtrack = new AliFlowTrack(fTrack);
9a0783cc 405 //flowtrack->setPID(...) from mc, when implemented
12b2b8bc 406 break;
9a0783cc 407 case kTrackWithMCpt:
408 if (!fMCparticle) return NULL;
409 flowtrack = new AliFlowTrack(fTrack);
410 flowtrack->SetPt(fMCparticle->Pt());
12b2b8bc 411 default:
412 flowtrack = new AliFlowTrack(fTrack);
413 }
414 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
415 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
416 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
417 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
daf66719 418 }
daf66719 419 return flowtrack;
420}
127a5825 421
422//-----------------------------------------------------------------------
423Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
424{
425 //check if current particle is a physical primary
9a0783cc 426 if (!fMCevent) return kFALSE;
427 if (fTrackLabel<0) return kFALSE;
428 return IsPhysicalPrimary(fMCevent, fTrackLabel);
429}
430
431//-----------------------------------------------------------------------
432Bool_t AliFlowTrackCuts::IsPhysicalPrimary(AliMCEvent* mcEvent, Int_t label)
433{
434 //check if current particle is a physical primary
435 Bool_t physprim=mcEvent->IsPhysicalPrimary(label);
436 if (!physprim) return kFALSE;
437 AliMCParticle* track = static_cast<AliMCParticle*>(mcEvent->GetTrack(label));
438 if (!track) return kFALSE;
439 TParticle* particle = track->Particle();
440 Bool_t transported = particle->TestBit(kTransportBit);
441 //printf("prim: %s, transp: %s\n",(physprim)?"YES":"NO ",(transported)?"YES":"NO ");
442 return (physprim && transported);
127a5825 443}
12b2b8bc 444
445//-----------------------------------------------------------------------
446const char* AliFlowTrackCuts::GetParamTypeName(trackParameterType type)
447{
448 //return the name of the selected parameter type
449 switch (type)
450 {
451 case kMC:
452 return "MC";
453 case kGlobal:
454 return "ESD global";
455 case kESD_TPConly:
456 return "TPC only";
457 case kESD_SPDtracklet:
458 return "SPD tracklet";
459 default:
460 return "unknown";
461 }
462 return "unknown";
463}
924b02b0 464
465//-----------------------------------------------------------------------
466void AliFlowTrackCuts::DefineHistograms()
467{
468}
9a0783cc 469
470//-----------------------------------------------------------------------
471Int_t AliFlowTrackCuts::GetNumberOfInputObjects() const
472{
473 //get the number of tracks in the input event according source
474 //selection (ESD tracks, tracklets, MC particles etc.)
475 AliESDEvent* esd=NULL;
476 switch (fParamType)
477 {
478 case kESD_SPDtracklet:
479 esd = dynamic_cast<AliESDEvent*>(fEvent);
480 if (!esd) return 0;
481 return esd->GetMultiplicity()->GetNumberOfTracklets();
482 case kMC:
483 if (!fMCevent) return 0;
484 return fMCevent->GetNumberOfTracks();
485 default:
486 if (!fEvent) return 0;
487 return fEvent->GetNumberOfTracks();
488 }
489 return 0;
490}
491
492//-----------------------------------------------------------------------
493TObject* AliFlowTrackCuts::GetInputObject(Int_t i)
494{
495 //get the input object according the data source selection:
496 //(esd tracks, traclets, mc particles,etc...)
497 AliESDEvent* esd=NULL;
498 switch (fParamType)
499 {
500 case kESD_SPDtracklet:
501 esd = dynamic_cast<AliESDEvent*>(fEvent);
502 if (!esd) return NULL;
503 return const_cast<AliMultiplicity*>(esd->GetMultiplicity());
504 case kMC:
505 if (!fMCevent) return NULL;
506 return fMCevent->GetTrack(i);
507 default:
508 if (!fEvent) return NULL;
509 return fEvent->GetTrack(i);
510 }
511}