]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrMaker.cxx
Initialize PHOS and EMCAL in AliAnaCalorimeterUtils and geometry matrices during...
[u/mrichter/AliRoot.git] / PWG / CaloTrackCorrBase / AliAnaCaloTrackCorrMaker.cxx
CommitLineData
f15155ed 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//_____________________________________________________________________________
17// Steering class for particle (gamma, hadron) identification and correlation
18// analysis. It is called by the task class AliAnalysisTaskCaloTrackCorrelation
19// and it connects the input (ESD/AOD/MonteCarlo) got with AliCaloTrackReader
20// (produces TClonesArrays of AODs (TParticles in MC case if requested)), with
21// the analysis classes that derive from AliAnaCaloTrackCorrBaseClass
22//
23// -- Author: Gustavo Conesa (INFN-LNF, LPSC-Grenoble)
24
25#include <cstdlib>
26
27// --- ROOT system ---
28#include "TClonesArray.h"
29#include "TList.h"
30#include "TH1I.h"
f15155ed 31//#include <TObjectTable.h>
32
33//---- AliRoot system ----
34#include "AliAnalysisManager.h"
35#include "AliVEventHandler.h"
36#include "AliAnaCaloTrackCorrBaseClass.h"
37#include "AliAnaCaloTrackCorrMaker.h"
38
39ClassImp(AliAnaCaloTrackCorrMaker)
40
41
42//__________________________________________________
43AliAnaCaloTrackCorrMaker::AliAnaCaloTrackCorrMaker() :
44TObject(),
4c795f31 45fReader(0), fCaloUtils(0),
f15155ed 46fOutputContainer(new TList ), fAnalysisContainer(new TList ),
47fMakeHisto(kFALSE), fMakeAOD(kFALSE),
4c795f31 48fAnaDebug(0), fCuts(new TList),
49fhNEvents(0x0), fhTrackMult(0x0),
50fhCentrality(0x0)
f15155ed 51{
52 //Default Ctor
53 if(fAnaDebug > 1 ) printf("*** Analysis Maker Constructor *** \n");
54
55 //Initialize parameters, pointers and histograms
56 InitParameters();
57}
58
59//________________________________________________________________________________________
60AliAnaCaloTrackCorrMaker::AliAnaCaloTrackCorrMaker(const AliAnaCaloTrackCorrMaker & maker) :
61TObject(),
4c795f31 62fReader(), //(new AliCaloTrackReader(*maker.fReader)),
63fCaloUtils(),//(new AliCalorimeterUtils(*maker.fCaloUtils)),
f15155ed 64fOutputContainer(new TList()), fAnalysisContainer(new TList()),
65fMakeHisto(maker.fMakeHisto), fMakeAOD(maker.fMakeAOD),
4c795f31 66fAnaDebug(maker.fAnaDebug), fCuts(new TList()),
67fhNEvents(maker.fhNEvents), fhTrackMult(maker.fhTrackMult),
68fhCentrality(maker.fhCentrality)
f15155ed 69{
70 // cpy ctor
71}
72
73//___________________________________________________
74AliAnaCaloTrackCorrMaker::~AliAnaCaloTrackCorrMaker()
75{
76 // Remove all owned pointers.
77
78 // Do not delete it here, already done somewhere else, need to understand where.
79 // if (fOutputContainer) {
80 // fOutputContainer->Clear();
81 // delete fOutputContainer ;
82 // }
83
4c795f31 84 if (fAnalysisContainer)
85 {
f15155ed 86 fAnalysisContainer->Delete();
87 delete fAnalysisContainer ;
88 }
89
90 if (fReader) delete fReader ;
91 if (fCaloUtils) delete fCaloUtils ;
92
4c795f31 93 if(fCuts)
94 {
f15155ed 95 fCuts->Delete();
96 delete fCuts;
97 }
98
99}
100
101//_______________________________________________________
102void AliAnaCaloTrackCorrMaker::AddAnalysis(TObject* ana, Int_t n)
103{
104 // Add analysis depending on AliAnaCaloTrackCorrBaseClass to list
105
106 if ( fAnalysisContainer)
107 {
108 fAnalysisContainer->AddAt(ana,n);
109 }
110 else
111 {
112 printf("AliAnaCaloTrackCorrMaker::AddAnalysis() - AnalysisContainer not initialized\n");
113 abort();
114 }
115}
116
117//_________________________________________________________
118TList * AliAnaCaloTrackCorrMaker::FillAndGetAODBranchList()
119{
120
121 // Get any new output AOD branches from analysis and put them in a list
122 // The list is filled in the maker, and new branch passed to the analysis frame
123 // AliAnalysisTaskCaloTrackCorrelation
124
125 TList *aodBranchList = fReader->GetAODBranchList() ;
126
4c795f31 127 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
128 {
f15155ed 129 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
130 if(ana->NewOutputAOD()) aodBranchList->Add(ana->GetCreateOutputAODBranch());
f15155ed 131 }
132
133 return aodBranchList ;
134
135}
136
137//_______________________________________________________
138TList * AliAnaCaloTrackCorrMaker::GetListOfAnalysisCuts()
139{
140
141 // Get the list of the cuts used for the analysis
142 // The list is filled in the maker, called by the task in LocalInit() and posted there
f15155ed 143
4c795f31 144 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
145 {
f15155ed 146 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
147 TObjString * objstring = ana->GetAnalysisCuts();
4c795f31 148
f15155ed 149 if(objstring)fCuts->Add(objstring);
150 }
4c795f31 151
f15155ed 152 return fCuts ;
153
154}
155
156//___________________________________________________
157TList *AliAnaCaloTrackCorrMaker::GetOutputContainer()
158{
159 // Fill the output list of histograms during the CreateOutputObjects stage.
160
161 //Initialize calorimeters geometry pointers
55d66f31 162 //GetCaloUtils()->InitPHOSGeometry();
163 //GetCaloUtils()->InitEMCALGeometry();
f15155ed 164
f15155ed 165 //General event histograms
166
167 fhNEvents = new TH1I("hNEvents", "Number of analyzed events" , 1 , 0 , 1 ) ;
4c795f31 168 fhNEvents->SetYTitle("# events");
f15155ed 169 fOutputContainer->Add(fhNEvents);
4c795f31 170
f15155ed 171 fhTrackMult = new TH1I("hTrackMult", "Number of tracks per events" , 2000 , 0 , 2000 ) ;
4c795f31 172 fhTrackMult->SetXTitle("# tracks");
f15155ed 173 fOutputContainer->Add(fhTrackMult);
174
4c795f31 175 fhCentrality =new TH1F("hCentrality","Number of events in centrality bin",100,0.,100) ;
176 fhCentrality->SetXTitle("Centrality bin");
177 fOutputContainer->Add(fhCentrality) ;
178
179 if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0)
180 {
181 printf("AliAnaCaloTrackCorrMaker::GetOutputContainer() - Analysis job list not initialized!!!\n");
182 return fOutputContainer;
183 }
184
185 const Int_t buffersize = 255;
186 char newname[buffersize];
187 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
188 {
189
190 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
191
192 if(fMakeHisto) // Analysis with histograms as output on
193 {
194
195 //Fill container with appropriate histograms
196 TList * templist = ana ->GetCreateOutputObjects();
197 templist->SetOwner(kFALSE); //Owner is fOutputContainer.
198
199 for(Int_t i = 0; i < templist->GetEntries(); i++)
200 {
201
202 //Add only to the histogram name the name of the task
203 if( strcmp((templist->At(i))->ClassName(),"TObjString") )
204 {
205 snprintf(newname,buffersize, "%s%s", (ana->GetAddedHistogramsStringToName()).Data(), (templist->At(i))->GetName());
206 ((TH1*) templist->At(i))->SetName(newname);
207 }
208
209 //Add histogram to general container
210 fOutputContainer->Add(templist->At(i)) ;
211
212 }
213
214 delete templist;
215
216 }// Analysis with histograms as output on
217
218 }//Loop on analysis defined
219
f15155ed 220 return fOutputContainer;
221
222}
223
224//___________________________________
225void AliAnaCaloTrackCorrMaker::Init()
226{
227 //Init container histograms and other common variables
228 // Fill the output list of histograms during the CreateOutputObjects stage.
229
230 //Initialize reader
231 GetReader()->Init();
232 GetReader()->SetCaloUtils(GetCaloUtils()); // pass the calo utils pointer to the reader
233
234
4c795f31 235 if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0)
236 {
f15155ed 237 printf("AliAnaCaloTrackCorrMaker::GetOutputInit() - Analysis job list not initialized!!!\n");
4c795f31 238 return;
f15155ed 239 }
4c795f31 240
241 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
242 {
f15155ed 243
4c795f31 244 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
245
246 ana->SetReader(fReader); // Set Reader for each analysis
247 ana->SetCaloUtils(fCaloUtils); // Set CaloUtils for each analysis
248
249 ana->Init();
250
251 }//Loop on analysis defined
252
f15155ed 253}
254
255//_____________________________________________
256void AliAnaCaloTrackCorrMaker::InitParameters()
257{
258 //Init data members
259
260 fMakeHisto = kTRUE;
261 fMakeAOD = kTRUE;
262 fAnaDebug = 0; // No debugging info displayed by default
263
264}
265
266//______________________________________________________________
267void AliAnaCaloTrackCorrMaker::Print(const Option_t * opt) const
268{
269 //Print some relevant parameters set for the analysis
270
271 if(! opt)
272 return;
273
274 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
4c795f31 275 printf("Debug level = %d\n", fAnaDebug ) ;
276 printf("Produce Histo = %d\n", fMakeHisto ) ;
277 printf("Produce AOD = %d\n", fMakeAOD ) ;
f15155ed 278 printf("Number of analysis tasks = %d\n", fAnalysisContainer->GetEntries()) ;
279
4c795f31 280 if(!strcmp("all",opt))
281 {
f15155ed 282 printf("Print analysis Tasks settings :\n") ;
4c795f31 283 for(Int_t iana = 0; iana<fAnalysisContainer->GetEntries(); iana++)
284 {
f15155ed 285 ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana))->Print("");
286 }
287
288 printf("Print analysis Reader settings :\n") ;
289 fReader->Print("");
290 printf("Print analysis Calorimeter Utils settings :\n") ;
291 fCaloUtils->Print("");
4c795f31 292
f15155ed 293 }
4c795f31 294
f15155ed 295}
296
297//_______________________________________________________________________
298void AliAnaCaloTrackCorrMaker::ProcessEvent(const Int_t iEntry,
299 const char * currentFileName)
300{
301 //Process analysis for this event
302
4c795f31 303 if(fMakeHisto && !fOutputContainer)
304 {
f15155ed 305 printf("AliAnaCaloTrackCorrMaker::ProcessEvent() - Histograms not initialized\n");
306 abort();
307 }
308
4c795f31 309 if(fAnaDebug >= 0 )
310 {
f15155ed 311 printf("*** AliAnaCaloTrackCorrMaker::ProcessEvent() Event %d *** \n",iEntry);
4c795f31 312 if(fAnaDebug > 1 )
313 {
f15155ed 314 printf("AliAnaCaloTrackCorrMaker::ProcessEvent() - Current File Name : %s\n", currentFileName);
315 //printf("fAODBranchList %p, entries %d\n",fAODBranchList,fAODBranchList->GetEntries());
316 }
317 }
318
319 //Each event needs an empty branch
320 TList * aodList = fReader->GetAODBranchList();
321 Int_t nAODBranches = aodList->GetEntries();
4c795f31 322 for(Int_t iaod = 0; iaod < nAODBranches; iaod++)
323 {
f15155ed 324 TClonesArray *tca = dynamic_cast<TClonesArray*> (aodList->At(iaod));
325 if(tca) tca->Clear("C");
326 }
327
328 //Set geometry matrices before filling arrays, in case recalibration/position calculation etc is needed
55d66f31 329 fCaloUtils->AccessGeometry(fReader->GetInputEvent());
330
331 //Set the AODB calibration, bad channels etc. parameters at least once
332 fCaloUtils->AccessOADB(fReader->GetInputEvent());
333
f15155ed 334
335 //Tell the reader to fill the data in the 3 detector lists
336 Bool_t ok = fReader->FillInputEvent(iEntry, currentFileName);
4c795f31 337 if(!ok)
338 {
f15155ed 339 if(fAnaDebug >= 1 )printf("*** Skip event *** %d \n",iEntry);
340 return ;
341 }
342
343 //Magic line to write events to file
344 if(fReader->WriteDeltaAODToFile())AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
345
346 //printf(">>>>>>>>>> BEFORE >>>>>>>>>>>\n");
347 //gObjectTable->Print();
4c795f31 348
f15155ed 349 //Loop on analysis algorithms
4c795f31 350
f15155ed 351 if(fAnaDebug > 0 ) printf("*** Begin analysis *** \n");
4c795f31 352
f15155ed 353 Int_t nana = fAnalysisContainer->GetEntries() ;
4c795f31 354 for(Int_t iana = 0; iana < nana; iana++)
355 {
f15155ed 356 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
357
358 ana->ConnectInputOutputAODBranches(); //Sets branches for each analysis
359 //Make analysis, create aods in aod branch or AODCaloClusters
360 if(fMakeAOD ) ana->MakeAnalysisFillAOD() ;
361 //Make further analysis with aod branch and fill histograms
362 if(fMakeHisto) ana->MakeAnalysisFillHistograms() ;
363
364 }
365
4c795f31 366 // Event control histograms
367 fhNEvents ->Fill(0); //Event analyzed
368 fhTrackMult ->Fill(fReader->GetTrackMultiplicity());
369 fhCentrality->Fill(fReader->GetEventCentrality());
f15155ed 370
371 fReader->ResetLists();
372
373 //printf(">>>>>>>>>> AFTER >>>>>>>>>>>\n");
374 //gObjectTable->Print();
375
376 if(fAnaDebug > 0 ) printf("*** End analysis *** \n");
377
378}
379
380//__________________________________________________________
381void AliAnaCaloTrackCorrMaker::Terminate(TList * outputList)
382{
383 //Execute Terminate of analysis
384 //Do some final plots.
385
4c795f31 386 if (!outputList)
387 {
f15155ed 388 Error("Terminate", "No output list");
389 return;
390 }
391
4c795f31 392 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
393 {
f15155ed 394
395 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
396 if(ana->MakePlotsOn())ana->Terminate(outputList);
397
398 }//Loop on analysis defined
4c795f31 399
f15155ed 400}
401