]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrDep/AliAnaPi0EbE.cxx
529bb6c761a057d8a3570e1988f6e8a6e5f976d5
[u/mrichter/AliRoot.git] / PWG4 / PartCorrDep / AliAnaPi0EbE.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 /* $Id: AliAnaPi0EbE.cxx 28688 2008-09-11 15:04:07Z gconesab $ */
16
17 //_________________________________________________________________________
18 // Class for the analysis of high pT pi0 event by event
19 // Pi0 identified by one of the following:
20 //  -Invariant mass of 2 cluster in calorimeter
21 //  -Shower shape analysis in calorimeter
22 //  -Invariant mass of one cluster in calorimeter and one photon reconstructed in CTS
23 //
24 // -- Author: Gustavo Conesa (LNF-INFN) &  Raphaelle Ichou (SUBATECH)
25 //////////////////////////////////////////////////////////////////////////////
26   
27   
28 // --- ROOT system --- 
29 #include <TList.h>
30 #include <TClonesArray.h>
31 #include <TObjString.h>
32 #include <TH3F.h>
33 //#include "Riostream.h"
34
35 // --- Analysis system --- 
36 #include "AliAnaPi0EbE.h" 
37 #include "AliCaloTrackReader.h"
38 #include "AliIsolationCut.h"
39 #include "AliNeutralMesonSelection.h"
40 #include "AliCaloPID.h"
41 #include "AliMCAnalysisUtils.h"
42 #include "AliStack.h"
43 #include "AliFiducialCut.h"
44 #include "TParticle.h"
45 #include "AliVCluster.h"
46 #include "AliAODEvent.h"
47 #include "AliAODMCParticle.h"
48
49 ClassImp(AliAnaPi0EbE)
50   
51 //____________________________________________________________________________
52 AliAnaPi0EbE::AliAnaPi0EbE() : 
53     AliAnaPartCorrBaseClass(),    fAnaType(kIMCalo),            fCalorimeter(""),
54     fMinDist(0.),fMinDist2(0.),   fMinDist3(0.),        
55     fInputAODGammaConv(0x0),      fInputAODGammaConvName(""),
56     //Histograms
57     fhPtPi0(0),                   fhEPi0(0),                    fhEEtaPhiPi0(0),
58     //Shower shape histos
59     fhEDispersion(0),             fhELambda0(0),                fhELambda1(0),             
60     //Time histograms
61     fhClusterPairDiffTimeE(0),    fhClusterPairDiffTimeAsy(0),
62     //MC histos
63     fhPtMCNoPi0(0),               fhPhiMCNoPi0(0),              fhEtaMCNoPi0(0), 
64     fhPtMCPi0(0),                 fhPhiMCPi0(0),                fhEtaMCPi0(0)
65 {
66   //default ctor
67   
68   for(Int_t i = 0; i < 6; i++){
69     fhEMCLambda0[i]     = 0;
70     fhEMCLambda1[i]     = 0;
71     fhEMCDispersion[i]  = 0;
72   }
73   
74   //Initialize parameters
75   InitParameters();
76   
77 }
78
79 //____________________________________________________________________________
80 AliAnaPi0EbE::~AliAnaPi0EbE() 
81 {
82   //dtor
83   if(fInputAODGammaConv){
84     fInputAODGammaConv->Clear() ; 
85     delete fInputAODGammaConv ;
86   }
87 }
88
89 //________________________________________________________________________
90 TObjString *  AliAnaPi0EbE::GetAnalysisCuts()
91 {       
92         //Save parameters used for analysis
93   TString parList ; //this will be list of parameters used for this analysis.
94   const Int_t buffersize = 255;
95   char onePar[buffersize] ;
96   
97   snprintf(onePar,buffersize,"--- AliAnaPi0EbE ---\n") ;
98   parList+=onePar ;     
99   snprintf(onePar,buffersize,"fAnaType=%d (Pi0 selection type) \n",fAnaType) ;
100   parList+=onePar ;
101   
102   if(fAnaType == kSSCalo){
103     snprintf(onePar,buffersize,"Calorimeter: %s\n",fCalorimeter.Data()) ;
104     parList+=onePar ;
105     snprintf(onePar,buffersize,"fMinDist =%2.2f (Minimal distance to bad channel to accept cluster) \n",fMinDist) ;
106     parList+=onePar ;
107     snprintf(onePar,buffersize,"fMinDist2=%2.2f (Cuts on Minimal distance to study acceptance evaluation) \n",fMinDist2) ;
108     parList+=onePar ;
109     snprintf(onePar,buffersize,"fMinDist3=%2.2f (One more cut on distance used for acceptance-efficiency study) \n",fMinDist3) ;
110     parList+=onePar ;
111   }
112   
113   //Get parameters set in base class.
114   parList += GetBaseParametersList() ;
115   
116   //Get parameters set in PID class.
117   if(fAnaType == kSSCalo) parList += GetCaloPID()->GetPIDParametersList() ;
118   
119   return new TObjString(parList) ;
120 }
121
122 //________________________________________________________________________
123 TList *  AliAnaPi0EbE::GetCreateOutputObjects()
124 {  
125   // Create histograms to be saved in output file and 
126   // store them in outputContainer
127   TList * outputContainer = new TList() ; 
128   outputContainer->SetName("Pi0EbEHistos") ; 
129   
130   Int_t nptbins  = GetHistoPtBins();           Float_t ptmax  = GetHistoPtMax();           Float_t ptmin  = GetHistoPtMin();
131   Int_t nphibins = GetHistoPhiBins();          Float_t phimax = GetHistoPhiMax();          Float_t phimin = GetHistoPhiMin();
132   Int_t netabins = GetHistoEtaBins();          Float_t etamax = GetHistoEtaMax();          Float_t etamin = GetHistoEtaMin();
133   Int_t ssbins   = GetHistoShowerShapeBins();  Float_t ssmax  = GetHistoShowerShapeMax();  Float_t ssmin  = GetHistoShowerShapeMin();
134   Int_t tdbins   = GetHistoDiffTimeBins() ;    Float_t tdmax  = GetHistoDiffTimeMax();     Float_t tdmin  = GetHistoDiffTimeMin();
135   
136   fhPtPi0  = new TH1F("hPtPi0","Number of identified  #pi^{0} decay",nptbins,ptmin,ptmax); 
137   fhPtPi0->SetYTitle("N");
138   fhPtPi0->SetXTitle("p_{T #pi^{0}}(GeV/c)");
139   outputContainer->Add(fhPtPi0) ; 
140   
141   fhEPi0  = new TH1F("hEPi0","Number of identified  #pi^{0} decay",nptbins,ptmin,ptmax); 
142   fhEPi0->SetYTitle("N");
143   fhEPi0->SetXTitle("E  #pi^{0}(GeV)");
144   outputContainer->Add(fhEPi0) ; 
145   
146   fhEEtaPhiPi0  = new TH3F
147   ("hEEtaPhiPi0","Selected #pi^{0} pairs: E vs #eta vs #phi",nptbins,ptmin,ptmax,netabins,etamin,etamax, nphibins,phimin,phimax); 
148   fhEEtaPhiPi0->SetZTitle("#phi");
149   fhEEtaPhiPi0->SetYTitle("#eta");
150   fhEEtaPhiPi0->SetXTitle("E (GeV)");
151   outputContainer->Add(fhEEtaPhiPi0) ; 
152   
153   ////////
154   
155   if(fAnaType == kIMCalo){
156     
157     fhEDispersion  = new TH2F
158     ("hEDispersion","Selected #pi^{0} pairs: E vs dispersion",nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
159     fhEDispersion->SetYTitle("D^{2}");
160     fhEDispersion->SetXTitle("E (GeV)");
161     outputContainer->Add(fhEDispersion) ; 
162     
163     fhELambda0  = new TH2F
164     ("hELambda0","Selected #pi^{0} pairs: E vs #lambda_{0}",nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
165     fhELambda0->SetYTitle("#lambda_{0}^{2}");
166     fhELambda0->SetXTitle("E (GeV)");
167     outputContainer->Add(fhELambda0) ; 
168     
169     fhELambda1  = new TH2F
170     ("hELambda1","Selected #pi^{0} pairs: E vs #lambda_{1}",nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
171     fhELambda1->SetYTitle("#lambda_{1}^{2}");
172     fhELambda1->SetXTitle("E (GeV)");
173     outputContainer->Add(fhELambda1) ; 
174     
175     fhClusterPairDiffTimeE = new TH2F("hClusterPairDiffTimeE","cluster pair time difference vs E",nptbins,ptmin,ptmax, tdbins,tdmin,tdmax);
176     fhClusterPairDiffTimeE->SetXTitle("E_{pair} (GeV)");
177     fhClusterPairDiffTimeE->SetYTitle("#Delta t (ns)");
178     outputContainer->Add(fhClusterPairDiffTimeE);
179     
180     fhClusterPairDiffTimeAsy = new TH2F("hClusterPairDiffTime","cluster pair time difference vs pair asymmetry",100,0,1, tdbins,tdmin,tdmax);
181     fhClusterPairDiffTimeAsy->SetXTitle("Asymmetry");
182     fhClusterPairDiffTimeAsy->SetYTitle("#Delta t (ns)");
183     outputContainer->Add(fhClusterPairDiffTimeAsy);    
184     
185   }// Invariant mass analysis in calorimeters only
186   
187   if(IsDataMC()) {
188     if((GetReader()->GetDataType() == AliCaloTrackReader::kMC && fAnaType!=kSSCalo) || 
189        GetReader()->GetDataType() != AliCaloTrackReader::kMC){
190       
191       fhPtMCPi0  = new TH1F("hPtMCPi0","Identified pi0 from pi0",nptbins,ptmin,ptmax); 
192       fhPtMCPi0->SetYTitle("N");
193       fhPtMCPi0->SetXTitle("p_{T #pi^{0}}(GeV/c)");
194       outputContainer->Add(fhPtMCPi0) ; 
195       
196       fhPhiMCPi0  = new TH2F
197       ("hPhiMCPi0","Identified pi0 from pi0",nptbins,ptmin,ptmax,nphibins,phimin,phimax); 
198       fhPhiMCPi0->SetYTitle("#phi");
199       fhPhiMCPi0->SetXTitle("p_{T #pi^{0}} (GeV/c)");
200       outputContainer->Add(fhPhiMCPi0) ; 
201       
202       fhEtaMCPi0  = new TH2F
203       ("hEtaMCPi0","Identified pi0 from pi0",nptbins,ptmin,ptmax,netabins,etamin,etamax); 
204       fhEtaMCPi0->SetYTitle("#eta");
205       fhEtaMCPi0->SetXTitle("p_{T #pi^{0}} (GeV/c)");
206       outputContainer->Add(fhEtaMCPi0) ;
207       
208       fhPtMCNoPi0  = new TH1F("hPtMCNoPi0","Identified pi0 not from pi0",nptbins,ptmin,ptmax); 
209       fhPtMCNoPi0->SetYTitle("N");
210       fhPtMCNoPi0->SetXTitle("p_{T #pi^{0}}(GeV/c)");
211       outputContainer->Add(fhPtMCNoPi0) ; 
212       
213       fhPhiMCNoPi0  = new TH2F
214       ("hPhiMCNoPi0","Identified pi0 not from pi0",nptbins,ptmin,ptmax,nphibins,phimin,phimax); 
215       fhPhiMCNoPi0->SetYTitle("#phi");
216       fhPhiMCNoPi0->SetXTitle("p_{T #pi^{0}} (GeV/c)");
217       outputContainer->Add(fhPhiMCNoPi0) ; 
218       
219       fhEtaMCNoPi0  = new TH2F
220       ("hEtaMCNoPi0","Identified pi0 not from pi0",nptbins,ptmin,ptmax,netabins,etamin,etamax); 
221       fhEtaMCNoPi0->SetYTitle("#eta");
222       fhEtaMCNoPi0->SetXTitle("p_{T #pi^{0}} (GeV/c)");
223       outputContainer->Add(fhEtaMCNoPi0) ;
224       
225       if(fAnaType == kIMCalo){
226         TString ptype[] ={"#gamma","#gamma->e^{#pm}","#pi^{0}","#eta","e^{#pm}", "hadron"}; 
227         TString pname[] ={"Photon","Conversion",     "Pi0",    "Eta", "Electron","Hadron"};
228         for(Int_t i = 0; i < 6; i++){ 
229           
230           fhEMCLambda0[i]  = new TH2F(Form("hELambda0_MC%s",pname[i].Data()),
231                                       Form("Selected pair, cluster from %s : E vs #lambda_{0}^{2}",ptype[i].Data()),
232                                       nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
233           fhEMCLambda0[i]->SetYTitle("#lambda_{0}^{2}");
234           fhEMCLambda0[i]->SetXTitle("E (GeV)");
235           outputContainer->Add(fhEMCLambda0[i]) ; 
236           
237           fhEMCLambda1[i]  = new TH2F(Form("hELambda1_MC%s",pname[i].Data()),
238                                       Form("Selected pair, cluster from %s : E vs #lambda_{1}^{2}",ptype[i].Data()),
239                                       nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
240           fhEMCLambda1[i]->SetYTitle("#lambda_{1}^{2}");
241           fhEMCLambda1[i]->SetXTitle("E (GeV)");
242           outputContainer->Add(fhEMCLambda1[i]) ; 
243                     
244           fhEMCDispersion[i]  = new TH2F(Form("hEDispersion_MC%s",pname[i].Data()),
245                                          Form("Selected pair, cluster from %s : E vs dispersion^{2}",ptype[i].Data()),
246                                          nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
247           fhEMCDispersion[i]->SetYTitle("D^{2}");
248           fhEMCDispersion[i]->SetXTitle("E (GeV)");
249           outputContainer->Add(fhEMCDispersion[i]) ; 
250       
251         }//
252         
253       }//kIMCalo
254     } //Not MC reader
255   }//Histos with MC
256   
257   
258   //Keep neutral meson selection histograms if requiered
259   //Setting done in AliNeutralMesonSelection
260   
261   if(fAnaType!=kSSCalo && GetNeutralMesonSelection()){
262     
263     TList * nmsHistos = GetNeutralMesonSelection()->GetCreateOutputObjects() ;
264     if(GetNeutralMesonSelection()->AreNeutralMesonSelectionHistosKept())
265       for(Int_t i = 0; i < nmsHistos->GetEntries(); i++) outputContainer->Add(nmsHistos->At(i)) ;
266     delete nmsHistos;
267           
268   }
269   
270   return outputContainer ;
271   
272 }
273
274 //____________________________________________________________________________
275 void AliAnaPi0EbE::Init()
276
277   //Init
278   //Do some checks
279   if(fCalorimeter == "PHOS" && !GetReader()->IsPHOSSwitchedOn() && NewOutputAOD()){
280     printf("AliAnaPi0EbE::Init() - !!STOP: You want to use PHOS in analysis but it is not read!! \n!!Check the configuration file!!\n");
281     abort();
282   }
283   else  if(fCalorimeter == "EMCAL" && !GetReader()->IsEMCALSwitchedOn() && NewOutputAOD()){
284     printf("AliAnaPi0EbE::Init() - !!STOP: You want to use EMCAL in analysis but it is not read!! \n!!Check the configuration file!!\n");
285     abort();
286   }
287   
288 }
289
290 //____________________________________________________________________________
291 void AliAnaPi0EbE::InitParameters()
292 {
293   //Initialize the parameters of the analysis.  
294   AddToHistogramsName("AnaPi0EbE_");
295   
296   fInputAODGammaConvName = "gammaconv" ;
297   fAnaType = kIMCalo ;
298   fCalorimeter = "EMCAL" ;
299   fMinDist  = 2.;
300   fMinDist2 = 4.;
301   fMinDist3 = 5.;
302   
303 }
304
305 //__________________________________________________________________
306 void  AliAnaPi0EbE::MakeAnalysisFillAOD() 
307 {
308   //Do analysis and fill aods
309   
310   switch(fAnaType) 
311   {
312     case kIMCalo:
313       MakeInvMassInCalorimeter();
314       break;
315       
316     case kSSCalo:
317       MakeShowerShapeIdentification();
318       break;
319       
320     case kIMCaloTracks:
321       MakeInvMassInCalorimeterAndCTS();
322       break;
323       
324   }
325 }
326
327 //__________________________________________________________________
328 void  AliAnaPi0EbE::MakeInvMassInCalorimeter() 
329 {
330   //Do analysis and fill aods
331   //Search for the photon decay in calorimeters
332   //Read photon list from AOD, produced in class AliAnaPhoton
333   //Check if 2 photons have the mass of the pi0.
334   
335   TLorentzVector mom1;
336   TLorentzVector mom2;
337   TLorentzVector mom ;
338   Int_t tag1 = 0;
339   Int_t tag2 = 0;
340   Int_t tag  = 0;
341   
342   if(!GetInputAODBranch()){
343     printf("AliAnaPi0EbE::MakeInvMassInCalorimeter() - No input calo photons in AOD with name branch < %s >, STOP \n",GetInputAODName().Data());
344     abort();
345   }
346   
347   for(Int_t iphoton = 0; iphoton < GetInputAODBranch()->GetEntriesFast()-1; iphoton++){
348     AliAODPWG4Particle * photon1 =  (AliAODPWG4Particle*) (GetInputAODBranch()->At(iphoton));
349     
350     //Vertex cut in case of mixed events
351     Int_t evtIndex1 = 0 ; 
352     if(GetMixedEvent())
353       evtIndex1 = GetMixedEvent()->EventIndexForCaloCluster(photon1->GetCaloLabel(0)) ;
354     if(TMath::Abs(GetVertex(evtIndex1)[2]) > GetZvertexCut()) continue ;  //vertex cut
355     mom1 = *(photon1->Momentum());
356     
357     //Get shower shape information of clusters
358     TObjArray *clusters = 0;
359     if     (!strcmp(fCalorimeter,"EMCAL")) clusters = GetEMCALClusters();
360     else if(!strcmp(fCalorimeter,"PHOS")) clusters = GetPHOSClusters() ;
361     
362     Bool_t bFound1        = kFALSE;
363     Int_t  caloLabel1     = photon1->GetCaloLabel(0);
364     Bool_t iclus1         = -1;    
365     AliVCluster *cluster1 = 0; 
366     if(clusters) {
367       //Get original cluster, to recover some information
368       for(Int_t iclus = 0; iclus < clusters->GetEntriesFast(); iclus++){
369         AliVCluster *cluster= dynamic_cast<AliVCluster*> (clusters->At(iclus));
370         if(cluster){
371           if     (cluster->GetID()==caloLabel1) {
372             bFound1  = kTRUE  ;
373             cluster1 = cluster;
374             iclus1   = iclus;
375           }
376         }      
377         if(bFound1) break;
378       }// calorimeter clusters loop
379     }
380     
381     for(Int_t jphoton = iphoton+1; jphoton < GetInputAODBranch()->GetEntriesFast(); jphoton++){
382       
383       AliAODPWG4Particle * photon2 =  (AliAODPWG4Particle*) (GetInputAODBranch()->At(jphoton));
384       Int_t evtIndex2 = 0 ; 
385       if(GetMixedEvent())
386         evtIndex2 = GetMixedEvent()->EventIndexForCaloCluster(photon2->GetCaloLabel(0)) ;
387       if(GetMixedEvent() && (evtIndex1 == evtIndex2))
388         continue ; 
389       if(TMath::Abs(GetVertex(evtIndex2)[2]) > GetZvertexCut()) continue ;  //vertex cut
390       mom2 = *(photon2->Momentum());
391       
392       //Photon1
393       Float_t e1    = photon1->E();
394       Float_t tof1  = -1;
395       Float_t disp1 = -1;
396       Float_t l01   = -1;
397       Float_t l11   = -1; 
398       
399       //Photon2
400       Float_t e2    = photon2->E();
401       Float_t disp2 = -1;
402       Float_t tof2  = -1;
403       Float_t l02   = -1;
404       Float_t l12   = -1; 
405       Bool_t bFound2        = kFALSE;
406       Int_t  caloLabel2     = photon2->GetCaloLabel(0);
407       AliVCluster *cluster2 = 0; 
408       if(clusters){      
409         for(Int_t iclus = iclus1+1; iclus < clusters->GetEntriesFast(); iclus++){
410           AliVCluster *cluster= dynamic_cast<AliVCluster*> (clusters->At(iclus));
411           if(cluster){
412             if(cluster->GetID()==caloLabel2) {
413               bFound2  = kTRUE  ;
414               cluster2 = cluster;
415             }          
416           }      
417           if(bFound2) break;
418         }// calorimeter clusters loop
419         
420         //Photon/Cluster 1
421         if(cluster1 && bFound1){
422           disp1   = cluster1->GetDispersion()*cluster1->GetDispersion();
423           l11     = cluster1->GetM20();
424           l01     = cluster1->GetM02();
425           tof1    = cluster1->GetTOF()*1e9;
426         }
427         //        else printf("cluster1 not available: calo label %d / %d, cluster ID %d\n",
428         //                     photon2->GetCaloLabel(0),(GetReader()->GetInputEvent())->GetNumberOfCaloClusters()-1,cluster1->GetID());
429         
430         //Photon/Cluster 2
431         if(cluster2 && bFound2){
432           disp2   = cluster2->GetDispersion()*cluster2->GetDispersion();
433           l12     = cluster2->GetM20();
434           l02     = cluster2->GetM02();
435           tof2    = cluster2->GetTOF()*1e9;
436         }
437         //        else printf("cluster2 not available: calo label %d / %d, cluster ID %d\n",
438         //                     photon2->GetCaloLabel(0),(GetReader()->GetInputEvent())->GetNumberOfCaloClusters()-1,cluster2->GetID());    
439         
440         //Select clusters with good time window difference
441         Double_t t12diff = tof1-tof2;
442         Float_t asymmetry = TMath::Abs(e1-e2)/(e1+e2);
443         fhClusterPairDiffTimeE  ->Fill(e1+e2,    t12diff);
444         fhClusterPairDiffTimeAsy->Fill(asymmetry,t12diff);
445         if(TMath::Abs(t12diff) > GetPairTimeCut()) continue;
446       }
447       
448       //Select good pair (good phi, pt cuts, aperture and invariant mass)
449       if(GetNeutralMesonSelection()->SelectPair(mom1, mom2))
450       {
451         if(GetDebug()>1) 
452           printf("AliAnaPi0EbE::MakeInvMassInCalorimeter() - Selected gamma pair: pt %f, phi %f, eta%f \n",(mom1+mom2).Pt(), (mom1+mom2).Phi()*180./3.1416, (mom1+mom2).Eta());
453         
454         //Play with the MC stack if available
455         if(IsDataMC()){
456           //Check origin of the candidates
457           Int_t  label1 = photon1->GetLabel();
458           Int_t  label2 = photon2->GetLabel();
459           if(label1>=0)tag1 = GetMCAnalysisUtils()->CheckOrigin(label1, GetReader(), photon1->GetInputFileIndex());
460           if(label2>=0)tag2 = GetMCAnalysisUtils()->CheckOrigin(label2, GetReader(), photon2->GetInputFileIndex());
461           
462           if(GetDebug() > 0) printf("AliAnaPi0EbE::MakeInvMassInCalorimeter() - Origin of: photon1 %d; photon2 %d \n",tag1, tag2);
463           if(GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCPi0Decay) && 
464              GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCPi0Decay)){
465             
466             //Check if pi0 mother is the same
467             if(GetReader()->ReadStack()){ 
468               if(label1>=0){
469                 TParticle * mother1 = GetMCStack()->Particle(label1);//photon in kine tree
470                 label1 = mother1->GetFirstMother();
471                 //mother1 = GetMCStack()->Particle(label1);//pi0
472               }
473               if(label2>=0){
474                 TParticle * mother2 = GetMCStack()->Particle(label2);//photon in kine tree
475                 label2 = mother2->GetFirstMother();
476                 //mother2 = GetMCStack()->Particle(label2);//pi0
477               }
478             }
479             else if(GetReader()->ReadAODMCParticles()){//&& (input > -1)){
480               if(label1>=0){
481                 AliAODMCParticle * mother1 = (AliAODMCParticle *) (GetReader()->GetAODMCParticles(photon1->GetInputFileIndex()))->At(label1);//photon in kine tree
482                 label1 = mother1->GetMother();
483                 //mother1 = GetMCStack()->Particle(label1);//pi0
484               }
485               if(label2>=0){
486                 AliAODMCParticle * mother2 = (AliAODMCParticle *) (GetReader()->GetAODMCParticles(photon2->GetInputFileIndex()))->At(label2);//photon in kine tree
487                 label2 = mother2->GetMother();
488                 //mother2 = GetMCStack()->Particle(label2);//pi0
489               }
490             }
491             
492             //printf("mother1 %d, mother2 %d\n",label1,label2);
493             if(label1 == label2 && label1>=0)
494               GetMCAnalysisUtils()->SetTagBit(tag,AliMCAnalysisUtils::kMCPi0);
495           }
496         }//Work with stack also   
497         
498         //Fill some histograms about shower shape
499         if(clusters && GetReader()->GetDataType()!=AliCaloTrackReader::kMC){
500           //Photon1 
501           
502           //printf("Signal Cl1: e %f, pt %f, disp %f, l1 %f, l0 %f, eta %f, phi %f \n",
503           //       e,pt,disp,l1,l0,photon2->Eta(),photon2->Phi());
504           
505           fhEDispersion->Fill(e1, disp1);   
506           fhELambda0   ->Fill(e1, l01  );  
507           fhELambda1   ->Fill(e1, l11  );  
508           
509           //Photon2
510           //printf("Signal Cl2: e %f, pt %f, disp %f, l1 %f, l0 %f, eta %f, phi %f \n",e
511           //     ,pt,disp,l1,l0,photon2->Eta(),photon2->Phi());
512           
513           fhEDispersion->Fill(e2, disp2);   
514           fhELambda0   ->Fill(e2, l02  ); 
515           fhELambda1   ->Fill(e2, l12  ); 
516           
517           if(IsDataMC()) {
518             //Photon1
519             if  ( GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCPi0)  ){
520               fhEMCLambda0[mcPi0]    ->Fill(e1, l01);
521               fhEMCLambda1[mcPi0]    ->Fill(e1, l11);
522               fhEMCDispersion[mcPi0] ->Fill(e1, disp1);
523             }//pi0
524             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCEta)  ){
525               fhEMCLambda0[mcEta]    ->Fill(e1, l01);
526               fhEMCLambda1[mcEta]    ->Fill(e1, l11);
527               fhEMCDispersion[mcEta] ->Fill(e1, disp1);
528             }//eta          
529             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCPhoton) &&
530                        GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCConversion) ){
531               fhEMCLambda0[mcConversion]    ->Fill(e1, l01);
532               fhEMCLambda1[mcConversion]    ->Fill(e1, l11);
533               fhEMCDispersion[mcConversion] ->Fill(e1, disp1);
534             }//conversion photon
535             else if( GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCPhoton) ){
536               fhEMCLambda0[mcPhoton]    ->Fill(e1, l01);
537               fhEMCLambda1[mcPhoton]    ->Fill(e1, l11);
538               fhEMCDispersion[mcPhoton] ->Fill(e1, disp1);
539             }//photon   no conversion
540             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCElectron)){
541               fhEMCLambda0[mcElectron]    ->Fill(e1, l01);
542               fhEMCLambda1[mcElectron]    ->Fill(e1, l11);
543               fhEMCDispersion[mcElectron] ->Fill(e1, disp1);
544             }//electron
545             else {
546               fhEMCLambda0[mcHadron]    ->Fill(e1, l01);
547               fhEMCLambda1[mcHadron]    ->Fill(e1, l11);
548               fhEMCDispersion[mcHadron] ->Fill(e1, disp1);
549             }//other particles 
550             
551             //Photon 2
552             if  ( GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCPi0)  ){
553                  fhEMCLambda0[mcPi0]    ->Fill(e2, l02);
554                  fhEMCLambda1[mcPi0]    ->Fill(e2, l12);
555                  fhEMCDispersion[mcPi0] ->Fill(e2, disp2);
556             }//pi0
557             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCEta)  ){
558               fhEMCLambda0[mcEta]    ->Fill(e2, l02);
559               fhEMCLambda1[mcEta]    ->Fill(e2, l12);
560               fhEMCDispersion[mcEta] ->Fill(e2, disp2);
561             }//eta            
562             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCConversion) && 
563                        GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCPhoton) ){
564                  fhEMCLambda0[mcConversion]    ->Fill(e2, l02);
565                  fhEMCLambda1[mcConversion]    ->Fill(e2, l12);
566                  fhEMCDispersion[mcConversion] ->Fill(e2, disp2);
567             }//conversion photon
568             else if( GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCPhoton) ){              
569                 fhEMCLambda0[mcPhoton]    ->Fill(e2, l02);
570                 fhEMCLambda1[mcPhoton]    ->Fill(e2, l12);
571                 fhEMCDispersion[mcPhoton] ->Fill(e2, disp2);
572             }//photon   no conversion
573             else if  ( GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCElectron)){
574               fhEMCLambda0[mcElectron]    ->Fill(e2, l02);
575               fhEMCLambda1[mcElectron]    ->Fill(e2, l12);
576               fhEMCDispersion[mcElectron] ->Fill(e2, disp2);
577             }//electron
578             else {
579               fhEMCLambda0[mcHadron]    ->Fill(e2, l02);
580               fhEMCLambda1[mcHadron]    ->Fill(e2, l12);
581               fhEMCDispersion[mcHadron] ->Fill(e2, disp2);
582             }//other particles 
583           }//is datamc
584         }//MC histograms
585         
586         //Create AOD for analysis
587         mom = mom1+mom2;
588         AliAODPWG4Particle pi0 = AliAODPWG4Particle(mom);
589         //pi0.SetLabel(calo->GetLabel());
590         pi0.SetIdentifiedParticleType(AliCaloPID::kPi0);
591         pi0.SetDetector(photon1->GetDetector());
592         pi0.SetTag(tag);  
593         //Set the indeces of the original caloclusters  
594         pi0.SetCaloLabel(photon1->GetCaloLabel(0), photon2->GetCaloLabel(0));
595         //pi0.SetInputFileIndex(input);
596         AddAODParticle(pi0);
597       }//pi0
598       
599     }//2n photon loop
600     
601   }//1st photon loop
602   
603   if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeInvMassInCalorimeter() - End fill AODs \n");  
604   
605 }
606
607 //__________________________________________________________________
608 void  AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() 
609 {
610   //Do analysis and fill aods
611   //Search for the photon decay in calorimeters
612   //Read photon list from AOD, produced in class AliAnaPhoton and AliGammaConversion
613   //Check if 2 photons have the mass of the pi0.
614   
615   TLorentzVector mom1;
616   TLorentzVector mom2;
617   TLorentzVector mom ;
618   Int_t tag1 = 0;
619   Int_t tag2 = 0;
620   Int_t tag  = 0;
621   Int_t evtIndex = 0;
622   if(!GetInputAODBranch()){
623     printf("AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() - No input calo photons in AOD branch with name < %s > , STOP\n",GetInputAODName().Data());
624     abort();
625   }
626   
627   for(Int_t iphoton = 0; iphoton < GetInputAODBranch()->GetEntriesFast(); iphoton++){
628     AliAODPWG4Particle * photon1 =  (AliAODPWG4Particle*) (GetInputAODBranch()->At(iphoton));
629     mom1 = *(photon1->Momentum());
630     
631     //Play with the MC stack if available
632     fInputAODGammaConv = (TClonesArray *) GetReader()->GetOutputEvent()->FindListObject(fInputAODGammaConvName);
633     if(!fInputAODGammaConv) {
634       printf("AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() - No input gamma conversions in AOD branch with name < %s >, STOP\n",fInputAODGammaConvName.Data());
635       abort();  
636     }
637     for(Int_t jphoton = 0; jphoton < fInputAODGammaConv->GetEntriesFast(); jphoton++){
638       AliAODPWG4Particle * photon2 =  (AliAODPWG4Particle*) (fInputAODGammaConv->At(jphoton));
639       if(GetMixedEvent())
640         evtIndex = GetMixedEvent()->EventIndexForCaloCluster(photon2->GetCaloLabel(0)) ;
641       if(TMath::Abs(GetVertex(evtIndex)[2]) > GetZvertexCut()) continue ;  //vertex cut
642       
643       mom2 = *(photon2->Momentum());
644       
645       //Int_t input = -1;       //if -1 photons come from different files, not a pi0
646       //if(photon1->GetInputFileIndex() == photon2->GetInputFileIndex()) input = photon1->GetInputFileIndex();
647       
648       //Select good pair (good phi, pt cuts, aperture and invariant mass)
649       if(GetNeutralMesonSelection()->SelectPair(mom1, mom2)){
650         if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() - Selected gamma pair: pt %f, phi %f, eta%f\n",(mom1+mom2).Pt(), (mom1+mom2).Phi()*180./3.1416, (mom1+mom2).Eta());
651         
652         if(IsDataMC()){
653           Int_t label1 = photon1->GetLabel();
654           Int_t label2 = photon2->GetLabel();
655           if(label1>=0)tag1 = GetMCAnalysisUtils()->CheckOrigin(label1, GetReader(), photon1->GetInputFileIndex());
656           if(label2>=0)tag2 = GetMCAnalysisUtils()->CheckOrigin(label2, GetReader(), photon2->GetInputFileIndex());
657           if(GetDebug() > 0) printf("AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() - Origin of: photon1 %d; photon2 %d \n",tag1, tag2);
658           if(GetMCAnalysisUtils()->CheckTagBit(tag1,AliMCAnalysisUtils::kMCPi0Decay) && 
659              GetMCAnalysisUtils()->CheckTagBit(tag2,AliMCAnalysisUtils::kMCPi0Decay)){
660             //Check if pi0 mother is the same
661             
662             if(GetReader()->ReadStack()){ 
663               if(label1>=0){
664                 TParticle * mother1 = GetMCStack()->Particle(label1);//photon in kine tree
665                 label1 = mother1->GetFirstMother();
666                 //mother1 = GetMCStack()->Particle(label1);//pi0
667               }
668               if(label2>=0){
669                 TParticle * mother2 = GetMCStack()->Particle(label2);//photon in kine tree
670                 label2 = mother2->GetFirstMother();
671                 //mother2 = GetMCStack()->Particle(label2);//pi0
672               }
673             }
674             else if(GetReader()->ReadAODMCParticles()&& label1>=0 && label2>=0){ //&& (input > -1)){
675               if(label1>=0){
676                 AliAODMCParticle * mother1 = (AliAODMCParticle *) (GetReader()->GetAODMCParticles(photon1->GetInputFileIndex()))->At(label1);//photon in kine tree
677                 label1 = mother1->GetMother();
678                 //mother1 = GetMCStack()->Particle(label1);//pi0
679               }
680               if(label2>=0){
681                 AliAODMCParticle * mother2 = (AliAODMCParticle *) (GetReader()->GetAODMCParticles(photon2->GetInputFileIndex()))->At(label2);//photon in kine tree
682                 label2 = mother2->GetMother();
683                 //mother2 = GetMCStack()->Particle(label2);//pi0
684               }
685             }
686             
687             //printf("mother1 %d, mother2 %d\n",label1,label2);
688             if(label1 == label2 && label1>=0)
689               GetMCAnalysisUtils()->SetTagBit(tag,AliMCAnalysisUtils::kMCPi0);
690           }
691         }//Work with stack also   
692         
693         //Create AOD for analysis
694         mom = mom1+mom2;
695         AliAODPWG4Particle pi0 = AliAODPWG4Particle(mom);
696         //pi0.SetLabel(calo->GetLabel());
697         pi0.SetIdentifiedParticleType(AliCaloPID::kPi0);
698         pi0.SetDetector(photon1->GetDetector());
699         pi0.SetTag(tag);
700         //Set the indeces of the original tracks or caloclusters  
701         pi0.SetCaloLabel(photon1->GetCaloLabel(0), -1);
702         pi0.SetTrackLabel(photon2->GetTrackLabel(0), photon2->GetTrackLabel(1));
703         //pi0.SetInputFileIndex(input);
704         AddAODParticle(pi0);
705       }//pi0
706     }//2n photon loop
707     
708   }//1st photon loop
709   
710   if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeInvMassInCalorimeterAndCTS() - End fill AODs \n");  
711   
712 }
713
714
715 //__________________________________________________________________
716 void  AliAnaPi0EbE::MakeShowerShapeIdentification() 
717 {
718   //Search for pi0 in fCalorimeter with shower shape analysis 
719   
720   TObjArray * pl = 0x0; 
721   //Select the Calorimeter of the photon
722   if(fCalorimeter == "PHOS")
723     pl = GetPHOSClusters();
724   else if (fCalorimeter == "EMCAL")
725     pl = GetEMCALClusters();
726   
727   if(!pl) {
728     Info("MakeShowerShapeIdentification","TObjArray with %s clusters is NULL!\n",fCalorimeter.Data());
729     return;
730   }  
731         
732   TLorentzVector mom ;
733   for(Int_t icalo = 0; icalo < pl->GetEntriesFast(); icalo++){
734     AliVCluster * calo = (AliVCluster*) (pl->At(icalo));        
735     
736     Int_t evtIndex = 0 ; 
737     if (GetMixedEvent()) {
738       evtIndex=GetMixedEvent()->EventIndexForCaloCluster(calo->GetID()) ; 
739     }
740     if(TMath::Abs(GetVertex(evtIndex)[2]) > GetZvertexCut()) continue ;  //vertex cut
741     
742     //Get Momentum vector, 
743     if(GetReader()->GetDataType() != AliCaloTrackReader::kMC){
744       calo->GetMomentum(mom,GetVertex(evtIndex)) ;}//Assume that come from vertex in straight line
745     else{
746       Double_t vertex[]={0,0,0};
747       calo->GetMomentum(mom,vertex) ;
748     }
749           
750     //If too small or big pt, skip it
751     if(mom.Pt() < GetMinPt() || mom.Pt() > GetMaxPt() ) continue ; 
752     //Check acceptance selection
753     if(IsFiducialCutOn()){
754       Bool_t in = GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
755       if(! in ) continue ;
756     }
757     
758     //Create AOD for analysis
759     AliAODPWG4Particle aodpi0 = AliAODPWG4Particle(mom);
760     aodpi0.SetLabel(calo->GetLabel());
761     //Set the indeces of the original caloclusters  
762     aodpi0.SetCaloLabel(calo->GetID(),-1);
763     aodpi0.SetDetector(fCalorimeter);
764     if(GetDebug() > 1) 
765       printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - FillAOD: Min pt cut and fiducial cut passed: pt %3.2f, phi %2.2f, eta %1.2f\n",aodpi0.Pt(),aodpi0.Phi(),aodpi0.Eta());    
766     
767     //Check Distance to Bad channel, set bit.
768     Double_t distBad=calo->GetDistanceToBadChannel() ; //Distance to bad channel
769     if(distBad < 0.) distBad=9999. ; //workout strange convension dist = -1. ;
770     if(distBad < fMinDist) //In bad channel (PHOS cristal size 2.2x2.2 cm)
771       continue ;
772     
773     if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - FillAOD: Bad channel cut passed %4.2f\n",distBad);
774     
775     if(distBad > fMinDist3) aodpi0.SetDistToBad(2) ;
776     else if(distBad > fMinDist2) aodpi0.SetDistToBad(1) ; 
777     else aodpi0.SetDistToBad(0) ;
778     
779     //Check PID
780     //PID selection or bit setting
781     if(GetReader()->GetDataType() == AliCaloTrackReader::kMC){
782       //Get most probable PID, check PID weights (in MC this option is mandatory)
783       aodpi0.SetIdentifiedParticleType(GetCaloPID()->GetIdentifiedParticleType(fCalorimeter,calo->GetPID(),mom.E()));//PID with weights
784       if(GetDebug() > 1) 
785         printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - FillAOD: PDG of identified particle %d\n",aodpi0.GetIdentifiedParticleType());
786       //If primary is not pi0, skip it.
787       if(aodpi0.GetIdentifiedParticleType() != AliCaloPID::kPi0) continue ;
788     }                                   
789     else if(IsCaloPIDOn()){
790       //Skip matched clusters with tracks
791       if(IsTrackMatched(calo)) continue ;
792       
793       //Get most probable PID, 2 options check PID weights 
794       //or redo PID, recommended option for EMCal.              
795       if(!IsCaloPIDRecalculationOn())
796         aodpi0.SetIdentifiedParticleType(GetCaloPID()->GetIdentifiedParticleType(fCalorimeter,calo->GetPID(),mom.E()));//PID with weights
797       else
798         aodpi0.SetIdentifiedParticleType(GetCaloPID()->GetIdentifiedParticleType(fCalorimeter,mom,calo));//PID recalculated
799       
800       if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - PDG of identified particle %d\n",aodpi0.GetIdentifiedParticleType());
801       
802       //If cluster does not pass pid, not pi0, skip it.
803       if(aodpi0.GetIdentifiedParticleType() != AliCaloPID::kPi0) continue ;                     
804       
805     }
806     else{
807       //Set PID bits for later selection (AliAnaPi0 for example)
808       //GetPDG already called in SetPIDBits.
809       GetCaloPID()->SetPIDBits(fCalorimeter,calo,&aodpi0, GetCaloUtils());
810       if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - PID Bits set \n");             
811     }
812     
813     if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - Pi0 selection cuts passed: pT %3.2f, pdg %d\n",aodpi0.Pt(), aodpi0.GetIdentifiedParticleType());
814     
815     //Play with the MC stack if available
816     //Check origin of the candidates
817     if(IsDataMC()){
818       if((GetReader()->GetDataType() == AliCaloTrackReader::kMC && fAnaType!=kSSCalo) || 
819          GetReader()->GetDataType() != AliCaloTrackReader::kMC){
820         //aodpi0.SetInputFileIndex(input);
821         Int_t tag       =0;
822         tag = GetMCAnalysisUtils()->CheckOrigin(calo->GetLabel(),GetReader(), aodpi0.GetInputFileIndex());
823         //GetMCAnalysisUtils()->CheckMultipleOrigin(calo->GetLabels(),calo->GetNLabels(), GetReader(), aodpi0.GetInputFileIndex(), tag);
824         aodpi0.SetTag(tag);
825         if(GetDebug() > 0) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - Origin of candidate %d\n",aodpi0.GetTag());
826       }
827     }//Work with stack also   
828     
829     //Add AOD with pi0 object to aod branch
830     AddAODParticle(aodpi0);
831     
832   }//loop
833   
834   if(GetDebug() > 1) printf("AliAnaPi0EbE::MakeShowerShapeIdentification() - End fill AODs \n");  
835   
836 }
837 //__________________________________________________________________
838 void  AliAnaPi0EbE::MakeAnalysisFillHistograms() 
839 {
840   //Do analysis and fill histograms
841   
842   if(!GetOutputAODBranch()){
843     printf("AliAnaPi0EbE::MakeAnalysisFillHistograms()  - No output pi0 in AOD branch with name < %s >,STOP \n",GetOutputAODName().Data());
844     abort();
845   }
846   //Loop on stored AOD pi0
847   Int_t naod = GetOutputAODBranch()->GetEntriesFast();
848   if(GetDebug() > 0) printf("AliAnaPi0EbE::MakeAnalysisFillHistograms() - aod branch entries %d\n", naod);
849   
850   for(Int_t iaod = 0; iaod < naod ; iaod++){
851     
852     AliAODPWG4Particle* pi0 =  (AliAODPWG4Particle*) (GetOutputAODBranch()->At(iaod));
853     Int_t pdg = pi0->GetIdentifiedParticleType();
854           
855     if(IsCaloPIDOn() && pdg != AliCaloPID::kPi0) continue;              
856     
857     //Fill pi0 histograms 
858     Float_t ener  = pi0->E();
859     Float_t pt    = pi0->Pt();
860     Float_t phi   = pi0->Phi();
861     if(phi < 0) phi+=TMath::TwoPi();
862     Float_t eta = pi0->Eta();
863     
864     fhPtPi0      ->Fill(pt);
865     fhEPi0       ->Fill(ener);
866     fhEEtaPhiPi0 ->Fill(ener,eta,phi);
867     
868     if(IsDataMC()){
869       if((GetReader()->GetDataType() == AliCaloTrackReader::kMC && fAnaType!=kSSCalo) || 
870          GetReader()->GetDataType() != AliCaloTrackReader::kMC){
871         if(GetMCAnalysisUtils()->CheckTagBit(pi0->GetTag(), AliMCAnalysisUtils::kMCPi0)){
872           fhPtMCPi0  ->Fill(pt);
873           fhPhiMCPi0 ->Fill(pt,phi);
874           fhEtaMCPi0 ->Fill(pt,eta);
875         }
876         else{
877           fhPtMCNoPi0  ->Fill(pt);
878           fhPhiMCNoPi0 ->Fill(pt,phi);
879           fhEtaMCNoPi0 ->Fill(pt,eta);
880         }
881       }
882     }//Histograms with MC
883     
884   }// aod loop
885   
886 }
887
888 //__________________________________________________________________
889 void AliAnaPi0EbE::Print(const Option_t * opt) const
890 {
891   //Print some relevant parameters set for the analysis
892   if(! opt)
893     return;
894   
895   printf("**** Print %s %s ****\n", GetName(), GetTitle() ) ;
896   AliAnaPartCorrBaseClass::Print("");
897   printf("Analysis Type = %d \n",  fAnaType) ;
898   if(fAnaType == kSSCalo){     
899     printf("Calorimeter            =     %s\n", fCalorimeter.Data()) ;
900     printf("Min Distance to Bad Channel   = %2.1f\n",fMinDist);
901     printf("Min Distance to Bad Channel 2 = %2.1f\n",fMinDist2);
902     printf("Min Distance to Bad Channel 3 = %2.1f\n",fMinDist3); 
903   } 
904   printf("    \n") ;
905   
906