correcting baryon mass subtraction for visible energy in MC
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJets.cxx
CommitLineData
e5b96aa0 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 **************************************************************************/
f1a3e20a 15
16/* $Id$ */
8838ab7a 17#include <Riostream.h>
e5b96aa0 18#include <TROOT.h>
19#include <TSystem.h>
20#include <TInterpreter.h>
21#include <TChain.h>
76c48857 22#include <TFile.h>
22003a60 23#include <TList.h>
0f5f5d71 24#include <TH1.h>
e5b96aa0 25
26#include "AliAnalysisTaskJets.h"
1d27ecd2 27#include "AliAnalysisManager.h"
e5b96aa0 28#include "AliJetFinder.h"
99c8d2ad 29#include "AliJetHeader.h"
8838ab7a 30#include "AliJetReader.h"
31#include "AliJetReaderHeader.h"
22003a60 32#include "AliJetHistos.h"
1b307662 33#include "AliESDEvent.h"
7f7091b8 34#include "AliESD.h"
1d27ecd2 35#include "AliAODEvent.h"
bcec7a80 36#include "AliAODJetEventBackground.h"
1d27ecd2 37#include "AliAODHandler.h"
691685d6 38#include "AliMCEventHandler.h"
9ff7671d 39#include "AliESDInputHandler.h"
7f7091b8 40#include "AliMCEvent.h"
691685d6 41#include "AliStack.h"
1d27ecd2 42
e5b96aa0 43
44ClassImp(AliAnalysisTaskJets)
45
46////////////////////////////////////////////////////////////////////////
47
19e6695b 48AliAnalysisTaskJets::AliAnalysisTaskJets():
8838ab7a 49 AliAnalysisTaskSE(),
50 fConfigFile("ConfigJetAnalysis.C"),
51 fNonStdBranch(""),
931c23a1 52 fNonStdFile(""),
4aa71b6f 53 fJetFinder(0x0),
54 fHistos(0x0),
931c23a1 55 fAODExtension(0x0),
8838ab7a 56 fListOfHistos(0x0),
57 fChain(0x0),
08c28025 58 fOpt(0),
0b64955a 59 fReadAODFromOutput(0),
60 fFilterPt(0.)
19e6695b 61{
62 // Default constructor
63}
64
e5b96aa0 65AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
8838ab7a 66 AliAnalysisTaskSE(name),
67 fConfigFile("ConfigJetAnalysis.C"),
68 fNonStdBranch(""),
931c23a1 69 fNonStdFile(""),
8838ab7a 70 fJetFinder(0x0),
71 fHistos(0x0),
931c23a1 72 fAODExtension(0x0),
8838ab7a 73 fListOfHistos(0x0),
74 fChain(0x0),
0f4a88df 75 fOpt(0),
0b64955a 76 fReadAODFromOutput(0),
77 fFilterPt(0.)
e5b96aa0 78{
79 // Default constructor
8838ab7a 80 DefineOutput(1, TList::Class());
eaabc21f 81}
82
8838ab7a 83AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
84 AliAnalysisTaskSE(name),
85 fConfigFile("ConfigJetAnalysis.C"),
86 fNonStdBranch(""),
931c23a1 87 fNonStdFile(""),
8838ab7a 88 fJetFinder(0x0),
89 fHistos(0x0),
931c23a1 90 fAODExtension(0x0),
8838ab7a 91 fListOfHistos(0x0),
92 fChain(chain),
0f4a88df 93 fOpt(0),
0b64955a 94 fReadAODFromOutput(0),
95 fFilterPt(0.)
eaabc21f 96{
8838ab7a 97 // Default constructor
98 DefineOutput(1, TList::Class());
99}
4aa71b6f 100
8838ab7a 101//----------------------------------------------------------------
102void AliAnalysisTaskJets::UserCreateOutputObjects()
103{
104 // Create the output container
105 //
106 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
931c23a1 107
8838ab7a 108 if(fNonStdBranch.Length()==0)
109 {
4aa71b6f 110 // Connec default AOD to jet finder
bcec7a80 111 // create a new branch for the background
112 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
113 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
114 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
115 AddAODBranch("AliAODJetEventBackground",&evBkg);
116 }
4aa71b6f 117 fJetFinder->ConnectAOD(AODEvent());
118 }
8838ab7a 119 else
120 {
4aa71b6f 121 // Create a new branch for jets...
8838ab7a 122 // how is this reset? -> cleared in the UserExec....
4aa71b6f 123 // Can this be handled by the framework?
931c23a1 124 // here we can also have the case that the brnaches are written to a separate file
125
4aa71b6f 126 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
931c23a1 127 tca->SetName(fNonStdBranch.Data());
128 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
8bca421f 129 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
bcec7a80 130 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
131 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
931c23a1 132 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
133 }
134
135 if(fNonStdFile.Length()!=0){
136 //
137 // case that we have an AOD extension we need to fetch the jets from the extended output
138 // we identifay the extension aod event by looking for the branchname
139 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
225f0094 140 fAODExtension = 0;
141 if(aodH){
142 TObjArray* extArray = aodH->GetExtensions();
143 if (extArray) {
144 TIter next(extArray);
145 while ((fAODExtension=(AliAODExtension*)next())){
146 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
147 if(fDebug>10){
148 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
149 fAODExtension->GetAOD()->Dump();
150 }
151 if(obj){
931c23a1 152 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
153 break;
225f0094 154 }
155 fAODExtension = 0;
931c23a1 156 }
931c23a1 157 }
158 }
159 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
160 }
161 else{
294056ab 162 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
931c23a1 163 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
bcec7a80 164 }
8838ab7a 165 }
bcec7a80 166
0f5f5d71 167 // do not add the histograms in the directory
168 // all handled by the list
169 Bool_t oldStatus = TH1::AddDirectoryStatus();
170 TH1::AddDirectory(kFALSE);
171
952b368c 172
8838ab7a 173 // Histograms
8838ab7a 174 fListOfHistos = new TList();
175 fHistos = new AliJetHistos();
176 fHistos->AddHistosToList(fListOfHistos);
177
178 // Add the JetFinderInformation to the Outputlist
179 AliJetHeader *fH = fJetFinder->GetHeader();
180
181 // Compose a characteristic output name
182 // with the name of the output branch
183 if(fH) {
184 if(fNonStdBranch.Length()==0) {
185 fH->SetName("AliJetHeader_jets");
4aa71b6f 186 }
8838ab7a 187 else {
188 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
99c8d2ad 189 }
8838ab7a 190 }
0f5f5d71 191
192 TH1::AddDirectory(oldStatus);
193
194
931c23a1 195 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
196 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
e5b96aa0 197}
198
8838ab7a 199//----------------------------------------------------------------
19e6695b 200void AliAnalysisTaskJets::Init()
e5b96aa0 201{
8838ab7a 202 // Initialization
203 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
204
205 // Call configuration file
206 if (fConfigFile.Length()) {
207 gROOT->LoadMacro(fConfigFile);
208 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
209 }
210 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
211 fOpt = header->GetDetector();
212
213 // Initialise Jet Analysis
214 if(fOpt == 0) fJetFinder->Init();
215 else fJetFinder->InitTask(fChain); // V2
19e6695b 216}
217
931c23a1 218
8838ab7a 219//----------------------------------------------------------------
ae24a5a1 220void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
e5b96aa0 221{
4aa71b6f 222 // Execute analysis for current event
223 //
4aa71b6f 224 // Fill control histos
225 TClonesArray* jarray = 0;
8bca421f 226 AliAODJetEventBackground* evBkg = 0;
8838ab7a 227
0b64955a 228 // only need this once
229 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
230
8838ab7a 231 if(fNonStdBranch.Length()==0) {
4aa71b6f 232 jarray = AODEvent()->GetJets();
bcec7a80 233 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
234 evBkg->Reset();
4aa71b6f 235 }
8838ab7a 236 else {
8bca421f 237 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
931c23a1 238 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
8bca421f 239 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
240 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
931c23a1 241 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
8bca421f 242 if(evBkg)evBkg->Reset();
4aa71b6f 243 }
931c23a1 244
0f4a88df 245 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
246// AOD is input event..........................................V
c98859dd 247 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
248 } else {
0f4a88df 249// AOD is read from output ....................................V
c98859dd 250 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
251 }
252
253
4aa71b6f 254
8838ab7a 255 if(fOpt==0) fJetFinder->ProcessEvent();
256 else fJetFinder->ProcessEvent2(); // V2
257
258 // Fill control histos
8bca421f 259 if(jarray)fHistos->FillHistos(jarray);
8838ab7a 260
0b64955a 261
262 if(aodH&&fFilterPt>0){
263 if(jarray->GetEntries()>0){
264 AliAODJet *jet = (AliAODJet*)jarray->At(0);
265 if(jet->Pt()>fFilterPt){
266 // aodH->EnableFillAODforEvent();
267 aodH->SetFillAOD(kTRUE);
268 }
269 }
270 }
271
4aa71b6f 272 // Post the data
273 PostData(1, fListOfHistos);
931c23a1 274 return;
e5b96aa0 275}
276
8838ab7a 277
278//*************************************************************
279
e5b96aa0 280void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
281{
282// Terminate analysis
283//
19e6695b 284 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
9ff7671d 285// if (fJetFinder) fJetFinder->FinishRun();
e5b96aa0 286}
287