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