]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/GammaConv/AliAnalysisTaskGammaConversion.cxx
comment
[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         Int_t eventQuality=-1;
410
411         AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
412         AliESDInputHandler *esdHandler=0x0;
413         if ( (esdHandler=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler())) && esdHandler->GetESDpid() ){
414                 AliV0Reader::SetESDpid(esdHandler->GetESDpid());
415         } else {
416                 //load esd pid bethe bloch parameters depending on the existance of the MC handler
417                 // yes: MC parameters
418                 // no:  data parameters
419                 if (!AliV0Reader::GetESDpid()){
420                         if (fMCEvent ) {
421                                 AliV0Reader::InitESDpid();
422                         } else {
423                                 AliV0Reader::InitESDpid(1);
424                         }
425                 }
426         } 
427
428         if(fAODGamma) fAODGamma->Clear();
429         
430
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
1027
1028                 if (!particle) {
1029                         //print warning here
1030                         continue;
1031                 }
1032                                 
1033
1034
1035                 
1036                 ///////////////////////Begin Chic Analysis/////////////////////////////
1037                 if(fDoChic) {
1038                         if(particle->GetPdgCode() == 443){//Is JPsi     
1039                                 if(particle->GetNDaughters()==2){
1040                                         if(TMath::Abs(fStack->Particle(particle->GetFirstDaughter())->GetPdgCode()) == 11 &&
1041                                                 TMath::Abs(fStack->Particle(particle->GetLastDaughter())->GetPdgCode()) == 11){
1042
1043                                                 TParticle* daug0 = fStack->Particle(particle->GetFirstDaughter());
1044                                                 TParticle* daug1 = fStack->Particle(particle->GetLastDaughter());
1045                                                 if(TMath::Abs(daug0->Eta()) < 0.9 && TMath::Abs(daug1->Eta()) < 0.9)
1046                                                         fHistograms->FillTable("Table_Electrons",3);//e+ e-     from J/Psi inside acceptance
1047                                                                 
1048                                                 if( TMath::Abs(daug0->Eta()) < 0.9){
1049                                                         if(daug0->GetPdgCode() == -11)
1050                                                                 fHistograms->FillTable("Table_Electrons",1);//e+        from J/Psi inside acceptance
1051                                                         else
1052                                                                 fHistograms->FillTable("Table_Electrons",2);//e-         from J/Psi inside acceptance
1053                                                                         
1054                                                 }
1055                                                 if(TMath::Abs(daug1->Eta()) < 0.9){
1056                                                         if(daug1->GetPdgCode() == -11)
1057                                                                 fHistograms->FillTable("Table_Electrons",1);//e+        from J/Psi inside acceptance
1058                                                         else
1059                                                                 fHistograms->FillTable("Table_Electrons",2);//e-         from J/Psi inside acceptance
1060                                                 }
1061                                         }
1062                                 }
1063                         }
1064                         //                                                      const int CHI_C0         = 10441;
1065                         //                                                      const int CHI_C1         = 20443;
1066                         //                                                      const int CHI_C2         = 445
1067                         if(particle->GetPdgCode() == 22){//gamma from JPsi
1068                                 if(particle->GetMother(0) > -1){
1069                                         if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 10441 ||
1070                                         fStack->Particle(particle->GetMother(0))->GetPdgCode() == 20443 ||
1071                                         fStack->Particle(particle->GetMother(0))->GetPdgCode() == 445){
1072                                                 if(TMath::Abs(particle->Eta()) < 1.2)
1073                                                         fHistograms->FillTable("Table_Electrons",17);// gamma from chic inside accptance
1074                                         }
1075                                 }
1076                         }
1077                         if(particle->GetPdgCode() == 10441 || particle->GetPdgCode() == 20443 || particle->GetPdgCode() == 445){
1078                                 if( particle->GetNDaughters() == 2){
1079                                         TParticle* daug0 = fStack->Particle(particle->GetFirstDaughter());
1080                                         TParticle* daug1 = fStack->Particle(particle->GetLastDaughter());
1081                                                                 
1082                                         if( (daug0->GetPdgCode() == 443 || daug0->GetPdgCode() == 22) && (daug1->GetPdgCode() == 443 || daug1->GetPdgCode() == 22) ){
1083                                                 if( daug0->GetPdgCode() == 443){
1084                                                         TParticle* daugE0 = fStack->Particle(daug0->GetFirstDaughter());
1085                                                         TParticle* daugE1 = fStack->Particle(daug0->GetLastDaughter());
1086                                                         if( TMath::Abs(daug1->Eta()) < 1.2 && TMath::Abs(daugE0->Eta()) < 0.9 && TMath::Abs(daugE1->Eta()) < 0.9 )
1087                                                                 fHistograms->FillTable("Table_Electrons",18);
1088                                                                 
1089                                                 } else if (daug1->GetPdgCode() == 443){
1090                                                         TParticle* daugE0 = fStack->Particle(daug1->GetFirstDaughter());
1091                                                         TParticle* daugE1 = fStack->Particle(daug1->GetLastDaughter());
1092                                                         if( TMath::Abs(daug0->Eta()) < 1.2 && TMath::Abs(daugE0->Eta()) < 0.9 && TMath::Abs(daugE1->Eta()) < 0.9 )
1093                                                         fHistograms->FillTable("Table_Electrons",18);
1094                                                 }//else if
1095                                         }//gamma o Jpsi
1096                                 }//GetNDaughters
1097                         }
1098                 }
1099                                 
1100                 /////////////////////End Chic Analysis////////////////////////////
1101                                 
1102                 //              if(TMath::Abs(particle->Eta())> fV0Reader->GetEtaCut() )        continue;
1103
1104
1105
1106
1107                 if(particle->Eta() <0.8 && particle->Eta() > (-0.8) && particle->GetPDG()->Charge() != 0) {
1108                    nCharged++;
1109                    if(particle->Pt()>0.150){
1110                    nCharged150MeV++;}
1111                 }
1112                 
1113                 
1114                                 
1115                 if(particle->R()>fV0Reader->GetMaxRCut())       continue; // cuts on distance from collision point
1116                                 
1117                 Double_t tmpPhi=particle->Phi();
1118                                 
1119                 if(particle->Phi()> TMath::Pi()){
1120                         tmpPhi = particle->Phi()-(2*TMath::Pi());
1121                 }
1122                                 
1123                 Double_t rapidity;
1124                 if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
1125                         rapidity=8.;
1126                 } else{
1127                         rapidity = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())));
1128                 }       
1129                                 
1130                 if( particle->GetPdgCode()==111){
1131
1132                         //AM move here, otherwise for evt we consider only pi0 to 2 g
1133                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1134                                 if(!fV0Reader->GetIsHeavyIon()) {
1135                                 
1136                                         switch(GetProcessType(fGCMCEvent)){
1137                                         case    kProcSD:
1138                                                 fHistograms->FillHistogram("MC_SD_EvtQ3_Pi0_Pt", particle->Pt());
1139                                                 break;
1140                                         case    kProcDD:
1141                                                 fHistograms->FillHistogram("MC_DD_EvtQ3_Pi0_Pt", particle->Pt());
1142                                                 break;
1143                                         case    kProcND:
1144                                                 fHistograms->FillHistogram("MC_ND_EvtQ3_Pi0_Pt", particle->Pt());
1145                                                 break;
1146                                         default:
1147                                                 AliError("Unknown Process");
1148                                         }       
1149                                 }       
1150                         }
1151                         fHistograms->FillHistogram("MC_Test_AllPi0_Pt", particle->Pt());
1152                         if(particle->GetNDaughters()==2){
1153                                 fHistograms->FillHistogram("MC_Test_2DaughPi0_Pt", particle->Pt());
1154                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1155                                         fHistograms->FillHistogram("MC_Test_2DaughPi0_Rap_Pt", particle->Pt());
1156                                 }
1157                         }
1158                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1159                                 fHistograms->FillHistogram("MC_Test_Pi0_Rap_Pt", particle->Pt());
1160                         }
1161                 }
1162                         
1163                         
1164                 if(particle->GetPdgCode()==221){
1165                         fHistograms->FillHistogram("MC_Test_AllEta_Pt", particle->Pt());
1166                         if(particle->GetNDaughters()==2){
1167                                 fHistograms->FillHistogram("MC_Test_2DaughEta_Pt", particle->Pt());
1168                                 if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1169                                         fHistograms->FillHistogram("MC_Test_2DaughEta_Rap_Pt", particle->Pt());
1170                                 }
1171                         }
1172                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1173                                 fHistograms->FillHistogram("MC_Test_Eta_Rap_Pt", particle->Pt());
1174                         }
1175                 }
1176
1177                 if(  particle->GetPdgCode()==310 ){
1178                         if(TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1179                                 fHistograms->FillHistogram("MC_K0S_Pt", particle->Pt());
1180                         }
1181                 }
1182
1183                 if(iTracks<=fStack->GetNprimary() ){
1184                         if ( particle->GetPdgCode()== -211 ||   particle->GetPdgCode()== 211 ||
1185                                 particle->GetPdgCode()== 2212 ||        particle->GetPdgCode()==-2212 ||
1186                                 particle->GetPdgCode()== 321    ||      particle->GetPdgCode()==-321 ){
1187                                 if(TMath::Abs(particle->Eta())> 0.8 )   continue;        // Eta cut used in charged particle spectrum
1188                                 //if( !particle->IsPhysicalPrimary() ){
1189                                 // cout<<"not Physical primary"<< particle->IsPhysicalPrimary()<<endl;
1190                                 //}
1191                                 if(particle->GetMother(0)>-1){
1192                                         // cout<<"Mother ::"<<fStack->Particle(particle->GetMother(0))->GetPdgCode()<<endl;
1193                                         if (fStack->Particle(particle->GetMother(0))->GetPdgCode()== -211 ||fStack->Particle(particle->GetMother(0))->GetPdgCode()== -3122 ){
1194                                                 //                                              cout<<"Mother K0, lambda::"<<fStack->Particle(particle->GetMother(0))->GetPdgCode()<<endl;
1195                                         continue;
1196                                         }
1197                                 }
1198                                 
1199                                 fHistograms->FillHistogram("MC_PhysicalPrimaryCharged_Pt", particle->Pt());
1200
1201                                 if (particle->GetPdgCode() == 211 ) fHistograms->FillHistogram("MC_PiPlus_Pt", particle->Pt());
1202                                 if (particle->GetPdgCode() == 321 ) fHistograms->FillHistogram("MC_KaonPlus_Pt", particle->Pt());
1203                                 if (particle->GetPdgCode() == 2212 ) fHistograms->FillHistogram("MC_Proton_Pt", particle->Pt());
1204                                 if (particle->GetPdgCode() == -211 ) fHistograms->FillHistogram("MC_PiMinus_Pt", particle->Pt());
1205                                 if (particle->GetPdgCode() == -321 ) fHistograms->FillHistogram("MC_KaonMinus_Pt", particle->Pt());
1206                                 if (particle->GetPdgCode() == -2212 ) fHistograms->FillHistogram("MC_AntiProton_Pt", particle->Pt()); 
1207                         }
1208                         if(TMath::Abs(particle->Eta())<=0.8 ){
1209                                 if (particle->GetPdgCode() == 111 ) fHistograms->FillHistogram("MC_Pi0_Test_Pt", particle->Pt());
1210                         }
1211                 }
1212
1213
1214                 //process the gammas
1215                 if (particle->GetPdgCode() == 22){
1216                         if(TMath::Abs(particle->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(particle->Eta())< fV0Reader->GetEtaCutMin())       continue;                       
1217
1218                         if(particle->GetMother(0) >-1 && fStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
1219                                 continue; // no photon as mothers!
1220                         }
1221                         
1222                         if(particle->GetMother(0) >= fStack->GetNprimary()){
1223                                 continue; // the gamma has a mother, and it is not a primary particle
1224                         }
1225                                 
1226                         if(particle->GetMother(0) >-1){
1227                                 fHistograms->FillHistogram("MC_DecayAllGamma_Pt", particle->Pt()); // All
1228                                 switch(fStack->Particle(particle->GetMother(0))->GetPdgCode()){
1229                                         case 111: // Pi0
1230                                                 fHistograms->FillHistogram("MC_DecayPi0Gamma_Pt", particle->Pt());
1231                                                 break;
1232                                         case 113: // Rho0
1233                                                 fHistograms->FillHistogram("MC_DecayRho0Gamma_Pt", particle->Pt());
1234                                                 break;
1235                                         case 221: // Eta
1236                                                 fHistograms->FillHistogram("MC_DecayEtaGamma_Pt", particle->Pt());
1237                                                 break;
1238                                         case 223: // Omega
1239                                                 fHistograms->FillHistogram("MC_DecayOmegaGamma_Pt", particle->Pt());
1240                                                 break;
1241                                         case 310: // K_s0
1242                                                 fHistograms->FillHistogram("MC_DecayK0sGamma_Pt", particle->Pt());
1243                                                 break;
1244                                         case 331: // Eta'
1245                                                 fHistograms->FillHistogram("MC_DecayEtapGamma_Pt", particle->Pt());
1246                                                 break;
1247                                         case 333: // Phi
1248                                                 fHistograms->FillHistogram("MC_DecayPhiGamma_Pt", particle->Pt());
1249                                                 break;
1250                                 }
1251                         }
1252                         
1253                         fHistograms->FillHistogram("MC_allGamma_Energy", particle->Energy());
1254                         fHistograms->FillHistogram("MC_allGamma_Pt", particle->Pt());
1255                         fHistograms->FillHistogram("MC_allGamma_Eta", particle->Eta());
1256                         fHistograms->FillHistogram("MC_allGamma_Phi", tmpPhi);
1257                         fHistograms->FillHistogram("MC_allGamma_Rapid", rapidity);
1258                                         
1259                         // for CF
1260                         if(fDoCF){
1261                                 containerInput[0] = particle->Pt();
1262                                 containerInput[1] = particle->Eta();
1263                                 if(particle->GetMother(0) >=0){
1264                                         containerInput[2] = fStack->Particle(particle->GetMother(0))->GetMass();
1265                                 } else{
1266                                         containerInput[2]=-1;
1267                                 }
1268                                 fCFManager->GetParticleContainer()->Fill(containerInput,kStepGenerated);                                        // generated gamma
1269                         }
1270                         
1271                         if(particle->GetMother(0) < 0 || //Phojet p+p -> Direct Photons have no mother
1272                         ((particle->GetMother(0) > -1) && 
1273                         ((TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) < 10)|| 
1274                         (TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) ==21) )) //Pythia p+p -> Direct Photons have quarksor gluons as mother
1275                         ){       // direct gamma
1276                                 fHistograms->FillHistogram("MC_allDirectGamma_Energy",particle->Energy());
1277                                 fHistograms->FillHistogram("MC_allDirectGamma_Pt", particle->Pt());
1278                                 fHistograms->FillHistogram("MC_allDirectGamma_Eta", particle->Eta());
1279                                 fHistograms->FillHistogram("MC_allDirectGamma_Phi", tmpPhi);
1280                                 fHistograms->FillHistogram("MC_allDirectGamma_Rapid", rapidity);                                
1281                         }
1282                                         
1283                         // looking for conversion (electron + positron from pairbuilding (= 5) )
1284                         TParticle* ePos = NULL;
1285                         TParticle* eNeg = NULL;
1286                                         
1287                         if(particle->GetNDaughters() >= 2){
1288                                 for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1289                                         TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1290                                         if(tmpDaughter->GetUniqueID() == 5){
1291                                                 if(tmpDaughter->GetPdgCode() == 11){
1292                                                         eNeg = tmpDaughter;
1293                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1294                                                         ePos = tmpDaughter;
1295                                                 }
1296                                         }
1297                                 }
1298                         }
1299                                                 
1300                         if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
1301                                 continue;
1302                         }
1303                                         
1304                                         
1305                         Double_t ePosPhi = ePos->Phi();
1306                         if(ePos->Phi()> TMath::Pi()) ePosPhi = ePos->Phi()-(2*TMath::Pi());
1307                                         
1308                         Double_t eNegPhi = eNeg->Phi();
1309                         if(eNeg->Phi()> TMath::Pi()) eNegPhi = eNeg->Phi()-(2*TMath::Pi());
1310                                                         
1311                         if(ePos->Pt()<fV0Reader->GetSinglePtCut() || eNeg->Pt()<fV0Reader->GetSinglePtCut()){
1312                                 continue; // no reconstruction below the Pt cut
1313                         }
1314                                         
1315                         if( TMath::Abs(ePos->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(ePos->Eta())< fV0Reader->GetEtaCutMin()  || 
1316                             TMath::Abs(eNeg->Eta())> fV0Reader->GetEtaCut() || TMath::Abs(eNeg->Eta())< fV0Reader->GetEtaCutMin() ) {
1317                                 continue;
1318                         }       
1319                                         
1320                         if(ePos->R()>fV0Reader->GetMaxRCut()){
1321                                 continue; // cuts on distance from collision point
1322                         }
1323
1324                         if(TMath::Abs(ePos->Vz()) > fV0Reader->GetMaxZCut()){
1325                                 continue;        // outside material
1326                         }
1327                         if(TMath::Abs(eNeg->Vz()) > fV0Reader->GetMaxZCut()){
1328                                 continue;        // outside material
1329                         }
1330
1331                         if( ePos->R() <= ((TMath::Abs(ePos->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue())){
1332                                 continue;                                                        // line cut to exclude regions where we do not reconstruct
1333                         } else if ( fV0Reader->GetEtaCutMin() != -0.1 &&   ePos->R() >= ((TMath::Abs(ePos->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())       ){
1334                                 continue;
1335                         }
1336                                         
1337                         if( eNeg->R() <= ((TMath::Abs(eNeg->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue())){
1338                                 continue;                                                        // line cut to exclude regions where we do not reconstruct
1339                         } else if ( fV0Reader->GetEtaCutMin() != -0.1 &&   eNeg->R() >= ((TMath::Abs(eNeg->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())       ){
1340                                 continue;
1341                         }
1342                                         
1343                         // for CF
1344                         if(fDoCF){
1345                                 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructable);  // reconstructable gamma        
1346                         }
1347                         fHistograms->FillHistogram("MC_ConvGamma_Energy", particle->Energy());
1348                         fHistograms->FillHistogram("MC_ConvGamma_Pt", particle->Pt());
1349                         // Move down, in the if that mother exists
1350                         //                      if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 221)
1351                         //                      fHistograms->FillHistogram("MC_ConvEtaGamma_Pt", particle->Pt());
1352                         fHistograms->FillHistogram("MC_ConvGamma_Eta", particle->Eta());
1353                         fHistograms->FillHistogram("MC_ConvGamma_Phi", tmpPhi);
1354                         fHistograms->FillHistogram("MC_ConvGamma_Rapid", rapidity);
1355                         fHistograms->FillHistogram("MC_ConvGamma_Pt_Eta", particle->Pt(),particle->Eta());
1356                                         
1357                         fHistograms->FillHistogram("MC_E_Energy", eNeg->Energy());
1358                         fHistograms->FillHistogram("MC_E_Pt", eNeg->Pt());
1359                         fHistograms->FillHistogram("MC_E_Eta", eNeg->Eta());
1360                         fHistograms->FillHistogram("MC_E_Phi", eNegPhi);
1361                                         
1362                         fHistograms->FillHistogram("MC_P_Energy", ePos->Energy());
1363                         fHistograms->FillHistogram("MC_P_Pt", ePos->Pt());
1364                         fHistograms->FillHistogram("MC_P_Eta", ePos->Eta());
1365                         fHistograms->FillHistogram("MC_P_Phi", ePosPhi);
1366                                         
1367                         if(!fV0Reader->GetIsHeavyIon()){
1368                                         
1369                                 // begin Mapping 
1370                                 Int_t rBin              = fHistograms->GetRBin(ePos->R());
1371                                 Int_t zBin              = fHistograms->GetZBin(ePos->Vz());
1372                                 Int_t phiBin    = fHistograms->GetPhiBin(particle->Phi());
1373                                 Double_t rFMD=30;
1374                                 Double_t rITSTPCMin=40;
1375                                 Double_t rITSTPCInt=55;
1376                                 Double_t rITSTPCMax=72.5;
1377                                 
1378                                 TVector3 vtxPos(ePos->Vx(),ePos->Vy(),ePos->Vz());      
1379                                 
1380                                 TString nameMCMappingPhiR="";
1381                                 nameMCMappingPhiR.Form("MC_Conversion_Mapping_Phi%02d_R%02d",phiBin,rBin);
1382                                 // fHistograms->FillHistogram(nameMCMappingPhiR, ePos->Vz(), particle->Eta());
1383                                 
1384                                 TString nameMCMappingPhi="";
1385                                 nameMCMappingPhi.Form("MC_Conversion_Mapping_Phi%02d",phiBin);
1386                                 //                      fHistograms->FillHistogram(nameMCMappingPhi, particle->Eta());
1387                                 //fHistograms->FillHistogram(nameMCMappingPhi, ePos->Vz(), particle->Eta());
1388                                 
1389                                 TString nameMCMappingR="";
1390                                 nameMCMappingR.Form("MC_Conversion_Mapping_R%02d",rBin);
1391                                 //                      fHistograms->FillHistogram(nameMCMappingR, particle->Eta());
1392                                 //fHistograms->FillHistogram(nameMCMappingR,ePos->Vz(), particle->Eta());
1393                                 
1394                                 TString nameMCMappingPhiInR="";
1395                                 nameMCMappingPhiInR.Form("MC_Conversion_Mapping_Phi_in_R_%02d",rBin);
1396                                 //                      fHistograms->FillHistogram(nameMCMappingPhiInR, tmpPhi);
1397                                 fHistograms->FillHistogram(nameMCMappingPhiInR, vtxPos.Phi());
1398                                 
1399                                 TString nameMCMappingZInR="";
1400                                 nameMCMappingZInR.Form("MC_Conversion_Mapping_Z_in_R_%02d",rBin);
1401                                 fHistograms->FillHistogram(nameMCMappingZInR,ePos->Vz() );
1402                                 
1403                                 
1404                                 TString nameMCMappingPhiInZ="";
1405                                 nameMCMappingPhiInZ.Form("MC_Conversion_Mapping_Phi_in_Z_%02d",zBin);
1406                                 //                      fHistograms->FillHistogram(nameMCMappingPhiInR, tmpPhi);
1407                                 fHistograms->FillHistogram(nameMCMappingPhiInZ, vtxPos.Phi());
1408                                 
1409                                 
1410                                 if(ePos->R()<rFMD){
1411                                         TString nameMCMappingFMDPhiInZ="";
1412                                         nameMCMappingFMDPhiInZ.Form("MC_Conversion_Mapping_FMD_Phi_in_Z_%02d",zBin);
1413                                         fHistograms->FillHistogram(nameMCMappingFMDPhiInZ, vtxPos.Phi());
1414                                 }
1415                         
1416                                 if(ePos->R()>rITSTPCMin && ePos->R()<rITSTPCInt){
1417                                         TString nameMCMappingITSTPCPhiInZ="";
1418                                         nameMCMappingITSTPCPhiInZ.Form("MC_Conversion_Mapping_ITSTPC_Phi_in_Z_%02d",zBin);
1419                                         fHistograms->FillHistogram(nameMCMappingITSTPCPhiInZ, vtxPos.Phi());
1420                                 }
1421                         
1422                                 if(ePos->R()>rITSTPCInt && ePos->R()<rITSTPCMax){
1423                                         TString nameMCMappingITSTPC2PhiInZ="";
1424                                         nameMCMappingITSTPC2PhiInZ.Form("MC_Conversion_Mapping_ITSTPC2_Phi_in_Z_%02d",zBin);
1425                                         fHistograms->FillHistogram(nameMCMappingITSTPC2PhiInZ, vtxPos.Phi());
1426                                 }
1427
1428                                 TString nameMCMappingRInZ="";
1429                                 nameMCMappingRInZ.Form("MC_Conversion_Mapping_R_in_Z_%02d",zBin);
1430                                 fHistograms->FillHistogram(nameMCMappingRInZ,ePos->R() );
1431                                 
1432                                 if(particle->Pt() > fLowPtMapping && particle->Pt()< fHighPtMapping){
1433                                         TString nameMCMappingMidPtPhiInR="";
1434                                         nameMCMappingMidPtPhiInR.Form("MC_Conversion_Mapping_MidPt_Phi_in_R_%02d",rBin);
1435                                         fHistograms->FillHistogram(nameMCMappingMidPtPhiInR, vtxPos.Phi());
1436                                         
1437                                         TString nameMCMappingMidPtZInR="";
1438                                         nameMCMappingMidPtZInR.Form("MC_Conversion_Mapping_MidPt_Z_in_R_%02d",rBin);
1439                                         fHistograms->FillHistogram(nameMCMappingMidPtZInR,ePos->Vz() );
1440                                         
1441                                         
1442                                         TString nameMCMappingMidPtPhiInZ="";
1443                                         nameMCMappingMidPtPhiInZ.Form("MC_Conversion_Mapping_MidPt_Phi_in_Z_%02d",zBin);
1444                                         fHistograms->FillHistogram(nameMCMappingMidPtPhiInZ, vtxPos.Phi());
1445                                         
1446                                         
1447                                         if(ePos->R()<rFMD){
1448                                                 TString nameMCMappingMidPtFMDPhiInZ="";
1449                                                 nameMCMappingMidPtFMDPhiInZ.Form("MC_Conversion_Mapping_MidPt_FMD_Phi_in_Z_%02d",zBin);
1450                                                 fHistograms->FillHistogram(nameMCMappingMidPtFMDPhiInZ, vtxPos.Phi());
1451                                         }
1452                                 
1453                                         TString nameMCMappingMidPtRInZ="";
1454                                         nameMCMappingMidPtRInZ.Form("MC_Conversion_Mapping_MidPt_R_in_Z_%02d",zBin);
1455                                         fHistograms->FillHistogram(nameMCMappingMidPtRInZ,ePos->R() );
1456                                         
1457                                 }
1458                         }
1459
1460                         //end mapping
1461                                         
1462                         fHistograms->FillHistogram("MC_Conversion_R",ePos->R());
1463                         fHistograms->FillHistogram("MC_Conversion_ZR",ePos->Vz(),ePos->R());
1464                         fHistograms->FillHistogram("MC_Conversion_XY",ePos->Vx(),ePos->Vy());
1465                         fHistograms->FillHistogram("MC_Conversion_OpeningAngle",GetMCOpeningAngle(ePos, eNeg));
1466                         fHistograms->FillHistogram("MC_ConvGamma_E_AsymmetryP",particle->P(),eNeg->P()/particle->P());
1467                         fHistograms->FillHistogram("MC_ConvGamma_P_AsymmetryP",particle->P(),ePos->P()/particle->P());
1468
1469
1470                         if(particle->GetMother(0) < 0 || //Phojet p+p -> Direct Photons have no mother
1471                                  ((particle->GetMother(0) > -1) && 
1472                                         ((TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) < 10)|| 
1473                                          (TMath::Abs(fStack->Particle(particle->GetMother(0))->GetPdgCode()) ==21) )) //Pythia p+p -> Direct Photons have quarksor gluons as mother
1474                                  ){      // direct gamma, still inside converted
1475                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Energy",particle->Energy());
1476                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Pt", particle->Pt());
1477                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Eta", particle->Eta());
1478                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Phi", tmpPhi);
1479                                 fHistograms->FillHistogram("MC_ConvDirectGamma_Rapid", rapidity);
1480                                                 
1481                         } else{  // mother exits 
1482                                 if(fStack->Particle(particle->GetMother(0))->GetPdgCode() == 221)
1483                                         fHistograms->FillHistogram("MC_ConvEtaGamma_Pt", particle->Pt());
1484                         /*      if( fStack->Particle(particle->GetMother(0))->GetPdgCode()==10441 ||//chic0 
1485                                 fStack->Particle(particle->GetMother(0))->GetPdgCode()==20443 ||//psi2S
1486                                 fStack->Particle(particle->GetMother(0))->GetPdgCode()==445     //chic2
1487                                 ){ 
1488                                 fMCGammaChic.push_back(particle);
1489                                 }
1490                         */
1491                         }       // end if mother exits
1492                 } // end if particle is a photon
1493                                 
1494                                 
1495                                 
1496                 // process motherparticles (2 gammas as daughters)
1497                 // the motherparticle had already to pass the R and the eta cut, but no line cut.
1498                 // the line cut is just valid for the conversions!
1499
1500                 // RR primary Pi0 debug ////////////////////////////////////////////////////////////////////////////////////////////
1501                 if (particle->GetPdgCode()==111){
1502                         if( TMath::Abs(rapidity) < fV0Reader->GetRapidityMesonCut() ){
1503                                 fHistograms->FillHistogram("MC_Pi0_Pt_vs_Rapid_allDaughters", particle->Pt(),rapidity);
1504                         }
1505                 }
1506                 // end RR primary Pi0 debug ////////////////////////////////////////////////////////////////////////////////////////
1507                                 
1508                 if(particle->GetNDaughters() == 2){
1509                                         
1510                         TParticle* daughter0 = (TParticle*)fStack->Particle(particle->GetFirstDaughter());
1511                         TParticle* daughter1 = (TParticle*)fStack->Particle(particle->GetLastDaughter());
1512                                         
1513                         if(daughter0->GetPdgCode() != 22 || daughter1->GetPdgCode() != 22) continue; //check for gamma gamma daughters
1514
1515                         if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ) continue; 
1516
1517                         // Check the acceptance for both gammas
1518                         Bool_t gammaEtaCut = kTRUE;
1519                         if(TMath::Abs(daughter0->Eta()) > fV0Reader->GetEtaCut() || TMath::Abs(daughter0->Eta()) < fV0Reader->GetEtaCutMin() || 
1520                            TMath::Abs(daughter1->Eta()) > fV0Reader->GetEtaCut() || TMath::Abs(daughter1->Eta()) < fV0Reader->GetEtaCutMin()    ) gammaEtaCut = kFALSE;
1521                         
1522                         Bool_t gammaRCut = kTRUE;
1523                         if(daughter0->R() > fV0Reader->GetMaxRCut() || daughter1->R() > fV0Reader->GetMaxRCut() ) gammaRCut = kFALSE;
1524                         
1525                         // check for conversions now -> have to pass eta, R and line cut!
1526                         Bool_t daughter0Electron = kFALSE;
1527                         Bool_t daughter0Positron = kFALSE;
1528                         Bool_t daughter1Electron = kFALSE;
1529                         Bool_t daughter1Positron = kFALSE;
1530                                         
1531                         if(daughter0->GetNDaughters() >= 2){    // first gamma
1532                                 for(Int_t TrackIndex=daughter0->GetFirstDaughter();TrackIndex<=daughter0->GetLastDaughter();TrackIndex++){
1533                                         TParticle *tmpDaughter = fStack->Particle(TrackIndex);
1534                                         if(tmpDaughter->GetUniqueID() == 5){
1535                                                 if(tmpDaughter->GetPdgCode() == 11){    
1536                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1537                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1538                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1539                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1540                                                                                         daughter0Electron = kTRUE;
1541                                                                                 }
1542                                                                         }
1543                                                                 }                       
1544                                                         }
1545                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1546                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1547                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1548                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1549                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1550                                                                                         daughter0Positron = kTRUE;
1551                                                                                 }
1552                                                                         }
1553                                                                 }                       
1554                                                         }                                       
1555                                                 }
1556                                         }
1557                                 }
1558                         }
1559                                         
1560                         if(daughter1->GetNDaughters() >= 2){     // second gamma
1561                                 for(Int_t TrackIndex=daughter1->GetFirstDaughter();TrackIndex<=daughter1->GetLastDaughter();TrackIndex++){
1562                                         TParticle *tmpDaughter = fStack->Particle(TrackIndex);
1563                                         if(tmpDaughter->GetUniqueID() == 5){
1564                                                 if(tmpDaughter->GetPdgCode() == 11){
1565                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1566                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1567                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1568                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1569                                                                                         daughter1Electron = kTRUE;
1570                                                                                 }
1571                                                                         }
1572                                                                 }                       
1573                                                         }
1574                                                 } else if(tmpDaughter->GetPdgCode() == -11){
1575                                                         if( TMath::Abs(tmpDaughter->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(tmpDaughter->Eta()) >= fV0Reader->GetEtaCutMin() ){
1576                                                                 if(  tmpDaughter->R() > ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlope()) - fV0Reader->GetLineCutZValue() ) ){
1577                                                                         if ( (fV0Reader->GetEtaCutMin() != -0.1 &&  tmpDaughter->R() < ((TMath::Abs(tmpDaughter->Vz()) * fV0Reader->GetLineCutZRSlopeMin()) - fV0Reader->GetLineCutZValueMin())) || fV0Reader->GetEtaCutMin() == -0.1   ){
1578                                                                                 if(tmpDaughter->R()< fV0Reader->GetMaxRCut()){
1579                                                                                         daughter1Positron = kTRUE;
1580                                                                                 }
1581                                                                         }
1582                                                                 }                       
1583                                                         }                                       
1584                                                 }
1585                                         }
1586                                 }
1587                         }       
1588                         if(particle->GetPdgCode()==111){                 //Pi0
1589                                 if( iTracks >= fStack->GetNprimary()){
1590                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Eta", particle->Eta());
1591                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Rapid", rapidity);
1592                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Phi", tmpPhi);
1593                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt", particle->Pt());
1594                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Energy", particle->Energy());
1595                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_R", particle->R());
1596                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_ZR", particle->Vz(),particle->R());
1597                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1598                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_XY", particle->Vx(),particle->Vy());//only fill from one daughter to avoid multiple filling
1599                                                                         
1600                                         if(gammaEtaCut && gammaRCut){   
1601                                                 //if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1602                                                 fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1603                                                 fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1604                                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1605                                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1606                                                         fHistograms->FillHistogram("MC_Pi0_Secondaries_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1607                                                 }
1608                                                 if(particle->GetMother(0) > -1){
1609                                                         Int_t pdgPionMother=fStack->Particle(particle->GetMother(0))->GetPdgCode();
1610                                                         if(pdgPionMother ==310 ){
1611                                                                 fHistograms->FillHistogram("MC_K0S_Pt_FromPi0", fStack->Particle(particle->GetMother(0))->Pt());
1612                                                         }
1613                                                 }
1614                                         }
1615                                 } else{
1616
1617                                         fHistograms->FillHistogram("MC_Pi0_Eta", particle->Eta());      
1618                                         fHistograms->FillHistogram("MC_Pi0_Rapid", rapidity);
1619                                         fHistograms->FillHistogram("MC_Pi0_Phi", tmpPhi);
1620                                         fHistograms->FillHistogram("MC_Pi0_Pt", particle->Pt());
1621                                         //if(fGCMCEvent->IsFromBGEvent(iTracks)) fHistograms->FillHistogram("MC_Pi0_Pt_under", particle->Pt());
1622                                         fHistograms->FillHistogram("MC_Pi0_Pt_vs_Rapid", particle->Pt(),rapidity);
1623                                         fHistograms->FillHistogram("MC_Pi0_Energy", particle->Energy());
1624                                         fHistograms->FillHistogram("MC_Pi0_R", particle->R());
1625                                         fHistograms->FillHistogram("MC_Pi0_ZR", particle->Vz(),particle->R());
1626                                         fHistograms->FillHistogram("MC_Pi0_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1627                                         fHistograms->FillHistogram("MC_Pi0_XY", particle->Vx(), particle->Vy());//only fill from one daughter to avoid multiple filling
1628                                         if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_Fiducial", particle->Pt());
1629                                         if(particle->GetMother(0) > -1){
1630                                                 Int_t pdgPionMother=fStack->Particle(particle->GetMother(0))->GetPdgCode();
1631                                                 if(pdgPionMother ==221 ){
1632                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromEta", particle->Pt());
1633                                                 }else   if( pdgPionMother==223 ){
1634                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromOmega", particle->Pt());
1635                                                 }else if(TMath::Abs(pdgPionMother) ==213 ){
1636                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromRhoPlusMinus", particle->Pt());
1637                                                 }else{
1638                                                         fHistograms->FillHistogram("MC_Pi0_Pt_FromOthers", particle->Pt());
1639                                                 }
1640                                         }else{
1641                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Direct", particle->Pt());
1642                                         }
1643
1644                                         if(gammaEtaCut && gammaRCut){
1645                         //              if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1646                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1647                                                 fHistograms->FillHistogram("MC_Pi0_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1648                                                 if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_withinAcceptance_Fiducial", particle->Pt());
1649                                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1650                                                         fHistograms->FillHistogram("MC_Pi0_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1651                                                         fHistograms->FillHistogram("MC_Pi0_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1652                                                         fHistograms->FillHistogram("MC_Pi0_ZR_ConvGamma_withinAcceptance", particle->Vz(),particle->R());
1653                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_OpeningAngle_Pt", particle->Pt(),GetMCOpeningAngle(daughter0,daughter1));
1654                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_PtGamma_Pt", particle->Pt(),daughter0->Pt());
1655                                                         fHistograms->FillHistogram("MC_Pi0_ConvGamma_PtGamma_Pt", particle->Pt(),daughter1->Pt());
1656
1657                                                         Double_t alfa=0.;
1658                                                         if((daughter0->Energy()+daughter1->Energy()) > 0.){
1659                                                                 alfa= TMath::Abs((daughter0->Energy()-daughter1->Energy())/(daughter0->Energy()+daughter1->Energy()));
1660                                                         }
1661                                                         fHistograms->FillHistogram("MC_Pi0_alpha",alfa);
1662                                                         if(TMath::Abs(particle->Eta())<0.9)fHistograms->FillHistogram("MC_Pi0_Pt_ConvGamma_withinAcceptance_Fiducial", particle->Pt());
1663                                                 }
1664                                         }
1665                                 }
1666                         }
1667                                         
1668                         if(particle->GetPdgCode()==221){         //Eta
1669                                 fHistograms->FillHistogram("MC_Eta_Eta", particle->Eta());
1670                                 fHistograms->FillHistogram("MC_Eta_Rapid", rapidity);
1671                                 fHistograms->FillHistogram("MC_Eta_Phi",tmpPhi);
1672                                 fHistograms->FillHistogram("MC_Eta_Pt", particle->Pt());
1673                                 fHistograms->FillHistogram("MC_Eta_Pt_vs_Rapid", particle->Pt(),rapidity);
1674                                 fHistograms->FillHistogram("MC_Eta_Energy", particle->Energy());
1675                                 fHistograms->FillHistogram("MC_Eta_R", particle->R());
1676                                 fHistograms->FillHistogram("MC_Eta_ZR", particle->Vz(),particle->R());
1677                                 fHistograms->FillHistogram("MC_Eta_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1678                                 fHistograms->FillHistogram("MC_Eta_XY", particle->Vx(), particle->Vy());//only fill from one daughter to avoid multiple filling
1679                                                         
1680                                 if(gammaEtaCut && gammaRCut){   
1681                                         //      if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1682                                         fHistograms->FillHistogram("MC_Eta_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1683                                         fHistograms->FillHistogram("MC_Eta_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1684                                         if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1685                                                 fHistograms->FillHistogram("MC_Eta_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1686                                                 fHistograms->FillHistogram("MC_Eta_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1687                                                 fHistograms->FillHistogram("MC_Eta_ZR_ConvGamma_withinAcceptance", particle->Vz(),particle->R());
1688                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_OpeningAngle_Pt", particle->Pt(),GetMCOpeningAngle(daughter0,daughter1));
1689                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_PtGamma_Pt", particle->Pt(),daughter0->Pt());
1690                                                 fHistograms->FillHistogram("MC_Eta_ConvGamma_PtGamma_Pt", particle->Pt(),daughter1->Pt());
1691
1692                                                 Double_t alfa=0.;
1693                                                 if((daughter0->Energy()+daughter1->Energy()) > 0.){
1694                                                         alfa= TMath::Abs((daughter0->Energy()-daughter1->Energy())/(daughter0->Energy()+daughter1->Energy()));
1695                                                 }
1696                                                 fHistograms->FillHistogram("MC_Eta_alpha",alfa);
1697                                         }                       
1698                                 }                       
1699                         }
1700                                         
1701                         // all motherparticles with 2 gammas as daughters
1702                         fHistograms->FillHistogram("MC_Mother_R", particle->R());
1703                         fHistograms->FillHistogram("MC_Mother_ZR", particle->Vz(),particle->R());
1704                         fHistograms->FillHistogram("MC_Mother_XY", particle->Vx(),particle->Vy());
1705                         fHistograms->FillHistogram("MC_Mother_Mass", particle->GetCalcMass());
1706                         fHistograms->FillHistogram("MC_Mother_GammaDaughter_OpeningAngle", GetMCOpeningAngle(daughter0,daughter1));
1707                         fHistograms->FillHistogram("MC_Mother_Energy", particle->Energy());
1708                         fHistograms->FillHistogram("MC_Mother_Pt", particle->Pt());
1709                         fHistograms->FillHistogram("MC_Mother_Eta", particle->Eta());
1710                         fHistograms->FillHistogram("MC_Mother_Rapid", rapidity);
1711                         fHistograms->FillHistogram("MC_Mother_Phi",tmpPhi);
1712                         fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt",particle->GetMass(),particle->Pt());                       
1713                                         
1714                         if(gammaEtaCut && gammaRCut){   
1715                                 //                      if(TMath::Abs(daughter0->Eta()) <= fV0Reader->GetEtaCut() && TMath::Abs(daughter1->Eta()) <= fV0Reader->GetEtaCut() ){
1716                                 fHistograms->FillHistogram("MC_Mother_Pt_Eta_withinAcceptance", particle->Pt(),particle->Eta());
1717                                 fHistograms->FillHistogram("MC_Mother_Pt_Rapid_withinAcceptance", particle->Pt(),rapidity);
1718                                 fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt_withinAcceptance",particle->GetMass(),particle->Pt());                      
1719                                 if(daughter0Electron && daughter0Positron && daughter1Electron && daughter1Positron){
1720                                         fHistograms->FillHistogram("MC_Mother_Pt_Eta_ConvGamma_withinAcceptance", particle->Pt(),particle->Eta());
1721                                         fHistograms->FillHistogram("MC_Mother_Pt_Rapid_ConvGamma_withinAcceptance", particle->Pt(),rapidity);
1722                                         fHistograms->FillHistogram("MC_Mother_InvMass_vs_Pt_ConvGamma_withinAcceptance",particle->GetMass(),particle->Pt());                    
1723                                 }                       
1724                         }       // end passed R and eta cut
1725                 } // end if(particle->GetNDaughters() == 2)
1726         }// end for (Int_t iTracks = 0; iTracks < fStack->GetNtrack(); iTracks++)
1727         
1728         fHistograms->FillHistogram("ESD_TrueMult_vs_MeasMult", nCharged,fMultiplicity);
1729         fHistograms->FillHistogram("ESD_TrueMult_vs_MeasMult_pt150MeV", nCharged150MeV,fMultiplicity);
1730         //cout << "True   " <<  nCharged << "     Meas.     " << fMultiplicity << endl;
1731
1732 } // end ProcessMCData
1733
1734
1735
1736 void AliAnalysisTaskGammaConversion::FillNtuple(){
1737         //Fills the ntuple with the different values
1738         
1739         if(fGammaNtuple == NULL){
1740                 return;
1741         }
1742         Int_t numberOfV0s = fV0Reader->GetNumberOfV0s();
1743         for(Int_t i=0;i<numberOfV0s;i++){
1744                 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};
1745                 AliESDv0 * cV0 = fV0Reader->GetV0(i);
1746                 Double_t negPID=0;
1747                 Double_t posPID=0;
1748                 fV0Reader->GetPIDProbability(negPID,posPID);
1749                 values[0]=cV0->GetOnFlyStatus();
1750                 values[1]=fV0Reader->CheckForPrimaryVertex();
1751                 values[2]=negPID;
1752                 values[3]=posPID;
1753                 values[4]=fV0Reader->GetX();
1754                 values[5]=fV0Reader->GetY();
1755                 values[6]=fV0Reader->GetZ();
1756                 values[7]=fV0Reader->GetXYRadius();
1757                 values[8]=fV0Reader->GetMotherCandidateNDF();
1758                 values[9]=fV0Reader->GetMotherCandidateChi2();
1759                 values[10]=fV0Reader->GetMotherCandidateEnergy();
1760                 values[11]=fV0Reader->GetMotherCandidateEta();
1761                 values[12]=fV0Reader->GetMotherCandidatePt();
1762                 values[13]=fV0Reader->GetMotherCandidateMass();
1763                 values[14]=fV0Reader->GetMotherCandidateWidth();
1764                 //              values[15]=fV0Reader->GetMotherMCParticle()->Pt();       MOVED TO THE END, HAS TO BE CALLED AFTER HasSameMother NB: still has the same entry in the array
1765                 values[16]=fV0Reader->GetOpeningAngle();
1766                 values[17]=fV0Reader->GetNegativeTrackEnergy();
1767                 values[18]=fV0Reader->GetNegativeTrackPt();
1768                 values[19]=fV0Reader->GetNegativeTrackEta();
1769                 values[20]=fV0Reader->GetNegativeTrackPhi();
1770                 values[21]=fV0Reader->GetPositiveTrackEnergy();
1771                 values[22]=fV0Reader->GetPositiveTrackPt();
1772                 values[23]=fV0Reader->GetPositiveTrackEta();
1773                 values[24]=fV0Reader->GetPositiveTrackPhi();
1774                 values[25]=fV0Reader->HasSameMCMother();
1775                 if(values[25] != 0){
1776                         values[26]=fV0Reader->GetMotherMCParticlePDGCode();
1777                         values[15]=fV0Reader->GetMotherMCParticle()->Pt();
1778                 }
1779                 fTotalNumberOfAddedNtupleEntries++;
1780                 fGammaNtuple->Fill(values);
1781         }
1782         fV0Reader->ResetV0IndexNumber();
1783         
1784 }
1785
1786 void AliAnalysisTaskGammaConversion::ProcessV0sNoCut(){
1787         // Process all the V0's without applying any cuts to it
1788         
1789         Int_t numberOfV0s = fV0Reader->GetNumberOfV0s();
1790         for(Int_t i=0;i<numberOfV0s;i++){
1791                 /*AliESDv0 * cV0 = */fV0Reader->GetV0(i);
1792                 
1793                 if(fV0Reader->CheckForPrimaryVertex() == kFALSE){
1794                         continue;
1795                 }
1796
1797                 //              if( !fV0Reader->GetV0(i)->GetOnFlyStatus()){
1798                 if( !fV0Reader->CheckV0FinderStatus(fV0Reader->GetV0(i))){
1799                         continue;
1800                 }
1801
1802
1803
1804                 if( !((fV0Reader->GetNegativeESDTrack())->GetStatus() & AliESDtrack::kTPCrefit) || 
1805                                 !((fV0Reader->GetPositiveESDTrack())->GetStatus() & AliESDtrack::kTPCrefit) ){
1806                         continue;
1807                 }
1808
1809                 if( fV0Reader->GetNegativeESDTrack()->GetSign()== fV0Reader->GetPositiveESDTrack()->GetSign()){
1810                         continue;
1811                 }
1812
1813                 if( fV0Reader->GetNegativeESDTrack()->GetKinkIndex(0) > 0 || 
1814                         fV0Reader->GetPositiveESDTrack()->GetKinkIndex(0) > 0) {                        
1815                         continue;
1816                 }
1817                 if(TMath::Abs(fV0Reader->GetMotherCandidateEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetMotherCandidateEta())< fV0Reader->GetEtaCutMin()){
1818                         continue;
1819                 }
1820                 if(TMath::Abs(fV0Reader->GetPositiveTrackEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetPositiveTrackEta())< fV0Reader->GetEtaCutMin()){
1821                         continue;
1822                 }
1823                 if(TMath::Abs(fV0Reader->GetNegativeTrackEta())> fV0Reader->GetEtaCut() || TMath::Abs(fV0Reader->GetNegativeTrackEta())< fV0Reader->GetEtaCutMin()){
1824                         continue;
1825                 }
1826                 if( fV0Reader->GetXYRadius() <= ((TMath::Abs(fV0Reader->GetZ())*fV0Reader->GetLineCutZRSlope())-fV0Reader->GetLineCutZValue()) ){ // cuts out regions where we do not reconstruct
1827                         continue; 
1828                 } else if ( fV0Reader->GetEtaCutMin() != -0.1 && fV0Reader->GetXYRadius() > ((TMath::Abs(fV0Reader->GetZ())*fV0Reader->GetLineCutZRSlopeMin())-fV0Reader->GetLineCutZValueMin()) ) {
1829                         continue; 
1830                 }
1831
1832                 fHistograms->FillHistogram("ESD_NoCutAllV0_Pt", fV0Reader->GetMotherCandidatePt());
1833
1834                 // RRnewTOF start ///////////////////////////////////////////////
1835                 UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus();
1836                 UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
1837
1838                 Double_t t0pos = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetPositiveTrackP());
1839                 Double_t t0neg = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetNegativeTrackP());
1840
1841                 Double_t timesPos[5];
1842                 fV0Reader->GetPositiveESDTrack()->GetIntegratedTimes(timesPos);
1843                 Double_t timesNeg[5];
1844                 fV0Reader->GetNegativeESDTrack()->GetIntegratedTimes(timesNeg);
1845
1846                 Double_t TOFsignalPos = fV0Reader->GetPositiveTrackTOFsignal();
1847                 Double_t TOFsignalNeg = fV0Reader->GetNegativeTrackTOFsignal();
1848
1849                 Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
1850                 Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
1851
1852                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_WOCutConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
1853                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_WOCutConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
1854                 // RRnewTOF end /////////////////////////////////////////////////
1855                 
1856                 if(fDoMCTruth){
1857                         
1858                         if(fV0Reader->HasSameMCMother() == kFALSE){
1859                                 continue;
1860                         }
1861                         
1862                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
1863                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
1864                         
1865                         if(TMath::Abs(negativeMC->GetPdgCode())!=11 || TMath::Abs(positiveMC->GetPdgCode())!=11){
1866                                 continue;
1867                         }
1868                         if(negativeMC->GetPdgCode() == positiveMC->GetPdgCode()){
1869                                 continue;
1870                         }
1871
1872                         if(negativeMC->GetUniqueID() != 5 || positiveMC->GetUniqueID() !=5){ // id 5 is conversion
1873                                 continue;
1874                         }
1875                         
1876                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){                               
1877                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
1878                                 if(negativeMC->GetMother(0) <= fStack->GetNprimary()){
1879                                    fHistograms->FillHistogram("ESD_NoCutConvPrimaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
1880                                 }
1881                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
1882                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Eta", fV0Reader->GetMotherCandidateEta());                               
1883                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
1884                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
1885                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
1886                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Chi2", fV0Reader->GetMotherCandidateChi2());
1887                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_NDF", fV0Reader->GetMotherCandidateNDF());
1888                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Rapid", fV0Reader->GetMotherCandidateRapidity());
1889                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt_Eta", fV0Reader->GetMotherCandidatePt(),fV0Reader->GetMotherCandidateEta());
1890                                                         
1891                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Pt_Chi2", fV0Reader->GetMotherCandidatePt(), fV0Reader->GetMotherCandidateChi2());
1892                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_Eta_Chi2", fV0Reader->GetMotherCandidateEta(), fV0Reader->GetMotherCandidateChi2());
1893                                                         
1894                                 fHistograms->FillHistogram("ESD_NoCutConversion_XY", fV0Reader->GetX(),fV0Reader->GetY());
1895                                 fHistograms->FillHistogram("ESD_NoCutConversion_R", fV0Reader->GetXYRadius());
1896                                 fHistograms->FillHistogram("ESD_NoCutConversion_MCR",fV0Reader->GetNegativeMCParticle()->R());
1897                                 fHistograms->FillHistogram("ESD_NoCutConversion_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1898                                 fHistograms->FillHistogram("ESD_NoCutConversion_OpeningAngle", fV0Reader->GetOpeningAngle());
1899                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_CosPointingAngle", fV0Reader->GetCosPointingAngle());
1900                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_DcaDaughters", fV0Reader->GetDcaDaughters());
1901                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_NormDcaDistDaughters", fV0Reader->GetNormDcaDistDaughters());
1902                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_LikelihoodAP", fV0Reader->GetLikelihoodAP());
1903
1904                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_E_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetNegativeTrackP()/fV0Reader->GetMotherCandidateP());
1905                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_P_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetPositiveTrackP()/fV0Reader->GetMotherCandidateP());
1906                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_E_dEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetNegativeTrackTPCdEdx());
1907                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_P_dEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetPositiveTrackTPCdEdx());
1908
1909                                 //store MCTruth properties
1910                                 fHistograms->FillHistogram("ESD_NoCutConvGamma_MC_Pt_Eta", fV0Reader->GetMotherMCParticle()->Pt(),fV0Reader->GetMotherMCParticle()->Eta());
1911                                 fHistograms->FillHistogram("ESD_NoCutConversion_MC_ZR", negativeMC->Vz(),negativeMC->R());
1912                                 fHistograms->FillHistogram("ESD_NoCutConversion_MC_XY", negativeMC->Vx(),negativeMC->Vy());
1913                         }
1914                 }
1915         }
1916         fV0Reader->ResetV0IndexNumber();
1917 }
1918
1919 void AliAnalysisTaskGammaConversion::ProcessV0s(){
1920         // see header file for documentation
1921
1922
1923         if(fWriteNtuple == kTRUE){
1924                 FillNtuple();
1925         }
1926         
1927         Int_t nSurvivingV0s=0;
1928         fV0Reader->ResetNGoodV0s();
1929         while(fV0Reader->NextV0()){
1930                 nSurvivingV0s++;
1931                 
1932
1933                 TVector3 vtxConv(fV0Reader->GetX(),fV0Reader->GetY(), fV0Reader->GetZ());
1934         
1935                 //-------------------------- filling v0 information -------------------------------------
1936                 fHistograms->FillHistogram("ESD_Conversion_R", fV0Reader->GetXYRadius());
1937                 fHistograms->FillHistogram("ESD_Conversion_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1938                 fHistograms->FillHistogram("ESD_Conversion_XY", fV0Reader->GetX(),fV0Reader->GetY());
1939                 fHistograms->FillHistogram("ESD_Conversion_OpeningAngle", fV0Reader->GetOpeningAngle());                
1940                 fHistograms->FillHistogram("ESD_ConversionMapping_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
1941                 fHistograms->FillHistogram("ESD_ConversionMapping_ZPhi", fV0Reader->GetZ(),vtxConv.Phi());
1942                 fHistograms->FillHistogram("ESD_ConversionMapping_RPhi", fV0Reader->GetXYRadius(),vtxConv.Phi());
1943                         
1944                 if ( fV0Reader->GetMotherCandidatePt() >= 2.){
1945                         fHistograms->FillHistogram("ESD_Conversion_minPt_R", fV0Reader->GetXYRadius());
1946                         fHistograms->FillHistogram("ESD_Conversion_minPt_Z", fV0Reader->GetZ());
1947                 }
1948
1949                 // Specific histograms for beam pipe studies
1950                 if( TMath::Abs(fV0Reader->GetZ()) < fV0Reader->GetLineCutZValue() && TMath::Abs(fV0Reader->GetZ()) > fV0Reader->GetLineCutZValueMin()){
1951                         fHistograms->FillHistogram("ESD_Conversion_XY_BeamPipe", fV0Reader->GetX(),fV0Reader->GetY());
1952                         fHistograms->FillHistogram("ESD_Conversion_RPhi_BeamPipe", vtxConv.Phi(),fV0Reader->GetXYRadius());
1953                 }
1954
1955         
1956                 fHistograms->FillHistogram("ESD_E_Energy", fV0Reader->GetNegativeTrackEnergy());
1957                 fHistograms->FillHistogram("ESD_E_Pt", fV0Reader->GetNegativeTrackPt());
1958                 fHistograms->FillHistogram("ESD_E_Eta", fV0Reader->GetNegativeTrackEta());
1959                 fHistograms->FillHistogram("ESD_E_Phi", fV0Reader->GetNegativeTrackPhi());
1960                 fHistograms->FillHistogram("ESD_E_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1961                 fHistograms->FillHistogram("ESD_E_nITSClusters", fV0Reader->GetNegativeTracknITSClusters());
1962                 if ( fV0Reader->GetNegativeTrackPt()> 0.150){
1963                         fHistograms->FillHistogram("ESD_E_minPt_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1964                 }
1965                 if ( fV0Reader->GetNegativeTracknITSClusters()==0){
1966                         fHistograms->FillHistogram("ESD_E_onlyTPC_nTPCClusters", fV0Reader->GetNegativeTracknTPCClusters());
1967                 }
1968
1969                 Double_t eClsToF= 0;
1970                 if(!fV0Reader->GetUseCorrectedTPCClsInfo()){
1971                         if(fV0Reader->GetNegativeTracknTPCFClusters()!=0 ){
1972                                 eClsToF=(Double_t)fV0Reader->GetNegativeTracknTPCClusters()/(Double_t)fV0Reader->GetNegativeTracknTPCFClusters();
1973                         }
1974                 } else {
1975                         eClsToF= fV0Reader->GetNegativeESDTrack()->GetTPCClusterInfo(2,0,fV0Reader->GetFirstTPCRow(fV0Reader->GetXYRadius()));
1976                 }
1977                         fHistograms->FillHistogram("ESD_E_nTPCClustersToFP", fV0Reader->GetNegativeTrackP(),eClsToF );
1978                         fHistograms->FillHistogram("ESD_E_nTPCClustersToFR", fV0Reader->GetXYRadius(),eClsToF );
1979
1980                 if(fV0Reader->GetNegativeTracknTPCClusters()!=0 ){
1981                         fHistograms->FillHistogram("ESD_E_TPCchi2", fV0Reader->GetNegativeTrackTPCchi2()/(Double_t)fV0Reader->GetNegativeTracknTPCClusters());
1982                 }
1983
1984
1985
1986                 fHistograms->FillHistogram("ESD_P_Energy", fV0Reader->GetPositiveTrackEnergy());
1987                 fHistograms->FillHistogram("ESD_P_Pt", fV0Reader->GetPositiveTrackPt());
1988                 fHistograms->FillHistogram("ESD_P_Eta", fV0Reader->GetPositiveTrackEta());
1989                 fHistograms->FillHistogram("ESD_P_Phi", fV0Reader->GetPositiveTrackPhi());
1990                 fHistograms->FillHistogram("ESD_P_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
1991                 fHistograms->FillHistogram("ESD_P_nITSClusters", fV0Reader->GetPositiveTracknITSClusters());
1992                 if ( fV0Reader->GetPositiveTrackPt()> 0.150){
1993                         fHistograms->FillHistogram("ESD_P_minPt_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
1994                 }
1995                 if (fV0Reader->GetPositiveTracknITSClusters()==0){
1996                         fHistograms->FillHistogram("ESD_P_onlyTPC_nTPCClusters", fV0Reader->GetPositiveTracknTPCClusters());
1997                 }
1998
1999                 Double_t pClsToF= 0;
2000                 if(!fV0Reader->GetUseCorrectedTPCClsInfo()){
2001                         if(fV0Reader->GetPositiveTracknTPCFClusters()!=0){
2002                                 pClsToF = (Double_t)fV0Reader->GetPositiveTracknTPCClusters()/(Double_t)fV0Reader->GetPositiveTracknTPCFClusters();
2003                         }
2004                 } else {
2005                         pClsToF= fV0Reader->GetPositiveESDTrack()->GetTPCClusterInfo(2,0,fV0Reader->GetFirstTPCRow(fV0Reader->GetXYRadius()));
2006                 }
2007
2008                 fHistograms->FillHistogram("ESD_P_nTPCClustersToFP",fV0Reader->GetPositiveTrackP(), pClsToF);
2009                 fHistograms->FillHistogram("ESD_P_nTPCClustersToFR",fV0Reader->GetXYRadius(), pClsToF);
2010
2011                 if(fV0Reader->GetPositiveTracknTPCClusters()!=0){
2012                         fHistograms->FillHistogram("ESD_P_TPCchi2", fV0Reader->GetPositiveTrackTPCchi2()/(Double_t)fV0Reader->GetPositiveTracknTPCClusters());
2013                 }
2014
2015
2016
2017                 fHistograms->FillHistogram("ESD_ConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
2018                 fHistograms->FillHistogram("ESD_ConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
2019                 fHistograms->FillHistogram("ESD_ConvGamma_Eta", fV0Reader->GetMotherCandidateEta());
2020                 fHistograms->FillHistogram("ESD_ConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
2021                 fHistograms->FillHistogram("ESD_ConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
2022                 fHistograms->FillHistogram("ESD_ConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
2023                 fHistograms->FillHistogram("ESD_ConvGamma_Chi2", fV0Reader->GetMotherCandidateChi2());
2024                 fHistograms->FillHistogram("ESD_ConvGamma_NDF", fV0Reader->GetMotherCandidateNDF());
2025                 fHistograms->FillHistogram("ESD_ConvGamma_Rapid", fV0Reader->GetMotherCandidateRapidity());
2026                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Eta", fV0Reader->GetMotherCandidatePt(),fV0Reader->GetMotherCandidateEta());
2027                 
2028                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Chi2", fV0Reader->GetMotherCandidatePt(), fV0Reader->GetMotherCandidateChi2());
2029                 fHistograms->FillHistogram("ESD_ConvGamma_Eta_Chi2", fV0Reader->GetMotherCandidateEta(), fV0Reader->GetMotherCandidateChi2());
2030                 
2031                 fHistograms->FillHistogram("ESD_ConvGamma_CosPointingAngle", fV0Reader->GetCosPointingAngle());
2032                 fHistograms->FillHistogram("ESD_ConvGamma_CosPoint_RecCosPoint",fV0Reader->GetCosPointingAngle(),fV0Reader->GetV0CosineOfPointingAngle(fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ()));
2033                 fHistograms->FillHistogram("ESD_ConvGamma_PsiPair", fV0Reader->GetPsiPair(fV0Reader->GetCurrentV0()));
2034                 
2035                 fHistograms->FillHistogram("ESD_ConvGamma_DcaDaughters", fV0Reader->GetDcaDaughters());
2036                 fHistograms->FillHistogram("ESD_ConvGamma_NormDcaDistDaughters", fV0Reader->GetNormDcaDistDaughters());
2037                 fHistograms->FillHistogram("ESD_ConvGamma_LikelihoodAP", fV0Reader->GetLikelihoodAP());
2038                 
2039                 fHistograms->FillHistogram("ESD_ConvGamma_E_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetNegativeTrackP()/fV0Reader->GetMotherCandidateP());
2040                 fHistograms->FillHistogram("ESD_ConvGamma_P_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetPositiveTrackP()/fV0Reader->GetMotherCandidateP());
2041                 fHistograms->FillHistogram("ESD_ConvGamma_E_dEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetNegativeTrackTPCdEdx());
2042                 fHistograms->FillHistogram("ESD_ConvGamma_P_dEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetPositiveTrackTPCdEdx());
2043                 fHistograms->FillHistogram("ESD_ConvGamma_E_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kElectron));
2044                 fHistograms->FillHistogram("ESD_ConvGamma_P_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kElectron));
2045                 fHistograms->FillHistogram("ESD_ConvGamma_PiPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kPion));
2046                 fHistograms->FillHistogram("ESD_ConvGamma_PiMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kPion));
2047                 fHistograms->FillHistogram("ESD_ConvGamma_KPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kKaon));
2048                 fHistograms->FillHistogram("ESD_ConvGamma_KMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kKaon));
2049                 fHistograms->FillHistogram("ESD_ConvGamma_PPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kProton));
2050                 fHistograms->FillHistogram("ESD_ConvGamma_PMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kProton));
2051                 fHistograms->FillHistogram("ESD_ConvGamma_MuPl_SigdEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetNegativeESDTrack(),AliPID::kMuon));
2052                 fHistograms->FillHistogram("ESD_ConvGamma_MuMi_SigdEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetESDpid()->NumberOfSigmasTPC(fV0Reader->GetPositiveESDTrack(),AliPID::kMuon));
2053                 
2054
2055                 UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus(); //moved up here from below RRnewTOF
2056                 UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
2057                 // RRnewTOF start ///////////////////////////////////////////////
2058                 Double_t t0pos = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetPositiveTrackP());
2059                 Double_t t0neg = fV0Reader->GetESDpid()->GetTOFResponse().GetStartTime(fV0Reader->GetNegativeTrackP());
2060
2061                 Double_t timesPos[5];
2062                 fV0Reader->GetPositiveESDTrack()->GetIntegratedTimes(timesPos);
2063                 Double_t timesNeg[5];
2064                 fV0Reader->GetNegativeESDTrack()->GetIntegratedTimes(timesNeg);
2065
2066                 Double_t TOFsignalPos = fV0Reader->GetPositiveTrackTOFsignal();
2067                 Double_t TOFsignalNeg = fV0Reader->GetNegativeTrackTOFsignal();
2068
2069                 Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
2070                 Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
2071
2072                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_ConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
2073                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) fHistograms->FillHistogram("ESD_ConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
2074                 // RRnewTOF end /////////////////////////////////////////////////
2075
2076                 Double_t negPID=0;
2077                 Double_t posPID=0;
2078                 fV0Reader->GetPIDProbability(negPID,posPID);
2079                 fHistograms->FillHistogram("ESD_ConvGamma_E_EProbP",fV0Reader->GetNegativeTrackP(),negPID);
2080                 fHistograms->FillHistogram("ESD_ConvGamma_P_EProbP",fV0Reader->GetPositiveTrackP(),posPID);
2081
2082                 Double_t negPIDmupi=0;
2083                 Double_t posPIDmupi=0;
2084                 fV0Reader->GetPIDProbabilityMuonPion(negPIDmupi,posPIDmupi);
2085                 fHistograms->FillHistogram("ESD_ConvGamma_E_mupiProbP",fV0Reader->GetNegativeTrackP(),negPIDmupi);
2086                 fHistograms->FillHistogram("ESD_ConvGamma_P_mupiProbP",fV0Reader->GetPositiveTrackP(),posPIDmupi);
2087
2088                 Double_t armenterosQtAlpha[2] = {0,0};
2089                 if(fV0Reader->GetUseESDQtCut() == 0){
2090                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetNegativeKFParticle(),
2091                                                    fV0Reader->GetPositiveKFParticle(),
2092                                                    fV0Reader->GetMotherCandidateKFCombination(),
2093                                                    armenterosQtAlpha);
2094                 }
2095                 else if(fV0Reader->GetUseESDQtCut() == 1){
2096                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetCurrentV0(), armenterosQtAlpha);
2097                 }
2098                 else if(fV0Reader->GetUseESDQtCut() == 2 || fV0Reader->GetUseESDQtCut() == 3){
2099                    fV0Reader->GetArmenterosQtAlpha(fV0Reader->GetNegativeKFParticle(),
2100                                                    fV0Reader->GetPositiveKFParticle(),
2101                                                    armenterosQtAlpha,
2102                                                    fV0Reader->GetUseESDQtCut());
2103                 }
2104                 
2105                 fHistograms->FillHistogram("ESD_ConvGamma_alfa_qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2106                 fHistograms->FillHistogram("ESD_ConvGamma_Pt_Qt",fV0Reader->GetMotherCandidatePt(),armenterosQtAlpha[0]);
2107         
2108                 if(!fV0Reader->GetIsHeavyIon()){
2109                         fHistograms->FillHistogram("3DPlots_Conversion_XYZ", fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ());            
2110                         //fHistograms->FillHistogram("3DPlots_Conversion_ZRPhi", fV0Reader->GetZ(),fV0Reader->GetXYRadius(), vtxConv.Phi());
2111
2112                         // begin mapping
2113                         Int_t rBin              = fHistograms->GetRBin(fV0Reader->GetXYRadius());
2114                         Int_t zBin              = fHistograms->GetZBin(fV0Reader->GetZ());
2115                         Int_t phiBin    = fHistograms->GetPhiBin(fV0Reader->GetNegativeTrackPhi());
2116                         Double_t rFMD=25;
2117                         Double_t rITSTPCMin=40;
2118                         Double_t rITSTPCInt=55;
2119                         Double_t rITSTPCMax=72.5;
2120                         
2121                         //              Double_t motherCandidateEta= fV0Reader->GetMotherCandidateEta();
2122                         
2123                         TString nameESDMappingPhiR="";
2124                         nameESDMappingPhiR.Form("ESD_Conversion_Mapping_Phi%02d_R%02d",phiBin,rBin);
2125                         //fHistograms->FillHistogram(nameESDMappingPhiR, fV0Reader->GetZ(), motherCandidateEta);
2126                         
2127                         TString nameESDMappingPhi="";
2128                         nameESDMappingPhi.Form("ESD_Conversion_Mapping_Phi%02d",phiBin);
2129                         //fHistograms->FillHistogram(nameESDMappingPhi, fV0Reader->GetZ(), motherCandidateEta);
2130                         
2131                         TString nameESDMappingR="";
2132                         nameESDMappingR.Form("ESD_Conversion_Mapping_R%02d",rBin);
2133                         //fHistograms->FillHistogram(nameESDMappingR, fV0Reader->GetZ(), motherCandidateEta);   
2134                         
2135                         TString nameESDMappingPhiInR="";
2136                         nameESDMappingPhiInR.Form("ESD_Conversion_Mapping_Phi_in_R_%02d",rBin);
2137                         //              fHistograms->FillHistogram(nameESDMappingPhiInR, fV0Reader->GetMotherCandidatePhi());
2138                         fHistograms->FillHistogram(nameESDMappingPhiInR, vtxConv.Phi());
2139                         
2140                         TString nameESDMappingZInR="";
2141                         nameESDMappingZInR.Form("ESD_Conversion_Mapping_Z_in_R_%02d",rBin);
2142                         fHistograms->FillHistogram(nameESDMappingZInR, fV0Reader->GetZ());
2143                         
2144                         TString nameESDMappingPhiInZ="";
2145                         nameESDMappingPhiInZ.Form("ESD_Conversion_Mapping_Phi_in_Z_%02d",zBin);
2146                         //              fHistograms->FillHistogram(nameESDMappingPhiInR, fV0Reader->GetMotherCandidatePhi());
2147                         fHistograms->FillHistogram(nameESDMappingPhiInZ, vtxConv.Phi());
2148                         
2149                         if(fV0Reader->GetXYRadius()<rFMD){
2150                                 TString nameESDMappingFMDPhiInZ="";
2151                                 nameESDMappingFMDPhiInZ.Form("ESD_Conversion_Mapping_FMD_Phi_in_Z_%02d",zBin);
2152                                 fHistograms->FillHistogram(nameESDMappingFMDPhiInZ, vtxConv.Phi());
2153                                 fHistograms->FillHistogram("ESD_ConversionMapping_FMD_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2154                         }
2155                         if(fV0Reader->GetXYRadius()>rFMD && fV0Reader->GetXYRadius()<rITSTPCMin){
2156                                 fHistograms->FillHistogram("ESD_ConversionMapping_FMD2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2157                         }
2158
2159                         if(fV0Reader->GetXYRadius()>rITSTPCMin && fV0Reader->GetXYRadius()<rITSTPCInt){
2160                                 TString nameESDMappingITSTPCPhiInZ="";
2161                                 nameESDMappingITSTPCPhiInZ.Form("ESD_Conversion_Mapping_ITSTPC_Phi_in_Z_%02d",zBin);
2162                                 fHistograms->FillHistogram(nameESDMappingITSTPCPhiInZ, vtxConv.Phi());
2163                                 fHistograms->FillHistogram("ESD_ConversionMapping_ITSTPC_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2164                         }
2165                         
2166                         if(fV0Reader->GetXYRadius()>rITSTPCInt && fV0Reader->GetXYRadius()<rITSTPCMax){
2167                                 TString nameESDMappingITSTPC2PhiInZ="";
2168                                 nameESDMappingITSTPC2PhiInZ.Form("ESD_Conversion_Mapping_ITSTPC2_Phi_in_Z_%02d",zBin);
2169                                 fHistograms->FillHistogram(nameESDMappingITSTPC2PhiInZ, vtxConv.Phi());
2170                                 fHistograms->FillHistogram("ESD_ConversionMapping_ITSTPC2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2171                         }
2172
2173                         TString nameESDMappingRInZ="";
2174                         nameESDMappingRInZ.Form("ESD_Conversion_Mapping_R_in_Z_%02d",zBin);
2175                         fHistograms->FillHistogram(nameESDMappingRInZ, fV0Reader->GetXYRadius());
2176                         
2177                         if(fV0Reader->GetMotherCandidatePt() > fLowPtMapping && fV0Reader->GetMotherCandidatePt()< fHighPtMapping){
2178                                 TString nameESDMappingMidPtPhiInR="";
2179                                 nameESDMappingMidPtPhiInR.Form("ESD_Conversion_Mapping_MidPt_Phi_in_R_%02d",rBin);
2180                                 fHistograms->FillHistogram(nameESDMappingMidPtPhiInR, vtxConv.Phi());
2181                                 
2182                                 TString nameESDMappingMidPtZInR="";
2183                                 nameESDMappingMidPtZInR.Form("ESD_Conversion_Mapping_MidPt_Z_in_R_%02d",rBin);
2184                                 fHistograms->FillHistogram(nameESDMappingMidPtZInR, fV0Reader->GetZ());
2185                                 
2186                                 TString nameESDMappingMidPtPhiInZ="";
2187                                 nameESDMappingMidPtPhiInZ.Form("ESD_Conversion_Mapping_MidPt_Phi_in_Z_%02d",zBin);
2188                                 fHistograms->FillHistogram(nameESDMappingMidPtPhiInZ, vtxConv.Phi());
2189                                 if(fV0Reader->GetXYRadius()<rFMD){
2190                                         TString nameESDMappingMidPtFMDPhiInZ="";
2191                                         nameESDMappingMidPtFMDPhiInZ.Form("ESD_Conversion_Mapping_MidPt_FMD_Phi_in_Z_%02d",zBin);
2192                                         fHistograms->FillHistogram(nameESDMappingMidPtFMDPhiInZ, vtxConv.Phi());
2193                                 }
2194                                 TString nameESDMappingMidPtRInZ="";
2195                                 nameESDMappingMidPtRInZ.Form("ESD_Conversion_Mapping_MidPt_R_in_Z_%02d",zBin);
2196                                 fHistograms->FillHistogram(nameESDMappingMidPtRInZ, fV0Reader->GetXYRadius());  
2197                         }
2198                 }
2199
2200                 // end mapping
2201                 
2202                    
2203                 new((*fKFReconstructedGammasTClone)[fKFReconstructedGammasTClone->GetEntriesFast()])    AliKFConversionPhoton(fV0Reader);
2204              
2205                  
2206                 //----------------------------------- checking for "real" conversions (MC match) --------------------------------------
2207                 if(fDoMCTruth){
2208                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
2209                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
2210                         Double_t rFMD=25;
2211                         Double_t rITSTPCMin=40;
2212                         Double_t rITSTPCInt=55;
2213                         Double_t rITSTPCMax=72.5;
2214  
2215                         if(fV0Reader->HasSameMCMother() == kFALSE){
2216                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_R", fV0Reader->GetXYRadius());
2217                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_Z", fV0Reader->GetZ());
2218                                 fHistograms->FillHistogram("ESD_TrueConvCombSelected_Alpha_Qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2219                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2220                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialMinPt_R", fV0Reader->GetXYRadius());
2221                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialMinPt_Z", fV0Reader->GetZ());                      
2222                                 }
2223                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorial_Pt", fV0Reader->GetMotherCandidatePt());
2224                                 fHistograms->FillHistogram("ESD_TrueConvCombinatorialDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2225                                 if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){
2226                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElec_R", fV0Reader->GetXYRadius());
2227                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElec_Pt", fV0Reader->GetMotherCandidatePt());
2228                                 }
2229                                 if(TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==211){
2230                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPi_R", fV0Reader->GetXYRadius());
2231                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPi_Pt", fV0Reader->GetMotherCandidatePt());
2232                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2233                                 }
2234                                 if((TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==2211) ||
2235                                         (TMath::Abs(negativeMC->GetPdgCode())==2212 && TMath::Abs(positiveMC->GetPdgCode())==211)){
2236                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiP_R", fV0Reader->GetXYRadius());
2237                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiP_Pt", fV0Reader->GetMotherCandidatePt());
2238                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialPiPDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2239                                 }
2240                                 if((TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==211) ||
2241                                         (TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==11)){
2242                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElecPi_R", fV0Reader->GetXYRadius());
2243                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorialElecPi_Pt", fV0Reader->GetMotherCandidatePt());
2244                                 }
2245                                 if( (statusPos & AliESDtrack::kTOFpid) && ( TMath::Abs(positiveMC->GetPdgCode()) != 11 ) && !(statusPos & AliESDtrack::kTOFmismatch) )
2246                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorial_DaughtersNotElec_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);//RRnewTOF
2247                                 if( (statusNeg & AliESDtrack::kTOFpid) && ( TMath::Abs(negativeMC->GetPdgCode()) != 11 ) && !(statusNeg & AliESDtrack::kTOFmismatch) )
2248                                         fHistograms->FillHistogram("ESD_TrueConvCombinatorial_DaughtersNotElec_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);//RRnewTOF
2249                                 continue;
2250                         } 
2251
2252                                                 // Moved up to check true electron background
2253                                                 //                      TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
2254                                                 //                      TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
2255                                                 
2256                         if(TMath::Abs(negativeMC->GetPdgCode())!=11 || TMath::Abs(positiveMC->GetPdgCode())!=11){
2257                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_R", fV0Reader->GetXYRadius());
2258                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Z", fV0Reader->GetZ());
2259                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2260                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBckMinPt_R", fV0Reader->GetXYRadius());
2261                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBckMinPt_Z", fV0Reader->GetZ());                        
2262                                 }
2263                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Pt", fV0Reader->GetMotherCandidatePt());
2264                                 fHistograms->FillHistogram("ESD_TrueConvHadronicBckDaughter_Pt", negativeMC->Pt(),positiveMC->Pt());
2265                                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) )
2266                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Daughters_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);//RRnewTOF
2267                                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) )
2268                                         fHistograms->FillHistogram("ESD_TrueConvHadronicBck_Daughters_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);//RRnewTOF
2269                                 if((TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==2211) ||
2270                                         (TMath::Abs(negativeMC->GetPdgCode())==2212 && TMath::Abs(positiveMC->GetPdgCode())==211)){
2271                                         fHistograms->FillHistogram("ESD_TrueConvLambda_R", fV0Reader->GetXYRadius());
2272                                         fHistograms->FillHistogram("ESD_TrueConvLambda_Pt", fV0Reader->GetMotherCandidatePt());
2273                                 }
2274                                 if(TMath::Abs(negativeMC->GetPdgCode())==211 && TMath::Abs(positiveMC->GetPdgCode())==211){
2275                                         fHistograms->FillHistogram("ESD_TrueConvMeson_R", fV0Reader->GetXYRadius());
2276                                         fHistograms->FillHistogram("ESD_TrueConvMeson_Pt", fV0Reader->GetMotherCandidatePt());
2277                                 }
2278                                 continue;
2279                         }
2280                          
2281
2282                         if(negativeMC->GetPdgCode()==positiveMC->GetPdgCode()){
2283                                 continue;
2284                         }
2285
2286                         //UInt_t statusPos = fV0Reader->GetPositiveESDTrack()->GetStatus(); moved higher
2287                         //UInt_t statusNeg = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
2288                         UChar_t itsPixelPos = fV0Reader->GetPositiveESDTrack()->GetITSClusterMap();
2289                         UChar_t itsPixelNeg = fV0Reader->GetNegativeESDTrack()->GetITSClusterMap();
2290
2291                         // Using the UniqueID Phojet does not get the Dalitz right
2292                         //                      if( (negativeMC->GetUniqueID() == 4 && positiveMC->GetUniqueID() ==4) ||
2293                         //      (negativeMC->GetUniqueID() == 0 && positiveMC->GetUniqueID() ==0) ){// fill r distribution for Dalitz decays 
2294                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 111){ //pi0
2295                                 fHistograms->FillHistogram("ESD_TrueDalitzContamination_R", fV0Reader->GetXYRadius());
2296                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_R", fV0Reader->GetXYRadius());
2297                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_Z", fV0Reader->GetZ());               
2298                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2299                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0MinPt_R", fV0Reader->GetXYRadius());
2300                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0MinPt_Z", fV0Reader->GetZ());                  
2301                                 }
2302                         
2303                                 //--------Histos for HFE 
2304
2305                                 if(statusPos & AliESDtrack::kTOFpid){
2306                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SinglePos_R", fV0Reader->GetXYRadius());
2307                                         if( TESTBIT(itsPixelPos, 0) ){ 
2308                                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SinglePos_kFirst_R", fV0Reader->GetXYRadius());
2309                                         }
2310                                 }
2311                                 if(statusNeg & AliESDtrack::kTOFpid){
2312                                         fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SingleNeg_R", fV0Reader->GetXYRadius());
2313                                         if( TESTBIT(itsPixelNeg, 0) ){ 
2314                                                 fHistograms->FillHistogram("ESD_TrueConvDalitzPi0_SingleNeg_kFirst_R", fV0Reader->GetXYRadius());
2315                                         }
2316                                 }
2317                                 //--------------------------------------------------------
2318
2319                         }
2320                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 221){ //eta
2321                                 fHistograms->FillHistogram("ESD_TrueConvDalitzEta_R", fV0Reader->GetXYRadius());
2322                                 fHistograms->FillHistogram("ESD_TrueConvDalitzEta_Z", fV0Reader->GetZ());                               
2323                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2324                                         fHistograms->FillHistogram("ESD_TrueConvDalitzEtaMinPt_R", fV0Reader->GetXYRadius());
2325                                         fHistograms->FillHistogram("ESD_TrueConvDalitzEtaMinPt_Z", fV0Reader->GetZ());                  
2326                                 }
2327                         }
2328
2329                         //}
2330
2331                         if(negativeMC->GetUniqueID() != 5 || positiveMC->GetUniqueID() !=5){// check if the daughters come from a conversion
2332                                 continue;
2333                         }
2334                         
2335                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
2336                                 if(fDoCF){
2337                                         Double_t containerInput[3];
2338                                         containerInput[0] = fV0Reader->GetMotherCandidatePt();
2339                                         containerInput[1] = fV0Reader->GetMotherCandidateEta();
2340                                         containerInput[2] = fV0Reader->GetMotherCandidateMass();
2341                                         fCFManager->GetParticleContainer()->Fill(containerInput,kStepTrueGamma); // for CF 
2342                                 }
2343
2344                                 // RRnewTOF start ///////////////////////////////////////////////
2345                                 if( (statusPos & AliESDtrack::kTOFpid) && !(statusPos & AliESDtrack::kTOFmismatch) ) {
2346                                         fHistograms->FillHistogram("ESD_TrueConvGamma_EandP_P_dT", fV0Reader->GetPositiveTrackP(), dTpos);
2347                                 }
2348                                 if( (statusNeg & AliESDtrack::kTOFpid) && !(statusNeg & AliESDtrack::kTOFmismatch) ) {
2349                                         fHistograms->FillHistogram("ESD_TrueConvGamma_EandP_P_dT", fV0Reader->GetNegativeTrackP(), dTneg);
2350                                 }
2351                                                                 // RRnewTOF end /////////////////////////////////////////////////
2352                                 if (fV0Reader->HasSameMCMother() == kTRUE){
2353                                         fHistograms->FillHistogram("ESD_TrueConvGammaSelected_Alpha_Qt",armenterosQtAlpha[1],armenterosQtAlpha[0]);
2354                                         fHistograms->FillHistogram("ESD_TrueConvGammaSelected_Pt_Qt",fV0Reader->GetMotherCandidatePt(),armenterosQtAlpha[0]);   
2355                                 }
2356                                 // RRnewTOF end /////////////////////////////////////////////////
2357
2358                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Pt", fV0Reader->GetMotherCandidatePt());
2359                                 fHistograms->FillHistogram("ESD_TrueConvGamma_CosPoint_RecCosPoint",fV0Reader->GetCosPointingAngle(),fV0Reader->GetV0CosineOfPointingAngle(fV0Reader->GetX(),fV0Reader->GetY(),fV0Reader->GetZ()));
2360                                 fHistograms->FillHistogram("ESD_TrueConvGamma_PsiPair", fV0Reader->GetPsiPair(fV0Reader->GetCurrentV0()));
2361                                 if(negativeMC->GetMother(0) <= fStack->GetNprimary()){ // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
2362                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
2363                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_R", fV0Reader->GetXYRadius());
2364                                         fHistograms->FillHistogram("ESD_TrueConvPrimaryGamma_Z", fV0Reader->GetZ());                            
2365                                         if(  fV0Reader->GetMotherCandidatePt() > 2. ) {
2366                                                 fHistograms->FillHistogram("ESD_TrueConvPrimaryGammaMinPt_R", fV0Reader->GetXYRadius());
2367                                                 fHistograms->FillHistogram("ESD_TrueConvPrimaryGammaMinPt_Z", fV0Reader->GetZ());                               
2368                                         }
2369                                 }
2370                                 else{
2371                                    fHistograms->FillHistogram("ESD_TrueConvSecondaryGamma_Pt", fV0Reader->GetMotherCandidatePt());
2372                                    if(fV0Reader->GetMotherMCParticle()->GetMother(0) > -1){
2373                                       if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetPdgCode() == 310){
2374                                          fHistograms->FillHistogram("ESD_TrueConvSecondaryGammaFromK0s_Pt", fV0Reader->GetMotherCandidatePt());                                         
2375                                       }
2376                                       if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetMother(0) > -1 && 
2377                                          fStack->Particle(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
2378                                          fHistograms->FillHistogram("ESD_TrueConvSecondaryGammaFromXFromK0s_Pt", fV0Reader->GetMotherCandidatePt());                                         
2379                                       }
2380                                    }
2381                                 }
2382                                 if(fV0Reader->GetMotherMCParticle()->GetMother(0) > -1){
2383                                         if(fStack->Particle(fV0Reader->GetMotherMCParticle()->GetMother(0))->GetPdgCode() == 221){ // Use just gamma from eta for ratio esdtruegamma / mcconvgamma
2384                                                 fHistograms->FillHistogram("ESD_TrueConvEtaGamma_Pt", fV0Reader->GetMotherCandidatePt());
2385                                         }
2386                                 }
2387                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Energy", fV0Reader->GetMotherCandidateEnergy());
2388                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Eta", fV0Reader->GetMotherCandidateEta());                                
2389                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Phi", fV0Reader->GetMotherCandidatePhi());
2390                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Mass", fV0Reader->GetMotherCandidateMass());
2391                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Width", fV0Reader->GetMotherCandidateWidth());
2392                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Chi2", fV0Reader->GetMotherCandidateChi2());
2393                                 fHistograms->FillHistogram("ESD_TrueConvGamma_NDF", fV0Reader->GetMotherCandidateNDF());
2394                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Pt_Eta", fV0Reader->GetMotherCandidatePt(),fV0Reader->GetMotherCandidateEta());
2395                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Rapid", fV0Reader->GetMotherCandidateRapidity());
2396                                 fHistograms->FillHistogram("ESD_TrueConvGamma_TrackLength",fV0Reader->GetNegativeNTPCClusters());
2397                                 fHistograms->FillHistogram("ESD_TrueConvGamma_TrackLength",fV0Reader->GetPositiveNTPCClusters());
2398                                 fHistograms->FillHistogram("ESD_TrueConvGamma_TrackLengthVSInvMass",fV0Reader->GetNegativeNTPCClusters(),fV0Reader->GetMotherCandidateMass());
2399                                 fHistograms->FillHistogram("ESD_TrueConvGamma_TrackLengthVSInvMass",fV0Reader->GetPositiveNTPCClusters(),fV0Reader->GetMotherCandidateMass());
2400                                                         
2401                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Pt_Chi2", fV0Reader->GetMotherCandidatePt(), fV0Reader->GetMotherCandidateChi2());
2402                                 fHistograms->FillHistogram("ESD_TrueConvGamma_Eta_Chi2", fV0Reader->GetMotherCandidateEta(), fV0Reader->GetMotherCandidateChi2());
2403                                 if ( fV0Reader->GetMotherCandidatePt() > 2. ) {
2404                                         fHistograms->FillHistogram("ESD_TrueConversionMinPt_R", fV0Reader->GetXYRadius());
2405                                         fHistograms->FillHistogram("ESD_TrueConversionMinPt_Z", fV0Reader->GetZ());                     
2406                                 }
2407                                                         
2408                                 fHistograms->FillHistogram("ESD_TrueConversion_E_nTPCClustersToFR", fV0Reader->GetXYRadius(),eClsToF );
2409                                 fHistograms->FillHistogram("ESD_TrueConversion_P_nTPCClustersToFR",fV0Reader->GetXYRadius(), pClsToF);
2410
2411                                 fHistograms->FillHistogram("ESD_TrueConversion_XY", fV0Reader->GetX(),fV0Reader->GetY());
2412                                 fHistograms->FillHistogram("ESD_TrueConversion_R", fV0Reader->GetXYRadius());
2413                                 fHistograms->FillHistogram("ESD_TrueConversion_Z", fV0Reader->GetZ());                          
2414                                 fHistograms->FillHistogram("ESD_TrueConversion_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
2415                                 fHistograms->FillHistogram("ESD_TrueConversionMapping_ZR", fV0Reader->GetZ(),fV0Reader->GetXYRadius());
2416                                 fHistograms->FillHistogram("ESD_TrueConversionMapping_ZPhi", fV0Reader->GetZ(),vtxConv.Phi());
2417                                 fHistograms->FillHistogram("ESD_TrueConversionMapping_RPhi", fV0Reader->GetXYRadius(),vtxConv.Phi());
2418                                 if(fV0Reader->GetXYRadius()<rFMD){
2419                                         fHistograms->FillHistogram("ESD_TrueConversionMapping_FMD_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2420                                 }
2421                                 if(fV0Reader->GetXYRadius()>rFMD && fV0Reader->GetXYRadius()<rITSTPCMin){
2422                                         fHistograms->FillHistogram("ESD_TrueConversionMapping_FMD2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2423                                 }
2424                                 if(fV0Reader->GetXYRadius()>rITSTPCMin && fV0Reader->GetXYRadius()<rITSTPCInt){
2425                                         fHistograms->FillHistogram("ESD_TrueConversionMapping_ITSTPC_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2426                                 }
2427                                 if(fV0Reader->GetXYRadius()>rITSTPCInt && fV0Reader->GetXYRadius()<rITSTPCMax){
2428                                         fHistograms->FillHistogram("ESD_TrueConversionMapping_ITSTPC2_ZPhi",fV0Reader->GetZ() ,vtxConv.Phi());
2429                                 }
2430
2431                                 fHistograms->FillHistogram("ESD_TrueConversion_OpeningAngle", fV0Reader->GetOpeningAngle());
2432
2433                                 //----Histos for HFE-------------------------------------- 
2434
2435                                 if(statusPos & AliESDtrack::kTOFpid){
2436                                         fHistograms->FillHistogram("ESD_TrueConversion_SinglePos_R", positiveMC->R(),fV0Reader->GetPositiveMCParticle()->Pt());
2437                                         if( TESTBIT(itsPixelPos, 0) ){ 
2438                                                 fHistograms->FillHistogram("ESD_TrueConversion_SinglePos_kFirst_R", positiveMC->R(),fV0Reader->GetPositiveMCParticle()->Pt());
2439                                         }
2440                                 }
2441                                 if(statusNeg & AliESDtrack::kTOFpid){
2442                                         fHistograms->FillHistogram("ESD_TrueConversion_SingleNeg_R", negativeMC->R(),fV0Reader->GetNegativeMCParticle()->Pt());
2443                                         if( TESTBIT(itsPixelNeg, 0) ){ 
2444                                                 fHistograms->FillHistogram("ESD_TrueConversion_SingleNeg_kFirst_R", negativeMC->R(),fV0Reader->GetNegativeMCParticle()->Pt());
2445                                         }
2446                                 }
2447                                 //--------------------------------------------------------
2448
2449                                 fHistograms->FillHistogram("ESD_TrueConvGamma_CosPointingAngle", fV0Reader->GetCosPointingAngle());
2450                                 fHistograms->FillHistogram("ESD_TrueConvGamma_DcaDaughters", fV0Reader->GetDcaDaughters());
2451                                 fHistograms->FillHistogram("ESD_TrueConvGamma_NormDcaDistDaughters", fV0Reader->GetNormDcaDistDaughters());
2452                                 fHistograms->FillHistogram("ESD_TrueConvGamma_LikelihoodAP", fV0Reader->GetLikelihoodAP());
2453                                 if (fV0Reader->GetMotherCandidateP() != 0) {
2454                                         fHistograms->FillHistogram("ESD_TrueConvGamma_E_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetNegativeTrackP()/fV0Reader->GetMotherCandidateP());
2455                                         fHistograms->FillHistogram("ESD_TrueConvGamma_P_AsymmetryP",fV0Reader->GetMotherCandidateP(),fV0Reader->GetPositiveTrackP()/fV0Reader->GetMotherCandidateP());
2456                                 } else { 
2457                                         cout << "Error::fV0Reader->GetNegativeTrackP() == 0 !!!" << endl;               
2458                                 }
2459                                 
2460                                 fHistograms->FillHistogram("ESD_TrueConvGamma_E_dEdxP",fV0Reader->GetNegativeTrackP(),fV0Reader->GetNegativeTrackTPCdEdx());
2461                                 fHistograms->FillHistogram("ESD_TrueConvGamma_P_dEdxP",fV0Reader->GetPositiveTrackP(),fV0Reader->GetPositiveTrackTPCdEdx());
2462                                         
2463                                 //store MCTruth properties
2464                                 fHistograms->FillHistogram("ESD_TrueConvGamma_MC_Pt_Eta", fV0Reader->GetMotherMCParticle()->Pt(),fV0Reader->GetMotherMCParticle()->Eta());
2465                                 fHistograms->FillHistogram("ESD_TrueConversion_MC_ZR", negativeMC->Vz(),negativeMC->R());
2466                                 fHistograms->FillHistogram("ESD_TrueConversion_MC_XY", negativeMC->Vx(),negativeMC->Vy());
2467                                 
2468                                 
2469                                 //___________________________________________Resolution______________________________________________________
2470                                 // Different Ways of Producing a Gamma                          
2471                                 // Standard V0 Information                              
2472                                 Double_t mcPt   = fV0Reader->GetMotherMCParticle()->Pt();
2473                                 Double_t mcR = fV0Reader->GetNegativeMCParticle()->R();
2474                                 Double_t mcZ = fV0Reader->GetNegativeMCParticle()->Vz();
2475                                 Double_t resPt = 0.;
2476                                 Double_t resR = 0;
2477                                 Double_t resZ = 0;
2478
2479                                 AliKFParticle AliKFPosParticle(*(fV0Reader->GetExternalTrackParamP(fV0Reader->GetCurrentV0())),-11);
2480                                 AliKFParticle AliKFNegParticle(*(fV0Reader->GetExternalTrackParamN(fV0Reader->GetCurrentV0())),11);
2481
2482                                 // Resolution Normal V0 unchanged from the On-fly/Offline
2483                                 Double_t xyz[3] = {0,0,0};
2484                                 fV0Reader->GetCurrentV0()->GetXYZ(xyz[0],xyz[1],xyz[2]);
2485                                 resPt = mcPt-fV0Reader->GetCurrentV0()->Pt();
2486                                 resR = mcR-TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
2487                                 resZ = mcZ-xyz[2];
2488                                 fHistograms->FillHistogram("Resolution_Gamma_AbsdPt_Pt", mcPt, resPt);
2489                                 fHistograms->FillHistogram("Resolution_Gamma_AbsdR_R", mcR,resR);
2490                                 fHistograms->FillHistogram("Resolution_Gamma_AbsdZ_Z", mcZ,resZ);
2491                                 
2492                                 // Resolution Recalculated V0
2493                                 resR = mcR-fV0Reader->GetXYRadius();
2494                                 resZ = mcZ-fV0Reader->GetZ();
2495                                 // No pt, because we not recalculate v0 pt
2496                                 fHistograms->FillHistogram("Resolution_GammaRecalcPos_AbsdR_R", mcR,resR);
2497                                 fHistograms->FillHistogram("Resolution_GammaRecalcPos_AbsdZ_Z", mcZ,resZ);
2498
2499                                 // Resolution ConstructGamma
2500                                 AliKFParticle constructGammaKF;
2501                                 constructGammaKF.ConstructGamma(AliKFNegParticle,AliKFPosParticle);
2502                                 resPt = mcPt-constructGammaKF.GetPt();
2503                                 resR = mcR-constructGammaKF.GetR();
2504                                 resZ = mcZ-constructGammaKF.GetZ();
2505                                 fHistograms->FillHistogram("Resolution_GammaConstr_AbsdPt_Pt", mcPt, resPt);
2506                                 fHistograms->FillHistogram("Resolution_GammaConstr_AbsdR_R", mcR,resR);
2507                                 fHistograms->FillHistogram("Resolution_GammaConstr_AbsdZ_Z", mcZ,resZ);
2508                                 if(constructGammaKF.GetNDF() !=0)
2509                                    fHistograms->FillHistogram("Resolution_GammaConstr_Chi2NDF", constructGammaKF.GetChi2()/constructGammaKF.GetNDF());
2510                                 
2511
2512                                 // Construct Gamma + Mass Constrained
2513                                 constructGammaKF.SetMassConstraint(0,0.0001);
2514                                 resPt = mcPt-constructGammaKF.GetPt();
2515                                 resR = mcR-constructGammaKF.GetR();
2516                                 resZ = mcZ-constructGammaKF.GetZ();
2517                                 fHistograms->FillHistogram("Resolution_GammaConstrMass_AbsdPt_Pt", mcPt, resPt);
2518                                 fHistograms->FillHistogram("Resolution_GammaConstrMass_AbsdR_R", mcR,resR);
2519                                 fHistograms->FillHistogram("Resolution_GammaConstrMass_AbsdZ_Z", mcZ,resZ);
2520                                 if(constructGammaKF.GetNDF() !=0)
2521                                    fHistograms->FillHistogram("Resolution_GammaConstrMass_Chi2NDF", constructGammaKF.GetChi2()/constructGammaKF.GetNDF());
2522
2523                                 // Construct Gamma + ProductionVertex
2524                                 constructGammaKF.ConstructGamma(AliKFNegParticle,AliKFPosParticle);
2525                                 AliKFVertex primaryVertexImprovedConstruct(*(fV0Reader->GetESDEvent()->GetPrimaryVertex()));
2526                                 primaryVertexImprovedConstruct+=constructGammaKF;
2527                                 constructGammaKF.SetProductionVertex(primaryVertexImprovedConstruct);
2528                                 resPt = mcPt-constructGammaKF.GetPt();
2529                                 resR = mcR-constructGammaKF.GetR();
2530                                 resZ = mcZ-constructGammaKF.GetZ();
2531                                 fHistograms->FillHistogram("Resolution_GammaConstrVtx_AbsdPt_Pt", mcPt, resPt);
2532                                 fHistograms->FillHistogram("Resolution_GammaConstrVtx_AbsdR_R", mcR,resR);
2533                                 fHistograms->FillHistogram("Resolution_GammaConstrVtx_AbsdZ_Z", mcZ,resZ);
2534                                 if(constructGammaKF.GetNDF() !=0)
2535                                    fHistograms->FillHistogram("Resolution_GammaConstrVtx_Chi2NDF", constructGammaKF.GetChi2()/constructGammaKF.GetNDF());
2536
2537                                 // Construct Gamma + Mass Constrained + Production Vtx
2538                                 constructGammaKF.ConstructGamma(AliKFNegParticle,AliKFPosParticle);
2539                                 constructGammaKF.SetMassConstraint(0,0.0001);
2540                                 AliKFVertex primaryVertexImprovedConstructC(*(fV0Reader->GetESDEvent()->GetPrimaryVertex()));
2541                                 primaryVertexImprovedConstructC+=constructGammaKF;
2542                                 constructGammaKF.SetProductionVertex(primaryVertexImprovedConstructC);
2543                                 resPt = mcPt-constructGammaKF.GetPt();
2544                                 resR = mcR-constructGammaKF.GetR();
2545                                 resZ = mcZ-constructGammaKF.GetZ();
2546                                 fHistograms->FillHistogram("Resolution_GammaConstrMassVtx_AbsdPt_Pt", mcPt, resPt);
2547                                 fHistograms->FillHistogram("Resolution_GammaConstrMassVtx_AbsdR_R", mcR,resR);
2548                                 fHistograms->FillHistogram("Resolution_GammaConstrMassVtx_AbsdZ_Z", mcZ,resZ);
2549                                 if(constructGammaKF.GetNDF() !=0)
2550                                    fHistograms->FillHistogram("Resolution_GammaConstrMassVtx_Chi2NDF", constructGammaKF.GetChi2()/constructGammaKF.GetNDF());
2551
2552                                 // Resolution Normal Gamma
2553                                 AliKFParticle normalGammaKF(AliKFNegParticle,AliKFPosParticle);
2554                                 resPt = mcPt-normalGammaKF.GetPt();
2555                                 resR = mcR-normalGammaKF.GetR();
2556                                 resZ = mcZ-normalGammaKF.GetZ();
2557                                 fHistograms->FillHistogram("Resolution_GammaNormal_AbsdPt_Pt", mcPt, resPt);
2558                                 fHistograms->FillHistogram("Resolution_GammaNormal_AbsdR_R", mcR,resR);
2559                                 fHistograms->FillHistogram("Resolution_GammaNormal_AbsdZ_Z", mcZ,resZ);
2560                                 if(normalGammaKF.GetNDF() !=0)
2561                                    fHistograms->FillHistogram("Resolution_GammaNormal_Chi2NDF", normalGammaKF.GetChi2()/normalGammaKF.GetNDF());
2562
2563                                 // Normal Gamma + Mass Constrained
2564                                 normalGammaKF.SetMassConstraint(0,0.0001);
2565                                 resPt = mcPt-normalGammaKF.GetPt();
2566                                 resR = mcR-normalGammaKF.GetR();
2567                                 resZ = mcZ-normalGammaKF.GetZ();
2568                                 fHistograms->FillHistogram("Resolution_GammaNormalMass_AbsdPt_Pt", mcPt, resPt);
2569                                 fHistograms->FillHistogram("Resolution_GammaNormalMass_AbsdR_R", mcR,resR);
2570                                 fHistograms->FillHistogram("Resolution_GammaNormalMass_AbsdZ_Z", mcZ,resZ);
2571                                 if(normalGammaKF.GetNDF() !=0)
2572                                    fHistograms->FillHistogram("Resolution_GammaNormalMass_Chi2NDF", normalGammaKF.GetChi2()/normalGammaKF.GetNDF());
2573                                 
2574                                 // Normal Gamma + ProductionVertex
2575                                 AliKFParticle normalGammaKFVtx(AliKFNegParticle,AliKFPosParticle);
2576                                 AliKFVertex primaryVertexImprovedNormal(*(fV0Reader->GetESDEvent()->GetPrimaryVertex()));
2577                                 primaryVertexImprovedNormal+=normalGammaKFVtx;
2578                                 normalGammaKFVtx.SetProductionVertex(primaryVertexImprovedNormal);
2579                                 resPt = mcPt-normalGammaKFVtx.GetPt();
2580                                 resR = mcR-normalGammaKFVtx.GetR();
2581                                 resZ = mcZ-normalGammaKFVtx.GetZ();
2582                                 fHistograms->FillHistogram("Resolution_GammaNormalVtx_AbsdPt_Pt", mcPt, resPt);
2583                                 fHistograms->FillHistogram("Resolution_GammaNormalVtx_AbsdR_R", mcR,resR);
2584                                 fHistograms->FillHistogram("Resolution_GammaNormalVtx_AbsdZ_Z", mcZ,resZ);
2585                                 if(normalGammaKFVtx.GetNDF() !=0)
2586                                    fHistograms->FillHistogram("Resolution_GammaNormalVtx_Chi2NDF", normalGammaKFVtx.GetChi2()/normalGammaKFVtx.GetNDF());
2587                                 
2588                                 // Normal Gamma + Mass Constrained + Production Vtx
2589                                 AliKFParticle normalGammaKFMassVtx(AliKFNegParticle,AliKFPosParticle);
2590                                 normalGammaKFMassVtx.SetMassConstraint(0,0.0001);
2591                                 AliKFVertex primaryVertexImprovedNormalMassVtx(*(fV0Reader->GetESDEvent()->GetPrimaryVertex()));
2592                                 primaryVertexImprovedNormalMassVtx+=normalGammaKFMassVtx;
2593                                 normalGammaKFMassVtx.SetProductionVertex(primaryVertexImprovedNormalMassVtx);
2594                                 resPt = mcPt-normalGammaKFMassVtx.GetPt();
2595                                 resR = mcR-normalGammaKFMassVtx.GetR();
2596                                 resZ = mcZ-normalGammaKFMassVtx.GetZ();
2597                                 fHistograms->FillHistogram("Resolution_GammaNormalMassVtx_AbsdPt_Pt", mcPt, resPt);
2598                                 fHistograms->FillHistogram("Resolution_GammaNormalMassVtx_AbsdR_R", mcR,resR);
2599                                 fHistograms->FillHistogram("Resolution_GammaNormalMassVtx_AbsdZ_Z", mcZ,resZ);
2600                                 if(normalGammaKFMassVtx.GetNDF() !=0)
2601                                    fHistograms->FillHistogram("Resolution_GammaNormalMassVtx_Chi2NDF", normalGammaKFMassVtx.GetChi2()/normalGammaKFMassVtx.GetNDF());
2602
2603
2604                                 // ---------- End new Resolution ------------------
2605                                 Double_t mcpt    = fV0Reader->GetMotherMCParticle()->Pt();
2606                                 Double_t esdpt  = fV0Reader->GetMotherCandidatePt();
2607                                 Double_t resdPt = 0.;
2608                                 if(mcpt > 0){
2609                                         resdPt = ((esdpt - mcpt)/mcpt)*100.;
2610                                 } else if(mcpt < 0){
2611                                         cout<<"Pt of MC particle is negative, this will cause wrong calculation of resPt"<<endl; 
2612                                 }
2613                                 
2614                                 TVector3 vtxConvRes(fV0Reader->GetX(),fV0Reader->GetY(), fV0Reader->GetZ());
2615                                 
2616                                 fHistograms->FillHistogram("Resolution_Gamma_dPt_Pt", mcpt, resdPt);
2617                                 fHistograms->FillHistogram("Resolution_MCPt_ESDPt", mcpt,esdpt);
2618                                 fHistograms->FillHistogram("Resolution_Gamma_dPt_Phi", vtxConvRes.Phi(), resdPt);
2619                                 if (esdpt> 0.150){
2620                                         fHistograms->FillHistogram("Resolution_Gamma_minPt_dPt_Phi", vtxConvRes.Phi(), resdPt);
2621                                 }
2622                                                 
2623                                 Double_t resdZ = 0.;
2624                                 if(fV0Reader->GetNegativeMCParticle()->Vz() != 0){
2625                                         resdZ = ((fV0Reader->GetZ() -fV0Reader->GetNegativeMCParticle()->Vz())/fV0Reader->GetNegativeMCParticle()->Vz())*100.;
2626                                 }
2627                                 Double_t resdZAbs = 0.;
2628                                 resdZAbs = (fV0Reader->GetZ() -fV0Reader->GetNegativeMCParticle()->Vz());
2629
2630                                 fHistograms->FillHistogram("Resolution_dZAbs_VS_R", fV0Reader->GetNegativeMCParticle()->R(), resdZAbs);
2631                                 fHistograms->FillHistogram("Resolution_dZAbs_VS_Z", fV0Reader->GetNegativeMCParticle()->Vz(), resdZAbs);
2632                                 fHistograms->FillHistogram("Resolution_dZAbs_VS_Phi", vtxConvRes.Phi(), resdZAbs);
2633                                 fHistograms->FillHistogram("Resolution_dZ", fV0Reader->GetNegativeMCParticle()->Vz(), resdZ);
2634                                 fHistograms->FillHistogram("Resolution_MCZ_ESDZ", fV0Reader->GetNegativeMCParticle()->Vz(),fV0Reader->GetZ());
2635                                         
2636                                 // new for dPt_Pt-histograms for Electron and Positron
2637                                 Double_t mcEpt;
2638                                 Double_t resEdPt=0;
2639                                 UInt_t kTRDoutN, statusN;
2640                                 Int_t nITSclsE;
2641                                 // new for dPt_Pt-histograms for Electron and Positron
2642                                 if (fV0Reader->GetNegativeMCParticle()->GetPdgCode() == 11) {
2643                                         mcEpt = fV0Reader->GetNegativeMCParticle()->Pt();
2644                                 } else {
2645                                         mcEpt = fV0Reader->GetPositiveMCParticle()->Pt();
2646                                 }
2647                                 if (mcEpt > 0){ 
2648                                         resEdPt = ((fV0Reader->GetNegativeTrackPt()-mcEpt)/mcEpt)*100.;
2649                                 }
2650                                 statusN = fV0Reader->GetNegativeESDTrack()->GetStatus(); 
2651                                 kTRDoutN =      (statusN & AliESDtrack::kTRDout);
2652                                 nITSclsE= fV0Reader->GetNegativeTracknITSClusters();
2653
2654                                 // filling Resolution_Pt_dPt with respect to the Number of ITS clusters for Positrons
2655                                 switch(nITSclsE){
2656                                 case 0: // 0 ITS clusters
2657                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS0", mcEpt, resEdPt);
2658                                         break;
2659                                 case 1: // 1 ITS cluster
2660                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS1", mcEpt, resEdPt);
2661                                         break;
2662                                 case 2: // 2 ITS clusters
2663                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS2", mcEpt, resEdPt);
2664                                         break;
2665                                 case 3: // 3 ITS clusters
2666                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS3", mcEpt, resEdPt);
2667                                         break;
2668                                 case 4: // 4 ITS clusters
2669                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS4", mcEpt, resEdPt);
2670                                         break;
2671                                 case 5: // 5 ITS clusters
2672                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS5", mcEpt, resEdPt);
2673                                         break;
2674                                 case 6: // 6 ITS clusters
2675                                         fHistograms->FillHistogram("Resolution_E_dPt_Pt_ITS6", mcEpt, resEdPt);
2676                                         break;
2677                                 }
2678                                 //Filling histograms with respect to Electron resolution
2679                                 fHistograms->FillHistogram("Resolution_E_dPt_Pt", mcEpt, resEdPt);
2680                                 fHistograms->FillHistogram("Resolution_E_dPt_Phi", vtxConvRes.Phi(), resEdPt);
2681                                 if (fV0Reader->GetNegativeTrackPt()> 0.150){
2682                                         fHistograms->FillHistogram("Resolution_E_minPt_dPt_Phi", vtxConvRes.Phi(), resEdPt);
2683                                 }
2684
2685                                 if(kTRDoutN){
2686                                         fHistograms->FillHistogram("Resolution_E_nTRDtracklets_ESDPt", fV0Reader->GetNegativeTrackPt(), fV0Reader->GetNegativeESDTrack()->GetTRDntracklets());
2687                                         fHistograms->FillHistogram("Resolution_E_nTRDtracklets_MCPt", mcEpt, fV0Reader->GetNegativeESDTrack()->GetTRDntracklets());     
2688                                         fHistograms->FillHistogram("Resolution_E_nTRDclusters_ESDPt",fV0Reader->GetNegativeTrackPt(), fV0Reader->GetNegativeESDTrack()->GetTRDncls());
2689                                         fHistograms->FillHistogram("Resolution_E_nTRDclusters_MCPt",mcEpt, fV0Reader->GetNegativeESDTrack()->GetTRDncls());
2690                                         fHistograms->FillHistogram("Resolution_E_TRDsignal_ESDPt", fV0Reader->GetNegativeTrackPt(), fV0Reader->GetNegativeESDTrack()->GetTRDsignal());
2691                                 }
2692
2693                                 Double_t mcPpt;
2694                                 if (fV0Reader->GetPositiveMCParticle()->GetPdgCode() == -11) {
2695                                         mcPpt = fV0Reader->GetPositiveMCParticle()->Pt();
2696                                 } else {
2697                                         mcPpt = fV0Reader->GetNegativeMCParticle()->Pt();
2698                                 }
2699
2700                                 Double_t resPdPt = 0;
2701                                 if (mcPpt > 0){ 
2702                                         resPdPt = ((fV0Reader->GetPositiveTrackPt()-mcPpt)/mcPpt)*100.;
2703                                 }
2704
2705                                 UInt_t statusP = fV0Reader->GetPositiveESDTrack()->GetStatus(); 
2706                                 //               AliESDtrack * posTr= fV0Reader->GetPositiveESDTrack();
2707                                 UInt_t kTRDoutP =       (statusP & AliESDtrack::kTRDout);
2708                                 
2709                                 Int_t nITSclsP = fV0Reader->GetPositiveTracknITSClusters();
2710                                 // filling Resolution_Pt_dPt with respect to the Number of ITS clusters for Positrons
2711                                 switch(nITSclsP){
2712                                 case 0: // 0 ITS clusters
2713                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS0", mcPpt, resPdPt);
2714                                         break;
2715                                 case 1: // 1 ITS cluster
2716                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS1", mcPpt, resPdPt);
2717                                         break;
2718                                 case 2: // 2 ITS clusters
2719                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS2", mcPpt, resPdPt);
2720                                         break;
2721                                 case 3: // 3 ITS clusters
2722                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS3", mcPpt, resPdPt);
2723                                         break;
2724                                 case 4: // 4 ITS clusters
2725                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS4", mcPpt, resPdPt);
2726                                         break;
2727                                 case 5: // 5 ITS clusters
2728                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS5", mcPpt, resPdPt);
2729                                         break;
2730                                 case 6: // 6 ITS clusters
2731                                         fHistograms->FillHistogram("Resolution_P_dPt_Pt_ITS6", mcPpt, resPdPt);
2732                                         break;
2733                                 }
2734                                 //Filling histograms with respect to Positron resolution
2735                                 fHistograms->FillHistogram("Resolution_P_dPt_Pt", mcPpt, resPdPt);
2736                                 fHistograms->FillHistogram("Resolution_P_dPt_Phi", vtxConvRes.Phi(), resPdPt);
2737                                 if (fV0Reader->GetPositiveTrackPt()> 0.150){
2738                                         fHistograms->FillHistogram("Resolution_P_minPt_dPt_Phi", vtxConvRes.Phi(), resPdPt);
2739                                 }
2740
2741                                 if(kTRDoutP){
2742                                         fHistograms->FillHistogram("Resolution_P_nTRDtracklets_ESDPt", fV0Reader->GetPositiveTrackPt(), fV0Reader->GetPositiveESDTrack()->GetTRDntracklets());
2743                                         fHistograms->FillHistogram("Resolution_P_nTRDtracklets_MCPt", mcPpt, fV0Reader->GetPositiveESDTrack()->GetTRDntracklets());
2744                                         fHistograms->FillHistogram("Resolution_P_nTRDclusters_ESDPt",fV0Reader->GetPositiveTrackPt(), fV0Reader->GetPositiveESDTrack()->GetTRDncls());
2745                                         fHistograms->FillHistogram("Resolution_P_nTRDclusters_MCPt",mcPpt, fV0Reader->GetPositiveESDTrack()->GetTRDncls());
2746                                         fHistograms->FillHistogram("Resolution_P_TRDsignal_ESDPt", fV0Reader->GetPositiveTrackPt(), fV0Reader->GetPositiveESDTrack()->GetTRDsignal());
2747                                 }
2748
2749                         
2750                                 Double_t resdR = 0.;
2751                                 if(fV0Reader->GetNegativeMCParticle()->R() != 0){
2752                                         resdR = ((fV0Reader->GetXYRadius() - fV0Reader->GetNegativeMCParticle()->R())/fV0Reader->GetNegativeMCParticle()->R())*100.;
2753                                 }
2754                                 Double_t resdRAbs = 0.;
2755                                 resdRAbs = (fV0Reader->GetXYRadius() - fV0Reader->GetNegativeMCParticle()->R());
2756
2757                                 fHistograms->FillHistogram("Resolution_dRAbs_VS_R", fV0Reader->GetNegativeMCParticle()->R(), resdRAbs);
2758                                 fHistograms->FillHistogram("Resolution_dRAbs_VS_Z", fV0Reader->GetNegativeMCParticle()->Vz(), resdRAbs);
2759                                 fHistograms->FillHistogram("Resolution_dRAbs_VS_Phi",  vtxConvRes.Phi(), resdRAbs);
2760                                 fHistograms->FillHistogram("Resolution_dR", fV0Reader->GetNegativeMCParticle()->R(), resdR);
2761                                 fHistograms->FillHistogram("Resolution_MCR_ESDR", fV0Reader->GetNegativeMCParticle()->R(),fV0Reader->GetXYRadius());
2762                                 fHistograms->FillHistogram("Resolution_R_dPt", fV0Reader->GetNegativeMCParticle()->R(), resdPt);
2763                                 if (esdpt> 0.150){
2764                                         fHistograms->FillHistogram("Resolution_minPt_R_dPt", fV0Reader->GetNegativeMCParticle()->R(), resdPt);
2765                                 }
2766
2767                                 Double_t resdPhiAbs=0.;
2768                                 resdPhiAbs=0.;
2769                                 resdPhiAbs= (vtxConvRes.Phi()-fV0Reader->GetNegativeMCParticle()->Phi());
2770                                 fHistograms->FillHistogram("Resolution_MCPhi_ESDPhi", fV0Reader->GetNegativeMCParticle()->Phi(),vtxConvRes.Phi());
2771                                 fHistograms->FillHistogram("Resolution_dPhiAbs_VS_R", fV0Reader->GetNegativeMCParticle()->R(), resdPhiAbs);
2772                                 fHistograms->FillHistogram("Resolution_dPhiAbs_VS_Z", fV0Reader->GetNegativeMCParticle()->Vz(), resdPhiAbs);
2773                                 fHistograms->FillHistogram("Resolution_dPhiAbs_VS_Phi",  vtxConvRes.Phi(), resdPhiAbs);
2774                         }//if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22)
2775                 }//if(fDoMCTruth)
2776         }//while(fV0Reader->NextV0)
2777         fHistograms->FillHistogram("ESD_NumberOfSurvivingV0s", nSurvivingV0s);
2778         fHistograms->FillHistogram("ESD_NumberOfV0s", fV0Reader->GetNumberOfV0s());
2779         fHistograms->FillHistogram("ESD_NumberOfContributorsVtx", fV0Reader->GetNumberOfContributorsVtx());
2780         fV0Reader->ResetV0IndexNumber();
2781 }
2782
2783  
2784
2785 //_____________________________________________________________________________________
2786 void AliAnalysisTaskGammaConversion::ProcessGammasForOmegaMesonAnalysis(){
2787         // omega meson analysis pi0+gamma decay
2788         for(Int_t firstPi0Index=0;firstPi0Index<fKFReconstructedPi0sTClone->GetEntriesFast();firstPi0Index++){
2789                 AliKFConversionMother * omegaCandidatePi0Daughter = (AliKFConversionMother *)fKFReconstructedPi0sTClone->At(firstPi0Index);
2790                 for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
2791
2792                         AliKFConversionPhoton * omegaCandidateGammaDaughter = (AliKFConversionPhoton *)fKFReconstructedGammasTClone->At(firstGammaIndex);
2793                            if(omegaCandidatePi0Daughter->GetGammaLabel(0)==firstGammaIndex || omegaCandidatePi0Daughter->GetGammaLabel(1)==firstGammaIndex){
2794                                 continue;
2795                         }
2796
2797                         AliKFParticle omegaCandidate(*omegaCandidatePi0Daughter,*omegaCandidateGammaDaughter);
2798                         Double_t massOmegaCandidate = 0.;
2799                         Double_t widthOmegaCandidate = 0.;
2800
2801                         omegaCandidate.GetMass(massOmegaCandidate,widthOmegaCandidate);
2802
2803                         if ( massOmegaCandidate > 733 && massOmegaCandidate < 833 ) {
2804                                 //AddOmegaToAOD(&omegaCandidate, massOmegaCandidate, firstPi0Index, firstGammaIndex);
2805                         }
2806                         
2807                         fHistograms->FillHistogram("ESD_Omega_InvMass_vs_Pt",massOmegaCandidate ,omegaCandidate.GetPt());
2808                         fHistograms->FillHistogram("ESD_Omega_InvMass",massOmegaCandidate);
2809  
2810                         //delete omegaCandidate;
2811
2812                 }// end of omega reconstruction in pi0+gamma channel
2813
2814                 if(fDoJet == kTRUE){
2815                         AliKFParticle* negPiKF=NULL;
2816                         AliKFParticle* posPiKF=NULL;
2817                         Int_t piPlusMotherLabel=-1;
2818                         Int_t piMinusMotherLabel=-1;
2819                         
2820                         // look at the pi+pi+pi0 channel 
2821                         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
2822                                 AliESDtrack* posTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
2823                                 if (posTrack->GetSign()<0) continue;
2824                                 if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(posTrack,AliPID::kPion))>2.) continue;
2825                                 if (posPiKF) delete posPiKF; posPiKF=NULL;
2826                                 posPiKF = new AliKFParticle( *(posTrack) ,211);
2827                                 if(fDoMCTruth){
2828                                         TParticle * positiveMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[iCh])->GetLabel()));
2829                                         if(positiveMCParticle->GetMother(0)>-1){
2830                                                 piPlusMotherLabel = positiveMCParticle->GetMother(0);
2831                                         }
2832                                 }
2833                                 
2834                                 for(Int_t jCh=0;jCh<fChargedParticles->GetEntriesFast();jCh++){
2835                                         AliESDtrack* negTrack = (AliESDtrack*)(fChargedParticles->At(jCh));
2836                                         if( negTrack->GetSign()>0) continue;
2837                                         if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(negTrack,AliPID::kPion))>2.) continue;
2838                                         if (negPiKF) delete negPiKF; negPiKF=NULL;
2839                                         negPiKF = new AliKFParticle( *(negTrack) ,-211);
2840                                         AliKFParticle omegaCandidatePipPinPi0(*omegaCandidatePi0Daughter,*posPiKF,*negPiKF);
2841                                         Double_t massOmegaCandidatePipPinPi0 = 0.;
2842                                         Double_t widthOmegaCandidatePipPinPi0 = 0.;
2843                                         
2844                                         omegaCandidatePipPinPi0.GetMass(massOmegaCandidatePipPinPi0,widthOmegaCandidatePipPinPi0);
2845
2846                                         if ( massOmegaCandidatePipPinPi0 > 733 && massOmegaCandidatePipPinPi0 < 833 ) {
2847                                                 // AddOmegaToAOD(&omegaCandidatePipPinPi0, massOmegaCandidatePipPinPi0, -1, -1);
2848                                         }
2849                                         
2850                                         fHistograms->FillHistogram("ESD_OmegaPipPinPi0_InvMass_vs_Pt",massOmegaCandidatePipPinPi0 ,omegaCandidatePipPinPi0.GetPt());
2851                                         fHistograms->FillHistogram("ESD_OmegaPipPinPi0_InvMass",massOmegaCandidatePipPinPi0);
2852
2853
2854                                         if(fDoMCTruth){
2855                                                 TParticle * negativeMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[jCh])->GetLabel()));
2856                                                 if(negativeMCParticle->GetMother(0)>-1){
2857                                                         piMinusMotherLabel = negativeMCParticle->GetMother(0);
2858                                                         if(     piMinusMotherLabel ==   piPlusMotherLabel){
2859                                                                 Int_t geantCode=fStack->Particle(TMath::Abs(piPlusMotherLabel))->GetPdgCode();
2860                                                                 if(geantCode == 221 || geantCode == 223){
2861                                                                         fHistograms->FillHistogram("ESD_TrueOmegaPipPinPi0_InvMass_vs_Pt",massOmegaCandidatePipPinPi0 ,omegaCandidatePipPinPi0.GetPt());
2862                                                                 }
2863                                                         }                               
2864
2865                                                 }
2866
2867                                         }
2868         
2869                                         //      delete omegaCandidatePipPinPi0;
2870                                 }
2871                         }
2872
2873                         if (posPiKF) delete posPiKF; posPiKF=NULL;               if (negPiKF) delete negPiKF; negPiKF=NULL;
2874
2875                 } // checking ig gammajet because in that case the chargedparticle list is created
2876
2877         }
2878         ////////////////////////
2879
2880         // gamma+ pi+
2881         if(fDoJet == kTRUE){
2882                 for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
2883                         AliKFConversionPhoton * rhoCandidateGammaDaughter = (AliKFConversionPhoton *)fKFReconstructedGammasTClone->At(firstGammaIndex);
2884                         Int_t gamma1MotherLabel=-1;
2885                         if(fDoMCTruth){
2886                                 Int_t indexKF1 = rhoCandidateGammaDaughter->GetV0Index();
2887                                 if(indexKF1<fV0Reader->GetNumberOfV0s()){
2888                                         fV0Reader->GetV0(indexKF1);//updates to the correct v0
2889
2890                                         if(fV0Reader->HasSameMCMother() == kTRUE){
2891                                                 //cout<<"This v0 is a real v0!!!!"<<endl;
2892                                                 TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
2893                                                 TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
2894                                                 if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){
2895                                                         if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){
2896                                                                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
2897                                                                         gamma1MotherLabel=fV0Reader->GetMotherMCParticle()->GetFirstMother();
2898                                                                 }
2899                                                         }
2900                                                 }
2901                                         }
2902                                 }
2903                         }
2904
2905                         AliKFParticle* posPiKF=NULL;
2906                         AliKFParticle* negPiKF=NULL;
2907                         Int_t piPlusMotherLabel=-1;
2908                         Int_t piMinusMotherLabel=-1;
2909                         
2910                         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
2911                                 AliESDtrack* posTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
2912                                 if (posTrack->GetSign()<0) continue;
2913                                 if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(posTrack,AliPID::kPion))>2.) continue;
2914                                 if (posPiKF) delete posPiKF; posPiKF=NULL;
2915                                 posPiKF = new AliKFParticle( *(posTrack) ,211);
2916                                 AliKFParticle rhoPlusCandidate(*posPiKF,*rhoCandidateGammaDaughter);
2917                                 Double_t massRhoPlusCandidate = 0.;
2918                                 Double_t widthRhoPlusCandidate = 0.;
2919
2920                                 rhoPlusCandidate.GetMass(massRhoPlusCandidate,widthRhoPlusCandidate);
2921                                 fHistograms->FillHistogram("ESD_RhoPlus_InvMass_vs_Pt",massRhoPlusCandidate ,rhoPlusCandidate.GetPt());
2922                                 fHistograms->FillHistogram("ESD_RhoPlus_InvMass",massRhoPlusCandidate);
2923
2924
2925                                 if(fDoMCTruth){
2926                                         TParticle * positiveMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[iCh])->GetLabel()));
2927                                         if(positiveMCParticle->GetMother(0)>-1){
2928                                                 piPlusMotherLabel = positiveMCParticle->GetMother(0);
2929                                                 if(piPlusMotherLabel == gamma1MotherLabel){
2930                                                         //Int_t geantCode=fStack->Particle(TMath::Abs(pionMotherLabel))->GetPdgCode();
2931               //cout<<"RhoPlus::" << geantCode<< endl;
2932                                                         fHistograms->FillHistogram("ESD_TrueRhoPlus_InvMass_vs_Pt",massRhoPlusCandidate ,rhoPlusCandidate.GetPt());
2933                                                 }
2934                                         }
2935                                 }
2936                                 for(Int_t jCh=0;jCh<fChargedParticles->GetEntriesFast();jCh++){
2937                                         AliESDtrack* negTrack = (AliESDtrack*)(fChargedParticles->At(jCh));
2938                                         if (negTrack->GetSign()>0) continue;
2939                                         if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(negTrack,AliPID::kPion))>2.) continue;
2940                                         if (negPiKF) delete negPiKF; negPiKF=NULL;
2941                                         negPiKF = new AliKFParticle( *(negTrack) ,-211);
2942                                         AliKFParticle rho0Candidate(*posPiKF,*negPiKF,*rhoCandidateGammaDaughter);
2943                                         Double_t massRho0Candidate = 0.;
2944                                         Double_t widthRho0Candidate = 0.;
2945                                         
2946                                         rho0Candidate.GetMass(massRho0Candidate,widthRho0Candidate);
2947                                         fHistograms->FillHistogram("ESD_Rho0_InvMass_vs_Pt",massRho0Candidate ,rho0Candidate.GetPt());
2948                                         fHistograms->FillHistogram("ESD_Rho0_InvMass",massRho0Candidate);
2949
2950                                         if(fDoMCTruth){
2951                                                 TParticle * negativeMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[jCh])->GetLabel()));
2952                                                 if(negativeMCParticle->GetMother(0)>-1){
2953                                                         piMinusMotherLabel = negativeMCParticle->GetMother(0);
2954                                                         if(     piMinusMotherLabel ==   piPlusMotherLabel && piMinusMotherLabel==gamma1MotherLabel ){
2955                                                                 Int_t geantCode=fStack->Particle(TMath::Abs(piPlusMotherLabel))->GetPdgCode();
2956                                                                 if(geantCode == 221 || geantCode == 113){
2957                                                                         fHistograms->FillHistogram("ESD_TrueRho0_InvMass_vs_Pt",massRho0Candidate ,rho0Candidate.GetPt());
2958                                                                 }
2959                                                         }                               
2960                                                 }
2961                                         }
2962                                 }
2963
2964                         }
2965
2966                         if (posPiKF) delete posPiKF; posPiKF=NULL;               if (negPiKF) delete negPiKF; negPiKF=NULL;
2967
2968
2969                         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
2970                                 AliESDtrack* negTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
2971                                 if (negTrack->GetSign()>0) continue;
2972                                 if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(negTrack,AliPID::kPion))>2.) continue;
2973                                 if (negPiKF) delete negPiKF; negPiKF=NULL;
2974                                 negPiKF = new AliKFParticle( *(negTrack) ,-211);
2975                                 AliKFParticle rhoMinusCandidate(*negPiKF,*rhoCandidateGammaDaughter);
2976                                 Double_t massRhoMinusCandidate = 0.;
2977                                 Double_t widthRhoMinusCandidate = 0.;
2978
2979                                 rhoMinusCandidate.GetMass(massRhoMinusCandidate,widthRhoMinusCandidate);
2980                                 fHistograms->FillHistogram("ESD_RhoMinus_InvMass_vs_Pt",massRhoMinusCandidate ,rhoMinusCandidate.GetPt());
2981                                 fHistograms->FillHistogram("ESD_RhoMinus_InvMass",massRhoMinusCandidate);
2982
2983                                 if(fDoMCTruth){
2984                                         TParticle * negativeMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[iCh])->GetLabel()));
2985                                         Int_t pionMotherLabel=-1;
2986
2987                                         if(negativeMCParticle->GetMother(0)>-1){
2988                                                 pionMotherLabel = negativeMCParticle->GetMother(0);
2989                                                 if(pionMotherLabel == gamma1MotherLabel){
2990                                                         //Int_t geantCode=fStack->Particle(TMath::Abs(pionMotherLabel))->GetPdgCode();
2991               //cout<<"RhoMinus::" << geantCode<< endl;
2992                                                         fHistograms->FillHistogram("ESD_TrueRhoMinus_InvMass_vs_Pt",massRhoMinusCandidate ,rhoMinusCandidate.GetPt());
2993                                                 }
2994                                         }
2995                                 }
2996                         }
2997                         if (posPiKF) delete posPiKF; posPiKF=NULL;               if (negPiKF) delete negPiKF; negPiKF=NULL;
2998
2999                         AliKFParticle* posProtKF=NULL;
3000
3001                         
3002                         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
3003                                 AliESDtrack* posTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
3004                                 if (posTrack->GetSign()<0) continue;
3005                                 if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(posTrack,AliPID::kProton))>2.) continue;
3006                                 if (posProtKF) delete posProtKF; posProtKF=NULL;
3007                                 posProtKF = new AliKFParticle( *(posTrack) ,2212);
3008                                 AliKFParticle deltaPlusCandidate(*posProtKF,*rhoCandidateGammaDaughter);
3009                                 Double_t massDeltaPlusCandidate = 0.;
3010                                 Double_t widthDeltaPlusCandidate = 0.;
3011
3012                                 deltaPlusCandidate.GetMass(massDeltaPlusCandidate,widthDeltaPlusCandidate);
3013                                 fHistograms->FillHistogram("ESD_DeltaPlus_InvMass_vs_Pt",massDeltaPlusCandidate ,deltaPlusCandidate.GetPt());
3014                                 fHistograms->FillHistogram("ESD_DeltaPlus_InvMass",massDeltaPlusCandidate);
3015
3016                                 if(fDoMCTruth){
3017                                         TParticle * positiveMCParticle = fStack->Particle(TMath::Abs(fESDEvent->GetTrack(fChargedParticlesId[iCh])->GetLabel()));
3018                                         Int_t protonMotherLabel=-1;
3019
3020                                         if(positiveMCParticle->GetMother(0)>-1){
3021                                                 protonMotherLabel = positiveMCParticle->GetMother(0);
3022                                                 if(protonMotherLabel == gamma1MotherLabel){
3023                                                         //Int_t geantCode=fStack->Particle(TMath::Abs(pionMotherLabel))->GetPdgCode();
3024               //cout<<"RhoPlus::" << geantCode<< endl;
3025                                                         fHistograms->FillHistogram("ESD_TrueDeltaPlus_InvMass_vs_Pt",massDeltaPlusCandidate ,deltaPlusCandidate.GetPt());
3026                                                 }
3027                                         }
3028                                 }
3029
3030                         }
3031                         if (posPiKF) delete posPiKF; posPiKF=NULL;               if (negPiKF) delete negPiKF; negPiKF=NULL; if (posProtKF) delete posProtKF; posProtKF=NULL;
3032                 }
3033         }
3034                 
3035         if(fCalculateBackground){
3036
3037                 AliGammaConversionBGHandler * bgHandler = fV0Reader->GetBGHandler();
3038                 
3039                 Int_t zbin= bgHandler->GetZBinIndex(fV0Reader->GetVertexZ());
3040                 Int_t mbin = 0;
3041                 if(fUseTrackMultiplicityForBG == kTRUE){
3042                         mbin = bgHandler->GetMultiplicityBinIndex(fV0Reader->CountESDTracks());
3043                 } else {
3044                         mbin = bgHandler->GetMultiplicityBinIndex(fV0Reader->GetNGoodV0s());
3045                 }
3046                 
3047                 AliGammaConversionBGHandler::GammaConversionVertex *bgEventVertex = NULL;
3048
3049                 // Background calculation for the omega
3050                 for(Int_t nEventsInBG=0;nEventsInBG <fV0Reader->GetNBGEvents();nEventsInBG++){
3051                         AliGammaConversionKFVector * previousEventV0s = bgHandler->GetBGGoodV0s(zbin,mbin,nEventsInBG);
3052                         
3053                         if(fMoveParticleAccordingToVertex == kTRUE){
3054                                 bgEventVertex = bgHandler->GetBGEventVertex(zbin,mbin,nEventsInBG);
3055                         }
3056                         for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
3057                                 AliKFParticle previousGoodV0 = (AliKFParticle)(*(previousEventV0s->at(iPrevious)));
3058
3059                                 if(fMoveParticleAccordingToVertex == kTRUE){
3060                                         MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
3061                                 }
3062
3063                                 for(Int_t firstPi0Index=0;firstPi0Index<fKFReconstructedPi0sTClone->GetEntriesFast();firstPi0Index++){
3064                                         AliKFParticle * omegaCandidatePi0Daughter = (AliKFParticle *)fKFReconstructedPi0sTClone->At(firstPi0Index);
3065                                         AliKFParticle * omegaBckCandidate = new AliKFParticle(*omegaCandidatePi0Daughter,previousGoodV0);
3066                                         Double_t massOmegaBckCandidate = 0.;
3067                                         Double_t widthOmegaBckCandidate = 0.;
3068                                         
3069                                         omegaBckCandidate->GetMass(massOmegaBckCandidate,widthOmegaBckCandidate);
3070
3071
3072                                         fHistograms->FillHistogram("ESD_Omega_Bck_InvMass_vs_Pt",massOmegaBckCandidate ,omegaBckCandidate->GetPt());
3073                                         fHistograms->FillHistogram("ESD_Omega_Bck_InvMass",massOmegaBckCandidate);
3074
3075                                         delete omegaBckCandidate; 
3076                                 }
3077
3078                                 // Bck for gamma pi+ pi-
3079
3080                                 AliKFParticle* posPiKF=NULL;
3081                                 AliKFParticle* negPiKF=NULL;
3082                         
3083                                 for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
3084                                         AliESDtrack* posTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
3085                                         if (posTrack->GetSign()<0) continue;
3086                                         if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(posTrack,AliPID::kPion))>2.) continue;
3087                                         if (posPiKF) delete posPiKF; posPiKF=NULL;
3088                                         posPiKF = new AliKFParticle( *(posTrack) ,211);
3089
3090                                         for(Int_t jCh=0;jCh<fChargedParticles->GetEntriesFast();jCh++){
3091                                                 AliESDtrack* negTrack = (AliESDtrack*)(fChargedParticles->At(jCh));
3092                                                 if (negTrack->GetSign()>0) continue;
3093                                                 if(TMath::Abs(fV0Reader->GetESDpid()->NumberOfSigmasTPC(negTrack,AliPID::kPion))>2.) continue;
3094                                                 if (negPiKF) delete negPiKF; negPiKF=NULL;
3095                                                 negPiKF = new AliKFParticle( *(negTrack) ,-211);
3096                                                 AliKFParticle rho0BckCandidate(*posPiKF,*negPiKF,previousGoodV0);
3097                                                 Double_t massRho0BckCandidate = 0.;
3098                                                 Double_t widthRho0BckCandidate = 0.;
3099                                                 
3100                                                 rho0BckCandidate.GetMass(massRho0BckCandidate,widthRho0BckCandidate);
3101                                                 fHistograms->FillHistogram("ESD_Rho0Bck_InvMass_vs_Pt",massRho0BckCandidate ,rho0BckCandidate.GetPt());
3102                                                 fHistograms->FillHistogram("ESD_Rho0Bck_InvMass",massRho0BckCandidate);
3103                                         }
3104                                         
3105                                 }
3106
3107                                 if (posPiKF) delete posPiKF; posPiKF=NULL;               if (negPiKF) delete negPiKF; negPiKF=NULL; 
3108
3109
3110                         }
3111                 }
3112         } // end of checking if background calculation is available
3113 }
3114
3115
3116 void AliAnalysisTaskGammaConversion::ProcessGammasForNeutralMesonAnalysis(){
3117         // see header file for documentation
3118         
3119         //      for(UInt_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammas.size();firstGammaIndex++){
3120         //              for(UInt_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fKFReconstructedGammas.size();secondGammaIndex++){
3121
3122         fESDEvent = fV0Reader->GetESDEvent();
3123
3124         if(fKFReconstructedGammasTClone->GetEntriesFast()>fV0Reader->GetNumberOfV0s()){
3125                 cout<<"Warning, number of entries in the tclone is bigger than number of v0s"<<endl;
3126         }
3127
3128         for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
3129                 for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();secondGammaIndex++){
3130                         
3131                         //                      AliKFParticle * twoGammaDecayCandidateDaughter0 = &fKFReconstructedGammas[firstGammaIndex];
3132                         //                      AliKFParticle * twoGammaDecayCandidateDaughter1 = &fKFReconstructedGammas[secondGammaIndex];
3133                         
3134                         AliKFConversionPhoton * twoGammaDecayCandidateDaughter0 = (AliKFConversionPhoton *)fKFReconstructedGammasTClone->At(firstGammaIndex);
3135                         AliKFConversionPhoton * twoGammaDecayCandidateDaughter1 = (AliKFConversionPhoton *)fKFReconstructedGammasTClone->At(secondGammaIndex);
3136
3137                            if(twoGammaDecayCandidateDaughter0->GetTrackLabelPositive()==twoGammaDecayCandidateDaughter1->GetTrackLabelPositive()||
3138                            twoGammaDecayCandidateDaughter0->GetTrackLabelPositive()==twoGammaDecayCandidateDaughter1->GetTrackLabelNegative()||
3139                            twoGammaDecayCandidateDaughter0->GetTrackLabelNegative()==twoGammaDecayCandidateDaughter1->GetTrackLabelPositive()||
3140                            twoGammaDecayCandidateDaughter0->GetTrackLabelNegative()==twoGammaDecayCandidateDaughter1->GetTrackLabelNegative())continue;
3141                         
3142                         AliKFConversionMother *twoGammaCandidate = new AliKFConversionMother(*twoGammaDecayCandidateDaughter0,*twoGammaDecayCandidateDaughter1);
3143                         twoGammaCandidate->SetGammaLabels(firstGammaIndex,secondGammaIndex);
3144
3145                         Double_t massTwoGammaCandidate = 0.;
3146                         Double_t widthTwoGammaCandidate = 0.;
3147                         Double_t chi2TwoGammaCandidate =10000.; 
3148                         twoGammaCandidate->GetMass(massTwoGammaCandidate,widthTwoGammaCandidate);
3149                         //                      if(twoGammaCandidate->GetNDF()>0){
3150                         //      chi2TwoGammaCandidate = twoGammaCandidate->GetChi2()/twoGammaCandidate->GetNDF();
3151                         chi2TwoGammaCandidate = twoGammaCandidate->GetChi2();
3152                                 
3153                         fHistograms->FillHistogram("ESD_Mother_Chi2",chi2TwoGammaCandidate);
3154                         if((chi2TwoGammaCandidate>0 && chi2TwoGammaCandidate<fV0Reader->GetChi2CutMeson()) || fApplyChi2Cut == kFALSE){
3155                                         
3156                                 TVector3 momentumVectorTwoGammaCandidate(twoGammaCandidate->GetPx(),twoGammaCandidate->GetPy(),twoGammaCandidate->GetPz());
3157                                 TVector3 spaceVectorTwoGammaCandidate(twoGammaCandidate->GetX(),twoGammaCandidate->GetY(),twoGammaCandidate->GetZ());
3158                                                                 
3159                                   Double_t openingAngleTwoGammaCandidate = twoGammaCandidate->GetOpeningAngle();
3160
3161                                 Double_t rapidity=twoGammaCandidate->GetRapidity();
3162                               
3163                                 if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut()){
3164                                         delete twoGammaCandidate;
3165                                         continue;        // rapidity cut
3166                                 }
3167
3168                                  Double_t alfa=twoGammaCandidate->GetAlpha();
3169
3170                                                                 
3171                                 if(openingAngleTwoGammaCandidate < fMinOpeningAngleGhostCut){
3172                                         delete twoGammaCandidate;
3173                                         continue;        // minimum opening angle to avoid using ghosttracks
3174                                 }
3175                         
3176                                 if(alfa>fV0Reader->GetAlphaMinCutMeson() && alfa<fV0Reader->GetAlphaCutMeson()){
3177                                         fHistograms->FillHistogram("ESD_Mother_GammaDaughter_OpeningAngle", openingAngleTwoGammaCandidate);
3178                                         fHistograms->FillHistogram("ESD_Mother_Energy", twoGammaCandidate->GetE());
3179                                         fHistograms->FillHistogram("ESD_Mother_Pt", momentumVectorTwoGammaCandidate.Pt());
3180                                         fHistograms->FillHistogram("ESD_Mother_Eta", momentumVectorTwoGammaCandidate.Eta());
3181                                         fHistograms->FillHistogram("ESD_Mother_Rapid", rapidity);                                       
3182                                         fHistograms->FillHistogram("ESD_Mother_Phi", spaceVectorTwoGammaCandidate.Phi());
3183                                         fHistograms->FillHistogram("ESD_Mother_Mass", massTwoGammaCandidate);
3184                                         fHistograms->FillHistogram("ESD_Mother_alfa", alfa);
3185                                         if( (massTwoGammaCandidate > 0.1) && (massTwoGammaCandidate < 0.15) ){
3186                                                 fHistograms->FillHistogram("ESD_Mother_alfa_Pi0", alfa);
3187                                                 fHistograms->FillHistogram("ESD_Mother_Pt_alpha_Pi0", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3188                                         }
3189                                         if( (massTwoGammaCandidate > 0.5) && (massTwoGammaCandidate < 0.57) ){
3190                                                 fHistograms->FillHistogram("ESD_Mother_alfa_Eta", alfa);
3191                                                 fHistograms->FillHistogram("ESD_Mother_Pt_alpha_Eta", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3192                                         }
3193
3194                                         fHistograms->FillHistogram("ESD_Mother_R", spaceVectorTwoGammaCandidate.Pt());          // Pt in Space == R!!!
3195                                         fHistograms->FillHistogram("ESD_Mother_ZR", twoGammaCandidate->GetZ(), spaceVectorTwoGammaCandidate.Pt());
3196                                         fHistograms->FillHistogram("ESD_Mother_XY", twoGammaCandidate->GetX(), twoGammaCandidate->GetY());
3197                                         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3198                                         fHistograms->FillHistogram("ESD_Mother_InvMass",massTwoGammaCandidate);                 
3199                                         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt_alpha",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3200                                 }
3201                                 if(alfa<0.1){
3202                                         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_E_alpha",massTwoGammaCandidate ,twoGammaCandidate->GetE());
3203                                 }
3204
3205                                 if(fCalculateBackground){
3206                                         /* Kenneth, just for testing*/
3207                                         AliGammaConversionBGHandler * bgHandlerTest = fV0Reader->GetBGHandler();
3208                                                 
3209                                         Int_t zbin= bgHandlerTest->GetZBinIndex(fV0Reader->GetVertexZ());
3210                                         Int_t mbin=0;
3211                                         Int_t multKAA=0;
3212                                         if(fUseTrackMultiplicityForBG == kTRUE){
3213                                                 multKAA=fV0Reader->CountESDTracks();
3214                                                 mbin = bgHandlerTest->GetMultiplicityBinIndex(fV0Reader->CountESDTracks());
3215                                         }
3216                                         else{// means we use #v0s for multiplicity
3217                                                 multKAA=fV0Reader->GetNGoodV0s();
3218                                                 mbin = bgHandlerTest->GetMultiplicityBinIndex(fV0Reader->GetNGoodV0s());
3219                                         }
3220                                         //                      cout<<"Filling bin number "<<zbin<<" and "<<mbin<<endl;
3221                                         //                      cout<<"Corresponding to z = "<<fV0Reader->GetVertexZ()<<" and m = "<<multKAA<<endl;
3222                                         if(alfa>fV0Reader->GetAlphaMinCutMeson() && alfa<fV0Reader->GetAlphaCutMeson()){
3223                                                 fHistograms->FillHistogram(Form("%d%dESD_Mother_InvMass",zbin,mbin),massTwoGammaCandidate);
3224                                                 fHistograms->FillHistogram(Form("%d%dESD_Mother_InvMass_vs_Pt",zbin,mbin),massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3225                                                 /* end Kenneth, just for testing*/
3226                                                 fHistograms->FillHistogram(Form("%dESD_Mother_InvMass_vs_Pt",mbin),massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3227                                         }
3228                                 }
3229                                 /*              if(fCalculateBackground){
3230                                                 AliGammaConversionBGHandler * bgHandler = fV0Reader->GetBGHandler();
3231                                                 Int_t mbin= bgHandler->GetMultiplicityBinIndex(fV0Reader->CountESDTracks());
3232                                                 fHistograms->FillHistogram(Form("%dESD_Mother_InvMass_vs_Pt",mbin),massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3233                                                 }*/
3234                                 //              if(fDoNeutralMesonV0MCCheck){
3235                                 if(fDoMCTruth){
3236                                         //Kenneth: Checking the eta of the gamma to check the difference between 0.9 and 1.2
3237                                         Int_t indexKF1 = twoGammaDecayCandidateDaughter0->GetV0Index();
3238                                         if(indexKF1<fV0Reader->GetNumberOfV0s()){
3239                                                 fV0Reader->GetV0(indexKF1);//updates to the correct v0
3240                                                 Double_t eta1 = fV0Reader->GetMotherCandidateEta();
3241                                                 Bool_t isRealPi0=kFALSE;
3242                                                 Bool_t isRealEta=kFALSE;
3243                                                 Int_t gamma1MotherLabel=-1;
3244                                                 if(fV0Reader->HasSameMCMother() == kTRUE){
3245                                                         //cout<<"This v0 is a real v0!!!!"<<endl;
3246                                                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
3247                                                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
3248                                                         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){
3249                                                                 if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){
3250                                                                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
3251                                                                                 gamma1MotherLabel=fV0Reader->GetMotherMCParticle()->GetFirstMother();
3252                                                                         }
3253                                                                 }
3254                                                                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() ==111){
3255                                                                         gamma1MotherLabel=-111;
3256                                                                 }
3257                                                                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() ==221){
3258                                                                         gamma1MotherLabel=-221;
3259                                                                 }
3260                                                         }
3261                                                 }
3262                                                 Int_t indexKF2 = twoGammaDecayCandidateDaughter1->GetV0Index();
3263                                                 if(indexKF1 == indexKF2){
3264                                                         cout<<"index of the two KF particles are the same.... should not happen"<<endl;
3265                                                 }
3266                                                 if(indexKF2<fV0Reader->GetNumberOfV0s()){
3267                                                         fV0Reader->GetV0(indexKF2);
3268                                                         Double_t eta2 = fV0Reader->GetMotherCandidateEta();
3269                                                         Int_t gamma2MotherLabel=-1;
3270                                                         if(fV0Reader->HasSameMCMother() == kTRUE){
3271                                                         TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
3272                                                         TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
3273                                                         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){
3274                                                                 if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){
3275                                                                         if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
3276                                                                                 gamma2MotherLabel=fV0Reader->GetMotherMCParticle()->GetFirstMother();
3277                                                                         }
3278                                                                 }
3279                                                                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() ==111){
3280                                                                         gamma2MotherLabel=-111;
3281                                                                 }
3282                                                                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() ==221){
3283                                                                         gamma2MotherLabel=-221;
3284                                                                 }
3285                                                                         
3286                                                                 }
3287                                                         }
3288                                                         if(gamma1MotherLabel>=0 && gamma1MotherLabel==gamma2MotherLabel){
3289                                                                 if(fV0Reader->CheckIfPi0IsMother(gamma1MotherLabel)){
3290                                                                         isRealPi0=kTRUE;
3291                                                                 }
3292                                                                 if(fV0Reader->CheckIfEtaIsMother(gamma1MotherLabel)){
3293                                                                         isRealEta=kTRUE;
3294                                                                 }
3295                                                         }
3296
3297                                                         //cout << "alpha   " << alfa << endl;
3298                                                         if(isRealPi0)fHistograms->FillHistogram("ESD_TruePi0_alpha",alfa);
3299                                                         if(isRealEta)fHistograms->FillHistogram("ESD_TrueEta_alpha",alfa);
3300
3301                                                         if(alfa>fV0Reader->GetAlphaMinCutMeson() && alfa<fV0Reader->GetAlphaCutMeson()){
3302                                                                 if(TMath::Abs(eta1)>0.9 && TMath::Abs(eta2)>0.9){
3303                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_1212",massTwoGammaCandidate);
3304                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt1212",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3305                                                                         if(isRealPi0 || isRealEta){
3306                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_1212",massTwoGammaCandidate);
3307                                                                                 fHistograms->FillHistogram("ESD_TruePi0_OpeningAngle_1212",openingAngleTwoGammaCandidate);
3308                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt1212",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3309                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3310                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass",massTwoGammaCandidate);
3311                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt_alpha",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3312                                                                                 if( (isRealPi0) && (massTwoGammaCandidate > 0.1) && (massTwoGammaCandidate < 0.15) )
3313                                                                                         fHistograms->FillHistogram("ESD_TruePi0_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3314                                                                                 if( (isRealEta) && (massTwoGammaCandidate > 0.5) && (massTwoGammaCandidate < 0.57) )
3315                                                                                         fHistograms->FillHistogram("ESD_TrueEta_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3316
3317                                                                         }
3318
3319                                                                         if(!isRealPi0 && !isRealEta){
3320                                                                                 if(gamma1MotherLabel>-1 && gamma2MotherLabel>-1){
3321                                                                                         fHistograms->FillHistogram("ESD_TrueBckGG_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3322                                                                                 } else {
3323                                                                                         fHistograms->FillHistogram("ESD_TrueBckCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3324                                                                                 }
3325                                                                                 if(gamma1MotherLabel==-111 || gamma2MotherLabel==-111 || gamma1MotherLabel==-221 || gamma2MotherLabel==-221){
3326                                                                                         fHistograms->FillHistogram("ESD_TruePi0DalitzCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3327                                                                                 }
3328                                                                         }
3329                                                                 } else if(TMath::Abs(eta1)>0.9 || TMath::Abs(eta2)>0.9){
3330                                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_0912",massTwoGammaCandidate);
3331                                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt0912",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3332                                                                         
3333                                                                         if(isRealPi0 || isRealEta){
3334                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_0912",massTwoGammaCandidate);
3335                                                                                 fHistograms->FillHistogram("ESD_TruePi0_OpeningAngle_0912",openingAngleTwoGammaCandidate);
3336                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt0912",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3337                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3338                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass",massTwoGammaCandidate);
3339                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt_alpha",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3340                                                                                 if( (isRealPi0) && (massTwoGammaCandidate > 0.1) && (massTwoGammaCandidate < 0.15) )
3341                                                                                         fHistograms->FillHistogram("ESD_TruePi0_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3342                                                                                 if( (isRealEta) && (massTwoGammaCandidate > 0.5) && (massTwoGammaCandidate < 0.57) )
3343                                                                                         fHistograms->FillHistogram("ESD_TrueEta_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3344                                                                         }
3345                                                                         if(!isRealPi0 && !isRealEta){
3346                                                                                 if(gamma1MotherLabel>-1 && gamma2MotherLabel>-1){
3347                                                                                         fHistograms->FillHistogram("ESD_TrueBckGG_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3348                                                                                 }else{
3349                                                                                         fHistograms->FillHistogram("ESD_TrueBckCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3350                                                                                 }
3351                                                                                 if(gamma1MotherLabel==-111 || gamma2MotherLabel==-111 || gamma1MotherLabel==-221 || gamma2MotherLabel==-221){
3352                                                                                         fHistograms->FillHistogram("ESD_TruePi0DalitzCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3353                                                                                 }
3354                                                                         }
3355                                                                 } else {
3356                                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_0909",massTwoGammaCandidate);
3357                                                                         //                      fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt0909",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3358                                                                         if(isRealPi0 || isRealEta){
3359                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_0909",massTwoGammaCandidate);
3360                                                                                 fHistograms->FillHistogram("ESD_TruePi0_OpeningAngle_0909",openingAngleTwoGammaCandidate);
3361                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt0909",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3362                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3363                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass",massTwoGammaCandidate);
3364                                                                                 fHistograms->FillHistogram("ESD_TruePi0_InvMass_vs_Pt_alpha",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3365                                                                                 if( (isRealPi0) && (massTwoGammaCandidate > 0.1) && (massTwoGammaCandidate < 0.15) )
3366                                                                                         fHistograms->FillHistogram("ESD_TruePi0_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3367                                                                                 if( (isRealEta) && (massTwoGammaCandidate > 0.5) && (massTwoGammaCandidate < 0.57) )
3368                                                                                         fHistograms->FillHistogram("ESD_TrueEta_Pt_alpha", momentumVectorTwoGammaCandidate.Pt(), alfa); //RR_alpha
3369                                                                                 if(gamma1MotherLabel > fV0Reader->GetMCStack()->GetNprimary()){
3370                                                                                         fHistograms->FillHistogram("ESD_TruePi0Sec_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3371                                                                                         TParticle * secPi0MC = (TParticle*)fStack->Particle(fV0Reader->GetMotherMCParticle()->GetFirstMother());
3372                                                                                         if (secPi0MC->GetMother(0) >-1){
3373                                                                                                 if(fStack->Particle(secPi0MC->GetMother(0))->GetPdgCode()==kK0Short){
3374                                                                                                         fHistograms->FillHistogram("ESD_TruePi0SecFromK0S_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3375                                                                                                         if(massTwoGammaCandidate>0.09 && massTwoGammaCandidate<0.145){
3376                                                                                                                 fHistograms->FillHistogram("ESD_K0SFromSecPi0_Pt",fStack->Particle(secPi0MC->GetMother(0))->Pt());
3377                                                                                                         }
3378                                                                                                 }
3379                                                                                         }
3380                                                                                 }
3381                                                                         }
3382                                                                         if(!isRealPi0 && !isRealEta){
3383                                                                                 if(gamma1MotherLabel>-1 && gamma2MotherLabel>-1){
3384                                                                                         fHistograms->FillHistogram("ESD_TrueBckGG_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3385                                                                                 }else{
3386                                                                                         fHistograms->FillHistogram("ESD_TrueBckCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3387                                                                                 }
3388                                                                                 if(gamma1MotherLabel==-111 || gamma2MotherLabel==-111 || gamma1MotherLabel==-221 || gamma2MotherLabel==-221 ){
3389                                                                                         fHistograms->FillHistogram("ESD_TruePi0DalitzCont_InvMass_vs_Pt",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3390                                                                                 }
3391                                                                         }
3392                                                                 }
3393                                                         }
3394                                                 }
3395                                         }
3396                                 }
3397                                 if(alfa>fV0Reader->GetAlphaMinCutMeson() && alfa<fV0Reader->GetAlphaCutMeson()){
3398                                         if ( TMath::Abs(twoGammaDecayCandidateDaughter0->GetEta())<0.9 &&       TMath::Abs(twoGammaDecayCandidateDaughter1->GetEta())<0.9 ){
3399                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt_Fiducial",massTwoGammaCandidate ,momentumVectorTwoGammaCandidate.Pt());
3400                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_Fiducial",massTwoGammaCandidate);
3401                                         }
3402                                                 
3403                                         if(TMath::Abs(twoGammaDecayCandidateDaughter0->GetEta())>0.9 && TMath::Abs(twoGammaDecayCandidateDaughter1->GetEta())>0.9){
3404                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_1212",massTwoGammaCandidate);
3405                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt1212",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3406                                         }
3407                                         else if(TMath::Abs(twoGammaDecayCandidateDaughter0->GetEta())>0.9 || TMath::Abs(twoGammaDecayCandidateDaughter1->GetEta())>0.9){
3408                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_0912",massTwoGammaCandidate);
3409                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt0912",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3410                                         }
3411                                         else{
3412                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_0909",massTwoGammaCandidate);
3413                                                 fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt0909",massTwoGammaCandidate,momentumVectorTwoGammaCandidate.Pt());
3414                                         }
3415
3416                                         Double_t lowMassPi0=0.1;
3417                                         Double_t highMassPi0=0.15;
3418                                         if ( ( massTwoGammaCandidate > lowMassPi0) && (massTwoGammaCandidate < highMassPi0) ){
3419                                                 new((*fKFReconstructedPi0sTClone)[fKFReconstructedPi0sTClone->GetEntriesFast()])        AliKFConversionMother(*twoGammaCandidate);
3420                                               }                         
3421                                                 
3422                                         if( fKFCreateAOD ) {
3423                                                 lowMassPi0=0.08;
3424                                                 highMassPi0=0.2;
3425                                                 Double_t lowMassEta=0.4;
3426                                                 Double_t highMassEta=0.7;
3427
3428                                                 if ( ( massTwoGammaCandidate > lowMassPi0) && (massTwoGammaCandidate < highMassPi0) ){
3429
3430                                                     TagDaughter(twoGammaCandidate->GetGammaLabel(0));
3431                                                     TagDaughter(twoGammaCandidate->GetGammaLabel(1));
3432                                                 //  AddPionToAOD(twoGammaCandidate);
3433                                                 } else  if ( ( massTwoGammaCandidate > lowMassEta) && (massTwoGammaCandidate < highMassEta) ){
3434                                                     TagDaughter(twoGammaCandidate->GetGammaLabel(0));
3435                                                     TagDaughter(twoGammaCandidate->GetGammaLabel(1));
3436                                                     // AddPionToAOD(twoGammaCandidate);
3437                                                 }
3438                                         } // if create aod
3439
3440                                 }
3441                         }
3442                         delete twoGammaCandidate;
3443                 }
3444         }
3445 }
3446
3447 ///__________________________________________________________________________________
3448 void AliAnalysisTaskGammaConversion::AddGammaToAOD(AliKFConversionPhoton * kfParticle) {
3449
3450     //Fill AOD with particles
3451     TClonesArray *branch=fAODGamma;
3452     if(branch){
3453                 new((*branch)[branch->GetEntriesFast()])  AliAODConversionPhoton(kfParticle);
3454                 static_cast<AliAODConversionPhoton*>(branch->Last())->SetMass(kfParticle->M());
3455     }
3456     else {
3457                 return;
3458     }
3459 }
3460
3461 /*///__________________________________________________________________________________
3462 void AliAnalysisTaskGammaConversion::AddPionToAOD(AliKFConversionMother * kfParticle) {
3463
3464     //Add pions to AOD
3465     TClonesArray *branch=fAODPi0;
3466
3467     if(branch){
3468         new((*branch)[branch->GetEntriesFast()])  AliAODConversionMother(kfParticle);
3469     }
3470
3471     TagDaughter(kfParticle->GetGammaLabel(0));
3472     TagDaughter(kfParticle->GetGammaLabel(1));
3473 }
3474
3475 ///__________________________________________________________________________________
3476 void AliAnalysisTaskGammaConversion::AddOmegaToAOD(AliKFParticle * kfParticle, Int_t daughter1, Int_t daughter2) {
3477
3478     //Add omegas to AOD
3479
3480     TClonesArray *branch=fAODOmega;
3481     // Get Daughters
3482    // AliAODConversionPhoton * fdaughter1 = dynamic_cast<AliAODConversionPhoton*>(fAODGamma->At(daughter1));
3483    // AliAODConversionPhoton * fdaughter2 = dynamic_cast<AliAODConversionPhoton*>(fAODGamma->At(daughter2));
3484
3485     if(branch){
3486      //   new((*branch)[branch->GetEntriesFast()])  AliAODConversionMother(kfParticle);
3487                 }
3488
3489         TagDaughter(daughter1);
3490         TagDaughter(daughter2);
3491
3492
3493 }
3494 */
3495 ///__________________________________________________________________________________
3496 void AliAnalysisTaskGammaConversion::TagDaughter(Int_t gammaIndex) {
3497         //Set conversion tag on pion daughters
3498         AliAODConversionPhoton * daughter = dynamic_cast<AliAODConversionPhoton*>(fAODGamma->At(gammaIndex));
3499         if(daughter) {
3500                 daughter->SetTag(kTRUE);
3501         } else {
3502                 AliError("Daughter not in gamma tree!!");
3503         }
3504 }
3505
3506 ///___________________________________________________________________________________
3507 void AliAnalysisTaskGammaConversion::FillAODWithConversionGammas(){
3508         // Fill AOD with reconstructed Gamma
3509         for(Int_t gammaIndex=0;gammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();gammaIndex++){
3510                 AliKFConversionPhoton * gammakf = dynamic_cast<AliKFConversionPhoton*>(fKFReconstructedGammasTClone->At(gammaIndex));
3511                 if(gammakf) {
3512                       AddGammaToAOD(gammakf);
3513                 }
3514         }
3515 }
3516
3517 /*
3518         void AliAnalysisTaskGammaConversion::ProcessConvPHOSGammasForNeutralMesonAnalysis(){
3519
3520         // see header file for documentation
3521         // Analyse Pi0 with one photon from Phos and 1 photon from conversions
3522         
3523
3524
3525         Double_t vtx[3];
3526         vtx[0] = fV0Reader->GetPrimaryVertex()->GetX();
3527         vtx[1] = fV0Reader->GetPrimaryVertex()->GetY();
3528         vtx[2] = fV0Reader->GetPrimaryVertex()->GetZ();
3529
3530
3531         // Loop over all CaloClusters and consider only the PHOS ones:
3532         AliESDCaloCluster *clu;
3533         TLorentzVector pPHOS;
3534         TLorentzVector gammaPHOS;
3535         TLorentzVector gammaGammaConv;
3536         TLorentzVector pi0GammaConvPHOS;
3537         TLorentzVector gammaGammaConvBck;
3538         TLorentzVector pi0GammaConvPHOSBck;
3539
3540
3541         for (Int_t i=0; i<fV0Reader->GetESDEvent()->GetNumberOfCaloClusters(); i++) {
3542         clu = fV0Reader->GetESDEvent()->GetCaloCluster(i);
3543         if ( !clu->IsPHOS() || clu->E()<0.1 ) continue;
3544         clu ->GetMomentum(pPHOS ,vtx);
3545         for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
3546         AliKFParticle * twoGammaDecayCandidateDaughter0 = (AliKFParticle *)fKFReconstructedGammasTClone->At(firstGammaIndex);
3547         gammaGammaConv.SetXYZM(twoGammaDecayCandidateDaughter0->Px(),twoGammaDecayCandidateDaughter0->Py(),twoGammaDecayCandidateDaughter0->Pz(),0.);
3548         gammaPHOS.SetXYZM(pPHOS.Px(),pPHOS.Py(),pPHOS.Pz(),0.);
3549         pi0GammaConvPHOS=gammaGammaConv+gammaPHOS;
3550         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvPHOS",pi0GammaConvPHOS.M());
3551         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt_GammaConvPHOS",pi0GammaConvPHOS.M(),pi0GammaConvPHOS.Pt());
3552
3553         TVector3 v3D0(twoGammaDecayCandidateDaughter0->Px(),twoGammaDecayCandidateDaughter0->Py(),twoGammaDecayCandidateDaughter0->Pz());
3554         TVector3 v3D1(gammaPHOS.Px(),gammaPHOS.Py(),gammaPHOS.Pz());
3555         Double_t opanConvPHOS= v3D0.Angle(v3D1);
3556         if ( opanConvPHOS < 0.35){
3557         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvPHOS_OpanLow",pi0GammaConvPHOS.M());
3558         }else{
3559         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvPHOS_OpanHigh",pi0GammaConvPHOS.M());
3560         }
3561
3562         }
3563
3564         //      Now the LorentVector pPHOS is obtained and can be paired with the converted proton
3565         }
3566         //==== End of the PHOS cluster selection ============
3567         TLorentzVector pEMCAL;
3568         TLorentzVector gammaEMCAL;
3569         TLorentzVector pi0GammaConvEMCAL;
3570         TLorentzVector pi0GammaConvEMCALBck;
3571
3572         for (Int_t i=0; i<fV0Reader->GetESDEvent()->GetNumberOfCaloClusters(); i++) {
3573         clu = fV0Reader->GetESDEvent()->GetCaloCluster(i);
3574         if ( !clu->IsEMCAL()    || clu->E()<0.1 ) continue;
3575         if (clu->GetNCells() <= 1) continue;
3576         if ( clu->GetTOF()*1e9 < 550    || clu->GetTOF()*1e9 > 750) continue;
3577
3578         clu ->GetMomentum(pEMCAL ,vtx);
3579         for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
3580         AliKFParticle * twoGammaDecayCandidateDaughter0 = (AliKFParticle *)fKFReconstructedGammasTClone->At(firstGammaIndex);
3581         gammaGammaConv.SetXYZM(twoGammaDecayCandidateDaughter0->Px(),
3582         twoGammaDecayCandidateDaughter0->Py(),
3583         twoGammaDecayCandidateDaughter0->Pz(),0.);
3584         gammaEMCAL.SetXYZM(pEMCAL.Px(),pEMCAL.Py(),pEMCAL.Pz(),0.);
3585         pi0GammaConvEMCAL=gammaGammaConv+gammaEMCAL;
3586         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvEMCAL",pi0GammaConvEMCAL.M());
3587         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt_GammaConvEMCAL",pi0GammaConvEMCAL.M(),pi0GammaConvEMCAL.Pt());
3588         TVector3 v3D0(twoGammaDecayCandidateDaughter0->Px(),
3589         twoGammaDecayCandidateDaughter0->Py(),
3590         twoGammaDecayCandidateDaughter0->Pz());
3591         TVector3 v3D1(gammaEMCAL.Px(),gammaEMCAL.Py(),gammaEMCAL.Pz());
3592
3593
3594         Double_t opanConvEMCAL= v3D0.Angle(v3D1);
3595         if ( opanConvEMCAL < 0.35){
3596         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvEMCAL_OpanLow",pi0GammaConvEMCAL.M());
3597         }else{
3598         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvEMCAL_OpanHigh",pi0GammaConvEMCAL.M());
3599         }
3600
3601         }
3602         if(fCalculateBackground){
3603         for(Int_t nEventsInBG=0;nEventsInBG <fV0Reader->GetNBGEvents();nEventsInBG++){
3604         AliGammaConversionKFVector * previousEventV0s = fV0Reader->GetBGGoodV0s(nEventsInBG);
3605         for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
3606         AliKFParticle previousGoodV0 = (AliKFParticle)(*(previousEventV0s->at(iPrevious)));
3607         gammaGammaConvBck.SetXYZM(previousGoodV0.Px(),
3608         previousGoodV0.Py(),
3609         previousGoodV0.Pz(),0.);
3610         pi0GammaConvEMCALBck=gammaGammaConvBck+gammaEMCAL;
3611         fHistograms->FillHistogram("ESD_Mother_InvMass_GammaConvEMCAL_Bck",pi0GammaConvEMCALBck.M());
3612         fHistograms->FillHistogram("ESD_Mother_InvMass_vs_Pt_GammaConvEMCAL_Bck",pi0GammaConvEMCALBck.M(),
3613         pi0GammaConvEMCALBck.Pt());
3614         }
3615         }
3616                         
3617         //      Now the LorentVector pEMCAL is obtained and can be paired with the converted proton
3618         } // end of checking if background photons are available
3619         }
3620         //==== End of the PHOS cluster selection ============
3621
3622         }
3623 */
3624
3625 void AliAnalysisTaskGammaConversion::MoveParticleAccordingToVertex(AliKFParticle * particle,const AliGammaConversionBGHandler::GammaConversionVertex *vertex){
3626         //see header file for documentation
3627
3628         Double_t dx = vertex->fX - fESDEvent->GetPrimaryVertex()->GetX();
3629         Double_t dy = vertex->fY - fESDEvent->GetPrimaryVertex()->GetY();
3630         Double_t dz = vertex->fZ - fESDEvent->GetPrimaryVertex()->GetZ();
3631         
3632         //      cout<<"dx, dy, dz: ["<<dx<<","<<dy<<","<<dz<<"]"<<endl;
3633         particle->X() = particle->GetX() - dx;
3634         particle->Y() = particle->GetY() - dy;
3635         particle->Z() = particle->GetZ() - dz;
3636 }
3637
3638 void AliAnalysisTaskGammaConversion::RotateKFParticle(AliKFParticle * kfParticle,Double_t angle){
3639         // Before rotate needs to be moved to position 0,0,0, ; move back after rotation
3640         Double_t dx = fESDEvent->GetPrimaryVertex()->GetX()-0.;
3641         Double_t dy = fESDEvent->GetPrimaryVertex()->GetY()-0.;
3642         Double_t dz = fESDEvent->GetPrimaryVertex()->GetZ()-0.;
3643         
3644         kfParticle->X() = kfParticle->GetX() - dx;
3645         kfParticle->Y() = kfParticle->GetY() - dy;
3646         kfParticle->Z() = kfParticle->GetZ() - dz;
3647
3648
3649         // Rotate the kf particle
3650         Double_t c = cos(angle);
3651         Double_t s = sin(angle);
3652         
3653         Double_t mA[8][ 8];
3654         for( Int_t i=0; i<8; i++ ){
3655                 for( Int_t j=0; j<8; j++){
3656                         mA[i][j] = 0;
3657                 }
3658         }
3659         for( int i=0; i<8; i++ ){
3660                 mA[i][i] = 1;
3661         }
3662         mA[0][0] =      c;      mA[0][1] = s;
3663         mA[1][0] = -s;  mA[1][1] = c;
3664         mA[3][3] =      c;      mA[3][4] = s;
3665         mA[4][3] = -s;  mA[4][4] = c;
3666         
3667         Double_t mAC[8][8];
3668         Double_t mAp[8];
3669         for( Int_t i=0; i<8; i++ ){
3670                 mAp[i] = 0;
3671                 for( Int_t k=0; k<8; k++){
3672                         mAp[i]+=mA[i][k] * kfParticle->GetParameter(k);
3673                 }
3674         }
3675         
3676         for( Int_t i=0; i<8; i++){
3677                 kfParticle->Parameter(i) = mAp[i];
3678         }
3679
3680         for( Int_t i=0; i<8; i++ ){
3681                 for( Int_t j=0; j<8; j++ ){
3682                         mAC[i][j] = 0;
3683                         for( Int_t k=0; k<8; k++ ){
3684         mAC[i][j]+= mA[i][k] * kfParticle->GetCovariance(k,j);
3685                         }
3686                 }
3687         }
3688
3689         for( Int_t i=0; i<8; i++ ){
3690                 for( Int_t j=0; j<=i; j++ ){
3691                         Double_t xx = 0;
3692                         for( Int_t k=0; k<8; k++){
3693         xx+= mAC[i][k]*mA[j][k];
3694                         }
3695                         kfParticle->Covariance(i,j) = xx;
3696                 }
3697         }
3698
3699         Double_t dx1 = 0.-fESDEvent->GetPrimaryVertex()->GetX();
3700         Double_t dy1 = 0.-fESDEvent->GetPrimaryVertex()->GetY();
3701         Double_t dz1 = 0.-fESDEvent->GetPrimaryVertex()->GetZ();
3702         
3703         kfParticle->X() = kfParticle->GetX() - dx1;
3704         kfParticle->Y() = kfParticle->GetY() - dy1;
3705         kfParticle->Z() = kfParticle->GetZ() - dz1;
3706
3707 }
3708
3709
3710 void AliAnalysisTaskGammaConversion::CalculateBackground(){
3711         // see header file for documentation
3712
3713
3714         TClonesArray * currentEventV0s = fV0Reader->GetCurrentEventGoodV0s();
3715
3716         AliGammaConversionBGHandler * bgHandler = fV0Reader->GetBGHandler();
3717         
3718         Int_t zbin= bgHandler->GetZBinIndex(fV0Reader->GetVertexZ());
3719         Int_t mbin = 0;
3720         if(fUseTrackMultiplicityForBG == kTRUE){
3721                 mbin = bgHandler->GetMultiplicityBinIndex(fV0Reader->CountESDTracks());
3722         }
3723         else{
3724                 mbin = bgHandler->GetMultiplicityBinIndex(fV0Reader->GetNGoodV0s());
3725         }
3726
3727         if(fDoRotation == kTRUE){
3728
3729                 for(Int_t iCurrent=0;iCurrent<currentEventV0s->GetEntriesFast();iCurrent++){
3730                         AliKFParticle currentEventGoodV0 = *(AliKFParticle *)(currentEventV0s->At(iCurrent)); 
3731                         for(Int_t iCurrent2=iCurrent+1;iCurrent2<currentEventV0s->GetEntriesFast();iCurrent2++){
3732         for(Int_t nRandom=0;nRandom<fNRandomEventsForBG;nRandom++){
3733         
3734                 AliKFParticle currentEventGoodV02 = *(AliKFParticle *)(currentEventV0s->At(iCurrent2));
3735
3736                 if(fCheckBGProbability == kTRUE){
3737                         Double_t massBGprob =0.;
3738                         Double_t widthBGprob = 0.;
3739                         AliKFParticle *backgroundCandidateProb = new AliKFParticle(currentEventGoodV0,currentEventGoodV02);
3740                         backgroundCandidateProb->GetMass(massBGprob,widthBGprob);
3741                         if(massBGprob>0.1 && massBGprob<0.14){
3742                                 if(fRandom.Rndm()>bgHandler->GetBGProb(zbin,mbin)){
3743                 delete backgroundCandidateProb;
3744                 continue;
3745                                 }
3746                         }
3747                         delete backgroundCandidateProb;
3748                 }
3749         
3750                 Double_t nRadiansPM = fNDegreesPMBackground*TMath::Pi()/180;
3751
3752                 Double_t rotationValue = fRandom.Rndm()*2*nRadiansPM + TMath::Pi()-nRadiansPM;
3753                 
3754                 RotateKFParticle(&currentEventGoodV02,rotationValue);
3755
3756                 AliKFParticle *backgroundCandidate = new AliKFParticle(currentEventGoodV0,currentEventGoodV02);
3757
3758                 Double_t massBG =0.;
3759                 Double_t widthBG = 0.;
3760                 Double_t chi2BG =10000.;        
3761                 backgroundCandidate->GetMass(massBG,widthBG);
3762                 //              if(backgroundCandidate->GetNDF()>0){
3763                 chi2BG = backgroundCandidate->GetChi2();
3764                 if((chi2BG>0 && chi2BG<fV0Reader->GetChi2CutMeson())    || fApplyChi2Cut == kFALSE){
3765                 
3766                         TVector3 momentumVectorbackgroundCandidate(backgroundCandidate->GetPx(),backgroundCandidate->GetPy(),backgroundCandidate->GetPz());
3767                         TVector3 spaceVectorbackgroundCandidate(backgroundCandidate->GetX(),backgroundCandidate->GetY(),backgroundCandidate->GetZ());
3768                 
3769                         Double_t openingAngleBG = currentEventGoodV0.GetAngle(currentEventGoodV02);
3770                 
3771                         Double_t rapidity;
3772                         if(backgroundCandidate->GetE() - backgroundCandidate->GetPz() == 0 || backgroundCandidate->GetE() + backgroundCandidate->GetPz() == 0) {
3773                                 rapidity=8.;
3774                         } else{
3775                                 rapidity = 0.5*(TMath::Log((backgroundCandidate->GetE() +backgroundCandidate->GetPz()) / (backgroundCandidate->GetE()-backgroundCandidate->GetPz())));
3776                         }
3777                         if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ){
3778                                 delete backgroundCandidate;      
3779                                 continue;        // rapidity cut
3780                         }                       
3781                                         
3782                 
3783                         Double_t alfa=0.0;
3784                         if( (currentEventGoodV0.GetE()+currentEventGoodV02.GetE()) != 0){
3785                                 alfa=TMath::Abs((currentEventGoodV0.GetE()-currentEventGoodV02.GetE())
3786                                                 /(currentEventGoodV0.GetE()+currentEventGoodV02.GetE()));
3787                         }
3788                 
3789                 
3790                         if(openingAngleBG < fMinOpeningAngleGhostCut ){
3791                                 delete backgroundCandidate;      
3792                                 continue;        // minimum opening angle to avoid using ghosttracks
3793                         }                       
3794                 
3795                         // original
3796                         if(alfa>fV0Reader->GetAlphaMinCutMeson() &&      alfa<fV0Reader->GetAlphaCutMeson()){
3797                                 fHistograms->FillHistogram("ESD_Background_GammaDaughter_OpeningAngle", openingAngleBG);
3798                                 fHistograms->FillHistogram("ESD_Background_Energy", backgroundCandidate->GetE());
3799                                 fHistograms->FillHistogram("ESD_Background_Pt", momentumVectorbackgroundCandidate.Pt());
3800                                 fHistograms->FillHistogram("ESD_Background_Eta", momentumVectorbackgroundCandidate.Eta());
3801                                 fHistograms->FillHistogram("ESD_Background_Rapidity", rapidity);
3802                                 fHistograms->FillHistogram("ESD_Background_Phi", spaceVectorbackgroundCandidate.Phi());
3803                                 fHistograms->FillHistogram("ESD_Background_Mass", massBG);
3804                                 fHistograms->FillHistogram("ESD_Background_R", spaceVectorbackgroundCandidate.Pt());    // Pt in Space == R!!!!
3805                                 fHistograms->FillHistogram("ESD_Background_ZR", backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
3806                                 fHistograms->FillHistogram("ESD_Background_XY", backgroundCandidate->GetX(), backgroundCandidate->GetY());
3807                                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt",massBG,momentumVectorbackgroundCandidate.Pt());
3808                                 fHistograms->FillHistogram("ESD_Background_InvMass",massBG);
3809                                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_alpha",massBG,momentumVectorbackgroundCandidate.Pt());
3810
3811                                 if(massBG>0.1 && massBG<0.15){
3812                 fHistograms->FillHistogram("ESD_Background_alfa_Pi0", alfa);
3813                 fHistograms->FillHistogram("ESD_Background_Pt_alpha_Pi0", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
3814                                 }
3815                                 if(massBG>0.5 && massBG<0.57){
3816                 fHistograms->FillHistogram("ESD_Background_alfa_Eta", alfa);
3817                 fHistograms->FillHistogram("ESD_Background_Pt_alpha_Eta", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
3818                                 }
3819
3820                                 if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(currentEventGoodV02.GetEta())<0.9 ){
3821                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_Fiducial",massBG,momentumVectorbackgroundCandidate.Pt());
3822                 fHistograms->FillHistogram("ESD_Background_InvMass_Fiducial",massBG);
3823                                 }
3824                                 
3825                                 fHistograms->FillHistogram(Form("%d%dESD_Background_GammaDaughter_OpeningAngle",zbin,mbin), openingAngleBG);
3826                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Energy",zbin,mbin), backgroundCandidate->GetE());
3827                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Pt",zbin,mbin),     momentumVectorbackgroundCandidate.Pt());
3828                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Eta",zbin,mbin), momentumVectorbackgroundCandidate.Eta());
3829                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Rapidity",zbin,mbin), rapidity);
3830                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Phi",zbin,mbin), spaceVectorbackgroundCandidate.Phi());
3831                                 fHistograms->FillHistogram(Form("%d%dESD_Background_Mass",zbin,mbin), massBG);
3832                                 fHistograms->FillHistogram(Form("%d%dESD_Background_R",zbin,mbin), spaceVectorbackgroundCandidate.Pt());        // Pt in Space == R!!!!
3833                                 fHistograms->FillHistogram(Form("%d%dESD_Background_ZR",zbin,mbin), backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
3834                                 fHistograms->FillHistogram(Form("%d%dESD_Background_XY",zbin,mbin), backgroundCandidate->GetX(), backgroundCandidate->GetY());
3835                                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
3836                                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass",zbin,mbin),massBG);
3837                                 
3838                                 if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(currentEventGoodV02.GetEta())<0.9 ){
3839                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt_Fiducial",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
3840                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_Fiducial",zbin,mbin),massBG);
3841                                 }
3842                         }
3843                         if(alfa<0.1){
3844                                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_E_alpha",massBG ,backgroundCandidate->GetE());
3845                         }
3846
3847                 }
3848                 //}
3849                 delete backgroundCandidate;                     
3850         }
3851                         }
3852                 }
3853         }
3854         else{ // means no rotation
3855                 AliGammaConversionBGHandler::GammaConversionVertex *bgEventVertex = NULL;
3856                         
3857                 if(fUseTrackMultiplicityForBG){
3858                         //              cout<<"Using charged track multiplicity for background calculation"<<endl;
3859                         for(Int_t nEventsInBG=0;nEventsInBG <fV0Reader->GetNBGEvents();nEventsInBG++){
3860
3861         AliGammaConversionKFVector * previousEventV0s = bgHandler->GetBGGoodV0s(zbin,mbin,nEventsInBG);//fV0Reader->GetBGGoodV0s(nEventsInBG);
3862                         
3863         if(fMoveParticleAccordingToVertex == kTRUE){
3864                 bgEventVertex = bgHandler->GetBGEventVertex(zbin,mbin,nEventsInBG);
3865         }
3866
3867         for(Int_t iCurrent=0;iCurrent<currentEventV0s->GetEntriesFast();iCurrent++){
3868                 AliKFParticle currentEventGoodV0 = *(AliKFParticle *)(currentEventV0s->At(iCurrent)); 
3869                 for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
3870                         AliKFParticle previousGoodV0 = (AliKFParticle)(*(previousEventV0s->at(iPrevious)));
3871                         AliKFParticle previousGoodV0test = (AliKFParticle)(*(previousEventV0s->at(iPrevious)));
3872
3873                         //cout<<"Primary Vertex event: ["<<fESDEvent->GetPrimaryVertex()->GetX()<<","<<fESDEvent->GetPrimaryVertex()->GetY()<<","<<fESDEvent->GetPrimaryVertex()->GetZ()<<"]"<<endl;
3874                         //cout<<"BG prim Vertex event: ["<<bgEventVertex->fX<<","<<bgEventVertex->fY<<","<<bgEventVertex->fZ<<"]"<<endl;
3875                 
3876                         //cout<<"XYZ of particle before transport: ["<<previousGoodV0.X()<<","<<previousGoodV0.Y()<<","<<previousGoodV0.Z()<<"]"<<endl;
3877                         if(fMoveParticleAccordingToVertex == kTRUE){
3878                                 MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
3879                         }
3880                         //cout<<"XYZ of particle after transport: ["<<previousGoodV0.X()<<","<<previousGoodV0.Y()<<","<<previousGoodV0.Z()<<"]"<<endl;
3881
3882                         AliKFParticle *backgroundCandidate = new AliKFParticle(currentEventGoodV0,previousGoodV0);
3883         
3884                         Double_t massBG =0.;
3885                         Double_t widthBG = 0.;
3886                         Double_t chi2BG =10000.;        
3887                         backgroundCandidate->GetMass(massBG,widthBG);
3888
3889                         //      if(backgroundCandidate->GetNDF()>0){
3890                         //              chi2BG = backgroundCandidate->GetChi2()/backgroundCandidate->GetNDF();
3891                         chi2BG = backgroundCandidate->GetChi2();
3892                         if((chi2BG>0 && chi2BG<fV0Reader->GetChi2CutMeson()) || fApplyChi2Cut == kFALSE){
3893                                         
3894                                 TVector3 momentumVectorbackgroundCandidate(backgroundCandidate->GetPx(),backgroundCandidate->GetPy(),backgroundCandidate->GetPz());
3895                                 TVector3 spaceVectorbackgroundCandidate(backgroundCandidate->GetX(),backgroundCandidate->GetY(),backgroundCandidate->GetZ());
3896                                         
3897                                 Double_t openingAngleBG = currentEventGoodV0.GetAngle(previousGoodV0);
3898                                         
3899                                 Double_t rapidity;
3900                         
3901                                 if(backgroundCandidate->GetE() - backgroundCandidate->GetPz() <= 0 || backgroundCandidate->GetE() + backgroundCandidate->GetPz() <= 0){
3902                 cout << "Error: |Pz| > E !!!! " << endl;
3903                 rapidity=8.;
3904                                 } else {
3905                 rapidity = 0.5*(TMath::Log((backgroundCandidate->GetE() +backgroundCandidate->GetPz()) / (backgroundCandidate->GetE()-backgroundCandidate->GetPz())));
3906                                 }                               
3907                                 if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ){
3908                 delete backgroundCandidate;      
3909                 continue;        // rapidity cut
3910                                 }                       
3911                                                         
3912         
3913                                 Double_t alfa=0.0;
3914                                 if( (currentEventGoodV0.GetE()+previousGoodV0.GetE()) != 0){
3915                 alfa=TMath::Abs((currentEventGoodV0.GetE()-previousGoodV0.GetE())
3916                                 /(currentEventGoodV0.GetE()+previousGoodV0.GetE()));
3917                                 }
3918                         
3919                                         
3920                                 if(openingAngleBG < fMinOpeningAngleGhostCut ){
3921                 delete backgroundCandidate;      
3922                 continue;        // minimum opening angle to avoid using ghosttracks
3923                                 }                       
3924
3925                                 // original
3926                                 if(alfa>fV0Reader->GetAlphaMinCutMeson() &&      alfa<fV0Reader->GetAlphaCutMeson()){
3927                 fHistograms->FillHistogram("ESD_Background_GammaDaughter_OpeningAngle", openingAngleBG);
3928                 fHistograms->FillHistogram("ESD_Background_Energy", backgroundCandidate->GetE());
3929                 fHistograms->FillHistogram("ESD_Background_Pt", momentumVectorbackgroundCandidate.Pt());
3930                 fHistograms->FillHistogram("ESD_Background_Eta", momentumVectorbackgroundCandidate.Eta());
3931                 fHistograms->FillHistogram("ESD_Background_Rapidity", rapidity);
3932                 fHistograms->FillHistogram("ESD_Background_Phi", spaceVectorbackgroundCandidate.Phi());
3933                 fHistograms->FillHistogram("ESD_Background_Mass", massBG);
3934                 fHistograms->FillHistogram("ESD_Background_R", spaceVectorbackgroundCandidate.Pt());    // Pt in Space == R!!!!
3935                 fHistograms->FillHistogram("ESD_Background_ZR", backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
3936                 fHistograms->FillHistogram("ESD_Background_XY", backgroundCandidate->GetX(), backgroundCandidate->GetY());
3937                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt",massBG,momentumVectorbackgroundCandidate.Pt());
3938                 fHistograms->FillHistogram("ESD_Background_InvMass",massBG);
3939                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_alpha",massBG,momentumVectorbackgroundCandidate.Pt());
3940
3941                 if(massBG>0.1 && massBG<0.15){
3942                         fHistograms->FillHistogram("ESD_Background_alfa_Pi0", alfa);
3943                         fHistograms->FillHistogram("ESD_Background_Pt_alpha_Pi0", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
3944                 }
3945                 if(massBG>0.5 && massBG<0.57){
3946                         fHistograms->FillHistogram("ESD_Background_alfa_Eta", alfa);
3947                         fHistograms->FillHistogram("ESD_Background_Pt_alpha_Eta", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
3948                 }
3949
3950                 if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(previousGoodV0.GetEta())<0.9 ){
3951                         fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_Fiducial",massBG,momentumVectorbackgroundCandidate.Pt());
3952                         fHistograms->FillHistogram("ESD_Background_InvMass_Fiducial",massBG);
3953                 }
3954
3955                 // test
3956                 fHistograms->FillHistogram(Form("%d%dESD_Background_GammaDaughter_OpeningAngle",zbin,mbin), openingAngleBG);
3957                 fHistograms->FillHistogram(Form("%d%dESD_Background_Energy",zbin,mbin), backgroundCandidate->GetE());
3958                 fHistograms->FillHistogram(Form("%d%dESD_Background_Pt",zbin,mbin),     momentumVectorbackgroundCandidate.Pt());
3959                 fHistograms->FillHistogram(Form("%d%dESD_Background_Eta",zbin,mbin), momentumVectorbackgroundCandidate.Eta());
3960                 fHistograms->FillHistogram(Form("%d%dESD_Background_Rapidity",zbin,mbin), rapidity);
3961                 fHistograms->FillHistogram(Form("%d%dESD_Background_Phi",zbin,mbin), spaceVectorbackgroundCandidate.Phi());
3962                 fHistograms->FillHistogram(Form("%d%dESD_Background_Mass",zbin,mbin), massBG);
3963                 fHistograms->FillHistogram(Form("%d%dESD_Background_R",zbin,mbin), spaceVectorbackgroundCandidate.Pt());        // Pt in Space == R!!!!
3964                 fHistograms->FillHistogram(Form("%d%dESD_Background_ZR",zbin,mbin), backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
3965                 fHistograms->FillHistogram(Form("%d%dESD_Background_XY",zbin,mbin), backgroundCandidate->GetX(), backgroundCandidate->GetY());
3966                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
3967                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass",zbin,mbin),massBG);
3968                 
3969                 if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(previousGoodV0.GetEta())<0.9 ){
3970                         fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt_Fiducial",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
3971                         fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_Fiducial",zbin,mbin),massBG);
3972                 }
3973                 //              }
3974                                 }
3975                                 if(alfa<0.1){
3976                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_E_alpha",massBG ,backgroundCandidate->GetE());
3977                                 }
3978
3979                         }
3980                         delete backgroundCandidate;                     
3981                 }
3982         }
3983                         }
3984                 }
3985                 else{ // means using #V0s for multiplicity
3986
3987                         //              cout<<"Using the v0 multiplicity to calculate background"<<endl;
3988                 
3989                         fHistograms->FillHistogram("ESD_Background_z_m",zbin,mbin);
3990                         fHistograms->FillHistogram("ESD_Mother_multpilicityVSv0s",fV0Reader->CountESDTracks(),fV0Reader->GetNumberOfV0s());
3991
3992                         for(Int_t nEventsInBG=0;nEventsInBG <fV0Reader->GetNBGEvents();nEventsInBG++){
3993         AliGammaConversionKFVector * previousEventV0s = bgHandler->GetBGGoodV0s(zbin,mbin,nEventsInBG);// fV0Reader->GetBGGoodV0s(nEventsInBG);
3994         if(previousEventV0s){
3995         
3996                 if(fMoveParticleAccordingToVertex == kTRUE){
3997                         bgEventVertex = bgHandler->GetBGEventVertex(zbin,mbin,nEventsInBG);
3998                 }
3999
4000                 for(Int_t iCurrent=0;iCurrent<currentEventV0s->GetEntriesFast();iCurrent++){
4001                         AliKFParticle currentEventGoodV0 = *(AliKFParticle *)(currentEventV0s->At(iCurrent)); 
4002                         for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
4003                                 AliKFParticle previousGoodV0 = (AliKFParticle)(*(previousEventV0s->at(iPrevious)));
4004
4005                                 if(fMoveParticleAccordingToVertex == kTRUE){
4006                 MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
4007                                 }
4008
4009                                 AliKFParticle *backgroundCandidate = new AliKFParticle(currentEventGoodV0,previousGoodV0);
4010                                 Double_t massBG =0.;
4011                                 Double_t widthBG = 0.;
4012                                 Double_t chi2BG =10000.;        
4013                                 backgroundCandidate->GetMass(massBG,widthBG);
4014
4015                                 /*                      if(backgroundCandidate->GetNDF()>0){
4016                                         chi2BG = backgroundCandidate->GetChi2()/backgroundCandidate->GetNDF();
4017                                         {//remember to remove
4018                                         TVector3 momentumVectorbackgroundCandidate(backgroundCandidate->GetPx(),backgroundCandidate->GetPy(),backgroundCandidate->GetPz());
4019                                         TVector3 spaceVectorbackgroundCandidate(backgroundCandidate->GetX(),backgroundCandidate->GetY(),backgroundCandidate->GetZ());
4020                                 
4021                                         Double_t openingAngleBG = currentEventGoodV0.GetAngle(previousGoodV0);
4022                                         fHistograms->FillHistogram("ESD_Background_GammaDaughter_OpeningAngle_nochi2", openingAngleBG);
4023                                         }
4024                                 */
4025                                 chi2BG = backgroundCandidate->GetChi2();
4026                                 if((chi2BG>0 && chi2BG<fV0Reader->GetChi2CutMeson()) || fApplyChi2Cut == kFALSE){
4027                 TVector3 momentumVectorbackgroundCandidate(backgroundCandidate->GetPx(),backgroundCandidate->GetPy(),backgroundCandidate->GetPz());
4028                 TVector3 spaceVectorbackgroundCandidate(backgroundCandidate->GetX(),backgroundCandidate->GetY(),backgroundCandidate->GetZ());
4029                                         
4030                 Double_t openingAngleBG = currentEventGoodV0.GetAngle(previousGoodV0);
4031                                         
4032                 Double_t rapidity;
4033                 if(backgroundCandidate->GetE() - backgroundCandidate->GetPz() == 0 || backgroundCandidate->GetE() + backgroundCandidate->GetPz() == 0){
4034                         rapidity=8.;
4035                 }else{
4036                         rapidity = 0.5*(TMath::Log((backgroundCandidate->GetE() +backgroundCandidate->GetPz()) / (backgroundCandidate->GetE()-backgroundCandidate->GetPz())));
4037                 }               
4038                 if(TMath::Abs(rapidity) > fV0Reader->GetRapidityMesonCut() ){
4039                         delete backgroundCandidate;      
4040                         continue;        // rapidity cut
4041                 }                       
4042                                                                 
4043
4044                 Double_t alfa=0.0;
4045                 if( (currentEventGoodV0.GetE()+previousGoodV0.GetE()) != 0){
4046                         alfa=TMath::Abs((currentEventGoodV0.GetE()-previousGoodV0.GetE())
4047                                         /(currentEventGoodV0.GetE()+previousGoodV0.GetE()));
4048                 }
4049                         
4050                                         
4051                 if(openingAngleBG < fMinOpeningAngleGhostCut ){
4052                         delete backgroundCandidate;      
4053                         continue;        // minimum opening angle to avoid using ghosttracks
4054                 }                       
4055
4056                 if(alfa>fV0Reader->GetAlphaMinCutMeson() &&      alfa<fV0Reader->GetAlphaCutMeson()){
4057                         fHistograms->FillHistogram("ESD_Background_GammaDaughter_OpeningAngle", openingAngleBG);
4058                         fHistograms->FillHistogram("ESD_Background_Energy", backgroundCandidate->GetE());
4059                         fHistograms->FillHistogram("ESD_Background_Pt", momentumVectorbackgroundCandidate.Pt());
4060                         fHistograms->FillHistogram("ESD_Background_Eta", momentumVectorbackgroundCandidate.Eta());
4061                         fHistograms->FillHistogram("ESD_Background_Rapidity", rapidity);
4062                         fHistograms->FillHistogram("ESD_Background_Phi", spaceVectorbackgroundCandidate.Phi());
4063                         fHistograms->FillHistogram("ESD_Background_Mass", massBG);
4064                         fHistograms->FillHistogram("ESD_Background_R", spaceVectorbackgroundCandidate.Pt());    // Pt in Space == R!!!!
4065                         fHistograms->FillHistogram("ESD_Background_ZR", backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
4066                         fHistograms->FillHistogram("ESD_Background_XY", backgroundCandidate->GetX(), backgroundCandidate->GetY());
4067                         fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt",massBG,momentumVectorbackgroundCandidate.Pt());
4068                         fHistograms->FillHistogram("ESD_Background_InvMass",massBG);
4069                         
4070
4071                         fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_alpha",massBG,momentumVectorbackgroundCandidate.Pt());
4072
4073                         if(massBG>0.1 && massBG<0.15){
4074                                 fHistograms->FillHistogram("ESD_Background_alfa_Pi0", alfa);
4075                                 fHistograms->FillHistogram("ESD_Background_Pt_alpha_Pi0", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
4076                         }
4077                         if(massBG>0.5 && massBG<0.57){
4078                                 fHistograms->FillHistogram("ESD_Background_alfa_Eta", alfa);
4079                                 fHistograms->FillHistogram("ESD_Background_Pt_alpha_Eta", momentumVectorbackgroundCandidate.Pt(), alfa); //RR_alpha
4080                         }
4081
4082                         if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(previousGoodV0.GetEta())<0.9 ){
4083                                 fHistograms->FillHistogram("ESD_Background_InvMass_vs_Pt_Fiducial",massBG,momentumVectorbackgroundCandidate.Pt());
4084                                 fHistograms->FillHistogram("ESD_Background_InvMass_Fiducial",massBG);
4085                         }
4086                         
4087                         if(massBG>0.5 && massBG<0.6){
4088                                 fHistograms->FillHistogram("ESD_Background_alfa_pt0506",momentumVectorbackgroundCandidate.Pt(),alfa);
4089                         }
4090                         if(massBG>0.3 && massBG<0.4){
4091                                 fHistograms->FillHistogram("ESD_Background_alfa_pt0304",momentumVectorbackgroundCandidate.Pt(),alfa);
4092                         }
4093                         
4094                         // test
4095                         fHistograms->FillHistogram(Form("%d%dESD_Background_GammaDaughter_OpeningAngle",zbin,mbin), openingAngleBG);
4096                         fHistograms->FillHistogram(Form("%d%dESD_Background_Energy",zbin,mbin), backgroundCandidate->GetE());
4097                         fHistograms->FillHistogram(Form("%d%dESD_Background_Pt",zbin,mbin),     momentumVectorbackgroundCandidate.Pt());
4098                         fHistograms->FillHistogram(Form("%d%dESD_Background_Eta",zbin,mbin), momentumVectorbackgroundCandidate.Eta());
4099                         fHistograms->FillHistogram(Form("%d%dESD_Background_Rapidity",zbin,mbin), rapidity);
4100                         fHistograms->FillHistogram(Form("%d%dESD_Background_Phi",zbin,mbin), spaceVectorbackgroundCandidate.Phi());
4101                         fHistograms->FillHistogram(Form("%d%dESD_Background_Mass",zbin,mbin), massBG);
4102                         fHistograms->FillHistogram(Form("%d%dESD_Background_R",zbin,mbin), spaceVectorbackgroundCandidate.Pt());        // Pt in Space == R!!!!
4103                         fHistograms->FillHistogram(Form("%d%dESD_Background_ZR",zbin,mbin), backgroundCandidate->GetZ(), spaceVectorbackgroundCandidate.Pt());
4104                         fHistograms->FillHistogram(Form("%d%dESD_Background_XY",zbin,mbin), backgroundCandidate->GetX(), backgroundCandidate->GetY());
4105                         fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
4106                         fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass",zbin,mbin),massBG);
4107                         
4108                         if ( TMath::Abs(currentEventGoodV0.GetEta())<0.9 &&     TMath::Abs(previousGoodV0.GetEta())<0.9 ){
4109                                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_vs_Pt_Fiducial",zbin,mbin),massBG,momentumVectorbackgroundCandidate.Pt());
4110                                 fHistograms->FillHistogram(Form("%d%dESD_Background_InvMass_Fiducial",zbin,mbin),massBG);
4111                         }
4112                 }
4113
4114                 if(alfa<0.1){
4115                         fHistograms->FillHistogram("ESD_Background_InvMass_vs_E_alpha",massBG ,backgroundCandidate->GetE());
4116                 }
4117                 //      }
4118                                 }
4119                                 delete backgroundCandidate;                     
4120                         }
4121                 }
4122         }
4123                         }
4124                 } // end else (means use #v0s as multiplicity)
4125         } // end no rotation
4126 }
4127
4128
4129 void AliAnalysisTaskGammaConversion::ProcessGammasForGammaJetAnalysis(){
4130         //ProcessGammasForGammaJetAnalysis
4131         
4132         Double_t distIsoMin;
4133         
4134         CreateListOfChargedParticles();
4135         
4136         
4137         //      for(UInt_t gammaIndex=0;gammaIndex<fKFReconstructedGammas.size();gammaIndex++){
4138         for(Int_t gammaIndex=0;gammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();gammaIndex++){
4139                 AliKFParticle * currentGamma = (AliKFParticle*)fKFReconstructedGammasTClone->At(gammaIndex);
4140                 TVector3 momentumVectorCurrentGamma(currentGamma->GetPx(),currentGamma->GetPy(),currentGamma->GetPz());
4141                 if( momentumVectorCurrentGamma.Pt()> fMinPtForGammaJet){
4142                         distIsoMin=GetMinimumDistanceToCharge(gammaIndex);
4143                         if (distIsoMin > fMinIsoConeSize && fLeadingChargedIndex>=0){
4144                                 CalculateJetCone(gammaIndex);
4145                         }
4146                 }
4147         }
4148 }
4149
4150 //____________________________________________________________________
4151 Bool_t AliAnalysisTaskGammaConversion::IsGoodImpPar(const AliESDtrack *const track)
4152 {
4153         //
4154         // check whether particle has good DCAr(Pt) impact
4155         // parameter. Only for TPC+ITS tracks (7*sigma cut)
4156         // Origin: Andrea Dainese
4157         //
4158
4159         Float_t d0z0[2],covd0z0[3];
4160         track->GetImpactParameters(d0z0,covd0z0);
4161         Float_t sigma= 0.0050+0.0060/TMath::Power(track->Pt(),0.9);
4162         Float_t d0max = 7.*sigma;
4163         if(TMath::Abs(d0z0[0]) < d0max) return kTRUE;
4164
4165         return kFALSE;
4166 }
4167
4168
4169 void AliAnalysisTaskGammaConversion::CreateListOfChargedParticles(){
4170         // CreateListOfChargedParticles
4171         
4172         fESDEvent = fV0Reader->GetESDEvent();
4173         Int_t numberOfESDTracks=0;
4174         for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
4175                 AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
4176                 
4177                 if(!curTrack){
4178                         continue;
4179                 }
4180                 // Not needed if Standard function used.
4181                 //               if(!IsGoodImpPar(curTrack)){
4182                 //                       continue;
4183                 //               }
4184                 
4185                 if(fEsdTrackCuts->AcceptTrack(curTrack) ){
4186                         new((*fChargedParticles)[fChargedParticles->GetEntriesFast()])  AliESDtrack(*curTrack);
4187                         //                      fChargedParticles.push_back(curTrack);
4188                         fChargedParticlesId.push_back(iTracks);
4189                         numberOfESDTracks++;
4190                 }
4191         }
4192         // Moved to UserExec using CountAcceptedTracks function. runjet is not needed by default
4193         //       fHistograms->FillHistogram("ESD_NumberOfGoodESDTracks",numberOfESDTracks);
4194         //       cout<<"esdtracks::"<< numberOfESDTracks<<endl;
4195         //       if (fV0Reader->GetNumberOfContributorsVtx()>=1){
4196         //               fHistograms->FillHistogram("ESD_NumberOfGoodESDTracksVtx",numberOfESDTracks);
4197         //       } 
4198 }
4199
4200 void AliAnalysisTaskGammaConversion::CalculateJetCone(Int_t gammaIndex){
4201         // CaculateJetCone
4202         
4203         Double_t cone;
4204         Double_t coneSize=0.3;
4205         Double_t ptJet=0;
4206         
4207         //      AliKFParticle * currentGamma = &fKFReconstructedGammas[gammaIndex];
4208         AliKFParticle * currentGamma = (AliKFParticle*)fKFReconstructedGammasTClone->At(gammaIndex);
4209
4210         TVector3 momentumVectorCurrentGamma(currentGamma->GetPx(),currentGamma->GetPy(),currentGamma->GetPz());
4211         
4212         AliESDtrack* leadingCharged = (AliESDtrack*)(fChargedParticles->At(fLeadingChargedIndex));
4213
4214         Double_t momLeadingCharged[3];
4215         leadingCharged->GetConstrainedPxPyPz(momLeadingCharged);
4216         
4217         TVector3 momentumVectorLeadingCharged(momLeadingCharged[0],momLeadingCharged[1],momLeadingCharged[2]);
4218         
4219         Double_t phi1=momentumVectorLeadingCharged.Phi();
4220         Double_t eta1=momentumVectorLeadingCharged.Eta();
4221         Double_t phi3=momentumVectorCurrentGamma.Phi();
4222         
4223         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
4224                 AliESDtrack* curTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
4225                 Int_t chId = fChargedParticlesId[iCh];
4226                 if(fLeadingChargedIndex==chId || fLeadingChargedIndex==chId) continue;
4227                 Double_t mom[3];
4228                 curTrack->GetConstrainedPxPyPz(mom);
4229                 TVector3 momentumVectorChargedParticle(mom[0],mom[1],mom[2]);
4230                 Double_t phi2=momentumVectorChargedParticle.Phi();
4231                 Double_t eta2=momentumVectorChargedParticle.Eta();
4232                 
4233                 
4234                 cone=100.;
4235                 if( TMath::Abs(phi2 - phi1) <= ( TMath::TwoPi()-coneSize) ){
4236                         cone = TMath::Sqrt(     TMath::Power((eta2-eta1),2)+ TMath::Power((phi2-phi1),2) );
4237                 }else{
4238                         if( (phi2 - phi1)> TMath::TwoPi()-coneSize ){
4239                                 cone = TMath::Sqrt(     TMath::Power((eta2-eta1),2)+ TMath::Power((phi2-TMath::TwoPi()-phi1),2) );
4240                         }
4241                         if( (phi2 - phi1)< -(TMath::TwoPi()-coneSize) ){
4242                                 cone = TMath::Sqrt(     TMath::Power((eta2-eta1),2)+ TMath::Power((phi2+TMath::TwoPi()-phi1),2) );
4243                         }
4244                 }
4245                 
4246                 if(cone <coneSize&& momentumVectorChargedParticle.Pt()>fMinPtJetCone ){
4247                         ptJet+= momentumVectorChargedParticle.Pt();
4248                         Double_t ffzHdrGam = momentumVectorChargedParticle.Pt()/momentumVectorCurrentGamma.Pt();
4249                         Double_t imbalanceHdrGam=-momentumVectorChargedParticle.Dot(momentumVectorCurrentGamma)/momentumVectorCurrentGamma.Mag2();
4250                         fHistograms->FillHistogram("ESD_FFzHdrGam",ffzHdrGam);
4251                         fHistograms->FillHistogram("ESD_ImbalanceHdrGam",imbalanceHdrGam);
4252                         
4253                 }
4254                 
4255                 Double_t dphiHdrGam=phi3-phi2;
4256                 if ( dphiHdrGam < (-TMath::PiOver2())){
4257                         dphiHdrGam+=(TMath::TwoPi());
4258                 }
4259                 
4260                 if ( dphiHdrGam > (3.*TMath::PiOver2()) ){
4261                         dphiHdrGam-=(TMath::TwoPi());
4262                 }
4263                 
4264                 if (momentumVectorChargedParticle.Pt()>fMinPtGamChargedCorr){
4265                         fHistograms->FillHistogram("ESD_dphiHdrGamIsolated",dphiHdrGam);
4266                 }
4267         }//track loop
4268         
4269         
4270         }
4271
4272
4273
4274 Double_t AliAnalysisTaskGammaConversion::GetMinimumDistanceToCharge(Int_t indexHighestPtGamma){
4275         // GetMinimumDistanceToCharge
4276         
4277         Double_t fIsoMin=100.;
4278         Double_t ptLeadingCharged=-1.;
4279
4280         fLeadingChargedIndex=-1;
4281         
4282         AliKFConversionPhoton * gammaHighestPt = (AliKFConversionPhoton*)fKFReconstructedGammasTClone->At(indexHighestPtGamma);
4283         TVector3 momentumVectorgammaHighestPt(gammaHighestPt->GetPx(),gammaHighestPt->GetPy(),gammaHighestPt->GetPz());
4284         
4285         Double_t phi1=momentumVectorgammaHighestPt.Phi();
4286         Double_t eta1=momentumVectorgammaHighestPt.Eta();
4287         
4288         for(Int_t iCh=0;iCh<fChargedParticles->GetEntriesFast();iCh++){
4289                 AliESDtrack* curTrack = (AliESDtrack*)(fChargedParticles->At(iCh));
4290                 Int_t chId = fChargedParticlesId[iCh];
4291                 if(gammaHighestPt->GetTrackLabelPositive()==chId || gammaHighestPt->GetTrackLabelNegative()==chId) continue;
4292                 Double_t mom[3];
4293                 curTrack->GetConstrainedPxPyPz(mom);
4294                 TVector3 momentumVectorChargedParticle(mom[0],mom[1],mom[2]);
4295                 Double_t phi2=momentumVectorChargedParticle.Phi();
4296                 Double_t eta2=momentumVectorChargedParticle.Eta();
4297                 Double_t iso=pow(       (pow( (eta1-eta2),2)+ pow((phi1-phi2),2)),0.5 );
4298                 
4299                 if(momentumVectorChargedParticle.Pt()>fMinPtIsoCone ){
4300                         if (iso<fIsoMin){
4301         fIsoMin=iso;
4302                         }
4303                 }
4304                 
4305                 Double_t dphiHdrGam=phi1-phi2;
4306                 if ( dphiHdrGam < (-TMath::PiOver2())){
4307                         dphiHdrGam+=(TMath::TwoPi());
4308                 }
4309                 
4310                 if ( dphiHdrGam > (3.*TMath::PiOver2()) ){
4311                         dphiHdrGam-=(TMath::TwoPi());
4312                 }
4313                 if (momentumVectorChargedParticle.Pt()>fMinPtGamChargedCorr){
4314                         fHistograms->FillHistogram("ESD_dphiHdrGam",dphiHdrGam);
4315                 }
4316                 
4317                 if (dphiHdrGam>0.9*TMath::Pi() && dphiHdrGam<1.1*TMath::Pi()){
4318                         if (momentumVectorChargedParticle.Pt()> ptLeadingCharged && momentumVectorChargedParticle.Pt()>0.1*momentumVectorgammaHighestPt.Pt()){
4319                                 ptLeadingCharged=momentumVectorChargedParticle.Pt();
4320                                 fLeadingChargedIndex=iCh;
4321                         }
4322                 }
4323                 
4324         }//track loop
4325         fHistograms->FillHistogram("ESD_MinimumIsoDistance",fIsoMin);
4326         return fIsoMin;
4327         
4328 }
4329
4330 Int_t   AliAnalysisTaskGammaConversion::GetIndexHighestPtGamma(){
4331         //GetIndexHighestPtGamma
4332         
4333         Int_t indexHighestPtGamma=-1;
4334         //Double_t 
4335         fGammaPtHighest = -100.;
4336         
4337         for(Int_t firstGammaIndex=0;firstGammaIndex<fKFReconstructedGammasTClone->GetEntriesFast();firstGammaIndex++){
4338                 AliKFParticle * gammaHighestPtCandidate = (AliKFParticle*)fKFReconstructedGammasTClone->At(firstGammaIndex);
4339                 TVector3 momentumVectorgammaHighestPtCandidate(gammaHighestPtCandidate->GetPx(),gammaHighestPtCandidate->GetPy(),gammaHighestPtCandidate->GetPz());
4340                 if (momentumVectorgammaHighestPtCandidate.Pt() > fGammaPtHighest){
4341                         fGammaPtHighest=momentumVectorgammaHighestPtCandidate.Pt();
4342                         //gammaHighestPt = gammaHighestPtCandidate;
4343                         indexHighestPtGamma=firstGammaIndex;
4344                 }
4345         }
4346         
4347         return indexHighestPtGamma;
4348         
4349 }
4350
4351
4352 void AliAnalysisTaskGammaConversion::Terminate(Option_t */*option*/)
4353 {
4354         // Terminate analysis
4355         //
4356         AliDebug(1,"Do nothing in Terminate");
4357 }
4358
4359 void AliAnalysisTaskGammaConversion::UserCreateOutputObjects()
4360 {
4361         
4362         if(fKFCreateAOD) {
4363
4364                 //AOD
4365                 if(!fAODGamma) fAODGamma = new TClonesArray("AliAODConversionPhoton", 0);
4366                 else fAODGamma->Delete();
4367                 fAODGamma->SetOwner(kTRUE);
4368                 fAODGamma->SetName(Form("%s_gamma", fAODBranchName.Data()));
4369                 
4370                 if(GetDeltaAODFileName().Length() > 0) {
4371                         AddAODBranch("TClonesArray", &fAODGamma, GetDeltaAODFileName().Data());
4372                         AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile(GetDeltaAODFileName().Data());
4373                 } else  {
4374                         AddAODBranch("TClonesArray", &fAODGamma);
4375                 }
4376         }
4377
4378         // Create the output container
4379         if(fOutputContainer != NULL){
4380                 delete fOutputContainer;
4381                 fOutputContainer = NULL;
4382         }
4383         if(fOutputContainer == NULL){
4384                 fOutputContainer = new TList();
4385                 fOutputContainer->SetOwner(kTRUE);
4386         }
4387         
4388         //Adding the histograms to the output container
4389         fHistograms->GetOutputContainer(fOutputContainer);
4390         
4391         
4392         if(fWriteNtuple){
4393                 if(fGammaNtuple == NULL){
4394                         fGammaNtuple = new TNtuple("V0ntuple","V0ntuple","OnTheFly:HasVertex:NegPIDProb:PosPIDProb:X:Y:Z:R:MotherCandidateNDF:MotherCandidateChi2:MotherCandidateEnergy:MotherCandidateEta:MotherCandidatePt:MotherCandidateMass:MotherCandidateWidth:MCMotherCandidatePT:EPOpeningAngle:ElectronEnergy:ElectronPt:ElectronEta:ElectronPhi:PositronEnergy:PositronPt:PositronEta:PositronPhi:HasSameMCMother:MotherMCParticlePIDCode",50000);
4395                 }
4396                 if(fNeutralMesonNtuple == NULL){
4397                         fNeutralMesonNtuple = new TNtuple("NeutralMesonNtuple","NeutralMesonNtuple","test");
4398                 }
4399                 TList * ntupleTList = new TList();
4400                 ntupleTList->SetOwner(kTRUE);
4401                 ntupleTList->SetName("Ntuple");
4402                 ntupleTList->Add((TNtuple*)fGammaNtuple);
4403                 fOutputContainer->Add(ntupleTList);
4404         }
4405         
4406         fOutputContainer->SetName(GetName());
4407
4408         PostData(0, fAODGamma);
4409         PostData(1, fOutputContainer);
4410         PostData(2, fCFManager->GetParticleContainer());        // for CF
4411         PostData(3, fAODGamma); 
4412 }
4413
4414 Double_t AliAnalysisTaskGammaConversion::GetMCOpeningAngle(const TParticle* const daughter0, const TParticle* const daughter1) const{
4415         //helper function
4416         TVector3 v3D0(daughter0->Px(),daughter0->Py(),daughter0->Pz());
4417         TVector3 v3D1(daughter1->Px(),daughter1->Py(),daughter1->Pz());
4418         return v3D0.Angle(v3D1);
4419 }
4420
4421 void AliAnalysisTaskGammaConversion::CheckV0Efficiency(){
4422         // see header file for documentation
4423
4424         vector<Int_t> indexOfGammaParticle;
4425         
4426         fStack = fV0Reader->GetMCStack();
4427         
4428         if(fV0Reader->CheckForPrimaryVertex() == kFALSE){
4429                 return; // aborts if the primary vertex does not have contributors.
4430         }
4431         
4432         for (Int_t iTracks = 0; iTracks < fStack->GetNprimary(); iTracks++) {
4433                 TParticle* particle = (TParticle *)fStack->Particle(iTracks);
4434                 if(particle->GetPdgCode()==22){          //Gamma
4435                         if(particle->GetNDaughters() >= 2){
4436                                 TParticle* electron=NULL;
4437                                 TParticle* positron=NULL; 
4438                                 for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
4439                                         TParticle *tmpDaughter = fStack->Particle(daughterIndex);
4440                                         if(tmpDaughter->GetUniqueID() == 5){
4441                                                 if(tmpDaughter->GetPdgCode() == 11){
4442                                                         electron = tmpDaughter;
4443                                                 }
4444                                                 else if(tmpDaughter->GetPdgCode() == -11){
4445                                                         positron = tmpDaughter;
4446                                                 }
4447                                         }
4448                                 }
4449                                 if(electron!=NULL && positron!=0){
4450                                         if(electron->R()<160){
4451                                                 indexOfGammaParticle.push_back(iTracks);
4452                                         }
4453                                 }
4454                         }
4455                 }
4456         }
4457         
4458         Int_t nFoundGammas=0;
4459         Int_t nNotFoundGammas=0;
4460         
4461         Int_t numberOfV0s = fV0Reader->GetNumberOfV0s();
4462         for(Int_t i=0;i<numberOfV0s;i++){
4463                 fV0Reader->GetV0(i);
4464                 
4465                 if(fV0Reader->HasSameMCMother() == kFALSE){
4466                         continue;
4467                 }
4468                 
4469                 TParticle * negativeMC = (TParticle*)fV0Reader->GetNegativeMCParticle();
4470                 TParticle * positiveMC = (TParticle*)fV0Reader->GetPositiveMCParticle();
4471                 
4472                 if(TMath::Abs(negativeMC->GetPdgCode())!=11 || TMath::Abs(positiveMC->GetPdgCode())!=11){
4473                         continue;
4474                 }
4475                 if(negativeMC->GetPdgCode()==positiveMC->GetPdgCode()){
4476                         continue;
4477                 }
4478                 
4479                 if(fV0Reader->GetMotherMCParticle()->GetPdgCode() == 22){
4480                         //TParticle * v0Gamma = fV0Reader->GetMotherMCParticle();
4481                         for(UInt_t mcIndex=0;mcIndex<indexOfGammaParticle.size();mcIndex++){
4482                                 if(negativeMC->GetFirstMother()==indexOfGammaParticle[mcIndex]){
4483                                         nFoundGammas++;
4484                                 }
4485                                 else{
4486                                         nNotFoundGammas++;
4487                                 }
4488                         }
4489                 }
4490         }
4491 }
4492
4493 //_____________________________________________________________________
4494 void  AliAnalysisTaskGammaConversion::ProcessHadronicInteraction(AliESDEvent *event){
4495         //
4496         // Process pairs of tracks to get a material budget map
4497         //
4498         //
4499         if (!event) return;
4500         if (event) AliKFParticle::SetField(event->GetMagneticField());  // set mean magnetic field for KF particles
4501 //      TTreeSRedirector *fpcstream = new TTreeSRedirector("eventInfoHadInt.root");
4502         // 1. Calculate total dEdx for all TPC tracks
4503         //
4504         const Int_t kMinCl=50;
4505         const Double_t kEpsilon=0.000001;
4506         const Float_t kMinRatio=0.7;
4507         const Float_t kMinDist=1.5;
4508         const Float_t kMinDistChi2=8.;        // 
4509         const Float_t kMaxDistZ=300.;        // max distanceZ
4510         const Float_t kMaxDistR=250.;          // max distanceR
4511         const Double_t kMaxChi2   =36.;     // maximal chi2 to define the vertex
4512         const Double_t kMaxDistVertexSec=2.;     // maximal distance to secondary vertex
4513         const Double_t kMinPtHadTrack = fPtMinHadInt;
4514         Float_t         arrayRBins[6] =                 {5.75,9.5,21.,35.,42.,55.};
4515         
4516         Double_t szz=1.;      // number to be taken from the OCDB - now it can be hack
4517         Double_t stt = 0.006667; // 
4518
4519         if (!event) return;
4520                 AliESDVertex *vertexSPD =  (AliESDVertex *)event->GetPrimaryVertexSPD();
4521 //      AliESDVertex * spdVertex   = (AliESDVertex *)event->GetPrimaryVertexSPD();
4522 //      AliESDVertex * trackVertex = (AliESDVertex *)event->GetPrimaryVertexTracks();
4523 //      AliESDVertex * tpcVertex   = (AliESDVertex *)event->GetPrimaryVertexTPC();
4524 //      AliESDTZERO  * tzero       = (AliESDTZERO  *)event->GetESDTZERO() ;
4525         //
4526         Double_t tpcSignalTotPrim=0; 
4527         Double_t tpcSignalTotSec=0; 
4528         Int_t ntracksTPC=0;
4529         Int_t nTPCPrim=0; 
4530         Int_t nTPCSec=0;  
4531         Int_t ntracks=event->GetNumberOfTracks();
4532         if ( ntracks<=2 ) return;
4533         
4534         //
4535         Float_t dca[2]={0};
4536         Float_t cov[3]={0};
4537         Float_t dca0[2]={0};
4538         Float_t dca1[2]={0};
4539         //
4540         //1. Calculate total dEdx for primary and secondary tracks
4541         //   and count primaries and secondaries
4542         Int_t *rejectTrack = new Int_t[ntracks];
4543         Float_t *trackUsedInVtx = new Float_t[ntracks];
4544         
4545         for (Int_t ii=0; ii<ntracks; ii++){
4546                 trackUsedInVtx[ii] = 0.;
4547         }
4548         Int_t nTracksCont = 0;
4549         
4550         for (Int_t itrack=0; itrack<ntracks; itrack++){
4551                 AliESDtrack *track=event->GetTrack(itrack);
4552                 rejectTrack[itrack]=0;
4553                 if (!track) continue;
4554                 if ((track->Pt())<kMinPtHadTrack){ rejectTrack[itrack]+=32; continue;}
4555                 if (track->GetTPCNcls()<=kMinCl) {rejectTrack[itrack]+=64; continue;}  // skip short tracks
4556                 ntracksTPC++;
4557                 if ((1.+track->GetTPCNcls())/(1.+track->GetTPCNclsF())<=kMinRatio){rejectTrack[itrack]+=128; continue;}
4558                 if (!track->GetInnerParam()) continue;  // skip not TPC tracks
4559                 if (track->GetKinkIndex(0)!=0)  {rejectTrack[itrack]+=16;continue;} // skip kinks
4560                 track->GetImpactParameters(dca,cov);
4561                 if (TMath::Abs(dca[0])>kMaxDistR && TMath::Abs(dca[1])>kMaxDistZ){rejectTrack[itrack]+=256; continue;}
4562                 // remove too dip secondaries
4563                 if (TMath::Abs(dca[0])<kMinDist && TMath::Abs(dca[1])<kMinDist){
4564                         tpcSignalTotPrim+=track->GetTPCsignal();
4565                         nTPCPrim++;
4566                         rejectTrack[itrack]+=256;
4567                 }else{
4568                         tpcSignalTotSec+=track->GetTPCsignal();
4569                         nTPCSec++;
4570                 };
4571                 if (cov[0]>kEpsilon &&TMath::Abs(dca[0])>kEpsilon &&TMath::Sqrt(dca[0]*dca[0]/(TMath::Abs(cov[0])))<kMinDistChi2) rejectTrack[itrack]+=1;  // primary
4572                 if (cov[0]>kEpsilon &&TMath::Abs(dca[0])>kEpsilon &&TMath::Abs(dca[0])<kMinDist)  rejectTrack[itrack]+=1;  // primary
4573                 if (track->GetTPCsignal()<40) rejectTrack[itrack]+=16;
4574                 //
4575                 if (CheckLooper(itrack, event))   rejectTrack[itrack]+=2;   // looper
4576                 if (CheckV0(itrack,event))       rejectTrack[itrack]+=4; //indentified V0 rejection (K0s, Lambda, gamma conv)
4577
4578 //              UInt_t status = track->GetStatus();
4579                 if (!track->IsOn(AliVTrack::kITSrefit) && !fDoMCTruth){ 
4580                         
4581                         Double_t *covar = (Double_t*)track->GetInnerParam()->GetCovariance();
4582                         //
4583                         //remove -systematic error estimate
4584                         //
4585                         Double_t sigmazz  = covar[track->GetIndex(1,1)];
4586                         Double_t dr = TMath::Abs(TMath::Sqrt((track->GetX()*track->GetX()+track->GetY()*track->GetY())) - TMath::Sqrt((track->GetInnerParam()->GetX()*track->GetInnerParam()->GetX()+track->GetInnerParam()->GetY()*track->GetInnerParam()->GetY()))) ;
4587                         
4588                         Double_t sigmazz0 = sigmazz -szz*szz - stt*stt*dr*dr;
4589 //                      cout << "old sigma z: "<<sigmazz << " new sigma z: " << sigmazz0 << endl;
4590                         if (sigmazz0<0) sigmazz0=0.1;  // should not happen - the code should be protected
4591                         covar[track->GetIndex(1,1)]=sigmazz0;
4592                         //
4593                         // + rescale the correlation terms
4594                         //
4595                         Double_t ratio = TMath::Sqrt(sigmazz0/sigmazz);
4596                         for (Int_t index=0; index<5; index++){
4597                                 Int_t jindex = track->GetIndex(index,1);
4598                                 covar[jindex]*=ratio;
4599                         }
4600                 }
4601         } 
4602         
4603         
4604         //
4605         // 2. Find secondary vertices - double loop
4606         //    
4607         
4608         AliKFVertex vertexStored[15];
4609         Int_t kVertexArr[15][7];
4610         for (Int_t ii = 0; ii < 15; ii++){
4611                 for (Int_t bb = 0; bb < 7; bb++){
4612                                 kVertexArr[ii][bb] = 0;
4613                 }               
4614         }
4615         Int_t kTrackArr[500][7];
4616         for (Int_t ii = 0; ii < 500; ii++){
4617                 for (Int_t bb = 0; bb < 7; bb++){
4618                                 kTrackArr[ii][bb] = 0;
4619                 }               
4620         }
4621         
4622         Int_t nVertices = 0;
4623         Int_t nVerticesPassed = 0;
4624         
4625         for (Int_t itrack0=0; itrack0<ntracks; itrack0++){
4626                 if (rejectTrack[itrack0]) continue;   // skip
4627                 AliESDtrack *track0=event->GetTrack(itrack0);
4628                 if (!track0) continue;
4629                 
4630                 track0->GetImpactParameters(dca[0],dca[1]);
4631                 track0->GetImpactParameters(dca0[0],dca0[1]);
4632
4633                 AliKFParticle part0;
4634                 if (!track0->IsOn(AliVTrack::kITSrefit)){ 
4635                         part0=AliKFParticle(*track0->GetInnerParam(),211);  //assuming pion mass
4636                 } else {
4637                         part0=AliKFParticle(*track0,211);  //assuming pion mass
4638                 }
4639                 if (track0->Charge()*part0.Q()<0) part0.Q()*=-1;  // change sign if opposite
4640                 //
4641                 for (Int_t itrack1=itrack0+1; itrack1<ntracks; itrack1++){
4642                         if (rejectTrack[itrack1]) continue;   // skip
4643                         AliESDtrack *track1=event->GetTrack(itrack1);
4644                         if (!track1) continue;
4645                         track1->GetImpactParameters(dca1[0],dca1[1]);
4646                         track1->GetImpactParameters(dca[0],dca[1]);
4647                         AliKFParticle part1; // assuming pion mass
4648                         if (!track1->IsOn(AliVTrack::kITSrefit)){ 
4649                                 part1=AliKFParticle(*track1->GetInnerParam(),211);  //assuming pion mass
4650                         } else {
4651                                 part1=AliKFParticle(*track1,211);  //assuming pion mass
4652                         }
4653                         if (track1->Charge()*part1.Q()<0) part1.Q()*=-1;  // change sign if opposite
4654
4655                         //
4656                         //
4657                         AliKFVertex vertex;
4658                         vertex+=part0;
4659                         vertex+=part1;
4660                         if ((vertex.GetChi2()/vertex.GetNDF())> kMaxChi2) continue;
4661                         if (TMath::Abs(vertex.GetX())>kMaxDistR) continue;
4662                         if (TMath::Abs(vertex.GetY())>kMaxDistR) continue;
4663                         if (TMath::Abs(vertex.GetZ())>kMaxDistZ) continue;
4664                         Double_t errX2=vertex.GetErrX();
4665                         Double_t errY2=vertex.GetErrY();
4666                         Double_t errZ2=vertex.GetErrZ();
4667                         //
4668                         Double_t err3D=TMath::Sqrt(errX2*errX2+errY2*errY2+errZ2*errZ2/10.);  
4669                         if (err3D>kMaxDistVertexSec) continue;
4670                         if (err3D*TMath::Sqrt(vertex.GetChi2()+0.00001)>kMaxDistVertexSec) continue;
4671
4672                         Double_t dvertex=0;
4673                         dvertex += (vertexSPD->GetX()-vertex.GetX())*(vertexSPD->GetX()-vertex.GetX());
4674                         dvertex += (vertexSPD->GetY()-vertex.GetY())*(vertexSPD->GetY()-vertex.GetY());
4675                         dvertex += (vertexSPD->GetZ()-vertex.GetZ())*(vertexSPD->GetZ()-vertex.GetZ());
4676                         dvertex=TMath::Sqrt(dvertex+0.00000001);
4677                         if (err3D>0.2*dvertex) continue;    
4678                         if (err3D*TMath::Sqrt(vertex.GetChi2()+0.000001)>0.1*dvertex) continue;
4679                         Double_t radius = TMath::Sqrt((vertex.GetX()*vertex.GetX()+vertex.GetY()*vertex.GetY()));
4680                         
4681                         for (Int_t bb= 0; bb < 6; bb++){
4682                                 if (radius > arrayRBins[bb]) {
4683                                         if (track0->HasPointOnITSLayer(bb) ||  track1->HasPointOnITSLayer(bb) ) continue; 
4684                                 }
4685                         }
4686                         AliKFVertex vertex2;
4687                         vertex2+=part0;
4688                         vertex2+=part1;
4689                         //
4690
4691 //                      if(fDoMCTruth){
4692 //                              
4693 //                      }
4694                                 
4695                         trackUsedInVtx[itrack0] +=1.; 
4696                         trackUsedInVtx[itrack1] +=1.; 
4697                         
4698                         nTracksCont= 2;
4699                         kTrackArr[itrack0][0]+= 1;
4700                         kTrackArr[itrack1][0]+= 1;
4701                         kVertexArr[nVertices][0] = 2;
4702                         kVertexArr[nVertices][1] = 1;
4703                         kVertexArr[nVertices][2] = itrack0;
4704                         kVertexArr[nVertices][3] = itrack1;
4705                         
4706                         for (Int_t itrack2=0; itrack2<ntracks; itrack2++){  
4707                                 if (rejectTrack[itrack2]) continue;   // skip
4708                                 if (itrack2==itrack0) continue;
4709                                 if (itrack2==itrack1) continue;
4710                                 AliESDtrack *track2=event->GetTrack(itrack2);
4711                                 if (!track2) continue;
4712                                 track2->GetImpactParameters(dca[0],dca[1]);
4713                                 if (TMath::Abs(track2->GetD(vertex.GetX(), vertex.GetY(),event->GetMagneticField()))>kMaxDistVertexSec) continue;
4714                                 Double_t vtxx[3]={vertex2.GetX(),vertex2.GetY(),vertex2.GetZ()};
4715                                 Double_t svtxx[3]={vertex.GetErrX(),vertex.GetErrY(),vertex.GetErrZ()};
4716                                 AliESDVertex vtx(vtxx,svtxx);
4717                                 
4718                                 AliExternalTrackParam param;
4719                                 if (!track2->IsOn(AliVTrack::kITSrefit)){ 
4720                                         param= *track2->GetInnerParam();  //assuming pion mass
4721                                 } else {
4722                                         param=*track2;
4723                                 }
4724                                 Double_t delta[2]={0,0};
4725                                 if (!param.PropagateToDCA(&vtx,event->GetMagneticField(),kMaxDistVertexSec,delta)) continue;    
4726                                 if (TMath::Abs(delta[0])>kMaxDistVertexSec) continue;
4727                                 if (TMath::Abs(delta[1])>kMaxDistVertexSec) continue;      
4728                                 if (TMath::Abs(delta[0])>6.*TMath::Sqrt(param.GetSigmaY2()+vertex2.GetErrY()*vertex2.GetErrY())+0.1) continue; 
4729                                 if (TMath::Abs(delta[1])>6.*TMath::Sqrt(param.GetSigmaZ2()+vertex2.GetErrZ()*vertex2.GetErrZ())+0.5) continue; 
4730                                 //
4731                                 AliKFParticle part2(param,211); // assuming pion mass
4732                                 if (track2->Charge()*part2.Q()<0) part2.Q()*=-1;  // change sign if opposite
4733
4734                                 for (Int_t cc= 0; cc < 6; cc++){
4735                                         if (radius > arrayRBins[cc]){
4736                                                 if (track2->HasPointOnITSLayer(cc)  ) continue; 
4737                                         }
4738                                 }
4739                         
4740
4741                                 vertex2+=part2;
4742 //                              rejectTrack[itrack0]+=10;  // do noit reuse the track
4743 //                              rejectTrack[itrack1]+=10;  // do not reuse the track      
4744 //                              rejectTrack[itrack2]+=10;
4745                                 trackUsedInVtx[itrack2] +=1.;           
4746 //                              cout << "track number " << itrack2 << " used times " <<  trackUsedInVtx[itrack2] << endl;
4747                                 nTracksCont++ ;
4748                                 kTrackArr[itrack2][0]+= 1;
4749                                 kVertexArr[nVertices][0] = nTracksCont;
4750                                 kVertexArr[nVertices][1] = 1;
4751                                 kVertexArr[nVertices][nTracksCont+1] = itrack2;
4752                         
4753                         }
4754 //                      if (nVertices == 0){            
4755 //                              cout << "new Event" << endl;
4756 //                      }
4757 //                      cout << "Vertex " << nVertices << " nTracks " << kVertexArr[nVertices][0] << endl;
4758 //                      for (Int_t ii = 2  ; ii < kVertexArr[nVertices][0]+2; ii++){
4759 //                              cout << "\t Track " << kVertexArr[nVertices][ii] << endl;
4760 //                      }
4761                         vertexStored[nVertices]= vertex2;
4762                         nVertices++;
4763 //                      Double_t errX=vertex2.GetErrX();
4764 //                      Double_t errY=vertex2.GetErrY();
4765 //                      Double_t errZ=vertex2.GetErrZ();
4766 //                      Double_t vx = vertex2.GetX();
4767 //                      Double_t vy = vertex2.GetY();
4768 //                      Double_t vz = vertex2.GetZ();
4769 //                      Double_t vr = sqrt((Double_t)(vx*vx + vy*vy));
4770 //                      Double_t vphi = vertex2.GetPhi(); 
4771 //                      Double_t vphi2 = TMath::ATan2(vy, vx);
4772 //                      cout << "\t Quality \t errX: " <<errX << "\t errY: " << errY << "\t errZ: " << errZ << "\t Chi2/ndf: " << vertex2.GetChi2()/vertex2.GetNDF() << endl;
4773 //                      cout << "\t Position \t x: " <<  vx << "\t y: " << vy << "\t z: " << vz <<"\t r: " << vr  << "\t phi: " << vphi << "\t phi dir calc: " << vphi2 << endl;
4774 //                      Double_t vNDCA = vertex2.GetDcaV0Daughters()/vertex2.GetDistSigma() 
4775 //                      if (fpcstream){
4776 //                              (*fpcstream)<<"ntracks="<<ntracks<<
4777 //                              "ntracksTPC="<<ntracksTPC<<
4778 //                              "nPrim="<<nTPCPrim<<              // number of primaries
4779 //                              "nSec="<<nTPCSec<<                // number of secondaries
4780 //                              "sigPrim="<<tpcSignalTotPrim<<    // total dEdx in primaries
4781 //                              "sigSec="<<tpcSignalTotSec<<      // total dEdx in secondaries
4782 //                              "v.="<<&vertex<<                  // KF vertex
4783 //                              "v2.="<<&vertex2<<                // KF vertex all tracks
4784 //                              "z0="<<dca0[1]<<
4785 //                              "z1="<<dca1[1]<<
4786 //                              "rphi0="<<dca0[0]<<
4787 //                              "rphi1="<<dca1[0]<<
4788 //                              "radius="<<radius<<
4789 //                              "vx="<<vx<<
4790 //                              "vy="<<vy<<
4791 //                              "vz="<<vz<<
4792 //                              "errX="<<errX<<
4793 //                              "errY="<<errY<<
4794 //                              "errZ="<<errZ<<
4795 //                              "err2D="<<err2D<<
4796 //                              "err3D="<<err3D<<         
4797 //                              "dvertex="<<dvertex<< 
4798 //                              "\n";
4799 //                      }
4800 //              
4801                         fHistograms->FillHistogram("ESD_HadIntQual_nTracks", ntracks);
4802                         fHistograms->FillHistogram("ESD_HadIntQual_ntracksTPC", ntracksTPC);
4803                 }
4804         }
4805
4806         Int_t verticesRejectedInLoop = 0;
4807         for (Int_t ll = 0; ll < nVertices; ll++){
4808                 if (kVertexArr[ll][1] == 0) continue;
4809                 for (Int_t kk = 0; kk < nVertices; kk++){
4810                         Int_t trackUsedTwice = 0;
4811                         Int_t numberOfTracksUsedTwice = 0;
4812                         Int_t trackNumberTrackUsedTwice[10];
4813                         if (ll == kk) continue;
4814                         if (kVertexArr[kk][1] == 0 || kVertexArr[ll][1] == 0 ) continue;
4815 //                      cout << "Vertex " << ll << " nTracks " << kVertexArr[ll][0] << endl;
4816                         for (Int_t ii = 2  ; ii < kVertexArr[ll][0]+2; ii++){
4817 //                              cout << "\t Track " << kVertexArr[ll][ii] << endl;
4818 //                              cout << "\t Vertex " << kk << " nTracks " << kVertexArr[kk][0] << endl;
4819                                 for (Int_t jj = 2 ; jj < kVertexArr[kk][0]+2; jj++){
4820 //                                      cout << "\t\t Track " << kVertexArr[kk][jj] << endl;
4821                                         if (kVertexArr[ll][ii] == kVertexArr[kk][jj]){
4822 //                                              cout << "\t\t track used twice" << endl;
4823                                                 trackUsedTwice = 1;
4824                                                 trackNumberTrackUsedTwice[numberOfTracksUsedTwice] = kVertexArr[kk][jj];
4825                                                 numberOfTracksUsedTwice++;
4826                                                 
4827                                         }
4828                                 }
4829                         }
4830                         if (trackUsedTwice){
4831                                 if (vertexStored[ll].GetChi2()/vertexStored[ll].GetNDF() < vertexStored[kk].GetChi2()/vertexStored[kk].GetNDF()){
4832 //                                      cout << "\t Vertex " <<  kk <<"\t track used twice: " << numberOfTracksUsedTwice << "\t tracks left for vertex: " << kVertexArr[kk][0]-numberOfTracksUsedTwice <<  endl;
4833                                         if ( kVertexArr[kk][0]-numberOfTracksUsedTwice < 2){
4834                                                 kVertexArr[kk][1] = 0;
4835                                         } else {
4836                                                 for (Int_t count = 0; count < numberOfTracksUsedTwice; count++){
4837                                                         for (Int_t hh = 2; hh < kVertexArr[kk][0]+2; hh++){
4838                                                                 if (kVertexArr[kk][hh] == trackNumberTrackUsedTwice[count]){
4839 //                                                                      cout << "\t track to be removed " << trackNumberTrackUsedTwice[count] << " from position "<< hh <<endl;
4840                                                                         for (Int_t ii = kVertexArr[kk][0]+2-hh; ii > 1; ii--){
4841                                                                                 Int_t pos = kVertexArr[kk][0]+2-ii;
4842                                                                                 kVertexArr[kk][pos] = kVertexArr[kk][pos+1];
4843                                                                         }
4844                                                                         kVertexArr[kk][0] -=1;
4845                                                                 }
4846                                                         }
4847                                                         
4848                                                         AliESDtrack *track0=event->GetTrack(kVertexArr[kk][2]);
4849                                                         AliKFParticle part0;
4850                                                         if (!track0->IsOn(AliVTrack::kITSrefit)){ 
4851                                                                 part0=AliKFParticle(*track0->GetInnerParam(),211);  //assuming pion mass
4852                                                         } else {
4853                                                                 part0=AliKFParticle(*track0,211);  //assuming pion mass
4854                                                         }
4855                                                 
4856                                                         if (track0->Charge()*part0.Q()<0) part0.Q()*=-1;  // change sign if opposite
4857
4858                                                         AliKFVertex vertex;                                             
4859                                                         vertex+=part0;
4860                                                         
4861 //                                                      cout << "\t Vertex " << kk << " nTracks " << kVertexArr[kk][0] << endl;
4862                                                         for (Int_t ii = 2  ; ii < kVertexArr[kk][0]+2; ii++){
4863 //                                                              cout << "\t \t Track " << kVertexArr[kk][ii] << endl;
4864                                                                 if (ii > 2){
4865                                                                         AliESDtrack *track1=event->GetTrack(kVertexArr[kk][ii]);
4866                                                                         AliKFParticle part1;
4867                                                                         if (!track1->IsOn(AliVTrack::kITSrefit)){ 
4868                                                                                 part1=AliKFParticle(*track1->GetInnerParam(),211);  //assuming pion mass
4869                                                                         } else {
4870                                                                                 part1=AliKFParticle(*track1,211);  //assuming pion mass
4871                                                                         }
4872                                                                 
4873                                                                         if (track1->Charge()*part1.Q()<0) part1.Q()*=-1;  // change sign if opposite
4874                                                                         vertex+=part1;
4875                                                                 }
4876                                                         }
4877                                                         vertexStored[kk]=vertex;
4878 //                                                      cout << "\t removing tracks from vtx " << kk << "new chi2/ndf: " << vertexStored[kk].GetChi2()/vertexStored[kk].GetNDF() <<endl;
4879 //                                                      cout << "Vertex " << kk << " nTracks " << kVertexArr[kk][0] << endl;
4880 //                                                              for (Int_t ii = 2  ; ii < kVertexArr[kk][0]+2; ii++){
4881 //                                                              cout << "\t Track " << kVertexArr[kk][ii] << endl;
4882 //                                                      }
4883 //                                                      Double_t errX=vertex.GetErrX();
4884 //                                                      Double_t errY=vertex.GetErrY();
4885 //                                                      Double_t errZ=vertex.GetErrZ();
4886 //                                                      Double_t vx = vertex.GetX();
4887 //                                                      Double_t vy = vertex.GetY();
4888 //                                                      Double_t vz = vertex.GetZ();
4889 //                                                      Double_t vr = sqrt((Double_t)(vx*vx + vy*vy));
4890 //                                                      Double_t vphi = TMath::ATan2(vy, vx);
4891 //                                                      cout << "\t Quality \t errX: " <<errX << "\t errY: " << errY << "\t errZ: " << errZ << "\t Chi2/ndf: " << vertex.GetChi2()/vertex.GetNDF() << endl;
4892 //                                                      cout << "\t Position \t x: " <<  vx << "\t y: " << vy << "\t z: " << vz <<"\t r: " << vr  << "\t phi: " << vphi << endl; 
4893                                                 }
4894                                                 kVertexArr[kk][1] = 1;
4895                                                 verticesRejectedInLoop--;
4896                                         }
4897                                         
4898 //                                      cout << "\t rejected vertex " << kk << endl;
4899                                 } else {
4900                                         kVertexArr[ll][1] = 0;
4901 //                                      cout << "\t Vertex " <<  ll  << "\t track used twice: " << numberOfTracksUsedTwice << "\t tracks left for vertex: " << kVertexArr[ll][0]-numberOfTracksUsedTwice <<  endl;
4902                                         if ( kVertexArr[ll][0]-numberOfTracksUsedTwice < 2){
4903                                                 kVertexArr[ll][1] = 0;
4904                                         } else {
4905                                                 for (Int_t count = 0; count < numberOfTracksUsedTwice; count++){
4906                                                         for (Int_t hh = 2; hh < kVertexArr[ll][0]+2; hh++){
4907                                                                 if (kVertexArr[ll][hh] == trackNumberTrackUsedTwice[count]){
4908 //                                                                      cout << "\t track to be removed " << trackNumberTrackUsedTwice[count] << " from position "<< hh <<endl;
4909                                                                         for (Int_t ii = kVertexArr[ll][0]+2-hh; ii > 1; ii--){
4910                                                                                 Int_t pos = kVertexArr[ll][0]+2-ii;
4911                                                                                 kVertexArr[ll][pos] = kVertexArr[ll][pos+1];
4912                                                                         }
4913                                                                         kVertexArr[ll][0] -=1;
4914                                                                 }
4915                                                         }
4916                                                         AliESDtrack *track0=event->GetTrack(kVertexArr[ll][2]);
4917                                                         AliKFParticle part0(*track0,211);  //assuming pion mass
4918                                                         if (track0->Charge()*part0.Q()<0) part0.Q()*=-1;  // change sign if opposite
4919
4920                                                         AliKFVertex vertex;                                             
4921                                                         vertex+=part0;
4922                                                         
4923 //                                                      cout << "\t Vertex " << ll << " nTracks " << kVertexArr[ll][0] << endl;
4924                                                         for (Int_t ii = 2  ; ii < kVertexArr[ll][0]+2; ii++){
4925 //                                                              cout << "\t \t Track " << kVertexArr[ll][ii] << endl;
4926                                                                 if (ii > 2){
4927                                                                         AliESDtrack *track1=event->GetTrack(kVertexArr[ll][ii]);
4928                                                                         AliKFParticle part1(*track1,211); // assuming pion mass
4929                                                                         if (track1->Charge()*part1.Q()<0) part1.Q()*=-1;  // change sign if opposite
4930                                                                         vertex+=part1;
4931                                                                 }
4932                                                         }
4933                                                         vertexStored[ll]=vertex;
4934 //                                                      cout << "\t removing tracks from vtx " << ll << "new chi2/ndf: " << vertexStored[ll].GetChi2()/vertexStored[ll].GetNDF() <<endl;
4935 //                                                      cout << "Vertex " << ll << " nTracks " << kVertexArr[ll][0] << endl;
4936 //                                                              for (Int_t ii = 2  ; ii < kVertexArr[ll][0]+2; ii++){
4937 //                                                              cout << "\t Track " << kVertexArr[ll][ii] << endl;
4938 //                                                      }
4939 //                                                      Double_t errX=vertex.GetErrX();
4940 //                                                      Double_t errY=vertex.GetErrY();
4941 //                                                      Double_t errZ=vertex.GetErrZ();
4942 //                                                      Double_t vx = vertex.GetX();
4943 //                                                      Double_t vy = vertex.GetY();
4944 //                                                      Double_t vz = vertex.GetZ();
4945 //                                                      Double_t vr = sqrt((Double_t)(vx*vx + vy*vy));
4946 //                                                      Double_t vphi = TMath::ATan2(vy, vx);
4947 //                                                      cout << "\t Quality \t errX: " <<errX << "\t errY: " << errY << "\t errZ: " << errZ << "\t Chi2/ndf: " << vertex.GetChi2()/vertex.GetNDF() << endl;
4948 //                                                      cout << "\t Position \t x: " <<  vx << "\t y: " << vy << "\t z: " << vz <<"\t r: " << vr  << "\t phi: " << vphi << endl; 
4949                                                 }
4950                                                 kVertexArr[ll][1] = 1;
4951                                                 verticesRejectedInLoop--;
4952                                         }
4953                                 }
4954                                 verticesRejectedInLoop++;
4955                         }
4956                 }
4957         }
4958 //      if (nVertices > 0){
4959 //              cout << "Selected Vertices___________________________________" << endl;
4960 //      }
4961         for (Int_t fin = 0; fin < nVertices; fin++){
4962                 if (kVertexArr[fin][1] == 0) continue;
4963                 Double_t errX=vertexStored[fin].GetErrX();
4964                 Double_t errY=vertexStored[fin].GetErrY();
4965                 Double_t errZ=vertexStored[fin].GetErrZ();
4966                 Double_t err3D=TMath::Sqrt(errX*errX+errY*errY+errZ*errZ/10.);  
4967                 Double_t err2D=TMath::Sqrt(errX*errX+errY*errY);  
4968                 Double_t vx = vertexStored[fin].GetX();
4969                 Double_t vy = vertexStored[fin].GetY();
4970                 Double_t vz = vertexStored[fin].GetZ();
4971                 Double_t vr = sqrt((Double_t)(vx*vx + vy*vy));
4972                 Double_t vphi = TMath::ATan2(vy, vx);
4973 //              cout << "Vertex " << fin << " nTracks " << kVertexArr[fin][0] << endl;
4974                 for (Int_t ii = 2  ; ii < kVertexArr[fin][0]+2; ii++){
4975 //                      cout << "\t Track " << kVertexArr[fin][ii] << endl;
4976                 }
4977 //              cout << "\t Quality \t errX: " <<errX << "\t errY: " << errY << "\t errZ: " << errZ << "\t Chi2/ndf: " << vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF() << endl;
4978 //              cout << "\t Position \t x: " <<  vx << "\t y: " << vy << "\t z: " << vz <<"\t r: " << vr  << "\t phi:" << vphi << endl;
4979
4980                 fHistograms->FillHistogram("ESD_HadIntQual_nTracksSecVtx", kVertexArr[fin][0]);
4981                 fHistograms->FillHistogram("ESD_HadIntQual_ErrX", errX);
4982 //                      fHistograms->FillHistogram("ESD_HadIntQual_NormDCA", vNDCA);
4983                 fHistograms->FillHistogram("ESD_HadIntQual_ErrY", errY);
4984                 fHistograms->FillHistogram("ESD_HadIntQual_ErrZ", errZ);
4985                 fHistograms->FillHistogram("ESD_HadIntQual_Err2D", err2D);
4986                 fHistograms->FillHistogram("ESD_HadIntQual_Err3D", err3D);
4987                 fHistograms->FillHistogram("ESD_HadIntQual_Chi2PerDOF", vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF());
4988                 Double_t chi2PerDOF = vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF();
4989                 if ( chi2PerDOF< fMaxChi2HadInt  && err2D < fMaxErr2DHadInt ){
4990                         fHistograms->FillHistogram("ESD_HadIntMap_ZR", vz,vr);
4991                         fHistograms->FillHistogram("ESD_HadIntMap_XY", vx,vy);
4992                         
4993                         fHistograms->FillHistogram("ESD_HadIntMap_ZPhi", vz,vphi);
4994                         fHistograms->FillHistogram("ESD_HadIntMap_RPhi", vr,vphi);
4995                         Double_t rFMD=25;
4996                         Double_t rITSTPCMin=45;
4997                         Double_t rITSTPCMax=80;
4998                 
4999                         if(vr<rFMD){
5000                                 fHistograms->FillHistogram("ESD_HadIntMap_FMD_ZPhi", vz,vphi);
5001                         }
5002                         if(vr>rFMD && vr<rITSTPCMin){
5003                                 fHistograms->FillHistogram("ESD_HadIntMap_FMD2_ZPhi", vz,vphi);
5004                         }
5005
5006                         if(vr>rITSTPCMin && vr<rITSTPCMax){
5007                                 fHistograms->FillHistogram("ESD_HadIntMap_ITSTPC_ZPhi", vz,vphi);
5008                         }
5009                         Double_t rHotZoneMin = 5.7;
5010                         Double_t rHotZoneMax = 50.;
5011                         Double_t zHotZoneMin = 45.;
5012                         Double_t zHotZoneMax = 75.;
5013                         
5014                         if (vr>rHotZoneMin && vr < rHotZoneMax){
5015                                 fHistograms->FillHistogram("ESD_HadIntMap_HotZone_ZPhi", vz,vphi);
5016                                 if (vz < zHotZoneMax && vz > zHotZoneMin){
5017                                         fHistograms->FillHistogram("ESD_HadIntMap_HotZone_XY", vx,vy);
5018                                 }
5019                         }
5020                         
5021                         Double_t zBeamPipeInner = 30.;
5022                         Double_t zOuterParts = 90.;
5023                         if (vz < zBeamPipeInner && vz > - zBeamPipeInner) {
5024                                 fHistograms->FillHistogram("ESD_HadIntMapInnerBeampipe_XY", vx,vy);
5025                                 fHistograms->FillHistogram("ESD_HadIntMapInnerParts_XY", vx,vy);
5026                                 if (vr < rFMD ){
5027                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_ErrX", errX);
5028                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_ErrY", errY);
5029                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_ErrZ", errZ);
5030                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_Err2D", err2D);
5031                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_Err3D", err3D);
5032                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallR_Chi2PerDOF", vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF());
5033                                 }
5034                         }
5035                         
5036                         if (vz > zOuterParts )  fHistograms->FillHistogram("ESD_HadIntMapPosZOuterParts_XY", vx,vy);
5037                         if (vz > zBeamPipeInner && vz < zOuterParts ) {
5038                                 fHistograms->FillHistogram("ESD_HadIntMapPosZFMD_XY", vx,vy);
5039                                 if (vr < rFMD ){
5040                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_ErrX", errX);
5041                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_ErrY", errY);
5042                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_ErrZ", errZ);
5043                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_Err2D", err2D);
5044                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_Err3D", err3D);
5045                                         fHistograms->FillHistogram("ESD_HadIntQualAftCutsSmallROut_Chi2PerDOF", vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF());
5046                                 }
5047                         }
5048                         if (vz < -zBeamPipeInner && vz > -zOuterParts )         fHistograms->FillHistogram("ESD_HadIntMapNegZFMD_XY", vx,vy);
5049                         
5050                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_ErrX", errX);
5051                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_ErrY", errY);
5052                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_ErrZ", errZ);
5053                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_Err2D", err2D);
5054                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_Err3D", err3D);
5055                         fHistograms->FillHistogram("ESD_HadIntQualAftCuts_Chi2PerDOF", vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF());
5056
5057                         if (kVertexArr[fin][0]>2 ){
5058                                 fHistograms->FillHistogram("ESD_HadIntMap3_ZR", vz,vr);
5059                                 fHistograms->FillHistogram("ESD_HadIntMap3_XY", vx,vy);
5060                         
5061                                 fHistograms->FillHistogram("ESD_HadIntMap3_ZPhi", vz,vphi);
5062                                 fHistograms->FillHistogram("ESD_HadIntMap3_RPhi", vr,vphi);
5063                         
5064                                 if(vr<rFMD){
5065                                         fHistograms->FillHistogram("ESD_HadIntMap3_FMD_ZPhi", vz,vphi);
5066                                 }
5067                                 if(vr>rFMD && vr<rITSTPCMin){
5068                                         fHistograms->FillHistogram("ESD_HadIntMap3_FMD2_ZPhi", vz,vphi);
5069                                 }
5070
5071                                 if (vr>rITSTPCMin && vr<rITSTPCMax){
5072                                         fHistograms->FillHistogram("ESD_HadIntMap3_ITSTPC_ZPhi", vz,vphi);
5073                                 }
5074                                 if (vz < zBeamPipeInner && vz > - zBeamPipeInner) {
5075                                         fHistograms->FillHistogram("ESD_HadIntMap3InnerBeampipe_XY", vx,vy);
5076                                         fHistograms->FillHistogram("ESD_HadIntMap3InnerParts_XY", vx,vy);
5077                                 }
5078                                 if (vz > zOuterParts )  fHistograms->FillHistogram("ESD_HadIntMap3PosZOuterParts_XY", vx,vy);
5079                                 if (vz > zBeamPipeInner && vz < zOuterParts ) {
5080                                         fHistograms->FillHistogram("ESD_HadIntMap3PosZFMD_XY", vx,vy);
5081                                 }
5082                                 if (vz < -zBeamPipeInner && vz > -zOuterParts )         fHistograms->FillHistogram("ESD_HadIntMap3NegZFMD_XY", vx,vy);
5083                         
5084                                 if (vr>rHotZoneMin && vr < rHotZoneMax){
5085                                         fHistograms->FillHistogram("ESD_HadIntMap3_HotZone_ZPhi", vz,vphi);
5086                                         if (vz < zHotZoneMax && vz > zHotZoneMin){
5087                                                 fHistograms->FillHistogram("ESD_HadIntMap3_HotZone_XY", vx,vy);
5088                                         }
5089                                 }       
5090                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_ErrX", errX);
5091                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_ErrY", errY);
5092                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_ErrZ", errZ);
5093                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_Err2D", err2D);
5094                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_Err3D", err3D);
5095                                 fHistograms->FillHistogram("ESD_HadIntQual3AftCuts_Chi2PerDOF", vertexStored[fin].GetChi2()/vertexStored[fin].GetNDF());
5096                         }
5097                         nVerticesPassed++;
5098                 }
5099         }
5100         
5101 //      if (nVertices > 0){
5102 //              cout << "number of total vertices: "<< nVertices << endl;
5103 //              cout << "number of total vertices passing selection: "<< nVerticesPassed << endl;
5104 //              cout << "vertices rejected in loop: " << verticesRejectedInLoop << endl;
5105 //      }
5106         delete [] rejectTrack;
5107 }
5108
5109
5110 Bool_t AliAnalysisTaskGammaConversion::CheckLooper(Int_t index, AliESDEvent *event){
5111   //
5112   // check if given track is looper candidate
5113   // if looper return kTRUE
5114   // 
5115   Int_t ntracks=event->GetNumberOfTracks();
5116   Int_t index1=-1;
5117   const Double_t ktglCut=0.03;
5118   const Double_t kalphaCut=0.4;
5119   //
5120   AliESDtrack * track0 = event->GetTrack(index);
5121   AliESDtrack * track1P = 0;
5122   for (Int_t itrack1=0; itrack1<ntracks; itrack1++){
5123     if (itrack1==index) continue;
5124     AliESDtrack *track1=event->GetTrack(itrack1);
5125     if (!track1) continue;
5126     if (TMath::Abs(TMath::Abs(track1->GetTgl())-TMath::Abs(track0->GetTgl()))>ktglCut) continue;
5127     if (TMath::Abs(TMath::Abs(track1->GetAlpha())-TMath::Abs(track0->GetAlpha()))>kalphaCut) continue;
5128     index1=index;
5129     track1P=track1;
5130   }
5131   if (index1>=0){
5132     return kTRUE;
5133   }
5134   return kFALSE;
5135 }
5136
5137 Bool_t AliAnalysisTaskGammaConversion::CheckV0(Int_t index, AliESDEvent *event){
5138         //
5139         // check if given track is V0 candidata
5140         // if looper return kTRUE
5141         // 
5142         return kFALSE;
5143         Int_t ntracks=event->GetNumberOfTracks();
5144         Int_t index1=-1;
5145         const Double_t kSigmaMass=0.001;
5146         const Int_t kChi2Cut=10;
5147         //
5148         AliESDtrack * track0 = event->GetTrack(index);
5149         AliExternalTrackParam pL(*track0);
5150         AliKFParticle part0El(*track0, 11);  //assuming  mass e
5151         AliKFParticle part0Pi(*track0, 211);  //assuming  mass pion
5152         AliKFParticle part0P(*track0, 2212);  //assuming  mass proton
5153         if (track0->Charge()*part0El.Q()<0) {
5154                 part0El.Q()*=-1;  // change sign if opposite
5155                 part0Pi.Q()*=-1;  // change sign if opposite
5156                 part0P.Q()*=-1;   // change sign if opposite
5157         }
5158         Bool_t isGamma=0;
5159         Bool_t isK0=0;
5160         Bool_t isLambda=0;
5161         Bool_t isLambdaBar=0;
5162         
5163         for (Int_t itrack1=0; itrack1<ntracks; itrack1++){
5164                 if (itrack1==index) continue;
5165                 AliESDtrack *track1=event->GetTrack(itrack1);
5166                 if (!track1) continue;
5167                 if (track1->Charge()*track0->Charge()>0) continue;
5168                 AliKFParticle part1El(*track1, 11);  //assuming  mass e
5169                 AliKFParticle part1Pi(*track1, 211);  //assuming  mass pion
5170                 AliKFParticle part1P(*track1, 2212);  //assuming  mass proton
5171                 if (track1->Charge()*part1El.Q()<0) {
5172                         part1El.Q()*=-1;  // change sign if opposite
5173                         part1Pi.Q()*=-1;  // change sign if opposite
5174                         part1P.Q()*=-1;   // change sign if opposite
5175                 }
5176                 //
5177                 AliKFVertex vertexG;  // gamma conversion candidate
5178                 vertexG+=part0El;
5179                 vertexG+=part1El;
5180                 AliKFVertex vertexGC;  // gamma conversion candidate
5181                 vertexGC+=part0El;
5182                 vertexGC+=part1El;
5183                 vertexGC.SetMassConstraint(0,kSigmaMass);
5184                 AliKFVertex vertexK0;  // K0s candidate
5185                 vertexK0+=part0Pi;
5186                 vertexK0+=part1Pi;
5187                 AliKFVertex vertexK0C;  // K0s candidate
5188                 vertexK0C+=part0Pi;
5189                 vertexK0C+=part1Pi;
5190                 vertexK0C.SetMassConstraint(0.497614,kSigmaMass);
5191                 AliKFVertex vertexLambda;  // Lambda candidate
5192                 vertexLambda+=part0Pi;
5193                 vertexLambda+=part1P;
5194                 AliKFVertex vertexLambdaC;  // Lambda candidate
5195                 vertexLambdaC+=part0Pi;
5196                 vertexLambdaC+=part1Pi;
5197                 vertexLambdaC.SetMassConstraint(1.115683,kSigmaMass);
5198                 AliKFVertex vertexLambdaB;  // Lambda candidate
5199                 vertexLambdaB+=part0Pi;
5200                 vertexLambdaB+=part1P;
5201                 AliKFVertex vertexLambdaBC;  // LambdaBar candidate
5202                 vertexLambdaBC+=part0Pi;
5203                 vertexLambdaBC+=part1Pi;
5204                 vertexLambdaBC.SetMassConstraint(1.115683,kSigmaMass);
5205                 
5206                 if (vertexGC.GetChi2()<kChi2Cut && vertexG.GetMass()<0.06)      isGamma=kTRUE;
5207                 if (vertexK0C.GetChi2()<kChi2Cut&&TMath::Abs(vertexK0.GetMass()-0.5)<0.06)  isK0=kTRUE;
5208                 if (vertexLambdaC.GetChi2()<kChi2Cut&&TMath::Abs(vertexLambda.GetMass()-1.1)<0.06)  isLambda=kTRUE;
5209                 if (vertexLambdaBC.GetChi2()<kChi2Cut&&TMath::Abs(vertexLambdaB.GetMass()-1.1)<0.06)  isLambdaBar=kTRUE;
5210                 if (isGamma||isK0||isLambda||isLambdaBar) {
5211                         index1=index;
5212                         break;
5213                 }
5214         }
5215         if (index1>0) return kTRUE;
5216         return kFALSE;
5217 }
5218
5219
5220 void AliAnalysisTaskGammaConversion::ProcessGammaElectronsForChicAnalysis(){
5221         // see header file for documantation
5222         
5223         fESDEvent = fV0Reader->GetESDEvent();
5224         
5225         
5226         TClonesArray * vESDeNegTemp = new TClonesArray("AliESDtrack",0);
5227         TClonesArray * vESDePosTemp = new TClonesArray("AliESDtrack",0);
5228         TClonesArray * vESDxNegTemp = new TClonesArray("AliESDtrack",0);
5229         TClonesArray * vESDxPosTemp = new TClonesArray("AliESDtrack",0);
5230         TClonesArray * vESDeNegNoJPsi = new TClonesArray("AliESDtrack",0);
5231         TClonesArray * vESDePosNoJPsi = new TClonesArray("AliESDtrack",0);
5232         
5233         /*
5234                 vector <AliESDtrack*> vESDeNegTemp(0);
5235                 vector <AliESDtrack*> vESDePosTemp(0);
5236                 vector <AliESDtrack*> vESDxNegTemp(0);
5237                 vector <AliESDtrack*> vESDxPosTemp(0);
5238                 vector <AliESDtrack*> vESDeNegNoJPsi(0);
5239                 vector <AliESDtrack*> vESDePosNoJPsi(0); 
5240         */
5241         
5242         
5243         fHistograms->FillTable("Table_Electrons",0);//Count number of Events
5244         
5245         for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
5246                 AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
5247                 
5248                 if(!curTrack){
5249                         //print warning here
5250                         continue;
5251                 }
5252                 
5253                 double p[3];if(!curTrack->GetConstrainedPxPyPz(p))continue;
5254                 double r[3];curTrack->GetConstrainedXYZ(r);
5255                 
5256                 TVector3 rXYZ(r);
5257                 
5258                 fHistograms->FillTable("Table_Electrons",4);//Count number of ESD tracks
5259                 
5260                 Bool_t flagKink                  =      kTRUE;
5261                 Bool_t flagTPCrefit      =      kTRUE;
5262                 Bool_t flagTRDrefit      =      kTRUE;
5263                 Bool_t flagITSrefit      =      kTRUE;
5264                 Bool_t flagTRDout                =      kTRUE;
5265                 Bool_t flagVertex                =      kTRUE;
5266                 
5267                 
5268                 //Cuts ---------------------------------------------------------------
5269                 
5270                 if(curTrack->GetKinkIndex(0) > 0){
5271                         fHistograms->FillHistogram("Table_Electrons",5);//Count kink
5272                         flagKink = kFALSE;
5273                 }
5274                 
5275                 ULong_t trkStatus = curTrack->GetStatus();
5276                 
5277                 ULong_t tpcRefit = (trkStatus & AliESDtrack::kTPCrefit);
5278                 
5279                 if(!tpcRefit){
5280                         fHistograms->FillHistogram("Table_Electrons",9);//Count not TPCrefit
5281                         flagTPCrefit = kFALSE;
5282                 }
5283                 
5284                 ULong_t itsRefit = (trkStatus & AliESDtrack::kITSrefit);
5285                 if(!itsRefit){
5286                         fHistograms->FillHistogram("Table_Electrons",10);//Count not ITSrefit
5287                         flagITSrefit = kFALSE;
5288                 }
5289                 
5290                 ULong_t trdRefit = (trkStatus & AliESDtrack::kTRDrefit);
5291                 
5292                 if(!trdRefit){
5293                         fHistograms->FillHistogram("Table_Electrons",8); //Count not TRDrefit
5294                         flagTRDrefit = kFALSE;
5295                 }
5296                 
5297                 ULong_t trdOut = (trkStatus & AliESDtrack::kTRDout);
5298                 
5299                 if(!trdOut) {
5300                         fHistograms->FillHistogram("Table_Electrons",7); //Count not TRDout
5301                         flagTRDout = kFALSE;
5302                 }
5303                 
5304                 double nsigmaToVxt = GetSigmaToVertex(curTrack);
5305                 
5306                 if(nsigmaToVxt > 3){
5307                         fHistograms->FillHistogram("Table_Electrons",6); //Count Tracks with number of sigmas > 3
5308                         flagVertex = kFALSE;
5309                 }
5310                 
5311                 if(! (flagKink && flagTPCrefit && flagITSrefit && flagTRDrefit && flagTRDout && flagVertex ) ) continue;
5312                 fHistograms->FillHistogram("Table_Electrons",11);//Count Tracks passed Cuts
5313                 
5314                 
5315                 Stat_t pid, weight;
5316                 GetPID(curTrack, pid, weight);
5317                 
5318                 if(pid!=0){
5319                         fHistograms->FillHistogram("Table_Electrons",12); //Count Tracks with pid != 0
5320                 }
5321                 
5322                 if(pid == 0){
5323                         fHistograms->FillHistogram("Table_Electrons",13); //Count Tracks with pid != 0
5324                 }
5325                 
5326                 
5327                 
5328                 
5329                 
5330                 
5331                 TLorentzVector curElec;
5332                 curElec.SetXYZM(p[0],p[1],p[2],fElectronMass);
5333                 
5334                 
5335                 if(fDoMCTruth){         
5336                         Int_t labelMC = TMath::Abs(curTrack->GetLabel());
5337                         TParticle* curParticle = fStack->Particle(labelMC);
5338                         if(curTrack->GetSign() > 0){
5339                                 if( pid == 0){
5340                                         fHistograms->FillHistogram("MC_ElectronPosNegPt",curParticle->Pt());
5341                                         fHistograms->FillHistogram("MC_ElectronPosNegEta",curParticle->Eta());
5342                                 } else {
5343                                         fHistograms->FillHistogram("MC_ElectronPosNegPt",curParticle->Pt());
5344                                         fHistograms->FillHistogram("MC_ElectronPosNegEta",curParticle->Eta());
5345                                 }
5346                         }
5347                 }
5348                 
5349                 
5350                 if(curTrack->GetSign() > 0){
5351                         
5352                         //               vESDxPosTemp.push_back(curTrack);
5353                         new((*vESDxPosTemp)[vESDxPosTemp->GetEntriesFast()])    AliESDtrack(*curTrack);
5354                         
5355                         if( pid == 0){
5356                                 fHistograms->FillHistogram("ESD_ElectronPosNegPt",curElec.Pt());
5357                                 fHistograms->FillHistogram("ESD_ElectronPosPt",curElec.Pt());
5358                                 //      fHistograms->FillHistogram("MC_ElectronPosNegPt",curParticle->Pt());
5359                                 fHistograms->FillHistogram("ESD_ElectronPosNegEta",curElec.Eta());
5360                                 //      fHistograms->FillHistogram("MC_ElectronPosNegEta",curParticle->Eta());
5361                                 //      vESDePosTemp.push_back(curTrack);
5362                                 new((*vESDePosTemp)[vESDePosTemp->GetEntriesFast()])    AliESDtrack(*curTrack);
5363                         }
5364                         
5365                 } else {
5366
5367                         new((*vESDxNegTemp)[vESDxNegTemp->GetEntriesFast()])    AliESDtrack(*curTrack);
5368                         
5369                         if( pid == 0){
5370                                         
5371                                 fHistograms->FillHistogram("ESD_ElectronPosNegPt",curElec.Pt());
5372                                 fHistograms->FillHistogram("ESD_ElectronNegPt",curElec.Pt());
5373                                 fHistograms->FillHistogram("ESD_ElectronPosNegEta",curElec.Eta());
5374                                 new((*vESDeNegTemp)[vESDeNegTemp->GetEntriesFast()])    AliESDtrack(*curTrack);
5375                                         
5376                         }
5377                         
5378                 }
5379                 
5380         }
5381         
5382         
5383         Bool_t ePosJPsi = kFALSE;
5384         Bool_t eNegJPsi = kFALSE;               
5385         Bool_t ePosPi0  = kFALSE;
5386         Bool_t eNegPi0  = kFALSE;
5387         
5388         UInt_t iePosJPsi=0,ieNegJPsi=0,iePosPi0=0,ieNegPi0=0;
5389         
5390         for(Int_t iNeg=0; iNeg < vESDeNegTemp->GetEntriesFast(); iNeg++){
5391                 if(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDeNegTemp->At(iNeg)))->GetLabel()))->GetPdgCode() == 11)
5392                 if(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDeNegTemp->At(iNeg)))->GetLabel()))->GetMother(0) > -1){
5393                 Int_t labelMother = fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDeNegTemp->At(iNeg)))->GetLabel()))->GetMother(0);
5394                         TParticle* partMother = fStack ->Particle(labelMother);
5395                         if (partMother->GetPdgCode() == 111){
5396                                 ieNegPi0 = iNeg;
5397                                 eNegPi0 = kTRUE;
5398                         }
5399                         if(partMother->GetPdgCode() == 443){ //Mother JPsi
5400                                 fHistograms->FillTable("Table_Electrons",14);
5401                                 ieNegJPsi = iNeg;
5402                                 eNegJPsi = kTRUE;
5403                         } else {        
5404                                 //              vESDeNegNoJPsi.push_back(vESDeNegTemp[iNeg]);
5405                                 new((*vESDeNegNoJPsi)[vESDeNegNoJPsi->GetEntriesFast()])        AliESDtrack(*(AliESDtrack*)(vESDeNegTemp->At(iNeg)));
5406                                 //              cout<<"ESD No Positivo JPsi "<<endl;
5407                         }
5408                 }
5409         }       
5410         
5411         for(Int_t iPos=0; iPos < vESDePosTemp->GetEntriesFast(); iPos++){
5412                 if(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDePosTemp->At(iPos)))->GetLabel()))->GetPdgCode() == -11)
5413                 if(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDePosTemp->At(iPos)))->GetLabel()))->GetMother(0) > -1){
5414                         Int_t labelMother = fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDePosTemp->At(iPos)))->GetLabel()))->GetMother(0);
5415                         TParticle* partMother = fStack ->Particle(labelMother);
5416                         if (partMother->GetPdgCode() == 111){
5417                                 iePosPi0 = iPos;
5418                                 ePosPi0 = kTRUE;
5419                         }
5420                         if(partMother->GetPdgCode() == 443){ //Mother JPsi
5421                                 fHistograms->FillTable("Table_Electrons",15);
5422                                 iePosJPsi = iPos;
5423                                 ePosJPsi = kTRUE;
5424                         }
5425                         else{
5426                                 //              vESDePosNoJPsi.push_back(vESDePosTemp[iPos]);
5427                                 new((*vESDePosNoJPsi)[vESDePosNoJPsi->GetEntriesFast()])        AliESDtrack(*(AliESDtrack*)(vESDePosTemp->At(iPos)));           
5428                                 //              cout<<"ESD No Negativo JPsi "<<endl;
5429                         }                               
5430                 }
5431         }
5432         
5433         if( eNegJPsi && ePosJPsi ){
5434                 TVector3 tempeNegV,tempePosV;
5435                 tempeNegV.SetXYZ(((AliESDtrack*)(vESDeNegTemp->At(ieNegJPsi)))->Px(),((AliESDtrack*)(vESDeNegTemp->At(ieNegJPsi)))->Py(),((AliESDtrack*)(vESDeNegTemp->At(ieNegJPsi)))->Pz());                  
5436                 tempePosV.SetXYZ(((AliESDtrack*)(vESDePosTemp->At(iePosJPsi)))->Px(),((AliESDtrack*)(vESDePosTemp->At(iePosJPsi)))->Py(),((AliESDtrack*)(vESDePosTemp->At(iePosJPsi)))->Pz());
5437                 fHistograms->FillTable("Table_Electrons",16);
5438                 fHistograms->FillHistogram("ESD_ElectronPosNegJPsiAngle",tempeNegV.Angle(tempePosV));   
5439                 fHistograms->FillHistogram("MC_ElectronPosNegJPsiAngle",GetMCOpeningAngle(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDeNegTemp->At(ieNegJPsi)))->GetLabel())),
5440                                                                                                 fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDePosTemp->At(iePosJPsi)))->GetLabel()))));      
5441         }
5442         
5443         if( eNegPi0 && ePosPi0 ){
5444                 TVector3 tempeNegV,tempePosV;
5445                 tempeNegV.SetXYZ(((AliESDtrack*)(vESDeNegTemp->At(ieNegPi0)))->Px(),((AliESDtrack*)(vESDeNegTemp->At(ieNegPi0)))->Py(),((AliESDtrack*)(vESDeNegTemp->At(ieNegPi0)))->Pz());
5446                 tempePosV.SetXYZ(((AliESDtrack*)(vESDePosTemp->At(iePosPi0)))->Px(),((AliESDtrack*)(vESDePosTemp->At(iePosPi0)))->Py(),((AliESDtrack*)(vESDePosTemp->At(iePosPi0)))->Pz());
5447                 fHistograms->FillHistogram("ESD_ElectronPosNegPi0Angle",tempeNegV.Angle(tempePosV));
5448                 fHistograms->FillHistogram("MC_ElectronPosNegPi0Angle",GetMCOpeningAngle(fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDeNegTemp->At(ieNegPi0)))->GetLabel())),
5449                                                                                          fStack->Particle(TMath::Abs(((AliESDtrack*)(vESDePosTemp->At(iePosPi0)))->GetLabel()))));       
5450         }
5451         
5452         
5453         FillAngle("ESD_eNegePosAngleBeforeCut",GetTLorentzVector(vESDeNegTemp),GetTLorentzVector(vESDePosTemp));
5454         
5455         CleanWithAngleCuts(*vESDeNegTemp,*vESDePosTemp,*fKFReconstructedGammasTClone);
5456         
5457         //      vector <TLorentzVector> vCurrentTLVeNeg = GetTLorentzVector(fCurrentEventNegElectron);
5458         //      vector <TLorentzVector> vCurrentTLVePos = GetTLorentzVector(fCurrentEventPosElectron);
5459         
5460         TClonesArray vCurrentTLVeNeg = GetTLorentzVector(fCurrentEventNegElectronTClone);
5461         TClonesArray vCurrentTLVePos = GetTLorentzVector(fCurrentEventPosElectronTClone);
5462         
5463         
5464         FillAngle("ESD_eNegePosAngleAfterCut",vCurrentTLVeNeg,vCurrentTLVePos);
5465         
5466         
5467         
5468         
5469         //FillAngle("ESD_eNegePosAngleAfterCut",CurrentTLVeNeg,CurrentTLVePos);
5470         
5471         
5472         FillElectronInvMass("ESD_InvMass_ePluseMinus",vCurrentTLVeNeg,vCurrentTLVePos);
5473         FillElectronInvMass("ESD_InvMass_xPlusxMinus",GetTLorentzVector(vESDxNegTemp),GetTLorentzVector(vESDxPosTemp));
5474         
5475         
5476         
5477         FillGammaElectronInvMass("ESD_InvMass_GammaePluseMinusChiC","ESD_InvMass_GammaePluseMinusChiCDiff",*fKFReconstructedGammasCutTClone,vCurrentTLVeNeg,vCurrentTLVePos);
5478         
5479         FillGammaElectronInvMass("ESD_InvMass_GammaePluseMinusPi0","ESD_InvMass_GammaePluseMinusPi0Diff",
5480                                  *fKFReconstructedGammasCutTClone,vCurrentTLVeNeg,vCurrentTLVePos);
5481         
5482         //BackGround
5483         
5484         //Like Sign e+e-
5485         ElectronBackground("ESD_ENegBackground",vCurrentTLVeNeg);
5486         ElectronBackground("ESD_EPosBackground",vCurrentTLVePos);
5487         ElectronBackground("ESD_EPosENegBackground",vCurrentTLVeNeg);
5488         ElectronBackground("ESD_EPosENegBackground",vCurrentTLVePos);
5489         
5490         //                              Like Sign e+e- no JPsi
5491         ElectronBackground("ESD_EPosENegNoJPsiBG",GetTLorentzVector(vESDeNegNoJPsi));
5492         ElectronBackground("ESD_EPosENegNoJPsiBG",GetTLorentzVector(vESDePosNoJPsi));
5493         
5494         //Mixed Event
5495         
5496         if( fCurrentEventPosElectronTClone->GetEntriesFast() > 0 && fCurrentEventNegElectronTClone->GetEntriesFast() > 0 && fKFReconstructedGammasCutTClone->GetEntriesFast() > 0 ){
5497                 FillGammaElectronInvMass("ESD_EPosENegGammaBackgroundMX","ESD_EPosENegGammaBackgroundMXDiff",
5498                                          *fKFReconstructedGammasCutTClone,*fPreviousEventTLVNegElectronTClone,*fPreviousEventTLVPosElectronTClone);
5499                 *fPreviousEventTLVNegElectronTClone = vCurrentTLVeNeg;
5500                 *fPreviousEventTLVPosElectronTClone = vCurrentTLVePos;
5501                 
5502         }
5503         
5504         /*
5505         //Photons P
5506         Double_t vtx[3];
5507         vtx[0]=0;vtx[1]=0;vtx[2]=0;
5508         for(UInt_t i=0;i<fKFReconstructedGammasChic.size();i++){
5509          
5510         //                      if(fMCGammaChicTempCut[i]->GetMother(0) < 0) continue;
5511          
5512          
5513          
5514         Int_t tempLabel = fStack->Particle(fMCGammaChicTempCut[i]->GetMother(0))->GetPdgCode();
5515         //                      cout<<" Label Pedro Gonzalez " <<tempLabel <<endl;
5516          
5517         //                      cout<<" Label Distance"<<fKFReconstructedGammasChic[i].GetDistanceFromVertex(vtx)<<endl;
5518          
5519         if( tempLabel == 10441 || tempLabel == 20443 || tempLabel == 445 )
5520          
5521         fHistograms->FillHistogram("ESD_PhotonsMomentum",fKFReconstructedGammasChic[i].GetMomentum());
5522          
5523          
5524         }
5525          
5526          
5527         */
5528
5529
5530         vESDeNegTemp->Delete();
5531         vESDePosTemp->Delete();
5532         vESDxNegTemp->Delete();
5533         vESDxPosTemp->Delete();
5534         vESDeNegNoJPsi->Delete();
5535         vESDePosNoJPsi->Delete();
5536
5537         delete vESDeNegTemp;
5538         delete vESDePosTemp;
5539         delete vESDxNegTemp;
5540         delete vESDxPosTemp;
5541         delete vESDeNegNoJPsi;
5542         delete vESDePosNoJPsi;  
5543 }
5544
5545 /*
5546         void AliAnalysisTaskGammaConversion::FillAngle(TString histoName,vector <TLorentzVector> tlVeNeg, vector <TLorentzVector> tlVePos){
5547         //see header file for documentation
5548         for( UInt_t iNeg=0; iNeg < tlVeNeg.size(); iNeg++){
5549         for (UInt_t iPos=0; iPos < tlVePos.size(); iPos++){
5550         fHistograms->FillHistogram(histoName.Data(),tlVeNeg[iNeg].Vect().Angle(tlVePos[iPos].Vect()));
5551         }
5552         }
5553         }
5554 */
5555 void AliAnalysisTaskGammaConversion::FillAngle(TString histoName,TClonesArray const tlVeNeg, TClonesArray const tlVePos){
5556         //see header file for documentation
5557         for( Int_t iNeg=0; iNeg < tlVeNeg.GetEntriesFast(); iNeg++){
5558                 for (Int_t iPos=0; iPos < tlVePos.GetEntriesFast(); iPos++){
5559                         fHistograms->FillHistogram(histoName.Data(),((TLorentzVector*)(tlVeNeg.At(iNeg)))->Vect().Angle(((TLorentzVector*)(tlVePos.At(iPos)))->Vect()));
5560                 }
5561         }
5562 }
5563
5564 void AliAnalysisTaskGammaConversion::FillElectronInvMass(TString histoName, TClonesArray const eNeg, TClonesArray const ePos){
5565         //see header file for documentation
5566         for( Int_t n=0; n < eNeg.GetEntriesFast(); n++){
5567                 TLorentzVector en = (*(TLorentzVector*)(eNeg.At(n)));
5568                 for (Int_t p=0; p < ePos.GetEntriesFast(); p++){
5569                         TLorentzVector ep = (*(TLorentzVector*)(ePos.At(p)));
5570                         TLorentzVector np = ep + en;
5571                         fHistograms->FillHistogram(histoName.Data(),np.M());
5572                 }
5573         }
5574 }
5575
5576 void AliAnalysisTaskGammaConversion::FillGammaElectronInvMass(TString histoMass,TString histoDiff,TClonesArray const fKFGammas,
5577                                                                                 TClonesArray const tlVeNeg,TClonesArray const tlVePos)
5578 {
5579         //see header file for documentation
5580         
5581         for( Int_t iNeg=0; iNeg < tlVeNeg.GetEntriesFast(); iNeg++ ){
5582                 
5583                 for (Int_t iPos=0; iPos < tlVePos.GetEntriesFast(); iPos++){
5584                         
5585                         TLorentzVector xy = *((TLorentzVector *)(tlVePos.At(iPos))) + *((TLorentzVector *)(tlVeNeg.At(iNeg)));
5586                         
5587                         for (Int_t iGam=0; iGam < fKFGammas.GetEntriesFast(); iGam++){
5588                                 
5589         //      AliKFParticle * gammaCandidate = &fKFGammas[iGam];
5590         AliKFParticle * gammaCandidate = (AliKFParticle *)(fKFGammas.At(iGam));
5591         TLorentzVector g;
5592                                 
5593         g.SetXYZM(gammaCandidate->GetPx(),gammaCandidate->GetPy(),gammaCandidate->GetPz(),fGammaMass);
5594         TLorentzVector xyg = xy + g;
5595         fHistograms->FillHistogram(histoMass.Data(),xyg.M());
5596         fHistograms->FillHistogram(histoDiff.Data(),(xyg.M()-xy.M()));
5597                         }
5598                 }
5599         }
5600         
5601 }
5602 void AliAnalysisTaskGammaConversion::ElectronBackground(TString hBg, TClonesArray e)
5603 {
5604         // see header file for documentation
5605         for(Int_t i=0; i < e.GetEntriesFast(); i++) {
5606                 for (Int_t j=i+1; j < e.GetEntriesFast(); j++) {
5607                         TLorentzVector ee = (*(TLorentzVector*)(e.At(i))) + (*(TLorentzVector*)(e.At(j)));
5608                         fHistograms->FillHistogram(hBg.Data(),ee.M());
5609                 }
5610         }
5611 }
5612
5613
5614 void AliAnalysisTaskGammaConversion::CleanWithAngleCuts(TClonesArray const negativeElectrons,
5615                                                         TClonesArray const positiveElectrons, 
5616                                                         TClonesArray const gammas){
5617         // see header file for documentation
5618         
5619         UInt_t  sizeN = negativeElectrons.GetEntriesFast();
5620         UInt_t  sizeP = positiveElectrons.GetEntriesFast();
5621         UInt_t  sizeG = gammas.GetEntriesFast();
5622         
5623         
5624         
5625         vector <Bool_t> xNegBand(sizeN);
5626         vector <Bool_t> xPosBand(sizeP);
5627         vector <Bool_t> gammaBand(sizeG);
5628         
5629         
5630         for(UInt_t iNeg=0; iNeg < sizeN; iNeg++) xNegBand[iNeg]=kTRUE;
5631         for(UInt_t iPos=0; iPos < sizeP; iPos++) xPosBand[iPos]=kTRUE;
5632         for(UInt_t iGam=0; iGam < sizeG; iGam++) gammaBand[iGam]=kTRUE;
5633         
5634         
5635         for(UInt_t iPos=0; iPos < sizeP; iPos++){
5636                 
5637                 Double_t aP[3]; 
5638                 ((AliESDtrack*)(positiveElectrons.At(iPos)))->GetConstrainedPxPyPz(aP); 
5639                 
5640                 TVector3 ePosV(aP[0],aP[1],aP[2]);
5641                 
5642                 for(UInt_t iNeg=0; iNeg < sizeN; iNeg++){
5643                         
5644                         Double_t aN[3]; 
5645                         ((AliESDtrack*)(negativeElectrons.At(iNeg)))->GetConstrainedPxPyPz(aN); 
5646                         TVector3 eNegV(aN[0],aN[1],aN[2]);
5647                         
5648                         if(ePosV.Angle(eNegV) < 0.05){ //e+e- from gamma
5649                                 xPosBand[iPos]=kFALSE;
5650                                 xNegBand[iNeg]=kFALSE;
5651                         }
5652                         
5653                         for(UInt_t iGam=0; iGam < sizeG; iGam++){
5654                                 AliKFParticle* gammaCandidate = (AliKFParticle*)gammas.At(iGam);
5655                                 TVector3 gammaCandidateVector(gammaCandidate->Px(),gammaCandidate->Py(),gammaCandidate->Pz());
5656                                 if(ePosV.Angle(gammaCandidateVector) < 0.05 || eNegV.Angle(gammaCandidateVector) < 0.05)
5657                                         gammaBand[iGam]=kFALSE;
5658                         }
5659                 }
5660         }
5661         
5662         for(UInt_t iPos=0; iPos < sizeP; iPos++){
5663                 if(xPosBand[iPos]){
5664                         new((*fCurrentEventPosElectronTClone)[fCurrentEventPosElectronTClone->GetEntriesFast()]) AliESDtrack((*(AliESDtrack*)(positiveElectrons.At(iPos))));
5665                         //                      fCurrentEventPosElectron.push_back(positiveElectrons[iPos]);
5666                 }
5667         }
5668         for(UInt_t iNeg=0;iNeg < sizeN; iNeg++){
5669                 if(xNegBand[iNeg]){
5670                         new((*fCurrentEventNegElectronTClone)[fCurrentEventNegElectronTClone->GetEntriesFast()]) AliESDtrack((*(AliESDtrack*)(negativeElectrons.At(iNeg))));
5671                         //                      fCurrentEventNegElectron.push_back(negativeElectrons[iNeg]);
5672                 }
5673         }
5674         for(UInt_t iGam=0; iGam < sizeG; iGam++){
5675                 if(gammaBand[iGam]){
5676                         new((*fKFReconstructedGammasCutTClone)[fKFReconstructedGammasCutTClone->GetEntriesFast()]) AliKFParticle((*(AliKFParticle*)(gammas.At(iGam))));
5677                         //fKFReconstructedGammasCut.push_back(*(AliKFParticle*)gammas->At(iGam));
5678                 }
5679         }
5680 }
5681
5682
5683 void    AliAnalysisTaskGammaConversion::GetPID(const AliESDtrack *track, Stat_t &pid, Stat_t &weight)
5684 {
5685         // see header file for documentation
5686         pid = -1;
5687         weight = -1;
5688         
5689         double wpart[5];
5690         double wpartbayes[5];
5691         
5692         //get probability of the diffenrent particle types
5693         track->GetESDpid(wpart);
5694         
5695         // Tentative particle type "concentrations"
5696         double c[5]={0.01, 0.01, 0.85, 0.10, 0.05};
5697         
5698         //Bayes' formula
5699         double rcc = 0.;
5700         for (int i = 0; i < 5; i++){
5701                 rcc+=(c[i] * wpart[i]);
5702         }
5703         
5704         
5705         
5706         for (int i=0; i<5; i++) {
5707                 if( rcc>0 || rcc<0){//Kenneth: not sure if the rcc<0 should be there, this is from fixing a coding violation where we are not allowed to say: rcc!=0 (RC19)     
5708                         wpartbayes[i] = c[i] * wpart[i] / rcc;
5709                 }
5710         }
5711         
5712         Float_t max=0.;
5713         int ipid=-1;
5714         //find most probable particle in ESD pid
5715         //0:Electron - 1:Muon - 2:Pion - 3:Kaon - 4:Proton
5716         for (int i = 0; i < 5; i++){
5717                         if (wpartbayes[i] > max){
5718                                 ipid = i;
5719                                 max = wpartbayes[i];
5720                         }
5721                 }
5722         
5723         pid = ipid;
5724         weight = max;
5725 }
5726
5727 double AliAnalysisTaskGammaConversion::GetSigmaToVertex(const AliESDtrack* t)
5728 {
5729         // Calculates the number of sigma to the vertex.
5730         
5731         Float_t b[2];
5732         Float_t bRes[2];
5733         Float_t bCov[3];
5734         t->GetImpactParameters(b,bCov);
5735         if (bCov[0]<=0 || bCov[2]<=0) {
5736                 AliDebug(1, "Estimated b resolution lower or equal zero!");
5737                 bCov[0]=0; bCov[2]=0;
5738         }
5739         bRes[0] = TMath::Sqrt(bCov[0]);
5740         bRes[1] = TMath::Sqrt(bCov[2]);
5741         
5742         // -----------------------------------
5743         // How to get to a n-sigma cut?
5744         //
5745         // The accumulated statistics from 0 to d is
5746         //
5747         // ->   Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
5748         // ->   1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
5749         //
5750         // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
5751         // Can this be expressed in a different way?
5752         
5753         if (bRes[0] == 0 || bRes[1] ==0)
5754                 return -1;
5755         
5756         double d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
5757         
5758         // stupid rounding problem screws up everything:
5759         // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
5760         if (TMath::Exp(-d * d / 2) < 1e-10)
5761                 return 1000;
5762         
5763         
5764         d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
5765         return d;
5766 }
5767
5768 //vector <TLorentzVector> AliAnalysisTaskGammaConversion::GetTLorentzVector(vector <AliESDtrack*> esdTrack){
5769 TClonesArray AliAnalysisTaskGammaConversion::GetTLorentzVector(TClonesArray *const esdTrack){
5770         //Return TLoresntz vector of track?
5771         //      vector <TLorentzVector> tlVtrack(0);
5772         TClonesArray array("TLorentzVector",0); 
5773         
5774         for(Int_t itrack=0; itrack < esdTrack->GetEntriesFast(); itrack++){
5775                 double p[3]; 
5776                 //esdTrack[itrack]->GetConstrainedPxPyPz(p);
5777                 ((AliESDtrack*)(esdTrack->At(itrack)))->GetConstrainedPxPyPz(p);
5778                 TLorentzVector currentTrack;
5779                 currentTrack.SetXYZM(p[0],p[1],p[2],fElectronMass);
5780                 new((array)[array.GetEntriesFast()])    TLorentzVector(currentTrack);
5781                 //              tlVtrack.push_back(currentTrack);
5782         }
5783         
5784         return array;
5785         
5786         //      return tlVtrack;
5787 }
5788 Int_t AliAnalysisTaskGammaConversion::GetProcessType(const AliMCEvent * mcEvt) {
5789
5790         // Determine if the event was generated with pythia or phojet and return the process type
5791
5792         // Check if mcEvt is fine
5793         if (!mcEvt) { // coverty does not allow this, the check is done elsewhere
5794                 AliFatal("NULL mc event");
5795                 return -1;
5796         } 
5797
5798         // Determine if it was a pythia or phojet header, and return the correct process type
5799         AliGenPythiaEventHeader * headPy        = 0;
5800         AliGenDPMjetEventHeader * headPho = 0;
5801         AliGenEventHeader * htmp = mcEvt->GenEventHeader();
5802         if(!htmp) {
5803                 AliFatal("Cannot Get MC Header!!");
5804                 return -1;
5805         }
5806         if( TString(htmp->IsA()->GetName()) == "AliGenPythiaEventHeader") {
5807                 headPy =        (AliGenPythiaEventHeader*) htmp;
5808         } else if (TString(htmp->IsA()->GetName()) == "AliGenDPMjetEventHeader") {
5809                 headPho = (AliGenDPMjetEventHeader*) htmp;
5810         } else {
5811                 AliError("Unknown header");
5812         }
5813
5814         // Determine process type
5815         if(headPy)       {
5816                 if(headPy->ProcessType() == 92 || headPy->ProcessType() == 93) {
5817                         // single difractive
5818                         return kProcSD;
5819                 } else if (headPy->ProcessType() == 94) {
5820                         // double diffractive
5821                         return kProcDD;
5822                 }
5823                 else if(headPy->ProcessType() != 92 && headPy->ProcessType() != 93 && headPy->ProcessType() != 94) {            
5824                         // non difractive
5825                         return kProcND; 
5826                 }
5827         } else if (headPho) {
5828                 if(headPho->ProcessType() == 5 || headPho->ProcessType() == 6 ) {
5829                         // single difractive
5830                         return kProcSD;
5831                 } else if (headPho->ProcessType() == 7) { 
5832                         // double diffractive
5833                         return kProcDD;                 
5834                 } else if(headPho->ProcessType() != 5 && headPho->ProcessType() != 6    && headPho->ProcessType() != 7 ) {
5835                         // non difractive
5836                         return kProcND; 
5837                 }                        
5838         }
5839         
5840
5841         // no process type found?
5842         AliError(Form("Unknown header: %s", htmp->IsA()->GetName()));
5843         return kProcUnknown;
5844 }
5845
5846
5847 Int_t AliAnalysisTaskGammaConversion::CalculateMultiplicityBin(){
5848         // Get Centrality bin
5849
5850         Int_t multiplicity = 0;
5851
5852         if ( fUseMultiplicity == 1 ) {
5853
5854                 if (fMultiplicity>= 0 && fMultiplicity<= 5) multiplicity=1;
5855                 if (fMultiplicity>= 6 && fMultiplicity<= 9) multiplicity=2;
5856                 if (fMultiplicity>=10 && fMultiplicity<=14) multiplicity=3;
5857                 if (fMultiplicity>=15 && fMultiplicity<=22) multiplicity=4;
5858                 if (fMultiplicity>=23 )                                                                          multiplicity=5;
5859
5860         }
5861
5862         if ( fUseHBTMultiplicity == 1 ) {
5863                 
5864                         if (fMultiplicity>= 0 && fMultiplicity<=11)     multiplicity=1;
5865                         if (fMultiplicity>=12 && fMultiplicity<=16)     multiplicity=2;
5866                         if (fMultiplicity>=17 && fMultiplicity<=22)     multiplicity=3;
5867                         if (fMultiplicity>=23 && fMultiplicity<=29)     multiplicity=4;
5868                         if (fMultiplicity>=30 && fMultiplicity<=36)     multiplicity=5;
5869                         if (fMultiplicity>=37 && fMultiplicity<=44)     multiplicity=6;
5870                         if (fMultiplicity>=45 && fMultiplicity<=57)     multiplicity=7;
5871                         if (fMultiplicity>=58 && fMultiplicity<=149) multiplicity=8;
5872                 
5873                 /*
5874                 if (fMultiplicity>= 0 && fMultiplicity<=5) multiplicity=1;
5875                 if (fMultiplicity>=6 && fMultiplicity<=11) multiplicity=2;
5876                 if (fMultiplicity>=12 && fMultiplicity<=16) multiplicity=3;
5877                 if (fMultiplicity>=17 && fMultiplicity<=22) multiplicity=4;
5878                 if (fMultiplicity>=23  )                 multiplicity=5;
5879                 */
5880
5881         }
5882
5883         return multiplicity;
5884 }