]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliAnalysisTaskJets.cxx
Fixes for cmake
[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
25 #include "AliAnalysisTaskJets.h"
26 #include "AliAnalysisManager.h"
27 #include "AliJetFinder.h"
28 #include "AliJetHeader.h"
29 #include "AliJetReader.h"
30 #include "AliJetReaderHeader.h"
31 #include "AliJetHistos.h"
32 #include "AliESDEvent.h"
33 #include "AliESD.h"
34 #include "AliAODEvent.h"
35 #include "AliAODJetEventBackground.h"
36 #include "AliAODHandler.h"
37 #include "AliMCEventHandler.h"
38 #include "AliESDInputHandler.h"
39 #include "AliMCEvent.h"
40 #include "AliStack.h"
41
42
43 ClassImp(AliAnalysisTaskJets)
44
45 ////////////////////////////////////////////////////////////////////////
46
47 AliAnalysisTaskJets::AliAnalysisTaskJets():
48   AliAnalysisTaskSE(),
49   fConfigFile("ConfigJetAnalysis.C"),
50   fNonStdBranch(""), 
51   fJetFinder(0x0),
52   fHistos(0x0),
53   fListOfHistos(0x0),
54   fChain(0x0),
55   fOpt(0)
56 {
57   // Default constructor
58 }
59
60 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
61   AliAnalysisTaskSE(name),
62   fConfigFile("ConfigJetAnalysis.C"),
63   fNonStdBranch(""),
64   fJetFinder(0x0),
65   fHistos(0x0),
66   fListOfHistos(0x0),
67   fChain(0x0),
68   fOpt(0)
69 {
70   // Default constructor
71   DefineOutput(1, TList::Class());
72 }
73
74 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
75   AliAnalysisTaskSE(name),
76   fConfigFile("ConfigJetAnalysis.C"),
77   fNonStdBranch(""),
78   fJetFinder(0x0),
79   fHistos(0x0),
80   fListOfHistos(0x0),
81   fChain(chain),
82   fOpt(0)
83 {
84   // Default constructor
85   DefineOutput(1, TList::Class());
86 }
87
88 //----------------------------------------------------------------
89 void AliAnalysisTaskJets::UserCreateOutputObjects()
90 {
91   // Create the output container
92   //
93   if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
94   
95   if(fNonStdBranch.Length()==0)
96     {
97       //  Connec default AOD to jet finder
98       // create a new branch for the background
99       if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
100         AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
101         evBkg->SetName(AliAODJetEventBackground::StdBranchName());
102         AddAODBranch("AliAODJetEventBackground",&evBkg);
103       }
104       fJetFinder->ConnectAOD(AODEvent());
105     }
106   else
107     {
108       // Create a new branch for jets...
109       // how is this reset? -> cleared in the UserExec....
110       // Can this be handled by the framework?
111       TClonesArray *tca = new TClonesArray("AliAODJet", 0);
112       tca->SetName(fNonStdBranch);
113       AddAODBranch("TClonesArray",&tca);
114       if(!AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
115         AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
116         evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
117         AddAODBranch("AliAODJetEventBackground",&evBkg);
118       }
119       fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data()); 
120     }
121
122
123   // Histograms
124   OpenFile(1);
125   fListOfHistos = new TList();
126   fHistos       = new AliJetHistos();
127   fHistos->AddHistosToList(fListOfHistos);
128   
129   // Add the JetFinderInformation to the Outputlist
130   AliJetHeader *fH = fJetFinder->GetHeader();
131   
132   // Compose a characteristic output name
133   // with the name of the output branch
134   if(fH) {
135     if(fNonStdBranch.Length()==0) {
136       fH->SetName("AliJetHeader_jets");
137     }
138     else {
139       fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
140     }
141   }
142   OutputTree()->GetUserInfo()->Add(fH);
143 }
144
145 //----------------------------------------------------------------
146 void AliAnalysisTaskJets::Init()
147 {
148   // Initialization
149   if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
150   
151   // Call configuration file
152   if (fConfigFile.Length()) {
153     gROOT->LoadMacro(fConfigFile);
154     fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
155   }
156   AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
157   fOpt = header->GetDetector();
158
159   // Initialise Jet Analysis
160   if(fOpt == 0) fJetFinder->Init();
161   else fJetFinder->InitTask(fChain); // V2
162   
163   // Write header information to local file
164   fJetFinder->WriteHeaders();
165 }
166
167 //----------------------------------------------------------------
168 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
169 {
170   // Execute analysis for current event
171   //
172   // Fill control histos
173   TClonesArray* jarray = 0;
174   AliAODJetEventBackground*  evBkg;
175
176   if(fNonStdBranch.Length()==0) {
177     jarray = AODEvent()->GetJets();
178     evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
179     evBkg->Reset();
180   }
181   else {
182     jarray = dynamic_cast<TClonesArray*>(AODEvent()->FindListObject(fNonStdBranch.Data()));
183     jarray->Delete();    // this is our responsibility, clear before filling again
184     evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
185     evBkg->Reset();
186   }
187   if (dynamic_cast<AliAODEvent*>(InputEvent()) !=  0) {
188       fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
189   } else {
190       fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
191   }
192   
193   
194
195   if(fOpt==0) fJetFinder->ProcessEvent();
196   else fJetFinder->ProcessEvent2();    // V2
197  
198   // Fill control histos
199   fHistos->FillHistos(jarray);
200
201   // Post the data
202   PostData(1, fListOfHistos);
203 }
204
205
206 //*************************************************************
207
208 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
209 {
210 // Terminate analysis
211 //
212     if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
213 //    if (fJetFinder) fJetFinder->FinishRun();
214 }
215