]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/PIDFluctuation/task/AliEbyEPidRatioTask.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGCF / EBYE / PIDFluctuation / task / AliEbyEPidRatioTask.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: ALICE Offline.                                                 *
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 //=========================================================================//
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            //
22 //                             (Test Only)                                 //
23 //        Copied from NetParticle Classes
24 //        Origin: Authors: Jochen Thaeder <jochen@thaeder.de>
25 //                         Michael Weber <m.weber@cern.ch>
26 //=========================================================================//
27
28 #include "TFile.h"
29 #include "TChain.h"
30 #include "TTree.h"
31 #include "TH1F.h"
32 #include "TH2F.h"
33 #include "TH3F.h"
34 #include "TCanvas.h"
35 #include "TStopwatch.h"
36 #include "TMath.h"
37 #include "THashList.h"
38
39 #include "AliAnalysisTask.h"
40 #include "AliAnalysisManager.h"
41 #include "AliTracker.h" 
42 #include "AliESDEvent.h"
43 #include "AliESDInputHandler.h"
44 #include "AliESDpid.h"
45 #include "AliStack.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"
57
58 using namespace std;
59 ClassImp(AliEbyEPidRatioTask)
60 //________________________________________________________________________
61 AliEbyEPidRatioTask::AliEbyEPidRatioTask(const char *name) :
62   AliAnalysisTaskSE(name),
63   fHelper(NULL),
64   fEffCont(NULL),
65   fEffContExtra(NULL),
66   fDCA(NULL),
67   fDist(NULL),
68   fQA(NULL),
69
70   fOutList(NULL),
71   fOutListEff(NULL),
72   fOutListCont(NULL),
73   fOutListDCA(NULL),
74   fOutListQA(NULL),
75
76   fESD(NULL), 
77   fESDHandler(NULL),
78
79   fESDTrackCutsBase(NULL),
80   fESDTrackCuts(NULL),
81   fESDTrackCutsBkg(NULL),
82   fESDTrackCutsEff(NULL),
83
84   fAOD(NULL), 
85   fAODHandler(NULL),
86
87   fIsMC(kFALSE),
88   fIsRatio(kFALSE),
89   fIsPtBin(kFALSE),
90   fIsDetectorWise(kFALSE),
91   fIsAOD(kFALSE),
92   fIsSub(kFALSE),
93   fIsBS(kFALSE),
94   fIsPer(kFALSE),
95
96   fIsEffExtra(kFALSE),
97
98   fESDTrackCutMode(0),
99   fModeEffCreation(0),
100   fModeDCACreation(0),
101   fModeDistCreation(0),
102   fModeQACreation(0),
103
104   fMCEvent(NULL),
105   fMCStack(NULL),
106
107   fEtaMax(0.8),
108   fEtaMaxEff(0.9),
109   fPtRange(),
110   fPtRangeEff(),
111
112   fAODtrackCutBit(1024) {
113   
114   AliLog::SetClassDebugLevel("AliEbyEPidRatioTask",10);
115
116   fPtRange[0]    = 0.4;
117   fPtRange[1]    = 0.8;
118   fPtRangeEff[0] = 0.2;
119   fPtRangeEff[1] = 1.6;
120
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());
126 }
127
128 //________________________________________________________________________
129 AliEbyEPidRatioTask::~AliEbyEPidRatioTask() {
130   // Destructor
131
132   if (fESDTrackCutsBase) delete fESDTrackCutsBase;
133   if (fESDTrackCuts)     delete fESDTrackCuts;
134   if (fESDTrackCutsBkg)  delete fESDTrackCutsBkg;
135   if (fESDTrackCutsEff)  delete fESDTrackCutsEff;
136
137   if (fEffCont)          delete fEffCont;
138   if (fEffContExtra)     delete fEffContExtra;
139   if (fDCA)              delete fDCA;
140   if (fDist)             delete fDist;
141   if (fQA)               delete fQA;
142   if (fHelper)           delete fHelper;
143 }
144
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; }   
159
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 <<<<");
171
172
173 }
174
175 //________________________________________________________________________
176 void AliEbyEPidRatioTask::UserCreateOutputObjects() {
177   Bool_t oldStatus = TH1::AddDirectoryStatus();
178   TH1::AddDirectory(kFALSE);
179
180   fOutList = new TList;
181   fOutList->SetName(GetName()) ;
182   fOutList->SetOwner(kTRUE);
183  
184   fOutListEff = new TList;
185   fOutListEff->SetName(Form("%s_eff",GetName()));
186   fOutListEff->SetOwner(kTRUE) ;
187
188   fOutListCont = new TList;
189   fOutListCont->SetName(Form("%s_cont",GetName()));
190   fOutListCont->SetOwner(kTRUE) ;
191
192   fOutListDCA = new TList;
193   fOutListDCA->SetName(Form("%s_dca",GetName()));
194   fOutListDCA->SetOwner(kTRUE) ;
195  
196   fOutListQA = new TList;
197   fOutListQA->SetName(Form("%s_qa",GetName()));
198   fOutListQA->SetOwner(kTRUE) ;
199
200   Initialize();
201
202   fOutList->Add(new TList);
203   TList *list = static_cast<TList*>(fOutList->Last());
204   list->SetName(Form("fStat"));
205   list->SetOwner(kTRUE);
206
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());
212
213   if ((fIsAOD||fIsMC) && fModeEffCreation == 1) {
214     if (fIsEffExtra) {
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));
219         }
220         for (Int_t j = 2; j < 4; j++) {
221           if (fEffContExtra->GetHnEff(i,j))
222             fOutListCont->Add(fEffContExtra->GetHnEff(i,j));
223         }
224
225       }
226     }
227     else {
228       fOutListEff->Add(fEffCont->GetHnEffMc());
229       fOutListEff->Add(fEffCont->GetHnEffRec());
230       
231       fOutListCont->Add(fEffCont->GetHnContMc());
232       fOutListCont->Add(fEffCont->GetHnContRec());
233
234     }
235   }
236   
237   if (fModeDCACreation == 1)
238     fOutListDCA->Add(fDCA->GetHnDCA());
239
240   if (fModeQACreation == 1) {
241     fOutListQA->Add(fQA->GetHnQAPid());
242     fOutListQA->Add(fQA->GetHnQADca());
243   }
244
245   TH1::AddDirectory(oldStatus);
246
247   PostData(1,fOutList);
248   PostData(2,fOutListEff);
249   PostData(3,fOutListCont);
250   PostData(4,fOutListDCA);
251   PostData(5,fOutListQA);
252
253   return;
254 }
255
256 //________________________________________________________________________
257 void AliEbyEPidRatioTask::UserExec(Option_t *) {
258   
259   if (SetupEvent() < 0) {
260     PostData(1,fOutList);
261     PostData(2,fOutListEff);
262     PostData(3,fOutListCont);
263     PostData(4,fOutListDCA);
264     PostData(5,fOutListQA);
265     return;
266   }
267
268
269   if ((fIsMC||fIsAOD) && fModeEffCreation == 1) {
270     if (fIsEffExtra)  fEffContExtra->Process();
271     else fEffCont->Process();
272   }
273
274   if (fModeDCACreation == 1)
275     fDCA->Process();
276
277   if (fModeDistCreation > 0)
278     fDist->Process();
279
280   if (fModeQACreation == 1)
281     fQA->Process();
282
283   PostData(1,fOutList);
284   PostData(2,fOutListEff);
285   PostData(3,fOutListCont);
286   PostData(4,fOutListDCA);
287   PostData(5,fOutListQA);
288
289   return;
290 }      
291
292 //________________________________________________________________________
293 void AliEbyEPidRatioTask::Terminate(Option_t *){
294   // Terminate
295 }
296
297 Int_t AliEbyEPidRatioTask::Initialize() {
298   // Initialize event
299
300   // ------------------------------------------------------------------
301   // -- ESD TrackCuts
302   // ------------------------------------------------------------------
303   TString sModeName("");
304   
305   // -- Create ESD track cuts
306   // --------------------------
307   fESDTrackCutsBase = new AliESDtrackCuts;
308   
309   if (fESDTrackCutMode == 0) {
310     fESDTrackCutsBase->SetMinNCrossedRowsTPC(70);                                             // TPC
311     fESDTrackCutsBase->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);                    // TPC
312   }
313   else if (fESDTrackCutMode == 1) {
314     fESDTrackCutsBase->SetMinNClustersTPC(70);                                                // TPC  2010
315   }
316
317   fESDTrackCutsBase->SetMaxChi2PerClusterTPC(4);                                              // TPC  2010
318   fESDTrackCutsBase->SetAcceptKinkDaughters(kFALSE);                                          // TPC  2010
319   fESDTrackCutsBase->SetRequireTPCRefit(kTRUE);                                               // TPC  2010
320
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
325   } 
326   else if (fESDTrackCutMode == 1) {
327     fESDTrackCutsBase->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny); // ITS 2010
328   //  fESDTrackCutsBase->SetMinNClustersITS(4);
329   }
330
331   fESDTrackCutsBase->SetRequireITSRefit(kTRUE);                                               // ITS 2010 
332   fESDTrackCutsBase->SetMaxChi2PerClusterITS(36);                                             // ITS 2010
333
334   fESDTrackCutsBase->SetDCAToVertex2D(kFALSE);                                                // VertexConstrained  2010
335   fESDTrackCutsBase->SetRequireSigmaToVertex(kFALSE);                                         // VertexConstrained  2010
336   fESDTrackCutsBase->SetMaxDCAToVertexZ(2);                                                   // VertexConstrained  2010
337  
338   fESDTrackCutsBase->SetEtaRange(-1.*fEtaMax, fEtaMax);                                       // Acceptance
339   fESDTrackCutsBase->SetPtRange(fPtRange[0],fPtRange[1]);                                     // Acceptance
340
341   // -- Mode : standard cuts
342   if (fESDTrackCutMode == 0) 
343     sModeName = "Std";
344   // -- Mode : for comparison to LF
345   else if (fESDTrackCutMode == 1)
346     sModeName = "LF";
347   // -- Mode : Default
348   else
349     sModeName = "Base";
350   
351   fESDTrackCutsBase->SetName(Form("NetParticleCuts2010_%s",sModeName.Data()));
352
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)
362
363   //  fESDTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);                                    // golden cut off
364
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
371   
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
378
379   // ------------------------------------------------------------------
380   // -- Initialize Helper
381   // ------------------------------------------------------------------
382
383   if (fHelper->Initialize(fESDTrackCutsEff, fIsMC,fIsRatio,fIsPtBin, fIsDetectorWise, fAODtrackCutBit, fModeDistCreation))
384     return -1;
385
386   // fHelper->SetIsRatio(fIsRatio);  
387   // fHelper->SetIsPtBin(fIsPtBin);  
388
389   // ------------------------------------------------------------------
390   // -- Create / Initialize Efficiency/Contamination
391   // ------------------------------------------------------------------
392   if ((fIsMC||fIsAOD) && fModeEffCreation == 1) {
393     if (fIsEffExtra) {
394       fEffContExtra = new AliEbyEPidRatioEffContExtra;
395       fEffContExtra->Initialize(fHelper, fESDTrackCutsEff);
396       Printf(" >>>> AliEbyEPidRatioEffContExtra::Initialize()-ed  ");
397     } else {
398       fEffCont = new AliEbyEPidRatioEffCont;
399       fEffCont->Initialize(fHelper, fESDTrackCutsEff);
400       Printf(" >>>> AliEbyEPidRatioEffCont::Initialize()-ed  ");
401     }
402   }
403
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  ");
412   }
413
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  ");
426   }
427
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  ");
435   }
436
437   // ------------------------------------------------------------------
438   // -- Reset Event
439   // ------------------------------------------------------------------
440   ResetEvent();
441
442   return 0;
443 }
444
445 //________________________________________________________________________
446 Int_t AliEbyEPidRatioTask::SetupEvent() {
447
448   ResetEvent();
449
450   // -- ESD Event
451   // ------------------------------------------------------------------
452   if (!fIsAOD && SetupESDEvent() < 0) {
453     AliError("Setup ESD Event failed");
454     return -1;
455   }
456
457   // -- AOD Event
458   // ------------------------------------------------------------------
459   if (fIsAOD && SetupAODEvent() < 0) {
460     AliError("Setup AOD Event failed");
461     return -1;
462   }
463   
464   // -- Setup MC Event
465   // ------------------------------------------------------------------
466   if (fIsMC && SetupMCEvent() < 0) {
467     AliError("Setup MC Event failed");
468     return -1;
469   }
470
471   // -- Setup Event for Helper / EffCont  / DCA / Dist / QA classes
472   // ------------------------------------------------------------------
473   fHelper->SetupEvent(fESDHandler, fAODHandler, fMCEvent);
474
475   
476   if (fModeEffCreation && (fIsMC || fIsAOD) ) {
477     if (fIsEffExtra) fEffContExtra->SetupEvent(); 
478     else fEffCont->SetupEvent(); 
479   }
480
481   if (fModeDCACreation == 1)
482     fDCA->SetupEvent();
483
484   if (fModeDistCreation > 0)
485     fDist->SetupEvent(); 
486
487   if (fModeQACreation == 1)
488     fQA->SetupEvent(); 
489
490  
491   // -- Evaluate Event cuts
492   // ------------------------------------------------------------------
493   return fHelper->IsEventRejected() ? -2 : 0;
494 }
495
496 //________________________________________________________________________
497 Int_t AliEbyEPidRatioTask::SetupESDEvent() {
498   // -- Setup ESD Event
499   // > return 0 for success 
500   // > return -1 for failed setup
501
502
503   
504
505   fESDHandler= dynamic_cast<AliESDInputHandler*> 
506     (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
507   if (!fESDHandler) {
508     AliError("Could not get ESD input handler");
509     return -1;
510   } 
511
512   fESD = fESDHandler->GetEvent();
513   if (!fESD) {
514     AliError("Could not get ESD event");
515     return -1;
516   }
517
518   // -- Check PID response
519   // ------------------------------------------------------------------
520   if (!fESDHandler->GetPIDResponse()) {
521     AliError("Could not get PID response");
522     return -1;
523   } 
524
525   // -- Check Vertex
526   // ------------------------------------------------------------------
527   if (!fESD->GetPrimaryVertexTracks()) {
528     AliError("Could not get vertex from tracks");
529     return -1;
530   }
531
532   // -- Check Centrality
533   // ------------------------------------------------------------------
534   if (!fESD->GetCentrality()) {
535     AliError("Could not get centrality");
536     return -1;
537   }
538
539   return 0;
540 }
541
542 //________________________________________________________________________
543 Int_t AliEbyEPidRatioTask::SetupAODEvent() {
544   // -- Setup AOD Event
545   // > return 0 for success 
546   // > return -1 for failed setup
547
548   fAODHandler= dynamic_cast<AliAODInputHandler*> 
549     (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
550   if (!fAODHandler) {
551     AliError("Could not get AOD input handler");
552     return -1;
553   } 
554
555   fAOD = fAODHandler->GetEvent();
556   if (!fAOD) {
557     AliError("Could not get AOD event");
558     return -1;
559   }
560
561   // -- Check PID response
562   // ------------------------------------------------------------------
563   if (!fAODHandler->GetPIDResponse()) {
564     AliError("Could not get PID response");
565     return -1;
566   } 
567
568   // -- Check Vertex
569   // ------------------------------------------------------------------
570   if (!fAOD->GetPrimaryVertex()) {
571     AliError("Could not get primary vertex");
572     return -1;
573   }
574
575   // -- Check Centrality
576   // ------------------------------------------------------------------
577   if (!((AliVAODHeader*)fAOD->GetHeader())->GetCentralityP()) {
578     AliError("Could not get centrality");
579     return -1;
580   }
581
582   return 0;
583 }
584
585 //________________________________________________________________________
586 Int_t AliEbyEPidRatioTask::SetupMCEvent() {
587   AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*> 
588     (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
589   
590   if (!mcH) {
591     AliError("MC event handler not available");
592     return -1;
593   }
594
595   fMCEvent = mcH->MCEvent();
596   if (!fMCEvent) {
597     AliError("MC event not available");
598     return -1;
599   }
600
601   // -- Get MC header
602   // ------------------------------------------------------------------
603   AliHeader* header = fMCEvent->Header();
604   if (!header) {
605     AliError("MC header not available");
606     return -1;
607   }
608
609   // -- Check Stack
610   // ------------------------------------------------------------------
611   fMCStack = fMCEvent->Stack(); 
612   if (!fMCStack) {
613     AliError("MC stack not available");
614     return -1;
615   }
616     
617   // -- Check GenHeader
618   // ------------------------------------------------------------------
619   if (!header->GenEventHeader()) {
620     AliError("Could not retrieve genHeader from header");
621     return -1;
622   }
623
624   // -- Check primary vertex
625   // ------------------------------------------------------------------
626   if (!fMCEvent->GetPrimaryVertex()){
627     AliError("Could not get MC vertex");
628     return -1;
629   }
630
631   return 0;
632 }
633
634 //________________________________________________________________________
635 void AliEbyEPidRatioTask::ResetEvent() {
636   // -- Reset event
637   
638   // -- Reset ESD Event
639   fESD       = NULL;
640
641   // -- Reset AOD Event
642   fAOD       = NULL;
643
644   // -- Reset MC Event
645   if (fIsMC)
646     fMCEvent = NULL;
647
648   // -- Reset Dist Creation 
649   if (fModeDistCreation > 0)
650     fDist->ResetEvent();
651
652   return;
653 }
654
655