coverity fixes
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliAnalysisTaskGammaConversion.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                                                                                                                                                                                                                                              *
4  * Author: Ana Marin, Kathrin Koch, Kenneth Aamodt                                                                                              *
5  * Version 1.1                                                                                                                                                                                                                                          *
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 //--------------------------------------------- 
18 // Class used to do analysis on conversion pairs
19 //---------------------------------------------
20 ///////////////////////////////////////////////
21
22 // root
23 #include <TChain.h>
24
25 // analysis
26 #include "AliAnalysisTaskGammaConversion.h"
27 #include "AliStack.h"
28 #include "AliLog.h"
29 #include "TTree.h"
30 #include "AliESDtrackCuts.h"
31 #include "TNtuple.h"
32 //#include "AliCFManager.h"     // for CF
33 //#include "AliCFContainer.h"    // for CF
34 #include "AliESDInputHandler.h"
35 #include "AliAnalysisManager.h"
36 #include "AliAODPWG4Particle.h"
37 #include "AliAODPWG4ParticleCorrelation.h"
38 #include "AliAODConversionPhoton.h"
39 #include "AliGammaConversionBGHandler.h"
40 #include "AliESDCaloCluster.h" // for combining PHOS and GammaConv
41 #include "AliKFVertex.h"
42 #include "AliGenPythiaEventHeader.h"
43 #include "AliGenDPMjetEventHeader.h"    
44 #include "AliGenEventHeader.h"
45 #include <AliMCEventHandler.h>
46 #include "TRandom3.h"
47 #include "AliTriggerAnalysis.h"
48 #include "AliCentrality.h"
49 #include "AliMultiplicity.h"
50 #include "AliAODHandler.h"
51 #include "AliKFConversionPhoton.h"
52 #include "AliKFConversionMother.h"
53 #include "AliESDVertex.h"
54 #include "AliESDTZERO.h"
55
56 class AliESDTrackCuts;
57 class AliCFContainer;
58 class AliCFManager;
59 class AliKFVertex;
60 class AliAODHandler;
61 class AliAODEvent;
62 class ALiESDEvent;
63 class AliMCEvent;
64 class AliMCEventHandler;
65 class AliESDInputHandler;
66 class AliAnalysisManager;
67 class Riostream;
68 class TFile;
69 class TInterpreter;
70 class TSystem;
71 class TROOT;
72
73 ClassImp(AliAnalysisTaskGammaConversion)
74
75
76 AliAnalysisTaskGammaConversion::AliAnalysisTaskGammaConversion():
77 AliAnalysisTaskSE(),
78         fpcstream(0x0),
79         fV0Reader(NULL),
80         fStack(NULL),
81         fMCTruth(NULL),         // for CF
82         fGCMCEvent(NULL),               // for CF
83         fESDEvent(NULL),        
84         fOutputContainer(NULL),
85         fCFManager(0x0),         // for CF
86         fHistograms(NULL),
87         fTriggerCINT1B(kFALSE),
88         fDoMCTruth(kFALSE),
89         fDoNeutralMeson(kFALSE),
90         fDoOmegaMeson(kFALSE),
91         fDoJet(kFALSE),
92         fDoChic(kFALSE),
93         fDoHadInt(kFALSE),
94         fRecalculateV0ForGamma(kFALSE),
95         fKFReconstructedGammasTClone(NULL),
96         fKFReconstructedPi0sTClone(NULL),
97         fKFRecalculatedGammasTClone(NULL),
98         fCurrentEventPosElectronTClone(NULL),
99         fCurrentEventNegElectronTClone(NULL),
100         fKFReconstructedGammasCutTClone(NULL),
101         fPreviousEventTLVNegElectronTClone(NULL),
102         fPreviousEventTLVPosElectronTClone(NULL),       
103        //  fElectronRecalculatedv1(),
104        // fElectronRecalculatedv2(),
105         fElectronMass(-1),
106         fGammaMass(-1),
107         fPi0Mass(-1),
108         fEtaMass(-1),
109         fGammaWidth(-1),
110         fPi0Width(-1),
111         fEtaWidth(-1),
112         fMinOpeningAngleGhostCut(0.),
113         fEsdTrackCuts(NULL),
114         fCalculateBackground(kFALSE),
115         fWriteNtuple(kFALSE),
116         fGammaNtuple(NULL),
117         fNeutralMesonNtuple(NULL),
118         fTotalNumberOfAddedNtupleEntries(0),
119         fChargedParticles(NULL),
120         fChargedParticlesId(),
121         fGammaPtHighest(0.),
122         fMinPtForGammaJet(1.),
123         fMinIsoConeSize(0.2),
124         fMinPtIsoCone(0.7),
125         fMinPtGamChargedCorr(0.5),
126         fMinPtJetCone(0.5),
127         fLeadingChargedIndex(-1),
128         fLowPtMapping(1.),
129         fHighPtMapping(3.),
130         fDoCF(kFALSE),
131         fAODGamma(NULL),
132         //fAODPi0(NULL),
133         //fAODOmega(NULL),
134         fAODBranchName("GammaConv"),
135         fKFCreateAOD(kTRUE),
136         fKFExchangeAOD(kFALSE),
137         fKFForceAOD(kFALSE),
138         fKFDeltaAODFileName(""),
139         fDoNeutralMesonV0MCCheck(kFALSE),
140         fUseTrackMultiplicityForBG(kTRUE),
141         fMoveParticleAccordingToVertex(kFALSE),
142         fApplyChi2Cut(kFALSE),
143         fNRandomEventsForBG(15),
144         fNDegreesPMBackground(15),
145         fDoRotation(kTRUE),
146         fCheckBGProbability(kTRUE),
147         fRemovePileUp(kFALSE),
148         fSelectV0AND(kFALSE),
149         fTriggerAnalysis(NULL),
150         fMultiplicity(0),
151         fUseMultiplicity(0), 
152         fUseMultiplicityBin(0),
153         fUseHBTMultiplicity(0),
154         fUseHBTMultiplicityBin(0),
155         fUseCentrality(0), 
156         fUseCentralityBin(0),
157         fRandom(0),
158         fMaxChi2HadInt(100.),           
159         fMaxErr2DHadInt(10.),
160         fPtMinHadInt(0.3)
161 {
162         // Default constructor
163
164         /*       Kenneth: the default constructor should not have any define input/output or the call to SetESDtrackCuts
165         // Common I/O in slot 0
166         DefineInput (0, TChain::Class());
167         DefineOutput(0, TTree::Class());
168         
169         // Your private output
170         DefineOutput(1, TList::Class());
171         
172         // Define standard ESD track cuts for Gamma-hadron correlation 
173         SetESDtrackCuts();
174         */
175 }
176
177 AliAnalysisTaskGammaConversion::AliAnalysisTaskGammaConversion(const char* name):
178         AliAnalysisTaskSE(name),
179         fpcstream(0x0),
180         fV0Reader(NULL),
181         fStack(NULL),
182         fMCTruth(NULL),         // for CF
183         fGCMCEvent(NULL),               // for CF
184         fESDEvent(NULL),        
185         fOutputContainer(0x0),
186         fCFManager(0x0),         // for CF
187         fHistograms(NULL),
188         fTriggerCINT1B(kFALSE),
189         fDoMCTruth(kFALSE),
190         fDoNeutralMeson(kFALSE),
191         fDoOmegaMeson(kFALSE),
192         fDoJet(kFALSE),
193         fDoChic(kFALSE),
194         fDoHadInt(kFALSE),
195         fRecalculateV0ForGamma(kFALSE),
196         fKFReconstructedGammasTClone(NULL),
197         fKFReconstructedPi0sTClone(NULL),
198         fKFRecalculatedGammasTClone(NULL),
199         fCurrentEventPosElectronTClone(NULL),
200         fCurrentEventNegElectronTClone(NULL),
201         fKFReconstructedGammasCutTClone(NULL),
202         fPreviousEventTLVNegElectronTClone(NULL),
203         fPreviousEventTLVPosElectronTClone(NULL),       
204       //  fElectronRecalculatedv1(),
205       //  fElectronRecalculatedv2(),
206         fElectronMass(-1),
207         fGammaMass(-1),
208         fPi0Mass(-1),
209         fEtaMass(-1),
210         fGammaWidth(-1),
211         fPi0Width(-1),
212         fEtaWidth(-1),
213         fMinOpeningAngleGhostCut(0.),
214         fEsdTrackCuts(NULL),
215         fCalculateBackground(kFALSE),
216         fWriteNtuple(kFALSE),
217         fGammaNtuple(NULL),
218         fNeutralMesonNtuple(NULL),
219         fTotalNumberOfAddedNtupleEntries(0),
220         fChargedParticles(NULL),
221         fChargedParticlesId(),
222         fGammaPtHighest(0.),
223         fMinPtForGammaJet(1.),
224         fMinIsoConeSize(0.2),
225         fMinPtIsoCone(0.7),
226         fMinPtGamChargedCorr(0.5),
227         fMinPtJetCone(0.5),
228         fLeadingChargedIndex(-1),
229         fLowPtMapping(1.),
230         fHighPtMapping(3.),
231         fDoCF(kFALSE),
232         fAODGamma(NULL),
233         //fAODPi0(NULL),
234         //fAODOmega(NULL),
235         fAODBranchName("GammaConv"),
236         fKFCreateAOD(kTRUE),
237         fKFExchangeAOD(kFALSE),
238         fKFForceAOD(kFALSE),
239         fKFDeltaAODFileName(""),
240         fDoNeutralMesonV0MCCheck(kFALSE),
241         fUseTrackMultiplicityForBG(kTRUE),
242         fMoveParticleAccordingToVertex(kFALSE),
243         fApplyChi2Cut(kFALSE),
244         fNRandomEventsForBG(15),
245         fNDegreesPMBackground(15),
246         fDoRotation(kTRUE),
247         fCheckBGProbability(kTRUE),
248         fRemovePileUp(kFALSE),
249         fSelectV0AND(kFALSE),
250         fTriggerAnalysis(NULL),
251         fMultiplicity(0),
252         fUseMultiplicity(0), 
253         fUseMultiplicityBin(0), 
254         fUseHBTMultiplicity(0),
255         fUseHBTMultiplicityBin(0),
256         fUseCentrality(0), 
257         fUseCentralityBin(0),
258         fRandom(0),
259         fMaxChi2HadInt(100.),           
260         fMaxErr2DHadInt(10.),
261         fPtMinHadInt(0.3)
262 {
263         // Common I/O in slot 0, don't define when inheriting from AnalysisTaskSE
264         // DefineInput (0, TChain::Class());    
265         // DefineOutput(0, TTree::Class()); 
266         
267         // Your private output
268         DefineOutput(1, TList::Class());
269         DefineOutput(2, AliCFContainer::Class());       // for CF
270         DefineOutput(3, TClonesArray::Class());
271         
272         // Define standard ESD track cuts for Gamma-hadron correlation 
273         SetESDtrackCuts();
274
275 }
276
277 AliAnalysisTaskGammaConversion::~AliAnalysisTaskGammaConversion() 
278 {
279         // Remove all pointers
280         
281         if(fOutputContainer){
282                 fOutputContainer->Clear() ; 
283                 delete fOutputContainer ;
284         }
285         if(fHistograms){
286                 delete fHistograms;
287         }
288         if(fV0Reader){
289                 delete fV0Reader;
290         }
291         
292         // for CF
293         if(fCFManager){
294                 delete fCFManager;
295         }
296
297         if(fEsdTrackCuts){
298                 delete fEsdTrackCuts;
299         }
300
301         //Delete AODs
302         if (fAODGamma) {
303                 fAODGamma->Clear();
304                 delete fAODGamma;
305         }
306         fAODGamma = NULL;
307
308         /*if (fAODPi0) {
309                 fAODPi0->Clear();
310                 delete fAODPi0;
311         }
312         fAODPi0 = NULL;
313
314         if (fAODOmega) {
315                 fAODOmega->Clear();
316                 delete fAODOmega;
317         }
318         fAODOmega = NULL;
319        */
320         if(fTriggerAnalysis) {
321                 delete fTriggerAnalysis;
322         }
323         if (fpcstream)
324                 delete fpcstream;
325         fpcstream = NULL;
326 }
327
328
329 void AliAnalysisTaskGammaConversion::Init()
330 {
331         // Initialization
332         // AliLog::SetGlobalLogLevel(AliLog::kError);
333 }
334 void AliAnalysisTaskGammaConversion::SetESDtrackCuts()
335 {
336         // SetESDtrackCuts
337         if (fEsdTrackCuts!=NULL){
338                 delete fEsdTrackCuts;
339         }
340         fEsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
341         //standard cuts from:
342         //http://aliceinfo.cern.ch/alicvs/viewvc/PWG0/dNdEta/CreateCuts.C?revision=1.4&view=markup
343
344         // Cuts used up to 3rd of March
345
346         //      fEsdTrackCuts->SetMinNClustersTPC(50);
347         //       fEsdTrackCuts->SetMaxChi2PerClusterTPC(3.5);
348         //       fEsdTrackCuts->SetRequireTPCRefit(kTRUE);
349         //       fEsdTrackCuts->SetRequireITSRefit(kTRUE);
350         //       fEsdTrackCuts->SetMaxNsigmaToVertex(3);
351         //       fEsdTrackCuts->SetRequireSigmaToVertex(kTRUE);
352
353         //------- To be tested-----------
354         // Cuts used up to 26th of Agost
355         //              Int_t minNClustersTPC = 70;
356         //              Double_t maxChi2PerClusterTPC = 4.0;
357         //              Double_t maxDCAtoVertexXY = 2.4; // cm
358         //              Double_t maxDCAtoVertexZ        = 3.2; // cm
359         //              fEsdTrackCuts->SetRequireSigmaToVertex(kFALSE);
360         //              fEsdTrackCuts->SetRequireTPCRefit(kTRUE);
361         //              fEsdTrackCuts->SetRequireITSRefit(kTRUE);
362         //              //       fEsdTrackCuts->SetRequireTPCStandAlone(kTRUE);
363         //              fEsdTrackCuts->SetAcceptKinkDaughters(kFALSE);
364         //              fEsdTrackCuts->SetMinNClustersTPC(minNClustersTPC);
365         //              fEsdTrackCuts->SetMaxChi2PerClusterTPC(maxChi2PerClusterTPC);
366         //              fEsdTrackCuts->SetMaxDCAToVertexXY(maxDCAtoVertexXY);
367         //              fEsdTrackCuts->SetMaxDCAToVertexZ(maxDCAtoVertexZ);
368         //              fEsdTrackCuts->SetDCAToVertex2D(kTRUE);
369         //              fEsdTrackCuts->SetEtaRange(-0.8, 0.8);
370         //              fEsdTrackCuts->SetPtRange(0.15);
371
372         //              fEsdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kFirst);
373
374
375         // Using standard function      for setting Cuts
376         Bool_t selectPrimaries=kTRUE;
377         fEsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
378         fEsdTrackCuts->SetMaxDCAToVertexZ(2);
379         fEsdTrackCuts->SetEtaRange(-0.8, 0.8);
380         fEsdTrackCuts->SetPtRange(0.15);
381         
382         //----- From Jacek 10.03.03 ------------------/
383         //               minNClustersTPC = 70;
384         //               maxChi2PerClusterTPC = 4.0;
385         //               maxDCAtoVertexXY = 2.4; // cm
386         //               maxDCAtoVertexZ        = 3.2; // cm
387
388         //               esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
389         //               esdTrackCuts->SetRequireTPCRefit(kFALSE);
390         //               esdTrackCuts->SetRequireTPCStandAlone(kTRUE);
391         //               esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
392         //               esdTrackCuts->SetMinNClustersTPC(minNClustersTPC);
393         //               esdTrackCuts->SetMaxChi2PerClusterTPC(maxChi2PerClusterTPC);
394         //               esdTrackCuts->SetMaxDCAToVertexXY(maxDCAtoVertexXY);
395         //               esdTrackCuts->SetMaxDCAToVertexZ(maxDCAtoVertexZ);
396         //               esdTrackCuts->SetDCAToVertex2D(kTRUE);
397         
398
399
400         //      fEsdTrackCuts->SetAcceptKinkDaughters(kFALSE);
401         //      fV0Reader->SetESDtrackCuts(fEsdTrackCuts);
402 }
403
404 void AliAnalysisTaskGammaConversion::UserExec(Option_t */*option*/)
405 {
406         // Execute analysis for current event
407
408         //      Load the esdpid from the esdhandler if exists (tender was applied) otherwise set the Bethe Bloch parameters
409
410         AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
411         AliESDInputHandler *esdHandler=0x0;
412         if ( (esdHandler=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler())) && esdHandler->GetESDpid() ){
413                 AliV0Reader::SetESDpid(esdHandler->GetESDpid());
414         } else {
415                 //load esd pid bethe bloch parameters depending on the existance of the MC handler
416                 // yes: MC parameters
417                 // no:  data parameters
418                 if (!AliV0Reader::GetESDpid()){
419                         if (fMCEvent ) {
420                                 AliV0Reader::InitESDpid();
421                         } else {
422                                 AliV0Reader::InitESDpid(1);
423                         }
424                 }
425         } 
426
427         if(fAODGamma) fAODGamma->Clear();
428         
429
430         Int_t eventQuality=-1;
431         if (fMCEvent ) {
432                 // To avoid crashes due to unzip errors. Sometimes the trees are not there.
433
434                 AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
435                 if (!mcHandler){ 
436                         AliError("Could not retrive MC event handler!"); 
437
438                         eventQuality=0;
439                         fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
440                 }
441                 if (!mcHandler->InitOk() ){
442                         eventQuality=0;
443                         fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
444                 }
445                 if (!mcHandler->TreeK() ){
446                         eventQuality=0;
447                         fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
448                 }
449                 if (!mcHandler->TreeTR() ) {
450                         eventQuality=0;
451                         fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
452                 }
453
454                 if (eventQuality > -1) {
455                   PostAODEvent();
456                   return;
457                 }
458         }
459         
460
461         fV0Reader->SetInputAndMCEvent(InputEvent(), MCEvent());
462
463         //Process hadronic interactions
464         if(fDoHadInt == kTRUE){
465                 ProcessHadronicInteraction(fESDEvent);
466         }
467
468         fV0Reader->Initialize();
469         fDoMCTruth = fV0Reader->GetDoMCTruth();
470
471         
472         if(fKFReconstructedGammasTClone == NULL){
473                 fKFReconstructedGammasTClone = new TClonesArray("AliKFConversionPhoton",0);
474         }
475         if(fCurrentEventPosElectronTClone == NULL){
476                 fCurrentEventPosElectronTClone = new TClonesArray("AliESDtrack",0);
477         }
478         if(fCurrentEventNegElectronTClone == NULL){
479                 fCurrentEventNegElectronTClone = new TClonesArray("AliESDtrack",0);
480         }
481         if(fKFReconstructedGammasCutTClone == NULL){
482                 fKFReconstructedGammasCutTClone = new TClonesArray("AliKFConversionPhoton",0);
483         }
484         if(fPreviousEventTLVNegElectronTClone == NULL){
485                 fPreviousEventTLVNegElectronTClone = new TClonesArray("TLorentzVector",0);
486         }
487         if(fPreviousEventTLVPosElectronTClone == NULL){
488                 fPreviousEventTLVPosElectronTClone      = new TClonesArray("TLorentzVector",0);
489         }
490         if(fChargedParticles == NULL){
491                 fChargedParticles = new TClonesArray("AliESDtrack",0);
492         }
493
494         if(fKFReconstructedPi0sTClone == NULL){
495                 fKFReconstructedPi0sTClone = new TClonesArray("AliKFConversionMother",0);
496         }
497  
498 /*      if(fKFRecalculatedGammasTClone == NULL){
499                 fKFRecalculatedGammasTClone = new TClonesArray("AliKFParticle",0);
500         }
501   */
502         if(fTriggerAnalysis== NULL){
503                 fTriggerAnalysis = new AliTriggerAnalysis;
504         }
505
506         //clear TClones
507         fKFReconstructedGammasTClone->Delete();
508         fCurrentEventPosElectronTClone->Delete();
509         fCurrentEventNegElectronTClone->Delete();
510         fKFReconstructedGammasCutTClone->Delete();
511         fPreviousEventTLVNegElectronTClone->Delete();
512         fPreviousEventTLVPosElectronTClone->Delete();
513         fKFReconstructedPi0sTClone->Delete();
514      //   fKFRecalculatedGammasTClone->Delete();
515
516         //clear vectors
517
518         fChargedParticles->Delete();    
519
520         fChargedParticlesId.clear();    
521
522
523         //Clear the data in the v0Reader
524         //      fV0Reader->UpdateEventByEventData();
525
526
527         // Process the MC information
528         if(fDoMCTruth){
529                 ProcessMCData();
530         }
531
532
533         if(!DoEventSelection()) {
534           PostAODEvent();
535           return;
536         }
537
538         
539         //Process the v0 information with no cuts
540         ProcessV0sNoCut();
541
542         // Process the v0 information
543         ProcessV0s();
544         
545
546         //Fill Gamma AOD
547         if(fKFCreateAOD) {
548           FillAODWithConversionGammas() ; 
549         }
550
551
552         // Process reconstructed gammas
553         if(fDoNeutralMeson == kTRUE){
554                 ProcessGammasForNeutralMesonAnalysis();
555
556         }
557         
558         if(fDoMCTruth == kTRUE){
559                 CheckV0Efficiency();
560         }
561         //Process reconstructed gammas electrons for Chi_c Analysis
562         if(fDoChic == kTRUE){
563                 ProcessGammaElectronsForChicAnalysis();
564         }
565         // Process reconstructed gammas for gamma Jet/hadron correlations
566         if(fDoJet == kTRUE){
567                 ProcessGammasForGammaJetAnalysis();
568         }
569         
570         //calculate background if flag is set
571         if(fCalculateBackground){
572                 CalculateBackground();
573         }
574
575         if(fDoNeutralMeson == kTRUE){
576                 //               ProcessConvPHOSGammasForNeutralMesonAnalysis();
577                 if(fDoOmegaMeson == kTRUE){
578                         ProcessGammasForOmegaMesonAnalysis();
579                 }
580         }
581
582
583         //Must set fForceAOD to true for the AOD to get filled. (Unless called by other task)
584         if(fKFForceAOD) {
585                 if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) { 
586                         AliFatal("Cannot run ESD filter without an output event handler");
587          
588                 } else {
589                         if(fAODGamma && fAODGamma->GetEntriesFast() > 0) {
590         AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
591         AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillExtension(kTRUE);      
592                         }
593                 }
594         
595         }
596
597         ///Make sure delta aod is filled if standard aod is filled (for synchronization when reading aod with standard aod)
598         if(fKFCreateAOD && !fKFExchangeAOD) {
599                 AliAODHandler * aodhandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
600                 if (aodhandler && aodhandler->GetFillAOD()) {
601                         AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillExtension(kTRUE);      
602                 }
603         }
604
605
606         //Clear the data in the v0Reader
607         fV0Reader->UpdateEventByEventData();
608         //if(fRecalculateV0ForGamma==kTRUE){
609        //       RecalculateV0ForGamma();
610        // }
611         PostAODEvent();
612         PostData(1, fOutputContainer);
613         PostData(2, fCFManager->GetParticleContainer());        // for CF
614 }
615
616
617 Bool_t AliAnalysisTaskGammaConversion::DoEventSelection() {
618
619
620   Int_t eventQuality = -1;
621
622         //Take Only events with proper trigger
623         /*
624                 if(fTriggerCINT1B){
625                 if(!fV0Reader->GetESDEvent()->IsTriggerClassFired("CINT1B-ABCE-NOPF-ALL")) return;
626                 }
627         */
628         Bool_t v0A                       = fTriggerAnalysis->IsOfflineTriggerFired(fV0Reader->GetESDEvent(), AliTriggerAnalysis::kV0A);
629         Bool_t v0C                       = fTriggerAnalysis->IsOfflineTriggerFired(fV0Reader->GetESDEvent(), AliTriggerAnalysis::kV0C);
630         Bool_t v0AND = v0A && v0C;
631
632         if(fSelectV0AND && !v0AND){
633                 eventQuality=5;
634                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
635                 if(fDoMCTruth){
636                         if(!fV0Reader->GetIsHeavyIon()){
637         CheckMesonProcessTypeEventQuality(eventQuality);
638                         }
639                 }
640
641                 return kFALSE;
642         }
643
644         if(fV0Reader->CheckForPrimaryVertex() == kFALSE){
645                 //              cout<< "Event not taken"<< endl;
646                 eventQuality=1;
647                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
648                 if(fDoMCTruth){
649                         if(!fV0Reader->GetIsHeavyIon()){
650                                 CheckMesonProcessTypeEventQuality(eventQuality);
651                         }
652                 }
653                 return kFALSE; // aborts if the primary vertex does not have contributors.
654         }
655
656          
657
658         if(!fV0Reader->CheckForPrimaryVertexZ() ){
659                 eventQuality=2;
660                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
661                 if(fDoMCTruth){
662                         if(!fV0Reader->GetIsHeavyIon()){
663                                 CheckMesonProcessTypeEventQuality(eventQuality);
664                         }
665                 }
666                 return kFALSE;
667         }
668
669
670         if(fV0Reader->GetESDEvent()->GetPrimaryVertexTracks()->GetNContributors()>0) {
671                 fHistograms->FillHistogram("ESD_GlobalPrimaryVtxZ",fV0Reader->GetESDEvent()->GetPrimaryVertex()->GetZ());
672         }else{
673                 if(fV0Reader->GetESDEvent()->GetPrimaryVertexSPD()->GetNContributors()>0) {
674                         fHistograms->FillHistogram("ESD_SPDPrimaryVtxZ",fV0Reader->GetESDEvent()->GetPrimaryVertex()->GetZ());
675                 }
676         }
677
678         if(fRemovePileUp && fV0Reader->GetESDEvent()->IsPileupFromSPD()) {
679                 eventQuality=4;
680                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
681                 return kFALSE;
682         }
683         
684
685         Int_t tTracklet=0, tITSTPC=0, tITSPure=0;
686         fV0Reader->GetESDEvent()->EstimateMultiplicity(tTracklet, tITSTPC, tITSPure, 0.8);
687         Int_t fMultiplicityITS = tITSPure;
688
689         fMultiplicity = fEsdTrackCuts->CountAcceptedTracks(fV0Reader->GetESDEvent());
690         Int_t fMultiplicityStandard = fMultiplicity;
691
692         if( fUseHBTMultiplicity==1) {
693                 fMultiplicity = fMultiplicityITS;
694
695         }
696
697
698         fHistograms->FillHistogram("ESD_MultiplicityDeviation",fMultiplicityStandard,fMultiplicityITS);
699
700         
701
702         if(fUseMultiplicity!=0 && CalculateMultiplicityBin()!=fUseMultiplicityBin ){
703                 eventQuality=6;
704                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
705                 return kFALSE;
706         }
707
708         
709         if(fUseHBTMultiplicity!=0 && CalculateMultiplicityBin()!=fUseHBTMultiplicityBin ){
710                 eventQuality=6;
711                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
712                 return kFALSE;
713         }
714
715
716         if(fV0Reader->GetIsHeavyIon()){
717                 if(fUseCentrality>0){
718                         AliCentrality *esdCentrality = fV0Reader->GetESDEvent()->GetCentrality();
719                         Int_t centralityC = -1;
720
721                         if(fUseCentrality==1){
722         centralityC = esdCentrality->GetCentralityClass10("V0M");
723         if( centralityC != fUseCentralityBin ){
724                 eventQuality=7;
725                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
726                 return kFALSE;
727         }
728                         }
729
730                         if(fUseCentrality==2){
731         centralityC = esdCentrality->GetCentralityClass10("CL1");
732         if( centralityC != fUseCentralityBin ){
733                 eventQuality=7;
734                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
735                 return kFALSE;
736         }
737                         }
738
739                         ////////////////////////////////////// RRnew start /////////////////////////////////////////////////////
740                         if(fUseCentrality==3){
741         centralityC = esdCentrality->GetCentralityClass10("V0M");
742         if( (fUseCentralityBin == 0) && (centralityC!=0) ){ // 0-10%
743                 eventQuality=7;
744                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
745                 return kFALSE;          
746         }
747         if( (fUseCentralityBin == 1) && (centralityC!=1) ){ // 10-20%
748                 eventQuality=7;
749                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
750                 return kFALSE;
751         }
752         if( (fUseCentralityBin == 2) && (centralityC!=2) && (centralityC!=3) ){ // 20-40%
753                 eventQuality=7;
754                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
755                 return kFALSE;
756         }
757         if( (fUseCentralityBin == 3) && (centralityC!=0) && (centralityC!=1) ){ // 0-20%
758                 eventQuality=7;
759                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
760                 return kFALSE;
761         }
762         if( (fUseCentralityBin == 4) && (centralityC!=4) && (centralityC!=5) ){ // 40-60%
763                 eventQuality=7;
764                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
765                 return kFALSE;
766         }
767         if( (fUseCentralityBin == 6) && (centralityC!=6) && (centralityC!=7) && (centralityC!=8) ){ // 60-90%
768                 eventQuality=7;
769                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
770                 return kFALSE;
771         }
772         if( (fUseCentralityBin == 7) && (centralityC!=6) && (centralityC!=7) ){ // 60-80%
773                 eventQuality=7;
774                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
775                 return kFALSE;
776         }
777         if( (fUseCentralityBin == 8) && (centralityC>=8) ){ // 0-80%
778                 eventQuality=7;
779                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
780                 return kFALSE;
781         }
782         if( (fUseCentralityBin == 9) && (centralityC>=9) ){ // 0-90%
783                 eventQuality=7;
784                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
785                 return kFALSE;
786         }
787                         }
788
789                         if(fUseCentrality==4){
790         centralityC = esdCentrality->GetCentralityClass10("CL1");
791         if( (fUseCentralityBin == 0) && (centralityC!=0) ){ // 0-10%
792                 eventQuality=7;
793                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
794                 return kFALSE;          
795         }
796         if( (fUseCentralityBin == 1) && (centralityC!=1) ){ // 10-20%
797                 eventQuality=7;
798                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
799                 return kFALSE;
800         }
801         if( (fUseCentralityBin == 2) && (centralityC!=2) && (centralityC!=3) ){ // 20-40%
802                 eventQuality=7;
803                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
804                 return kFALSE;
805         }
806         if( (fUseCentralityBin == 4) && (centralityC!=4) && (centralityC!=5) ){ // 40-60%
807                 eventQuality=7;
808                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
809                 return kFALSE;
810         }
811         if( (fUseCentralityBin == 6) && (centralityC!=6) && (centralityC!=7) && (centralityC!=8) ){ // 60-90%
812                 eventQuality=7;
813                 fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
814                 return kFALSE;
815         }
816                         }
817                         ////////////////////////////////////// RRnew end ///////////////////////////////////////////////////////
818                         
819                 }
820         }
821
822
823         eventQuality=3;
824
825         fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
826
827
828
829         fHistograms->FillHistogram("ESD_NumberOfGoodESDTracks",fMultiplicity);
830         if (fV0Reader->GetNumberOfContributorsVtx()>=1){
831                 fHistograms->FillHistogram("ESD_NumberOfGoodESDTracksVtx",fMultiplicity);
832         } 
833
834
835
836         return kTRUE;
837
838 }
839
840
841 ///_______________________________________________________________
842 void AliAnalysisTaskGammaConversion::PostAODEvent() {
843   ///Post AOD array to correct output slot
844   if(fKFCreateAOD) {
845         if(!fKFExchangeAOD) {
846           PostData(0, fAODGamma);
847         }  else {
848           PostData(3, fAODGamma); 
849         }
850   }
851 }
852
853 // void AliAnalysisTaskGammaConversion::ConnectInputData(Option_t *option){
854 //       // see header file for documentation
855 //       //     printf("         ConnectInputData %s\n", GetName());
856
857 //       AliAnalysisTaskSE::ConnectInputData(option);
858
859 //       if(fV0Reader == NULL){
860 //               // Write warning here cuts and so on are default if this ever happens
861 //       }
862 //       fV0Reader->Initialize();
863 //       fDoMCTruth = fV0Reader->GetDoMCTruth();
864 // }
865
866 void AliAnalysisTaskGammaConversion::CheckMesonProcessTypeEventQuality(Int_t evtQ){
867         // Check meson process type event quality
868         fStack= MCEvent()->Stack();
869         fGCMCEvent=MCEvent();
870
871  
872
873         for (Int_t iTracks = 0; iTracks < fStack->GetNprimary(); iTracks++) {
874                 TParticle* particle = (TParticle *)fStack->Particle(iTracks);
875                 if (!particle) {
876                         //print warning here
877                         continue;
878                 }
879                 //               if(particle->GetPdgCode()!=111 || particle->GetPdgCode()!=221){
880                 //                       continue;
881                 //               }
882                 
883                 Double_t rapidity;
884                 if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
885                         rapidity=8.;
886                 }
887                 else{
888                         rapidity = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())));
889                 }       
890                 
891
892                 if( particle->GetPdgCode()==111){
893                         fHistograms->FillHistogram("MC_Test_AllPi0_Pt", particle->Pt());
894                         if(particle->GetNDaughters()==2){
895                                 fHistograms->FillHistogram("MC_Test_2DaughPi0_Pt", particle->Pt());
896                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
897                                         fHistograms->FillHistogram("MC_Test_2DaughPi0_Rap_Pt", particle->Pt());
898                                 }
899                         }
900                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
901                                 fHistograms->FillHistogram("MC_Test_Pi0_Rap_Pt", particle->Pt());
902                         }
903                 }
904                         
905                         
906                 if(particle->GetPdgCode()==221){
907                         fHistograms->FillHistogram("MC_Test_AllEta_Pt", particle->Pt());
908                         if(particle->GetNDaughters()==2){
909                                 fHistograms->FillHistogram("MC_Test_2DaughEta_Pt", particle->Pt());
910                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
911                                         fHistograms->FillHistogram("MC_Test_2DaughEta_Rap_Pt", particle->Pt());
912                                 }
913                         }
914                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
915                                 fHistograms->FillHistogram("MC_Test_Eta_Rap_Pt", particle->Pt());
916                         }
917                         
918                 }
919
920
921                 if(particle->GetPdgCode()!=111){                 //Pi0
922                         continue;
923                 }
924
925
926                 if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ) continue; 
927                 if(fV0Reader->GetIsHeavyIon()) continue;
928
929                 if(evtQ==1){
930                         switch(GetProcessType(fGCMCEvent)){
931                         case    kProcSD:
932                                 fHistograms->FillHistogram("MC_SD_EvtQ1_Pi0_Pt", particle->Pt());
933                                 break;
934                         case    kProcDD:
935                                 fHistograms->FillHistogram("MC_DD_EvtQ1_Pi0_Pt", particle->Pt());
936                                 break;
937                         case    kProcND:
938                                 fHistograms->FillHistogram("MC_ND_EvtQ1_Pi0_Pt", particle->Pt());
939                                 break;
940                         default:
941                                 AliError("Unknown Process");
942                         }
943                 }
944                 if(evtQ==2){
945                         switch(GetProcessType(fGCMCEvent)){
946                         case    kProcSD:
947                                 fHistograms->FillHistogram("MC_SD_EvtQ2_Pi0_Pt", particle->Pt());
948                         break;
949                         case    kProcDD:
950                                 fHistograms->FillHistogram("MC_DD_EvtQ2_Pi0_Pt", particle->Pt());
951                         break;
952                         case    kProcND:
953                                 fHistograms->FillHistogram("MC_ND_EvtQ2_Pi0_Pt", particle->Pt());
954                         break;
955                         default:
956                                 AliError("Unknown Process");
957                         }
958                 }
959
960                 if(evtQ==4){
961                         switch(GetProcessType(fGCMCEvent)){
962                         case    kProcSD:
963                                 fHistograms->FillHistogram("MC_SD_EvtQ4_Pi0_Pt", particle->Pt());
964                         break;
965                         case    kProcDD:
966                                 fHistograms->FillHistogram("MC_DD_EvtQ4_Pi0_Pt", particle->Pt());
967                         break;
968                         case    kProcND:
969                                 fHistograms->FillHistogram("MC_ND_EvtQ4_Pi0_Pt", particle->Pt());
970                         break;
971                         default:
972                                 AliError("Unknown Process");
973                         }
974                 }
975
976                 if(evtQ==5){
977                         switch(GetProcessType(fGCMCEvent)){
978                         case    kProcSD:
979                                 fHistograms->FillHistogram("MC_SD_EvtQ5_Pi0_Pt", particle->Pt());
980                         break;
981                         case    kProcDD:
982                                 fHistograms->FillHistogram("MC_DD_EvtQ5_Pi0_Pt", particle->Pt());
983                         break;
984                         case    kProcND:
985                                 fHistograms->FillHistogram("MC_ND_EvtQ5_Pi0_Pt", particle->Pt());
986                         break;
987                         default:
988                                 AliError("Unknown Process");
989                         }
990                 }
991
992         }
993
994 }
995
996 void AliAnalysisTaskGammaConversion::ProcessMCData(){
997         // see header file for documentation
998         //InputEvent(), MCEvent());
999         /* TestAnaMarin
1000                 fStack = fV0Reader->GetMCStack();
1001                 fMCTruth = fV0Reader->GetMCTruth();     // for CF
1002                 fGCMCEvent = fV0Reader->GetMCEvent();   // for CF
1003         */
1004         fStack= MCEvent()->Stack();
1005         fGCMCEvent=MCEvent();
1006                 
1007         // for CF
1008         Double_t containerInput[3];
1009         if(fDoCF){
1010                 if(!fGCMCEvent) cout << "NO MC INFO FOUND" << endl;
1011                 fCFManager->SetEventInfo(fGCMCEvent);
1012         } 
1013         // end for CF
1014                 
1015         if(fV0Reader->CheckForPrimaryVertex() == kFALSE){
1016                 return; // aborts if the primary vertex does not have contributors.
1017         }
1018         
1019         Int_t nCharged = 0;
1020         Int_t nCharged150MeV = 0;
1021
1022         for (Int_t iTracks = 0; iTracks < fStack->GetNprimary(); iTracks++) {
1023                 //      for (Int_t iTracks = 0; iTracks < fStack->GetNtrack(); iTracks++) {
1024                 TParticle* particle = (TParticle *)fStack->Particle(iTracks);
1025
1026                 if (!particle) {
1027                    //print warning here
1028                    continue;
1029                 }
1030
1031
1032                 if(fV0Reader->GetExcludeBackgroundEventForGammaCorrection()){
1033                    Bool_t isFromBGEvent = kFALSE;
1034                    isFromBGEvent = fV0Reader->IsParticleFromBGEvent(iTracks);
1035                    if(isFromBGEvent) continue;
1036                 }
1037                 
1038
1039                 
1040                 ///////////////////////Begin Chic Analysis/////////////////////////////
1041                 if(fDoChic) {
1042                         if(particle->GetPdgCode() == 443){//Is JPsi     
1043                                 if(particle->GetNDaughters()==2){
1044                                         if(TMath::Abs(fStack->Particle(particle->GetFirstDaughter())->GetPdgCode()) == 11 &&
1045                                                 TMath::Abs(fStack->Particle(particle->GetLastDaughter())->GetPdgCode()) == 11){
1046
1047                                                 TParticle* daug0 = fStack->Particle(particle->GetFirstDaughter());
1048                                                 TParticle* daug1 = fStack->Particle(particle->GetLastDaughter());
1049                                                 if(TMath::Abs(daug0->Eta()) < 0.9 && TMath::Abs(daug1->Eta()) < 0.9)
1050                                                         fHistograms->FillTable("Table_Electrons",3);//e+ e-     from J/Psi inside acceptance
1051                                                                 
1052                                                 if( TMath::Abs(daug0->Eta()) < 0.9){
1053                                                         if(daug0->GetPdgCode() == -11)
1054                                                                 fHistograms->FillTable("Table_Electrons",1);//e+        from J/Psi inside acceptance
1055                                                         else
1056                                                                 fHistograms->FillTable("Table_Electrons",2);//e-         from J/Psi inside acceptance
1057                                                                         
1058                                                 }
1059                                                 if(TMath::Abs(daug1->Eta()) < 0.9){
1060                                                         if(daug1->GetPdgCode() == -11)
1061                                                                 fHistograms->FillTable("Table_Electrons",1);//e+        from J/Psi inside acceptance
1062                                                         else
1063                                                                 fHistograms->FillTable("Table_Electrons",2);//e-         from J/Psi inside acceptance
1064                                                 }
1065                                         }
1066                                 }
1067                         }
1068                         //                                                      const int CHI_C0         = 10441;
1069                         //                                                      const int CHI_C1         = 20443;
1070                         //                                                      const int CHI_C2         = 445
1071                         if(particle->GetPdgCode() == 22){//gamma from JPsi
1072                                 if(particle->GetMother(0) > -1){
1073                                         if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 10441 ||
1074                                         fStack->Particle(particle->GetMother(0))->GetPdgCode() == 20443 ||
1075                                         fStack->Particle(particle->GetMother(0))->GetPdgCode() == 445){
1076                                                 if(TMath::Abs(particle->Eta()) < 1.2)
1077                                                         fHistograms->FillTable("Table_Electrons",17);// gamma from chic inside accptance
1078                                         }
1079                                 }
1080                         }
1081                         if(particle->GetPdgCode() == 10441 || particle->GetPdgCode() == 20443 || particle->GetPdgCode() == 445){
1082                                 if( particle->GetNDaughters() == 2){
1083                                         TParticle* daug0 = fStack->Particle(particle->GetFirstDaughter());
1084                                         TParticle* daug1 = fStack->Particle(particle->GetLastDaughter());
1085                                                                 
1086                                         if( (daug0->GetPdgCode() == 443 || daug0->GetPdgCode() == 22) && (daug1->GetPdgCode() == 443 || daug1->GetPdgCode() == 22) ){
1087                                                 if( daug0->GetPdgCode() == 443){
1088                                                         TParticle* daugE0 = fStack->Particle(daug0->GetFirstDaughter());
1089                                                         TParticle* daugE1 = fStack->Particle(daug0->GetLastDaughter());
1090                                                         if( TMath::Abs(daug1->Eta()) < 1.2 && TMath::Abs(daugE0->Eta()) < 0.9 && TMath::Abs(daugE1->Eta()) < 0.9 )
1091                                                                 fHistograms->FillTable("Table_Electrons",18);
1092                                                                 
1093                                                 } else if (daug1->GetPdgCode() == 443){
1094                                                         TParticle* daugE0 = fStack->Particle(daug1->GetFirstDaughter());
1095                                                         TParticle* daugE1 = fStack->Particle(daug1->GetLastDaughter());
1096                                                         if( TMath::Abs(daug0->Eta()) < 1.2 && TMath::Abs(daugE0->Eta()) < 0.9 && TMath::Abs(daugE1->Eta()) < 0.9 )
1097                                                         fHistograms->FillTable("Table_Electrons",18);
1098                                                 }//else if
1099                                         }//gamma o Jpsi
1100                                 }//GetNDaughters
1101                         }
1102                 }
1103                                 
1104                 /////////////////////End Chic Analysis////////////////////////////
1105                                 
1106                 //              if(TMath::Abs(particle->Eta())> fV0Reader->GetEtaCut() )        continue;
1107
1108
1109
1110
1111                 if(particle->Eta() <0.8 && particle->Eta() > (-0.8) && particle->GetPDG()->Charge() != 0) {
1112                    nCharged++;
1113                    if(particle->Pt()>0.150){
1114                    nCharged150MeV++;}
1115                 }
1116                 
1117                 
1118                                 
1119                 if(particle->R()>fV0Reader->GetMaxRCut())       continue; // cuts on distance from collision point
1120                                 
1121                 Double_t tmpPhi=particle->Phi();
1122                                 
1123                 if(particle->Phi()> TMath::Pi()){
1124                         tmpPhi = particle->Phi()-(2*TMath::Pi());
1125                 }
1126                                 
1127                 Double_t rapidity;
1128                 if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
1129                         rapidity=8.;
1130                 } else{
1131                         rapidity = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())));
1132                 }       
1133                                 
1134                 if( particle->GetPdgCode()==111){
1135
1136                         //AM move here, otherwise for evt we consider only pi0 to 2 g
1137                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1138                                 if(!fV0Reader->GetIsHeavyIon()) {
1139                                 
1140                                         switch(GetProcessType(fGCMCEvent)){
1141                                         case    kProcSD:
1142                                                 fHistograms->FillHistogram("MC_SD_EvtQ3_Pi0_Pt", particle->Pt());
1143                                                 break;
1144                                         case    kProcDD:
1145                                                 fHistograms->FillHistogram("MC_DD_EvtQ3_Pi0_Pt", particle->Pt());
1146                                                 break;
1147                                         case    kProcND:
1148                                                 fHistograms->FillHistogram("MC_ND_EvtQ3_Pi0_Pt", particle->Pt());
1149                                                 break;
1150                                         default:
1151                                                 AliError("Unknown Process");
1152                                         }       
1153                                 }       
1154                         }
1155                         fHistograms->FillHistogram("MC_Test_AllPi0_Pt", particle->Pt());
1156                         if(particle->GetNDaughters()==2){
1157                                 fHistograms->FillHistogram("MC_Test_2DaughPi0_Pt", particle->Pt());
1158                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1159                                         fHistograms->FillHistogram("MC_Test_2DaughPi0_Rap_Pt", particle->Pt());
1160                                 }
1161                         }
1162                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1163                                 fHistograms->FillHistogram("MC_Test_Pi0_Rap_Pt", particle->Pt());
1164                         }
1165                 }
1166                         
1167                         
1168                 if(particle->GetPdgCode()==221){
1169                         fHistograms->FillHistogram("MC_Test_AllEta_Pt", particle->Pt());
1170                         if(particle->GetNDaughters()==2){
1171                                 fHistograms->FillHistogram("MC_Test_2DaughEta_Pt", particle->Pt());
1172                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1173                                         fHistograms->FillHistogram("MC_Test_2DaughEta_Rap_Pt", particle->Pt());
1174                                 }
1175                         }
1176                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1177                                 fHistograms->FillHistogram("MC_Test_Eta_Rap_Pt", particle->Pt());
1178                         }
1179                 }
1180
1181                 if(  particle->GetPdgCode()==310 ){
1182                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1183                                 fHistograms->FillHistogram("MC_K0S_Pt", particle->Pt());
1184                         }
1185                 }
1186
1187                 if(iTracks<=fStack->GetNprimary() ){
1188                         if ( particle->GetPdgCode()== -211 ||   particle->GetPdgCode()== 211 ||
1189                                 particle->GetPdgCode()== 2212 ||        particle->GetPdgCode()==-2212 ||
1190                                 particle->GetPdgCode()== 321    ||      particle->GetPdgCode()==-321 ){
1191                                 if(TMath::Abs(particle->Eta())> 0.8 )   continue;        // Eta cut used in charged particle spectrum
1192                                 //if( !particle->IsPhysicalPrimary() ){
1193                                 // cout<<"not Physical primary"<< particle->IsPhysicalPrimary()<<endl;
1194                                 //}
1195                                 if(particle->GetMother(0)>-1){
1196                                         // cout<<"Mother ::"<<fStack->Particle(particle->GetMother(0))->GetPdgCode()<<endl;
1197                                         if (fStack->Particle(particle->GetMother(0))->GetPdgCode()== -211 ||fStack->Particle(particle->GetMother(0))->GetPdgCode()== -3122 ){
1198                                                 //                                              cout<<"Mother K0, lambda::"<<fStack->Particle(particle->GetMother(0))->GetPdgCode()<<endl;
1199                                         continue;
1200                                         }
1201                                 }
1202                                 
1203                                 fHistograms->FillHistogram("MC_PhysicalPrimaryCharged_Pt", particle->Pt());
1204
1205                                 if (particle->GetPdgCode() == 211 ) fHistograms->FillHistogram("MC_PiPlus_Pt", particle->Pt());
1206                                 if (particle->GetPdgCode() == 321 ) fHistograms->FillHistogram("MC_KaonPlus_Pt", particle->Pt());
1207                                 if (particle->GetPdgCode() == 2212 ) fHistograms->FillHistogram("MC_Proton_Pt", particle->Pt());
1208                                 if (particle->GetPdgCode() == -211 ) fHistograms->FillHistogram("MC_PiMinus_Pt", particle->Pt());
1209                                 if (particle->GetPdgCode() == -321 ) fHistograms->FillHistogram("MC_KaonMinus_Pt", particle->Pt());
1210                                 if (particle->GetPdgCode() == -2212 ) fHistograms->FillHistogram("MC_AntiProton_Pt", particle->Pt()); 
1211                         }
1212                         if(TMath::Abs(particle->Eta())<=0.8 ){
1213                                 if (particle->GetPdgCode() == 111 ) fHistograms->FillHistogram("MC_Pi0_Test_Pt", particle->Pt());
1214                         }
1215                 }
1216
1217
1218                 //process the gammas
1219                 if (particle->GetPdgCode() == 22){
1220                         if(TMath::Abs(particle->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(particle->Eta())< fV0Reader->GetEtaCutMin())       continue;                       
1221
1222                         if(particle->GetMother(0) >-1 && fStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
1223                                 continue; // no photon as mothers!
1224                         }
1225                         
1226                         if(particle->GetMother(0) >= fStack->GetNprimary()){
1227                                 continue; // the gamma has a mother, and it is not a primary particle
1228                         }
1229                                 
1230                         if(particle->GetMother(0) >-1){
1231                                 fHistograms->FillHistogram("MC_DecayAllGamma_Pt", particle->Pt()); // All
1232                                 switch(fStack->Particle(particle->GetMother(0))->GetPdgCode()){
1233                                         case 111: // Pi0
1234                                                 fHistograms->FillHistogram("MC_DecayPi0Gamma_Pt", particle->Pt());
1235                                                 break;
1236                                         case 113: // Rho0
1237                                                 fHistograms->FillHistogram("MC_DecayRho0Gamma_Pt", particle->Pt());
1238                                                 break;
1239                                         case 221: // Eta
1240                                                 fHistograms->FillHistogram("MC_DecayEtaGamma_Pt", particle->Pt());
1241                                                 break;
1242                                         case 223: // Omega
1243                                                 fHistograms->FillHistogram("MC_DecayOmegaGamma_Pt", particle->Pt());
1244                                                 break;
1245                                         case 310: // K_s0
1246                                                 fHistograms->FillHistogram("MC_DecayK0sGamma_Pt", particle->Pt());
1247                                                 break;
1248                                         case 331: // Eta'
1249                                                 fHistograms->FillHistogram("MC_DecayEtapGamma_Pt", particle->Pt());
1250                                                 break;
1251                                         case 333: // Phi
1252                                                 fHistograms->FillHistogram("MC_DecayPhiGamma_Pt", particle->Pt());
1253                                                 break;
1254                                 }
1255                         }
1256                         
1257                         fHistograms->FillHistogram("MC_allGamma_Energy", particle->Energy());
1258                         fHistograms->FillHistogram("MC_allGamma_Pt", particle->Pt());
1259                         fHistograms->FillHistogram("MC_allGamma_Eta", particle->Eta());
1260                         fHistograms->FillHistogram("MC_allGamma_Phi", tmpPhi);
1261                         fHistograms->FillHistogram("MC_allGamma_Rapid", rapidity);
1262                                         
1263                         // for CF
1264                         if(fDoCF){
1265                                 containerInput[0] = particle->Pt();
1266                                 containerInput[1] = particle->Eta();
1267                                 if(particle->GetMother(0) >=0){
1268                                         containerInput[2] = fStack->Particle(particle->GetMother(0))->GetMass();
1269                                 } else{
1270                                         containerInput[2]=-1;
1271                                 }
1272                                 fCFManager->GetParticleContainer()->Fill(containerInput,kStepGenerated);                                        // generated gamma
1273                         }
1274                         
1275                         if(particle->GetMother(0) < 0 || //Phojet p+p -> Direct Photons have no mother
1276                         ((particle->GetMother(0) > -1) && 
1277                         ((TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) < 10)|| 
1278                         (TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) ==21) )) //Pythia p+p -> Direct Photons have quarksor gluons as mother
1279                         ){       // direct gamma
1280                                 fHistograms->FillHistogram("MC_allDirectGamma_Energy",particle->Energy());
1281                                 fHistograms->FillHistogram("MC_allDirectGamma_Pt", particle->Pt());
1282                                 fHistograms->FillHistogram("MC_allDirectGamma_Eta", particle->Eta());
1283                                 fHistograms->FillHistogram("MC_allDirectGamma_Phi", tmpPhi);
1284                                 fHistograms->FillHistogram("MC_allDirectGamma_Rapid", rapidity);                                
1285                         }
1286                                         
1287                         // looking for conversion (electron + positron from pairbuilding (= 5) )
1288                         TParticle* ePos = NULL;
1289                         TParticle* eNeg = NULL;
1290                                         
1291                         if(particle->GetNDaughters() >= 2){
1292                                 for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1293                                         TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1294                                         if(tmpDaughter->GetUniqueID() == 5){
1295                                                 if(tmpDaughter->GetPdgCode() == 11){
1296                                                         eNeg = tmpDaughter;
1297                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1298                                                         ePos = tmpDaughter;
1299                                                 }
1300                                         }
1301                                 }
1302                         }
1303                                                 
1304                         if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
1305                                 continue;
1306                         }
1307                                         
1308                                         
1309                         Double_t ePosPhi = ePos->Phi();
1310                         if(ePos->Phi()> TMath::Pi()) ePosPhi = ePos->Phi()-(2*TMath::Pi());
1311                                         
1312                         Double_t eNegPhi = eNeg->Phi();
1313                         if(eNeg->Phi()> TMath::Pi()) eNegPhi = eNeg->Phi()-(2*TMath::Pi());
1314                                                         
1315                         if(ePos->Pt()<fV0Reader->GetSinglePtCut() || eNeg->Pt()<fV0Reader->GetSinglePtCut()){
1316                                 continue; // no reconstruction below the Pt cut
1317                         }
1318                                         
1319                         if( TMath::Abs(ePos->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(ePos->Eta())< fV0Reader->GetEtaCutMin()  || 
1320                             TMath::Abs(eNeg->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(eNeg->Eta())< fV0Reader->GetEtaCutMin() ) {
1321                                 continue;
1322                         }       
1323                                         
1324                         if(ePos->R()>fV0Reader->GetMaxRCut()){
1325                                 continue; // cuts on distance from collision point
1326                         }
1327
1328                         if(TMath::Abs(ePos->Vz()) > fV0Reader->GetMaxZCut()){
1329                                 continue;        // outside material
1330                         }
1331                         if(TMath::Abs(eNeg->Vz()) > fV0Reader->GetMaxZCut()){
1332                                 continue;        // outside material
1333                         }
1334
1335                         if( ePos->R() <= ((TMath::Abs(ePos->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue())){
1336                                 continue;                                                        // line cut to exclude regions where we do not reconstruct
1337                         } else if ( fV0Reader->GetEtaCutMin() != -0.1 &&   ePos->R() >= ((TMath::Abs(ePos->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())       ){
1338                                 continue;
1339                         }
1340                                         
1341                         if( eNeg->R() <= ((TMath::Abs(eNeg->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue())){
1342                                 continue;                                                        // line cut to exclude regions where we do not reconstruct
1343                         } else if ( fV0Reader->GetEtaCutMin() != -0.1 &&   eNeg->R() >= ((TMath::Abs(eNeg->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())       ){
1344                                 continue;
1345                         }
1346                                         
1347                         // for CF
1348                         if(fDoCF){
1349                                 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructable);  // reconstructable gamma        
1350                         }
1351                         fHistograms->FillHistogram("MC_ConvGamma_Energy", particle->Energy());
1352                         fHistograms->FillHistogram("MC_ConvGamma_Pt", particle->Pt());
1353                         // Move down, in the if that mother exists
1354                         //                      if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 221)
1355                         //                      fHistograms->FillHistogram("MC_ConvEtaGamma_Pt", particle->Pt());
1356                         fHistograms->FillHistogram("MC_ConvGamma_Eta", particle->Eta());
1357                         fHistograms->FillHistogram("MC_ConvGamma_Phi", tmpPhi);
1358                         fHistograms->FillHistogram("MC_ConvGamma_Rapid", rapidity);
1359                         fHistograms->FillHistogram("MC_ConvGamma_Pt_Eta", particle->Pt(),particle->Eta());
1360                                         
1361                         fHistograms->FillHistogram("MC_E_Energy", eNeg->Energy());
1362                         fHistograms->FillHistogram("MC_E_Pt", eNeg->Pt());
1363                         fHistograms->FillHistogram("MC_E_Eta", eNeg->Eta());
1364                         fHistograms->FillHistogram("MC_E_Phi", eNegPhi);
1365                                         
1366                         fHistograms->FillHistogram("MC_P_Energy", ePos->Energy());
1367                         fHistograms->FillHistogram("MC_P_Pt", ePos->Pt());
1368                         fHistograms->FillHistogram("MC_P_Eta", ePos->Eta());
1369                         fHistograms->FillHistogram("MC_P_Phi", ePosPhi);
1370                                         
1371                         if(!fV0Reader->GetIsHeavyIon()){
1372                                         
1373                                 // begin Mapping 
1374                                 Int_t rBin              = fHistograms->GetRBin(ePos->R());
1375                                 Int_t zBin              = fHistograms->GetZBin(ePos->Vz());
1376                                 Int_t phiBin    = fHistograms->GetPhiBin(particle->Phi());
1377                                 Double_t rFMD=30;
1378                                 Double_t rITSTPCMin=40;
1379                                 Double_t rITSTPCInt=55;
1380                                 Double_t rITSTPCMax=72.5;
1381                                 
1382                                 TVector3 vtxPos(ePos->Vx(),ePos->Vy(),ePos->Vz());      
1383                                 
1384                                 TString nameMCMappingPhiR="";
1385                                 nameMCMappingPhiR.Form("MC_Conversion_Mapping_Phi%02d_R%02d",phiBin,rBin);
1386                                 // fHistograms->FillHistogram(nameMCMappingPhiR, ePos->Vz(), particle->Eta());
1387                                 
1388                                 TString nameMCMappingPhi="";
1389                                 nameMCMappingPhi.Form("MC_Conversion_Mapping_Phi%02d",phiBin);
1390                                 //                      fHistograms->FillHistogram(nameMCMappingPhi, particle->Eta());
1391                                 //fHistograms->FillHistogram(nameMCMappingPhi, ePos->Vz(), particle->Eta());
1392                                 
1393                                 TString nameMCMappingR="";
1394                                 nameMCMappingR.Form("MC_Conversion_Mapping_R%02d",rBin);
1395                                 //                      fHistograms->FillHistogram(nameMCMappingR, particle->Eta());
1396                                 //fHistograms->FillHistogram(nameMCMappingR,ePos->Vz(), particle->Eta());
1397                                 
1398                                 TString nameMCMappingPhiInR="";
1399                                 nameMCMappingPhiInR.Form("MC_Conversion_Mapping_Phi_in_R_%02d",rBin);
1400                                 //                      fHistograms->FillHistogram(nameMCMappingPhiInR, tmpPhi);
1401                                 fHistograms->FillHistogram(nameMCMappingPhiInR, vtxPos.Phi());
1402                                 
1403                                 TString nameMCMappingZInR="";
1404                                 nameMCMappingZInR.Form("MC_Conversion_Mapping_Z_in_R_%02d",rBin);
1405                                 fHistograms->FillHistogram(nameMCMappingZInR,ePos->Vz() );
1406                                 
1407                                 
1408                                 TString nameMCMappingPhiInZ="";
1409                                 nameMCMappingPhiInZ.Form("MC_Conversion_Mapping_Phi_in_Z_%02d",zBin);
1410                                 //                      fHistograms->FillHistogram(nameMCMappingPhiInR, tmpPhi);
1411                                 fHistograms->FillHistogram(nameMCMappingPhiInZ, vtxPos.Phi());
1412                                 
1413                                 
1414                                 if(ePos->R()<rFMD){
1415                                         TString nameMCMappingFMDPhiInZ="";
1416                                         nameMCMappingFMDPhiInZ.Form("MC_Conversion_Mapping_FMD_Phi_in_Z_%02d",zBin);
1417                                         fHistograms->FillHistogram(nameMCMappingFMDPhiInZ, vtxPos.Phi());
1418                                 }
1419                         
1420                                 if(ePos->R()>rITSTPCMin && ePos->R()<rITSTPCInt){
1421                                         TString nameMCMappingITSTPCPhiInZ="";
1422                                         nameMCMappingITSTPCPhiInZ.Form("MC_Conversion_Mapping_ITSTPC_Phi_in_Z_%02d",zBin);
1423                                         fHistograms->FillHistogram(nameMCMappingITSTPCPhiInZ, vtxPos.Phi());
1424                                 }
1425                         
1426                                 if(ePos->R()>rITSTPCInt && ePos->R()<rITSTPCMax){
1427                                         TString nameMCMappingITSTPC2PhiInZ="";
1428                                         nameMCMappingITSTPC2PhiInZ.Form("MC_Conversion_Mapping_ITSTPC2_Phi_in_Z_%02d",zBin);
1429                                         fHistograms->FillHistogram(nameMCMappingITSTPC2PhiInZ, vtxPos.Phi());
1430                                 }
1431
1432                                 TString nameMCMappingRInZ="";
1433                                 nameMCMappingRInZ.Form("MC_Conversion_Mapping_R_in_Z_%02d",zBin);
1434                                 fHistograms->FillHistogram(nameMCMappingRInZ,ePos->R() );
1435                                 
1436                                 if(particle->Pt() > fLowPtMapping && particle->Pt()< fHighPtMapping){
1437                                         TString nameMCMappingMidPtPhiInR="";
1438                                         nameMCMappingMidPtPhiInR.Form("MC_Conversion_Mapping_MidPt_Phi_in_R_%02d",rBin);
1439                                         fHistograms->FillHistogram(nameMCMappingMidPtPhiInR, vtxPos.Phi());
1440                                         
1441                                         TString nameMCMappingMidPtZInR="";
1442                                         nameMCMappingMidPtZInR.Form("MC_Conversion_Mapping_MidPt_Z_in_R_%02d",rBin);
1443                                         fHistograms->FillHistogram(nameMCMappingMidPtZInR,ePos->Vz() );
1444                                         
1445                                         
1446                                         TString nameMCMappingMidPtPhiInZ="";
1447                                         nameMCMappingMidPtPhiInZ.Form("MC_Conversion_Mapping_MidPt_Phi_in_Z_%02d",zBin);
1448                                         fHistograms->FillHistogram(nameMCMappingMidPtPhiInZ, vtxPos.Phi());
1449                                         
1450                                         
1451                                         if(ePos->R()<rFMD){
1452                                                 TString nameMCMappingMidPtFMDPhiInZ="";
1453                                                 nameMCMappingMidPtFMDPhiInZ.Form("MC_Conversion_Mapping_MidPt_FMD_Phi_in_Z_%02d",zBin);
1454                                                 fHistograms->FillHistogram(nameMCMappingMidPtFMDPhiInZ, vtxPos.Phi());
1455                                         }
1456                                 
1457                                         TString nameMCMappingMidPtRInZ="";
1458                                         nameMCMappingMidPtRInZ.Form("MC_Conversion_Mapping_MidPt_R_in_Z_%02d",zBin);
1459                                         fHistograms->FillHistogram(nameMCMappingMidPtRInZ,ePos->R() );
1460                                         
1461                                 }
1462                         }
1463
1464                         //end mapping
1465                                         
1466                         fHistograms->FillHistogram("MC_Conversion_R",ePos->R());
1467                         fHistograms->FillHistogram("MC_Conversion_ZR",ePos->Vz(),ePos->R());
1468                         fHistograms->FillHistogram("MC_Conversion_XY",ePos->Vx(),ePos->Vy());
1469                         fHistograms->FillHistogram("MC_Conversion_OpeningAngle",GetMCOpeningAngle(ePos, eNeg));
1470                         fHistograms->FillHistogram("MC_ConvGamma_E_AsymmetryP",particle->P(),eNeg->P()/particle->P());
1471                         fHistograms->FillHistogram("MC_ConvGamma_P_AsymmetryP",particle->P(),ePos->P()/particle->P());
1472
1473
1474                         if(particle->GetMother(0) < 0 || //Phojet p+p -> Direct Photons have no mother
1475                                  ((particle->GetMother(0) > -1) && 
1476                                         ((TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) < 10)|| 
1477                                          (TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) ==21) )) //Pythia p+p -> Direct Photons have quarksor gluons as mother
1478                                  ){      // direct gamma, still inside converted
1479                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Energy",particle->Energy());
1480                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Pt", particle->Pt());
1481                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Eta", particle->Eta());
1482                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Phi", tmpPhi);
1483                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Rapid", rapidity);
1484                                                 
1485                         } else{  // mother exits 
1486                                 if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 221)
1487                                         fHistograms->FillHistogram("MC_ConvEtaGamma_Pt", particle->Pt());
1488                         /*      if( fStack->Particle(particle->GetMother(0))->GetPdgCode()==10441 ||//chic0 
1489                                 fStack->Particle(particle->GetMother(0))->GetPdgCode()==20443 ||//psi2S
1490                                 fStack->Particle(particle->GetMother(0))->GetPdgCode()==445     //chic2
1491                                 ){ 
1492                                 fMCGammaChic.push_back(particle);
1493                                 }
1494                         */
1495                         }       // end if mother exits
1496                 } // end if particle is a photon
1497                                 
1498                                 
1499                                 
1500                 // process motherparticles (2 gammas as daughters)
1501                 // the motherparticle had already to pass the R and the eta cut, but no line cut.
1502                 // the line cut is just valid for the conversions!
1503
1504                 // RR primary Pi0 debug ////////////////////////////////////////////////////////////////////////////////////////////
1505                 if (particle->GetPdgCode()==111){
1506                         if( TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1507                                 fHistograms->FillHistogram("MC_Pi0_Pt_vs_Rapid_allDaughters", particle->Pt(),rapidity);
1508                         }
1509                 }
1510                 // end RR primary Pi0 debug ////////////////////////////////////////////////////////////////////////////////////////
1511                                 
1512                 if(particle->GetNDaughters() == 2){
1513                                         
1514                         TParticle* daughter0 = (TParticle*)fStack->Particle(particle->GetFirstDaughter());
1515                         TParticle* daughter1 = (TParticle*)fStack->Particle(particle->GetLastDaughter());
1516                                         
1517                         if(daughter0->GetPdgCode() != 22 || daughter1->GetPdgCode() != 22) continue; //check for gamma gamma daughters
1518
1519                         if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ) continue; 
1520
1521                         // Check the acceptance for both gammas
1522                         Bool_t gammaEtaCut = kTRUE;
1523                         if(TMath::Abs(daughter0->Eta()) > fV0Reader->GetEtaCut() || TMath::Abs(daughter0->Eta()) < fV0Reader->GetEtaCutMin() || 
1524                            TMath::Abs(daughter1->Eta()) > fV0Reader->GetEtaCut() || TMath::Abs(daughter1->Eta()) < fV0Reader->GetEtaCutMin()    ) gammaEtaCut = kFALSE;
1525                         
1526                         Bool_t gammaRCut = kTRUE;
1527                         if(daughter0->R() > fV0Reader->GetMaxRCut() || daughter1->R() > fV0Reader->GetMaxRCut() ) gammaRCut = kFALSE;
1528                         
1529                         // check for conversions now -> have to pass eta, R and line cut!
1530                         Bool_t daughter0Electron = kFALSE;
1531                         Bool_t daughter0Positron = kFALSE;
1532                         Bool_t daughter1Electron = kFALSE;
1533                         Bool_t daughter1Positron = kFALSE;
1534                                         
1535                         if(daughter0->GetNDaughters() >= 2){    // first gamma
1536                                 for(Int_t TrackIndex=daughter0->GetFirstDaughter();TrackIndex<=daughter0->GetLastDaughter();TrackIndex++){
1537                                         TParticle *tmpDaughter = fStack->Particle(TrackIndex);
1538                                         if(tmpDaughter->GetUniqueID() == 5){
1539                                                 if(tmpDaughter->GetPdgCode() == 11){    
1540                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1541                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1542                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1543                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1544                                                                                         daughter0Electron = kTRUE;
1545                                                                                 }
1546                                                                         }
1547                                                                 }                       
1548                                                         }
1549                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1550                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1551                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1552                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1553                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1554                                                                                         daughter0Positron = kTRUE;
1555                                                                                 }
1556                                                                         }
1557                                                                 }                       
1558                                                         }                                       
1559                                                 }
1560                                         }
1561                                 }
1562                         }
1563                                         
1564                         if(daughter1->GetNDaughters() >= 2){     // second gamma
1565                                 for(Int_t TrackIndex=daughter1->GetFirstDaughter();TrackIndex<=daughter1->GetLastDaughter();TrackIndex++){
1566                                         TParticle *tmpDaughter = fStack->Particle(TrackIndex);
1567                                         if(tmpDaughter->GetUniqueID() == 5){
1568                                                 if(tmpDaughter->GetPdgCode() == 11){
1569                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1570                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1571                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1572                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1573                                                                                         daughter1Electron = kTRUE;
1574                                                                                 }
1575                                                                         }
1576                                                                 }                       
1577                                                         }
1578                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1579                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1580                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1581                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1582                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1583                                                                                         daughter1Positron = kTRUE;
1584                                                                                 }
1585                                                                         }
1586                                                                 }                       
1587                                                         }                                       
1588                                                 }
1589                                         }
1590                                 }
1591                         }       
1592                         if(particle->GetPdgCode()==111){                 //Pi0
1593                                 if( iTracks >= fStack->GetNprimary()){
1594                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Eta", particle->Eta());
1595                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Rapid", rapidity);
1596                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Phi", tmpPhi);
1597                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt", particle->Pt());
1598                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Energy", particle->Energy());
1599                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_R", particle->R());
1600                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_ZR", particle->Vz(),particle->R());
1601                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1602                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_XY", particle->Vx(),particle->Vy());//only fill from one daughter to avoid multiple filling
1603                                                                         
1604                                         if(gammaEtaCut && gammaRCut){   
1605                                                 //if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1606                                                 fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1607                                                 fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1608                                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1609                                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1610                                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1611                                                 }
1612                                                 if(particle->GetMother(0) > -1){
1613                                                         Int_t pdgPionMother=fStack->Particle(particle->GetMother(0))->GetPdgCode();
1614                                                         if(pdgPionMother ==310 ){
1615                                                                 fHistograms->FillHistogram("MC_K0S_Pt_FromPi0", fStack->Particle(particle->GetMother(0))->Pt());
1616                                                         }
1617                                                 }
1618                                         }
1619                                 } else{
1620
1621                                         fHistograms->FillHistogram("MC_Pi0_Eta", particle->Eta());      
1622                                         fHistograms->FillHistogram("MC_Pi0_Rapid", rapidity);
1623                                         fHistograms->FillHistogram("MC_Pi0_Phi", tmpPhi);
1624                                         fHistograms->FillHistogram("MC_Pi0_Pt", particle->Pt());
1625                                         //if(fGCMCEvent->IsFromBGEvent(iTracks)) fHistograms->FillHistogram("MC_Pi0_Pt_under", particle->Pt());
1626                                         fHistograms->FillHistogram("MC_Pi0_Pt_vs_Rapid", particle->Pt(),rapidity);
1627                                         fHistograms->FillHistogram("MC_Pi0_Energy", particle->Energy());
1628                                         fHistograms->FillHistogram("MC_Pi0_R", particle->R());
1629                                         fHistograms->FillHistogram("MC_Pi0_ZR", particle->Vz(),particle->R());
1630                                         fHistograms->FillHistogram("MC_Pi0_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1631                                         fHistograms->FillHistogram("MC_Pi0_XY", particle->Vx(), particle->Vy());//only fill from one daughter to avoid multiple filling
1632                                         if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_Fiducial", particle->Pt());
1633                                         if(particle->GetMother(0) > -1){
1634                                                 Int_t pdgPionMother=fStack->Particle(particle->GetMother(0))->GetPdgCode();
1635                                                 if(pdgPionMother ==221 ){
1636                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromEta", particle->Pt());
1637                                                 }else   if( pdgPionMother==223 ){
1638                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromOmega", particle->Pt());
1639                                                 }else if(TMath::Abs(pdgPionMother) ==213 ){
1640                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromRhoPlusMinus", particle->Pt());
1641                                                 }else{
1642                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromOthers", particle->Pt());
1643                                                 }
1644                                         }else{
1645                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Direct", particle->Pt());
1646                                         }
1647
1648                                         if(gammaEtaCut && gammaRCut){
1649                         //              if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1650                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1651                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1652                                                 if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_withinAcceptance_Fiducial", particle->Pt());
1653                                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1654                                                         fHistograms->FillHistogram("MC_Pi0_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1655                                                         fHistograms->FillHistogram("MC_Pi0_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1656                                                         fHistograms->FillHistogram("MC_Pi0_ZR_ConvGamma_withinAcceptance", particle->Vz(),particle->R());
1657                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_OpeningAngle_Pt", particle->Pt(),GetMCOpeningAngle(daughter0,daughter1));
1658                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_PtGamma_Pt", particle->Pt(),daughter0->Pt());
1659                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_PtGamma_Pt", particle->Pt(),daughter1->Pt());
1660
1661                                                         Double_t alfa=0.;
1662                                                         if((daughter0->Energy()+daughter1->Energy()) > 0.){
1663                                                                 alfa= TMath::Abs((daughter0->Energy()-daughter1->Energy())/(daughter0->Energy()+daughter1->Energy()));
1664                                                         }
1665                                                         fHistograms->FillHistogram("MC_Pi0_alpha",alfa);
1666                                                         if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_ConvGamma_withinAcceptance_Fiducial", particle->Pt());
1667                                                 }
1668                                         }
1669                                 }
1670                         }
1671                                         
1672                         if(particle->GetPdgCode()==221){         //Eta
1673                                 fHistograms->FillHistogram("MC_Eta_Eta", particle->Eta());
1674                                 fHistograms->FillHistogram("MC_Eta_Rapid", rapidity);
1675                                 fHistograms->FillHistogram("MC_Eta_Phi",tmpPhi);
1676                                 fHistograms->FillHistogram("MC_Eta_Pt", particle->Pt());
1677                                 fHistograms->FillHistogram("MC_Eta_Pt_vs_Rapid", particle->Pt(),rapidity);
1678                                 fHistograms->FillHistogram("MC_Eta_Energy", particle->Energy());
1679                                 fHistograms->FillHistogram("MC_Eta_R", particle->R());
1680                                 fHistograms->FillHistogram("MC_Eta_ZR", particle->Vz(),particle->R());
1681                                 fHistograms->FillHistogram("MC_Eta_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1682                                 fHistograms->FillHistogram("MC_Eta_XY", particle->Vx(), particle->Vy());//only fill from one daughter to avoid multiple filling
1683                                                         
1684                                 if(gammaEtaCut && gammaRCut){   
1685                                         //      if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1686                                         fHistograms->FillHistogram("MC_Eta_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1687                                         fHistograms->FillHistogram("MC_Eta_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1688                                         if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1689                                                 fHistograms->FillHistogram("MC_Eta_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1690                                                 fHistograms->FillHistogram("MC_Eta_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1691                                                 fHistograms->FillHistogram("MC_Eta_ZR_ConvGamma_withinAcceptance", particle->Vz(),particle->R());
1692                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_OpeningAngle_Pt", particle->Pt(),GetMCOpeningAngle(daughter0,daughter1));
1693                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_PtGamma_Pt", particle->Pt(),daughter0->Pt());
1694                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_PtGamma_Pt", particle->Pt(),daughter1->Pt());
1695
1696                                                 Double_t alfa=0.;
1697                                                 if((daughter0->Energy()+daughter1->Energy()) > 0.){
1698                                                         alfa= TMath::Abs((daughter0->Energy()-daughter1->Energy())/(daughter0->Energy()+daughter1->Energy()));
1699                                                 }
1700                                                 fHistograms->FillHistogram("MC_Eta_alpha",alfa);
1701                                         }                       
1702                                 }                       
1703                         }
1704                                         
1705                         // all motherparticles with 2 gammas as daughters
1706                         fHistograms->FillHistogram("MC_Mother_R", particle->R());
1707                         fHistograms->FillHistogram("MC_Mother_ZR", particle->Vz(),particle->R());
1708                         fHistograms->FillHistogram("MC_Mother_XY", particle->Vx(),particle->Vy());
1709                         fHistograms->FillHistogram("MC_Mother_Mass", particle->GetCalcMass());
1710                         fHistograms->FillHistogram("MC_Mother_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1711                         fHistograms->FillHistogram("MC_Mother_Energy", particle->Energy());
1712                         fHistograms->FillHistogram("MC_Mother_Pt", particle->Pt());
1713                         fHistograms->FillHistogram("MC_Mother_Eta", particle->Eta());
1714                         fHistograms->FillHistogram("MC_Mother_Rapid", rapidity);
1715                         fHistograms->FillHistogram("MC_Mother_Phi",tmpPhi);
1716                         fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt",particle->GetMass(),particle->Pt());                       
1717                                         
1718                         if(gammaEtaCut && gammaRCut){   
1719                                 //                      if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1720                                 fHistograms->FillHistogram("MC_Mother_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1721                                 fHistograms->FillHistogram("MC_Mother_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1722                                 fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt_withinAcceptance",particle->GetMass(),particle->Pt());                      
1723                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1724                                         fHistograms->FillHistogram("MC_Mother_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1725                                         fHistograms->FillHistogram("MC_Mother_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1726                                         fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt_ConvGamma_withinAcceptance",particle->GetMass(),particle->Pt());                    
1727                                 }                       
1728                         }       // end passed R and eta cut
1729                 } // end if(particle->GetNDaughters() == 2)
1730         }// end for (Int_t iTracks = 0; iTracks < fStack->GetNtrack(); iTracks++)
1731         
1732         fHistograms->FillHistogram("ESD_TrueMult_vs_MeasMult", nCharged,fMultiplicity);
1733         fHistograms->FillHistogram("ESD_TrueMult_vs_MeasMult_pt150MeV", nCharged150MeV,fMultiplicity);
1734         //cout << "True   " <<  nCharged << "     Meas.     " << fMultiplicity << endl;
1735
1736 } // end ProcessMCData
1737
1738
1739
1740 void AliAnalysisTaskGammaConversion::FillNtuple(){
1741         //Fills the ntuple with the different values
1742         
1743         if(fGammaNtuple == NULL){
1744                 return;
1745         }
1746         Int_t numberOfV0s = fV0Reader->GetNumberOfV0s();
1747         for(Int_t i=0;i<numberOfV0s;i++){
1748                 Float_t values[27] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1749                 AliESDv0 * cV0 = fV0Reader->GetV0(i);
1750                 Double_t negPID=0;
1751                 Double_t posPID=0;
1752                 fV0Reader->GetPIDProbability(negPID,posPID);
1753                 values[0]=cV0->GetOnFlyStatus();
1754                 values[1]=fV0Reader->CheckForPrimaryVertex();
1755                 values[2]=negPID;
1756                 values[3]=posPID;
1757                 values[4]=fV0Reader->GetX();
1758                 values[5]=fV0Reader->GetY();
1759                 values[6]=fV0Reader->GetZ();
1760                 values[7]=fV0Reader->GetXYRadius();
1761                 values[8]=fV0Reader->GetMotherCandidateNDF();
1762                 values[9]=fV0Reader->GetMotherCandidateChi2();
1763                 values[10]=fV0Reader->GetMotherCandidateEnergy();
1764                 values[11]=fV0Reader->GetMotherCandidateEta();
1765                 values[12]=fV0Reader->GetMotherCandidatePt();
1766                 values[13]=fV0Reader->GetMotherCandidateMass();
1767                 values[14]=fV0Reader->GetMotherCandidateWidth();
1768                 //              values[15]=fV0Reader->GetMotherMCParticle()->Pt();       MOVED TO THE END, HAS TO BE CALLED AFTER HasSameMother NB: still has the same entry in the array
1769                 values[16]=fV0Reader->GetOpeningAngle();
1770                 values[17]=fV0Reader->GetNegativeTrackEnergy();
1771                 values[18]=fV0Reader->GetNegativeTrackPt();
1772                 values[19]=fV0Reader->GetNegativeTrackEta();
1773                 values[20]=fV0Reader->GetNegativeTrackPhi();
1774                 values[21]=fV0Reader->GetPositiveTrackEnergy();
1775                 values[22]=fV0Reader->GetPositiveTrackPt();
1776                 values[23]=fV0Reader->GetPositiveTrackEta();
1777                 values[24]=fV0Reader->GetPositiveTrackPhi();
1778                 values[25]=fV0Reader->HasSameMCMother();
1779                 if(values[25] != 0){
1780                         values[26]=fV0Reader->GetMotherMCParticlePDGCode();
1781                         values[15]=fV0Reader->GetMotherMCParticle()->Pt();
1782                 }
1783                 fTotalNumberOfAddedNtupleEntries++;
1784                 fGammaNtuple->Fill(values);
1785         }
1786         fV0Reader->ResetV0IndexNumber();
1787         
1788 }
1789
1790 void AliAnalysisTaskGammaConversion::ProcessV0sNoCut(){
1791         // Process all the V0's without applying any cuts to it
1792         
1793         Int_t numberOfV0s = fV0Reader->GetNumberOfV0s();
1794         for(Int_t i=0;i<numberOfV0s;i++){
1795                 /*AliESDv0 * cV0 = */fV0Reader->GetV0(i);
1796                 
1797                 if(fV0Reader->CheckForPrimaryVertex() == kFALSE){
1798                         continue;
1799                 }
1800
1801                 //              if( !fV0Reader->GetV0(i)->GetOnFlyStatus()){
1802                 if( !fV0Reader->CheckV0FinderStatus(fV0Reader->GetV0(i))){
1803                         continue;
1804                 }
1805
1806
1807                 if( !((fV0Reader->GetNegativeESDTrack())->GetStatus() & AliESDtrack::kTPCrefit) || 
1808                                 !((fV0Reader->GetPositiveESDTrack())->GetStatus() & AliESDtrack::kTPCrefit) ){
1809                         continue;
1810                 }
1811
1812                 if( fV0Reader->GetNegativeESDTrack()->GetSign()== fV0Reader->GetPositiveESDTrack()->GetSign()){
1813                         continue;
1814                 }
1815
1816                 if( fV0Reader->GetNegativeESDTrack()->GetKinkIndex(0) > 0 || 
1817                         fV0Reader->GetPositiveESDTrack()->GetKinkIndex(0) > 0) {                        
1818                         continue;
1819                 }
1820                 if(TMath::Abs(fV0Reader->GetMotherCandidateEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetMotherCandidateEta())< fV0Reader->GetEtaCutMin()){
1821                         continue;
1822                 }
1823                 if(TMath::Abs(fV0Reader->GetPositiveTrackEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetPositiveTrackEta())< fV0Reader->GetEtaCutMin()){
1824                         continue;
1825                 }
1826                 if(TMath::Abs(fV0Reader->GetNegativeTrackEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetNegativeTrackEta())< fV0Reader->GetEtaCutMin()){
1827                         continue;
1828                 }
1829                 if( fV0Reader->GetXYRadius() <= ((TMath::Abs(fV0Reader->GetZ())*fV0Reader->GetLineCutZRSlope())-fV0Reader->GetLineCutZValue()) ){ // cuts out regions where we do not reconstruct
1830                         continue; 
1831                 } else if ( fV0Reader->GetEtaCutMin() != -0.1 && fV0Reader->GetXYRadius() > ((TMath::Abs(fV0Reader->GetZ())*fV0Reader->GetLineCutZRSlopeMin())-fV0Reader->GetLineCutZValueMin()) ) {
1832                         continue; 
1833                 }
1834
1835                 fHistograms->FillHistogram("ESD_NoCutAllV0_Pt", fV0Reader->GetMotherCandidatePt());
1836
1837                 // RRnewTOF start ///////////////////////////////////////////////
1838                 UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus();
1839                 UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
1840
1841                 Double_t t0pos = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetPositiveTrackP());
1842                 Double_t t0neg = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetNegativeTrackP());
1843
1844                 Double_t timesPos[5];
1845                 fV0Reader->GetPositiveESDTrack()->GetIntegratedTimes(timesPos);
1846                 Double_t timesNeg[5];
1847                 fV0Reader->GetNegativeESDTrack()->GetIntegratedTimes(timesNeg);
1848
1849                 Double_t TOFsignalPos = fV0Reader->GetPositiveTrackTOFsignal();
1850                 Double_t TOFsignalNeg = fV0Reader->GetNegativeTrackTOFsignal();
1851
1852                 Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
1853                 Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
1854
1855                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_WOCutConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
1856                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_WOCutConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
1857                 // RRnewTOF end /////////////////////////////////////////////////
1858                 
1859                 if(fDoMCTruth){
1860                         
1861                         if(fV0Reader->HasSameMCMother() == kFALSE){
1862                                 continue;
1863                         }
1864                         
1865                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
1866                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
1867                         
1868                         if(TMath::Abs(negativeMC->GetPdgCode())!=11 || TMath::Abs(positiveMC->GetPdgCode())!=11){
1869                                 continue;
1870                         }
1871                         if(negativeMC->GetPdgCode() == positiveMC->GetPdgCode()){
1872                                 continue;
1873                         }
1874
1875                         if(negativeMC->GetUniqueID() != 5 || positiveMC->GetUniqueID() !=5){ // id 5 is conversion
1876                                 continue;
1877                         }
1878                 
1879                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){                               
1880                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
1881                                 if(negativeMC->GetMother(0) <= fStack->GetNprimary()){
1882                                    fHistograms->FillHistogram("ESD_NoCutConvPrimaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
1883                                 }
1884                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
1885                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Eta", fV0Reader->GetMotherCandidateEta());                               
1886                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
1887                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
1888                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
1889                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Chi2", fV0Reader->GetMotherCandidateChi2());
1890                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_NDF", fV0Reader->GetMotherCandidateNDF());
1891                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Rapid", fV0Reader->GetMotherCandidateRapidity());
1892                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt_Eta", fV0Reader->GetMotherCandidatePt(),fV0Reader->GetMotherCandidateEta());
1893                                                         
1894                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt_Chi2", fV0Reader->GetMotherCandidatePt(), fV0Reader->GetMotherCandidateChi2());
1895                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Eta_Chi2", fV0Reader->GetMotherCandidateEta(), fV0Reader->GetMotherCandidateChi2());
1896                                                         
1897                                 fHistograms->FillHistogram("ESD_NoCutConversion_XY", fV0Reader->GetX(),fV0Reader->GetY());
1898                                 fHistograms->FillHistogram("ESD_NoCutConversion_R", fV0Reader->GetXYRadius());
1899                                 fHistograms->FillHistogram("ESD_NoCutConversion_MCR",fV0Reader->GetNegativeMCParticle()->R());
1900                                 fHistograms->FillHistogram("ESD_NoCutConversion_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1901                                 fHistograms->FillHistogram("ESD_NoCutConversion_OpeningAngle", fV0Reader->GetOpeningAngle());
1902                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_CosPointingAngle", fV0Reader->GetCosPointingAngle());
1903                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_DcaDaughters", fV0Reader->GetDcaDaughters());
1904                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_NormDcaDistDaughters", fV0Reader->GetNormDcaDistDaughters());
1905                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_LikelihoodAP", fV0Reader->GetLikelihoodAP());
1906
1907                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_E_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetNegativeTrackP()/fV0Reader->GetMotherCandidateP());
1908                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_P_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetPositiveTrackP()/fV0Reader->GetMotherCandidateP());
1909                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_E_dEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetNegativeTrackTPCdEdx());
1910                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_P_dEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetPositiveTrackTPCdEdx());
1911
1912                                 //store MCTruth properties
1913                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_MC_Pt_Eta", fV0Reader->GetMotherMCParticle()->Pt(),fV0Reader->GetMotherMCParticle()->Eta());
1914                                 fHistograms->FillHistogram("ESD_NoCutConversion_MC_ZR", negativeMC->Vz(),negativeMC->R());
1915                                 fHistograms->FillHistogram("ESD_NoCutConversion_MC_XY", negativeMC->Vx(),negativeMC->Vy());
1916                         }
1917                 }
1918         }
1919         fV0Reader->ResetV0IndexNumber();
1920 }
1921
1922 void AliAnalysisTaskGammaConversion::ProcessV0s(){
1923         // see header file for documentation
1924
1925
1926         if(fWriteNtuple == kTRUE){
1927                 FillNtuple();
1928         }
1929         
1930         Int_t nSurvivingV0s=0;
1931         fV0Reader->ResetNGoodV0s();
1932         while(fV0Reader->NextV0()){
1933                 nSurvivingV0s++;
1934                 
1935
1936                 TVector3 vtxConv(fV0Reader->GetX(),fV0Reader->GetY(), fV0Reader->GetZ());
1937         
1938                 //-------------------------- filling v0 information -------------------------------------
1939                 fHistograms->FillHistogram("ESD_Conversion_R", fV0Reader->GetXYRadius());
1940                 fHistograms->FillHistogram("ESD_Conversion_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1941                 fHistograms->FillHistogram("ESD_Conversion_XY", fV0Reader->GetX(),fV0Reader->GetY());
1942                 fHistograms->FillHistogram("ESD_Conversion_OpeningAngle", fV0Reader->GetOpeningAngle());                
1943                 fHistograms->FillHistogram("ESD_ConversionMapping_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1944                 fHistograms->FillHistogram("ESD_ConversionMapping_ZPhi", fV0Reader->GetZ(),vtxConv.Phi());
1945                 fHistograms->FillHistogram("ESD_ConversionMapping_RPhi", fV0Reader->GetXYRadius(),vtxConv.Phi());
1946                         
1947                 if ( fV0Reader->GetMotherCandidatePt() >= 2.){
1948                         fHistograms->FillHistogram("ESD_Conversion_minPt_R", fV0Reader->GetXYRadius());
1949                         fHistograms->FillHistogram("ESD_Conversion_minPt_Z", fV0Reader->GetZ());
1950                 }
1951
1952                 // Specific histograms for beam pipe studies
1953                 if( TMath::Abs(fV0Reader->GetZ()) < fV0Reader->GetLineCutZValue() && TMath::Abs(fV0Reader->GetZ()) > fV0Reader->GetLineCutZValueMin()){
1954                         fHistograms->FillHistogram("ESD_Conversion_XY_BeamPipe", fV0Reader->GetX(),fV0Reader->GetY());
1955                         fHistograms->FillHistogram("ESD_Conversion_RPhi_BeamPipe", vtxConv.Phi(),fV0Reader->GetXYRadius());
1956                 }
1957
1958         
1959                 fHistograms->FillHistogram("ESD_E_Energy", fV0Reader->GetNegativeTrackEnergy());
1960                 fHistograms->FillHistogram("ESD_E_Pt", fV0Reader->GetNegativeTrackPt());
1961                 fHistograms->FillHistogram("ESD_E_Eta", fV0Reader->GetNegativeTrackEta());
1962                 fHistograms->FillHistogram("ESD_E_Phi", fV0Reader->GetNegativeTrackPhi());
1963                 fHistograms->FillHistogram("ESD_E_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1964                 fHistograms->FillHistogram("ESD_E_nITSClusters", fV0Reader->GetNegativeTracknITSClusters());
1965                 if ( fV0Reader->GetNegativeTrackPt()> 0.150){
1966                         fHistograms->FillHistogram("ESD_E_minPt_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1967                 }
1968                 if ( fV0Reader->GetNegativeTracknITSClusters()==0){
1969                         fHistograms->FillHistogram("ESD_E_onlyTPC_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1970                 }
1971
1972                 Double_t eClsToF= 0;
1973                 if(!fV0Reader->GetUseCorrectedTPCClsInfo()){
1974                         if(fV0Reader->GetNegativeTracknTPCFClusters()!=0 ){
1975                                 eClsToF=(Double_t)fV0Reader->GetNegativeTracknTPCClusters()/(Double_t)fV0Reader->GetNegativeTracknTPCFClusters();
1976                         }
1977                 } else {
1978                         eClsToF= fV0Reader->GetNegativeESDTrack()->GetTPCClusterInfo(2,0,fV0Reader->GetFirstTPCRow(fV0Reader->GetXYRadius()));
1979                 }
1980                         fHistograms->FillHistogram("ESD_E_nTPCClustersToFP", fV0Reader->GetNegativeTrackP(),eClsToF );
1981                         fHistograms->FillHistogram("ESD_E_nTPCClustersToFR", fV0Reader->GetXYRadius(),eClsToF );
1982
1983                 if(fV0Reader->GetNegativeTracknTPCClusters()!=0 ){
1984                         fHistograms->FillHistogram("ESD_E_TPCchi2", fV0Reader->GetNegativeTrackTPCchi2()/(Double_t)fV0Reader->GetNegativeTracknTPCClusters());
1985                 }
1986
1987
1988
1989                 fHistograms->FillHistogram("ESD_P_Energy", fV0Reader->GetPositiveTrackEnergy());
1990                 fHistograms->FillHistogram("ESD_P_Pt", fV0Reader->GetPositiveTrackPt());
1991                 fHistograms->FillHistogram("ESD_P_Eta", fV0Reader->GetPositiveTrackEta());
1992                 fHistograms->FillHistogram("ESD_P_Phi", fV0Reader->GetPositiveTrackPhi());
1993                 fHistograms->FillHistogram("ESD_P_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
1994                 fHistograms->FillHistogram("ESD_P_nITSClusters", fV0Reader->GetPositiveTracknITSClusters());
1995                 if ( fV0Reader->GetPositiveTrackPt()> 0.150){
1996                         fHistograms->FillHistogram("ESD_P_minPt_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
1997                 }
1998                 if (fV0Reader->GetPositiveTracknITSClusters()==0){
1999                         fHistograms->FillHistogram("ESD_P_onlyTPC_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
2000                 }
2001
2002                 Double_t pClsToF= 0;
2003                 if(!fV0Reader->GetUseCorrectedTPCClsInfo()){
2004                         if(fV0Reader->GetPositiveTracknTPCFClusters()!=0){
2005                                 pClsToF = (Double_t)fV0Reader->GetPositiveTracknTPCClusters()/(Double_t)fV0Reader->GetPositiveTracknTPCFClusters();
2006                         }
2007                 } else {
2008                         pClsToF= fV0Reader->GetPositiveESDTrack()->GetTPCClusterInfo(2,0,fV0Reader->GetFirstTPCRow(fV0Reader->GetXYRadius()));
2009                 }
2010
2011                 fHistograms->FillHistogram("ESD_P_nTPCClustersToFP",fV0Reader->GetPositiveTrackP(), pClsToF);
2012                 fHistograms->FillHistogram("ESD_P_nTPCClustersToFR",fV0Reader->GetXYRadius(), pClsToF);
2013
2014                 if(fV0Reader->GetPositiveTracknTPCClusters()!=0){
2015                         fHistograms->FillHistogram("ESD_P_TPCchi2", fV0Reader->GetPositiveTrackTPCchi2()/(Double_t)fV0Reader->GetPositiveTracknTPCClusters());
2016                 }
2017
2018
2019
2020                 fHistograms->FillHistogram("ESD_ConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
2021                 fHistograms->FillHistogram("ESD_ConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
2022                 fHistograms->FillHistogram("ESD_ConvGamma_Eta", fV0Reader->GetMotherCandidateEta());
2023                 fHistograms->FillHistogram("ESD_ConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
2024                 fHistograms->FillHistogram("ESD_ConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
2025                 fHistograms->FillHistogram("ESD_ConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
2026                 fHistograms->FillHistogram("ESD_ConvGamma_Chi2", fV0Reader->GetMotherCandidateChi2());
2027                 fHistograms->FillHistogram("ESD_ConvGamma_NDF", fV0Reader->GetMotherCandidateNDF());
2028                 fHistograms->FillHistogram("ESD_ConvGamma_Rapid", fV0Reader->GetMotherCandidateRapidity());
2029                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Eta", fV0Reader->GetMotherCandidatePt(),fV0Reader->GetMotherCandidateEta());
2030                 
2031                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Chi2", fV0Reader->GetMotherCandidatePt(), fV0Reader->GetMotherCandidateChi2());
2032                 fHistograms->FillHistogram("ESD_ConvGamma_Eta_Chi2", fV0Reader->GetMotherCandidateEta(), fV0Reader->GetMotherCandidateChi2());
2033                 
2034                 fHistograms->FillHistogram("ESD_ConvGamma_CosPointingAngle", fV0Reader->GetCosPointingAngle());
2035                 fHistograms->FillHistogram("ESD_ConvGamma_CosPoint_RecCosPoint",fV0Reader->GetCosPointingAngle(),fV0Reader->GetV0CosineOfPointingAngle(fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ()));
2036                 fHistograms->FillHistogram("ESD_ConvGamma_PsiPair", fV0Reader->GetPsiPair(fV0Reader->GetCurrentV0()));
2037                 
2038                 fHistograms->FillHistogram("ESD_ConvGamma_DcaDaughters", fV0Reader->GetDcaDaughters());
2039                 fHistograms->FillHistogram("ESD_ConvGamma_NormDcaDistDaughters", fV0Reader->GetNormDcaDistDaughters());
2040                 fHistograms->FillHistogram("ESD_ConvGamma_LikelihoodAP", fV0Reader->GetLikelihoodAP());
2041                 
2042                 fHistograms->FillHistogram("ESD_ConvGamma_E_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetNegativeTrackP()/fV0Reader->GetMotherCandidateP());
2043                 fHistograms->FillHistogram("ESD_ConvGamma_P_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetPositiveTrackP()/fV0Reader->GetMotherCandidateP());
2044                 fHistograms->FillHistogram("ESD_ConvGamma_E_dEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetNegativeTrackTPCdEdx());
2045                 fHistograms->FillHistogram("ESD_ConvGamma_P_dEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetPositiveTrackTPCdEdx());
2046                 fHistograms->FillHistogram("ESD_ConvGamma_E_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kElectron));
2047                 fHistograms->FillHistogram("ESD_ConvGamma_P_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kElectron));
2048                 fHistograms->FillHistogram("ESD_ConvGamma_PiPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kPion));
2049                 fHistograms->FillHistogram("ESD_ConvGamma_PiMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kPion));
2050                 fHistograms->FillHistogram("ESD_ConvGamma_KPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kKaon));
2051                 fHistograms->FillHistogram("ESD_ConvGamma_KMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kKaon));
2052                 fHistograms->FillHistogram("ESD_ConvGamma_PPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kProton));
2053                 fHistograms->FillHistogram("ESD_ConvGamma_PMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kProton));
2054                 fHistograms->FillHistogram("ESD_ConvGamma_MuPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kMuon));
2055                 fHistograms->FillHistogram("ESD_ConvGamma_MuMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kMuon));
2056                 
2057
2058                 UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus(); //moved up here from below RRnewTOF
2059                 UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
2060                 // RRnewTOF start ///////////////////////////////////////////////
2061                 Double_t t0pos = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetPositiveTrackP());
2062                 Double_t t0neg = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetNegativeTrackP());
2063
2064                 Double_t timesPos[5];
2065                 fV0Reader->GetPositiveESDTrack()->GetIntegratedTimes(timesPos);
2066                 Double_t timesNeg[5];
2067                 fV0Reader->GetNegativeESDTrack()->GetIntegratedTimes(timesNeg);
2068
2069                 Double_t TOFsignalPos = fV0Reader->GetPositiveTrackTOFsignal();
2070                 Double_t TOFsignalNeg = fV0Reader->GetNegativeTrackTOFsignal();
2071
2072                 Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
2073                 Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
2074
2075                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_ConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
2076                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_ConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
2077                 // RRnewTOF end /////////////////////////////////////////////////
2078
2079                 Double_t negPID=0;
2080                 Double_t posPID=0;
2081                 fV0Reader->GetPIDProbability(negPID,posPID);
2082                 fHistograms->FillHistogram("ESD_ConvGamma_E_EProbP",fV0Reader->GetNegativeTrackP(),negPID);
2083                 fHistograms->FillHistogram("ESD_ConvGamma_P_EProbP",fV0Reader->GetPositiveTrackP(),posPID);
2084
2085                 Double_t negPIDmupi=0;
2086                 Double_t posPIDmupi=0;
2087                 fV0Reader->GetPIDProbabilityMuonPion(negPIDmupi,posPIDmupi);
2088                 fHistograms->FillHistogram("ESD_ConvGamma_E_mupiProbP",fV0Reader->GetNegativeTrackP(),negPIDmupi);
2089                 fHistograms->FillHistogram("ESD_ConvGamma_P_mupiProbP",fV0Reader->GetPositiveTrackP(),posPIDmupi);
2090
2091                 Double_t armenterosQtAlpha[2] = {0,0};
2092                 if(fV0Reader->GetUseESDQtCut() == 0){
2093                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetNegativeKFParticle(),
2094                                                    fV0Reader->GetPositiveKFParticle(),
2095                                                    fV0Reader->GetMotherCandidateKFCombination(),
2096                                                    armenterosQtAlpha);
2097                 }
2098                 else if(fV0Reader->GetUseESDQtCut() == 1){
2099                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetCurrentV0(), armenterosQtAlpha);
2100                 }
2101                 else if(fV0Reader->GetUseESDQtCut() == 2 || fV0Reader->GetUseESDQtCut() == 3){
2102                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetNegativeKFParticle(),
2103                                                    fV0Reader->GetPositiveKFParticle(),
2104                                                    armenterosQtAlpha,
2105                                                    fV0Reader->GetUseESDQtCut());
2106                 }
2107                 
2108                 fHistograms->FillHistogram("ESD_ConvGamma_alfa_qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2109                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Qt",fV0Reader->GetMotherCandidatePt(),armenterosQtAlpha[0]);
2110         
2111                 if(!fV0Reader->GetIsHeavyIon()){
2112                         fHistograms->FillHistogram("3DPlots_Conversion_XYZ", fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ());            
2113                         //fHistograms->FillHistogram("3DPlots_Conversion_ZRPhi", fV0Reader->GetZ(),fV0Reader->GetXYRadius(), vtxConv.Phi());
2114
2115                         // begin mapping
2116                         Int_t rBin              = fHistograms->GetRBin(fV0Reader->GetXYRadius());
2117                         Int_t zBin              = fHistograms->GetZBin(fV0Reader->GetZ());
2118                         Int_t phiBin    = fHistograms->GetPhiBin(fV0Reader->GetNegativeTrackPhi());
2119                         Double_t rFMD=25;
2120                         Double_t rITSTPCMin=40;
2121                         Double_t rITSTPCInt=55;
2122                         Double_t rITSTPCMax=72.5;
2123                         
2124                         //              Double_t motherCandidateEta= fV0Reader->GetMotherCandidateEta();
2125                         
2126                         TString nameESDMappingPhiR="";
2127                         nameESDMappingPhiR.Form("ESD_Conversion_Mapping_Phi%02d_R%02d",phiBin,rBin);
2128                         //fHistograms->FillHistogram(nameESDMappingPhiR, fV0Reader->GetZ(), motherCandidateEta);
2129                         
2130                         TString nameESDMappingPhi="";
2131                         nameESDMappingPhi.Form("ESD_Conversion_Mapping_Phi%02d",phiBin);
2132                         //fHistograms->FillHistogram(nameESDMappingPhi, fV0Reader->GetZ(), motherCandidateEta);
2133                         
2134                         TString nameESDMappingR="";
2135                         nameESDMappingR.Form("ESD_Conversion_Mapping_R%02d",rBin);
2136                         //fHistograms->FillHistogram(nameESDMappingR, fV0Reader->GetZ(), motherCandidateEta);   
2137                         
2138                         TString nameESDMappingPhiInR="";
2139                         nameESDMappingPhiInR.Form("ESD_Conversion_Mapping_Phi_in_R_%02d",rBin);
2140                         //              fHistograms->FillHistogram(nameESDMappingPhiInR, fV0Reader->GetMotherCandidatePhi());
2141                         fHistograms->FillHistogram(nameESDMappingPhiInR, vtxConv.Phi());
2142                         
2143                         TString nameESDMappingZInR="";
2144                         nameESDMappingZInR.Form("ESD_Conversion_Mapping_Z_in_R_%02d",rBin);
2145                         fHistograms->FillHistogram(nameESDMappingZInR, fV0Reader->GetZ());
2146                         
2147                         TString nameESDMappingPhiInZ="";
2148                         nameESDMappingPhiInZ.Form("ESD_Conversion_Mapping_Phi_in_Z_%02d",zBin);
2149                         //              fHistograms->FillHistogram(nameESDMappingPhiInR, fV0Reader->GetMotherCandidatePhi());
2150                         fHistograms->FillHistogram(nameESDMappingPhiInZ, vtxConv.Phi());
2151                         
2152                         if(fV0Reader->GetXYRadius()<rFMD){
2153                                 TString nameESDMappingFMDPhiInZ="";
2154                                 nameESDMappingFMDPhiInZ.Form("ESD_Conversion_Mapping_FMD_Phi_in_Z_%02d",zBin);
2155                                 fHistograms->FillHistogram(nameESDMappingFMDPhiInZ, vtxConv.Phi());
2156                                 fHistograms->FillHistogram("ESD_ConversionMapping_FMD_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2157                         }
2158                         if(fV0Reader->GetXYRadius()>rFMD && fV0Reader->GetXYRadius()<rITSTPCMin){
2159                                 fHistograms->FillHistogram("ESD_ConversionMapping_FMD2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2160                         }
2161
2162                         if(fV0Reader->GetXYRadius()>rITSTPCMin && fV0Reader->GetXYRadius()<rITSTPCInt){
2163                                 TString nameESDMappingITSTPCPhiInZ="";
2164                                 nameESDMappingITSTPCPhiInZ.Form("ESD_Conversion_Mapping_ITSTPC_Phi_in_Z_%02d",zBin);
2165                                 fHistograms->FillHistogram(nameESDMappingITSTPCPhiInZ, vtxConv.Phi());
2166                                 fHistograms->FillHistogram("ESD_ConversionMapping_ITSTPC_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2167                         }
2168                         
2169                         if(fV0Reader->GetXYRadius()>rITSTPCInt && fV0Reader->GetXYRadius()<rITSTPCMax){
2170                                 TString nameESDMappingITSTPC2PhiInZ="";
2171                                 nameESDMappingITSTPC2PhiInZ.Form("ESD_Conversion_Mapping_ITSTPC2_Phi_in_Z_%02d",zBin);
2172                                 fHistograms->FillHistogram(nameESDMappingITSTPC2PhiInZ, vtxConv.Phi());
2173                                 fHistograms->FillHistogram("ESD_ConversionMapping_ITSTPC2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2174                         }
2175
2176                         TString nameESDMappingRInZ="";
2177                         nameESDMappingRInZ.Form("ESD_Conversion_Mapping_R_in_Z_%02d",zBin);
2178                         fHistograms->FillHistogram(nameESDMappingRInZ, fV0Reader->GetXYRadius());
2179                         
2180                         if(fV0Reader->GetMotherCandidatePt() > fLowPtMapping && fV0Reader->GetMotherCandidatePt()< fHighPtMapping){
2181                                 TString nameESDMappingMidPtPhiInR="";
2182                                 nameESDMappingMidPtPhiInR.Form("ESD_Conversion_Mapping_MidPt_Phi_in_R_%02d",rBin);
2183                                 fHistograms->FillHistogram(nameESDMappingMidPtPhiInR, vtxConv.Phi());
2184                                 
2185                                 TString nameESDMappingMidPtZInR="";
2186                                 nameESDMappingMidPtZInR.Form("ESD_Conversion_Mapping_MidPt_Z_in_R_%02d",rBin);
2187                                 fHistograms->FillHistogram(nameESDMappingMidPtZInR, fV0Reader->GetZ());
2188                                 
2189                                 TString nameESDMappingMidPtPhiInZ="";
2190                                 nameESDMappingMidPtPhiInZ.Form("ESD_Conversion_Mapping_MidPt_Phi_in_Z_%02d",zBin);
2191                                 fHistograms->FillHistogram(nameESDMappingMidPtPhiInZ, vtxConv.Phi());
2192                                 if(fV0Reader->GetXYRadius()<rFMD){
2193                                         TString nameESDMappingMidPtFMDPhiInZ="";
2194                                         nameESDMappingMidPtFMDPhiInZ.Form("ESD_Conversion_Mapping_MidPt_FMD_Phi_in_Z_%02d",zBin);
2195                                         fHistograms->FillHistogram(nameESDMappingMidPtFMDPhiInZ, vtxConv.Phi());
2196                                 }
2197                                 TString nameESDMappingMidPtRInZ="";
2198                                 nameESDMappingMidPtRInZ.Form("ESD_Conversion_Mapping_MidPt_R_in_Z_%02d",zBin);
2199                                 fHistograms->FillHistogram(nameESDMappingMidPtRInZ, fV0Reader->GetXYRadius());  
2200                         }
2201                 }
2202
2203                 // end mapping
2204                 
2205                    
2206                 new((*fKFReconstructedGammasTClone)[fKFReconstructedGammasTClone->GetEntriesFast()])    AliKFConversionPhoton(fV0Reader);
2207              
2208                  
2209                 //----------------------------------- checking for "real" conversions (MC match) --------------------------------------
2210                 if(fDoMCTruth){
2211                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
2212                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
2213                         Double_t rFMD=25;
2214                         Double_t rITSTPCMin=40;
2215                         Double_t rITSTPCInt=55;
2216                         Double_t rITSTPCMax=72.5;
2217  
2218                         if(fV0Reader->HasSameMCMother() == kFALSE){
2219                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_R", fV0Reader->GetXYRadius());
2220                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_Z", fV0Reader->GetZ());
2221                                 fHistograms->FillHistogram("ESD_TrueConvCombSelected_Alpha_Qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2222                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2223                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialMinPt_R", fV0Reader->GetXYRadius());
2224                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialMinPt_Z", fV0Reader->GetZ());                      
2225                                 }
2226                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_Pt", fV0Reader->GetMotherCandidatePt());
2227                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorialDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2228                                 if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){
2229                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElec_R", fV0Reader->GetXYRadius());
2230                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElec_Pt", fV0Reader->GetMotherCandidatePt());
2231                                 }
2232                                 if(TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==211){
2233                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPi_R", fV0Reader->GetXYRadius());
2234                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPi_Pt", fV0Reader->GetMotherCandidatePt());
2235                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2236                                 }
2237                                 if((TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==2211) ||
2238                                         (TMath::Abs(negativeMC->GetPdgCode())==2212 && TMath::Abs(positiveMC->GetPdgCode())==211)){
2239                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiP_R", fV0Reader->GetXYRadius());
2240                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiP_Pt", fV0Reader->GetMotherCandidatePt());
2241                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiPDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2242                                 }
2243                                 if((TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==211) ||
2244                                         (TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==11)){
2245                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElecPi_R", fV0Reader->GetXYRadius());
2246                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElecPi_Pt", fV0Reader->GetMotherCandidatePt());
2247                                 }
2248                                 if( (statusPos & AliESDtrack::kTOFpid) && ( TMath::Abs(positiveMC->GetPdgCode()) != 11 ) && !(statusPos & AliESDtrack::kTOFmismatch) )
2249                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorial_DaughtersNotElec_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);//RRnewTOF
2250                                 if( (statusNeg & AliESDtrack::kTOFpid) && ( TMath::Abs(negativeMC->GetPdgCode()) != 11 ) && !(statusNeg & AliESDtrack::kTOFmismatch) )
2251                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorial_DaughtersNotElec_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);//RRnewTOF
2252                                 continue;
2253                         } 
2254
2255                                                 // Moved up to check true electron background
2256                                                 //                      TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
2257                                                 //                      TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
2258                                                 
2259                         if(TMath::Abs(negativeMC->GetPdgCode())!=11 || TMath::Abs(positiveMC->GetPdgCode())!=11){
2260                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_R", fV0Reader->GetXYRadius());
2261                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Z", fV0Reader->GetZ());
2262                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2263                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBckMinPt_R", fV0Reader->GetXYRadius());
2264                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBckMinPt_Z", fV0Reader->GetZ());                        
2265                                 }
2266                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Pt", fV0Reader->GetMotherCandidatePt());
2267                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBckDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2268                                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) )
2269                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Daughters_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);//RRnewTOF
2270                                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) )
2271                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Daughters_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);//RRnewTOF
2272                                 if((TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==2211) ||
2273                                         (TMath::Abs(negativeMC->GetPdgCode())==2212 && TMath::Abs(positiveMC->GetPdgCode())==211)){
2274                                         fHistograms->FillHistogram("ESD_TrueConvLambda_R", fV0Reader->GetXYRadius());
2275                                         fHistograms->FillHistogram("ESD_TrueConvLambda_Pt", fV0Reader->GetMotherCandidatePt());
2276                                 }
2277                                 if(TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==211){
2278                                         fHistograms->FillHistogram("ESD_TrueConvMeson_R", fV0Reader->GetXYRadius());
2279                                         fHistograms->FillHistogram("ESD_TrueConvMeson_Pt", fV0Reader->GetMotherCandidatePt());
2280                                 }
2281                                 continue;
2282                         }
2283                          
2284
2285                         if(negativeMC->GetPdgCode()==positiveMC->GetPdgCode()){
2286                                 continue;
2287                         }
2288
2289                         //UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus(); moved higher
2290                         //UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
2291                         UChar_t itsPixelPos = fV0Reader->GetPositiveESDTrack()->GetITSClusterMap();
2292                         UChar_t itsPixelNeg = fV0Reader->GetNegativeESDTrack()->GetITSClusterMap();
2293
2294                         // Using the UniqueID Phojet does not get the Dalitz right
2295                         //                      if( (negativeMC->GetUniqueID() == 4 && positiveMC->GetUniqueID() ==4) ||
2296                         //      (negativeMC->GetUniqueID() == 0 && positiveMC->GetUniqueID() ==0) ){// fill r distribution for Dalitz decays 
2297                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 111){ //pi0
2298                                 fHistograms->FillHistogram("ESD_TrueDalitzContamination_R", fV0Reader->GetXYRadius());
2299                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_R", fV0Reader->GetXYRadius());
2300                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_Z", fV0Reader->GetZ());               
2301                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2302                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0MinPt_R", fV0Reader->GetXYRadius());
2303                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0MinPt_Z", fV0Reader->GetZ());                  
2304                                 }
2305                         
2306                                 //--------Histos for HFE 
2307
2308                                 if(statusPos & AliESDtrack::kTOFpid){
2309                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SinglePos_R", fV0Reader->GetXYRadius());
2310                                         if( TESTBIT(itsPixelPos, 0) ){ 
2311                                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SinglePos_kFirst_R", fV0Reader->GetXYRadius());
2312                                         }
2313                                 }
2314                                 if(statusNeg & AliESDtrack::kTOFpid){
2315                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SingleNeg_R", fV0Reader->GetXYRadius());
2316                                         if( TESTBIT(itsPixelNeg, 0) ){ 
2317                                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SingleNeg_kFirst_R", fV0Reader->GetXYRadius());
2318                                         }
2319                                 }
2320                                 //--------------------------------------------------------
2321
2322                         }
2323                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 221){ //eta
2324                                 fHistograms->FillHistogram("ESD_TrueConvDalitzEta_R", fV0Reader->GetXYRadius());
2325                                 fHistograms->FillHistogram("ESD_TrueConvDalitzEta_Z", fV0Reader->GetZ());                               
2326                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2327                                         fHistograms->FillHistogram("ESD_TrueConvDalitzEtaMinPt_R", fV0Reader->GetXYRadius());
2328                                         fHistograms->FillHistogram("ESD_TrueConvDalitzEtaMinPt_Z", fV0Reader->GetZ());                  
2329                                 }
2330                         }
2331
2332                         //}
2333
2334                         if(negativeMC->GetUniqueID() != 5 || positiveMC->GetUniqueID() !=5){// check if the daughters come from a conversion
2335                                 continue;
2336                         }
2337                         
2338                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
2339                                 if(fDoCF){
2340                                         Double_t containerInput[3];
2341                                         containerInput[0] = fV0Reader->GetMotherCandidatePt();
2342                                         containerInput[1] = fV0Reader->GetMotherCandidateEta();
2343                                         containerInput[2] = fV0Reader->GetMotherCandidateMass();
2344                                         fCFManager->GetParticleContainer()->Fill(containerInput,kStepTrueGamma); // for CF 
2345                                 }
2346
2347                                 // RRnewTOF start ///////////////////////////////////////////////
2348                                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) {
2349                                         fHistograms->FillHistogram("ESD_TrueConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
2350                                 }
2351                                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) {
2352                                         fHistograms->FillHistogram("ESD_TrueConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
2353                                 }
2354                                                                 // RRnewTOF end /////////////////////////////////////////////////
2355                                 if (fV0Reader->HasSameMCMother() == kTRUE){
2356                                         fHistograms->FillHistogram("ESD_TrueConvGammaSelected_Alpha_Qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2357                                         fHistograms->FillHistogram("ESD_TrueConvGammaSelected_Pt_Qt",fV0Reader->GetMotherCandidatePt(),armenterosQtAlpha[0]);   
2358                                 }
2359                                 // RRnewTOF end /////////////////////////////////////////////////
2360
2361                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
2362                                 fHistograms->FillHistogram("ESD_TrueConvGamma_CosPoint_RecCosPoint",fV0Reader->GetCosPointingAngle(),fV0Reader->GetV0CosineOfPointingAngle(fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ()));
2363                                 fHistograms->FillHistogram("ESD_TrueConvGamma_PsiPair", fV0Reader->GetPsiPair(fV0Reader->GetCurrentV0()));
2364                                 if(negativeMC->GetMother(0) <= fStack->GetNprimary()){ // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
2365                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
2366                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_R", fV0Reader->GetXYRadius());
2367                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_Z", fV0Reader->GetZ());                            
2368                                         if(  fV0Reader->GetMotherCandidatePt() > 2. ) {
2369                                                 fHistograms->FillHistogram("ESD_TrueConvPrimaryGammaMinPt_R", fV0Reader->GetXYRadius());
2370                                                 fHistograms->FillHistogram("ESD_TrueConvPrimaryGammaMinPt_Z", fV0Reader->GetZ());                               
2371                                         }
2372                                 }
2373                                 else{
2374                                    fHistograms->FillHistogram("ESD_TrueConvSecondaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
2375                                    if(fV0Reader->GetMotherMCParticle()->GetMother(0) > -1){
2376                                       if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetPdgCode() == 310){
2377                                          fHistograms->FillHistogram("ESD_TrueConvSecondaryGammaFromK0s_Pt", fV0Reader->GetMotherCandidatePt());                                         
2378                                       }
2379                                       if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetMother(0) > -1 && 
2380                                          fStack->Particle(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
2381                                          fHistograms->FillHistogram("ESD_TrueConvSecondaryGammaFromXFromK0s_Pt", fV0Reader->GetMotherCandidatePt());                                         
2382                                       }
2383                                    }
2384                                 }
2385                                 if(fV0Reader->GetMotherMCParticle()->GetMother(0) > -1){
2386                                         if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetPdgCode() == 221){ // Use just gamma from eta for ratio esdtruegamma / mcconvgamma
2387                                                 fHistograms->FillHistogram("ESD_TrueConvEtaGamma_Pt", fV0Reader->GetMotherCandidatePt());
2388                                         }
2389                                 }
2390                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
2391                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Eta", fV0Reader->GetMotherCandidateEta());                                
2392                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
2393                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
2394                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
2395    &nbs