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