making the container name parameterized
[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"
f52538d5 35#include "AliInputEventHandler.h"
f15155ed 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),
accd903d 49fScaleFactor(-1),
099de61e 50fhNEvents(0), fhNPileUpEvents(0),
51fhZVertex(0),
accd903d 52fhTrackMult(0), fhCentrality(0),
f7eac3ca 53fhEventPlaneAngle(0),
accd903d 54fhNMergedFiles(0), fhScaleFactor(0)
f15155ed 55{
56 //Default Ctor
57 if(fAnaDebug > 1 ) printf("*** Analysis Maker Constructor *** \n");
58
59 //Initialize parameters, pointers and histograms
60 InitParameters();
61}
62
63//________________________________________________________________________________________
64AliAnaCaloTrackCorrMaker::AliAnaCaloTrackCorrMaker(const AliAnaCaloTrackCorrMaker & maker) :
65TObject(),
4c795f31 66fReader(), //(new AliCaloTrackReader(*maker.fReader)),
67fCaloUtils(),//(new AliCalorimeterUtils(*maker.fCaloUtils)),
f15155ed 68fOutputContainer(new TList()), fAnalysisContainer(new TList()),
69fMakeHisto(maker.fMakeHisto), fMakeAOD(maker.fMakeAOD),
4c795f31 70fAnaDebug(maker.fAnaDebug), fCuts(new TList()),
accd903d 71fScaleFactor(maker.fScaleFactor),
099de61e 72fhNEvents(maker.fhNEvents),
73fhNPileUpEvents(maker.fhNPileUpEvents),
74fhZVertex(maker.fhZVertex),
75fhTrackMult(maker.fhTrackMult),
76fhCentrality(maker.fhCentrality),
f7eac3ca 77fhEventPlaneAngle(maker.fhEventPlaneAngle),
accd903d 78fhNMergedFiles(maker.fhNMergedFiles),
79fhScaleFactor(maker.fhScaleFactor)
f15155ed 80{
81 // cpy ctor
82}
83
84//___________________________________________________
85AliAnaCaloTrackCorrMaker::~AliAnaCaloTrackCorrMaker()
86{
87 // Remove all owned pointers.
88
89 // Do not delete it here, already done somewhere else, need to understand where.
90 // if (fOutputContainer) {
91 // fOutputContainer->Clear();
92 // delete fOutputContainer ;
93 // }
94
4c795f31 95 if (fAnalysisContainer)
96 {
f15155ed 97 fAnalysisContainer->Delete();
98 delete fAnalysisContainer ;
99 }
100
101 if (fReader) delete fReader ;
102 if (fCaloUtils) delete fCaloUtils ;
103
4c795f31 104 if(fCuts)
105 {
f15155ed 106 fCuts->Delete();
107 delete fCuts;
108 }
109
110}
111
accd903d 112//__________________________________________________________________
f15155ed 113void AliAnaCaloTrackCorrMaker::AddAnalysis(TObject* ana, Int_t n)
114{
115 // Add analysis depending on AliAnaCaloTrackCorrBaseClass to list
116
117 if ( fAnalysisContainer)
118 {
119 fAnalysisContainer->AddAt(ana,n);
120 }
121 else
122 {
123 printf("AliAnaCaloTrackCorrMaker::AddAnalysis() - AnalysisContainer not initialized\n");
124 abort();
125 }
126}
127
128//_________________________________________________________
129TList * AliAnaCaloTrackCorrMaker::FillAndGetAODBranchList()
130{
131
132 // Get any new output AOD branches from analysis and put them in a list
133 // The list is filled in the maker, and new branch passed to the analysis frame
134 // AliAnalysisTaskCaloTrackCorrelation
135
136 TList *aodBranchList = fReader->GetAODBranchList() ;
137
4c795f31 138 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
139 {
f15155ed 140 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
141 if(ana->NewOutputAOD()) aodBranchList->Add(ana->GetCreateOutputAODBranch());
f15155ed 142 }
143
144 return aodBranchList ;
145
146}
147
148//_______________________________________________________
149TList * AliAnaCaloTrackCorrMaker::GetListOfAnalysisCuts()
150{
151
152 // Get the list of the cuts used for the analysis
153 // The list is filled in the maker, called by the task in LocalInit() and posted there
f15155ed 154
4c795f31 155 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
156 {
f15155ed 157 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
158 TObjString * objstring = ana->GetAnalysisCuts();
4c795f31 159
f15155ed 160 if(objstring)fCuts->Add(objstring);
161 }
4c795f31 162
f15155ed 163 return fCuts ;
164
165}
166
167//___________________________________________________
168TList *AliAnaCaloTrackCorrMaker::GetOutputContainer()
169{
170 // Fill the output list of histograms during the CreateOutputObjects stage.
171
172 //Initialize calorimeters geometry pointers
55d66f31 173 //GetCaloUtils()->InitPHOSGeometry();
174 //GetCaloUtils()->InitEMCALGeometry();
f15155ed 175
f15155ed 176 //General event histograms
177
accd903d 178 fhNEvents = new TH1I("hNEvents", "Number of analyzed events" , 1 , 0 , 1 ) ;
4c795f31 179 fhNEvents->SetYTitle("# events");
f15155ed 180 fOutputContainer->Add(fhNEvents);
4c795f31 181
099de61e 182 fhNPileUpEvents = new TH1I("hNPileUpEvents", "Number of events considered as pile-up", 2 , 0 , 2 ) ;
183 fhNPileUpEvents->SetYTitle("# events");
184 fhNPileUpEvents->GetXaxis()->SetBinLabel(1 ,"SPD");
185 fhNPileUpEvents->GetXaxis()->SetBinLabel(2 ,"Multi SPD");
186 fOutputContainer->Add(fhNPileUpEvents);
187
accd903d 188 fhZVertex = new TH1F("hZVertex", " Z vertex distribution" , 200 , -50 , 50 ) ;
d2655d46 189 fhZVertex->SetXTitle("v_{z} (cm)");
190 fOutputContainer->Add(fhZVertex);
191
accd903d 192 fhTrackMult = new TH1I("hTrackMult", "Number of tracks per events" , 2000 , 0 , 2000 ) ;
4c795f31 193 fhTrackMult->SetXTitle("# tracks");
f15155ed 194 fOutputContainer->Add(fhTrackMult);
195
accd903d 196 fhCentrality = new TH1F("hCentrality","Number of events in centrality bin",100,0.,100) ;
4c795f31 197 fhCentrality->SetXTitle("Centrality bin");
198 fOutputContainer->Add(fhCentrality) ;
199
f7eac3ca 200 fhEventPlaneAngle=new TH1F("hEventPlaneAngle","Number of events in event plane",100,0.,TMath::Pi()) ;
201 fhEventPlaneAngle->SetXTitle("EP angle (rad)");
202 fOutputContainer->Add(fhEventPlaneAngle) ;
203
accd903d 204 if(fScaleFactor > 0)
205 {
206 fhNMergedFiles = new TH1I("hNMergedFiles", "Number of merged output files" , 1 , 0 , 1 ) ;
207 fhNMergedFiles->SetYTitle("# files");
208 fhNMergedFiles->Fill(1); // Fill here with one entry, while merging it will count the rest
209 fOutputContainer->Add(fhNMergedFiles);
210
211 fhScaleFactor = new TH1F("hScaleFactor", "Number of merged output files" , 1 , 0 , 1 ) ;
212 fhScaleFactor->SetYTitle("scale factor");
213 fhScaleFactor->SetBinContent(1,fScaleFactor); // Fill here
214 fOutputContainer->Add(fhScaleFactor);
215 }
216
4c795f31 217 if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0)
218 {
219 printf("AliAnaCaloTrackCorrMaker::GetOutputContainer() - Analysis job list not initialized!!!\n");
220 return fOutputContainer;
221 }
222
223 const Int_t buffersize = 255;
224 char newname[buffersize];
225 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
226 {
227
228 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
229
230 if(fMakeHisto) // Analysis with histograms as output on
231 {
232
233 //Fill container with appropriate histograms
234 TList * templist = ana ->GetCreateOutputObjects();
235 templist->SetOwner(kFALSE); //Owner is fOutputContainer.
236
237 for(Int_t i = 0; i < templist->GetEntries(); i++)
238 {
239
240 //Add only to the histogram name the name of the task
241 if( strcmp((templist->At(i))->ClassName(),"TObjString") )
242 {
243 snprintf(newname,buffersize, "%s%s", (ana->GetAddedHistogramsStringToName()).Data(), (templist->At(i))->GetName());
244 ((TH1*) templist->At(i))->SetName(newname);
245 }
246
247 //Add histogram to general container
248 fOutputContainer->Add(templist->At(i)) ;
249
250 }
251
252 delete templist;
253
254 }// Analysis with histograms as output on
255
256 }//Loop on analysis defined
257
f15155ed 258 return fOutputContainer;
259
260}
261
262//___________________________________
263void AliAnaCaloTrackCorrMaker::Init()
264{
265 //Init container histograms and other common variables
266 // Fill the output list of histograms during the CreateOutputObjects stage.
267
268 //Initialize reader
269 GetReader()->Init();
270 GetReader()->SetCaloUtils(GetCaloUtils()); // pass the calo utils pointer to the reader
271
272
4c795f31 273 if(!fAnalysisContainer || fAnalysisContainer->GetEntries()==0)
274 {
f15155ed 275 printf("AliAnaCaloTrackCorrMaker::GetOutputInit() - Analysis job list not initialized!!!\n");
4c795f31 276 return;
f15155ed 277 }
4c795f31 278
279 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
280 {
f15155ed 281
4c795f31 282 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
283
284 ana->SetReader(fReader); // Set Reader for each analysis
285 ana->SetCaloUtils(fCaloUtils); // Set CaloUtils for each analysis
286
287 ana->Init();
288
289 }//Loop on analysis defined
290
f15155ed 291}
292
293//_____________________________________________
294void AliAnaCaloTrackCorrMaker::InitParameters()
295{
296 //Init data members
297
298 fMakeHisto = kTRUE;
299 fMakeAOD = kTRUE;
300 fAnaDebug = 0; // No debugging info displayed by default
301
302}
303
304//______________________________________________________________
305void AliAnaCaloTrackCorrMaker::Print(const Option_t * opt) const
306{
307 //Print some relevant parameters set for the analysis
308
309 if(! opt)
310 return;
311
312 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
4c795f31 313 printf("Debug level = %d\n", fAnaDebug ) ;
314 printf("Produce Histo = %d\n", fMakeHisto ) ;
315 printf("Produce AOD = %d\n", fMakeAOD ) ;
f15155ed 316 printf("Number of analysis tasks = %d\n", fAnalysisContainer->GetEntries()) ;
317
4c795f31 318 if(!strcmp("all",opt))
319 {
f15155ed 320 printf("Print analysis Tasks settings :\n") ;
4c795f31 321 for(Int_t iana = 0; iana<fAnalysisContainer->GetEntries(); iana++)
322 {
f15155ed 323 ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana))->Print("");
324 }
325
326 printf("Print analysis Reader settings :\n") ;
327 fReader->Print("");
328 printf("Print analysis Calorimeter Utils settings :\n") ;
329 fCaloUtils->Print("");
4c795f31 330
f15155ed 331 }
4c795f31 332
f15155ed 333}
334
335//_______________________________________________________________________
336void AliAnaCaloTrackCorrMaker::ProcessEvent(const Int_t iEntry,
337 const char * currentFileName)
338{
339 //Process analysis for this event
340
4c795f31 341 if(fMakeHisto && !fOutputContainer)
342 {
f15155ed 343 printf("AliAnaCaloTrackCorrMaker::ProcessEvent() - Histograms not initialized\n");
344 abort();
345 }
346
4c795f31 347 if(fAnaDebug >= 0 )
348 {
f15155ed 349 printf("*** AliAnaCaloTrackCorrMaker::ProcessEvent() Event %d *** \n",iEntry);
4c795f31 350 if(fAnaDebug > 1 )
351 {
f15155ed 352 printf("AliAnaCaloTrackCorrMaker::ProcessEvent() - Current File Name : %s\n", currentFileName);
353 //printf("fAODBranchList %p, entries %d\n",fAODBranchList,fAODBranchList->GetEntries());
354 }
355 }
356
357 //Each event needs an empty branch
358 TList * aodList = fReader->GetAODBranchList();
359 Int_t nAODBranches = aodList->GetEntries();
4c795f31 360 for(Int_t iaod = 0; iaod < nAODBranches; iaod++)
361 {
f15155ed 362 TClonesArray *tca = dynamic_cast<TClonesArray*> (aodList->At(iaod));
363 if(tca) tca->Clear("C");
364 }
365
366 //Set geometry matrices before filling arrays, in case recalibration/position calculation etc is needed
55d66f31 367 fCaloUtils->AccessGeometry(fReader->GetInputEvent());
368
369 //Set the AODB calibration, bad channels etc. parameters at least once
370 fCaloUtils->AccessOADB(fReader->GetInputEvent());
371
f15155ed 372
373 //Tell the reader to fill the data in the 3 detector lists
374 Bool_t ok = fReader->FillInputEvent(iEntry, currentFileName);
4c795f31 375 if(!ok)
376 {
f15155ed 377 if(fAnaDebug >= 1 )printf("*** Skip event *** %d \n",iEntry);
378 return ;
379 }
380
381 //Magic line to write events to file
382 if(fReader->WriteDeltaAODToFile())AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
383
384 //printf(">>>>>>>>>> BEFORE >>>>>>>>>>>\n");
385 //gObjectTable->Print();
4c795f31 386
f15155ed 387 //Loop on analysis algorithms
4c795f31 388
f15155ed 389 if(fAnaDebug > 0 ) printf("*** Begin analysis *** \n");
4c795f31 390
f15155ed 391 Int_t nana = fAnalysisContainer->GetEntries() ;
4c795f31 392 for(Int_t iana = 0; iana < nana; iana++)
393 {
f15155ed 394 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
395
396 ana->ConnectInputOutputAODBranches(); //Sets branches for each analysis
397 //Make analysis, create aods in aod branch or AODCaloClusters
398 if(fMakeAOD ) ana->MakeAnalysisFillAOD() ;
399 //Make further analysis with aod branch and fill histograms
400 if(fMakeHisto) ana->MakeAnalysisFillHistograms() ;
401
402 }
403
f52538d5 404 fReader->ResetLists();
405
406 // In case of mixing analysis, non triggered events are used,
407 // do not fill control histograms for a non requested triggered event
408 if(!fReader->IsEventTriggerAtSEOn())
409 {
410 AliAnalysisManager *manager = AliAnalysisManager::GetAnalysisManager();
411 AliInputEventHandler *inputHandler = dynamic_cast<AliInputEventHandler*>(manager->GetInputEventHandler());
412
413 if(!inputHandler) return ;
414
415 UInt_t isTrigger = inputHandler->IsEventSelected() & fReader->GetEventTriggerMask();
416 if(!isTrigger)
417 {
418 if(fAnaDebug > 0 ) printf("AliAnaCaloTrackMaker::ProcessEvent() - *** End analysis, MB for mixing *** \n");
419
420 return;
421 }
422 }
423
4c795f31 424 // Event control histograms
f52538d5 425
f7eac3ca 426 fhNEvents ->Fill(0); // Number of events analyzed
099de61e 427 if(fReader->IsPileUpFromSPD())
428 fhNPileUpEvents->Fill(0.5);
429 if(fReader->GetInputEvent()->IsPileupFromSPDInMultBins())
430 fhNPileUpEvents->Fill(1.5);
f7eac3ca 431 fhTrackMult ->Fill(fReader->GetTrackMultiplicity());
432 fhCentrality ->Fill(fReader->GetEventCentrality ());
433 fhEventPlaneAngle->Fill(fReader->GetEventPlaneAngle ());
099de61e 434
d2655d46 435 Double_t v[3];
436 fReader->GetInputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
437 fhZVertex->Fill(v[2]);
f52538d5 438
f15155ed 439 //printf(">>>>>>>>>> AFTER >>>>>>>>>>>\n");
440 //gObjectTable->Print();
441
f52538d5 442 if(fAnaDebug > 0 ) printf("AliAnaCaloTrackMaker::ProcessEvent() - *** End analysis *** \n");
f15155ed 443
444}
445
446//__________________________________________________________
447void AliAnaCaloTrackCorrMaker::Terminate(TList * outputList)
448{
449 //Execute Terminate of analysis
450 //Do some final plots.
451
4c795f31 452 if (!outputList)
453 {
f15155ed 454 Error("Terminate", "No output list");
455 return;
456 }
accd903d 457
4c795f31 458 for(Int_t iana = 0; iana < fAnalysisContainer->GetEntries(); iana++)
459 {
f15155ed 460
461 AliAnaCaloTrackCorrBaseClass * ana = ((AliAnaCaloTrackCorrBaseClass *) fAnalysisContainer->At(iana)) ;
462 if(ana->MakePlotsOn())ana->Terminate(outputList);
463
464 }//Loop on analysis defined
4c795f31 465
f15155ed 466}
467