Change of getter in AliAnalysisManager
[u/mrichter/AliRoot.git] / PWG4 / AliAnaGammaPhos.cxx
CommitLineData
ce9d0223 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"
c0acc236 40#include "AliAODPhoton.h"
ce9d0223 41#include "AliLog.h"
42
43//______________________________________________________________________________
44AliAnaGammaPhos::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//______________________________________________________________________________
65AliAnaGammaPhos::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//______________________________________________________________________________
93AliAnaGammaPhos::~AliAnaGammaPhos()
94{
95 // dtor
c0acc236 96 // fOutputList->Clear() ;
97 //delete fOutputList ;
ce9d0223 98}
99
100
101//______________________________________________________________________________
102void 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//________________________________________________________________________
126void AliAnaGammaPhos::CreateOutputObjects()
127{
128 // Create the outputs containers
129
130 OpenFile(0) ;
691685d6 131 AliAODHandler* handler = (AliAODHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
c0acc236 132 fTreeA = handler->GetTree() ;
ce9d0223 133 fAOD = handler->GetAOD();
134 fAODPhotons = fAOD->GetClusters() ;
c0acc236 135
ce9d0223 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//______________________________________________________________________________
164void 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] ;
c0acc236 194 caloCluster->GetPosition( pos ) ;
195 fhPHOSEnergy->Fill( caloCluster->E() ) ;
ce9d0223 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]) ;
c0acc236 202 phosPhotonsEnergy[fPhotonsInPhos]=caloCluster->E() ;
ce9d0223 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 }
32392f88 225
ce9d0223 226 PostData(0, fTreeA) ;
227 PostData(1, fOutputList);
228
229 delete [] phosVector ;
230 delete [] phosPhotonsEnergy ;
231
232}
233
234
235//______________________________________________________________________________
236void AliAnaGammaPhos::Init()
237{
238 // Intialisation of parameters
239 AliInfo("Doing initialisation") ;
240 SetPhotonId(0.9) ;
241}
242
75480d65 243//______________________________________________________________________________
ce9d0223 244void AliAnaGammaPhos::Terminate(Option_t *)
245{
246 // Processing when the event loop is ended
247
c0acc236 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);
ce9d0223 257
32392f88 258
ce9d0223 259 Bool_t problem = kFALSE ;
260 AliInfo(Form(" *** %s Report:", GetName())) ;
261 printf(" PHOSEnergy Mean : %5.3f , RMS : %5.3f \n", fhPHOSEnergy->GetMean(), fhPHOSEnergy->GetRMS() ) ;
262 printf(" PHOSDigits Mean : %5.3f , RMS : %5.3f \n", fhPHOSDigits->GetMean(), fhPHOSDigits->GetRMS() ) ;
263 printf(" PHOSRecParticles Mean : %5.3f , RMS : %5.3f \n", fhPHOSRecParticles->GetMean(), fhPHOSRecParticles->GetRMS() ) ;
264 printf(" PHOSPhotons Mean : %5.3f , RMS : %5.3f \n", fhPHOSPhotons->GetMean(), fhPHOSPhotons->GetRMS() ) ;
265 printf(" PHOSInvariantMass Mean : %5.3f , RMS : %5.3f \n", fhPHOSInvariantMass->GetMean(), fhPHOSInvariantMass->GetRMS() ) ;
266 printf(" PHOSDigitsEvent Mean : %5.3f , RMS : %5.3f \n", fhPHOSDigitsEvent->GetMean(), fhPHOSDigitsEvent->GetRMS() ) ;
267
268 TCanvas * cPHOS = new TCanvas("cPHOS", "PHOS ESD Test", 400, 10, 600, 700) ;
269 cPHOS->Divide(3, 2);
270
271 cPHOS->cd(1) ;
272 if ( fhPHOSEnergy->GetMaximum() > 0. )
273 gPad->SetLogy();
274 fhPHOSEnergy->SetAxisRange(0, 25.);
275 fhPHOSEnergy->SetLineColor(2);
276 fhPHOSEnergy->Draw();
277
278 cPHOS->cd(2) ;
279 fhPHOSDigits->SetAxisRange(0,25.);
280 fhPHOSDigits->SetLineColor(2);
281 fhPHOSDigits->Draw();
282
283 cPHOS->cd(3) ;
284 if ( fhPHOSRecParticles->GetMaximum() > 0. )
285 gPad->SetLogy();
286 fhPHOSRecParticles->SetAxisRange(0, 25.);
287 fhPHOSRecParticles->SetLineColor(2);
288 fhPHOSRecParticles->Draw();
289
290 cPHOS->cd(4) ;
291 if ( fhPHOSPhotons->GetMaximum() > 0. )
292 gPad->SetLogy();
293 fhPHOSPhotons->SetAxisRange(0,25.);
294 fhPHOSPhotons->SetLineColor(2);
295 fhPHOSPhotons->Draw();
296
297 cPHOS->cd(5) ;
298 fhPHOSInvariantMass->SetLineColor(2);
299 fhPHOSInvariantMass->Draw();
300
301 cPHOS->cd(6) ;
302 if ( fhPHOSDigitsEvent->GetMaximum() > 0. )
303 gPad->SetLogy();
304 fhPHOSDigitsEvent->SetAxisRange(0,40.);
305 fhPHOSDigitsEvent->SetLineColor(2);
306 fhPHOSDigitsEvent->Draw();
307
308 cPHOS->Print("PHOS.eps");
309
310 char line[1024] ;
311 sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ;
312 gROOT->ProcessLine(line);
313 sprintf(line, ".!rm -fR *.eps");
314 gROOT->ProcessLine(line);
315
316 AliInfo(Form("!!! All the eps files are in %s.tar.gz !!!", GetName())) ;
317
318 char * report ;
319 if(problem)
320 report="Problems found, please check!!!";
321 else
322 report="OK";
323
324 AliInfo(Form("*** %s Summary Report: %s \n",GetName(), report)) ;
325}