4ae78bb1 |
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 | |
803d1ab0 |
16 | /* $Id$ */ |
4ae78bb1 |
17 | |
18 | //_________________________________________________________________________ |
19 | // A singleton. This class should be used in the analysis stage to get |
20 | // reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles, |
21 | // instead of directly reading them from galice.root file. This container |
22 | // ensures, that one reads Digits, made of these particular digits, RecPoints, |
23 | // made of these particular RecPoints, TrackSegments and RecParticles. |
24 | // This becomes non trivial if there are several identical branches, produced with |
25 | // different set of parameters. |
26 | // |
27 | // An example of how to use (see also class AliPHOSAnalyser): |
28 | // AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ; |
29 | // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++) |
30 | // AliPHOSRecParticle * part = gime->RecParticle(1) ; |
31 | // ................ |
2a657981 |
32 | // gime->Event(event) ; // reads new event from galice.root |
4ae78bb1 |
33 | // |
2a657981 |
34 | //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH) |
35 | //*-- Completely redesigned by Dmitri Peressounko March 2001 |
4ae78bb1 |
36 | // |
37 | //*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make |
38 | //*-- systematic usage of TFolders without changing the interface |
39 | ////////////////////////////////////////////////////////////////////////////// |
40 | |
4ae78bb1 |
41 | // --- ROOT system --- |
88cb7938 |
42 | |
43 | #include "TSystem.h" |
4ae78bb1 |
44 | #include "TROOT.h" |
88cb7938 |
45 | |
4ae78bb1 |
46 | |
47 | // --- Standard library --- |
4ae78bb1 |
48 | |
49 | // --- AliRoot header files --- |
4ae78bb1 |
50 | #include "AliPHOSGetter.h" |
e957fea8 |
51 | #include "AliPHOS.h" |
88cb7938 |
52 | #include "AliRunLoader.h" |
53 | #include "AliStack.h" |
7fba1747 |
54 | #include "AliHeader.h" |
88cb7938 |
55 | #include "AliPHOSLoader.h" |
7bb289a7 |
56 | #include "AliPHOSBeamTestEvent.h" |
5d12ce38 |
57 | #include "AliMC.h" |
95635748 |
58 | #include "AliESD.h" |
88cb7938 |
59 | |
4ae78bb1 |
60 | ClassImp(AliPHOSGetter) |
61 | |
88cb7938 |
62 | AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ; |
63 | AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0; |
64 | Int_t AliPHOSGetter::fgDebug = 0; |
65 | |
66 | // TFile * AliPHOSGetter::fgFile = 0 ; |
4ae78bb1 |
67 | |
68 | //____________________________________________________________________________ |
88cb7938 |
69 | AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption) |
4ae78bb1 |
70 | { |
88cb7938 |
71 | // ctor only called by Instance() |
4ae78bb1 |
72 | |
88cb7938 |
73 | AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ; |
74 | if (!rl) { |
75 | rl = AliRunLoader::Open(headerFile, version, openingOption); |
76 | if (!rl) { |
77 | Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ; |
78 | return ; |
79 | } |
80 | if (rl->GetAliRun() == 0x0) { |
81 | rl->LoadgAlice(); |
82 | gAlice = rl->GetAliRun(); // should be removed |
83 | } |
fbf811ec |
84 | } |
88cb7938 |
85 | fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader")); |
86 | if ( !fgPhosLoader ) |
87 | Error("AliPHOSGetter", "Could not find PHOSLoader") ; |
88 | else |
89 | fgPhosLoader->SetTitle(version); |
90 | |
91 | |
92 | // initialize data members |
93 | SetDebug(0) ; |
94 | fBTE = 0 ; |
95 | fPrimaries = 0 ; |
96 | fLoadingStatus = "" ; |
95635748 |
97 | fESDFileName = "AliESDs.root" ; |
98 | fESDFile = 0 ; |
88cb7938 |
99 | } |
9bd3caba |
100 | |
88cb7938 |
101 | //____________________________________________________________________________ |
102 | AliPHOSGetter::~AliPHOSGetter() |
103 | { |
104 | // dtor |
105 | delete fgPhosLoader ; |
106 | fgPhosLoader = 0 ; |
107 | delete fBTE ; |
108 | fBTE = 0 ; |
109 | fPrimaries->Delete() ; |
110 | delete fPrimaries ; |
0ef40383 |
111 | fgObjGetter = 0; |
112 | } |
113 | |
114 | //____________________________________________________________________________ |
115 | void AliPHOSGetter::Reset() |
116 | { |
117 | // resets things in case the getter is called consecutively with different files |
118 | // the PHOS Loader is already deleted by the Run Loader |
119 | |
120 | if (fPrimaries) { |
121 | fPrimaries->Delete() ; |
122 | delete fPrimaries ; |
123 | } |
124 | fgPhosLoader = 0; |
125 | fgObjGetter = 0; |
88cb7938 |
126 | } |
fbf811ec |
127 | |
88cb7938 |
128 | //____________________________________________________________________________ |
129 | AliPHOSClusterizer * AliPHOSGetter::Clusterizer() |
130 | { |
e957fea8 |
131 | // Returns pointer to the Clusterizer task |
88cb7938 |
132 | AliPHOSClusterizer * rv ; |
133 | rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ; |
134 | if (!rv) { |
135 | Event(0, "R") ; |
136 | rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ; |
137 | } |
138 | return rv ; |
139 | } |
4ae78bb1 |
140 | |
88cb7938 |
141 | //____________________________________________________________________________ |
142 | TObjArray * AliPHOSGetter::CpvRecPoints() |
143 | { |
144 | // asks the Loader to return the CPV RecPoints container |
4ae78bb1 |
145 | |
88cb7938 |
146 | TObjArray * rv = 0 ; |
147 | |
148 | rv = PhosLoader()->CpvRecPoints() ; |
149 | if (!rv) { |
150 | PhosLoader()->MakeRecPointsArray() ; |
151 | rv = PhosLoader()->CpvRecPoints() ; |
152 | } |
153 | return rv ; |
154 | } |
dca3a7c4 |
155 | |
88cb7938 |
156 | //____________________________________________________________________________ |
157 | TClonesArray * AliPHOSGetter::Digits() |
158 | { |
159 | // asks the Loader to return the Digits container |
7bb289a7 |
160 | |
88cb7938 |
161 | TClonesArray * rv = 0 ; |
162 | rv = PhosLoader()->Digits() ; |
7bb289a7 |
163 | |
88cb7938 |
164 | if( !rv ) { |
165 | PhosLoader()->MakeDigitsArray() ; |
166 | rv = PhosLoader()->Digits() ; |
4ae78bb1 |
167 | } |
88cb7938 |
168 | return rv ; |
169 | } |
4b808d52 |
170 | |
88cb7938 |
171 | //____________________________________________________________________________ |
172 | AliPHOSDigitizer * AliPHOSGetter::Digitizer() |
173 | { |
e957fea8 |
174 | // Returns pointer to the Digitizer task |
88cb7938 |
175 | AliPHOSDigitizer * rv ; |
176 | rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ; |
177 | if (!rv) { |
178 | Event(0, "D") ; |
179 | rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ; |
180 | } |
181 | return rv ; |
4ae78bb1 |
182 | } |
fbf811ec |
183 | |
88cb7938 |
184 | |
4ae78bb1 |
185 | //____________________________________________________________________________ |
88cb7938 |
186 | TObjArray * AliPHOSGetter::EmcRecPoints() |
0bc3b8ed |
187 | { |
88cb7938 |
188 | // asks the Loader to return the EMC RecPoints container |
d489fb96 |
189 | |
88cb7938 |
190 | TObjArray * rv = 0 ; |
65549808 |
191 | |
88cb7938 |
192 | rv = PhosLoader()->EmcRecPoints() ; |
193 | if (!rv) { |
194 | PhosLoader()->MakeRecPointsArray() ; |
195 | rv = PhosLoader()->EmcRecPoints() ; |
89165262 |
196 | } |
88cb7938 |
197 | return rv ; |
81bb1a45 |
198 | } |
7a9d98f9 |
199 | |
65549808 |
200 | //____________________________________________________________________________ |
88cb7938 |
201 | TClonesArray * AliPHOSGetter::TrackSegments() |
65549808 |
202 | { |
88cb7938 |
203 | // asks the Loader to return the TrackSegments container |
204 | |
205 | TClonesArray * rv = 0 ; |
206 | |
207 | rv = PhosLoader()->TrackSegments() ; |
208 | if (!rv) { |
209 | PhosLoader()->MakeTrackSegmentsArray() ; |
210 | rv = PhosLoader()->TrackSegments() ; |
211 | } |
212 | return rv ; |
65549808 |
213 | } |
4ae78bb1 |
214 | |
0c87da39 |
215 | //____________________________________________________________________________ |
e957fea8 |
216 | AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker() |
88cb7938 |
217 | { |
e957fea8 |
218 | // Returns pointer to the TrackSegmentMaker task |
88cb7938 |
219 | AliPHOSTrackSegmentMaker * rv ; |
220 | rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ; |
221 | if (!rv) { |
222 | Event(0, "T") ; |
223 | rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ; |
0c87da39 |
224 | } |
88cb7938 |
225 | return rv ; |
0c87da39 |
226 | } |
227 | |
4ae78bb1 |
228 | //____________________________________________________________________________ |
88cb7938 |
229 | TClonesArray * AliPHOSGetter::RecParticles() |
4ae78bb1 |
230 | { |
88cb7938 |
231 | // asks the Loader to return the TrackSegments container |
232 | |
233 | TClonesArray * rv = 0 ; |
4ae78bb1 |
234 | |
88cb7938 |
235 | rv = PhosLoader()->RecParticles() ; |
236 | if (!rv) { |
237 | PhosLoader()->MakeRecParticlesArray() ; |
238 | rv = PhosLoader()->RecParticles() ; |
b134c32f |
239 | } |
88cb7938 |
240 | return rv ; |
4ae78bb1 |
241 | } |
4ae78bb1 |
242 | //____________________________________________________________________________ |
fc7e2f43 |
243 | void AliPHOSGetter::Event(Int_t event, const char* opt) |
4ae78bb1 |
244 | { |
88cb7938 |
245 | // Reads the content of all Tree's S, D and R |
548f0134 |
246 | |
88cb7938 |
247 | if ( event >= MaxEvent() ) { |
248 | Error("Event", "%d not found in TreeE !", event) ; |
249 | return ; |
fbf811ec |
250 | } |
4ae78bb1 |
251 | |
88cb7938 |
252 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
df25f7dd |
253 | |
88cb7938 |
254 | // checks if we are dealing with test-beam data |
255 | TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ; |
256 | if(btb){ |
257 | if(!fBTE) |
258 | fBTE = new AliPHOSBeamTestEvent() ; |
259 | btb->SetAddress(&fBTE) ; |
260 | btb->GetEntry(event) ; |
fbf811ec |
261 | } |
88cb7938 |
262 | else{ |
263 | if(fBTE){ |
264 | delete fBTE ; |
265 | fBTE = 0 ; |
fbf811ec |
266 | } |
fbf811ec |
267 | } |
88cb7938 |
268 | |
269 | // Loads the type of object(s) requested |
b134c32f |
270 | |
88cb7938 |
271 | rl->GetEvent(event) ; |
272 | |
273 | if( strstr(opt,"X") || (strcmp(opt,"")==0) ) |
274 | ReadPrimaries() ; |
275 | |
276 | if(strstr(opt,"H") ) |
277 | ReadTreeH(); |
278 | |
279 | if(strstr(opt,"S") ) |
280 | ReadTreeS() ; |
281 | |
282 | if( strstr(opt,"D") ) |
283 | ReadTreeD() ; |
284 | |
285 | if( strstr(opt,"R") ) |
286 | ReadTreeR() ; |
287 | |
288 | if( strstr(opt,"T") ) |
289 | ReadTreeT() ; |
290 | |
291 | if( strstr(opt,"P") ) |
292 | ReadTreeP() ; |
95635748 |
293 | |
88cb7938 |
294 | // if( strstr(opt,"Q") ) |
295 | // ReadTreeQA() ; |
296 | |
297 | } |
298 | |
299 | |
300 | //____________________________________________________________________________ |
301 | Int_t AliPHOSGetter::EventNumber() const |
302 | { |
303 | // return the current event number |
304 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
305 | return static_cast<Int_t>(rl->GetEventNumber()) ; |
fbf811ec |
306 | } |
d489fb96 |
307 | |
fbf811ec |
308 | //____________________________________________________________________________ |
88cb7938 |
309 | TClonesArray * AliPHOSGetter::Hits() |
fbf811ec |
310 | { |
88cb7938 |
311 | // asks the loader to return the Hits container |
312 | |
313 | TClonesArray * rv = 0 ; |
314 | |
315 | rv = PhosLoader()->Hits() ; |
316 | if ( !rv ) { |
317 | PhosLoader()->LoadHits("read"); |
318 | rv = PhosLoader()->Hits() ; |
fbf811ec |
319 | } |
88cb7938 |
320 | return rv ; |
321 | } |
fbf811ec |
322 | |
88cb7938 |
323 | //____________________________________________________________________________ |
324 | AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption) |
325 | { |
326 | // Creates and returns the pointer of the unique instance |
327 | // Must be called only when the environment has changed |
d489fb96 |
328 | |
88cb7938 |
329 | //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption); |
330 | |
331 | if(!fgObjGetter){ // first time the getter is called |
332 | fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ; |
fbf811ec |
333 | } |
88cb7938 |
334 | else { // the getter has been called previously |
335 | AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()); |
336 | if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name |
337 | // check if the file is already open |
338 | TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ; |
339 | |
340 | if ( !galiceFile ) |
341 | fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ; |
342 | |
343 | else { // the file is already open check the version name |
344 | TString currentVersionName = rl->GetEventFolder()->GetName() ; |
345 | TString newVersionName(version) ; |
346 | if (currentVersionName == newVersionName) |
347 | if(fgDebug) |
348 | ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ; |
349 | else { |
350 | fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ; |
351 | } |
352 | } |
353 | } |
7fba1747 |
354 | else { |
355 | AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ; |
1c221c70 |
356 | if ( strstr(version, AliConfig::fgkDefaultEventFolderName) ) // false in case of merging |
357 | delete rl ; |
88cb7938 |
358 | fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ; |
7fba1747 |
359 | } |
48f12df6 |
360 | } |
88cb7938 |
361 | if (!fgObjGetter) |
95635748 |
362 | ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ; |
88cb7938 |
363 | else |
364 | if (fgDebug) |
365 | Print() ; |
4ae78bb1 |
366 | |
88cb7938 |
367 | return fgObjGetter ; |
4ae78bb1 |
368 | } |
369 | |
6ad0e528 |
370 | //____________________________________________________________________________ |
88cb7938 |
371 | AliPHOSGetter * AliPHOSGetter::Instance() |
6ad0e528 |
372 | { |
88cb7938 |
373 | // Returns the pointer of the unique instance already defined |
fbf811ec |
374 | |
95635748 |
375 | if(!fgObjGetter && fgDebug) |
376 | ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ; |
6ad0e528 |
377 | |
88cb7938 |
378 | return fgObjGetter ; |
379 | |
6ad0e528 |
380 | } |
381 | |
382 | //____________________________________________________________________________ |
88cb7938 |
383 | Int_t AliPHOSGetter::MaxEvent() const |
6ad0e528 |
384 | { |
88cb7938 |
385 | // returns the number of events in the run (from TE) |
0bc3b8ed |
386 | |
88cb7938 |
387 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
388 | return static_cast<Int_t>(rl->GetNumberOfEvents()) ; |
6ad0e528 |
389 | } |
390 | |
391 | //____________________________________________________________________________ |
88cb7938 |
392 | TParticle * AliPHOSGetter::Primary(Int_t index) const |
6ad0e528 |
393 | { |
88cb7938 |
394 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
395 | return rl->Stack()->Particle(index) ; |
396 | } |
6ad0e528 |
397 | |
4ae78bb1 |
398 | //____________________________________________________________________________ |
88cb7938 |
399 | AliPHOS * AliPHOSGetter:: PHOS() const |
4ae78bb1 |
400 | { |
401 | // returns the PHOS object |
88cb7938 |
402 | AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ; |
7a9d98f9 |
403 | if (!phos) |
88cb7938 |
404 | if (fgDebug) |
405 | Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ; |
7a9d98f9 |
406 | return phos ; |
4ae78bb1 |
407 | } |
408 | |
88cb7938 |
409 | |
410 | |
411 | //____________________________________________________________________________ |
e957fea8 |
412 | AliPHOSPID * AliPHOSGetter::PID() |
88cb7938 |
413 | { |
e957fea8 |
414 | // Returns pointer to the PID task |
88cb7938 |
415 | AliPHOSPID * rv ; |
416 | rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ; |
417 | if (!rv) { |
418 | Event(0, "P") ; |
419 | rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ; |
420 | } |
421 | return rv ; |
422 | } |
423 | |
4ae78bb1 |
424 | //____________________________________________________________________________ |
88cb7938 |
425 | AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const |
4ae78bb1 |
426 | { |
0bc3b8ed |
427 | // Returns PHOS geometry |
428 | |
7a9d98f9 |
429 | AliPHOSGeometry * rv = 0 ; |
430 | if (PHOS() ) |
431 | rv = PHOS()->GetGeometry() ; |
432 | return rv ; |
433 | } |
4ae78bb1 |
434 | |
cb34a1fa |
435 | //____________________________________________________________________________ |
88cb7938 |
436 | TClonesArray * AliPHOSGetter::Primaries() |
437 | { |
438 | // creates the Primaries container if needed |
439 | if ( !fPrimaries ) { |
440 | if (fgDebug) |
441 | Info("Primaries", "Creating a new TClonesArray for primaries") ; |
442 | fPrimaries = new TClonesArray("TParticle", 1000) ; |
443 | } |
444 | return fPrimaries ; |
445 | } |
446 | |
447 | //____________________________________________________________________________ |
448 | void AliPHOSGetter::Print() |
449 | { |
450 | // Print usefull information about the getter |
451 | |
452 | AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()); |
453 | ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ; |
454 | } |
cb34a1fa |
455 | |
88cb7938 |
456 | //____________________________________________________________________________ |
457 | void AliPHOSGetter::ReadPrimaries() |
458 | { |
459 | // Read Primaries from Kinematics.root |
cb34a1fa |
460 | |
88cb7938 |
461 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
cb34a1fa |
462 | |
88cb7938 |
463 | // gets kine tree from the root file (Kinematics.root) |
7fba1747 |
464 | if ( ! rl->TreeK() ) { // load treeK the first time |
88cb7938 |
465 | rl->LoadKinematics() ; |
7fba1747 |
466 | } |
88cb7938 |
467 | |
7fba1747 |
468 | fNPrimaries = (rl->GetHeader())->GetNtrack(); |
88cb7938 |
469 | if (fgDebug) |
470 | Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ; |
cb34a1fa |
471 | |
cb34a1fa |
472 | |
88cb7938 |
473 | // first time creates the container |
474 | if ( Primaries() ) |
475 | fPrimaries->Clear() ; |
cb34a1fa |
476 | |
88cb7938 |
477 | Int_t index = 0 ; |
478 | for (index = 0 ; index < fNPrimaries; index++) { |
479 | new ((*fPrimaries)[index]) TParticle(*(Primary(index))); |
cb34a1fa |
480 | } |
cb34a1fa |
481 | } |
482 | |
95635748 |
483 | //____________________________________________________________________________ |
484 | AliESD * AliPHOSGetter::ESD(Int_t event) |
485 | { |
486 | //Read the ESD |
487 | if (!fESDFile) |
488 | OpenESDFile() ; |
489 | |
490 | TString esdEvent("ESD") ; |
491 | esdEvent+= event ; |
492 | AliESD * esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ; |
493 | return esd ; |
494 | } |
495 | |
496 | //____________________________________________________________________________ |
497 | Bool_t AliPHOSGetter::OpenESDFile(TString name) |
498 | { |
499 | Bool_t rv = kTRUE ; |
500 | fESDFileName = name ; |
501 | if (!fESDFile) |
502 | fESDFile = new TFile(fESDFileName) ; |
503 | else if (fESDFile->IsOpen()) { |
504 | fESDFile->Close() ; |
505 | fESDFile = TFile::Open(fESDFileName) ; |
506 | } |
507 | if (!fESDFile->IsOpen()) |
508 | rv = kFALSE ; |
509 | return rv ; |
510 | } |
511 | |
b0bba0af |
512 | //____________________________________________________________________________ |
88cb7938 |
513 | Int_t AliPHOSGetter::ReadTreeD() |
514 | { |
515 | // Read the Digits |
b0bba0af |
516 | |
7a9d98f9 |
517 | |
88cb7938 |
518 | // gets TreeD from the root file (PHOS.SDigits.root) |
519 | if ( !IsLoaded("D") ) { |
520 | PhosLoader()->LoadDigits("UPDATE") ; |
521 | PhosLoader()->LoadDigitizer("UPDATE") ; |
522 | SetLoaded("D") ; |
523 | } |
524 | return Digits()->GetEntries() ; |
525 | } |
7a9d98f9 |
526 | |
b0bba0af |
527 | //____________________________________________________________________________ |
88cb7938 |
528 | Int_t AliPHOSGetter::ReadTreeH() |
529 | { |
530 | // Read the Hits |
531 | |
532 | // gets TreeH from the root file (PHOS.Hit.root) |
533 | if ( !IsLoaded("H") ) { |
534 | PhosLoader()->LoadHits("UPDATE") ; |
535 | SetLoaded("H") ; |
536 | } |
537 | return Hits()->GetEntries() ; |
538 | } |
4ae78bb1 |
539 | |
88cb7938 |
540 | //____________________________________________________________________________ |
541 | Int_t AliPHOSGetter::ReadTreeR() |
542 | { |
543 | // Read the RecPoints |
b0bba0af |
544 | |
88cb7938 |
545 | |
546 | // gets TreeR from the root file (PHOS.RecPoints.root) |
547 | if ( !IsLoaded("R") ) { |
548 | PhosLoader()->LoadRecPoints("UPDATE") ; |
549 | PhosLoader()->LoadClusterizer("UPDATE") ; |
550 | SetLoaded("R") ; |
7a9d98f9 |
551 | } |
f1611b7c |
552 | |
88cb7938 |
553 | return EmcRecPoints()->GetEntries() ; |
b0bba0af |
554 | } |
7a9d98f9 |
555 | |
b0bba0af |
556 | //____________________________________________________________________________ |
88cb7938 |
557 | Int_t AliPHOSGetter::ReadTreeT() |
558 | { |
559 | // Read the TrackSegments |
7a9d98f9 |
560 | |
407ae4df |
561 | |
88cb7938 |
562 | // gets TreeT from the root file (PHOS.TrackSegments.root) |
563 | if ( !IsLoaded("T") ) { |
564 | PhosLoader()->LoadTracks("UPDATE") ; |
565 | PhosLoader()->LoadTrackSegmentMaker("UPDATE") ; |
566 | SetLoaded("T") ; |
407ae4df |
567 | } |
fbf811ec |
568 | |
88cb7938 |
569 | return TrackSegments()->GetEntries() ; |
570 | } |
b0bba0af |
571 | //____________________________________________________________________________ |
88cb7938 |
572 | Int_t AliPHOSGetter::ReadTreeP() |
573 | { |
574 | // Read the TrackSegments |
b0bba0af |
575 | |
88cb7938 |
576 | |
577 | // gets TreeT from the root file (PHOS.TrackSegments.root) |
578 | if ( !IsLoaded("P") ) { |
579 | PhosLoader()->LoadRecParticles("UPDATE") ; |
580 | PhosLoader()->LoadPID("UPDATE") ; |
581 | SetLoaded("P") ; |
7a9d98f9 |
582 | } |
583 | |
88cb7938 |
584 | return RecParticles()->GetEntries() ; |
585 | } |
586 | //____________________________________________________________________________ |
587 | Int_t AliPHOSGetter::ReadTreeS() |
588 | { |
589 | // Read the SDigits |
590 | |
7a9d98f9 |
591 | |
88cb7938 |
592 | // gets TreeS from the root file (PHOS.SDigits.root) |
593 | if ( !IsLoaded("S") ) { |
7b4c1168 |
594 | PhosLoader()->LoadSDigits("READ") ; |
595 | PhosLoader()->LoadSDigitizer("READ") ; |
88cb7938 |
596 | SetLoaded("S") ; |
7a9d98f9 |
597 | } |
b0bba0af |
598 | |
88cb7938 |
599 | return SDigits()->GetEntries() ; |
600 | } |
f1611b7c |
601 | |
88cb7938 |
602 | //____________________________________________________________________________ |
603 | TClonesArray * AliPHOSGetter::SDigits() |
604 | { |
605 | // asks the Loader to return the Digits container |
b0bba0af |
606 | |
88cb7938 |
607 | TClonesArray * rv = 0 ; |
608 | |
609 | rv = PhosLoader()->SDigits() ; |
610 | if (!rv) { |
611 | PhosLoader()->MakeSDigitsArray() ; |
612 | rv = PhosLoader()->SDigits() ; |
613 | } |
614 | return rv ; |
b0bba0af |
615 | } |
616 | |
617 | //____________________________________________________________________________ |
e957fea8 |
618 | AliPHOSSDigitizer * AliPHOSGetter::SDigitizer() |
88cb7938 |
619 | { |
e957fea8 |
620 | // Returns pointer to the SDigitizer task |
88cb7938 |
621 | AliPHOSSDigitizer * rv ; |
622 | rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ; |
623 | if (!rv) { |
624 | Event(0, "S") ; |
625 | rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ; |
b0bba0af |
626 | } |
88cb7938 |
627 | return rv ; |
b0bba0af |
628 | } |
7a9d98f9 |
629 | |
b0bba0af |
630 | //____________________________________________________________________________ |
fc7e2f43 |
631 | TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const |
88cb7938 |
632 | { |
633 | // Return first (index=1) or second (index=2) secondary particle of primary particle p |
634 | |
635 | if(index <= 0) |
636 | return 0 ; |
637 | if(index > 2) |
638 | return 0 ; |
b0bba0af |
639 | |
88cb7938 |
640 | if(p) { |
641 | Int_t daughterIndex = p->GetDaughter(index-1) ; |
642 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
5d12ce38 |
643 | return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ; |
88cb7938 |
644 | } |
645 | else |
646 | return 0 ; |
647 | } |
4ae78bb1 |
648 | |
88cb7938 |
649 | //____________________________________________________________________________ |
fc7e2f43 |
650 | void AliPHOSGetter::Track(Int_t itrack) |
88cb7938 |
651 | { |
652 | // Read the first entry of PHOS branch in hit tree gAlice->TreeH() |
653 | |
654 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
b0bba0af |
655 | |
88cb7938 |
656 | if( !TreeH() ) // load treeH the first time |
657 | rl->LoadHits() ; |
b0bba0af |
658 | |
88cb7938 |
659 | // first time create the container |
660 | TClonesArray * hits = Hits() ; |
661 | if ( hits ) |
662 | hits->Clear() ; |
b0bba0af |
663 | |
88cb7938 |
664 | TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ; |
665 | phosbranch->SetAddress(&hits) ; |
666 | phosbranch->GetEntry(itrack) ; |
b0bba0af |
667 | } |
668 | |
b0bba0af |
669 | //____________________________________________________________________________ |
88cb7938 |
670 | TTree * AliPHOSGetter::TreeD() const |
671 | { |
e957fea8 |
672 | // Returns pointer to the Digits Tree |
88cb7938 |
673 | TTree * rv = 0 ; |
674 | rv = PhosLoader()->TreeD() ; |
675 | if ( !rv ) { |
676 | PhosLoader()->MakeTree("D"); |
677 | rv = PhosLoader()->TreeD() ; |
b0bba0af |
678 | } |
b0bba0af |
679 | |
88cb7938 |
680 | return rv ; |
b0bba0af |
681 | } |
548f0134 |
682 | |
b0bba0af |
683 | //____________________________________________________________________________ |
88cb7938 |
684 | TTree * AliPHOSGetter::TreeH() const |
685 | { |
e957fea8 |
686 | // Returns pointer to the Hits Tree |
88cb7938 |
687 | TTree * rv = 0 ; |
688 | rv = PhosLoader()->TreeH() ; |
689 | if ( !rv ) { |
690 | PhosLoader()->MakeTree("H"); |
691 | rv = PhosLoader()->TreeH() ; |
692 | } |
693 | |
694 | return rv ; |
b0bba0af |
695 | } |
7a9d98f9 |
696 | |
b0bba0af |
697 | //____________________________________________________________________________ |
88cb7938 |
698 | TTree * AliPHOSGetter::TreeR() const |
0bc3b8ed |
699 | { |
e957fea8 |
700 | // Returns pointer to the RecPoints Tree |
88cb7938 |
701 | TTree * rv = 0 ; |
702 | rv = PhosLoader()->TreeR() ; |
703 | if ( !rv ) { |
704 | PhosLoader()->MakeTree("R"); |
705 | rv = PhosLoader()->TreeR() ; |
706 | } |
b0bba0af |
707 | |
88cb7938 |
708 | return rv ; |
b0bba0af |
709 | } |
710 | |
b0bba0af |
711 | //____________________________________________________________________________ |
88cb7938 |
712 | TTree * AliPHOSGetter::TreeT() const |
0bc3b8ed |
713 | { |
e957fea8 |
714 | // Returns pointer to the TrackSegments Tree |
88cb7938 |
715 | TTree * rv = 0 ; |
716 | rv = PhosLoader()->TreeT() ; |
717 | if ( !rv ) { |
718 | PhosLoader()->MakeTree("T"); |
719 | rv = PhosLoader()->TreeT() ; |
720 | } |
b0bba0af |
721 | |
88cb7938 |
722 | return rv ; |
b0bba0af |
723 | } |
b0bba0af |
724 | //____________________________________________________________________________ |
88cb7938 |
725 | TTree * AliPHOSGetter::TreeP() const |
0bc3b8ed |
726 | { |
e957fea8 |
727 | // Returns pointer to the RecParticles Tree |
88cb7938 |
728 | TTree * rv = 0 ; |
729 | rv = PhosLoader()->TreeP() ; |
730 | if ( !rv ) { |
731 | PhosLoader()->MakeTree("P"); |
732 | rv = PhosLoader()->TreeP() ; |
733 | } |
4ae78bb1 |
734 | |
88cb7938 |
735 | return rv ; |
b0bba0af |
736 | } |
737 | |
738 | //____________________________________________________________________________ |
88cb7938 |
739 | TTree * AliPHOSGetter::TreeS() const |
e957fea8 |
740 | { |
741 | // Returns pointer to the SDigits Tree |
88cb7938 |
742 | TTree * rv = 0 ; |
743 | rv = PhosLoader()->TreeS() ; |
744 | if ( !rv ) { |
745 | PhosLoader()->MakeTree("S"); |
746 | rv = PhosLoader()->TreeS() ; |
b0bba0af |
747 | } |
b0bba0af |
748 | |
88cb7938 |
749 | return rv ; |
b0bba0af |
750 | } |
7a9d98f9 |
751 | |
b0bba0af |
752 | //____________________________________________________________________________ |
88cb7938 |
753 | Bool_t AliPHOSGetter::VersionExists(TString & opt) const |
754 | { |
755 | // checks if the version with the present name already exists in the same directory |
7a9d98f9 |
756 | |
88cb7938 |
757 | Bool_t rv = kFALSE ; |
758 | |
759 | AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle()); |
760 | TString version( rl->GetEventFolder()->GetName() ) ; |
7a9d98f9 |
761 | |
88cb7938 |
762 | opt.ToLower() ; |
b0bba0af |
763 | |
88cb7938 |
764 | if ( opt == "sdigits") { |
765 | // add the version name to the root file name |
766 | TString fileName( PhosLoader()->GetSDigitsFileName() ) ; |
767 | if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name |
768 | fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ; |
769 | if ( !(gSystem->AccessPathName(fileName)) ) { |
770 | Warning("VersionExists", "The file %s already exists", fileName.Data()) ; |
771 | rv = kTRUE ; |
4ae78bb1 |
772 | } |
88cb7938 |
773 | PhosLoader()->SetSDigitsFileName(fileName) ; |
b0bba0af |
774 | } |
7a9d98f9 |
775 | |
88cb7938 |
776 | if ( opt == "digits") { |
777 | // add the version name to the root file name |
778 | TString fileName( PhosLoader()->GetDigitsFileName() ) ; |
779 | if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name |
780 | fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ; |
781 | if ( !(gSystem->AccessPathName(fileName)) ) { |
782 | Warning("VersionExists", "The file %s already exists", fileName.Data()) ; |
783 | rv = kTRUE ; |
7a9d98f9 |
784 | } |
b0bba0af |
785 | } |
7a9d98f9 |
786 | |
88cb7938 |
787 | return rv ; |
7a9d98f9 |
788 | |
b0bba0af |
789 | } |
88cb7938 |
790 | |
7bb289a7 |
791 | //____________________________________________________________________________ |
88cb7938 |
792 | UShort_t AliPHOSGetter::EventPattern(void) const |
0bc3b8ed |
793 | { |
794 | // Return the pattern (trigger bit register) of the beam-test event |
7bb289a7 |
795 | if(fBTE) |
796 | return fBTE->GetPattern() ; |
797 | else |
798 | return 0 ; |
799 | } |
800 | //____________________________________________________________________________ |
88cb7938 |
801 | Float_t AliPHOSGetter::BeamEnergy(void) const |
0bc3b8ed |
802 | { |
803 | // Return the beam energy of the beam-test event |
7bb289a7 |
804 | if(fBTE) |
805 | return fBTE->GetBeamEnergy() ; |
806 | else |
807 | return 0 ; |
808 | } |