making the container name parameterized
[u/mrichter/AliRoot.git] / PWG / CaloTrackCorrBase / AliAnalysisTaskCaloTrackCorrelation.cxx
CommitLineData
1c5acb87 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 **************************************************************************/
1c5acb87 15
16//_________________________________________________________________________
17// Analysis task that executes the analysis classes
f15155ed 18// that depend on the CaloTrackCorr frame, frame for Particle identification
19// with calorimeters and tracks and correlations.
1c5acb87 20// Specially designed for calorimeters but also can be used for charged tracks
f15155ed 21// Input of this task is a configuration file that contains all the settings
22// of the analysis
1c5acb87 23//
f15155ed 24// -- Author: Gustavo Conesa (INFN-LNF, LPSC-Grenoble)
1c5acb87 25
268934f9 26#include <cstdlib>
fbeaf916 27
28// --- Root ---
1c5acb87 29#include <TROOT.h>
1c5acb87 30#include <TInterpreter.h>
1cd71065 31#include <TClonesArray.h>
1c5acb87 32//#include <Riostream.h>
1cd71065 33//#include <TObjectTable.h>
1c5acb87 34
fbeaf916 35// --- Analysis ---
f15155ed 36#include "AliAnalysisTaskCaloTrackCorrelation.h"
37#include "AliAnaCaloTrackCorrMaker.h"
1c5acb87 38#include "AliCaloTrackReader.h"
7175a03a 39#include "AliPDG.h"
42dc8e7d 40#include "AliAnalysisManager.h"
66580b85 41#include "AliInputEventHandler.h"
1c5acb87 42
f15155ed 43ClassImp(AliAnalysisTaskCaloTrackCorrelation)
1c5acb87 44
f15155ed 45//________________________________________________________________________
46AliAnalysisTaskCaloTrackCorrelation::AliAnalysisTaskCaloTrackCorrelation() :
fbeaf916 47 AliAnalysisTaskSE(),
48 fAna(0x0),
49 fOutputContainer(0x0),
f15155ed 50 fConfigName(""),
51 fCuts(0x0)
1c5acb87 52{
53 // Default constructor
54}
55
f15155ed 56//________________________________________________________________________________________
57AliAnalysisTaskCaloTrackCorrelation::AliAnalysisTaskCaloTrackCorrelation(const char* name) :
477d6cee 58 AliAnalysisTaskSE(name),
59 fAna(0x0),
60 fOutputContainer(0x0),
f15155ed 61 fConfigName(""),
62 fCuts(0x0)
1c5acb87 63{
64 // Default constructor
477d6cee 65
1c5acb87 66 DefineOutput(1, TList::Class());
0c1383b5 67 DefineOutput(2, TList::Class()); // will contain cuts or local params
1c5acb87 68}
69
f15155ed 70//_________________________________________________________________________
71AliAnalysisTaskCaloTrackCorrelation::~AliAnalysisTaskCaloTrackCorrelation()
1c5acb87 72{
73 // Remove all pointers
f15155ed 74
90bb999a 75 if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;
76
77 if (fOutputContainer)
accd903d 78 {
be9d1d38 79 fOutputContainer->Clear() ;
80 delete fOutputContainer ;
81 }
f15155ed 82
90bb999a 83 if (fAna) delete fAna;
f15155ed 84
1c5acb87 85}
86
f15155ed 87//_________________________________________________________________
88void AliAnalysisTaskCaloTrackCorrelation::UserCreateOutputObjects()
1c5acb87 89{
477d6cee 90 // Create the output container
f15155ed 91 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserCreateOutputObjects() - Begin\n");
477d6cee 92
93 //Get list of aod arrays, add each aod array to analysis frame
f37fa8d2 94 TList * list = fAna->FillAndGetAODBranchList(); //Loop the analysis and create the list of branches
accd903d 95
f15155ed 96 if (DebugLevel() >= 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserCreateOutputObjects() - n AOD branches %d\n",list->GetEntries());
f37fa8d2 97
98 //Put the delta AODs in output file, std or delta
accd903d 99 if((fAna->GetReader())->WriteDeltaAODToFile())
100 {
f37fa8d2 101 TString deltaAODName = (fAna->GetReader())->GetDeltaAODFileName();
accd903d 102 for(Int_t iaod = 0; iaod < list->GetEntries(); iaod++)
103 {
104 TClonesArray * array = (TClonesArray*) list->At(iaod);
f37fa8d2 105 if(deltaAODName!="") AddAODBranch("TClonesArray", &array, deltaAODName);//Put it in DeltaAOD file
106 else AddAODBranch("TClonesArray", &array);//Put it in standard AOD file
107 }
108 }
109
477d6cee 110 //Histograms container
111 OpenFile(1);
112 fOutputContainer = fAna->GetOutputContainer();
f37fa8d2 113
f15155ed 114 if (DebugLevel() >= 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserCreateOutputObjects() - n histograms %d\n",fOutputContainer->GetEntries());
115
4a745797 116 fOutputContainer->SetOwner(kTRUE);
f37fa8d2 117
f15155ed 118 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserCreateOutputObjects() - End\n");
119
609de1b2 120 PostData(1,fOutputContainer);
f15155ed 121
1c5acb87 122}
f15155ed 123
124//___________________________________________________
125void AliAnalysisTaskCaloTrackCorrelation::LocalInit()
0c1383b5 126{
127 // Local Initialization
128
37c0bcde 129 //Call the Init to initialize the configuration of the analysis
130 Init();
131
0c1383b5 132}
1c5acb87 133
f15155ed 134//______________________________________________
135void AliAnalysisTaskCaloTrackCorrelation::Init()
1c5acb87 136{
137 // Initialization
f15155ed 138
139 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::Init() - Begin\n");
477d6cee 140
141 // Call configuration file if specified
142
accd903d 143 if (fConfigName.Length())
144 {
f15155ed 145 printf("AliAnalysisTaskCaloTrackCorrelation::Init() - ### Configuration file is %s.C ###\n", fConfigName.Data());
146 gROOT->LoadMacro(fConfigName+".C");
147 fAna = (AliAnaCaloTrackCorrMaker*) gInterpreter->ProcessLine("ConfigAnalysis()");
1c5acb87 148 }
1c5acb87 149
fbeaf916 150 if(!fAna) {
f15155ed 151 printf("AliAnalysisTaskCaloTrackCorrelation::Init() - Analysis maker pointer not initialized, no analysis specified, STOP !\n");
152 abort();
477d6cee 153 }
1c5acb87 154
7175a03a 155 // Add different generator particles to PDG Data Base
156 // to avoid problems when reading MC generator particles
157 AliPDG::AddParticlesToPdgDataBase();
f15155ed 158
486258c9 159 //Set in the reader the name of the task in case is needed
160 (fAna->GetReader())->SetTaskName(GetName());
161
1c5acb87 162 // Initialise analysis
163 fAna->Init();
f15155ed 164
42dc8e7d 165 //Delta AOD
166 if((fAna->GetReader())->GetDeltaAODFileName()!="")
167 AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile((fAna->GetReader())->GetDeltaAODFileName());
f15155ed 168
169 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::Init() - End\n");
1c5acb87 170
171}
172
173
f15155ed 174//______________________________________________________________________
175void AliAnalysisTaskCaloTrackCorrelation::UserExec(Option_t */*option*/)
1c5acb87 176{
177 // Execute analysis for current event
f15155ed 178
179 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserExec() - Begin\n");
180
181 //Get the type of data, check if type is correct
1c5acb87 182 Int_t datatype = fAna->GetReader()->GetDataType();
183 if(datatype != AliCaloTrackReader::kESD && datatype != AliCaloTrackReader::kAOD &&
accd903d 184 datatype != AliCaloTrackReader::kMC)
185 {
f15155ed 186 printf("AliAnalysisTaskCaloTrackCorrelation::UserExec() - Wrong type of data\n");
1c5acb87 187 return ;
188 }
f15155ed 189
477d6cee 190 fAna->GetReader()->SetInputOutputMCEvent(InputEvent(), AODEvent(), MCEvent());
f15155ed 191
1c5acb87 192 //Process event
a79a2424 193 fAna->ProcessEvent((Int_t) Entry(), CurrentFileName());
f15155ed 194
195 //printf("AliAnalysisTaskCaloTrackCorrelation::Current Event %d; Current File Name : %s\n",(Int_t) Entry(), CurrentFileName());
196 if (DebugLevel() > 1) printf("AliAnalysisTaskCaloTrackCorrelation::UserExec() - End\n");
1cd71065 197
1c5acb87 198 PostData(1, fOutputContainer);
1cd71065 199
200 //gObjectTable->Print();
1c5acb87 201
202}
203
f15155ed 204//_______________________________________________________________________
205void AliAnalysisTaskCaloTrackCorrelation::Terminate(Option_t */*option*/)
1c5acb87 206{
207 // Terminate analysis
6639984f 208 // Do some plots
f15155ed 209
a5cc4f03 210 // Get merged histograms from the output container
a5cc4f03 211 // Propagate histagrams to maker
1cd71065 212 fAna->Terminate((TList*)GetOutputData(1));
a5cc4f03 213
accd903d 214 // Create cuts/param objects and publish to slot
215 fCuts = fAna->GetListOfAnalysisCuts();
216 fCuts ->SetOwner(kTRUE);
217 // Post Data
218 PostData(2, fCuts);
219
1c5acb87 220}
221
f15155ed 222//__________________________________________________________
223void AliAnalysisTaskCaloTrackCorrelation::FinishTaskOutput()
224{
66580b85 225 // Put in the output some event summary histograms
226 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
f15155ed 227
66580b85 228 AliInputEventHandler *inputH = dynamic_cast<AliInputEventHandler*>(am->GetInputEventHandler());
f15155ed 229
66580b85 230 if (!inputH) return;
f15155ed 231
66580b85 232 TH2F *histStat = dynamic_cast<TH2F*>(inputH->GetStatistics());
233 TH2F *histBin0 = dynamic_cast<TH2F*>(inputH->GetStatistics("BIN0"));
234
49b5c49b 235 if(histStat)fOutputContainer->Add(histStat);
236 else if(DebugLevel()>0)
f15155ed 237 printf("AliAnalysisTaskCaloTrackCorrelation::FinishTaskOutput() - Stat histogram not available check, \n if ESDs, that AliPhysicsSelection was on, \n if AODs, if EventStat_temp.root exists \n");
238
4b892846 239 if(histBin0)fOutputContainer->Add(histBin0);
66580b85 240
241}
242