]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/PHOS_Tagging/AliAnalysisTaskTaggedPhotons.cxx
Weights improved
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / PHOS_Tagging / AliAnalysisTaskTaggedPhotons.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: */
17
18 //_________________________________________________________________________
19 // Analysis for Tagged Photons
20 // Prepares all necessary histograms for calculation of 
21 // the yield of pi0 decay photon in calorimeter:
22 // Marks photons which makes pi0 with some other and
23 // fill invariant mass distributions for estimate background below pi0
24 // peak so that estimate proportion of fake pairs. 
25 // Fills as well controll MC histograms with clasification of the photon origin 
26 // and check of the proportion of truly tagged photons.
27 // 
28 //
29 //*-- Dmitry Blau, Dmitri Peresunko 
30 //////////////////////////////////////////////////////////////////////////////
31
32 #include <TH1.h>
33 #include <TH2.h>
34 #include <TH3.h>
35 #include <THashList.h>
36 #include <TFile.h>
37 #include <TROOT.h>
38
39 #include "AliAnalysisTaskTaggedPhotons.h" 
40 #include "AliAnalysisManager.h"
41 #include "AliAODEvent.h" 
42 #include "AliAODEvent.h" 
43 #include "AliVCluster.h" 
44 #include "AliCaloPhoton.h"
45 #include "AliAODMCParticle.h"
46 #include "AliAnalysisManager.h"
47 #include "AliLog.h"
48 #include "TGeoManager.h"
49 #include "AliMCEventHandler.h"
50 #include "AliMCEvent.h"
51 #include "AliStack.h"
52 #include "AliPHOSGeometry.h"
53 #include "AliTriggerAnalysis.h"
54 #include "AliEMCALGeometry.h"
55 #include "AliAnalysisUtils.h"
56 #include "AliOADBContainer.h"
57
58 ClassImp(AliAnalysisTaskTaggedPhotons)
59
60 //______________________________________________________________________________
61 AliAnalysisTaskTaggedPhotons::AliAnalysisTaskTaggedPhotons() : 
62   AliAnalysisTaskSE(),
63   fPHOSgeom(0x0),
64   fOutputContainer(0x0),
65   fStack(0x0),
66   fTrackEvent(0x0),
67   fPHOSEvent(0x0),
68   fCurrentMixedList(0x0),
69   fTriggerAnalysis(0x0),
70   fUtils(0x0),
71   fZmax(0.),
72   fZmin(0.),
73   fPhimax(0.),
74   fPhimin(0.),
75   fCentrality(0.),
76   fCentBin(0), 
77   fIsMB(0),
78   fIsMC(0)
79 {
80   //Deafult constructor
81   //no memory allocations
82   for(Int_t i=0;i<10;i++)
83     for(Int_t j=0;j<2;j++)
84       fPHOSEvents[i][j]=0x0 ;    //Container for PHOS photons
85   for(Int_t i=0;i<6;i++)
86     fPHOSBadMap[i]=0x0;
87 }
88 //______________________________________________________________________________
89 AliAnalysisTaskTaggedPhotons::AliAnalysisTaskTaggedPhotons(const char *name) : 
90   AliAnalysisTaskSE(name),
91   fPHOSgeom(0x0),
92   fOutputContainer(0x0),
93   fStack(0x0),
94   fTrackEvent(0x0),
95   fPHOSEvent(0x0),
96   fCurrentMixedList(0x0),
97   fTriggerAnalysis(new AliTriggerAnalysis),
98   fUtils(0x0),
99   fZmax(-60.),
100   fZmin(60.),
101   fPhimax(250.),
102   fPhimin(320.),
103   fCentrality(0.),
104   fCentBin(0),
105   fIsMB(0),
106   fIsMC(0)
107 {
108   // Constructor.
109
110   // Output slots #0 write into a TH1 container
111   DefineOutput(1,THashList::Class());
112   // Set bad channel map (empty so far)
113   for(Int_t i=0;i<1;i++)
114     for(Int_t j=0;j<5;j++)
115       fPHOSEvents[i][j]=0x0 ;    //Container for PHOS photons
116   for(Int_t i=0;i<6;i++)
117     fPHOSBadMap[i]=0x0;
118   
119   
120 }
121
122 //____________________________________________________________________________
123 AliAnalysisTaskTaggedPhotons::AliAnalysisTaskTaggedPhotons(const AliAnalysisTaskTaggedPhotons& ap) :
124   AliAnalysisTaskSE(ap.GetName()),  
125   fPHOSgeom(0x0),
126   fOutputContainer(0x0),
127   fStack(0x0),
128   fTrackEvent(0x0),
129   fPHOSEvent(0x0),
130   fCurrentMixedList(0x0),
131   fTriggerAnalysis(new AliTriggerAnalysis),  
132   fUtils(0x0),
133   fZmax(-60.),
134   fZmin(60.),
135   fPhimax(250.),
136   fPhimin(320.),
137   fCentrality(0.),
138   fCentBin(0),
139   fIsMB(0),
140   fIsMC(0)
141 {
142   // cpy ctor
143   fZmax=ap.fZmax ;
144   fZmin=ap.fZmin ;
145   fPhimax=ap.fPhimax ;
146   fPhimin=ap.fPhimin ;
147   for(Int_t i=0;i<1;i++)
148     for(Int_t j=0;j<5;j++)
149       fPHOSEvents[i][j]=0x0 ;    //Container for PHOS photons
150   for(Int_t i=0;i<6;i++)
151     fPHOSBadMap[i]=0x0;
152
153 }
154
155 //_____________________________________________________________________________
156 AliAnalysisTaskTaggedPhotons& AliAnalysisTaskTaggedPhotons::operator = (const AliAnalysisTaskTaggedPhotons& ap)
157 {
158 // assignment operator
159
160   this->~AliAnalysisTaskTaggedPhotons();
161   new(this) AliAnalysisTaskTaggedPhotons(ap);
162   return *this;
163 }
164
165 //______________________________________________________________________________
166 AliAnalysisTaskTaggedPhotons::~AliAnalysisTaskTaggedPhotons()
167 {
168   // dtor
169   if(fOutputContainer && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
170     fOutputContainer->Clear() ; 
171     delete fOutputContainer ;
172   }
173   for(Int_t i=0;i<10;i++)
174     for(Int_t j=0;j<2;j++)
175       if(fPHOSEvents[i][j]){
176         delete fPHOSEvents[i][j] ;
177         fPHOSEvents[i][j]=0x0 ;   
178       }
179 }
180 //________________________________________________________________________
181 void AliAnalysisTaskTaggedPhotons::UserCreateOutputObjects()
182
183
184
185   // Create the outputs containers
186   if(fOutputContainer != NULL){
187     delete fOutputContainer;
188   }
189   fOutputContainer = new THashList();
190   fOutputContainer->SetOwner(kTRUE);
191   fOutputContainer->SetName(GetName()) ; 
192
193   //QA histograms
194   fOutputContainer->Add(new TH1F("hSelEvents","Event selection", 10,0.,10.)) ;
195   
196   //vertex distribution
197   fOutputContainer->Add(new TH1F("hNvertexTracks","N of primary tracks from the primary vertex",150,0.,150.));
198   fOutputContainer->Add(new TH1F("hZvertex","Z vertex",200,-50.,+50.));
199   fOutputContainer->Add(new TH2F("hTrackMult","Charged track multiplicity",100,0.,100.,250,0.,500.));
200   fOutputContainer->Add(new TH2F("hTrackEtaPhi","Charged track eta vs phi distribution",200,-2.,2.,200,0.,TMath::TwoPi()));
201   fOutputContainer->Add(new TH2F("hTrackEtaPt","Charged track eta vs pt distribution",200,-2.,2.,200,0.,50.));
202   
203   //centrality
204   fOutputContainer->Add(new TH1F("hCentrality","Ccentrality",100,0.,100.));
205   fOutputContainer->Add(new TH2F("hPHOSCentrality","PHOS vs centrality",100,0.,100.,100,0.,100.)); 
206   fOutputContainer->Add(new TH2F("hTOF","cluster TOF",200,0.,20.,300,-3.e-6,6.e-6));
207   
208   fOutputContainer->Add(new TH2F("hCluNXZM1","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
209   fOutputContainer->Add(new TH2F("hCluNXZM2","Clu (X,Z), M2"   ,64,0.5,64.5, 56,0.5,56.5));
210   fOutputContainer->Add(new TH2F("hCluNXZM3","Clu (X,Z), M3"   ,64,0.5,64.5, 56,0.5,56.5));
211   fOutputContainer->Add(new TH2F("hCluEXZM1","Clu E(X,Z), M1"  ,64,0.5,64.5, 56,0.5,56.5));
212   fOutputContainer->Add(new TH2F("hCluEXZM2","Clu E(X,Z), M2"  ,64,0.5,64.5, 56,0.5,56.5));
213   fOutputContainer->Add(new TH2F("hCluEXZM3","Clu E(X,Z), M3"  ,64,0.5,64.5, 56,0.5,56.5));
214
215   fOutputContainer->Add(new TH2F("hCluArea2M1","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
216   fOutputContainer->Add(new TH2F("hCluArea2M2","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
217   fOutputContainer->Add(new TH2F("hCluArea2M3","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
218   fOutputContainer->Add(new TH2F("hCluArea3M1","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
219   fOutputContainer->Add(new TH2F("hCluArea3M2","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
220   fOutputContainer->Add(new TH2F("hCluArea3M3","Clu (X,Z), M1"   ,64,0.5,64.5, 56,0.5,56.5));
221   
222   fOutputContainer->Add(new TH2F("hTofM1","TOF in mod1",200,-1.e-6,1.e-6,200,0.,20.)) ;
223   fOutputContainer->Add(new TH2F("hTofM2","TOF in mod2",200,-1.e-6,1.e-6,200,0.,20.)) ;
224   fOutputContainer->Add(new TH2F("hTofM3","TOF in mod3",200,-1.e-6,1.e-6,200,0.,20.)) ;
225
226   char cPID[4][5] ;
227   snprintf(cPID[0],5,"All") ;
228   snprintf(cPID[1],5,"Disp");
229   snprintf(cPID[2],5,"CPV") ;
230   snprintf(cPID[3],5,"Both"); 
231   
232  
233   const Int_t nPt=400 ;
234   const Double_t ptMax=40. ;
235   const Int_t nM=400 ;
236   const Double_t mMax=1. ;
237
238   const Int_t nCenBin=5;
239   for(Int_t cen=0; cen<nCenBin; cen++){
240
241   for(Int_t iPID=0; iPID<4; iPID++){
242     
243     //Inclusive spectra
244     fOutputContainer->Add(new TH1F(Form("hPhot_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
245     fOutputContainer->Add(new TH1F(Form("hPhot_Dist2_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
246     fOutputContainer->Add(new TH1F(Form("hPhot_Dist3_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
247   
248     fOutputContainer->Add(new TH1F(Form("hPhot_Area1_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
249     fOutputContainer->Add(new TH1F(Form("hPhot_Area2_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
250     fOutputContainer->Add(new TH1F(Form("hPhot_Area3_%s_cent%d",cPID[iPID],cen),"Spectrum of all reconstructed particles",nPt,0.,ptMax)) ;
251
252     for(Int_t itag=0; itag<18; itag++){
253       fOutputContainer->Add(new TH1F(Form("hPhot_nTagged%d_Area1_%s_cent%d",itag,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
254       fOutputContainer->Add(new TH1F(Form("hPhot_nTagged%d_Area2_%s_cent%d",itag,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
255       fOutputContainer->Add(new TH1F(Form("hPhot_nTagged%d_Area3_%s_cent%d",itag,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
256     }    
257     for(Int_t kind=1; kind<33; kind*=2){
258       fOutputContainer->Add(new TH1F(Form("hPi_Isolation%d_%s_cent%d",kind,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
259       fOutputContainer->Add(new TH1F(Form("hPhot_Isolation%d_%s_cent%d",kind,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
260       fOutputContainer->Add(new TH1F(Form("hPhot_Isolation%d_Area1_%s_cent%d",kind,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
261       fOutputContainer->Add(new TH1F(Form("hPhot_nTagged_Isolation%d_Area1_%s_cent%d",kind,cPID[iPID],cen),"Spectrum of all reconstructed particles, no PID",nPt,0.,ptMax)) ;
262     }
263   }
264     
265   
266   fOutputContainer->Add(new TH1F(Form("hTaggedMult_cent%d",cen),"Spectrum of multiply tagged photons",nPt,0.,ptMax)) ;
267
268   //Invariant mass distributions for fake corrections
269   
270   for(Int_t iPID=0; iPID<4; iPID++){
271     fOutputContainer->Add(new TH2F(Form("hInvM_Re_Emin1_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
272     fOutputContainer->Add(new TH2F(Form("hInvM_Re_Emin2_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
273     fOutputContainer->Add(new TH2F(Form("hInvM_Re_Emin3_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
274     fOutputContainer->Add(new TH2F(Form("hInvM_Mi_Emin1_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
275     fOutputContainer->Add(new TH2F(Form("hInvM_Mi_Emin2_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
276     fOutputContainer->Add(new TH2F(Form("hInvM_Mi_Emin3_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
277     
278     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin1_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
279     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin2_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
280     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin3_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
281     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin1_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
282     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin2_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
283     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Re_Emin3_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
284
285     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin1_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
286     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin2_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
287     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin3_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
288     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin1_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
289     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin2_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
290     fOutputContainer->Add(new TH2F(Form("hSingleInvM_Mi_Emin3_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
291
292     
293     
294   }  
295
296  
297   fOutputContainer->Add(new TH2F(Form("QA_Cone1_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
298   fOutputContainer->Add(new TH2F(Form("QA_Cone2_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
299   fOutputContainer->Add(new TH2F(Form("QA_Cone3_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
300   fOutputContainer->Add(new TH2F(Form("QA_PCone1_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
301   fOutputContainer->Add(new TH2F(Form("QA_PCone2_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
302   fOutputContainer->Add(new TH2F(Form("QA_PCone3_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
303   fOutputContainer->Add(new TH2F(Form("QA_Pi0Cone1_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
304   fOutputContainer->Add(new TH2F(Form("QA_Pi0Cone2_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
305   fOutputContainer->Add(new TH2F(Form("QA_Pi0Cone3_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
306   fOutputContainer->Add(new TH2F(Form("QA_Pi0PCone1_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
307   fOutputContainer->Add(new TH2F(Form("QA_Pi0PCone2_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
308   fOutputContainer->Add(new TH2F(Form("QA_Pi0PCone3_Tracks_cent%d",cen),"Two-photon inv. mass vs first photon pt",50,0.,50.,200,0.,100.)) ;
309   }//centrality
310   
311   //MC  
312   char partName[15][10] ;
313   snprintf(partName[0],10,"gamma") ;
314   snprintf(partName[1],10,"pi0");
315   snprintf(partName[2],10,"eta") ;
316   snprintf(partName[3],10,"omega"); 
317   snprintf(partName[4],10,"K0s"); 
318   snprintf(partName[5],10,"Kpm"); 
319   snprintf(partName[6],10,"pipm"); 
320   snprintf(partName[7],10,"n"); 
321   snprintf(partName[8],10,"nbar"); 
322   snprintf(partName[9],10,"p"); 
323   snprintf(partName[10],10,"pbar"); 
324   
325   
326   if(fIsMC){
327       
328       fOutputContainer->Add(new TH1F("hMCConversionRadius","Clusters without label",600,0.,600.)) ;
329       fOutputContainer->Add(new TH2F("hMCRecPi0Vtx","Secondary pi0s",100,0.,10.,600,0.,600.)) ;
330       fOutputContainer->Add(new TH2F("hMCRecEtaVtx","Secondary etas",100,0.,10.,600,0.,600.)) ;
331       fOutputContainer->Add(new TH2F("hMCRecOmegaVtx","Secondary etas",100,0.,10.,600,0.,600.)) ;
332       fOutputContainer->Add(new TH2F("hMCRecEtaprVtx","Secondary etas",100,0.,10.,600,0.,600.)) ;
333       fOutputContainer->Add(new TH2F("hMCRecK0sVtx","Secondary K0s",100,0.,10.,600,0.,600.)) ;
334       fOutputContainer->Add(new TH2F("hMCRecK0lVtx","Secondary K0l",100,0.,10.,600,0.,600.)) ;
335       fOutputContainer->Add(new TH2F("hMCGammaPi0MisConvR","Converted photons",400,0.,40.,600,0.,600.)) ;
336  
337   for(Int_t ipart=0; ipart<11; ipart++){  
338     fOutputContainer->Add(new TH2F(Form("hMC%s_ptrap",partName[ipart]),"Spectrum of primary photons",100,0.,10.,100,-2.,2.)) ;
339     fOutputContainer->Add(new TH2F(Form("hMC%s_ptphi",partName[ipart]),"Spectrum of primary photons",100,0.,10.,100,0.,TMath::TwoPi())) ;
340     fOutputContainer->Add(new TH2F(Form("hMC_%s_vertex",partName[ipart]),"vertex",nPt,0.,ptMax,150,0.,600.)) ;
341     for(Int_t cen=0; cen<nCenBin; cen++){
342        fOutputContainer->Add(new TH1F(Form("hMC_all_%s_cent%d",partName[ipart],cen),"Spectum (full rapifity)",nPt,0.,ptMax)) ;
343        fOutputContainer->Add(new TH1F(Form("hMC_unitEta_%s_cent%d",partName[ipart],cen),"Spectum, |y|<0.15",nPt,0.,ptMax)) ;
344        fOutputContainer->Add(new TH1F(Form("hMC_rap_%s_cent%d",partName[ipart],cen),"Rapidity",100,-5.,5.)) ;
345        fOutputContainer->Add(new TH1F(Form("hMC_phi_%s_cent%d",partName[ipart],cen),"Azimuthal angle",100,0.,TMath::TwoPi())) ;
346     }
347   }
348   for(Int_t cen=0; cen<nCenBin; cen++){
349   
350     fOutputContainer->Add(new TH2F(Form("LabelsNPrim_cent%d",cen),"vertex",nPt,0.,ptMax,20,0.,20.)) ;
351     fOutputContainer->Add(new TH1F(Form("LabelsGamma_cent%d",cen),"vertex",nPt,0.,ptMax)) ;
352     fOutputContainer->Add(new TH2F(Form("LabelsGammaE_cent%d",cen),"vertex",nPt,0.,ptMax,100,0.,2.)) ;
353     
354     
355        //Sort registered particles spectra according MC information
356        for(Int_t iPID=0; iPID<4; iPID++){
357          fOutputContainer->Add(new TH1F(Form("hMCRecPhoton_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
358          fOutputContainer->Add(new TH1F(Form("hMCRecE_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
359          fOutputContainer->Add(new TH1F(Form("hMCRecPbar_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
360          fOutputContainer->Add(new TH1F(Form("hMCRecNbar_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
361          fOutputContainer->Add(new TH1F(Form("hMCRecCharg_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
362          fOutputContainer->Add(new TH1F(Form("hMCRecNeutral_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
363          fOutputContainer->Add(new TH1F(Form("hMCRecK0s_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
364          fOutputContainer->Add(new TH1F(Form("hMCRecNoPRim_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
365          fOutputContainer->Add(new TH1F(Form("hMCRecUnknown_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. electrons", nPt,0.,ptMax )) ;
366
367          //Decay photons         
368          fOutputContainer->Add(new TH1F(Form("hMCRecPhotPi0_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
369          fOutputContainer->Add(new TH1F(Form("hMCRecPhotEta_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
370          fOutputContainer->Add(new TH1F(Form("hMCRecPhotOmega_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
371          fOutputContainer->Add(new TH1F(Form("hMCRecPhotOther_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
372          fOutputContainer->Add(new TH1F(Form("hMCRecPhotNoPrim_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax )) ;
373        
374    
375     
376          //MC tagging: reasons of partner loss etc.
377          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnStack_%s_cent%d",cPID[iPID],cen),"Decay photons with partner not in Stack", nPt,0.,ptMax )) ;
378          fOutputContainer->Add(new TH1F(Form("hMCDecWithFoundPartn_%s_cent%d",cPID[iPID],cen),"Decay photon with found partner", nPt,0.,ptMax )) ;
379          fOutputContainer->Add(new TH1F(Form("hMCDecWithWrongMass_%s_cent%d",cPID[iPID],cen),"Decay photon with wrong mass", nPt,0.,ptMax )) ;       
380          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAccept_%s_cent%d",cPID[iPID],cen),"Decay photon with parttner not in PHOS acc", nPt,0.,ptMax )) ;
381          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA1_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due geometry Fid. area. 1", nPt,0.,ptMax )) ;
382          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA2_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due geometry Fid. area. 2", nPt,0.,ptMax)) ;
383          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA3_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due geometry Fid. area. 3", nPt,0.,ptMax )) ;
384          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnConv_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due to conversion", nPt,0.,ptMax )) ;
385          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnEmin_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due to low energy", nPt,0.,ptMax )) ;
386          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnOther_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due unknown reason", nPt,0.,ptMax )) ;
387          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAll_%s_cent%d",cPID[iPID],cen),"Decay photons with partner missed due to any reason", nPt,0.,ptMax )) ;
388          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnNPhot_%s_cent%d",cPID[iPID],cen),"pi0 decay photon with non-photon partner", nPt,0.,ptMax )) ;
389
390        
391          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutEmin_%s_cent%d",cPID[iPID],cen),"Decay photons with rec. partner but failed Emin cut", nPt,0.,ptMax )) ;
392          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutNcell_%s_cent%d",cPID[iPID],cen),"Decay photons with rec. partner but failed Ncell cut", nPt,0.,ptMax )) ;
393          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutEcross_%s_cent%d",cPID[iPID],cen),"Decay photons with rec. partner but failed Ecross cut", nPt,0.,ptMax )) ;
394          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutM02_%s_cent%d",cPID[iPID],cen),"Decay photons with rec. partner but failed M02 cut", nPt,0.,ptMax )) ;
395          fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnDefCuts_%s_cent%d",cPID[iPID],cen),"Decay photons with rec. partner but failed default cuts", nPt,0.,ptMax )) ;
396          fOutputContainer->Add(new TH1F(Form("hMCDecWRecPartn_%s_cent%d",cPID[iPID],cen),"Decay photons with rec partner", nPt,0.,ptMax )) ;
397
398          fOutputContainer->Add(new TH2F(Form("hMC_InvM_Re_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
399          fOutputContainer->Add(new TH2F(Form("hMC_InvM_Re_Strict_%s_cent%d",cPID[iPID],cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
400        }    
401        fOutputContainer->Add(new TH2F(Form("hMCmass_cent%d",cen),"Mass with reconstructed decay partner",nM,0.,mMax,nPt,0.,ptMax )) ;                   
402     }
403     
404 /*   
405     fOutputContainer->Add(new TH1F(Form("hMCRecNoLabel_cent%d",cen),"Clusters without label",nPt,0.,ptMax)) ;
406     fOutputContainer->Add(new TH1F(Form("hMCConversionRadius_cent%d",cen),"Clusters without label",600,0.,600.)) ;
407     fOutputContainer->Add(new TH2F(Form("hMCRecPi0Vtx_cent%d",cen),"Secondary pi0s",100,0.,10.,600,0.,600.)) ;
408     fOutputContainer->Add(new TH2F(Form("hMCRecEtaVtx_cent%d",cen),"Secondary etas",100,0.,10.,600,0.,600.)) ;
409     fOutputContainer->Add(new TH2F(Form("hMCRecOmegaVtx_cent%d",cen),"Secondary etas",100,0.,10.,600,0.,600.)) ;
410     fOutputContainer->Add(new TH2F(Form("hMCRecEtaprVtx_cent%d",cen),"Secondary etas",100,0.,10.,600,0.,600.)) ;
411     fOutputContainer->Add(new TH2F(Form("hMCRecK0sVtx_cent%d",cen),"Secondary K0s",100,0.,10.,600,0.,600.)) ;
412     fOutputContainer->Add(new TH2F(Form("hMCRecK0lVtx_cent%d",cen),"Secondary K0l",100,0.,10.,600,0.,600.)) ;
413     fOutputContainer->Add(new TH2F(Form("hMCGammaPi0MisConvR_cent%d",cen),"Converted photons",400,0.,40.,600,0.,600.)) ;
414   
415   
416     fOutputContainer->Add(new TH2F(Form("hMCGammaPi0PrimMgg_cent%d",cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
417     fOutputContainer->Add(new TH2F(Form("hMCGammaPi0RecMgg_cent%d",cen),"Two-photon inv. mass vs first photon pt",nM,0.,mMax,nPt,0.,ptMax)) ;
418  
419     for(Int_t iPID=0; iPID<4; iPID++){    
420       fOutputContainer->Add(new TH1F(Form("hMCRecNoPrim_%s_cent%d",cPID[iPID],cen),"Reconstructed particles withour primary",nPt,0.,ptMax)) ;
421       fOutputContainer->Add(new TH1F(Form("hMCRecGamma_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: Gamma",nPt,0.,ptMax)) ;
422       fOutputContainer->Add(new TH1F(Form("hMCRecPhotConv_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: e+-",nPt,0.,ptMax)) ;
423       fOutputContainer->Add(new TH1F(Form("hMCRecPi0_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: pi0",nPt,0.,ptMax)) ;
424       fOutputContainer->Add(new TH1F(Form("hMCRecEta_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: eta",nPt,0.,ptMax)) ;
425       fOutputContainer->Add(new TH1F(Form("hMCRecOmega_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: Gamma",nPt,0.,ptMax)) ;
426       fOutputContainer->Add(new TH1F(Form("hMCRecEtapr_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: eta prime",nPt,0.,ptMax)) ;
427       fOutputContainer->Add(new TH1F(Form("hMCRecPbar_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: bar(p)",nPt,0.,ptMax)) ;
428       fOutputContainer->Add(new TH1F(Form("hMCRecNbar_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: bar(n)",nPt,0.,ptMax)) ;
429       fOutputContainer->Add(new TH1F(Form("hMCRecPipm_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: pipm",nPt,0.,ptMax)) ;
430       fOutputContainer->Add(new TH1F(Form("hMCRecN_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: n",nPt,0.,ptMax)) ;
431       fOutputContainer->Add(new TH1F(Form("hMCRecP_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: p",nPt,0.,ptMax)) ;
432       fOutputContainer->Add(new TH1F(Form("hMCRecKpm_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: K+-",nPt,0.,ptMax)) ;
433       fOutputContainer->Add(new TH1F(Form("hMCRecK0s_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: K0s",nPt,0.,ptMax)) ;
434       fOutputContainer->Add(new TH1F(Form("hMCRecK0l_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: K0l",nPt,0.,ptMax)) ;
435       fOutputContainer->Add(new TH1F(Form("hMCRecUnknownCh_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: K0l",nPt,0.,ptMax)) ;
436       fOutputContainer->Add(new TH1F(Form("hMCRecUnknownNeu_%s_cent%d",cPID[iPID],cen),"Reconstructed particles with primary: K0l",nPt,0.,ptMax)) ;
437
438       //Decay photons
439       fOutputContainer->Add(new TH1F(Form("hMCRecGammaDir_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, no primary",nPt,0.,ptMax)) ;
440       fOutputContainer->Add(new TH1F(Form("hMCRecGammaPi0_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
441       fOutputContainer->Add(new TH1F(Form("hMCRecGammaEta_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from eta",nPt,0.,ptMax)) ;
442       fOutputContainer->Add(new TH1F(Form("hMCRecGammaOmega_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from omega",nPt,0.,ptMax)) ;
443       fOutputContainer->Add(new TH1F(Form("hMCRecGammaOther_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from other",nPt,0.,ptMax)) ;
444       fOutputContainer->Add(new TH1F(Form("hMCRecPhotNoPrim_%s_cent%d",cPID[iPID],cen),"Spectrum of rec. photons", nPt,0.,ptMax)) ;
445     
446       //Pi0 decay photons
447       
448       //MC tagging: reasons of partner loss etc.
449        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnStack_cent%d",cen),"Decay photons with partner not in Stack", nPt,0.,ptMax)) ;
450        fOutputContainer->Add(new TH1F(Form("hMCDecWithFoundPartn_cent%d",cen),"Decay photon with found partner", nPt,0.,ptMax)) ;
451        fOutputContainer->Add(new TH1F(Form("hMCDecWithWrongMass_cent%d",cen),"Decay photon with wrong mass", nPt,0.,ptMax)) ;       
452        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAccept_cent%d",cen),"Decay photon with parttner not in PHOS acc", nPt,0.,ptMax)) ;
453        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA1_cent%d",cen),"Decay photons with partner missed due geometry Fid. area. 1", nPt,0.,ptMax)) ;
454        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA2_cent%d",cen),"Decay photons with partner missed due geometry Fid. area. 2", nPt,0.,ptMax)) ;
455        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAcceptFA3_cent%d",cen),"Decay photons with partner missed due geometry Fid. area. 3", nPt,0.,ptMax)) ;
456        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnConv_cent%d",cen),"Decay photons with partner missed due to conversion", nPt,0.,ptMax)) ;
457        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnEmin_cent%d",cen),"Decay photons with partner missed due to low energy", nPt,0.,ptMax)) ;
458        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnOther_cent%d",cen),"Decay photons with partner missed due unknown reason", nPt,0.,ptMax)) ;
459        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnAll_cent%d",cen),"Decay photons with partner missed due to any reason", nPt,0.,ptMax)) ;
460        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnNPhot_cent%d",cen),"pi0 decay photon with non-photon partner", nPt,0.,ptMax)) ;
461
462        
463        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutEmin_cent%d",cen),"Decay photons with rec. partner but failed Emin cut", nPt,0.,ptMax)) ;
464        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutNcell_cent%d",cen),"Decay photons with rec. partner but failed Ncell cut", nPt,0.,ptMax)) ;
465        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutEcross_cent%d",cen),"Decay photons with rec. partner but failed Ecross cut", nPt,0.,ptMax)) ;
466        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnCutM02_cent%d",cen),"Decay photons with rec. partner but failed M02 cut", nPt,0.,ptMax)) ;
467        fOutputContainer->Add(new TH1F(Form("hMCDecWMisPartnDefCuts_cent%d",cen),"Decay photons with rec. partner but failed default cuts", nPt,0.,ptMax)) ;
468        fOutputContainer->Add(new TH1F(Form("hMCDecWRecPartn_cent%d",cen),"Decay photons with rec partner", nPt,0.,ptMax)) ;
469        
470        fOutputContainer->Add(new TH2F(Form("hMCmass_cent%d",cen),"Mass with reconstructed decay partner",nM,0.,mMax,nPt,0.,ptMax)) ;                    
471       
472       
473       fOutputContainer->Add(new TH1F(Form("hMCRecGammaPi0Dalitz_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
474       fOutputContainer->Add(new TH1F(Form("hMCRecGammaPi0NoStack_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
475       fOutputContainer->Add(new TH1F(Form("hMCGammaPi02Gamma_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
476       fOutputContainer->Add(new TH1F(Form("hMCGammaPi0Rec_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
477       fOutputContainer->Add(new TH1F(Form("hMCGammaPi0RecSoft_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
478       fOutputContainer->Add(new TH1F(Form("hMCGammaPi0RecCells_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
479
480     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0Tagged_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
481     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0FakeTagged_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
482     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0TrueTagged_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
483     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MultyTagged_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
484     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisGeo_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
485     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisGeoFA1_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
486     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisGeoFA2_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
487     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisGeoFA3_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
488     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisConv_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
489     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisEmin_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
490     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisOther_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
491     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisFakePrim_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
492     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisFoundPrim_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
493     fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisNPhot_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;  
494
495     //all clusters fake tagged
496     fOutputContainer->Add(new TH1F(Form("hMCAllFakeTagged_%s_cent%d",cPID[iPID],cen),"Reconstructed gammas, from pi0",nPt,0.,ptMax)) ;
497
498    
499   }
500   fOutputContainer->Add(new TH1F(Form("hMCGammaPi0MisPartner_cent%d",cen),"Spectrum of missed partners",nPt,0.,ptMax)) ;
501   fOutputContainer->Add(new TH2F(Form("hMCGammaPi0MisPartnerEtaPhi_cent%d",cen),"Spectrum of missed partners",100,-0.2,0.2,100,4.5,5.6)) ;
502     }
503 */    
504   }
505
506   //If we work with MC, need to set Sumw2 - we will use weights
507   if(fIsMC){
508       for(Int_t i=0; i<fOutputContainer->GetSize();i++){
509         ((TH1*)fOutputContainer->At(i))->Sumw2() ; 
510       }
511   }
512     
513   
514   
515   for(Int_t i=0;i<10;i++)
516     for(Int_t j=0;j<5;j++)
517       fPHOSEvents[i][j]=0x0 ;    //Container for PHOS photons
518   
519
520   PostData(1, fOutputContainer);
521
522
523 }
524
525 //______________________________________________________________________________
526 void AliAnalysisTaskTaggedPhotons::UserExec(Option_t *) 
527 {
528   //Select events
529   //Select photons
530   //Fill QA histograms
531   //Fill Tagging histogsms
532
533   
534   const Double_t kEcrossCut=0.98 ;
535   const Double_t kTOFMaxCut= 100.e-9 ;  
536   const Double_t kTOFMinCut=-100.e-9 ;  
537   
538   // Event selection flags
539   //  FillHistogram("hSelEvents",0) ;
540     
541   AliVEvent* event = (AliVEvent*)InputEvent();
542   if(!event){
543     AliDebug(1,"No event") ;
544     PostData(1, fOutputContainer);
545     return;
546   }
547   FillHistogram("hSelEvents",1) ;
548
549   //MC stack init
550   fStack = (TClonesArray*)event->FindListObject(AliAODMCParticle::StdBranchName());
551   
552   //read geometry if not read yet
553   if(fPHOSgeom==0){
554     InitGeometry() ;
555   }
556   
557   if(!fUtils) 
558     fUtils = new AliAnalysisUtils();
559
560   Bool_t isMB = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kINT7)  ; 
561   Bool_t isPHI7 = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kPHI7);
562    
563   if((fIsMB && !isMB) || (!fIsMB && !isPHI7)){
564     PostData(1, fOutputContainer);
565     return;    
566   }
567   FillHistogram("hSelEvents",2) ;
568   
569   // Checks if we have a primary vertex
570   // Get primary vertices form AOD
571
572   Double_t vtx5[3];
573   vtx5[0] = event->GetPrimaryVertex()->GetX();
574   vtx5[1] = event->GetPrimaryVertex()->GetY();
575   vtx5[2] = event->GetPrimaryVertex()->GetZ();
576
577   FillHistogram("hNvertexTracks",event->GetPrimaryVertex()->GetNContributors());
578   FillHistogram("hZvertex"      ,vtx5[2]);
579   if (TMath::Abs(vtx5[2]) > 10. ){
580     PostData(1, fOutputContainer);
581     return ;
582   }
583     
584   FillHistogram("hSelEvents",3) ;
585   //Vtx class z-bin
586   Int_t zvtx = TMath::Min(9,Int_t((vtx5[2]+10.)/2.)) ; 
587
588   
589   
590 //  if (event->IsPileupFromSPD()){
591 //    PostData(1, fOutputContainer);
592 //    return ;
593 //  }
594   
595   if(!fUtils->IsVertexSelected2013pA(event)){
596     PostData(1, fOutputContainer);
597     return ;
598   }
599   FillHistogram("hSelEvents",4) ;
600   
601   if(fUtils->IsPileUpEvent(event)){
602     PostData(1, fOutputContainer);
603     return ;
604   }
605   FillHistogram("hSelEvents",5) ;
606   
607   //centrality
608   AliCentrality *centrality = event->GetCentrality();
609   if( centrality )
610     fCentrality=centrality->GetCentralityPercentile("V0M");
611   else {
612     AliError("Event has 0x0 centrality");
613     fCentrality = -1.;
614   }
615   FillHistogram("hCentrality",fCentrality) ;
616
617   if(fCentrality<0. || fCentrality>=100.){
618     PostData(1, fOutputContainer);
619     return ;
620   }
621   fCentBin = (Int_t)(fCentrality/20.) ; 
622
623   FillHistogram("hSelEvents",6) ;
624   
625   
626   //Calculate charged multiplicity
627   Int_t trackMult = 0;
628   if(fTrackEvent)
629     fTrackEvent->Clear() ;
630   else
631     fTrackEvent = new TClonesArray("AliCaloPhoton",event->GetNumberOfTracks()) ;
632
633   for (Int_t i=0;i<event->GetNumberOfTracks();++i) {
634     AliAODTrack *track = (AliAODTrack*)event->GetTrack(i) ;
635     if(!track->IsHybridGlobalConstrainedGlobal())
636       continue ;
637     if(TMath::Abs(track->Eta())< 0.9){
638       if(trackMult>=fTrackEvent->GetSize())
639         fTrackEvent->Expand(2*trackMult) ;
640       new ((*fTrackEvent)[trackMult]) AliCaloPhoton(track->Px(),track->Py(),track->Pz(),track->P());
641       trackMult++;
642      FillHistogram("hTrackEtaPhi",track->Eta(),track->Phi()) ;
643      FillHistogram("hTrackEtaPt",track->Eta(),track->Pt()) ;
644     }
645   }
646   FillHistogram("hTrackMult",fCentrality,trackMult+0.5) ;
647
648   if(!fPHOSEvents[zvtx][fCentBin]) 
649     fPHOSEvents[zvtx][fCentBin]=new TList() ;
650   fCurrentMixedList = fPHOSEvents[zvtx][fCentBin] ;
651
652    const Double_t rcut=1. ; //cut on vertex to consider particle as "primary" 
653  
654   //---------Select photons-------------------
655   Int_t multClust = event->GetNumberOfCaloClusters();
656   if(!fPHOSEvent)
657     fPHOSEvent   = new TClonesArray("AliCaloPhoton",multClust);
658   else
659     fPHOSEvent->Clear() ;
660   Int_t inList = 0; //counter of caloClusters
661
662   for (Int_t i=0; i<multClust; i++) {
663     AliVCluster * clu = event->GetCaloCluster(i);
664     
665     if(!clu->IsPHOS())
666       continue ; 
667     
668     if(clu->E()<0.1) 
669       continue;
670
671     if(clu->GetNCells()<3)
672       continue ;          
673     
674     if(clu->GetM02()<0.2) 
675       continue ;          
676   
677     if(clu->GetMCEnergyFraction()>kEcrossCut) //Ecross cut, should be filled with Tender
678      continue ;    
679
680     Float_t pos[3] ;
681     clu->GetPosition(pos) ;
682     Int_t fidArea=GetFiducialArea(pos) ;
683 //    if(fidArea==0) //Bad cell
684 //      continue; 
685     
686     TVector3 global1(pos) ;
687     Int_t relId[4] ;
688     fPHOSgeom->GlobalPos2RelId(global1,relId) ;
689     Int_t mod  = relId[0] ;
690     Int_t cellX = relId[2];
691     Int_t cellZ = relId[3] ;
692     
693     FillHistogram("hTOF",clu->E(),clu->GetTOF()) ;
694     FillHistogram(Form("hTofM%d",mod),clu->GetTOF(),clu->E()) ;
695     if(clu->GetTOF() < kTOFMinCut || clu->GetTOF() > kTOFMaxCut)
696       continue ;          
697     
698 //    if(clu->GetDistanceToBadChannel()<2.5)
699 //      continue ;
700
701     
702     FillHistogram(Form("hCluNXZM%d",mod),cellX,cellZ,1.);
703     FillHistogram(Form("hCluEXZM%d",mod),cellX,cellZ,clu->E());
704     if(fidArea>1){
705       FillHistogram(Form("hCluArea2M%d",mod),cellX,cellZ,1.);
706       if(fidArea>2){
707          FillHistogram(Form("hCluArea3M%d",mod),cellX,cellZ,1.);
708       }
709     }
710     
711     TLorentzVector momentum ;
712     clu->GetMomentum(momentum, vtx5);
713     AliCaloPhoton *p = new ((*fPHOSEvent)[inList]) AliCaloPhoton(momentum.Px(),momentum.Py(),momentum.Pz(),clu->E() );
714     inList++;
715
716     Int_t isolation = EvalIsolation(&momentum,kTRUE) ;
717     p->SetIsolationTag(isolation) ;
718     
719     p->SetDistToBad((Int_t)(1.+clu->GetDistanceToBadChannel()/2.2));
720     
721     p->SetTagInfo(0); //Strict PID pi0 partner not found
722     p->SetTagged(kFALSE);   //Reconstructed pairs found
723     
724     p->SetFiducialArea(fidArea) ;
725
726     if(fIsMC){    
727        //This is primary entered PHOS
728        FillHistogram(Form("LabelsNPrim_cent%d",fCentBin),clu->E(),float(clu->GetNLabels())) ;
729        Int_t primLabel=clu->GetLabelAt(0) ; //FindPrimary(clu,sure) ;
730        //Look what particle left vertex
731        if(primLabel>-1){
732          AliAODMCParticle * prim = (AliAODMCParticle*)fStack->At(primLabel) ;
733          Int_t iparent=primLabel;
734          AliAODMCParticle * parent = prim;
735          Double_t r2=prim->Xv()*prim->Xv()+prim->Yv()*prim->Yv() ;
736          while((r2 > rcut*rcut) && (iparent>-1)){
737            iparent=parent->GetMother();
738            parent=(AliAODMCParticle*)fStack->At(iparent);
739            r2=parent->Xv()*parent->Xv()+parent->Yv()*parent->Yv() ;
740          }
741          p->SetPrimary(primLabel) ;
742          p->SetPrimaryAtVertex(iparent) ;
743          p->SetWeight(PrimaryParticleWeight(parent)) ;
744        }
745        else{
746          p->SetPrimary(-1); //Primary index    
747          p->SetPrimaryAtVertex(-1) ;
748          p->SetWeight(1.) ;
749        }
750     }
751     else{  
752       p->SetPrimary(-1); //Primary index    
753       p->SetPrimaryAtVertex(-1) ;
754       p->SetWeight(1.) ;
755     }
756     //PID criteria
757     p->SetDispBit(clu->Chi2()<2.5) ;
758     p->SetTOFBit(TestTOF(clu->GetTOF(),clu->E())) ;
759     p->SetCPVBit(clu->GetEmcCpvDistance()>2.5) ;      
760   }
761   FillHistogram("hPHOSCentrality",fCentrality,inList+0.5) ;
762   
763   
764   FillMCHistos() ;
765   FillTaggingHistos() ;
766
767   //Remove old events
768   fCurrentMixedList->AddFirst(fPHOSEvent);
769   fPHOSEvent=0x0 ;
770   if(fCurrentMixedList->GetSize() > 10){
771     TClonesArray *tmp = static_cast <TClonesArray*> (fCurrentMixedList->Last());
772     fCurrentMixedList->Remove(tmp);
773     delete tmp;
774   }
775   
776   PostData(1, fOutputContainer);
777
778 }
779 //________________________________________________
780 void AliAnalysisTaskTaggedPhotons::FillMCHistos(){
781    
782   //MC info about this particle
783   if(!fIsMC)
784     return ;
785   const Double_t rcut=1. ; //cut on vertex to consider particle as "primary" 
786   const Double_t phiMin=260.*TMath::Pi()/180. ;
787   const Double_t phiMax=320.*TMath::Pi()/180. ;
788   
789   Int_t nPrim = fStack->GetEntriesFast() ;
790   //Fill Primary particl yields
791   
792   for(Int_t i=0;i<nPrim;i++){
793     AliAODMCParticle * prim = (AliAODMCParticle*)fStack->At(i) ;
794     Double_t r2=prim->Xv()*prim->Xv()+prim->Yv()*prim->Yv() ;
795     if(r2>rcut*rcut)
796       continue ;
797
798     Int_t pdg=prim->GetPdgCode() ;    
799     char partName[30] ;
800     if(pdg == 111)
801       snprintf(partName,30,"pi0") ;
802     else
803       if(pdg == 221)
804         snprintf(partName,30,"eta") ;
805       else
806         if(pdg == 22)
807            snprintf(partName,30,"gamma") ;
808         else
809           if(pdg == 310)
810              snprintf(partName,30,"K0s") ;
811           else
812             if(abs(pdg) == 321)
813               snprintf(partName,30,"Kpm") ;
814             else
815               if(abs(pdg) == 211)
816                 snprintf(partName,30,"pipm") ;
817               else  
818                 if(abs(pdg) == 2212)
819                   snprintf(partName,30,"p") ;
820                 else  
821                   if(abs(pdg) ==-2212)
822                     snprintf(partName,30,"pbar") ;
823                   else  
824                     if(abs(pdg) == 2112)
825                       snprintf(partName,30,"n") ;
826                     else  
827                       if(abs(pdg) ==-2112)
828                         snprintf(partName,30,"nbar") ;
829                       else  
830                         continue ;                    
831
832     //Primary particle
833     Double_t phi=prim->Phi() ;
834     while(phi<0.)phi+=TMath::TwoPi() ;
835     while(phi>TMath::TwoPi())phi-=TMath::TwoPi() ;
836     Double_t pt=prim->Pt() ;
837
838     //Total number of pi0 with creation radius <1 cm
839     Double_t w = PrimaryParticleWeight(prim) ;  
840     FillHistogram(Form("hMC_all_%s_cent%d",partName,fCentBin),pt,w) ;
841     if(TMath::Abs(prim->Y())<0.13){
842       FillHistogram(Form("hMC_phi_%s_cent%d",partName,fCentBin),phi,w) ;
843       if(phi>phiMin && phi<phiMax)
844         FillHistogram(Form("hMC_unitEta_%s_cent%d",partName,fCentBin),pt,w) ;
845     }
846
847     FillHistogram(Form("hMC_rap_%s_cent%d",partName,fCentBin),prim->Y(),w) ;
848     //Some additional QA
849     if(pdg == 111){
850        FillHistogram("hMCpi0_ptrap",pt,prim->Y(),w) ;   
851        FillHistogram("hMCpi0_ptphi",pt,phi,w) ;   
852     }
853     if(pdg == 22){
854        FillHistogram("hMCgamma_ptrap",pt,prim->Y(),w) ;   
855        FillHistogram("hMCgamma_ptphi",pt,phi,w) ;   
856     }
857     
858   }
859   
860  
861   
862   //Clussify reconstructed clusters
863   //First - photons (from vertex) and contaminations
864   //Second - photons from different sources
865   //Third - photons from pi0s - missed for different reasons
866   
867   const Int_t n=fPHOSEvent->GetEntriesFast() ;
868   for(Int_t i=0;i<n;i++){
869     AliCaloPhoton *p = static_cast<AliCaloPhoton*>(fPHOSEvent->At(i));
870     Int_t label=p->GetPrimary() ;
871     if(label<0){ //No label!
872       FillHistogram("hMCRecNoLabel",p->Pt(),p->GetWeight());
873       continue ;
874     }     
875
876     
877     AliAODMCParticle * prim = (AliAODMCParticle*)fStack->At(p->GetPrimary()) ;
878     //Look what particle left virtex
879     Int_t iparent=p->GetPrimary();
880     AliAODMCParticle * parent = prim;
881     while(parent->Xv()*parent->Xv()+parent->Yv()*parent->Yv() > rcut*rcut){
882         iparent=parent->GetMother();
883         if(iparent<0)
884           break ;
885         parent = (AliAODMCParticle*)fStack->At(iparent) ;       
886       }
887       Int_t parentPDG=parent->GetPdgCode() ;     
888       switch(parentPDG){
889         case 22: //electron/positron conversion
890           FillPIDHistograms("hMCRecPhoton",p);  //Reconstructed with photon from conversion primary
891           break ;
892         case  11:
893         case -11: //electron/positron conversion
894           FillPIDHistograms("hMCRecE",p);  //Reconstructed with photon from conversion primary
895           break ;
896         case -2212:
897           FillPIDHistograms("hMCRecPbar",p);  //Reconstructed with photon from antibaryon annihilation
898           break ;         
899         case -2112: //antineutron & antiproton conversion
900           FillPIDHistograms("hMCRecNbar",p);  //Reconstructed with photon from antibaryon annihilation
901           break ;         
902         case  211:
903         case -211:
904         case 2212:
905         case  321:
906         case -321:
907           FillPIDHistograms("hMCRecCharg",p);  //Reconstructed with photon from conversion primary
908           break ;
909         case 310:
910           FillPIDHistograms("hMCRecK0s",p);  //Reconstructed with photon from conversion primary
911           break ;
912         case 2112: //antineutron & antiproton conversion
913         case 130:
914           FillPIDHistograms("hMCRecNeutral",p);  //Reconstructed with photon from antibaryon annihilation
915           break ;
916         case -1: //direct photon or no primary
917           FillPIDHistograms("hMCRecNoPRim",p);
918           break ;         
919         default:  
920           printf("Unknown PDG: %d \n",parentPDG) ;
921           FillPIDHistograms("hMCRecUnknown",p);
922           break ;
923       }  
924     
925     
926       //Now classify decay photon
927       if(parentPDG==22){
928         Int_t iGrandParent=parent->GetMother();
929         if(iGrandParent<0 || iGrandParent>=fStack->GetEntriesFast()){
930           FillPIDHistograms("hMCRecPhotNoPrim",p);
931           continue ;      
932         }
933         AliAODMCParticle * grandParent = (AliAODMCParticle*)fStack->At(iGrandParent) ;  
934         Int_t grandParentPDG=grandParent->GetPdgCode() ;     
935         switch(grandParentPDG){
936         case 111: //pi0
937           FillPIDHistograms("hMCRecPhotPi0",p);
938           break ;               
939         case 221: //eta decay
940           FillPIDHistograms("hMCRecPhotEta",p);
941           break ;  
942         case 223: //omega meson decay
943           FillPIDHistograms("hMCRecPhotOmega",p);
944           break ;
945         default:
946           FillPIDHistograms("hMCRecPhotOther",p);
947         }
948         //--------consider pi0 decays--------------------
949         if(grandParentPDG==111){
950           //First find which daughter is our cluster
951           //iparent - index of curent photon      
952           Int_t ipartner=grandParent->GetDaughter(0) ;
953           if(ipartner==iparent){//look for other
954             if(grandParent->GetNDaughters()>1){
955               ipartner=grandParent->GetDaughter(1);  
956             }
957             else{
958               ipartner=-1 ;
959             }
960           }
961         
962           //There is no partner in stack
963           if(ipartner==-1){
964             FillPIDHistograms("hMCDecWMisPartnStack",p) ;
965           }
966           else{
967             AliAODMCParticle * partner = (AliAODMCParticle *)fStack->At(ipartner);
968             //Check if partner is registered and made correct mass
969             //If not - trace the reason
970             AliCaloPhoton *pp = 0x0 ;
971           
972             for(Int_t ii=0;ii<n;ii++){
973               if(i==ii) continue; 
974               AliCaloPhoton * tmp = static_cast<AliCaloPhoton*>(fPHOSEvent->At(ii));
975               Int_t ipartnPrim = tmp->GetPrimary() ;
976               while(ipartnPrim>-1){
977                 if(ipartnPrim==ipartner)
978                   break ;
979                 ipartnPrim = ((AliAODMCParticle *)fStack->At(ipartnPrim))->GetMother();
980               }
981               if(ipartnPrim==ipartner){
982                 pp=tmp ;
983                 break ;
984               }
985             }
986
987             if(pp){
988               //Partner reconstructed, but did not pass cuts
989                 FillPIDHistograms("hMCDecWRecPartn",p) ;        
990                 Double_t invMass=(*p+ *pp).M() ;
991                 FillHistogram("hMCmass",invMass,p->Pt(),p->GetWeight()) ;
992                 if(IsInPi0Band(invMass,p->Pt())){
993                   FillPIDHistograms("hMCDecWithFoundPartn",p) ;
994                 }
995                 else{
996                   FillPIDHistograms("hMCDecWithWrongMass",p) ;
997                 }
998             }
999             else{//Partner not reconstructed
1000               if(partner->GetPdgCode()==22){
1001                 Bool_t isPartnerLost=kFALSE; //If partner is lost for some reason
1002                 
1003                 //Check if partner miss PHOS
1004                 Int_t modulenum ;
1005                 Double_t ztmp=0.,xtmp=0. ;
1006                 Double_t vtx[3]={partner->Xv(),partner->Yv(),partner->Zv()} ;
1007                 Bool_t impact=fPHOSgeom->ImpactOnEmc(vtx,partner->Theta(),partner->Phi(),modulenum,ztmp,xtmp) ;
1008                 
1009                 if(impact){//still check bad map
1010                   Int_t relId[4] ;
1011                   fPHOSgeom->RelPosToRelId(modulenum,xtmp,ztmp,relId) ;
1012                   if ( !IsGoodChannel(modulenum,relId[2],relId[3]) ) {
1013                      impact=kFALSE ;                
1014                   }  
1015                 }
1016  
1017                 if(!impact){ //this photon cannot hit PHOS                
1018                   FillPIDHistograms("hMCDecWMisPartnAccept",p) ;  //Spectrum of tagged with missed partner
1019                   Int_t iFidArea = p->GetFiducialArea(); 
1020                   if(iFidArea>0){
1021                     FillPIDHistograms("hMCDecWMisPartnAcceptFA1",p) ;  //Spectrum of tagged with missed partner
1022                     if(iFidArea>1){
1023                       FillPIDHistograms("hMCDecWMisPartnAcceptFA2",p) ;  //Spectrum of tagged with missed partner
1024                       if(iFidArea>2){
1025                         FillPIDHistograms("hMCDecWMisPartnAcceptFA3",p) ;  //Spectrum of tagged with missed partner
1026                       }
1027                     }
1028                   }
1029                   isPartnerLost=kTRUE;
1030                 }
1031                 
1032                 if(!isPartnerLost){
1033                   //this photon is converted before it is registered
1034                   if(partner->GetNDaughters()>0){
1035                     AliAODMCParticle* tmpP=(AliAODMCParticle*)fStack->At(partner->GetDaughter(0));
1036                     if(tmpP->Xv()*tmpP->Xv()+tmpP->Yv()*tmpP->Yv()<450.*450.){  
1037                       FillPIDHistograms("hMCDecWMisPartnConv",p) ;  //Spectrum of tagged with missed partner
1038                       isPartnerLost=kTRUE;
1039                     }
1040                   }
1041                 }
1042                 if(!isPartnerLost && 
1043                    partner->E()<0.3){ //energy is not enough to be registered by PHOS
1044                   FillPIDHistograms("hMCDecWMisPartnEmin",p) ;  //Spectrum of tagged with missed partner
1045                   isPartnerLost=kTRUE;
1046                 }
1047                 if(!isPartnerLost){ //Reason not found!!!!!                               
1048                   FillPIDHistograms("hMCDecWMisPartnOther",p);
1049                 }
1050                 else{//Sum of all missed partners
1051                   FillPIDHistograms("hMCDecWMisPartnAll",p);
1052                 }
1053               }//Partner - photon
1054               else{//partner not photon
1055                 FillPIDHistograms("hMCDecWMisPartnNPhot",p);                
1056               }
1057               
1058             }//Partner not reconstructed
1059           }//Partner in stack
1060         }//photon from pi0 decay
1061       }//photon
1062     } //PHOS clusters    
1063    
1064 }
1065     
1066 //________________________________________________
1067 void AliAnalysisTaskTaggedPhotons::FillTaggingHistos(){
1068   //Fill all necessary histograms
1069
1070
1071  //First fill invariant mass distrubutions and mark tagged photons
1072   //Invariant Mass analysis
1073   const Int_t n=fPHOSEvent->GetEntriesFast() ;
1074   for(Int_t i=0;i<n-1;i++){
1075     AliCaloPhoton *p1 = static_cast<AliCaloPhoton*>(fPHOSEvent->At(i));
1076     for(Int_t j = i+1 ; j < n ; j++) {
1077       AliCaloPhoton * p2 = static_cast<AliCaloPhoton*>(fPHOSEvent->At(j));
1078       
1079       Double_t invMass = (*p1 + *p2).M();   
1080
1081       if((p1->E()>0.1) && (p2->E()>0.1)){
1082         FillPIDHistograms("hInvM_Re_Emin1",p1,p2,invMass,kTRUE) ;
1083         if((p1->E()>0.2) && (p2->E()>0.2)){
1084           FillPIDHistograms("hInvM_Re_Emin2",p1,p2,invMass,kTRUE) ;
1085           if((p1->E()>0.3) && (p2->E()>0.3)){
1086             FillPIDHistograms("hInvM_Re_Emin3",p1,p2,invMass,kTRUE) ;
1087      
1088             //Fill izolated pi0s
1089             Double_t nsigma1 = IsInPi0Band(invMass,p1->Pt()) ; //in band with n sigmas
1090             Double_t nsigma2 = IsInPi0Band(invMass,p2->Pt()) ; //in band with n sigmas
1091             if(nsigma1<2 || nsigma2<2){ //2 sigma band
1092               TLorentzVector pi0=*p1+*p2 ;
1093               Int_t isolation=EvalIsolation(&pi0,0) ;
1094               for(Int_t kind=1; kind<33; kind*=2){
1095                  if((isolation&kind)){
1096                    FillHistogram(Form("hPi_Isolation%d",kind),pi0.Pt()) ;
1097                  }
1098               }
1099             }
1100             
1101           }
1102         }
1103       }
1104       
1105       
1106       if(p2->E()>0.1){
1107         FillPIDHistograms("hSingleInvM_Re_Emin1",p1,invMass) ;
1108         if(p2->E()>0.2){
1109           FillPIDHistograms("hSingleInvM_Re_Emin2",p1,invMass) ;
1110           if(p2->E()>0.3){
1111             FillPIDHistograms("hSingleInvM_Re_Emin3",p1,invMass) ;
1112           }
1113         }
1114       }
1115         
1116       if(p1->E()>0.1){
1117         FillPIDHistograms("hSingleInvM_Re_Emin1",p2,invMass) ;
1118         if(p1->E()>0.2){
1119           FillPIDHistograms("hSingleInvM_Re_Emin2",p2,invMass) ;
1120           if(p1->E()>0.3){
1121             FillPIDHistograms("hSingleInvM_Re_Emin3",p2,invMass) ;
1122           }
1123         }
1124       }
1125       if(TestPID(3, p2)){
1126         if(p2->E()>0.1){
1127           FillPIDHistograms("hSingleInvM_Re_Emin1_Strict",p1,invMass) ;
1128           if(p2->E()>0.2){
1129             FillPIDHistograms("hSingleInvM_Re_Emin2_Strict",p1,invMass) ;
1130             if(p2->E()>0.3){
1131               FillPIDHistograms("hSingleInvM_Re_Emin3_Strict",p1,invMass) ;
1132             }
1133           }
1134         }
1135       }
1136       if(TestPID(3, p1)){
1137         if(p1->E()>0.1){
1138           FillPIDHistograms("hSingleInvM_Re_Emin1_Strict",p2,invMass) ;
1139           if(p1->E()>0.1){
1140             FillPIDHistograms("hSingleInvM_Re_Emin2_Strict",p2,invMass) ;
1141             if(p1->E()>0.3){
1142               FillPIDHistograms("hSingleInvM_Re_Emin3_Strict",p2,invMass) ;
1143             }
1144           }
1145         }
1146       }
1147       if(IsSameParent(p1,p2)==111){
1148         FillPIDHistograms("hMC_InvM_Re",p1,invMass) ;
1149         FillPIDHistograms("hMC_InvM_Re",p2,invMass) ;
1150         if(TestPID(3, p2)){
1151           FillPIDHistograms("hMC_InvM_Re_Strict",p1,invMass) ;
1152         }
1153         if(TestPID(3, p1)){
1154           FillPIDHistograms("hMC_InvM_Re_Strict",p2,invMass) ;
1155         }
1156       }
1157
1158       //Tagging: 1,2,3 sigma
1159       //Emin=100,200,300 Mev
1160       //IsInPi0Band(mass, Ptphoton, type Emin cut
1161       Int_t tag1=0 ;
1162       for(Int_t eminType=0; eminType<3; eminType++){
1163         if(p2->E()>0.1*(eminType+1)){
1164           //Set corresponding bit
1165           Double_t nsigma = IsInPi0Band(invMass,p1->Pt()) ; //in band with n sigmas
1166           for(Int_t isigma=0; isigma<3; isigma++){
1167             if(nsigma<1+isigma){
1168               tag1|= (1 << (3*eminType+isigma)) ;
1169               if(TestPID(3, p2))
1170                 tag1|= (1 << (3*eminType+isigma+9)) ;
1171             }
1172           }
1173         }
1174       }
1175       p1->SetTagInfo(tag1) ;
1176       Int_t tag2=0 ;
1177       for(Int_t eminType=0; eminType<3; eminType++){
1178         if(p1->E()>0.1*(eminType+1)){
1179           //Set corresponding bit
1180           Double_t nsigma = IsInPi0Band(invMass,p2->Pt()) ; //in band with n sigmas
1181           for(Int_t isigma=0; isigma<3; isigma++){
1182             if(nsigma<1+isigma){
1183               tag2|= (1 << (3*eminType+isigma)) ;
1184               if(TestPID(3, p2))
1185                 tag2|= (1 << (3*eminType+isigma+9)) ;
1186             }
1187           }
1188         }
1189       }
1190       p2->SetTagInfo(tag2) ;
1191       
1192       if(tag1 & (1<<7)){ //2 sigma, Emin=0.3: default tagging
1193         if(p1->IsTagged()){//Multiple tagging
1194           FillHistogram(Form("hTaggedMult_cent%d",fCentBin),p1->Pt(),p1->GetWeight());
1195         }  
1196         p1->SetTagged(kTRUE) ;
1197       }
1198       if(tag2 & (1<<7)){ //2 sigma, Emin=0.3: default tagging
1199         if(p2->IsTagged()){//Multiple tagging
1200           FillHistogram(Form("hTaggedMult_cent%d",fCentBin),p2->Pt(),p2->GetWeight());
1201         }  
1202         p2->SetTagged(kTRUE) ;
1203       }      
1204     }
1205   }
1206   
1207   
1208   
1209   //Single particle histgams
1210   for(Int_t i=0;i<n;i++){
1211     AliCaloPhoton *p = static_cast<AliCaloPhoton*>(fPHOSEvent->At(i));
1212
1213     Int_t isolation = p->GetIsolationTag();
1214
1215     //Inclusive spectra
1216     FillPIDHistograms("hPhot",p) ;
1217       
1218     if(p->DistToBad()>1){
1219       FillPIDHistograms("hPhot_Dist2",p) ;
1220       if(p->DistToBad()>2){
1221         FillPIDHistograms("hPhot_Dist3",p) ;
1222       }
1223     }
1224       
1225       
1226     for(Int_t kind=1; kind<33; kind*=2){
1227       if((isolation&kind)){
1228         FillPIDHistograms(Form("hPhot_Isolation%d",kind),p) ;
1229       }
1230     }
1231       
1232     Int_t iFidArea = p->GetFiducialArea(); 
1233     if(iFidArea>0){
1234       FillPIDHistograms("hPhot_Area1",p) ;
1235       for(Int_t kind=1; kind<33; kind*=2){
1236         if((isolation&kind)){
1237           FillPIDHistograms(Form("hPhot_Isolation%d_Area1",kind),p) ;
1238         }
1239       }
1240
1241       //Fill taggings with 
1242       //3 Emin cuts
1243       //Default Emin, 1,2,3 sigmas
1244       //strict and loose PID cut on partner
1245       Int_t tag=p->GetTagInfo() ;
1246       for(Int_t ibit=0; ibit<18; ibit++){
1247         if((tag & (1<<ibit))==0){ 
1248           FillPIDHistograms(Form("hPhot_nTagged%d_Area1",ibit),p) ;
1249         }
1250       }
1251
1252       if(iFidArea>1){
1253         FillPIDHistograms("hPhot_Area2",p) ;
1254         for(Int_t ibit=0; ibit<18; ibit++){
1255           if((tag & (1<<ibit))==0){ 
1256             FillPIDHistograms(Form("hPhot_nTagged%d_Area2",ibit),p) ;
1257           }
1258         }
1259         if(iFidArea>2){
1260           FillPIDHistograms("hPhot_Area3",p) ;
1261           for(Int_t ibit=0; ibit<18; ibit++){
1262             if((tag & (1<<ibit))==0){ 
1263               FillPIDHistograms(Form("hPhot_nTagged%d_Area3",ibit),p) ;
1264             }
1265           }
1266         }
1267       }
1268     }
1269   } 
1270   
1271    //Fill Mixed InvMass distributions:
1272   TIter nextEv(fCurrentMixedList) ;
1273   for(Int_t i=0;i<n;i++){
1274     AliCaloPhoton *p1 = static_cast<AliCaloPhoton*>(fPHOSEvent->At(i));
1275     while(TClonesArray * event2 = static_cast<TClonesArray*>(nextEv())){
1276       Int_t nPhotons2 = event2->GetEntriesFast() ;
1277       for(Int_t j=0; j < nPhotons2 ; j++){
1278         AliCaloPhoton * p2 = static_cast<AliCaloPhoton*>(event2->At(j)) ;
1279         Double_t invMass = (*p1 + *p2).M();
1280
1281         if((p1->E()>0.1) && (p2->E()>0.1)){
1282           FillPIDHistograms("hInvM_Mi_Emin1",p1,p2,invMass,kFALSE) ;
1283           if((p1->E())>0.2 && (p2->E()>0.2)){
1284             FillPIDHistograms("hInvM_Mi_Emin2",p1,p2,invMass,kFALSE) ;
1285             if((p1->E())>0.3 && (p2->E()>0.3)){
1286               FillPIDHistograms("hInvM_Mi_Emin3",p1,p2,invMass,kFALSE) ;
1287             }
1288           }
1289         }
1290         
1291         
1292         if(p2->E()>0.1){
1293           FillPIDHistograms("hSingleInvM_Mi_Emin1",p1,invMass) ;
1294           if(p2->E()>0.2){
1295             FillPIDHistograms("hSingleInvM_Mi_Emin2",p1,invMass) ;
1296             if(p2->E()>0.3){
1297               FillPIDHistograms("hSingleInvM_Mi_Emin3",p1,invMass) ;
1298             }
1299           }
1300         }
1301         if(TestPID(3, p2)){
1302           if(p2->E()>0.1){
1303             FillPIDHistograms("hSingleInvM_Mi_Emin1_Strict",p1,invMass) ;
1304             if(p2->E()>0.2){
1305               FillPIDHistograms("hSingleInvM_Mi_Emin2_Strict",p1,invMass) ;
1306               if(p2->E()>0.3){
1307                 FillPIDHistograms("hSingleInvM_Mi_Emin3_Strict",p1,invMass) ;
1308               }
1309             }
1310           }
1311         }
1312         
1313         if(p1->E()>0.1){
1314           FillPIDHistograms("hSingleInvM_Mi_Emin1",p2,invMass) ;
1315           if(p1->E()>0.2){
1316             FillPIDHistograms("hSingleInvM_Mi_Emin2",p2,invMass) ;
1317             if(p1->E()>0.3){
1318               FillPIDHistograms("hSingleInvM_Mi_Emin3",p2,invMass) ;
1319             }
1320           }
1321         }
1322         if(TestPID(3, p1)){
1323           if(p1->E()>0.1){
1324             FillPIDHistograms("hSingleInvM_Mi_Emin1_Strict",p2,invMass) ;
1325             if(p1->E()>0.2){
1326               FillPIDHistograms("hSingleInvM_Mi_Emin2_Strict",p2,invMass) ;
1327               if(p1->E()>0.3){
1328                 FillPIDHistograms("hSingleInvM_Mi_Emin3_Strict",p2,invMass) ;
1329               }
1330             }
1331           }
1332         }
1333       }
1334     }
1335   } 
1336   
1337 }
1338
1339 //______________________________________________________________________________
1340 void AliAnalysisTaskTaggedPhotons::Init()
1341 {
1342   // Intialisation of parameters
1343 }
1344
1345 //______________________________________________________________________________
1346 void AliAnalysisTaskTaggedPhotons::Terminate(Option_t *)
1347 {
1348   // Processing when the event loop is ended
1349   if (fDebug > 1) Printf("Terminate()");
1350 }
1351 //______________________________________________________________________________
1352 Bool_t AliAnalysisTaskTaggedPhotons::IsInPi0Band(Double_t m, Double_t pt)const
1353 {
1354   //Parameterization of the pi0 peak region
1355   //for LHC13bcdef
1356   Double_t mpi0mean =  0.13447 - 1.41259e-03 * TMath::Exp(-pt/1.30044) ;  
1357
1358   Double_t mpi0sigma=TMath::Sqrt(5.22245e-03*5.22245e-03 +2.86851e-03*2.86851e-03/pt) + 9.09932e-05*pt ;
1359  
1360   return (m>mpi0mean-2*mpi0sigma && m<mpi0mean+2*mpi0sigma) ;
1361 }
1362 //______________________________________________________________________________
1363 Int_t AliAnalysisTaskTaggedPhotons::IsSameParent(const AliCaloPhoton *p1, const AliCaloPhoton *p2)const{
1364   //Looks through parents and finds if there was commont pi0 among ancestors
1365
1366   if(!fIsMC)
1367     return 0 ; //can not say anything
1368
1369   Int_t prim1 = p1->GetPrimary();
1370   while(prim1!=-1){ 
1371     Int_t prim2 = p2->GetPrimary();
1372   
1373     while(prim2!=-1){       
1374       if(prim1==prim2){
1375         return ((AliAODMCParticle*)fStack->At(prim1))->GetPdgCode() ;
1376       }
1377       prim2=((AliAODMCParticle*)fStack->At(prim2))->GetMother() ;
1378     }
1379     prim1=((AliAODMCParticle*)fStack->At(prim1))->GetMother() ;
1380   }
1381   return 0 ;
1382 }
1383 //______________________________________________________________________________
1384 Int_t AliAnalysisTaskTaggedPhotons::GetFiducialArea(const Float_t * position)const{
1385   //calculates in which kind of fiducial area photon hit
1386
1387   TVector3 global1(position) ;
1388   Int_t relId[4] ;
1389   fPHOSgeom->GlobalPos2RelId(global1,relId) ;
1390 //  Int_t mod  = relId[0] ;
1391   Int_t cellX = relId[2];
1392   Int_t cellZ = relId[3] ;
1393
1394   //New we are in good channel, 
1395   //calculate distance to the closest group of bad channels
1396   const Int_t cut1=10;
1397   const Int_t cut2=15;
1398 //For 3-mod configuration
1399 //  if((mod==3 && cellX<=cut1) || (mod==1 && cellX>=65-cut1) || cellZ<=cut1 || cellZ>=57-cut1)
1400 //For 1+3 configuraion
1401   if( cellX<=cut1 ||  cellX>=65-cut1 || cellZ<=cut1 || cellZ>=57-cut1)
1402     return 1;
1403 //  //and from large dead area
1404 //Full configuration
1405 //    if((mod==3 && cellX<=cut2) || (mod==1 && cellX>=65-cut2) || cellZ<=cut2 || cellZ>=57-cut2)
1406 //1+3 configuration
1407   if( cellX<=cut2 || cellX>=65-cut2 || cellZ<=cut2 || cellZ>=57-cut2)
1408     return 2;
1409   //Very good channel
1410   return 3 ;
1411
1412 }
1413 //______________________________________________________________________________^M
1414 void  AliAnalysisTaskTaggedPhotons::InitGeometry(){
1415   //Rotation matrixes are set with Tender
1416   
1417   if(fPHOSgeom) return ;
1418   
1419   
1420   fPHOSgeom = AliPHOSGeometry::GetInstance() ;
1421  
1422   if(!fPHOSgeom){ //Geometry not yet constructed with Tender
1423     fPHOSgeom = AliPHOSGeometry::GetInstance("IHEP","");
1424
1425     AliOADBContainer geomContainer("phosGeo");
1426     geomContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSGeometry.root","PHOSRotationMatrixes");
1427     TObjArray *matrixes = (TObjArray*)geomContainer.GetObject(170000,"PHOSRotationMatrixes");
1428     for(Int_t mod=0; mod<5; mod++) {
1429       if(!matrixes->At(mod)) continue;
1430       fPHOSgeom->SetMisalMatrix(((TGeoHMatrix*)matrixes->At(mod)),mod) ;   
1431     }
1432   }
1433     
1434   //Read BadMap for MC simulations
1435   Int_t runNumber=196208 ; //LHC13bcdef
1436   AliOADBContainer badmapContainer(Form("phosBadMap"));
1437   badmapContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSBadMaps.root","phosBadMap");
1438   TObjArray *maps = (TObjArray*)badmapContainer.GetObject(runNumber,"phosBadMap");
1439   if(!maps){
1440       AliError("TaggedPhotons: Can not read Bad map\n") ;    
1441   }
1442   else{
1443     AliInfo(Form("TaggedPhotons: Setting PHOS bad map with name %s \n",maps->GetName())) ;
1444     for(Int_t mod=0; mod<5;mod++){
1445       if(fPHOSBadMap[mod]) 
1446         delete fPHOSBadMap[mod] ;
1447       TH2I * h = (TH2I*)maps->At(mod) ;      
1448       if(h)
1449         fPHOSBadMap[mod]=new TH2I(*h) ;
1450     }
1451   }    
1452 }
1453 //_____________________________________________________________________________
1454 void AliAnalysisTaskTaggedPhotons::FillHistogram(const char * key,Double_t x)const{
1455   //FillHistogram
1456   TH1I * tmpI = dynamic_cast<TH1I*>(fOutputContainer->FindObject(key)) ;
1457   if(tmpI){
1458     tmpI->Fill(x) ;
1459     return ;
1460   }
1461   TH1F * tmpF = dynamic_cast<TH1F*>(fOutputContainer->FindObject(key)) ;
1462   if(tmpF){
1463     tmpF->Fill(x) ;
1464     return ;
1465   }
1466   TH1D * tmpD = dynamic_cast<TH1D*>(fOutputContainer->FindObject(key)) ;
1467   if(tmpD){
1468     tmpD->Fill(x) ;
1469     return ;
1470   }
1471   AliInfo(Form("can not find histogram <%s> ",key)) ;
1472 }
1473 //_____________________________________________________________________________
1474 void AliAnalysisTaskTaggedPhotons::FillHistogram(const char * key,Double_t x,Double_t y)const{
1475   //FillHistogram
1476   TObject * tmp = fOutputContainer->FindObject(key) ;
1477   if(!tmp){
1478     AliInfo(Form("can not find histogram <%s> ",key)) ;
1479     return ;
1480   }
1481   if(tmp->IsA() == TClass::GetClass("TH1F")){
1482     ((TH1F*)tmp)->Fill(x,y) ;
1483     return ;
1484   }
1485   if(tmp->IsA() == TClass::GetClass("TH2F")){
1486     ((TH2F*)tmp)->Fill(x,y) ;
1487     return ;
1488   }
1489   AliError(Form("Calling FillHistogram with 2 parameters for histo <%s> of type %s",key,tmp->IsA()->GetName())) ;
1490 }
1491
1492 //_____________________________________________________________________________
1493 void AliAnalysisTaskTaggedPhotons::FillHistogram(const char * key,Double_t x,Double_t y, Double_t z) const{
1494   //Fills 1D histograms with key
1495   TObject * tmp = fOutputContainer->FindObject(key) ;
1496   if(!tmp){
1497     AliInfo(Form("can not find histogram <%s> ",key)) ;
1498     return ;
1499   }
1500   if(tmp->IsA() == TClass::GetClass("TH2F")){
1501     ((TH2F*)tmp)->Fill(x,y,z) ;
1502     return ;
1503   }
1504   if(tmp->IsA() == TClass::GetClass("TH3F")){
1505     ((TH3F*)tmp)->Fill(x,y,z) ;
1506     return ;
1507   }
1508 }
1509 //_____________________________________________________________________________
1510 void AliAnalysisTaskTaggedPhotons::FillPIDHistograms(const char * name, const AliCaloPhoton * p) const{
1511
1512   FillHistogram(Form("%s_All_cent%d",name,fCentBin),p->Pt(),p->GetWeight()) ;
1513   if(p->IsDispOK())
1514     FillHistogram(Form("%s_Disp_cent%d",name,fCentBin),p->Pt(),p->GetWeight()) ;
1515   if(p->IsCPVOK())
1516     FillHistogram(Form("%s_CPV_cent%d",name,fCentBin),p->Pt(),p->GetWeight()) ;
1517   if(p->IsDispOK() && p->IsCPVOK()) 
1518     FillHistogram(Form("%s_Both_cent%d",name,fCentBin),p->Pt(),p->GetWeight()) ;
1519   
1520 }
1521 //_____________________________________________________________________________
1522 void AliAnalysisTaskTaggedPhotons::FillPIDHistograms(const char * name, const AliCaloPhoton * p,Double_t x) const{
1523
1524   FillHistogram(Form("%s_All_cent%d",name,fCentBin),x,p->Pt(),p->GetWeight()) ;
1525   if(p->IsDispOK())
1526     FillHistogram(Form("%s_Disp_cent%d",name,fCentBin),x,p->Pt(),p->GetWeight()) ;
1527   if(p->IsCPVOK())
1528     FillHistogram(Form("%s_CPV_cent%d",name,fCentBin),x,p->Pt(),p->GetWeight()) ;
1529   if(p->IsDispOK() && p->IsCPVOK()) 
1530     FillHistogram(Form("%s_Both_cent%d",name,fCentBin),x,p->Pt(),p->GetWeight()) ;
1531   
1532 }
1533 //_____________________________________________________________________________
1534 void AliAnalysisTaskTaggedPhotons::FillPIDHistograms(const char * name, const AliCaloPhoton * p1,const AliCaloPhoton * p2,Double_t x, Bool_t isRe) const{
1535
1536   Double_t ptPi = (*p1 + *p2).Pt() ;
1537   Double_t w=TMath::Sqrt(p1->GetWeight()*p2->GetWeight()) ;
1538 //  if(isRe){
1539 //    Int_t pdg=IsSameParent(p1,p2) ;
1540 //    if(pdg!=0)
1541 //      w=p1->GetWeight() ;
1542 //  }
1543   FillHistogram(Form("%s_All_cent%d",name,fCentBin),x,ptPi,w) ;
1544   if(p1->IsDispOK() && p2->IsDispOK())
1545     FillHistogram(Form("%s_Disp_cent%d",name,fCentBin),x,ptPi,w) ;
1546   if(p1->IsCPVOK() && p2->IsCPVOK())
1547     FillHistogram(Form("%s_CPV_cent%d",name,fCentBin),x,ptPi,w) ;
1548   if(p1->IsDispOK() && p1->IsCPVOK() && p2->IsDispOK() && p2->IsCPVOK()) 
1549     FillHistogram(Form("%s_Both_cent%d",name,fCentBin),x,ptPi,w) ;
1550   
1551 }
1552 //_____________________________________________________________________________
1553 Bool_t AliAnalysisTaskTaggedPhotons::TestLambda(Double_t pt,Double_t l1,Double_t l2){
1554   
1555   Double_t l2Mean  = 1.53126+9.50835e+06/(1.+1.08728e+07*pt+1.73420e+06*pt*pt) ;
1556   Double_t l1Mean  = 1.12365+0.123770*TMath::Exp(-pt*0.246551)+5.30000e-03*pt ;
1557   Double_t l2Sigma = 6.48260e-02+7.60261e+10/(1.+1.53012e+11*pt+5.01265e+05*pt*pt)+9.00000e-03*pt;
1558   Double_t l1Sigma = 4.44719e-04+6.99839e-01/(1.+1.22497e+00*pt+6.78604e-07*pt*pt)+9.00000e-03*pt;
1559   Double_t c=-0.35-0.550*TMath::Exp(-0.390730*pt) ;
1560   Double_t R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma + 
1561               0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
1562               0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
1563   return (R2<2.5*2.5) ;
1564   
1565 }
1566 //_________________________________________________________________________________
1567 Int_t AliAnalysisTaskTaggedPhotons::EvalIsolation(TLorentzVector * ph, Bool_t isPhoton){
1568
1569    // Check if this particle is isolated. 
1570    //We use several cone radii and epsilons.
1571    //As well we look at charged particles and EMCAL ones
1572
1573    const Double_t coneR1=0.3 ;
1574    const Double_t coneR2=0.4 ;
1575    const Double_t coneR3=0.5 ;
1576
1577    const Double_t epsilon1=0.1 ;
1578    const Double_t epsilon2=0.05 ;
1579
1580    if(!ph) return 0 ;
1581
1582    //Sum of energies in cones, tracks and clusters in EMCAL
1583    Double_t eCone1 = 0;
1584    Double_t eCone2 = 0;
1585    Double_t eCone3 = 0;
1586    //Cross-check, energy in cone perpr to photon
1587    Double_t eP1Cone1 = 0;
1588    Double_t eP1Cone2 = 0;
1589    Double_t eP1Cone3 = 0;
1590    Double_t eP2Cone1 = 0;
1591    Double_t eP2Cone2 = 0;
1592    Double_t eP2Cone3 = 0;
1593    
1594
1595    Double_t  phiTrig = ph->Phi();
1596    Double_t  etaTrig = ph->Eta();
1597
1598    Int_t n=fTrackEvent->GetEntriesFast() ;
1599    for(Int_t itr=0; itr<n; itr++){
1600      AliCaloPhoton * track = (AliCaloPhoton*)fTrackEvent->At(itr) ;
1601          
1602      Double_t deleta = etaTrig - track->Eta() ;
1603      Double_t delphi = phiTrig - track->Phi() ;      
1604      while(delphi<-TMath::Pi()) delphi+=TMath::TwoPi() ;
1605      while(delphi>TMath::Pi()) delphi-=TMath::TwoPi() ;
1606    
1607      //Perp cones
1608      Double_t delphiP1 = phiTrig +TMath::PiOver2()- track->Phi() ;      
1609      while(delphiP1<-TMath::Pi()) delphiP1+=TMath::TwoPi() ;
1610      while(delphiP1>TMath::Pi()) delphiP1-=TMath::TwoPi() ;
1611      Double_t delphiP2 = phiTrig -TMath::PiOver2()- track->Phi() ;      
1612      while(delphiP2<-TMath::Pi()) delphiP2+=TMath::TwoPi() ;
1613      while(delphiP2>TMath::Pi()) delphiP2-=TMath::TwoPi() ;
1614      
1615      
1616      Double_t dr    = TMath::Sqrt(deleta * deleta + delphi * delphi);
1617      Double_t drP1    = TMath::Sqrt(deleta * deleta + delphiP1 * delphiP1);
1618      Double_t drP2    = TMath::Sqrt(deleta * deleta + delphiP2 * delphiP2);
1619
1620      if(dr<coneR3){
1621        eCone3+=track->Pt() ;
1622        if(dr<coneR2){
1623          eCone2+=track->Pt() ;
1624          if(dr<coneR1){
1625            eCone1+=track->Pt() ;
1626          }
1627         }
1628       } 
1629        
1630     if(drP1<coneR3){
1631        eP1Cone3+=track->Pt() ;
1632        if(drP1<coneR2){
1633          eP1Cone2+=track->Pt() ;
1634          if(drP1<coneR1){
1635            eP1Cone1+=track->Pt() ;
1636          }
1637        }
1638     }   
1639        
1640     if(drP2<coneR3){
1641        eP2Cone3+=track->Pt() ;
1642        if(drP2<coneR2){
1643          eP2Cone2+=track->Pt() ;
1644          if(drP2<coneR1){
1645            eP2Cone1+=track->Pt() ;
1646          }
1647         }
1648       } 
1649     }   
1650          
1651     //Fill QA histgams
1652     Double_t ptTrig=ph->Pt() ;
1653     if(isPhoton){
1654     FillHistogram(Form("QA_Cone1_Tracks_cent%d",fCentBin),ptTrig,eCone1) ;
1655     FillHistogram(Form("QA_Cone2_Tracks_cent%d",fCentBin),ptTrig,eCone2) ;
1656     FillHistogram(Form("QA_Cone3_Tracks_cent%d",fCentBin),ptTrig,eCone3) ;
1657     FillHistogram(Form("QA_PCone1_Tracks_cent%d",fCentBin),ptTrig,eP1Cone1) ;
1658     FillHistogram(Form("QA_PCone2_Tracks_cent%d",fCentBin),ptTrig,eP1Cone2) ;
1659     FillHistogram(Form("QA_PCone3_Tracks_cent%d",fCentBin),ptTrig,eP1Cone3) ;
1660     FillHistogram(Form("QA_PCone1_Tracks_cent%d",fCentBin),ptTrig,eP2Cone1) ;
1661     FillHistogram(Form("QA_PCone2_Tracks_cent%d",fCentBin),ptTrig,eP2Cone2) ;
1662     FillHistogram(Form("QA_PCone3_Tracks_cent%d",fCentBin),ptTrig,eP2Cone3) ;
1663     }
1664     else{
1665     FillHistogram(Form("QA_Pi0Cone1_Tracks_cent%d",fCentBin),ptTrig,eCone1) ;
1666     FillHistogram(Form("QA_Pi0Cone2_Tracks_cent%d",fCentBin),ptTrig,eCone2) ;
1667     FillHistogram(Form("QA_Pi0Cone3_Tracks_cent%d",fCentBin),ptTrig,eCone3) ;
1668     FillHistogram(Form("QA_Pi0PCone1_Tracks_cent%d",fCentBin),ptTrig,eP1Cone1) ;
1669     FillHistogram(Form("QA_Pi0PCone2_Tracks_cent%d",fCentBin),ptTrig,eP1Cone2) ;
1670     FillHistogram(Form("QA_Pi0PCone3_Tracks_cent%d",fCentBin),ptTrig,eP1Cone3) ;
1671     FillHistogram(Form("QA_Pi0PCone1_Tracks_cent%d",fCentBin),ptTrig,eP2Cone1) ;
1672     FillHistogram(Form("QA_Pi0PCone2_Tracks_cent%d",fCentBin),ptTrig,eP2Cone2) ;
1673     FillHistogram(Form("QA_Pi0PCone3_Tracks_cent%d",fCentBin),ptTrig,eP2Cone3) ;
1674       
1675     }
1676     
1677     //Fill Bits
1678     Int_t iCone1E1 = (epsilon1*ptTrig > eCone1) ;
1679     Int_t iCone2E1 = (epsilon1*ptTrig > eCone2) ;
1680     Int_t iCone3E1 = (epsilon1*ptTrig > eCone3) ;
1681     
1682     Int_t iCone1E2 = (epsilon2*ptTrig > eCone1) ;
1683     Int_t iCone2E2 = (epsilon2*ptTrig > eCone2) ;
1684     Int_t iCone3E2 = (epsilon2*ptTrig > eCone3) ;
1685     
1686     
1687     Int_t isolation=   iCone1E1+  2*iCone2E1   +4*iCone3E1+
1688                     8*iCone1E2 +16*iCone2E2 +32*iCone3E2 ;
1689     return isolation ;              
1690 }
1691 //_________________________________________________________________________________
1692 Bool_t AliAnalysisTaskTaggedPhotons::TestPID(Int_t iPID, AliCaloPhoton* part){
1693 //   //Checks PID of particle
1694   
1695   if(!part) return kFALSE ;
1696   if(iPID==0) return kTRUE ;
1697   if(iPID==1) return part->IsDispOK() ;
1698   if(iPID==2) return part->IsCPVOK() ;
1699   if(iPID==3) return part->IsDispOK() && part->IsCPVOK() ;
1700   return kFALSE ;
1701     
1702 }
1703 //_________________________________________________________________________________
1704 Double_t AliAnalysisTaskTaggedPhotons::PrimaryParticleWeight(AliAODMCParticle * particle){
1705   if(!fIsMC)  //This is real data
1706      return 1;
1707   //Classify parent at vertex
1708   //Introduce for eta and pi0 weights   
1709      
1710   Double_t r2=particle->Xv()*particle->Xv()+particle->Yv()*particle->Yv() ;
1711   Int_t mother = particle->GetMother() ;
1712   while(mother>-1){
1713     if(r2<1.)
1714       break ;
1715     particle = (AliAODMCParticle*) fStack->At(mother);
1716     mother = particle->GetMother() ;
1717     r2=particle->Xv()*particle->Xv()+particle->Yv()*particle->Yv() ;
1718   }
1719   
1720   //Particle within 1 cm from the virtex
1721   Int_t pdg = particle->GetPdgCode() ;
1722   Double_t x = particle->Pt() ;
1723   mother = particle->GetMother() ;
1724   while(TMath::Abs(pdg)<100){//gamma, electrons, muons 
1725     if(mother>-1){
1726       AliAODMCParticle * tmpP=(AliAODMCParticle*)fStack->At(mother) ;
1727       pdg=tmpP->GetPdgCode() ;
1728       x = tmpP->Pt() ;
1729       mother = tmpP->GetMother() ;
1730     }
1731     else{ //direct photon/electron....
1732       return 1.; 
1733     }
1734   } 
1735   if(pdg == 111){
1736   //Pi0
1737      if(x<1) return 1. ;
1738      else return fWeightParamPi0[0]*TMath::Power(x,fWeightParamPi0[1])*
1739        (1.+fWeightParamPi0[2]*x+fWeightParamPi0[3]*x*x)/
1740        (1.+fWeightParamPi0[4]*x+fWeightParamPi0[5]*x*x) ;
1741   }
1742   if(pdg == 221){
1743   //Eta - same weight
1744      if(x<1) return 1. ;
1745      else return fWeightParamPi0[0]*TMath::Power(x,fWeightParamPi0[1])*
1746        (1.+fWeightParamPi0[2]*x+fWeightParamPi0[3]*x*x)/
1747        (1.+fWeightParamPi0[4]*x+fWeightParamPi0[5]*x*x) ;
1748   }
1749   return 1. ;
1750 }
1751 //_________________________________________________________________________________
1752 void AliAnalysisTaskTaggedPhotons::SetPi0WeightParameters(TArrayD * ar){
1753  
1754   for(Int_t i=0; i<6; i++){ //Array range
1755     if(ar->GetSize()>i) fWeightParamPi0[i]=ar->At(i) ;
1756     else fWeightParamPi0[i]=0.;
1757   }
1758   //normalize to obtain smooth transition at 1 GeV
1759   Double_t x=1. ;
1760   fWeightParamPi0[0]=1./(TMath::Power(x,fWeightParamPi0[1])*
1761        (1.+fWeightParamPi0[2]*x+fWeightParamPi0[3]*x*x)/
1762        (1.+fWeightParamPi0[4]*x+fWeightParamPi0[5]*x*x)) ;
1763   
1764   
1765 }
1766 //___________________________________________________________________________
1767 Int_t AliAnalysisTaskTaggedPhotons::FindPrimary(AliVCluster*clu,  Bool_t&sure){
1768   //Finds primary and estimates if it unique one?
1769   //First check can it be photon/electron
1770   const Double_t emFraction=0.9; //part of energy of cluster to be assigned to EM particle
1771   Int_t n=clu->GetNLabels() ;
1772   FillHistogram(Form("LabelsNPrim_cent%d",fCentBin),clu->E(),n) ;
1773   if(n==1){
1774     sure=kTRUE;
1775     return clu->GetLabelAt(0) ;
1776   }
1777   //Number of clusters with one or more photons
1778   Bool_t hasGamma=kFALSE ;
1779   Double_t eMax=0. ;
1780   for(Int_t i=0;  i<n;  i++){
1781     AliAODMCParticle*  p=  (AliAODMCParticle*)fStack->At(clu->GetLabelAt(i)) ;
1782     Int_t pdg = p->GetPdgCode() ;
1783     if(pdg==22){
1784       hasGamma=kTRUE ;
1785       if(p->E()>eMax){
1786         eMax=p->E();
1787       }
1788     }
1789   }
1790   if(hasGamma){
1791     FillHistogram(Form("LabelsGamma_cent%d",fCentBin),clu->E()) ;
1792     FillHistogram(Form("LabelsGammaE_cent%d",fCentBin),clu->E(),eMax/clu->E()) ;
1793   }  
1794   
1795   for(Int_t i=0;  i<n;  i++){
1796     AliAODMCParticle*  p= (AliAODMCParticle*) fStack->At(clu->GetLabelAt(i)) ;
1797     Int_t pdg = p->GetPdgCode() ;
1798     if(pdg==22  ||  pdg==11 || pdg == -11){
1799       if(p->E()>emFraction*clu->E()){
1800         sure=kTRUE ;
1801         return clu->GetLabelAt(i);
1802       }
1803     }
1804   }
1805
1806   Double_t*  Ekin=  new  Double_t[n] ;
1807   for(Int_t i=0;  i<n;  i++){
1808     AliAODMCParticle*  p=(AliAODMCParticle*) fStack->At(clu->GetLabelAt(i)) ;
1809     Ekin[i]=p->P() ;  // estimate of kinetic energy
1810     if(p->GetPdgCode()==-2212  ||  p->GetPdgCode()==-2112){
1811       Ekin[i]+=1.8  ;  //due to annihilation
1812     }
1813   }
1814   Int_t iMax=0;
1815   Double_t eSubMax=0. ;
1816   eMax=0.;
1817   for(Int_t i=0;  i<n;  i++){
1818     if(Ekin[i]>eMax){
1819       eSubMax=eMax;
1820       eMax=Ekin[i];
1821       iMax=i;
1822     }
1823   }
1824   if(eSubMax>0.8*eMax)//not obvious primary
1825     sure=kFALSE;
1826   else
1827     sure=kTRUE;
1828   delete[]  Ekin;
1829   return  clu->GetLabelAt(iMax) ;
1830 }
1831 //___________________________________________________________________________
1832 Bool_t AliAnalysisTaskTaggedPhotons::IsGoodChannel(Int_t mod, Int_t ix, Int_t iz)
1833 {
1834   //Check if this channel belogs to the good ones
1835   
1836   if(mod>4 || mod<1){
1837     return kTRUE ;
1838   }
1839   if(!fPHOSBadMap[mod]){
1840      return kTRUE ;
1841   }
1842   if(fPHOSBadMap[mod]->GetBinContent(ix,iz)>0)
1843     return kFALSE ;
1844   else
1845     return kTRUE ;
1846 }
1847
1848