]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGCF/EBYE/NetParticle/AliAnalysisNetParticleHelper.cxx
Coverity fix (Diego)
[u/mrichter/AliRoot.git] / PWGCF / EBYE / NetParticle / AliAnalysisNetParticleHelper.cxx
CommitLineData
cb68eb1d 1//-*- Mode: C++ -*-
2
3#include "TMath.h"
4#include "TAxis.h"
5#include "TSystem.h"
6#include "TFile.h"
7#include "TPRegexp.h"
9be43c8e 8#include "TDatabasePDG.h"
cb68eb1d 9
10#include "AliStack.h"
11#include "AliMCEvent.h"
12#include "AliMCParticle.h"
13#include "AliESDtrackCuts.h"
14#include "AliESDInputHandler.h"
15#include "AliESDpid.h"
9be43c8e 16#include "AliAODInputHandler.h"
17#include "AliAODEvent.h"
18#include "AliAODMCParticle.h"
cb68eb1d 19#include "AliCentrality.h"
20#include "AliTracker.h"
21
22#include "AliAnalysisNetParticleHelper.h"
23
24using namespace std;
25
26// Task for NetParticle checks
27// Author: Jochen Thaeder <jochen@thaeder.de>
28
29ClassImp(AliAnalysisNetParticleHelper)
30
3aa68b92 31/*
32 * ---------------------------------------------------------------------------------
33 * particle names
34 * ---------------------------------------------------------------------------------
35 */
36
478c95cf 37 // MW make fgk ... static const
38
3aa68b92 39 const Char_t* aPartNames[AliPID::kSPECIES][2] = {
40 {"ele", "posi"},
41 {"mubar", "mu"},
42 {"pibar", "pi"},
43 {"kbar", "k"},
44 {"pbar", "p"}
45 };
46
47 const Char_t* aPartTitles[AliPID::kSPECIES][2] = {
48 {"Electron", "Positron"},
49 {"Anti-Muon", "Muon"},
50 {"Anti-Pion", "Proton"},
51 {"Anti-Kaon", "Kaon"},
52 {"Anti-Proton", "Proton"}
53 };
54
55 const Char_t* aPartTitlesLatex[AliPID::kSPECIES][2] = {
56 {"e^{-}", "e^{+}" },
57 {"#mu^{-}", "#mu^{+}" },
58 {"#pi^{-}", "#pi^{+}" },
59 {"K^{-}", "K^{+}" },
60 {"#bar{p}", "p"}
61 };
62
63 const Char_t* aControlPartNames[2] = {"lambdabar", "lambda"};
64 const Char_t* aControlPartTitles[2] = {"Anti-Lambda", "Lambda"};
65
cb68eb1d 66/*
67 * ---------------------------------------------------------------------------------
68 * Constructor / Destructor
69 * ---------------------------------------------------------------------------------
70 */
71
72//________________________________________________________________________
73AliAnalysisNetParticleHelper::AliAnalysisNetParticleHelper() :
478c95cf 74 fModeDistCreation(0),
75
76 fInputEventHandler(NULL),
cb68eb1d 77 fPIDResponse(NULL),
78 fESD(NULL),
9be43c8e 79 fAOD(NULL),
cb68eb1d 80 fMCEvent(NULL),
81 fStack(NULL),
82
83 fCentralityBin(-1),
84 fCentralityPercentile(-1.),
85
86 fCentralityBinMax(7),
87 fVertexZMax(10.),
88 fRapidityMax(0.5),
89 fMinTrackLengthMC(70.),
90 fNSigmaMaxCdd(3.),
91 fNSigmaMaxCzz(3.),
92
93 fParticleSpecies(AliPID::kProton),
94 fControlParticleCode(3122),
95 fControlParticleIsNeutral(kTRUE),
96 fControlParticleName("Lambda"),
97
478c95cf 98 fUsePID(kTRUE),
cb68eb1d 99 fNSigmaMaxTPC(2.5),
100 fNSigmaMaxTOF(2.5),
101 fMinPtForTOFRequired(0.8),
102
103 fHEventStat0(NULL),
104 fHEventStat1(NULL),
105 fHEventStatMax(6),
106
107 fHTriggerStat(NULL),
108 fNTriggers(5),
109
110 fHCentralityStat(NULL),
111 fNCentralityBins(10),
112
113 fEtaCorrFunc(NULL),
114 fCorr0(NULL),
478c95cf 115 fCorr1(NULL),
116 fCorr2(NULL) {
cb68eb1d 117 // Constructor
118
119 AliLog::SetClassDebugLevel("AliAnalysisNetParticleHelper",10);
120}
121
122//________________________________________________________________________
123AliAnalysisNetParticleHelper::~AliAnalysisNetParticleHelper() {
124 // Destructor
125
478c95cf 126 if (fModeDistCreation == 1) {
127 for (Int_t jj = 0; jj < 2; ++jj) {
128 if (fCorr0[jj]) delete[] fCorr0[jj];
129 if (fParticleSpecies == AliPID::kProton) {
130 if (fCorr1[jj]) delete[] fCorr1[jj];
131 if (fCorr2[jj]) delete[] fCorr2[jj];
132 }
133 }
134 if (fCorr0) delete[] fCorr0;
135 if (fParticleSpecies == AliPID::kProton) {
136 if (fCorr1) delete[] fCorr1;
137 if (fCorr2) delete[] fCorr2;
138 }
cb68eb1d 139 }
478c95cf 140
cb68eb1d 141 return;
142}
143
3aa68b92 144/*
145 * ---------------------------------------------------------------------------------
146 * Setter
147 * ---------------------------------------------------------------------------------
148 */
149
150//________________________________________________________________________
151void AliAnalysisNetParticleHelper::SetParticleSpecies(AliPID::EParticleType pid) {
152 // -- Set particle species (ID, Name, Title, Title LATEX)
478c95cf 153
154 if ( Int_t(pid) < 0 || Int_t(pid) > AliPID::kSPECIES) {
3aa68b92 155 AliWarning("Particle ID not in AliPID::kSPECIES --> Set to protons");
156 pid = AliPID::kProton;
157 }
478c95cf 158
159 fParticleSpecies = pid;
160
3aa68b92 161 for (Int_t idxPart = 0; idxPart < 2; ++idxPart) {
162 fPartName[idxPart] = aPartNames[fParticleSpecies][idxPart];
163 fPartTitle[idxPart] = aPartTitles[fParticleSpecies][idxPart];
164 fPartTitleLatex[idxPart] = aPartTitlesLatex[fParticleSpecies][idxPart];
165 }
166}
478c95cf 167//________________________________________________________________________
168void AliAnalysisNetParticleHelper::SetUsePID(Bool_t usePID) {
169 // -- Set usage of PID
170 // > if turn off, set charge types (ID, Name, Title, Title LATEX)
171
172 fUsePID = usePID;
173
174 if (!usePID) {
175 fParticleSpecies = AliPID::kUnknown;
3aa68b92 176
478c95cf 177 fPartName[0] = "neg";
178 fPartName[1] = "pos";
179 fPartTitle[0] = "Negative";
180 fPartTitle[1] = "Positive";
181 fPartTitleLatex[0] = "Negative";
182 fPartTitleLatex[1] = "Positive";
183 }
184}
3aa68b92 185
186/*
187 * ---------------------------------------------------------------------------------
188 * Getter
189 * ---------------------------------------------------------------------------------
190 */
191
192//________________________________________________________________________
193TString AliAnalysisNetParticleHelper::GetParticleName(Int_t idxPart) {
194 // -- Get particle Name
195
196 if( idxPart != 0 && idxPart != 1){
197 AliWarning("Particle type not known --> Set to antiparticles");
198 idxPart = 0;
199 }
200
201 return fPartName[idxPart];
202}
203
204//________________________________________________________________________
205TString AliAnalysisNetParticleHelper::GetParticleTitle(Int_t idxPart) {
206 // -- Get particle Title
207
208 if( idxPart != 0 && idxPart != 1){
209 AliWarning("Particle type not known --> Set to antiparticles");
210 idxPart = 0;
211 }
212
213 return fPartTitle[idxPart];
214}
215
216//________________________________________________________________________
217TString AliAnalysisNetParticleHelper::GetParticleTitleLatex(Int_t idxPart) {
218 // -- Get particle Title LATEX
219
220 if( idxPart != 0 && idxPart != 1){
221 AliWarning("Particle type not known --> Set to antiparticles");
222 idxPart = 0;
223 }
224
225 return fPartTitleLatex[idxPart];
226}
227
228//________________________________________________________________________
229TString AliAnalysisNetParticleHelper::GetControlParticleName(Int_t idxPart) {
230 // -- Get particle Title LATEX
231
232 if( idxPart != 0 && idxPart != 1){
233 AliWarning("Particle type not known --> Set to antiparticles");
234 idxPart = 0;
235 }
236
237 return aControlPartNames[idxPart];
238}
239
240//________________________________________________________________________
241TString AliAnalysisNetParticleHelper::GetControlParticleTitle(Int_t idxPart) {
242 // -- Get particle Title LATEX
243
244 if( idxPart != 0 && idxPart != 1){
245 AliWarning("Particle type not known --> Set to antiparticles");
246 idxPart = 0;
247 }
248
249 return aControlPartTitles[idxPart];
250}
251
cb68eb1d 252/*
253 * ---------------------------------------------------------------------------------
254 * Public Methods
255 * ---------------------------------------------------------------------------------
256 */
257
258//________________________________________________________________________
478c95cf 259Int_t AliAnalysisNetParticleHelper::Initialize(Bool_t isMC, Int_t modeDistCreation) {
cb68eb1d 260 // -- Initialize helper
261
262 Int_t iResult = 0;
478c95cf 263 fModeDistCreation = modeDistCreation;
cb68eb1d 264
265 // -- Setup event cut statistics
266 InitializeEventStats();
267
268 // -- Setup trigger statistics
269 InitializeTriggerStats();
270
271 // -- Setup centrality statistics
272 InitializeCentralityStats();
273
274 // -- Load Eta correction function
275 iResult = InitializeEtaCorrection(isMC);
276
3aa68b92 277 // -- Load track by track correction function
cb68eb1d 278 iResult = InitializeTrackbyTrackCorrection();
279
280 return iResult;
281}
282
283//________________________________________________________________________
9be43c8e 284Int_t AliAnalysisNetParticleHelper::SetupEvent(AliESDInputHandler *esdHandler, AliAODInputHandler *aodHandler, AliMCEvent *mcEvent) {
cb68eb1d 285 // -- Setup Event
478c95cf 286
cb68eb1d 287 // -- Get ESD objects
9be43c8e 288 if(esdHandler){
478c95cf 289 fInputEventHandler = static_cast<AliInputEventHandler*>(esdHandler);
290 fESD = dynamic_cast<AliESDEvent*>(fInputEventHandler->GetEvent());
9be43c8e 291 }
292
293 // -- Get AOD objects
294 else if(aodHandler){
478c95cf 295 fInputEventHandler = static_cast<AliInputEventHandler*>(aodHandler);
296 fAOD = dynamic_cast<AliAODEvent*>(fInputEventHandler->GetEvent());
9be43c8e 297 }
cb68eb1d 298
478c95cf 299 // -- Get Common objects
300 fPIDResponse = fInputEventHandler->GetPIDResponse();
301
cb68eb1d 302 // -- Get MC objects
303 fMCEvent = mcEvent;
304 if (fMCEvent)
305 fStack = fMCEvent->Stack();
306
307 // -- Get event centrality
308 // > 0-5|5-10|10-20|20-30|30-40|40-50|50-60|60-70|70-80|80-90 --> 10 bins
309 // > 0 1 2 3 4 5 6 7 8 9
310
9be43c8e 311 AliCentrality *centrality = NULL;
312
313 if(esdHandler)
314 centrality = fESD->GetCentrality();
315 else if(aodHandler)
316 centrality = fAOD->GetHeader()->GetCentralityP();
317
cb68eb1d 318 Int_t centBin = centrality->GetCentralityClass10("V0M");
319 if (centBin == 0)
320 fCentralityBin = centrality->GetCentralityClass5("V0M");
321 else if (centBin == 10 || centBin == -1.)
322 fCentralityBin = -1;
323 else if (centBin > 0 && centBin < fNCentralityBins)
324 fCentralityBin = centBin + 1;
325 else
326 fCentralityBin = -2;
478c95cf 327
cb68eb1d 328 // -- Stay within the max centrality bin
329 if (fCentralityBin >= fCentralityBinMax)
330 fCentralityBin = -2;
478c95cf 331
cb68eb1d 332 fCentralityPercentile = centrality->GetCentralityPercentile("V0M");
333
478c95cf 334 // -- Update TPC pid with eta correction (only for ESDs!!)
335 if(esdHandler)
9be43c8e 336 UpdateEtaCorrectedTPCPid();
cb68eb1d 337
338 return 0;
339}
340
341/*
342 * ---------------------------------------------------------------------------------
343 * Event / Trigger Statistics
344 * ---------------------------------------------------------------------------------
345 */
346
347//________________________________________________________________________
348Bool_t AliAnalysisNetParticleHelper::IsEventTriggered() {
349 // -- Check if Event is triggered and fill Trigger Histogram
350
351 Bool_t *aTriggerFired = new Bool_t[fNTriggers];
352 for (Int_t ii = 0; ii < fNTriggers; ++ii)
353 aTriggerFired[ii] = kFALSE;
354
478c95cf 355 if ((fInputEventHandler->IsEventSelected() & AliVEvent::kMB)) aTriggerFired[0] = kTRUE;
356 if ((fInputEventHandler->IsEventSelected() & AliVEvent::kCentral)) aTriggerFired[1] = kTRUE;
357 if ((fInputEventHandler->IsEventSelected() & AliVEvent::kSemiCentral)) aTriggerFired[2] = kTRUE;
358 if ((fInputEventHandler->IsEventSelected() & AliVEvent::kEMCEJE)) aTriggerFired[3] = kTRUE;
359 if ((fInputEventHandler->IsEventSelected() & AliVEvent::kEMCEGA)) aTriggerFired[4] = kTRUE;
9be43c8e 360
cb68eb1d 361 Bool_t isTriggered = kFALSE;
362
363 for (Int_t ii=0; ii<fNTriggers; ++ii) {
364 if(aTriggerFired[ii]) {
365 isTriggered = kTRUE;
366 fHTriggerStat->Fill(ii);
367 }
368 }
369
370 delete[] aTriggerFired;
371
372 return isTriggered;
373}
374
375//________________________________________________________________________
376Bool_t AliAnalysisNetParticleHelper::IsEventRejected() {
377 // -- Evaluate event statistics histograms
378
379 Int_t *aEventCuts = new Int_t[fHEventStatMax];
380 // set aEventCuts[ii] to 1 in case of reject
381
382 for (Int_t ii=0;ii<fHEventStatMax; ++ii)
383 aEventCuts[ii] = 0;
384
385 Int_t iCut = 0;
386
387 // -- 0 - Before Physics Selection
388 aEventCuts[iCut] = 0;
389
390 // -- 1 - No Trigger fired
391 ++iCut;
392 if (!IsEventTriggered())
393 aEventCuts[iCut] = 1;
394
395 // -- 2 - No Vertex
396 ++iCut;
9be43c8e 397 const AliESDVertex* vtxESD = NULL;
398 const AliAODVertex* vtxAOD = NULL;
399 if (fESD){
400 vtxESD = fESD->GetPrimaryVertexTracks();
401 if (!vtxESD)
402 aEventCuts[iCut] = 1;
403 }
404 else if (fAOD){
405 vtxAOD = fAOD->GetPrimaryVertex();
406 if (!vtxAOD)
407 aEventCuts[iCut] = 1;
408 }
cb68eb1d 409
410 // -- 3 - Vertex z outside cut window
411 ++iCut;
412 if (vtxESD){
413 if(TMath::Abs(vtxESD->GetZv()) > fVertexZMax)
414 aEventCuts[iCut] = 1;
415 }
9be43c8e 416 else if(vtxAOD){
417 if(TMath::Abs(vtxAOD->GetZ()) > fVertexZMax)
418 aEventCuts[iCut] = 1;
419 }
cb68eb1d 420 else
421 aEventCuts[iCut] = 1;
478c95cf 422
cb68eb1d 423 // -- 4 - Centrality = -1 (no centrality or not hadronic)
424 ++iCut;
425 if(fCentralityBin == -1.)
426 aEventCuts[iCut] = 1;
427
428 // -- 5 - Centrality < fCentralityMax
429 ++iCut;
430 if(fCentralityBin == -2.)
431 aEventCuts[iCut] = 1;
432
433 // -- Fill statistics / reject event
434 Bool_t isRejected = FillEventStats(aEventCuts);
435
436 // -- Cleanup
437 delete[] aEventCuts;
438
439 return isRejected;
440}
441
442/*
443 * ---------------------------------------------------------------------------------
444 * Accept Particle Methods - private
445 * ---------------------------------------------------------------------------------
446 */
447
448//________________________________________________________________________
449Bool_t AliAnalysisNetParticleHelper::IsParticleAcceptedBasicCharged(TParticle *particle, Int_t idxMC) {
450 // -- Check if MC particle is accepted for basic parameters
451
452 if (!particle)
453 return kFALSE;
454
455 // -- check if PDF code exists
456 if (!particle->GetPDG())
457 return kFALSE;
458
459 // -- check if charged
460 if (particle->GetPDG()->Charge() == 0.0)
461 return kFALSE;
462
463 // -- check if physical primary
464 if(!fStack->IsPhysicalPrimary(idxMC))
465 return kFALSE;
466
467 return kTRUE;
468}
478c95cf 469
cb68eb1d 470//________________________________________________________________________
9be43c8e 471Bool_t AliAnalysisNetParticleHelper::IsParticleAcceptedBasicCharged(AliAODMCParticle *particle) {
472 // -- Check if MC particle is accepted for basic parameters
473
474 if (!particle)
475 return kFALSE;
476
477 // -- check if PDF code exists
478 if (!(TDatabasePDG::Instance()->GetParticle(particle->PdgCode())))
479 return kFALSE;
480
481 // -- check if charged
482 if ((TDatabasePDG::Instance()->GetParticle(particle->PdgCode()))->Charge() == 0.0)
483 return kFALSE;
484
485 // -- check if physical primary
486 if(!particle->IsPhysicalPrimary())
487 return kFALSE;
488
489 return kTRUE;
490}
478c95cf 491
9be43c8e 492//________________________________________________________________________
cb68eb1d 493Bool_t AliAnalysisNetParticleHelper::IsParticleAcceptedBasicNeutral(TParticle *particle, Int_t idxMC) {
494 // -- Check if MC particle is accepted for basic parameters
495
496 if (!particle)
497 return kFALSE;
498
499 // -- check if PDF code exists
500 if (!particle->GetPDG())
501 return kFALSE;
502
503 // -- check if neutral
504 if (particle->GetPDG()->Charge() != 0.0)
505 return kFALSE;
506
507 // -- check if physical primary
508 if(!fStack->IsPhysicalPrimary(idxMC))
509 return kFALSE;
510
511 return kTRUE;
512}
9be43c8e 513//________________________________________________________________________
514Bool_t AliAnalysisNetParticleHelper::IsParticleAcceptedBasicNeutral(AliAODMCParticle *particle) {
515 // -- Check if MC particle is accepted for basic parameters
516
517 if (!particle)
518 return kFALSE;
cb68eb1d 519
9be43c8e 520 // -- check if PDF code exists
521 if (!(TDatabasePDG::Instance()->GetParticle(particle->PdgCode())))
522 return kFALSE;
523
524 // -- check if charged
525 if ((TDatabasePDG::Instance()->GetParticle(particle->PdgCode()))->Charge() != 0.0)
526 return kFALSE;
527
528 // -- check if physical primary
529 if(!particle->IsPhysicalPrimary())
530 return kFALSE;
531
532 return kTRUE;
533}
cb68eb1d 534//________________________________________________________________________
535Bool_t AliAnalysisNetParticleHelper::IsParticleAcceptedRapidity(TParticle *particle, Double_t &yP) {
536 // -- Check if particle is accepted
537 // > in rapidity
478c95cf 538 // > if no pid :
539 // > use yP as input for the pseudo-rapdity_MAX to be checked
cb68eb1d 540 // > return 0 if not accepted
541
478c95cf 542 if (!fUsePID) {
543 Bool_t isAccepted = kFALSE;
544 if (TMath::Abs(particle->Eta()) < yP)
545 isAccepted = kTRUE;
546 yP = particle->Eta();
547 return isAccepted;
548 }
549
cb68eb1d 550 Double_t mP = AliPID::ParticleMass(fParticleSpecies);
551
552 // -- Calculate rapidities and kinematics
553 Double_t p = particle->P();
554 Double_t pz = particle->Pz();
555
556 Double_t eP = TMath::Sqrt(p*p + mP*mP);
557 yP = 0.5 * TMath::Log((eP + pz) / (eP - pz));
558
559 // -- Check Rapidity window
560 if (TMath::Abs(yP) > fRapidityMax)
561 return kFALSE;
562
563 return kTRUE;
564}
565
566//_____________________________________________________________________________
567Bool_t AliAnalysisNetParticleHelper::IsParticleFindable(Int_t label) {
568 // -- Check if MC particle is findable tracks
569
570 AliMCParticle *mcParticle = static_cast<AliMCParticle*>(fMCEvent->GetTrack(label));
571 if(!mcParticle)
572 return kFALSE;
573
574 Int_t counter;
575 Float_t tpcTrackLength = mcParticle->GetTPCTrackLength(AliTracker::GetBz(), 0.05, counter, 3.0);
576
577 return (tpcTrackLength > fMinTrackLengthMC);
578}
579
580/*
581 * ---------------------------------------------------------------------------------
582 * Accept Track Methods - public
583 * ---------------------------------------------------------------------------------
584 */
9be43c8e 585
cb68eb1d 586//________________________________________________________________________
478c95cf 587Bool_t AliAnalysisNetParticleHelper::IsTrackAcceptedBasicCharged(AliVTrack* track) {
cb68eb1d 588 // -- Check if track is accepted
589 // > for basic parameters
9be43c8e 590
cb68eb1d 591 if (!track)
592 return kFALSE;
593
594 if (track->Charge() == 0)
595 return kFALSE;
596
9be43c8e 597 return kTRUE;
598}
599
cb68eb1d 600//________________________________________________________________________
9be43c8e 601Bool_t AliAnalysisNetParticleHelper::IsTrackAcceptedRapidity(AliVTrack *track, Double_t &yP) {
cb68eb1d 602 // -- Check if track is accepted
603 // > in rapidity
604 // > return 0 if not accepted
605
478c95cf 606 if (!fUsePID) {
607 yP = track->Eta();
608 return kTRUE;
609 }
610
cb68eb1d 611 Double_t mP = AliPID::ParticleMass(fParticleSpecies);
612
613 // -- Calculate rapidities and kinematics
614 Double_t pvec[3];
615 track->GetPxPyPz(pvec);
616
9be43c8e 617 Double_t p = track->P();
cb68eb1d 618 Double_t eP = TMath::Sqrt(p*p + mP*mP);
619 yP = 0.5 * TMath::Log((eP + pvec[2]) / (eP - pvec[2]));
620
621 // -- Check Rapidity window
622 if (TMath::Abs(yP) > fRapidityMax)
623 return kFALSE;
624
625 return kTRUE;
626}
627
628//________________________________________________________________________
478c95cf 629Bool_t AliAnalysisNetParticleHelper::IsTrackAcceptedDCA(AliVTrack *vTrack) {
630 // -- Check if track is accepted - ONLY FOR ESDs so far
cb68eb1d 631 // > for DCA, if both SPD layers have hits
478c95cf 632 // > For now only Implemented for ESDs
cb68eb1d 633
634 Bool_t isAccepted = kTRUE;
635
478c95cf 636 if (!fESD)
637 return isAccepted;
638
639 AliESDtrack* track = dynamic_cast<AliESDtrack*>(vTrack);
640 if (!track)
641 return kFALSE;
642
cb68eb1d 643 // -- Get nHits SPD
644 if (track->HasPointOnITSLayer(0) && track->HasPointOnITSLayer(1)) {
645
646 // -- Get DCA nSigmas
647 Float_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z
648 track->GetImpactParameters(dca,cov);
649
650 Float_t nSigmaCdd = (cov[0] != 0.) ? dca[0]/TMath::Sqrt(cov[0]) : -9.99;
651 Float_t nSigmaCzz = (cov[2] != 0.) ? dca[1]/TMath::Sqrt(cov[2]) : -9.99;
652
653 if (fNSigmaMaxCdd != 0.) {
654 if (TMath::Abs(nSigmaCdd) > fNSigmaMaxCdd)
655 isAccepted = kFALSE;
656 }
657
658 if (fNSigmaMaxCzz != 0.) {
659 if (TMath::Abs(nSigmaCzz) > fNSigmaMaxCzz)
660 isAccepted = kFALSE;
661 }
662 }
663
664 return isAccepted;
665}
666
667//________________________________________________________________________
9be43c8e 668Bool_t AliAnalysisNetParticleHelper::IsTrackAcceptedPID(AliVTrack *track, Double_t* pid) {
cb68eb1d 669 // -- Check if track is accepted
670 // > provides TPC and TOF nSigmas to the argument
671
672 Bool_t isAcceptedTPC = kFALSE;
673 Bool_t isAcceptedTOF = kTRUE;
478c95cf 674
675 // -- In case not PID is used
676 if (!fUsePID) {
677 pid[0] = 10.;
678 pid[1] = 10.;
679 return kTRUE;
680 }
cb68eb1d 681
682 // -- Get PID
683 pid[0] = fPIDResponse->NumberOfSigmasTPC(track, fParticleSpecies);
684 pid[1] = fPIDResponse->NumberOfSigmasTOF(track, fParticleSpecies);
685
686 // -- Check PID with TPC
687 if (TMath::Abs(pid[0]) < fNSigmaMaxTPC)
688 isAcceptedTPC = kTRUE;
689
690 // -- Check PID with TOF
691 if (isAcceptedTPC) {
692
693 // Has TOF PID availible
694 if (track->GetStatus() & AliVTrack::kTOFpid) {
695 if (TMath::Abs(pid[1]) < fNSigmaMaxTOF)
696 isAcceptedTOF = kTRUE;
697 else
698 isAcceptedTOF = kFALSE;
699 }
700
701 // Has no TOF PID availible
702 else {
478c95cf 703 if (track->Pt() > fMinPtForTOFRequired)
cb68eb1d 704 isAcceptedTOF = kFALSE;
705 else
706 isAcceptedTOF = kTRUE;
707 }
708 } // if (isAcceptedTPC) {
709
710 return (isAcceptedTPC && isAcceptedTOF);
711}
712
713/*
714 * ---------------------------------------------------------------------------------
715 * Helper Methods
716 * ---------------------------------------------------------------------------------
717 */
718
719//________________________________________________________________________
720void AliAnalysisNetParticleHelper::UpdateEtaCorrectedTPCPid() {
721 // -- Update eta corrected TPC pid
722
723 if (!fEtaCorrFunc)
724 return;
725
726 for (Int_t idxTrack = 0; idxTrack < fESD->GetNumberOfTracks(); ++idxTrack) {
727 AliESDtrack *track = fESD->GetTrack(idxTrack);
728
729 // -- Check if charged track is accepted for basic parameters
730 if (!IsTrackAcceptedBasicCharged(track))
731 continue;
732
733 Double_t newTPCSignal = track->GetTPCsignal() / fEtaCorrFunc->Eval(track->Eta());
734 track->SetTPCsignal(newTPCSignal, track->GetTPCsignalSigma(), track->GetTPCsignalN());
735 }
736}
737
738//________________________________________________________________________
739Double_t AliAnalysisNetParticleHelper::GetTrackbyTrackCorrectionFactor(Double_t *aTrack, Int_t flag) {
740 // -- Get efficiency correctionf of particle dependent on (eta, phi, pt, centrality)
741
742 Int_t idxPart = (aTrack[2] < 0) ? 0 : 1;
478c95cf 743 THnF* corrMatrix = NULL;
744 if (flag == 0)
745 corrMatrix = fCorr0[idxPart][fCentralityBin];
746 else if (flag == 1)
747 corrMatrix = fCorr1[idxPart][fCentralityBin];
748 else
749 corrMatrix = fCorr2[idxPart][fCentralityBin];
cb68eb1d 750
751 Double_t dimBin[3] = {aTrack[3], aTrack[4], aTrack[1]}; // eta, phi, pt
752
753 Double_t corr = corrMatrix->GetBinContent(corrMatrix->GetBin(dimBin));
754 if (corr == 0.) {
755 AliError(Form("Should not happen : bin content = 0. >> eta: %.2f | phi : %.2f | pt : %.2f | cent %d",
756 aTrack[3], aTrack[4], aTrack[1], fCentralityBin));
757 corr = 1.;
758 }
759
760 return corr;
761}
762
763//________________________________________________________________________
478c95cf 764void AliAnalysisNetParticleHelper::BinLogAxis(const THnBase *h, Int_t axisNumber) {
cb68eb1d 765 // -- Method for the correct logarithmic binning of histograms
766
767 TAxis *axis = h->GetAxis(axisNumber);
768 Int_t bins = axis->GetNbins();
769
770 Double_t from = axis->GetXmin();
771 Double_t to = axis->GetXmax();
772 Double_t *newBins = new Double_t[bins + 1];
773
774 newBins[0] = from;
775 Double_t factor = pow(to/from, 1./bins);
776
478c95cf 777 for (int i = 1; i <= bins; i++)
cb68eb1d 778 newBins[i] = factor * newBins[i-1];
478c95cf 779
cb68eb1d 780 axis->Set(bins, newBins);
478c95cf 781
cb68eb1d 782 delete [] newBins;
783}
784
785///////////////////////////////////////////////////////////////////////////////////
786
787/*
788 * ---------------------------------------------------------------------------------
789 * Initialize - Private
790 * ---------------------------------------------------------------------------------
791 */
792
793//________________________________________________________________________
794void AliAnalysisNetParticleHelper::InitializeEventStats() {
795 // -- Initialize event statistics histograms
796
797 const Char_t* aEventNames[] = {"All", "IsTriggered", "HasVertex", "Vz<Vz_{Max}", "Centrality [0,90]%"};
798 const Char_t* aCentralityMaxNames[] = {"5", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"};
799
800 fHEventStat0 = new TH1F("fHEventStat0","Event cut statistics 0;Event Cuts;Events", fHEventStatMax,-0.5,fHEventStatMax-0.5);
801 fHEventStat1 = new TH1F("fHEventStat1","Event cut statistics 1;Event Cuts;Events", fHEventStatMax,-0.5,fHEventStatMax-0.5);
802
803 for ( Int_t ii=0; ii < fHEventStatMax-1; ii++ ) {
804 fHEventStat0->GetXaxis()->SetBinLabel(ii+1, aEventNames[ii]);
805 fHEventStat1->GetXaxis()->SetBinLabel(ii+1, aEventNames[ii]);
806 }
807 fHEventStat0->GetXaxis()->SetBinLabel(fHEventStatMax, Form("Centrality [0-%s]%%", aCentralityMaxNames[fCentralityBinMax-1]));
808 fHEventStat1->GetXaxis()->SetBinLabel(fHEventStatMax, Form("Centrality [0-%s]%%", aCentralityMaxNames[fCentralityBinMax-1]));
809}
810
811//________________________________________________________________________
812void AliAnalysisNetParticleHelper::InitializeTriggerStats() {
813 // -- Initialize trigger statistics histograms
814
815 const Char_t* aTriggerNames[] = { "kMB", "kCentral", "kSemiCentral", "kEMCEJE", "kEMCEGA" };
816
817 fHTriggerStat = new TH1F("fHTriggerStat","Trigger statistics;Trigger;Events", fNTriggers,-0.5,fNTriggers-0.5);
818
819 for ( Int_t ii=0; ii < fNTriggers; ii++ )
820 fHTriggerStat->GetXaxis()->SetBinLabel(ii+1, aTriggerNames[ii]);
821}
822
823//________________________________________________________________________
824void AliAnalysisNetParticleHelper::InitializeCentralityStats() {
825 // -- Initialize trigger statistics histograms
826
827 const Char_t* aCentralityNames[] = {"0-5%", "5-10%", "10-20%", "20-30%", "30-40%", "40-50%",
828 "50-60%", "60-70%", "70-80%", "80-90%", "90-100%"};
829
830 fHCentralityStat = new TH1F("fHCentralityStat","Centrality statistics;Centrality Bins;Events",
831 fNCentralityBins,-0.5,fNCentralityBins-0.5);
832
833 for ( Int_t ii=0; ii < fNCentralityBins; ii++ )
834 fHCentralityStat->GetXaxis()->SetBinLabel(ii+1, aCentralityNames[ii]);
835}
836
837//________________________________________________________________________
838Int_t AliAnalysisNetParticleHelper::InitializeEtaCorrection(Bool_t isMC) {
839 // -- Initialize eta correction maps for TPC pid
840
841 TFile fileEtaCorrMaps("${ALICE_ROOT}/PWGDQ/dielectron/files/EtaCorrMaps.root");
842 if (!fileEtaCorrMaps.IsOpen())
843 return -1;
844
845 TList *keyList = fileEtaCorrMaps.GetListOfKeys();
846
847 TString sList("");
848 sList = (isMC) ? "LHC11a10" : "LHC10h.pass2";
849
850 for (Int_t idx = 0; idx < keyList->GetEntries(); ++idx) {
851 TString keyName = keyList->At(idx)->GetName();
852 TPRegexp reg(keyName);
853 if (reg.MatchB(sList)){
854 AliInfo(Form("Using Eta Correction Function: %s",keyName.Data()));
855 fEtaCorrFunc = static_cast<TF1*>(fileEtaCorrMaps.Get(keyName.Data()));
856 return 0;
857 }
858 }
859
860 return -2;
861}
862
863//________________________________________________________________________
864Int_t AliAnalysisNetParticleHelper::InitializeTrackbyTrackCorrection() {
865 // -- Initialize track by track correction matrices
866
478c95cf 867 if (fModeDistCreation != 1)
868 return 0;
3aa68b92 869
478c95cf 870 TFile* corrFile = TFile::Open("/hera/alice/jthaeder/train/trunk/jthaeder_trigger/netParticle/eff/effectiveCorrection.root");
871 // JMT In future --> !!!!!!!!!!!!!!!!!!!!!!!
872 // JMT TFile* corrFile = TFile::Open("${ALICE_ROOT}/PWGCF/EBYE/NetParticle/eff/effectiveCorrection.root");
873
cb68eb1d 874 if (!corrFile) {
875 AliError("Track-by-track correction file can not be opened!");
876 return -1;
877 }
878
478c95cf 879 // -- Correction - not cross section corrected
880 fCorr0 = new THnF**[2];
881 fCorr0[0] = new THnF*[fCentralityBinMax];
882 fCorr0[1] = new THnF*[fCentralityBinMax];
cb68eb1d 883
884 for (Int_t idxCent = 0; idxCent < fCentralityBinMax; ++idxCent) {
478c95cf 885 THnF *sp0 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr0_Cent_%d", fPartName[0].Data(), idxCent)));
886 THnF *sp1 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr0_Cent_%d", fPartName[1].Data(), idxCent)));
cb68eb1d 887
888 if (!sp0 || !sp1) {
478c95cf 889 AliError(Form("Effective correction objects 0 - idxCent %d can not be retrieved!", idxCent));
cb68eb1d 890 return -1;
891 }
892
478c95cf 893 fCorr0[0][idxCent] = static_cast<THnF*>(sp0->Clone());
894 fCorr0[1][idxCent] = static_cast<THnF*>(sp1->Clone());
cb68eb1d 895 }
896
478c95cf 897 // -- From now only for protons
898 if (fParticleSpecies != AliPID::kProton)
899 return 0;
900
901 // -- Correction - cross section corrected
902 fCorr1 = new THnF**[2];
903 fCorr1[0] = new THnF*[fCentralityBinMax];
904 fCorr1[1] = new THnF*[fCentralityBinMax];
cb68eb1d 905
906 for (Int_t idxCent = 0; idxCent < fCentralityBinMax; ++idxCent) {
478c95cf 907 THnF *sp0 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr1_Cent_%d", fPartName[0].Data(), idxCent)));
908 THnF *sp1 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr1_Cent_%d", fPartName[1].Data(), idxCent)));
909
910 if (!sp0 || !sp1) {
911 AliError(Form("Effective correction objects 1 - idxCent %d can not be retrieved!", idxCent));
912 return -1;
913 }
3aa68b92 914
478c95cf 915 fCorr1[0][idxCent] = static_cast<THnF*>(sp0->Clone());
916 fCorr1[1][idxCent] = static_cast<THnF*>(sp1->Clone());
917 }
918
919 // -- Correction - cross section correction only
920 fCorr2 = new THnF**[2];
921 fCorr2[0] = new THnF*[fCentralityBinMax];
922 fCorr2[1] = new THnF*[fCentralityBinMax];
923
924 for (Int_t idxCent = 0; idxCent < fCentralityBinMax; ++idxCent) {
925 THnF *sp0 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr2_Cent_%d", fPartName[0].Data(), idxCent)));
926 THnF *sp1 = static_cast<THnF*>(corrFile->Get(Form("hn_%s_Corr2_Cent_%d", fPartName[1].Data(), idxCent)));
cb68eb1d 927
928 if (!sp0 || !sp1) {
478c95cf 929 AliError(Form("Effective correction objects 2 - idxCent %d can not be retrieved!", idxCent));
cb68eb1d 930 return -1;
931 }
932
478c95cf 933 fCorr2[0][idxCent] = static_cast<THnF*>(sp0->Clone());
934 fCorr2[1][idxCent] = static_cast<THnF*>(sp1->Clone());
cb68eb1d 935 }
936
937 return 0;
938}
939
940/*
941 * ---------------------------------------------------------------------------------
942 * Event / Trigger Statistics - private
943 * ---------------------------------------------------------------------------------
944 */
945
946//________________________________________________________________________
947Bool_t AliAnalysisNetParticleHelper::FillEventStats(Int_t *aEventCuts) {
948 // -- Fill event / centrality statistics
949
950 Bool_t isRejected = kFALSE;
951
952 // -- Fill event statistics
953 for (Int_t idx = 0; idx < fHEventStatMax ; ++idx) {
9be43c8e 954
cb68eb1d 955 if (aEventCuts[idx])
956 isRejected = kTRUE;
957 else
958 fHEventStat0->Fill(idx);
959 }
960
961 for (Int_t idx = 0; idx < fHEventStatMax; ++idx) {
962 if (aEventCuts[idx])
963 break;
964 fHEventStat1->Fill(idx);
965 }
966
967 // -- Fill centrality statistics of accepted events
968 if (!isRejected)
969 fHCentralityStat->Fill(fCentralityBin);
970
971 return isRejected;
972}