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