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