1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: ALICE Offline. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //=========================================================================//
17 // AliEbyE Analysis for Particle Ratio Fluctuation //
18 // Deepika Rathee | Satyajit Jena //
19 // drathee@cern.ch | sjena@cern.ch //
20 // Date: Wed Jul 9 18:38:30 CEST 2014 //
21 // New approch to find particle ratio to reduce memory //
23 // Copied from NetParticle Classes
24 // Origin: Authors: Jochen Thaeder <jochen@thaeder.de>
25 // Michael Weber <m.weber@cern.ch>
26 //=========================================================================//
35 #include "TStopwatch.h"
37 #include "THashList.h"
39 #include "AliAnalysisTask.h"
40 #include "AliAnalysisManager.h"
41 #include "AliTracker.h"
42 #include "AliESDEvent.h"
43 #include "AliESDInputHandler.h"
44 #include "AliESDpid.h"
46 #include "AliMCEvent.h"
47 #include "AliMCEventHandler.h"
48 #include "AliESDtrackCuts.h"
49 #include "AliKineTrackCuts.h"
50 #include "AliMCParticle.h"
51 #include "AliESDVZERO.h"
52 #include "AliEbyEPidRatioTask.h"
53 #include "AliGenEventHeader.h"
54 #include "AliCentrality.h"
55 #include "AliAODEvent.h"
56 #include "AliAODInputHandler.h"
59 ClassImp(AliEbyEPidRatioTask)
60 //________________________________________________________________________
61 AliEbyEPidRatioTask::AliEbyEPidRatioTask(const char *name) :
62 AliAnalysisTaskSE(name),
79 fESDTrackCutsBase(NULL),
81 fESDTrackCutsBkg(NULL),
82 fESDTrackCutsEff(NULL),
90 fIsDetectorWise(kFALSE),
101 fModeDistCreation(0),
112 fAODtrackCutBit(1024) {
114 AliLog::SetClassDebugLevel("AliEbyEPidRatioTask",10);
118 fPtRangeEff[0] = 0.2;
119 fPtRangeEff[1] = 1.6;
121 DefineOutput(1, TList::Class());
122 DefineOutput(2, TList::Class());
123 DefineOutput(3, TList::Class());
124 DefineOutput(4, TList::Class());
125 DefineOutput(5, TList::Class());
128 //________________________________________________________________________
129 AliEbyEPidRatioTask::~AliEbyEPidRatioTask() {
132 if (fESDTrackCutsBase) delete fESDTrackCutsBase;
133 if (fESDTrackCuts) delete fESDTrackCuts;
134 if (fESDTrackCutsBkg) delete fESDTrackCutsBkg;
135 if (fESDTrackCutsEff) delete fESDTrackCutsEff;
137 if (fEffCont) delete fEffCont;
138 if (fEffContExtra) delete fEffContExtra;
139 if (fDCA) delete fDCA;
140 if (fDist) delete fDist;
142 if (fHelper) delete fHelper;
145 void AliEbyEPidRatioTask::SetIsRatio(Int_t i) {
146 if (i == 1) { fIsRatio = 1; fIsPtBin = 0; fIsDetectorWise = 0; }
147 else if (i == 2) { fIsRatio = 0; fIsPtBin = 1; fIsDetectorWise = 0; }
148 else if (i == 3) { fIsRatio = 1; fIsPtBin = 1; fIsDetectorWise = 0; }
149 else if (i == 4) { fIsRatio = 0; fIsPtBin = 0; fIsDetectorWise = 1; }
150 else if (i == 5) { fIsRatio = 0; fIsPtBin = 1; fIsDetectorWise = 1; }
151 else if (i == 6) { fIsRatio = 1; fIsPtBin = 1; fIsDetectorWise = 1; }
152 else if (i == 7) { fIsSub = 1; fIsBS = 0; fIsPtBin = 0; }
153 else if (i == 8) { fIsSub = 1; fIsBS = 1; fIsRatio = 1; }
154 else if (i == 9) { fIsSub = 1; fIsBS = 1; fIsPtBin = 0; }
155 else if (i ==10) { fIsSub = 1; fIsBS = 0; fIsPtBin = 1; }
156 else if (i ==11) { fIsSub = 0; fIsBS = 1; fIsPtBin = 1; }
157 else if (i ==12) { fIsSub = 1; fIsBS = 1; fIsPtBin = 1; }
158 else { fIsRatio = 0; fIsPtBin = 0; fIsDetectorWise = 0; }
160 if (fModeDistCreation == 0)
161 Printf(">>>> Task: No Physics Variable <<<<");
162 if (fModeDistCreation > 0 && fIsRatio)
163 Printf(">>>> Task: Setting Ratios : ON <<<<");
164 else Printf(">>>> Task: Setting Ratios : OFF <<<<");
165 if (fModeDistCreation > 0 && fIsPtBin)
166 Printf(">>>> Task: Setting Binwise : ON <<<<");
167 else Printf(">>>> Task: Setting Binwise : OFF <<<<");
168 if (fModeDistCreation > 0 && fIsDetectorWise)
169 Printf(">>>> Task: Setting TOF-TPC wise: ON <<<<");
170 else Printf(">>>> Task: Setting TOF-TPC wise: OFF <<<<");
175 //________________________________________________________________________
176 void AliEbyEPidRatioTask::UserCreateOutputObjects() {
177 Bool_t oldStatus = TH1::AddDirectoryStatus();
178 TH1::AddDirectory(kFALSE);
180 fOutList = new TList;
181 fOutList->SetName(GetName()) ;
182 fOutList->SetOwner(kTRUE);
184 fOutListEff = new TList;
185 fOutListEff->SetName(Form("%s_eff",GetName()));
186 fOutListEff->SetOwner(kTRUE) ;
188 fOutListCont = new TList;
189 fOutListCont->SetName(Form("%s_cont",GetName()));
190 fOutListCont->SetOwner(kTRUE) ;
192 fOutListDCA = new TList;
193 fOutListDCA->SetName(Form("%s_dca",GetName()));
194 fOutListDCA->SetOwner(kTRUE) ;
196 fOutListQA = new TList;
197 fOutListQA->SetName(Form("%s_qa",GetName()));
198 fOutListQA->SetOwner(kTRUE) ;
202 fOutList->Add(new TList);
203 TList *list = static_cast<TList*>(fOutList->Last());
204 list->SetName(Form("fStat"));
205 list->SetOwner(kTRUE);
207 list->Add(fHelper->GetHEventStat0());
208 list->Add(fHelper->GetHEventStat1());
209 list->Add(fHelper->GetHTriggerStat());
210 list->Add(fHelper->GetHCentralityPercentile());
211 list->Add(fHelper->GetHCentralityPercentileAll());
213 if ((fIsAOD||fIsMC) && fModeEffCreation == 1) {
215 for (Int_t i = 0; i < 4; i++) {
216 for (Int_t j = 0; j < 2; j++) {
217 if (fEffContExtra->GetHnEff(i,j))
218 fOutListEff->Add(fEffContExtra->GetHnEff(i,j));
220 for (Int_t j = 2; j < 4; j++) {
221 if (fEffContExtra->GetHnEff(i,j))
222 fOutListCont->Add(fEffContExtra->GetHnEff(i,j));
228 fOutListEff->Add(fEffCont->GetHnEffMc());
229 fOutListEff->Add(fEffCont->GetHnEffRec());
231 fOutListCont->Add(fEffCont->GetHnContMc());
232 fOutListCont->Add(fEffCont->GetHnContRec());
237 if (fModeDCACreation == 1)
238 fOutListDCA->Add(fDCA->GetHnDCA());
240 if (fModeQACreation == 1) {
241 fOutListQA->Add(fQA->GetHnQAPid());
242 fOutListQA->Add(fQA->GetHnQADca());
245 TH1::AddDirectory(oldStatus);
247 PostData(1,fOutList);
248 PostData(2,fOutListEff);
249 PostData(3,fOutListCont);
250 PostData(4,fOutListDCA);
251 PostData(5,fOutListQA);
256 //________________________________________________________________________
257 void AliEbyEPidRatioTask::UserExec(Option_t *) {
259 if (SetupEvent() < 0) {
260 PostData(1,fOutList);
261 PostData(2,fOutListEff);
262 PostData(3,fOutListCont);
263 PostData(4,fOutListDCA);
264 PostData(5,fOutListQA);
269 if ((fIsMC||fIsAOD) && fModeEffCreation == 1) {
270 if (fIsEffExtra) fEffContExtra->Process();
271 else fEffCont->Process();
274 if (fModeDCACreation == 1)
277 if (fModeDistCreation > 0)
280 if (fModeQACreation == 1)
283 PostData(1,fOutList);
284 PostData(2,fOutListEff);
285 PostData(3,fOutListCont);
286 PostData(4,fOutListDCA);
287 PostData(5,fOutListQA);
292 //________________________________________________________________________
293 void AliEbyEPidRatioTask::Terminate(Option_t *){
297 Int_t AliEbyEPidRatioTask::Initialize() {
300 // ------------------------------------------------------------------
302 // ------------------------------------------------------------------
303 TString sModeName("");
305 // -- Create ESD track cuts
306 // --------------------------
307 fESDTrackCutsBase = new AliESDtrackCuts;
309 if (fESDTrackCutMode == 0) {
310 fESDTrackCutsBase->SetMinNCrossedRowsTPC(70); // TPC
311 fESDTrackCutsBase->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8); // TPC
313 else if (fESDTrackCutMode == 1) {
314 fESDTrackCutsBase->SetMinNClustersTPC(70); // TPC 2010
317 fESDTrackCutsBase->SetMaxChi2PerClusterTPC(4); // TPC 2010
318 fESDTrackCutsBase->SetAcceptKinkDaughters(kFALSE); // TPC 2010
319 fESDTrackCutsBase->SetRequireTPCRefit(kTRUE); // TPC 2010
321 if (fESDTrackCutMode == 0) {
322 fESDTrackCutsBase->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kOff); // ITS
323 fESDTrackCutsBase->SetClusterRequirementITS(AliESDtrackCuts::kSDD,AliESDtrackCuts::kOff); // ITS
324 fESDTrackCutsBase->SetClusterRequirementITS(AliESDtrackCuts::kSSD,AliESDtrackCuts::kOff); // ITS
326 else if (fESDTrackCutMode == 1) {
327 fESDTrackCutsBase->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny); // ITS 2010
328 // fESDTrackCutsBase->SetMinNClustersITS(4);
331 fESDTrackCutsBase->SetRequireITSRefit(kTRUE); // ITS 2010
332 fESDTrackCutsBase->SetMaxChi2PerClusterITS(36); // ITS 2010
334 fESDTrackCutsBase->SetDCAToVertex2D(kFALSE); // VertexConstrained 2010
335 fESDTrackCutsBase->SetRequireSigmaToVertex(kFALSE); // VertexConstrained 2010
336 fESDTrackCutsBase->SetMaxDCAToVertexZ(2); // VertexConstrained 2010
338 fESDTrackCutsBase->SetEtaRange(-1.*fEtaMax, fEtaMax); // Acceptance
339 fESDTrackCutsBase->SetPtRange(fPtRange[0],fPtRange[1]); // Acceptance
341 // -- Mode : standard cuts
342 if (fESDTrackCutMode == 0)
344 // -- Mode : for comparison to LF
345 else if (fESDTrackCutMode == 1)
351 fESDTrackCutsBase->SetName(Form("NetParticleCuts2010_%s",sModeName.Data()));
353 // -- Create ESD track cuts -> Base + DCA
354 // ------------------------------
355 fESDTrackCuts = static_cast<AliESDtrackCuts*>(fESDTrackCutsBase->Clone());
356 fESDTrackCuts->SetName(Form("NetParticleCuts2010_%s",sModeName.Data()));
357 if (fESDTrackCutMode == 0)
358 fESDTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01"); // 2010 VertexConstrained -> 7*(0.0026+0.0050/pt^1.01)
359 // fESDTrackCuts->SetMaxDCAToVertexXY(0.3);
360 else if (fESDTrackCutMode == 1)
361 fESDTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01"); // 2010 VertexConstrained -> 7*(0.0026+0.0050/pt^1.01)
363 // fESDTrackCuts->SetMaxChi2TPCConstrainedGlobal(36); // golden cut off
365 // -- Create ESD BKG track cuts -> Base + Acceptance(Eff)
366 // ------------------------------
367 fESDTrackCutsBkg = static_cast<AliESDtrackCuts*>(fESDTrackCutsBase->Clone());
368 fESDTrackCutsBkg->SetName(Form("NetParticleCuts2010_%s_Bkg",sModeName.Data()));
369 fESDTrackCutsBkg->SetPtRange(fPtRangeEff[0],fPtRangeEff[1]); // Acceptance
370 fESDTrackCutsBkg->SetEtaRange(-1.*fEtaMaxEff, fEtaMaxEff); // Acceptance
372 // -- Create ESD Eff track cuts -> Base + DCA + Acceptance(Eff)
373 // ------------------------------
374 fESDTrackCutsEff = static_cast<AliESDtrackCuts*>(fESDTrackCuts->Clone());
375 fESDTrackCutsEff->SetName(Form("NetParticleCuts2010_%s_Eff",sModeName.Data()));
376 fESDTrackCutsEff->SetPtRange(fPtRangeEff[0],fPtRangeEff[1]); // Acceptance
377 fESDTrackCutsEff->SetEtaRange(-1.*fEtaMaxEff, fEtaMaxEff); // Acceptance
379 // ------------------------------------------------------------------
380 // -- Initialize Helper
381 // ------------------------------------------------------------------
383 if (fHelper->Initialize(fESDTrackCutsEff, fIsMC,fIsRatio,fIsPtBin, fIsDetectorWise, fAODtrackCutBit, fModeDistCreation))
386 // fHelper->SetIsRatio(fIsRatio);
387 // fHelper->SetIsPtBin(fIsPtBin);
389 // ------------------------------------------------------------------
390 // -- Create / Initialize Efficiency/Contamination
391 // ------------------------------------------------------------------
392 if ((fIsMC||fIsAOD) && fModeEffCreation == 1) {
394 fEffContExtra = new AliEbyEPidRatioEffContExtra;
395 fEffContExtra->Initialize(fHelper, fESDTrackCutsEff);
396 Printf(" >>>> AliEbyEPidRatioEffContExtra::Initialize()-ed ");
398 fEffCont = new AliEbyEPidRatioEffCont;
399 fEffCont->Initialize(fHelper, fESDTrackCutsEff);
400 Printf(" >>>> AliEbyEPidRatioEffCont::Initialize()-ed ");
404 // ------------------------------------------------------------------
405 // -- Create / Initialize DCA Determination
406 // ------------------------------------------------------------------
407 if (fModeDCACreation == 1) {
408 fDCA = new AliEbyEPidRatioDCA;
409 fDCA->SetESDTrackCutsBkg(fESDTrackCutsBkg);
410 fDCA->Initialize(fHelper, fESDTrackCutsEff);
411 Printf(" >>>> AliEbyEPidRatioDCA:Initialize()-ed ");
414 // ------------------------------------------------------------------
415 // -- Create / Initialize Phy Determination
416 // ------------------------------------------------------------------
417 if (fModeDistCreation > 0) {
418 fDist = new AliEbyEPidRatioPhy;
419 fDist->SetOutList(fOutList);
420 if (fModeDistCreation == 2) fDist->SetQA();
421 if (fIsSub) fDist->SetSubRun();
422 if (fIsBS) fDist->SetBSRun();
423 if (fIsPer) fDist->SetIsPer();
424 fDist->Initialize(fHelper, fESDTrackCuts);
425 Printf(" >>>> AliEbyEPidRatioPhy:Initialize()-ed ");
428 // ------------------------------------------------------------------
429 // -- Create / Initialize QA Determination
430 // ------------------------------------------------------------------
431 if (fModeQACreation == 1) {
432 fQA = new AliEbyEPidRatioQA();
433 fQA->Initialize(fHelper, fESDTrackCutsEff);
434 Printf(" >>>> AliEbyEPidRatioQA:Initialize()-ed ");
437 // ------------------------------------------------------------------
439 // ------------------------------------------------------------------
445 //________________________________________________________________________
446 Int_t AliEbyEPidRatioTask::SetupEvent() {
451 // ------------------------------------------------------------------
452 if (!fIsAOD && SetupESDEvent() < 0) {
453 AliError("Setup ESD Event failed");
458 // ------------------------------------------------------------------
459 if (fIsAOD && SetupAODEvent() < 0) {
460 AliError("Setup AOD Event failed");
465 // ------------------------------------------------------------------
466 if (fIsMC && SetupMCEvent() < 0) {
467 AliError("Setup MC Event failed");
471 // -- Setup Event for Helper / EffCont / DCA / Dist / QA classes
472 // ------------------------------------------------------------------
473 fHelper->SetupEvent(fESDHandler, fAODHandler, fMCEvent);
476 if (fModeEffCreation && (fIsMC || fIsAOD) ) {
477 if (fIsEffExtra) fEffContExtra->SetupEvent();
478 else fEffCont->SetupEvent();
481 if (fModeDCACreation == 1)
484 if (fModeDistCreation > 0)
487 if (fModeQACreation == 1)
491 // -- Evaluate Event cuts
492 // ------------------------------------------------------------------
493 return fHelper->IsEventRejected() ? -2 : 0;
496 //________________________________________________________________________
497 Int_t AliEbyEPidRatioTask::SetupESDEvent() {
498 // -- Setup ESD Event
499 // > return 0 for success
500 // > return -1 for failed setup
505 fESDHandler= dynamic_cast<AliESDInputHandler*>
506 (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
508 AliError("Could not get ESD input handler");
512 fESD = fESDHandler->GetEvent();
514 AliError("Could not get ESD event");
518 // -- Check PID response
519 // ------------------------------------------------------------------
520 if (!fESDHandler->GetPIDResponse()) {
521 AliError("Could not get PID response");
526 // ------------------------------------------------------------------
527 if (!fESD->GetPrimaryVertexTracks()) {
528 AliError("Could not get vertex from tracks");
532 // -- Check Centrality
533 // ------------------------------------------------------------------
534 if (!fESD->GetCentrality()) {
535 AliError("Could not get centrality");
542 //________________________________________________________________________
543 Int_t AliEbyEPidRatioTask::SetupAODEvent() {
544 // -- Setup AOD Event
545 // > return 0 for success
546 // > return -1 for failed setup
548 fAODHandler= dynamic_cast<AliAODInputHandler*>
549 (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
551 AliError("Could not get AOD input handler");
555 fAOD = fAODHandler->GetEvent();
557 AliError("Could not get AOD event");
561 // -- Check PID response
562 // ------------------------------------------------------------------
563 if (!fAODHandler->GetPIDResponse()) {
564 AliError("Could not get PID response");
569 // ------------------------------------------------------------------
570 if (!fAOD->GetPrimaryVertex()) {
571 AliError("Could not get primary vertex");
575 // -- Check Centrality
576 // ------------------------------------------------------------------
577 if (!((AliVAODHeader*)fAOD->GetHeader())->GetCentralityP()) {
578 AliError("Could not get centrality");
585 //________________________________________________________________________
586 Int_t AliEbyEPidRatioTask::SetupMCEvent() {
587 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>
588 (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
591 AliError("MC event handler not available");
595 fMCEvent = mcH->MCEvent();
597 AliError("MC event not available");
602 // ------------------------------------------------------------------
603 AliHeader* header = fMCEvent->Header();
605 AliError("MC header not available");
610 // ------------------------------------------------------------------
611 fMCStack = fMCEvent->Stack();
613 AliError("MC stack not available");
617 // -- Check GenHeader
618 // ------------------------------------------------------------------
619 if (!header->GenEventHeader()) {
620 AliError("Could not retrieve genHeader from header");
624 // -- Check primary vertex
625 // ------------------------------------------------------------------
626 if (!fMCEvent->GetPrimaryVertex()){
627 AliError("Could not get MC vertex");
634 //________________________________________________________________________
635 void AliEbyEPidRatioTask::ResetEvent() {
638 // -- Reset ESD Event
641 // -- Reset AOD Event
648 // -- Reset Dist Creation
649 if (fModeDistCreation > 0)