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