]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/AliAnaGammaPhos.cxx
adatped to the new AliAnalysisGoodies functionalities
[u/mrichter/AliRoot.git] / PWG4 / AliAnaGammaPhos.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 // A basic analysis task to analyse photon detected by PHOS
20 //
21 //*-- Yves Schutz 
22 //////////////////////////////////////////////////////////////////////////////
23
24 #include <TCanvas.h>
25 #include <TChain.h>
26 #include <TFile.h> 
27 #include <TH1.h>
28 #include <TH1F.h>
29 #include <TH1I.h>
30 #include <TLegend.h> 
31 #include <TNtuple.h>
32 #include <TROOT.h> 
33 #include <TVector3.h> 
34
35 #include "AliAnaGammaPhos.h" 
36 #include "AliAnalysisManager.h"
37 #include "AliESD.h" 
38 #include "AliAODEvent.h"
39 #include "AliAODHandler.h"
40 #include "AliAODPhoton.h"
41 #include "AliLog.h"
42
43 //______________________________________________________________________________
44 AliAnaGammaPhos::AliAnaGammaPhos() : 
45   fChain(0x0),
46   fDebug(0),
47   fESD(0x0),
48   fAOD(0x0),
49   fAODPhotons(0x0), 
50   fPhotonsInPhos(0),
51   fTreeA(0x0),
52   fPhotonId(1.0),
53   fOutputList(0x0), 
54   fhPHOS(0),
55   fhPHOSEnergy(0),
56   fhPHOSDigits(0),
57   fhPHOSRecParticles(0),
58   fhPHOSPhotons(0),
59   fhPHOSInvariantMass(0),
60   fhPHOSDigitsEvent(0)
61 {
62   //Default constructor
63 }
64 //______________________________________________________________________________
65 AliAnaGammaPhos::AliAnaGammaPhos(const char *name) : 
66   AliAnalysisTask(name,""),  
67   fChain(0x0),
68   fDebug(0),
69   fESD(0x0),
70   fAOD(0x0),
71   fAODPhotons(0x0), 
72   fPhotonsInPhos(0),
73   fTreeA(0x0),
74   fPhotonId(1.0),
75   fOutputList(0x0), 
76   fhPHOS(0),
77   fhPHOSEnergy(0),
78   fhPHOSDigits(0),
79   fhPHOSRecParticles(0),
80   fhPHOSPhotons(0),
81   fhPHOSInvariantMass(0),
82   fhPHOSDigitsEvent(0)
83 {
84   // Constructor.
85   // Input slot #0 
86   DefineInput(0, TChain::Class());
87   // Output slots 
88   DefineOutput(0,  TTree::Class()) ; 
89   DefineOutput(1,  TList::Class()) ; 
90 }
91
92 //______________________________________________________________________________
93 AliAnaGammaPhos::~AliAnaGammaPhos()
94 {
95   // dtor
96   //  fOutputList->Clear() ; 
97   //delete fOutputList ;
98 }
99
100
101 //______________________________________________________________________________
102 void AliAnaGammaPhos::ConnectInputData(const Option_t*)
103 {
104   // Initialisation of branch container and histograms 
105     
106   AliInfo(Form("*** Initialization of %s", GetName())) ; 
107   
108   // Get input data
109   fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
110   if (!fChain) {
111     AliError(Form("Input 0 for %s not found\n", GetName()));
112     return ;
113   }
114   
115   // One should first check if the branch address was taken by some other task
116   char ** address = (char **)GetBranchAddress(0, "ESD");
117   if (address) {
118     fESD = (AliESD*)(*address);
119   } else {
120     fESD = new AliESD();
121     SetBranchAddress(0, "ESD", &fESD);
122   }
123 }
124
125 //________________________________________________________________________
126 void AliAnaGammaPhos::CreateOutputObjects()
127 {  
128   // Create the outputs containers
129  
130   OpenFile(0) ;
131   AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetEventHandler());  
132   fTreeA = handler->GetTree() ; 
133   fAOD   = handler->GetAOD();
134   fAODPhotons = fAOD->GetClusters() ; 
135   
136
137   OpenFile(1) ; 
138
139   fhPHOSPos            = new TNtuple("PHOSPos"         , "Position in PHOS"  , "x:y:z");
140   fhPHOS               = new TNtuple("PHOS"            , "PHOS"  , "event:digits:clusters:photons");
141   fhPHOSEnergy         = new TH1D("PHOSEnergy"         , "PHOSEnergy"        , 1000, 0., 10. ) ;
142   fhPHOSDigits         = new TH1I("PHOSDigitsCluster"  , "PHOSDigits"        , 20 , 0 , 20  ) ;
143   fhPHOSRecParticles   = new TH1D("PHOSRecParticles"   , "PHOSRecParticles" , 20 , 0., 20. ) ;
144   fhPHOSPhotons        = new TH1I("PHOSPhotons"        , "PHOSPhotons"       , 20 , 0 , 20  ) ;
145   fhPHOSInvariantMass  = new TH1D("PHOSInvariantMass"  , "PHOSInvariantMass" , 400, 0., 400.) ;
146   fhPHOSDigitsEvent    = new TH1I("PHOSDigitsEvent"    , "PHOSDigitsEvent"   , 30 , 0 , 30  ) ;
147   
148   // create output container
149   
150   fOutputList = new TList() ; 
151   fOutputList->SetName(GetName()) ; 
152
153   fOutputList->AddAt(fhPHOSPos,             0) ; 
154   fOutputList->AddAt(fhPHOS,                1) ; 
155   fOutputList->AddAt(fhPHOSEnergy,          2) ; 
156   fOutputList->AddAt(fhPHOSDigits,          3) ; 
157   fOutputList->AddAt(fhPHOSRecParticles,    4) ; 
158   fOutputList->AddAt(fhPHOSPhotons,         5) ; 
159   fOutputList->AddAt(fhPHOSInvariantMass,   6) ; 
160   fOutputList->AddAt(fhPHOSDigitsEvent,     7) ; 
161 }
162
163 //______________________________________________________________________________
164 void AliAnaGammaPhos::Exec(Option_t *) 
165 {
166   // Processing of one event
167     
168   Long64_t entry = fChain->GetReadEntry() ;
169   
170   if (!fESD) {
171     AliError("fESD is not connected to the input!") ; 
172     return ; 
173   }
174   
175   if ( !((entry-1)%100) ) 
176     AliInfo(Form("%s ----> Processing event # %lld",  (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ; 
177   
178   //************************  PHOS *************************************
179       
180   Int_t       firstPhosCluster       = fESD->GetFirstPHOSCluster() ;
181   const Int_t numberOfPhosClusters   = fESD->GetNumberOfPHOSClusters() ;
182   
183   TVector3 ** phosVector       = new TVector3*[numberOfPhosClusters] ;
184   Float_t  * phosPhotonsEnergy = new Float_t[numberOfPhosClusters] ;
185   Int_t      phosCluster ; 
186   Int_t      numberOfDigitsInPhos   = 0 ;
187   
188   fPhotonsInPhos  = 0 ;
189   // loop over the PHOS Cluster
190   for(phosCluster = firstPhosCluster ; phosCluster < firstPhosCluster + numberOfPhosClusters ; phosCluster++) {
191     AliESDCaloCluster * caloCluster = fESD->GetCaloCluster(phosCluster) ;
192     if (caloCluster) {
193       Float_t pos[3] ;
194       caloCluster->GetPosition( pos ) ;
195       fhPHOSEnergy->Fill( caloCluster->E() ) ;
196       fhPHOSPos->Fill( pos[0], pos[1], pos[2] ) ;
197       fhPHOSDigits->Fill(entry, caloCluster->GetNumberOfDigits() ) ;
198       numberOfDigitsInPhos += caloCluster->GetNumberOfDigits() ;
199       Float_t * pid = caloCluster->GetPid() ;
200       if(pid[AliPID::kPhoton] > GetPhotonId() ) {
201         phosVector[fPhotonsInPhos] = new TVector3(pos[0],pos[1],pos[2]) ;
202         phosPhotonsEnergy[fPhotonsInPhos]=caloCluster->E() ;
203         //new ((*fAODPhotons)[fPhotonsInPhos++;]) AliAODPhoton ( );
204       }
205     }
206   } //PHOS clusters
207     
208   fhPHOSRecParticles->Fill(numberOfPhosClusters);
209   fhPHOSPhotons->Fill(fPhotonsInPhos);
210   fhPHOSDigitsEvent->Fill(numberOfDigitsInPhos);
211   fhPHOS->Fill(entry, numberOfDigitsInPhos, numberOfPhosClusters, fPhotonsInPhos) ; 
212
213   // invariant Mass
214   if (fPhotonsInPhos > 1 ) {
215     Int_t phosPhoton1, phosPhoton2 ; 
216     for(phosPhoton1 = 0 ; phosPhoton1 < fPhotonsInPhos ; phosPhoton1++) {
217       for(phosPhoton2 = phosPhoton1 + 1 ; phosPhoton2 < fPhotonsInPhos ; phosPhoton2++) {      
218         Float_t tempMass = TMath::Sqrt( 2 * phosPhotonsEnergy[phosPhoton1] * phosPhotonsEnergy[phosPhoton2] *
219                                         ( 1 - TMath::Cos(phosVector[phosPhoton1]->Angle(*phosVector[phosPhoton2])) ) 
220                                         );
221         fhPHOSInvariantMass->Fill(tempMass*1000.);
222       }
223     }    
224   }
225   
226   PostData(0, fTreeA) ; 
227   PostData(1, fOutputList);
228
229   delete [] phosVector ; 
230   delete [] phosPhotonsEnergy ; 
231   
232 }
233
234
235 //______________________________________________________________________________
236 void AliAnaGammaPhos::Init()
237 {
238   // Intialisation of parameters
239   AliInfo("Doing initialisation") ; 
240   SetPhotonId(0.9) ; 
241 }
242
243 //______________________________________________________________________________
244 void AliAnaGammaPhos::Terminate(Option_t *)
245 {
246   // Processing when the event loop is ended
247
248 //   fOutputList = (TList*)GetOutputData(0);  
249 //   fhPHOSPos            = (TNtuple*)fOutputList->At(0);
250 //   fhPHOS               = (TNtuple*)fOutputList->At(1);
251 //   fhPHOSEnergy         = (TH1D*)fOutputList->At(2);
252 //   fhPHOSDigits         = (TH1I*)fOutputList->At(3);
253 //   fhPHOSRecParticles   = (TH1D*)fOutputList->At(4);
254 //   fhPHOSPhotons        = (TH1I*)fOutputList->At(5);
255 //   fhPHOSInvariantMass  = (TH1D*)fOutputList->At(6);
256 //   fhPHOSDigitsEvent    = (TH1I*)fOutputList->At(7);
257
258   Bool_t problem = kFALSE ; 
259   AliInfo(Form(" *** %s Report:", GetName())) ; 
260   printf("        PHOSEnergy Mean         : %5.3f , RMS : %5.3f \n", fhPHOSEnergy->GetMean(),         fhPHOSEnergy->GetRMS()         ) ;
261   printf("        PHOSDigits Mean         : %5.3f , RMS : %5.3f \n", fhPHOSDigits->GetMean(),         fhPHOSDigits->GetRMS()         ) ;
262   printf("        PHOSRecParticles Mean   : %5.3f , RMS : %5.3f \n", fhPHOSRecParticles->GetMean(),   fhPHOSRecParticles->GetRMS()   ) ;
263   printf("        PHOSPhotons Mean        : %5.3f , RMS : %5.3f \n", fhPHOSPhotons->GetMean(),        fhPHOSPhotons->GetRMS()        ) ;
264   printf("        PHOSInvariantMass Mean  : %5.3f , RMS : %5.3f \n", fhPHOSInvariantMass->GetMean(),  fhPHOSInvariantMass->GetRMS()  ) ;
265   printf("        PHOSDigitsEvent Mean    : %5.3f , RMS : %5.3f \n", fhPHOSDigitsEvent->GetMean(),    fhPHOSDigitsEvent->GetRMS()    ) ;
266
267   TCanvas  * cPHOS = new TCanvas("cPHOS", "PHOS ESD Test", 400, 10, 600, 700) ;
268   cPHOS->Divide(3, 2);
269
270   cPHOS->cd(1) ; 
271   if ( fhPHOSEnergy->GetMaximum() > 0. ) 
272     gPad->SetLogy();
273   fhPHOSEnergy->SetAxisRange(0, 25.);
274   fhPHOSEnergy->SetLineColor(2);
275   fhPHOSEnergy->Draw();
276
277   cPHOS->cd(2) ; 
278   fhPHOSDigits->SetAxisRange(0,25.);
279   fhPHOSDigits->SetLineColor(2);
280   fhPHOSDigits->Draw();
281
282   cPHOS->cd(3) ; 
283   if ( fhPHOSRecParticles->GetMaximum() > 0. ) 
284     gPad->SetLogy();
285   fhPHOSRecParticles->SetAxisRange(0, 25.);
286   fhPHOSRecParticles->SetLineColor(2);
287   fhPHOSRecParticles->Draw();
288
289   cPHOS->cd(4) ; 
290   if ( fhPHOSPhotons->GetMaximum() > 0. ) 
291     gPad->SetLogy();
292   fhPHOSPhotons->SetAxisRange(0,25.);
293   fhPHOSPhotons->SetLineColor(2);
294   fhPHOSPhotons->Draw();
295
296   cPHOS->cd(5) ; 
297   fhPHOSInvariantMass->SetLineColor(2);
298   fhPHOSInvariantMass->Draw();
299  
300   cPHOS->cd(6) ; 
301   if ( fhPHOSDigitsEvent->GetMaximum() > 0. ) 
302     gPad->SetLogy();
303   fhPHOSDigitsEvent->SetAxisRange(0,40.);
304   fhPHOSDigitsEvent->SetLineColor(2);
305   fhPHOSDigitsEvent->Draw();
306  
307   cPHOS->Print("PHOS.eps");
308  
309   char line[1024] ; 
310   sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ; 
311   gROOT->ProcessLine(line);
312   sprintf(line, ".!rm -fR *.eps"); 
313   gROOT->ProcessLine(line);
314  
315   AliInfo(Form("!!! All the eps files are in %s.tar.gz !!!", GetName())) ;
316
317   char * report ; 
318   if(problem)
319     report="Problems found, please check!!!";  
320   else 
321     report="OK";
322
323   AliInfo(Form("*** %s Summary Report: %s \n",GetName(), report)) ; 
324 }