]> git.uio.no Git - u/mrichter/AliRoot.git/blame - JETAN/AliJetFinder.cxx
Reference to tracks forming the jet added.
[u/mrichter/AliRoot.git] / JETAN / AliJetFinder.cxx
CommitLineData
99e5fe42 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 **************************************************************************/
83a444b1 15
52ff852a 16/* $Id$ */
17
99e5fe42 18//---------------------------------------------------------------------
19// Jet finder base class
20// manages the search for jets
7d0f353c 21// Authors: jgcn@mda.cinvestav.mx
22// andreas.morsch@cern.ch
99e5fe42 23//---------------------------------------------------------------------
24
25#include <Riostream.h>
26#include <TFile.h>
1d27ecd2 27#include <TClonesArray.h>
28
99e5fe42 29#include "AliJetFinder.h"
30#include "AliJet.h"
1d27ecd2 31#include "AliAODJet.h"
99e5fe42 32#include "AliJetReader.h"
33#include "AliJetReaderHeader.h"
34#include "AliJetControlPlots.h"
35#include "AliLeading.h"
1d27ecd2 36#include "AliAODEvent.h"
99e5fe42 37
99e5fe42 38ClassImp(AliJetFinder)
39
1b7d5d7e 40AliJetFinder::AliJetFinder():
eaabc21f 41 fTreeJ(0),
7d0f353c 42 fPlotMode(kFALSE),
43 fJets(0),
44 fGenJets(0),
45 fLeading(0),
46 fReader(0x0),
19e6695b 47 fHeader(0x0),
1d27ecd2 48 fAODjets(0x0),
49 fNAODjets(0),
7d0f353c 50 fPlots(0x0),
51 fOut(0x0)
52
99e5fe42 53{
99e5fe42 54 // Constructor
655dbb2b 55 fJets = new AliJet();
99e5fe42 56 fGenJets = new AliJet();
57 fLeading = new AliLeading();
1d27ecd2 58 fAODjets = 0;
99e5fe42 59}
60
99e5fe42 61////////////////////////////////////////////////////////////////////////
62
63AliJetFinder::~AliJetFinder()
64{
99e5fe42 65 // destructor
99e5fe42 66 // here reset and delete jets
67 fJets->ClearJets();
68 delete fJets;
69 fGenJets->ClearJets();
70 delete fGenJets;
71 // close file
72 if (fOut) {
73 fOut->Close();
74 fOut->Delete();
75 }
76 delete fOut;
77 // reset and delete control plots
78 if (fPlots) delete fPlots;
dbd1a3a2 79 if ( fLeading )
80 delete fLeading;
81 fLeading = NULL;
99e5fe42 82}
83
99e5fe42 84////////////////////////////////////////////////////////////////////////
85
1d27ecd2 86void AliJetFinder::SetOutputFile(const char */*name*/)
99e5fe42 87{
eaabc21f 88 // opens output file
1d27ecd2 89 // fOut = new TFile(name,"recreate");
99e5fe42 90}
91
99e5fe42 92////////////////////////////////////////////////////////////////////////
93
94void AliJetFinder::PrintJets()
95{
83a444b1 96 // Print jet information
99e5fe42 97 cout << " Jets found with jet algorithm:" << endl;
98 fJets->PrintJets();
99 cout << " Jets found by pythia:" << endl;
100 fGenJets->PrintJets();
101}
102
99e5fe42 103////////////////////////////////////////////////////////////////////////
104
105void AliJetFinder::SetPlotMode(Bool_t b)
106{
83a444b1 107 // Sets the plotting mode
99e5fe42 108 fPlotMode=b;
109 if (b && !fPlots) fPlots = new AliJetControlPlots();
110}
111
112////////////////////////////////////////////////////////////////////////
eaabc21f 113TTree* AliJetFinder::MakeTreeJ(char* name)
99e5fe42 114{
eaabc21f 115 // Create the tree for reconstructed jets
eaabc21f 116 fTreeJ = new TTree(name, "AliJet");
117 fTreeJ->Branch("FoundJet", &fJets, 1000);
118 fTreeJ->Branch("GenJet", &fGenJets,1000);
119 fTreeJ->Branch("LeadingPart",&fLeading,1000);
120 return fTreeJ;
99e5fe42 121}
122
123////////////////////////////////////////////////////////////////////////
124
125void AliJetFinder::WriteRHeaderToFile()
126{
127 // write reader header
76c48857 128 AliJetReaderHeader *rh = fReader->GetReaderHeader();
129 rh->Write();
99e5fe42 130}
131
99e5fe42 132////////////////////////////////////////////////////////////////////////
133
99e5fe42 134
135void AliJetFinder::Run()
136{
7d0f353c 137 // Do some initialization
99e5fe42 138 Init();
99e5fe42 139 // connect files
140 fReader->OpenInputFiles();
141
142 // write headers
7d0f353c 143 WriteHeaders();
99e5fe42 144 // loop over events
b45b0c92 145 Int_t nFirst, nLast, option, debug, arrayInitialised;
99e5fe42 146 nFirst = fReader->GetReaderHeader()->GetFirstEvent();
b45b0c92 147 nLast = fReader->GetReaderHeader()->GetLastEvent();
148
149 option = fReader->GetReaderHeader()->GetDetector();
150 debug = fReader->GetReaderHeader()->GetDebug();
151 arrayInitialised = fReader->GetArrayInitialised();
152
99e5fe42 153 // loop over events
154 for (Int_t i=nFirst;i<nLast;i++) {
ae24a5a1 155 fReader->FillMomentumArray();
99e5fe42 156 fLeading->FindLeading(fReader);
7d0f353c 157 fReader->GetGenJets(fGenJets);
b45b0c92 158
159 if (option == 0) { // TPC with fMomentumArray
160 if(debug > 1)
161 printf("In FindJetsTPC() routine: find jets with fMomentumArray !!!\n");
162 FindJetsTPC();
163 } else {
1d27ecd2 164 if(debug > 1) printf("In FindJets() routine: find jets with fUnitArray !!!\n");
165 FindJets();
b45b0c92 166 }
eaabc21f 167 if (fOut) {
168 fOut->cd();
eaabc21f 169 }
170
83a444b1 171 if (fPlots) fPlots->FillHistos(fJets);
99e5fe42 172 fLeading->Reset();
173 fGenJets->ClearJets();
174 Reset();
175 }
b45b0c92 176
99e5fe42 177 // write out
178 if (fPlots) {
179 fPlots->Normalize();
180 fPlots->PlotHistos();
181 }
182 if (fOut) {
183 fOut->cd();
184 fPlots->Write();
185 fOut->Close();
186 }
187}
7d0f353c 188
189
190//
191// The following methods have been added to allow for event steering from the outside
192//
193
f3f3617d 194void AliJetFinder::ConnectTree(TTree* tree, TObject* data)
7d0f353c 195{
196 // Connect the input file
f3f3617d 197 fReader->ConnectTree(tree, data);
7d0f353c 198}
199
200void AliJetFinder::WriteHeaders()
201{
202 // Write the Headers
76c48857 203 TFile* f = new TFile("jets_local.root", "recreate");
204 WriteRHeaderToFile();
205 WriteJHeaderToFile();
206 f->Close();
7d0f353c 207}
208
209
ae24a5a1 210Bool_t AliJetFinder::ProcessEvent()
7d0f353c 211{
212//
213// Process one event
214//
ae24a5a1 215 Bool_t ok = fReader->FillMomentumArray();
7d0f353c 216 if (!ok) return kFALSE;
76c48857 217
218 // Leading particles
7d0f353c 219 fLeading->FindLeading(fReader);
76c48857 220 // Jets
7d0f353c 221 FindJets();
76c48857 222
7d0f353c 223 if (fPlots) fPlots->FillHistos(fJets);
224 fLeading->Reset();
225 fGenJets->ClearJets();
226 Reset();
227 return kTRUE;
228}
229
230void AliJetFinder::FinishRun()
231{
232 // Finish a run
eaabc21f 233 if (fPlots) {
234 fPlots->Normalize();
235 fPlots->PlotHistos();
236 }
237
238 if (fOut) {
239 fOut->cd();
eaabc21f 240 if (fPlots) {
241 fPlots->Write();
242 }
243 fOut->Close();
244 }
7d0f353c 245}
246
1d27ecd2 247void AliJetFinder::AddJet(AliAODJet p)
248{
4aa71b6f 249 // Add new jet to the list
1d27ecd2 250 new ((*fAODjets)[fNAODjets++]) AliAODJet(p);
251}
252
253void AliJetFinder::ConnectAOD(AliAODEvent* aod)
254{
255// Connect to the AOD
1d27ecd2 256 fAODjets = aod->GetJets();
1d27ecd2 257}
4aa71b6f 258
259void AliJetFinder::ConnectAODNonStd(AliAODEvent* aod,const char *bname)
260{
261
262 fAODjets = dynamic_cast<TClonesArray*>(aod->FindListObject(bname));
263 // how is this is reset? Cleared?
264}