]>
Commit | Line | Data |
---|---|---|
e8f1e037 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2002, 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 | ||
17 | /* | |
18 | $Log$ | |
19 | */ | |
20 | ||
21 | //*-- Authors: Aleksei Pavlinov (WSU) | |
22 | //* | |
23 | ||
24 | #include "AliEMCALJetMicroDst.h" | |
25 | #include "AliRun.h" | |
26 | #include "AliHeader.h" | |
27 | #include "AliGenEventHeader.h" | |
28 | #include "AliGenHijingEventHeader.h" | |
29 | #include "AliEMCALJetFinder.h" | |
30 | #include <TVector3.h> | |
31 | #include <TROOT.h> | |
32 | #include <TBrowser.h> | |
33 | #include <TString.h> | |
34 | #include <TParticle.h> | |
35 | ||
36 | ClassImp(AliEMCALJetMicroDst) | |
37 | ||
38 | TString nameTree("jetMDST"); // 7-feb-2002 | |
39 | ||
40 | TH1F* hPtPart, *hNJet, *hPtJet; | |
41 | TH2F* hEtaPhiPart, *hEtaPhiJet; | |
42 | ||
43 | AliEMCALJetMicroDst::AliEMCALJetMicroDst(char *name, char *tit) : TNamed(name,tit) | |
44 | { | |
45 | fFile = 0; | |
46 | fTree = 0; | |
47 | fDebug = 0; | |
48 | fName = "dstTest.root"; // default name | |
49 | ||
50 | // Don't add histos to the current directory | |
51 | // TH1::AddDirectory(0); | |
52 | gROOT->cd(); | |
53 | hPtPart = new TH1F("hPtPart","P_{T} for partons", 300, 0., 300.); | |
54 | hEtaPhiPart = new TH2F("hEtaPhiPart","#eta #phi distr.for partons after HSc", | |
55 | 28, -0.7, 0.7, 21, 0.0, TMath::Pi()*2./3.); | |
56 | ||
57 | hNJet = new TH1F("hNJet","number of jets", 11, -0.5, 10.5); | |
58 | hPtJet = new TH1F("hPtJet","P_{T} for jets", 300, 0., 300.); | |
59 | hEtaPhiJet = new TH2F("hEtaPhiJet","#eta #phi distr.for jets (W)", | |
60 | 28, -0.7, 0.7, 21, 0.0, TMath::Pi()*2./3.); | |
61 | fListHist = MoveHistsToList("Hist For AliEMCALJetMicroDst", kFALSE); | |
62 | } | |
63 | ||
64 | AliEMCALJetMicroDst::~AliEMCALJetMicroDst() | |
65 | { | |
66 | if(fFile) fFile->Close(); | |
67 | } | |
68 | ||
69 | Bool_t AliEMCALJetMicroDst::Create(TFile *file) | |
70 | { | |
71 | if(!file) { | |
72 | printf("<E> AliEMCALJetMicroDst::create -> define TFile for output\n"); | |
73 | return kFALSE; | |
74 | } | |
75 | fFile = file; | |
76 | fFile->cd(); | |
77 | fTree = new TTree(nameTree.Data(),"Temporary micro DST for jets analysis"); | |
78 | // partons | |
79 | fTree->Branch("npart", &fNpart, "npart/I"); | |
80 | fTree->Branch("xpt", fXpt, "xpt[npart]/F"); | |
81 | fTree->Branch("xeta", fXeta, "xeta[npart]/F"); | |
82 | fTree->Branch("xphi", fXphi, "xphi[npart]/F"); | |
83 | // jets | |
84 | fTree->Branch("njet", &fNjet, "njet/I"); | |
85 | fTree->Branch("jet", fJet, "jet[njet]/F"); | |
86 | fTree->Branch("jetaw", fJetaW, "jetaw[njet]/F"); | |
87 | fTree->Branch("jphiw", fJphiW, "jphiw[njet]/F"); | |
88 | fTree->Branch("jetal", fJetaL, "jetal[njet]/F"); | |
89 | fTree->Branch("jphil", fJphiL, "jphil[njet]/F"); | |
90 | return kTRUE; | |
91 | } | |
92 | ||
93 | Bool_t AliEMCALJetMicroDst::Create(const char *fname) | |
94 | { | |
95 | TFile *file = new TFile(fname, "RECREATE"); | |
96 | if(file) { | |
97 | fName = fname; | |
98 | return Create(file); | |
99 | } else return kFALSE; | |
100 | } | |
101 | ||
102 | Bool_t AliEMCALJetMicroDst::Open(const char *fname) | |
103 | { | |
104 | if(fFile && fFile->IsOpen()) fFile->Close(); | |
105 | if(strlen(fname)) fName = fname; | |
106 | TFile *file = new TFile(fName.Data(), "READ"); | |
107 | if(file) { | |
108 | printf("<I> open file %s \n",fName.Data()); | |
109 | return Initialize(file); | |
110 | } else { | |
111 | printf("<E> can not open file %s \n",fName.Data()); | |
112 | return kFALSE; | |
113 | } | |
114 | } | |
115 | ||
116 | Bool_t AliEMCALJetMicroDst::Initialize(TFile *file) | |
117 | { | |
118 | if(file) fFile = file; | |
119 | fFile->cd(); | |
120 | fTree = (TTree*)fFile->Get(nameTree.Data()); | |
121 | if(!fTree) return kFALSE; | |
122 | // partons | |
123 | fTree->SetBranchAddress("npart",&fNpart); | |
124 | fTree->SetBranchAddress("xpt", fXpt); | |
125 | fTree->SetBranchAddress("xeta", fXeta); | |
126 | fTree->SetBranchAddress("xphi", fXphi); | |
127 | // jets | |
128 | fTree->SetBranchAddress("njet", &fNjet); | |
129 | fTree->SetBranchAddress("jet", fJet); | |
130 | fTree->SetBranchAddress("jetaw", fJetaW); | |
131 | fTree->SetBranchAddress("jphiw", fJphiW); | |
132 | fTree->SetBranchAddress("jetal", fJetaL); | |
133 | fTree->SetBranchAddress("jphil", fJphiL); | |
134 | ||
135 | return kTRUE; | |
136 | } | |
137 | ||
138 | void AliEMCALJetMicroDst::Print(Option_t* option) const | |
139 | { | |
140 | if(option); | |
141 | if(fFile) { | |
142 | fFile->Print(); | |
143 | if(fTree) fTree->Print(); | |
144 | else printf("<I> TRee is zero\n"); | |
145 | } else printf("<I> File with TRee is zero\n"); | |
146 | printf("Default name of file %s\n", fName.Data()); | |
147 | ||
148 | printf("\n #partons %2i ", fNpart); | |
149 | for(Int_t i=0; i<fNpart; i++){ | |
150 | printf("\n %1i Pt %7.1f eta %f7.4 phi %f7.4 ", | |
151 | i, fXpt[i],fXeta[i],fXphi[i]); | |
152 | } | |
153 | ||
154 | printf("\n #jets %2i ", fNjet); | |
155 | for(Int_t i=0; i<fNjet; i++){ | |
156 | printf("\n %1i Et %7.1f etaW %f7.4 phiW %f7.4 ", | |
157 | i,fJet[i],fJetaW[i],fJphiW[i]); | |
158 | } | |
159 | } | |
160 | ||
161 | void AliEMCALJetMicroDst::Fill(AliRun *run, AliEMCALJetFinder* jetFinder) | |
162 | { | |
163 | if(!run) run = gAlice; | |
164 | AliGenEventHeader* evHeader = run->GetHeader()->GenEventHeader(); | |
165 | TString tmp(evHeader->ClassName()); | |
166 | if(tmp.Contains("Hijing")) { | |
167 | AliGenHijingEventHeader *hijEvHeader = (AliGenHijingEventHeader*)evHeader; | |
168 | FillPartons(hijEvHeader); | |
169 | } else if(tmp.Contains("Pythia")) { | |
170 | FillPartons(); | |
171 | } else { | |
172 | printf("\n <E> Wrong type of generator -> %s ",tmp.Data()); | |
173 | printf("\n Inof about partons will be absent "); | |
174 | } | |
175 | ||
176 | FillJets(jetFinder); | |
177 | fTree->Fill(); | |
178 | } | |
179 | ||
180 | void AliEMCALJetMicroDst::FillPartons(AliGenHijingEventHeader *header) | |
181 | { | |
182 | TLorentzVector parton[4]; | |
183 | header->GetJets(parton[0], parton[1], parton[2], parton[3]); | |
184 | ||
185 | fNpart = 4; // | |
186 | for(Int_t i=0; i<4; i++){ | |
187 | fXpt[i] = parton[i].Pt(); | |
188 | fXeta[i] = parton[i].Eta(); | |
189 | fXphi[i] = parton[i].Phi(); | |
190 | if(i>1) { | |
191 | hEtaPhiPart->Fill(parton[i].Eta(), parton[i].Phi()); | |
192 | hPtPart->Fill(parton[i].Pt()); | |
193 | } | |
194 | } | |
195 | } | |
196 | ||
197 | void AliEMCALJetMicroDst::FillPartons() | |
198 | {// for case of Pythia -> get info from full event record | |
199 | ||
200 | fNpart = 2; | |
201 | TParticle *MPart; | |
202 | Int_t ind; | |
203 | for(Int_t i=6; i<8; i++){ | |
204 | MPart = gAlice->Particle(i); | |
205 | ind = i-6; | |
206 | fXpt[ind] = MPart->Pt(); | |
207 | fXeta[ind] = MPart->Eta(); | |
208 | fXphi[ind] = MPart->Phi(); | |
209 | ||
210 | hEtaPhiPart->Fill(fXeta[ind], fXphi[ind]); | |
211 | hPtPart->Fill(fXpt[ind]); | |
212 | } | |
213 | } | |
214 | ||
215 | void AliEMCALJetMicroDst::FillJets(AliEMCALJetFinder* jetFinder) | |
216 | { | |
217 | fNjet = 0; | |
218 | if(fDebug>1) printf("\n<I> AliEMCALJetMicroDst::FillJets"); | |
219 | if(!jetFinder) { | |
220 | if(fDebug>1) printf("\n : jetFinder is zero"); | |
221 | return; | |
222 | } | |
223 | fNjet = jetFinder->Njets(); | |
224 | if(fNjet>10) { | |
225 | if(fDebug>1) printf("\n <W> wrong value of jetFinder->Njets() %i ", fNjet); | |
226 | fNjet = 10; | |
227 | } | |
228 | hNJet->Fill(fNjet); | |
229 | if(fDebug>1) printf("\n <I> fNjet %i", fNjet); | |
230 | if(fNjet){ | |
231 | for(Int_t i=0; i<fNjet; i++){ | |
232 | fJet[i] = jetFinder->JetEnergy(i); | |
233 | fJetaW[i] = jetFinder->JetEtaW(i); | |
234 | fJphiW[i] = jetFinder->JetPhiW(i); | |
235 | fJetaL[i] = jetFinder->JetEtaL(i); | |
236 | fJphiL[i] = jetFinder->JetPhiL(i); | |
237 | hPtJet->Fill(fJet[i]); | |
238 | hEtaPhiJet->Fill(fJetaW[i],fJphiW[i]); | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | Int_t AliEMCALJetMicroDst::GetEntry(Int_t entry) | |
244 | { // Read contents of entry. | |
245 | if (!fTree) { | |
246 | printf("\n<E> AliEMCALJetMicroDst::GetEntry() -> define TTree \n"); | |
247 | return -1; | |
248 | } | |
249 | return fTree->GetEntry(entry); | |
250 | } | |
251 | ||
252 | Bool_t AliEMCALJetMicroDst::GetParton(Int_t i, Float_t& pt, Float_t& eta, Float_t& phi) | |
253 | { | |
254 | if(i>=0 && i<fNpart) { | |
255 | pt = fXpt[i]; | |
256 | eta = fXeta[i]; | |
257 | phi = fXphi[i]; | |
258 | return kTRUE; | |
259 | } else return kFALSE; | |
260 | } | |
261 | ||
262 | Bool_t AliEMCALJetMicroDst::GetParton(Int_t i, TVector3& vec) | |
263 | { | |
264 | static Float_t pt, eta, phi; | |
265 | ||
266 | if(!GetParton(i, pt, eta, phi)) return kFALSE; | |
267 | ||
268 | FillVector(pt, eta, phi, vec); | |
269 | return kTRUE; | |
270 | } | |
271 | ||
272 | Bool_t AliEMCALJetMicroDst::GetJet(Int_t i,Int_t mode,Float_t& pt, Float_t& eta, Float_t& phi) | |
273 | {// mode=1(W) mode=any(L) | |
274 | if(i>=0 && i<fNjet) { | |
275 | pt = fJet[i]; | |
276 | if(mode==1) { | |
277 | eta = fJetaW[i]; | |
278 | phi = fJphiW[i]; | |
279 | } else { | |
280 | eta = fJetaL[i]; | |
281 | phi = fJphiL[i]; | |
282 | } | |
283 | return kTRUE; | |
284 | } else return kFALSE; | |
285 | } | |
286 | ||
287 | Bool_t AliEMCALJetMicroDst::GetJet(Int_t i, Int_t mode, TVector3& vec) | |
288 | { | |
289 | static Float_t pt, eta, phi; | |
290 | ||
291 | if(!GetJet(i, mode, pt, eta, phi)) return kFALSE; | |
292 | FillVector(pt, eta, phi, vec); | |
293 | return kTRUE; | |
294 | } | |
295 | ||
296 | void AliEMCALJetMicroDst::Test() | |
297 | { | |
298 | if(!fFile || !fTree ) { | |
299 | printf("\n<I> AliEMCALJetMicroDst::Test() -> define file with proper TTree !"); | |
300 | return; | |
301 | } | |
302 | Int_t nbytes=0, nb=0, nentries=Int_t(fTree->GetEntries()); | |
303 | for(Int_t i=0; i<nentries; i++){ | |
304 | nb = fTree->GetEntry(i); | |
305 | nbytes += nb; | |
306 | for(Int_t j=0; j<fNpart; j++){ | |
307 | hEtaPhiPart->Fill(fXeta[j], fXphi[j]); | |
308 | hPtPart->Fill(fXpt[j]); | |
309 | } | |
310 | ||
311 | hNJet->Fill(fNjet); | |
312 | if(fNjet){ | |
313 | for(Int_t j=0; j<fNjet; j++) { | |
314 | hPtJet->Fill(fJet[j]); | |
315 | hEtaPhiJet->Fill(fJetaW[j],fJphiW[j]); | |
316 | } | |
317 | } | |
318 | } | |
319 | printf("\n<I> AliEMCALJetMicroDst::Test() -> Entries %5i Bytes %10i\n", nentries, nb); | |
320 | } | |
321 | ||
322 | void AliEMCALJetMicroDst::FillVector(Float_t pt, Float_t eta, Float_t phi, TVector3& vec) | |
323 | { // service function | |
324 | static Float_t px, py, pz; | |
325 | ||
326 | px = pt*TMath::Cos(phi); | |
327 | py = pt*TMath::Sin(phi); | |
328 | pz = pt*TMath::SinH(eta); // sinh(eta) = cot(theta) | |
329 | ||
330 | vec.SetXYZ(px, py, pz); | |
331 | } | |
332 | ||
333 | void AliJetMicroDst::Close() | |
334 | { | |
335 | fFile->Write(); | |
336 | fTree->Print(); | |
337 | fFile->Close(); | |
338 | fFile = 0; | |
339 | fTree = 0; | |
340 | } | |
341 | ||
342 | void AliJetMicroDst::Browse(TBrowser* b) | |
343 | { | |
344 | if(fTree) b->Add((TObject*)fTree); | |
345 | if(fListHist) b->Add((TObject*)fListHist); | |
346 | // TObject::Browse(b); | |
347 | } | |
348 | ||
349 | Bool_t AliJetMicroDst::IsFolder() const | |
350 | { | |
351 | if(fTree || fListHist) return kTRUE; | |
352 | else return kFALSE; | |
353 | } | |
354 | ||
355 | TList* AliJetMicroDst::MoveHistsToList(char* name, Bool_t putToBrowser) | |
356 | { | |
357 | gROOT->cd(); | |
358 | TIter nextHist(gDirectory->GetList()); | |
359 | TList *list = new TList; | |
360 | list->SetName(name); | |
361 | TObject *objHist; | |
362 | while((objHist=nextHist())){ | |
363 | if (!objHist->InheritsFrom("TH1")) continue; | |
364 | ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT | |
365 | list->Add(objHist); | |
366 | } | |
367 | if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list); | |
368 | return list; | |
369 | } |