]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx
changed Resolution, Material, and PhotonQA task to be able to run on the grid
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliAnalysisTaskConversionQA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Svein Lindal, Daniel Lohner                                   *
5  * Version 1.0                                                            *
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 // QA Task for V0 Reader V1
19 //---------------------------------------------
20 ////////////////////////////////////////////////
21
22 #include "AliAnalysisTaskConversionQA.h"
23 #include "TChain.h"
24 #include "AliAnalysisManager.h"
25 #include "TParticle.h"
26 #include "TVectorF.h"
27 #include "AliPIDResponse.h"
28 #include "TFile.h"
29 #include "AliESDtrackCuts.h"
30 #include "AliAODMCParticle.h"
31 #include "AliAODMCHeader.h"
32
33
34 class iostream;
35
36 using namespace std;
37
38 ClassImp(AliAnalysisTaskConversionQA)
39
40 //________________________________________________________________________
41 AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA() : AliAnalysisTaskSE(),
42    fV0Reader(NULL),
43    fConversionGammas(NULL),
44    fConversionCuts(NULL),
45    fInputEvent(NULL),
46    fNumberOfESDTracks(0),
47    fMCEvent(NULL),
48    fMCStack(NULL),
49    fTreeQA(NULL),
50    fIsHeavyIon(kFALSE),
51    ffillTree(kFALSE),
52    ffillHistograms(kFALSE),
53    fOutputList(NULL),
54    fTreeList(NULL),
55    fESDList(NULL),
56    hVertexZ(NULL),
57    hNGoodESDTracks(NULL),
58    hNV0Tracks(NULL),
59    hNContributorsVertex(NULL),
60    hITSClusterPhi(NULL),
61    hGammaPt(NULL),
62    hGammaPhi(NULL),
63    hGammaEta(NULL),
64    hGammaChi2perNDF(NULL),
65    hGammaPsiPair(NULL),
66    hGammaQt(NULL),
67    hGammaCosinePointingAngle(NULL),
68    hGammaXY(NULL),
69    hGammaZR(NULL),
70    hElecPt(NULL),
71    hElecEta(NULL),
72    hElecPhi(NULL),
73    hElecNfindableClsTPC(NULL),
74    hPosiNfindableClsTPC(NULL),
75    hElecAsymP(NULL),
76    fTrueList(NULL),
77    hTrueResolutionR(NULL),
78    hTrueResolutionZ(NULL),
79    hTrueResolutionPhi(NULL),
80    hTrueGammaPt(NULL),
81    hTrueGammaPhi(NULL),
82    hTrueGammaEta(NULL),
83    hTrueGammaMass(NULL),
84    hTrueGammaChi2perNDF(NULL),
85    hTrueGammaPsiPair(NULL),
86    hTrueGammaQt(NULL),
87    hTrueGammaCosinePointingAngle(NULL),
88    hTrueGammaXY(NULL),
89    hTrueGammaZR(NULL),
90    hTrueElecPt(NULL),
91    hTrueElecEta(NULL),
92    hTrueElecPhi(NULL),
93    hTrueElecNfindableClsTPC(NULL),
94    hTruePosiNfindableClsTPC(NULL),
95    hTrueElecAsymP(NULL),
96    fGammaPt(0),
97    fGammaTheta(0),
98    fGammaChi2NDF(0),
99    fGammaPhotonProp(5),
100    fGammaConvCoord(5),
101    fDaughterProp(20),
102    fKind(0),
103    fIsMC(kFALSE),
104    fnGammaCandidates(1),
105    fMCStackPos(NULL),
106    fMCStackNeg(NULL)
107 {
108
109 }
110
111 AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : AliAnalysisTaskSE(name),
112    fV0Reader(NULL),
113    fConversionGammas(NULL),
114    fConversionCuts(NULL),
115    fInputEvent(NULL),
116    fNumberOfESDTracks(0),
117    fMCEvent(NULL),
118    fMCStack(NULL),
119    fTreeQA(NULL),
120    fIsHeavyIon(kFALSE),
121    ffillTree(kFALSE),
122    ffillHistograms(kFALSE),
123    fOutputList(NULL),
124    fTreeList(NULL),
125    fESDList(NULL),
126    hVertexZ(NULL),
127    hNGoodESDTracks(NULL),
128    hNV0Tracks(NULL),
129    hNContributorsVertex(NULL),
130    hITSClusterPhi(NULL),
131    hGammaPt(NULL),
132    hGammaPhi(NULL),
133    hGammaEta(NULL),
134    hGammaChi2perNDF(NULL),
135    hGammaPsiPair(NULL),
136    hGammaQt(NULL),
137    hGammaCosinePointingAngle(NULL),
138    hGammaXY(NULL),
139    hGammaZR(NULL),
140    hElecPt(NULL),
141    hElecEta(NULL),
142    hElecPhi(NULL),
143    hElecNfindableClsTPC(NULL),
144    hPosiNfindableClsTPC(NULL),
145    hElecAsymP(NULL),
146    fTrueList(NULL),
147    hTrueResolutionR(NULL),
148    hTrueResolutionZ(NULL),
149    hTrueResolutionPhi(NULL),
150    hTrueGammaPt(NULL),
151    hTrueGammaPhi(NULL),
152    hTrueGammaEta(NULL),
153    hTrueGammaMass(NULL),
154    hTrueGammaChi2perNDF(NULL),
155    hTrueGammaPsiPair(NULL),
156    hTrueGammaQt(NULL),
157    hTrueGammaCosinePointingAngle(NULL),
158    hTrueGammaXY(NULL),
159    hTrueGammaZR(NULL),
160    hTrueElecPt(NULL),
161    hTrueElecEta(NULL),
162    hTrueElecPhi(NULL),
163    hTrueElecNfindableClsTPC(NULL),
164    hTruePosiNfindableClsTPC(NULL),
165    hTrueElecAsymP(NULL),
166    fGammaPt(0),
167    fGammaTheta(0),
168    fGammaChi2NDF(0),
169    fGammaPhotonProp(5),
170    fGammaConvCoord(5),
171    fDaughterProp(20),
172    fKind(0),
173    fIsMC(kFALSE),
174    fnGammaCandidates(1),
175    fMCStackPos(NULL),
176    fMCStackNeg(NULL)
177 {
178    // Default constructor
179
180    DefineInput(0, TChain::Class());
181    DefineOutput(1, TList::Class());
182 }
183
184 //________________________________________________________________________
185 AliAnalysisTaskConversionQA::~AliAnalysisTaskConversionQA()
186 {
187    // default deconstructor
188   
189 }
190 //________________________________________________________________________
191 void AliAnalysisTaskConversionQA::UserCreateOutputObjects()
192 {
193    // Create User Output Objects
194
195    if(fOutputList != NULL){
196       delete fOutputList;
197       fOutputList = NULL;
198    }
199    if(fOutputList == NULL){
200       fOutputList = new TList();
201       fOutputList->SetOwner(kTRUE);
202    }
203    
204    if(ffillHistograms){
205          
206       fESDList = new TList();
207       fESDList->SetOwner(kTRUE);
208       fESDList->SetName("ESD QA");
209       fOutputList->Add(fESDList);
210
211       hVertexZ = new TH1F("Vertex_Z","Vertex_Z",300,-15,15);
212       fESDList->Add(hVertexZ);
213       hNContributorsVertex = new TH1I("ContrVertex_Z","ContrVertex_Z",3000,0,3000);
214       fESDList->Add(hNContributorsVertex);
215       if(fIsHeavyIon) hNGoodESDTracks = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
216       else hNGoodESDTracks = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
217       fESDList->Add(hNGoodESDTracks);
218       if(fIsHeavyIon) hNV0Tracks = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
219       else hNV0Tracks = new TH1I("V0 Multiplicity","V0 Multiplicity",2000,0,2000);
220       fESDList->Add(hNV0Tracks);
221
222       hITSClusterPhi = new TH2F("ITSClusterPhi","hITSClusterPhi",72,0,2*TMath::Pi(),7,0,7);
223       fESDList->Add(hITSClusterPhi);
224       hGammaPt = new TH1F("Gamma_Pt","Gamma_Pt",250,0,25);
225       fESDList->Add(hGammaPt);
226       hGammaPhi = new TH1F("Gamma_Phi","Gamma_Phi",360,0,2*TMath::Pi());
227       fESDList->Add(hGammaPhi);
228       hGammaEta = new TH1F("Gamma_Eta","Gamma_Eta",600,-1.5,1.5);
229       fESDList->Add(hGammaEta);
230       hGammaChi2perNDF = new TH1F("Gamma_Chi2perNDF","Gamma_Chi2perNDF",500,0,100);
231       fESDList->Add(hGammaChi2perNDF);
232       hGammaPsiPair = new TH1F("Gamma_PsiPair","Gamma_PsiPair",500,0,2);
233       fESDList->Add(hGammaPsiPair);
234       hGammaQt = new TH1F("Gamma_Qt","Gamma_Qt",400,0,0.1);
235       fESDList->Add(hGammaQt);
236       hGammaCosinePointingAngle = new TH1F("Gamma_CosinePointingAngle","Gamma_CosinePointingAngle",900,0.7,1.);
237       fESDList->Add(hGammaCosinePointingAngle);
238       hGammaXY = new TH2F("Gamma_ConversionPoint_XY","Gamma_ConversionPoint_XY",960,-120,120,960,-120,120);
239       fESDList->Add(hGammaXY);
240       hGammaZR= new TH2F("Gamma_ConversionPoint_ZR","Gamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
241       fESDList->Add(hGammaZR);
242
243       hElecPt = new TH2F("Electron_Positron_Pt","Electron_Positron_Pt",250,0,25,250,0,25);
244       fESDList->Add(hElecPt);
245       hElecEta = new TH2F("Electron_Positron_Eta","Electron_Positron_Eta",600,-1.5,1.5,600,-1.5,1.5);
246       fESDList->Add(hElecEta);
247       hElecPhi = new TH2F("Electron_Positron_Phi","Electron_Positron_Phi",360,0,2*TMath::Pi(),360,0,2*TMath::Pi());
248       fESDList->Add(hElecPhi);
249       hElecNfindableClsTPC = new TH1F("Electron_findableClusterTPC","Electron_findableClusterTPC",100,0,1);
250       fESDList->Add(hElecNfindableClsTPC);
251       hPosiNfindableClsTPC = new TH1F("Positron_findableClusterTPC","Positron_findableClusterTPC",100,0,1);
252       fESDList->Add(hPosiNfindableClsTPC);
253       hElecAsymP = new TH2F("Electron_Asym_vs_P", "Electron_Asym_vs_P",200,0.,20.,200,0.,1.); 
254       fESDList->Add(hElecAsymP);
255
256       if(fIsMC){
257          fTrueList = new TList();
258          fTrueList->SetOwner(kTRUE);
259          fTrueList->SetName("True QA");
260          fOutputList->Add(fTrueList);
261
262          hTrueResolutionR = new TH2F("True_ConversionPointResolution_R","True_ConversionPointResolution_R",240,0,120,200,-20,20);
263          fTrueList->Add(hTrueResolutionR);
264          hTrueResolutionZ = new TH2F("True_ConversionPointResolution_Z","True_ConversionPointResolution_Z",480,-120,120,200,-20,20);
265          fTrueList->Add(hTrueResolutionZ);
266          hTrueResolutionPhi = new TH2F("True_ConversionPointResolution_Phi","True_ConversionPointResolution_Phi",360,0,2*TMath::Pi(),200,-TMath::Pi()/30., TMath::Pi()/30.);
267          fTrueList->Add(hTrueResolutionPhi);
268
269          hTrueGammaPt = new TH1F("True_Gamma_Pt","True_Gamma_Pt",250,0,25);
270          fTrueList->Add(hTrueGammaPt);
271          hTrueGammaPhi = new TH1F("True_Gamma_Phi","True_Gamma_Phi",360,0,2*TMath::Pi());
272          fTrueList->Add(hTrueGammaPhi);
273          hTrueGammaEta = new TH1F("True_Gamma_Eta","True_Gamma_Eta",600,-1.5,1.5);
274          fTrueList->Add(hTrueGammaEta);
275          hTrueGammaMass = new TH1F("True_Gamma_Mass","True_Gamma_Mass",1000,0,0.3);
276          fTrueList->Add(hTrueGammaMass);
277          hTrueGammaChi2perNDF = new TH1F("True_Gamma_Chi2perNDF","True_Gamma_Chi2perNDF",500,0,100);
278          fTrueList->Add(hTrueGammaChi2perNDF);
279          hTrueGammaPsiPair = new TH1F("True_Gamma_PsiPair","True_Gamma_PsiPair",500,0,2);
280          fTrueList->Add(hTrueGammaPsiPair);
281          hTrueGammaQt = new TH1F("True_Gamma_Qt","True_Gamma_Qt",400,0,0.1);
282          fTrueList->Add(hTrueGammaQt);
283          hTrueGammaCosinePointingAngle = new TH1F("True_Gamma_CosinePointingAngle","True_Gamma_CosinePointingAngle",900,0.7,1.);
284          fTrueList->Add(hTrueGammaCosinePointingAngle);
285          hTrueGammaXY = new TH2F("True_Gamma_ConversionPoint_XY","True_Gamma_ConversionPoint_XY",960,-120,120,960,-120,120);
286          fTrueList->Add(hTrueGammaXY);
287          hTrueGammaZR= new TH2F("TrueGamma_ConversionPoint_ZR","TrueGamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
288          fTrueList->Add(hTrueGammaZR);
289
290          hTrueElecPt = new TH2F("True_Electron_Positron_Pt","True_Electron_Positron_Pt",250,0,25,250,0,25);
291          fTrueList->Add(hTrueElecPt);
292          hTrueElecEta = new TH2F("True_Electron_Positron_Eta","True_Electron_Positron_Eta",600,-1.5,1.5,600,-1.5,1.5);
293          fTrueList->Add(hTrueElecEta);
294          hTrueElecPhi = new TH2F("True_Electron_Positron_Phi","True_Electron_Positron_Phi",360,0,2*TMath::Pi(),360,0,2*TMath::Pi());
295          fTrueList->Add(hTrueElecPhi);
296          hTrueElecNfindableClsTPC = new TH1F("True_Electron_findableClusterTPC","True_Electron_findableClusterTPC",100,0,1);
297          fTrueList->Add(hTrueElecNfindableClsTPC);
298          hTruePosiNfindableClsTPC = new TH1F("True_Positron_findableClusterTPC","True_Positron_findableClusterTPC",100,0,1);
299          fTrueList->Add(hTruePosiNfindableClsTPC);
300                                  hTrueElecAsymP = new TH2F("True_Electron_Asym_vs_P", "True_Electron_Asym_vs_P",200,0.,20.,200,0.,1.); 
301                                  fTrueList->Add(hTrueElecAsymP);
302       }
303       if(fConversionCuts->GetCutHistograms()){
304          fOutputList->Add(fConversionCuts->GetCutHistograms());
305       }
306    }
307    
308    if(ffillTree){
309       fTreeList = new TList();
310       fTreeList->SetOwner(kTRUE);
311       fTreeList->SetName("TreeList");
312       fOutputList->Add(fTreeList);
313
314       fTreeQA = new TTree("PhotonQA","PhotonQA");   
315      
316       fTreeQA->Branch("daughterProp",&fDaughterProp);
317       fTreeQA->Branch("recCords",&fGammaConvCoord);
318       fTreeQA->Branch("photonProp",&fGammaPhotonProp);
319       fTreeQA->Branch("pt",&fGammaPt,"fGammaPt/F");
320       fTreeQA->Branch("theta",&fGammaTheta,"fGammaTheta/F");
321       fTreeQA->Branch("chi2ndf",&fGammaChi2NDF,"fGammaChi2NDF/F");
322       if (fIsMC) {
323          fTreeQA->Branch("kind",&fKind,"fKind/b");
324       }   
325       fTreeList->Add(fTreeQA);
326
327    }
328
329    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
330    
331    PostData(1, fOutputList);
332 }
333 //_____________________________________________________________________________
334 Bool_t AliAnalysisTaskConversionQA::Notify()
335 {
336    if(!fConversionCuts->GetDoEtaShift()) return kTRUE;; // No Eta Shift requested, continue
337       
338    if(fConversionCuts->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
339       fConversionCuts->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
340       fConversionCuts->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
341       return kTRUE;
342    }
343    else{
344       printf(" Gamma Conversion QA Task %s :: Eta Shift Manually Set to %f \n\n",
345              (fConversionCuts->GetCutNumber()).Data(),fConversionCuts->GetEtaShift());
346       fConversionCuts->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
347    }
348    
349    return kTRUE;
350 }
351 //________________________________________________________________________
352 void AliAnalysisTaskConversionQA::UserExec(Option_t *){
353
354
355
356    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
357    if(eventQuality != 0){// Event Not Accepted
358       return;
359    }
360    fInputEvent = InputEvent();
361    if(fIsMC) fMCEvent = MCEvent();
362    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){ fMCStack = fMCEvent->Stack(); }
363
364    Int_t eventNotAccepted =
365       fConversionCuts->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
366    if(eventNotAccepted) return; // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
367
368    fConversionGammas=fV0Reader->GetReconstructedGammas();
369
370    if(fMCEvent){
371       if(fConversionCuts->GetSignalRejection() != 0){
372          if(fInputEvent->IsA()==AliESDEvent::Class()){
373                fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
374                                                         fConversionCuts->GetAcceptedHeader(),
375                                                         fMCEvent);
376          }
377          else if(fInputEvent->IsA()==AliAODEvent::Class()){
378             fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
379                                                       fConversionCuts->GetAcceptedHeader(),
380                                                       fInputEvent);
381          }
382       }
383    }
384
385    if(ffillHistograms){
386       CountTracks();
387       hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
388       hNContributorsVertex->Fill(fConversionCuts->GetNumberOfContributorsVtx(fInputEvent));
389       hNGoodESDTracks->Fill(fNumberOfESDTracks);
390       hNV0Tracks->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
391    }
392
393     if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
394       RelabelAODPhotonCandidates(kTRUE);    // In case of AODMC relabeling MC
395    
396    for(Int_t firstGammaIndex=0;firstGammaIndex<fConversionGammas->GetEntriesFast();firstGammaIndex++){
397       AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(firstGammaIndex));
398       if (gamma==NULL) continue;
399       if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
400          if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelPositive(), fMCStack, fInputEvent))
401             continue;
402          if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelNegative(), fMCStack, fInputEvent))
403             continue;
404       }
405       if(!fConversionCuts->PhotonIsSelected(gamma,fInputEvent)){
406          continue;
407       }
408
409       if(ffillTree) ProcessQATree(gamma);
410       if(ffillHistograms) ProcessQA(gamma);
411    }
412    if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
413       RelabelAODPhotonCandidates(kFALSE);    // In case of AODMC relabeling MC
414       
415    PostData(1, fOutputList);
416 }
417
418
419 ///________________________________________________________________________
420 void AliAnalysisTaskConversionQA::ProcessQATree(AliAODConversionPhoton *gamma){
421
422    // Fill Histograms for QA and MC
423    AliVEvent* event = (AliVEvent*) InputEvent();
424    
425    
426    
427    AliPIDResponse* pidResonse = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetPIDResponse();
428
429    fGammaPt = gamma->GetPhotonPt();
430    
431    fGammaTheta = gamma->Theta();
432    fGammaChi2NDF = gamma->GetChi2perNDF();
433    
434    fGammaPhotonProp(0)  = gamma->GetArmenterosQt();
435    fGammaPhotonProp(1)  = gamma->GetArmenterosAlpha();
436    fGammaPhotonProp(2)  = gamma->GetPsiPair();
437    fGammaPhotonProp(3) = fConversionCuts->GetCosineOfPointingAngle(gamma,event);
438         fGammaPhotonProp(4) = gamma->GetMass();
439    
440    fGammaConvCoord(0) = gamma->GetConversionX();
441    fGammaConvCoord(1) = gamma->GetConversionY();
442    fGammaConvCoord(2) = gamma->GetConversionZ();
443    fGammaConvCoord(3) = gamma->GetConversionRadius();
444    fGammaConvCoord(4) = gamma->GetPhotonPhi();
445    
446    AliVTrack * negTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelNegative());
447    AliVTrack * posTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelPositive());
448
449    
450    if(!negTrack||!posTrack)return;
451
452    fKind = 9;
453    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
454       fKind = IsTruePhotonESD(gamma);
455    } else if (fMCEvent && fInputEvent->IsA()==AliAODEvent::Class()){
456       fKind = IsTruePhotonAOD(gamma);   
457    }
458
459    fDaughterProp(0) =  posTrack->Pt();
460    fDaughterProp(7) =  negTrack->Pt();
461    fDaughterProp(1) =  posTrack->Theta();
462    fDaughterProp(8) =  negTrack->Theta();
463    Double32_t signalPos[4] = {0,0,0,0};
464    Char_t nclPos[3];
465    Char_t nrowsPos[3];
466    if (posTrack->GetTPCdEdxInfo()) {
467       posTrack->GetTPCdEdxInfo()->GetTPCSignalRegionInfo(signalPos,nclPos,nrowsPos);
468       fDaughterProp(2) =  signalPos[0];
469       fDaughterProp(14) =  signalPos[1];
470       fDaughterProp(16) =  signalPos[2];
471    } else {
472       fDaughterProp(2) =  posTrack->GetTPCsignal();
473       fDaughterProp(14) =  0;
474       fDaughterProp(16) =  0;
475    }
476    Double32_t signalNeg[4] = {0,0,0,0};
477    Char_t nclNeg[3];
478    Char_t nrowsNeg[3];
479    if (negTrack->GetTPCdEdxInfo()) {
480       negTrack->GetTPCdEdxInfo()->GetTPCSignalRegionInfo(signalNeg,nclNeg,nrowsNeg);
481       fDaughterProp(9) =  signalNeg[0];
482       fDaughterProp(15) =  signalNeg[1];
483       fDaughterProp(17) =  signalNeg[2];
484    } else {
485       fDaughterProp(9) =  negTrack->GetTPCsignal();
486       fDaughterProp(15) =  0;
487       fDaughterProp(17) =  0;
488    }
489    fDaughterProp(3) =  pidResonse->NumberOfSigmasTPC(posTrack,AliPID::kElectron);
490    fDaughterProp(10) =  pidResonse->NumberOfSigmasTPC(negTrack,AliPID::kElectron);
491    if((posTrack->GetStatus() & AliESDtrack::kTOFpid) && !(posTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
492       Double_t t0pos = pidResonse->GetTOFResponse().GetStartTime(posTrack->P());
493       Double_t timesPos[5];
494       posTrack->GetIntegratedTimes(timesPos);
495       Double_t TOFsignalPos =   posTrack->GetTOFsignal();
496       Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
497       fDaughterProp(4) =  dTpos;
498       fDaughterProp(5) =  pidResonse->NumberOfSigmasTOF(posTrack, AliPID::kElectron);
499    } else {
500       fDaughterProp(4) =  20000;
501       fDaughterProp(5) =  -20;
502    }
503    if((negTrack->GetStatus() & AliESDtrack::kTOFpid) && !(negTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
504       Double_t t0neg = pidResonse->GetTOFResponse().GetStartTime(negTrack->P());
505       Double_t timesNeg[5];
506       negTrack->GetIntegratedTimes(timesNeg);
507       Double_t TOFsignalNeg =   negTrack->GetTOFsignal();
508       Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
509       fDaughterProp(11) =  dTneg;
510       fDaughterProp(12) =  pidResonse->NumberOfSigmasTOF(negTrack, AliPID::kElectron);
511    } else {
512       fDaughterProp(11) =  20000;
513       fDaughterProp(12) =  -20;
514    }
515
516    fDaughterProp(6) =  (Float_t)posTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius()));
517    fDaughterProp(18) =  posTrack->GetNcls(1);
518    fDaughterProp(13) =  (Float_t)negTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius()));
519    fDaughterProp(19) =  negTrack->GetNcls(1);
520    
521    if (fTreeQA){
522       fTreeQA->Fill();
523    }
524 }
525
526 //_____________________________________________________________________________________________________
527 void AliAnalysisTaskConversionQA::ProcessQA(AliAODConversionPhoton *gamma){
528
529
530    // Fill Histograms for QA and MC
531    hGammaPt->Fill(gamma->GetPhotonPt());
532    hGammaPhi->Fill(gamma->GetPhotonPhi());
533    hGammaEta->Fill(gamma->Eta());
534    hGammaChi2perNDF->Fill(gamma->GetChi2perNDF());
535    hGammaPsiPair->Fill(gamma->GetPsiPair());
536    hGammaQt->Fill(gamma->GetArmenterosQt());
537    hGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(gamma,fInputEvent));
538    hGammaXY->Fill(gamma->GetConversionX(),gamma->GetConversionY());
539    hGammaZR->Fill(gamma->GetConversionZ(),gamma->GetConversionRadius());
540
541    AliVTrack * negTrack = fConversionCuts->GetTrack(fInputEvent, gamma->GetTrackLabelNegative());
542    AliVTrack * posTrack = fConversionCuts->GetTrack(fInputEvent, gamma->GetTrackLabelPositive());
543    if(!negTrack||!posTrack)return;
544
545    Double_t negtrackPhi = negTrack->Phi();
546    Double_t postrackPhi = posTrack->Phi();
547    hITSClusterPhi->Fill(negtrackPhi,6);
548    hITSClusterPhi->Fill(postrackPhi,6);
549    for(Int_t itsLayer = 0; itsLayer<6;itsLayer++){
550       if(TESTBIT(negTrack->GetITSClusterMap(),itsLayer)){
551          hITSClusterPhi->Fill(negtrackPhi,itsLayer);
552       }
553       if(TESTBIT(posTrack->GetITSClusterMap(),itsLayer)){
554          hITSClusterPhi->Fill(postrackPhi,itsLayer);
555       }
556    }
557
558    hElecPt->Fill(negTrack->Pt(),posTrack->Pt());
559    hElecEta->Fill(negTrack->Eta(),posTrack->Eta());
560    hElecPhi->Fill(negTrack->Phi(),posTrack->Phi());
561
562    hElecNfindableClsTPC->Fill((Float_t)posTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius())));
563    hPosiNfindableClsTPC->Fill((Float_t)negTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius())));
564    if(gamma->P()!=0){
565                  hElecAsymP->Fill(gamma->P(),negTrack->P()/gamma->P());
566          }
567    // hElecNfindableClsTPC->Fill((Float_t)negTrack->GetNcls(1)/(Float_t)negTrack->GetTPCNclsF());
568    // hPosiNfindableClsTPC->Fill((Float_t)posTrack->GetNcls(1)/(Float_t)posTrack->GetTPCNclsF());
569    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
570       ProcessTrueQAESD(gamma,(AliESDtrack*)negTrack,(AliESDtrack*)posTrack);
571    } else if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class()){
572         ProcessTrueQAAOD(gamma,(AliAODTrack*)negTrack,(AliAODTrack*)posTrack);
573    }
574 }
575
576 //________________________________________________________________________
577 void AliAnalysisTaskConversionQA::ProcessTrueQAESD(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi)
578 {
579
580    if(IsTruePhotonESD(TruePhotonCandidate)!=0 && IsTruePhotonESD(TruePhotonCandidate)!=5  ) return;
581
582    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
583    TParticle *mcPhoton = TruePhotonCandidate->GetMCParticle(fMCStack);
584    // True Photon
585    hTrueResolutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
586                            TruePhotonCandidate->GetConversionRadius()-negDaughter->R());
587    hTrueResolutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
588                            TruePhotonCandidate->GetConversionZ()-negDaughter->Vz());
589    hTrueResolutionPhi->Fill(TruePhotonCandidate->Phi(),
590                              TruePhotonCandidate->Phi()-mcPhoton->Phi());
591    hTrueGammaPt->Fill(TruePhotonCandidate->Pt());
592    hTrueGammaPhi->Fill(TruePhotonCandidate->Phi());
593    hTrueGammaEta->Fill(TruePhotonCandidate->Eta());
594    hTrueGammaMass->Fill(TruePhotonCandidate->GetMass());
595    hTrueGammaChi2perNDF->Fill(TruePhotonCandidate->GetChi2perNDF());
596    hTrueGammaPsiPair->Fill(TruePhotonCandidate->GetPsiPair());
597    hTrueGammaQt->Fill(TruePhotonCandidate->GetArmenterosQt());
598    hTrueGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(TruePhotonCandidate,fInputEvent));
599    hTrueGammaXY->Fill(TruePhotonCandidate->GetConversionX(),TruePhotonCandidate->GetConversionY());
600    hTrueGammaZR->Fill(TruePhotonCandidate->GetConversionZ(),TruePhotonCandidate->GetConversionRadius());
601    hTrueElecPt->Fill(elec->Pt(),posi->Pt());
602    hTrueElecEta->Fill(elec->Eta(),posi->Eta());
603    hTrueElecPhi->Fill(elec->Phi(),posi->Phi());
604    hTrueElecNfindableClsTPC
605       ->Fill((Float_t)elec->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
606    hTruePosiNfindableClsTPC
607       ->Fill((Float_t)posi->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
608    if(TruePhotonCandidate->P()!=0){
609                  hTrueElecAsymP->Fill(TruePhotonCandidate->P(),elec->P()/TruePhotonCandidate->P());
610          }
611
612    // hTrueElecNfindableClsTPC->Fill((Float_t)elec->GetNcls(1)/(Float_t)elec->GetTPCNclsF());
613    // hTruePosiNfindableClsTPC->Fill((Float_t)posi->GetNcls(1)/(Float_t)posi->GetTPCNclsF());
614 }
615
616 //________________________________________________________________________
617 void AliAnalysisTaskConversionQA::ProcessTrueQAAOD(AliAODConversionPhoton *TruePhotonCandidate, AliAODTrack *elec, AliAODTrack *posi)
618 {
619
620    if(IsTruePhotonAOD(TruePhotonCandidate)!=0 && IsTruePhotonESD(TruePhotonCandidate)!=5 ) return;
621
622    TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
623    AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
624    AliAODMCParticle *mcPhoton = (AliAODMCParticle*) AODMCTrackArray->At(negDaughter->GetMother());
625    // True Photon
626    hTrueResolutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
627                            TruePhotonCandidate->GetConversionRadius()-(TMath::Sqrt(negDaughter->Xv()*negDaughter->Xv()+negDaughter->Yv()*negDaughter->Yv())));
628    hTrueResolutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
629                            TruePhotonCandidate->GetConversionZ()-negDaughter->Zv());
630    hTrueResolutionPhi->Fill(TruePhotonCandidate->Phi(),
631                              TruePhotonCandidate->Phi()-mcPhoton->Phi());
632    hTrueGammaPt->Fill(TruePhotonCandidate->Pt());
633    hTrueGammaPhi->Fill(TruePhotonCandidate->Phi());
634    hTrueGammaEta->Fill(TruePhotonCandidate->Eta());
635    hTrueGammaMass->Fill(TruePhotonCandidate->GetMass());
636    hTrueGammaChi2perNDF->Fill(TruePhotonCandidate->GetChi2perNDF());
637    hTrueGammaPsiPair->Fill(TruePhotonCandidate->GetPsiPair());
638    hTrueGammaQt->Fill(TruePhotonCandidate->GetArmenterosQt());
639    hTrueGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(TruePhotonCandidate,fInputEvent));
640    hTrueGammaXY->Fill(TruePhotonCandidate->GetConversionX(),TruePhotonCandidate->GetConversionY());
641    hTrueGammaZR->Fill(TruePhotonCandidate->GetConversionZ(),TruePhotonCandidate->GetConversionRadius());
642    hTrueElecPt->Fill(elec->Pt(),posi->Pt());
643    hTrueElecEta->Fill(elec->Eta(),posi->Eta());
644    hTrueElecPhi->Fill(elec->Phi(),posi->Phi());
645    hTrueElecNfindableClsTPC
646       ->Fill((Float_t)elec->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
647    hTruePosiNfindableClsTPC
648       ->Fill((Float_t)posi->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
649    // hTrueElecNfindableClsTPC->Fill((Float_t)elec->GetNcls(1)/(Float_t)elec->GetTPCNclsF());
650    // hTruePosiNfindableClsTPC->Fill((Float_t)posi->GetNcls(1)/(Float_t)posi->GetTPCNclsF());
651 }
652
653 //________________________________________________________________________
654 void AliAnalysisTaskConversionQA::CountTracks(){
655
656    if(fInputEvent->IsA()==AliESDEvent::Class()){
657    // Using standard function for setting Cuts
658    Bool_t selectPrimaries=kTRUE;
659    AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
660    EsdTrackCuts->SetMaxDCAToVertexZ(2);
661    EsdTrackCuts->SetEtaRange(-0.8, 0.8);
662    EsdTrackCuts->SetPtRange(0.15);
663       fNumberOfESDTracks = 0;
664       for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
665          AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
666          if(!curTrack) continue;
667          // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
668          //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
669          // }
670          if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
671       }
672       delete EsdTrackCuts;
673       EsdTrackCuts=0x0;
674    }
675    else if(fInputEvent->IsA()==AliAODEvent::Class()){
676       fNumberOfESDTracks = 0;
677       for(Int_t iTracks = 0; iTracks<fInputEvent->GetNumberOfTracks(); iTracks++){
678          AliAODTrack* curTrack = (AliAODTrack*) fInputEvent->GetTrack(iTracks);
679          if(!curTrack->IsPrimaryCandidate()) continue;
680          if(abs(curTrack->Eta())>0.8) continue;
681          if(curTrack->Pt()<0.15) continue;
682          if(abs(curTrack->ZAtDCA())>2) continue;
683          fNumberOfESDTracks++;
684       }
685    }
686    
687    return;
688 }
689 //________________________________________________________________________
690 /*
691 Bool_t AliAnalysisTaskConversionQA::IsTruePhotonESD(AliAODConversionPhoton *TruePhotonCandidate)
692 {
693    TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCStack);
694    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
695
696    if(posDaughter == NULL || negDaughter == NULL) return kFALSE; // One particle does not exist
697    Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
698    if(posDaughter->GetMother(0) != negDaughter->GetMother(0)) return kFALSE;
699    else if(posDaughter->GetMother(0) == -1) return kFALSE;
700
701    if(pdgCode[0]!=11 || pdgCode[1]!=11) return kFALSE; //One Particle is not electron
702    if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return kFALSE; // Same Charge
703    if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return kFALSE;// check if the daughters come from a conversion
704
705    TParticle *Photon = TruePhotonCandidate->GetMCParticle(fMCStack);
706    if(Photon->GetPdgCode() != 22) return kFALSE; // Mother is no Photon
707
708    return kTRUE;
709 }
710 */
711 UInt_t AliAnalysisTaskConversionQA::IsTruePhotonESD(AliAODConversionPhoton *TruePhotonCandidate)
712 {
713
714
715         UInt_t kind = 9;
716         TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCStack);
717         TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
718         TParticle *Photon = TruePhotonCandidate->GetMCParticle(fMCStack);
719         Int_t motherLabelPhoton; 
720         Int_t pdgCodePos = 0; 
721         Int_t pdgCodeNeg = 0; 
722         Int_t pdgCode = 0; 
723
724
725         if(posDaughter == NULL || negDaughter == NULL) {
726                 kind = 9;
727                 //              return kFALSE; // One particle does not exist
728    
729   } else if( posDaughter->GetMother(0) != negDaughter->GetMother(0)  || (posDaughter->GetMother(0) == negDaughter->GetMother(0) && posDaughter->GetMother(0) ==-1)) {
730                 //              kind = 1;
731           return 1;
732                 pdgCodePos=TMath::Abs(posDaughter->GetPdgCode());
733                 pdgCodeNeg=TMath::Abs(negDaughter->GetPdgCode());
734                 if(pdgCodePos==11 && pdgCodeNeg==11) return 10; //Electron Combinatorial
735                 if(pdgCodePos==11 && pdgCodeNeg==11 && 
736                         (posDaughter->GetMother(0) == negDaughter->GetMother(0) && posDaughter->GetMother(0) ==-1)) return 15; //direct Electron Combinatorial
737                                 
738                 if(pdgCodePos==211 && pdgCodeNeg==211) return 11; //Pion Combinatorial
739                 if((pdgCodePos==211 && pdgCodeNeg==2212) ||(pdgCodePos==2212 && pdgCodeNeg==211))       return 12; //Pion, Proton Combinatorics
740                 if((pdgCodePos==211 && pdgCodeNeg==11) ||(pdgCodePos==11 && pdgCodeNeg==211)) return 13; //Pion, Electron Combinatorics
741                 if(pdgCodePos==321 || pdgCodeNeg==321) return 14; //Kaon combinatorics
742         }else{          
743  
744                 pdgCodePos=posDaughter->GetPdgCode();
745                 pdgCodeNeg=negDaughter->GetPdgCode();
746           motherLabelPhoton= Photon->GetMother(0);
747                 if ( TruePhotonCandidate->GetMCParticle(fMCStack)->GetPdgCode()) pdgCode = TruePhotonCandidate->GetMCParticle(fMCStack)->GetPdgCode(); 
748
749                 if(TMath::Abs(pdgCodePos)!=11 || TMath::Abs(pdgCodeNeg)!=11) return 2; // true from hadronic decays
750                 else if ( !(pdgCodeNeg==pdgCodePos)){
751                         if(pdgCode == 111) return 3; // pi0 Dalitz
752                         else if (pdgCode == 221) return 4; // eta Dalitz
753                         else if (!(negDaughter->GetUniqueID() != 5 || posDaughter->GetUniqueID() !=5)){
754                                 if(pdgCode == 22 && motherLabelPhoton < fMCStack->GetNprimary()){
755                                         return 0; // primary photons
756                                 } else if (pdgCode == 22){
757                                         return 5; //secondary photons
758                                 }
759                         }
760                 }
761         }
762
763         return kind;
764 }
765
766 //________________________________________________________________________
767 UInt_t AliAnalysisTaskConversionQA::IsTruePhotonAOD(AliAODConversionPhoton *TruePhotonCandidate)
768 {   
769
770         UInt_t kind = 9;
771
772   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
773         AliAODMCParticle *posDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelPositive());
774         AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
775         AliAODMCParticle *Photon = (AliAODMCParticle*) AODMCTrackArray->At(posDaughter->GetMother());
776         Int_t motherLabelPhoton = Photon->GetMother();
777         Int_t pdgCodePos = 0; 
778         Int_t pdgCodeNeg = 0; 
779         Int_t pdgCode = 0; 
780
781         if(posDaughter == NULL || negDaughter == NULL) {
782                 kind = 9;
783                 //              return kFALSE; // One particle does not exist
784    
785   } else if( posDaughter->GetMother() != negDaughter->GetMother()  || (posDaughter->GetMother() == negDaughter->GetMother() && posDaughter->GetMother() ==-1)) {
786                 kind = 1;
787
788                 pdgCodePos=TMath::Abs(posDaughter->GetPdgCode());
789                 pdgCodeNeg=TMath::Abs(negDaughter->GetPdgCode());
790                 if(pdgCodePos==11 && pdgCodeNeg==11)    kind = 10; //Electron Combinatorial
791                 if(pdgCodePos==11 && pdgCodeNeg==11 && 
792                         (posDaughter->GetMother() == negDaughter->GetMother() && posDaughter->GetMother() ==-1))kind = 15; //direct Electron Combinatorial
793                                 
794                 if(pdgCodePos==211 && pdgCodeNeg==211) kind = 11; //Pion Combinatorial
795                 if((pdgCodePos==211 && pdgCodeNeg==2212) ||(pdgCodePos==2212 && pdgCodeNeg==211))       kind = 12; //Pion, Proton Combinatorics
796                 if((pdgCodePos==211 && pdgCodeNeg==11) ||(pdgCodePos==11 && pdgCodeNeg==211)) kind = 13; //Pion, Electron Combinatorics
797                 if(pdgCodePos==321 || pdgCodeNeg==321) kind = 14; //Kaon combinatorics
798         }else{          
799  
800                 pdgCodePos=posDaughter->GetPdgCode();
801                 pdgCodeNeg=negDaughter->GetPdgCode();
802
803                 if ( TruePhotonCandidate->GetMCParticle(fMCStack)->GetPdgCode()) 
804                         pdgCode = TruePhotonCandidate->GetMCParticle(fMCStack)->GetPdgCode(); 
805                 if(TMath::Abs(pdgCodePos)!=11 || TMath::Abs(pdgCodeNeg)!=11) kind = 2; // true from hadronic decays
806                 else if ( !(pdgCodeNeg==pdgCodePos)){
807                         if(pdgCode == 111) kind = 3; // pi0 Dalitz
808                         else if (pdgCode == 221) kind = 4; // eta Dalitz
809                         else if (!(negDaughter->GetMCProcessCode() != 5 || posDaughter->GetMCProcessCode() !=5)){
810                                 if(pdgCode == 22 && motherLabelPhoton < fMCStack->GetNprimary()){
811                                         kind = 0; // primary photons
812                                 } else if (pdgCode == 22){
813                                         kind = 5; //secondary photons
814                                 }
815                         }
816                 }
817         }
818
819
820         return kind;
821
822
823 }
824
825 //________________________________________________________________________
826 void AliAnalysisTaskConversionQA::RelabelAODPhotonCandidates(Bool_t mode){
827
828    // Relabeling For AOD Event
829    // ESDiD -> AODiD
830    // MCLabel -> AODMCLabel
831    
832    if(mode){
833       fMCStackPos = new Int_t[fConversionGammas->GetEntries()];
834       fMCStackNeg = new Int_t[fConversionGammas->GetEntries()];
835    }
836    
837    for(Int_t iGamma = 0;iGamma<fConversionGammas->GetEntries();iGamma++){
838       AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fConversionGammas->At(iGamma);
839       if(!PhotonCandidate) continue;
840       if(!mode){// Back to ESD Labels
841          PhotonCandidate->SetMCLabelPositive(fMCStackPos[iGamma]);
842          PhotonCandidate->SetMCLabelNegative(fMCStackNeg[iGamma]);
843          //PhotonCandidate->IsAODMCLabel(kFALSE);
844          continue;
845       }
846       fMCStackPos[iGamma] =  PhotonCandidate->GetMCLabelPositive();
847       fMCStackNeg[iGamma] =  PhotonCandidate->GetMCLabelNegative();
848
849       Bool_t AODLabelPos = kFALSE;
850       Bool_t AODLabelNeg = kFALSE;
851
852       for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
853          AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
854          if(!AODLabelPos){
855             if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelPositive() ){
856                PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
857                AODLabelPos = kTRUE;
858             }
859          }
860          if(!AODLabelNeg){
861             if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelNegative()){
862                PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
863                AODLabelNeg = kTRUE;
864             }
865          }
866          if(AODLabelNeg && AODLabelPos){
867             break;
868          }
869       } // Both ESD Tracks have AOD Tracks with Positive IDs
870       if(!AODLabelPos || !AODLabelNeg){
871          for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
872             AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
873             if(tempDaughter->GetID()<0){
874                if(!AODLabelPos){
875                   if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelPositive()){
876                      PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
877                      AODLabelPos = kTRUE;
878                   }
879                }
880                if(!AODLabelNeg){
881                   if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelNegative()){
882                      PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
883                      AODLabelNeg = kTRUE;
884                   }
885                }
886             }
887             if(AODLabelNeg && AODLabelPos){
888                break;
889             }
890          }
891          if(!AODLabelPos || !AODLabelNeg){
892             cout<<"WARNING!!! AOD TRACKS NOT FOUND FOR"<<endl;
893          }
894       }
895    }
896    
897    if(!mode){
898       delete[] fMCStackPos;
899       delete[] fMCStackNeg;
900    }
901 }
902
903 //________________________________________________________________________
904 void AliAnalysisTaskConversionQA::Terminate(Option_t *)
905 {
906
907 }