Fixed memory leak at sdigits mixing: TreeS is properly cleaned for each file
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
CommitLineData
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
16/* $Id: */
17
18/* $Log:
19 29.05.2001 Yuri Kharlov:
20 Everywhere reading the treese TTree->GetEvent(i)
21 is replaced by reading the branches TBranch->GetEntry(0)
22*/
23
24//_________________________________________________________________________
25// A singleton. This class should be used in the analysis stage to get
26// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
27// instead of directly reading them from galice.root file. This container
28// ensures, that one reads Digits, made of these particular digits, RecPoints,
29// made of these particular RecPoints, TrackSegments and RecParticles.
30// This becomes non trivial if there are several identical branches, produced with
31// different set of parameters.
32//
33// An example of how to use (see also class AliPHOSAnalyser):
34// AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
35// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
36// AliPHOSRecParticle * part = gime->RecParticle(1) ;
37// ................
38// please->GetEvent(event) ; // reads new event from galice.root
39//
40//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
41//*-- Completely redesigned by Dmitri Peressounko March 2001
42//
43//*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
44//*-- systematic usage of TFolders without changing the interface
45//////////////////////////////////////////////////////////////////////////////
46
47
48// --- ROOT system ---
49
50#include "TFile.h"
51#include "TTree.h"
52#include "TROOT.h"
53#include "TObjString.h"
54#include "TFolder.h"
55
56// --- Standard library ---
57#include <iostream.h>
58
59// --- AliRoot header files ---
60
61#include "AliRun.h"
62#include "AliPHOSGetter.h"
63#include "AliPHOS.h"
64#include "AliPHOSDigitizer.h"
65#include "AliPHOSSDigitizer.h"
66#include "AliPHOSClusterizer.h"
67#include "AliPHOSClusterizerv1.h"
68#include "AliPHOSTrackSegmentMaker.h"
69#include "AliPHOSTrackSegmentMakerv1.h"
70#include "AliPHOSTrackSegment.h"
71#include "AliPHOSPID.h"
72#include "AliPHOSPIDv1.h"
73#include "AliPHOSGeometry.h"
74
75ClassImp(AliPHOSGetter)
76
77 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
78
79//____________________________________________________________________________
80AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle )
81{
82 //Initialize all lists
83
84 fHeaderFile = headerFile ;
85 fSDigitsTitle = branchTitle ;
86 fDigitsTitle = branchTitle ;
87 fRecPointsTitle = branchTitle ;
88 fRecParticlesTitle = branchTitle ;
89 fTrackSegmentsTitle = branchTitle ;
90
91 fPrimaries = new TObjArray(1) ;
92
eb9763ac 93 if ( fHeaderFile != "aliroot" ) { // to call the getter without a file
518b8b75 94
eb9763ac 95 //open headers file
96 TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
4ae78bb1 97
eb9763ac 98 if(file == 0){ //if file was not opened yet, read gAlice
99 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
100 file = TFile::Open(fHeaderFile.Data(),"update") ;
101 else
102 file = new TFile(fHeaderFile.Data(),"update") ;
103
104 if (!file->IsOpen()) {
105 cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot open " << fHeaderFile.Data() << endl ;
106 abort() ;
107 }
108
109 gAlice = (AliRun *) file->Get("gAlice") ;
110
111 if (!gAlice) {
112 cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ;
113 abort() ;
114 }
4ae78bb1 115 }
116 }
518b8b75 117 fDebug="";
4ae78bb1 118}
4ae78bb1 119//____________________________________________________________________________
120void AliPHOSGetter::CreateWhiteBoard() const
121{
122 // Posts a few item to the white board (folders)
123
124 // -- the geometry
125 Post(fHeaderFile, "G") ;
126
127 // -- the hits
128 Post(fHeaderFile, "H") ;
129
130}
131
132//____________________________________________________________________________
133AliPHOSGetter * AliPHOSGetter::GetInstance()
134{
135 // Returns the pointer of the unique instance already defined
136
137 AliPHOSGetter * rv = 0 ;
138 if ( fgObjGetter )
139 rv = fgObjGetter ;
140 else
141 cout << "AliPHOSGetter::GetInstance ERROR: not yet initialized" << endl ;
142
143 return rv ;
144}
145
146//____________________________________________________________________________
147AliPHOSGetter * AliPHOSGetter::GetInstance(const char* headerFile,
148 const char* branchTitle)
149{
150 // Creates and returns the pointer of the unique instance
151 // Must be called only when the environment has changed
152
153
154 if ( fgObjGetter ) // delete it if already exists
155 delete fgObjGetter ;
156
157 fgObjGetter = new AliPHOSGetter(headerFile,branchTitle) ;
158
159 // Posts a few item to the white board (folders)
160 fgObjGetter->CreateWhiteBoard() ;
161
162 // Get the first event into the arrays posted on the white board
163 // branchTitle = 0, means simulation run and no event yet
164 if (branchTitle)
165 fgObjGetter->Event(0) ;
166
167 return fgObjGetter ;
168
169}
170
171//____________________________________________________________________________
172 const AliPHOS * AliPHOSGetter::PHOS() const
173{
174 // returns the PHOS object
175 return ( (AliPHOS*)gAlice->GetDetector("PHOS") );
176}
177
178//____________________________________________________________________________
179 const AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
180{
181 // retrieves the geometr from the folder
182
183 TString path("YSAlice/WhiteBoard/Geometry/PHOS/") ;
184 path += PHOS()->GetTitle() ;
185 return (AliPHOSGeometry*)gROOT->FindObjectAny(path.Data()) ;
186}
187
188//____________________________________________________________________________
189void AliPHOSGetter::Post(const char * headerFile, const char * opt, const char * name, const Int_t event) const
190{
191 // Adds a new folder for summable digits
192
193 TString foldertitle ;
194 if ( event >= 0 )
195 foldertitle += event ;
196 else
197 foldertitle = "" ;
198
199 TFolder * aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice") ;
200
201 if ( strcmp(opt, "G") == 0 ) { // Geometry
202 // the hierarchy is //YSALICE/WhiteBoard/Geometry/PHOS/
203 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance(PHOS()->GetTitle(),"") ;
204 TFolder * geomF = (TFolder*)aliceF->FindObject("WhiteBoard/Geometry/PHOS") ;
205 if ( !geomF ) {
206 cerr << "ERROR: AliPHOSGetter::Post G -> Folder WhiteBoard/Geometry/PHOS/" << " not found!" << endl;
207 abort() ;
208 }
209 else
210 geomF->Add((TObject*)geom) ;
211
212 } else if ( strcmp(opt, "H") == 0 ) { // Hits
213 // the hierarchy is //YSALICE/WhiteBoard/SDigits/PHOS/Hits
214 TClonesArray * hits = new TClonesArray("AliPHOSHit",1000) ;
215 hits->SetName("Hits") ;
216 TFolder * hitsF = (TFolder*)aliceF->FindObject("WhiteBoard/Hits/PHOS") ;
217 if ( !hitsF ) {
218 cerr << "ERROR: AliPHOSGetter::Post H -> Folder WhiteBoard/Hits/PHOS/" << " not found!" << endl;
219 abort() ;
220 }
221 else
222 hitsF->Add(hits) ;
223
224 } else if ( strcmp(opt, "S") == 0 ) { // summable digits
225 // the hierarchy is //YSALICE/WhiteBoard/SDigits/PHOS/headerFile/sdigitsname
226 // because you can have sdigits from several hit files for mixing
227 TClonesArray * sdigits = new TClonesArray("AliPHOSDigit",1000) ;
228 TString sdigitsName ;
229 if (name)
230 sdigitsName = name ;
231 else
232 sdigitsName = "SDigits" ;
233 sdigits->SetName( sdigitsName.Data() ) ;
234 TFolder * sdigitsF = (TFolder*)aliceF->FindObject("WhiteBoard/SDigits/PHOS") ;
235 TFolder * sdigitsF2 = 0 ;
236 TString subdir(headerFile) ;
237 if ( !(sdigitsF2=(TFolder*)sdigitsF->FindObject(subdir)) )
238 sdigitsF2 = sdigitsF->AddFolder(subdir, foldertitle);
239 else {
240 if ( sdigitsF2->FindObject( sdigitsName.Data() ) ) {
518b8b75 241 if (fDebug.Contains("S"))
242 cerr <<"INFO: AliPHOSGetter::Post S -> Folder " << subdir << ", " << foldertitle
243 << " already exists!" << endl ;
4ae78bb1 244 return ;
245 }
246 }
247 if ( !sdigitsF2 ) {
248 cerr << "ERROR: AliPHOSGetter::Post S -> Folder WhiteBoard/SDigits/PHOS/" << subdir << " not created!" << endl;
249 abort() ;
250 }
251 else
252 sdigitsF2->Add(sdigits) ;
253
254 } else if ( strcmp(opt, "Ser") == 0 ) { // sdigizer
255 // the hierarchy is //YSALICE/tasks/Digitizer/PHOS/sdigitsname
256 AliPHOSSDigitizer * sdigitizer = new AliPHOSSDigitizer() ;
257 TString sdigitsName ;
258 if (name)
259 sdigitsName = name ;
260 else
261 sdigitsName = "SDigitizer" ;
262 sdigitizer->SetName( sdigitsName.Data() ) ;
263 TTask * sdigitsF = (TTask*)aliceF->FindObject("tasks/SDigitizer") ;
264 if ( !sdigitsF ) {
265 cerr << "ERROR: AliPHOSGetter::Post Ser -> Task tasks/SDigitizer" << " not found!" << endl;
266 abort() ;
267 }
268 TTask * phos = (TTask*)sdigitsF->GetListOfTasks()->FindObject("PHOS") ;
269 if ( !phos ) {
270 cerr <<"ERROR: AliPHOSGetter::Post Ser -> tasks/SDigitizer/PHOS" << " not found!" << endl;
271 abort() ;
272 } else {
273 AliPHOSSDigitizer * phossd = (AliPHOSSDigitizer*)phos->GetListOfTasks()->FindObject(sdigitsName.Data()) ;
274 if (phossd) {
518b8b75 275 if (fDebug.Contains("Ser"))
276 cout << "INFO: AliPHOSGetter::Post Ser -> Task " << sdigitsName.Data() << " already exists" << endl ;
4ae78bb1 277 return ;
278 } else
279 phos->Add(sdigitizer) ;
280 }
281
282 } else if ( strcmp(opt, "D") == 0 ) { // digits
283 // the hierarchy is //YSALICE/WhiteBoard/Digits/PHOS/digitsname
284 TClonesArray * digits = new TClonesArray("AliPHOSDigit",20000) ;
285 TString digitsName ;
286 if (name)
287 digitsName = name ;
288 else
289 digitsName = "Digits" ;
290 digits->SetName( digitsName.Data() ) ;
291 TFolder * digitsF = (TFolder*)aliceF->FindObject("WhiteBoard/Digits/PHOS") ;
292 if ( !digitsF ) {
293 cerr << "ERROR: AliPHOSGetter::Post D -> Folder WhiteBoard/Digits/PHOS/" << " not found!" << endl;
294 abort() ;
295 }
296 digitsF->SetTitle(foldertitle) ;
297 if ( digitsF->FindObject( digitsName.Data() ) ) {
518b8b75 298 if (fDebug.Contains("D"))
299 cerr <<"INFO: AliPHOSGetter::Post D -> Object " << digitsName.Data()
300 << " already exists!" << endl ;
4ae78bb1 301 return ;
302 }
303 else
304 digitsF->Add(digits) ;
305
306 } else if ( strcmp(opt, "Der") == 0 ) { // sdigizer
307 // the hierarchy is //YSALICE/tasks/Digitizer/PHOS/digitsname
308 AliPHOSDigitizer * digitizer = new AliPHOSDigitizer() ;
309 TString digitsName ;
310 if (name)
311 digitsName = name ;
312 else
313 digitsName = "Digitizer" ;
314 digitizer->SetName( digitsName.Data() ) ;
315 TTask * digitsF = (TTask*)aliceF->FindObject("tasks/Digitizer") ;
316 if ( !digitsF ) {
317 cerr << "ERROR: AliPHOSGetter::Post Der -> Task tasks/Digitizer" << " not found!" << endl;
318 abort() ;
319 }
320 TTask * phos = (TTask*)digitsF->GetListOfTasks()->FindObject("PHOS") ;
321 if ( !phos ) {
322 cerr <<"ERROR: AliPHOSGetter::Post Der -> tasks/Digitizer/PHOS" << " not found!" << endl;
323 abort() ;
324 } else {
325 AliPHOSDigitizer * phosd = (AliPHOSDigitizer*)phos->GetListOfTasks()->FindObject(digitsName.Data()) ;
326 if (phosd) {
518b8b75 327 if (fDebug.Contains("Der"))
328 cout << "INFO: AliPHOSGetter::Post Der -> Task " << digitsName.Data() << " already exists" << endl ;
4ae78bb1 329 return ;
330 } else
331 phos->Add(digitizer) ;
332 }
333
334 } else if ( strcmp(opt, "R") == 0 ) { // RecPoints
335 // the hierarchy is //YSALICE/WhiteBoard/RecPoints/PHOS/emc/recpointsname
336 // //YSALICE/WhiteBoard/RecPoints/PHOS/cpv/recpointsname
337 TObjArray * emcrp = new TObjArray(100) ;
338 TObjArray * cpvrp = new TObjArray(100) ;
339 TString recpointsName ;
340 if (name)
341 recpointsName = name ;
342 else
343 recpointsName = "RecPoints" ;
344 emcrp->SetName( recpointsName.Data() ) ;
345 cpvrp->SetName( recpointsName.Data() ) ;
346 TFolder * emcrpF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/emc") ;
347 TFolder * cpvrpF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/cpv") ;
348 emcrpF->SetTitle(foldertitle) ;
349 cpvrpF->SetTitle(foldertitle) ;
350 if ( !emcrpF || !cpvrpF ) {
351 cerr << "ERROR: AliPHOSGetter::Post R -> Folder WhiteBoard/RecPoints/PHOS/emc(cpv)" << " not found!" << endl;
352 abort() ;
353 }
354 // TString title("PHOS Digits") ;
355 if ( emcrpF->FindObject( recpointsName.Data() ) || cpvrpF->FindObject( recpointsName.Data() ) ) {
518b8b75 356 if (fDebug.Contains("R"))
357 cerr <<"INFO: AliPHOSGetter::Post R -> Object " << recpointsName.Data()
358 << " already exists!" << endl ;
4ae78bb1 359 return ;
360 }
361 else {
362 emcrpF->Add(emcrp) ;
363 cpvrpF->Add(cpvrp) ;
364 }
365
366 } else if ( strcmp(opt, "Rer") == 0 ) { // clusterizer
367 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/recpointsname
368 AliPHOSClusterizer * clusterizer;
369 if ( strstr(name, "clu-v1") != 0 )
370 clusterizer = new AliPHOSClusterizerv1() ;
371 else {
372 cerr << "ERROR: AliPHOSGetter::Post Rer -> " << name << " unknown clusterizer version" << endl ;
373 abort() ;
374 }
375 TString recpointsName ;
376 if (name)
377 recpointsName = name ;
378 else
379 recpointsName = "Clusterizer" ;
380 clusterizer->SetName( recpointsName.Data() ) ;
381 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
382 if ( !reF ) {
383 cerr << "ERROR: AliPHOSGetter::Post Rer -> Task tasks/Reconstructioner" << " not found!" << endl;
384 abort() ;
385 }
386 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
387 if ( !phos ) {
388 cerr <<"ERROR: AliPHOSGetter::Post Rer -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
389 abort() ;
390 } else {
391 AliPHOSClusterizer * phoscl = (AliPHOSClusterizer*)phos->GetListOfTasks()->FindObject(recpointsName.Data()) ;
392 if (phoscl) {
518b8b75 393 if (fDebug.Contains("Rer"))
394 cout << "INFO: AliPHOSGetter::Post Rer -> Task " << recpointsName.Data() << " already exists" << endl ;
4ae78bb1 395 return ;
396 } else
397 phos->Add(clusterizer) ;
398 }
399
400 } else if ( strcmp(opt, "T") == 0 ) { //TrackSegments
401 // the hierarchy is //YSALICE/WhiteBoard/TrackSegments/PHOS/tracksegmentsname
402
403 TClonesArray * tracksegments = new TClonesArray("AliPHOSTrackSegment", 200) ;
404 TString tracksegmentsName ;
405 if (name)
406 tracksegmentsName = name ;
407 else
408 tracksegmentsName = "TrackSegments" ;
409 tracksegments->SetName( tracksegmentsName.Data() ) ;
410 TFolder * tracksegmentsF = (TFolder*)aliceF->FindObject("WhiteBoard/TrackSegments/PHOS") ;
411 tracksegmentsF->SetTitle(foldertitle) ;
412 if ( !tracksegmentsF) {
413 cerr << "ERROR: AliPHOSGetter::Post T -> Folder WhiteBoard/TrackSegments/PHOS" << " not found!" << endl;
414 abort() ;
415 }
416 if ( tracksegmentsF->FindObject( tracksegmentsName.Data() ) ) {
518b8b75 417 if (fDebug.Contains("T"))
418 cerr <<"INFO: AliPHOSGetter::Post T -> Object " << tracksegmentsName.Data()
419 << " already exists!" << endl ;
4ae78bb1 420 return ;
421 }
422 else
423 tracksegmentsF->Add(tracksegments) ;
424
425 } else if ( strcmp(opt, "Ter") == 0 ) { // TrackSegmentsMaker
426 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/tracksegmentsname
427 AliPHOSTrackSegmentMaker * tracksegmentmaker ;
428 if ( strstr(name, "tsm-v1") != 0 )
429 tracksegmentmaker = new AliPHOSTrackSegmentMakerv1() ;
430 else {
431 cerr << "ERROR: AliPHOSGetter::Post Ter -> " << name << " unknown track segment maker version" << endl ;
432 abort() ;
433 }
434 TString tracksegmentsName ;
435 if (name)
436 tracksegmentsName = name ;
437 else
438 tracksegmentsName = "TrackSegmentMaker" ;
439 tracksegmentmaker->SetName( tracksegmentsName.Data() ) ;
440 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
441 if ( !reF ) {
442 cerr << "ERROR: AliPHOSGetter::Post Ter -> Task tasks/Reconstructioner" << " not found!" << endl;
443 abort() ;
444 }
445 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
446 if ( !phos ) {
447 cerr <<"ERROR: AliPHOSGetter::Post Ter -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
448 abort() ;
449 } else {
450 AliPHOSTrackSegmentMaker * phosts = (AliPHOSTrackSegmentMaker*)phos->GetListOfTasks()->FindObject(tracksegmentsName.Data()) ;
451 if (phosts) {
518b8b75 452 if (fDebug.Contains("Ter"))
453 cout << "INFO: AliPHOSGetter::Post Ter -> Task " << tracksegmentsName.Data() << " already exists" << endl ;
4ae78bb1 454 return ;
455 } else
456 phos->Add(tracksegmentmaker) ;
457 }
458
459 } else if ( strcmp(opt, "P") == 0 ) { // RecParticles
460 // the hierarchy is //YSALICE/WhiteBoard/RecParticles/PHOS/recparticlesname
461
462 TClonesArray * recparticles = new TClonesArray("AliPHOSRecParticle", 200) ;
463 TString recparticlesName ;
464 if (name)
465 recparticlesName = name ;
466 else
467 recparticlesName = "RecParticles" ;
468 recparticles->SetName( recparticlesName.Data() ) ;
469 TFolder * recparticlesF = (TFolder*)aliceF->FindObject("WhiteBoard/RecParticles/PHOS") ;
470 recparticlesF->SetTitle(foldertitle) ;
471 if ( !recparticlesF) {
472 cerr << "ERROR: AliPHOSGetter::Post P -> Folder WhiteBoard/RecParticles/PHOS" << " not found!" << endl;
473 abort() ;
474 }
475 if ( recparticlesF->FindObject( recparticlesName.Data() ) ) {
518b8b75 476 if (fDebug.Contains("P"))
477 cerr <<"INFO: AliPHOSGetter::Post P -> Object " << recparticlesName.Data()
478 << " already exists!" << endl ;
4ae78bb1 479 return ;
480 }
481 else
482 recparticlesF->Add(recparticles) ;
483
484 } else if ( strcmp(opt, "Per") == 0 ) { // PID Maker
485 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/recparticlesname
486 AliPHOSPID * pid ;
487 if ( strstr(name, "pid-v1") != 0 )
488 pid = new AliPHOSPIDv1() ;
489 else {
490 cerr << "ERROR: AliPHOSGetter::Post Per -> " << name << " unknown PID maker version" << endl ;
491 abort() ;
492 }
493 TString recparticlesName ;
494 if (name)
495 recparticlesName = name ;
496 else
497 recparticlesName = "PID" ;
498 pid->SetName( recparticlesName.Data() ) ;
499 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
500 if ( !reF ) {
501 cerr << "ERROR: AliPHOSGetter::Post Per -> Task tasks/Reconstructioner" << " not found!" << endl;
502 abort() ;
503 }
504 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
505 if ( !phos ) {
506 cerr <<"ERROR: AliPHOSGetter::Post Per -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
507 abort() ;
508 } else {
509 AliPHOSPID * phospid = (AliPHOSPID*)phos->GetListOfTasks()->FindObject(recparticlesName.Data()) ;
510 if (phospid) {
518b8b75 511 if (fDebug.Contains("Per"))
512 cout << "INFO: AliPHOSGetter::Post Per -> Task " << recparticlesName.Data() << " already exists" << endl ;
4ae78bb1 513 return ;
514 } else
515 phos->Add(pid) ;
516 }
517 }
518 else if ( strcmp(opt, "QA") == 0 ) { // Alarms
519 // the hierarchy is //YSALICE/WhiteBoard/Alarms/PHOS/
520
521 TFolder * alarmsF = new TFolder() ;
522 TString alarmsName ;
523 if (name)
524 alarmsName = name ;
525 else
526 alarmsName = "Alarm with no name" ;
527 alarmsF->SetName( alarmsName.Data() ) ;
528 alarmsF->SetTitle(foldertitle) ;
529 TFolder * qaaF = (TFolder*)aliceF->FindObject("WhiteBoard/QAAlarms") ;
530 if ( !qaaF) {
531 cerr << "ERROR: AliPHOSGetter::Post QA -> Folder WhiteBoard/QAAlarms/" << " not found!" << endl;
532 return ;
533 }
534 if ( qaaF->FindObject( alarmsName.Data() ) )
535 qaaF->RecursiveRemove( qaaF->FindObject( alarmsName.Data() ) ) ;
536
537 qaaF->Add(alarmsF) ;
538
539 }
540}
541
542//____________________________________________________________________________
543const TParticle * AliPHOSGetter::Primary(Int_t index) const
544{
545 // Return primary particle numbered by <index>
546
547 if(index < 0)
548 return 0 ;
549
550 Int_t primaryIndex = index % 10000000 ;
551 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
552
553 if ( primaryList > 0 ) {
554 cout << " Getter does not support currently Mixing of primary " << endl ;
555 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
556 return 0;
557 }
558
559 return gAlice->Particle(primaryIndex) ;
560
561}
562
563//____________________________________________________________________________
564void AliPHOSGetter::ReadTreeD()
565{
566 // Read the digit tree gAlice->TreeD()
567 if(gAlice->TreeD()== 0){
568 cerr << "ERROR: AliPHOSGetter::ReadTreeD: can not read TreeD " << endl ;
569 return ;
570 }
571
572 TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
573 TIter next(lob) ;
574 TBranch * branch = 0 ;
575 TBranch * digitsbranch = 0 ;
576 TBranch * digitizerbranch = 0 ;
577 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
578
579 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
580 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
581 digitsbranch = branch ;
582 phosfound = kTRUE ;
583 }
584 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
585 digitizerbranch = branch ;
586 digitizerfound = kTRUE ;
587 }
588 }
589
590 if ( !phosfound || !digitizerfound ) {
591 cerr << "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " << fDigitsTitle << endl ;
592 return ;
593 }
594
595
596 // Post the Digits
597 Post(fHeaderFile, "D", fDigitsTitle) ;
598
599 // Post the Digitizer
600 Post(fHeaderFile, "Der", fDigitsTitle) ;
601
602 TClonesArray * digits = Digits(fDigitsTitle) ;
603 digits->Clear() ;
604 digitsbranch ->SetAddress(&digits) ;
605
606 AliPHOSDigitizer * digitizer = Digitizer(fDigitsTitle) ;
607 digitizerbranch->SetAddress(&digitizer) ;
608
609 digitsbranch ->GetEntry(0) ;
610 digitizerbranch->GetEntry(0) ;
611
612}
613
614//____________________________________________________________________________
615void AliPHOSGetter::ReadTreeH()
616{
617 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
618
619 if(gAlice->TreeH()== 0){
620 cerr << "ERROR: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
621 return ;
622 }
623
624 TBranch * hitsbranch = (TBranch*)gAlice->TreeH()->GetListOfBranches()->FindObject("PHOS") ;
625 if ( !hitsbranch ) {
626 cerr << "WARNING: AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ;
627 } else {
628 TClonesArray * hits = Hits() ;
629 hits->Clear() ;
630 hitsbranch->SetAddress(&hits) ;
631 hitsbranch->GetEntry(0) ;
632 }
633}
634
635//____________________________________________________________________________
636void AliPHOSGetter::ReadTreeQA()
637{
638 // Read the digit tree gAlice->TreeQA()
639 // so far only PHOS knows about this Tree
640
641 if(PHOS()->TreeQA()== 0){
642 cerr << "ERROR: AliPHOSGetter::ReadTreeQA: can not read TreeQA " << endl ;
643 return ;
644 }
645
646 TBranch * qabranch = PHOS()->TreeQA()->GetBranch("PHOS") ;
647 if (!qabranch) {
648 cerr << "WARNING: AliPHOSGetter::ReadTreeQA -> Cannot find QA Alarms for PHOS" << endl ;
649 return ;
650 }
651
652 // Post the QA Alarms
653 Post(fHeaderFile, "QA", "PHOS") ;
654 TFolder * alarmsF = Alarms() ;
655 alarmsF->Clear() ;
656 qabranch->SetAddress(&alarmsF) ;
657 qabranch->GetEntry(0) ;
658
659}
660
661//____________________________________________________________________________
662void AliPHOSGetter::ReadTreeR()
663{
664 // Read the reconstrunction tree gAlice->TreeR()
665
666 if(gAlice->TreeR()== 0){
667 cout << "ERROR: AliPHOSGetter::ReadTreeR: can not read TreeR " << endl ;
668 return ;
669 }
670 // RecPoints
671 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
672 TIter next(lob) ;
673 TBranch * branch = 0 ;
674 TBranch * emcbranch = 0 ;
675 TBranch * cpvbranch = 0 ;
676 TBranch * clusterizerbranch = 0 ;
677 Bool_t phosemcrpfound = kFALSE, phoscpvrpfound = kFALSE, clusterizerfound = kFALSE ;
678
679 while ( (branch = (TBranch*)next()) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) {
680 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
681 emcbranch = branch ;
682 phosemcrpfound = kTRUE ;
683 }
684 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
685 cpvbranch = branch ;
686 phoscpvrpfound = kTRUE ;
687 }
688 else if ( (strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
689 clusterizerbranch = branch ;
690 clusterizerfound = kTRUE ;
691 }
692 }
693
694 if ( !phosemcrpfound || !phoscpvrpfound || !clusterizerfound ) {
695 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecPoints and/or Clusterizer with name " << fRecPointsTitle << endl ;
696 return ;
697 }
698
699 // Post the RecPoints
700 Post(fHeaderFile, "R", fRecPointsTitle) ;
701
702 // Post the Clusterizer
703 // Need the version first
704 AliPHOSClusterizer * clusterizer = 0 ;
705 clusterizerbranch->SetAddress(&clusterizer) ;
706 clusterizerbranch->GetEntry(0) ;
707 TString clusterizerName(fRecPointsTitle) ;
708 clusterizerName.Append(clusterizer->Version()) ;
709 delete clusterizer ;
710 Post(fHeaderFile, "Rer", clusterizerName) ;
711
712 TObjArray * emcRecPoints = EmcRecPoints(fRecPointsTitle) ;
518b8b75 713 emcRecPoints->Delete() ;
4ae78bb1 714 emcbranch->SetAddress(&emcRecPoints) ;
715
716 TObjArray * cpvRecPoints = CpvRecPoints(fRecPointsTitle) ;
518b8b75 717 cpvRecPoints->Delete() ;
4ae78bb1 718 cpvbranch->SetAddress(&cpvRecPoints) ;
719
720 clusterizer = Clusterizer(clusterizerName) ;
721 clusterizerbranch->SetAddress(&clusterizer) ;
722
723 emcbranch ->GetEntry(0) ;
724 cpvbranch ->GetEntry(0) ;
725 clusterizerbranch->GetEntry(0) ;
726
727 // TrackSegments
728 next.Reset() ;
729 TBranch * tsbranch = 0 ;
730 TBranch * tsmakerbranch = 0 ;
731 Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ;
732
733 while ( (branch = (TBranch*)next()) && (!phostsfound || !tsmakerfound) ) {
734 if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0) ) {
735 tsbranch = branch ;
736 phostsfound = kTRUE ;
737 }
738 else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0) ) {
739 tsmakerbranch = branch ;
740 tsmakerfound = kTRUE ;
741 }
742 }
743
744 if ( !phostsfound || !tsmakerfound ) {
745 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name " << fTrackSegmentsTitle << endl ;
746 return ;
747 }
748
749 // Post the TrackSegments
750 Post(fHeaderFile, "T", fTrackSegmentsTitle) ;
751
752 // Post the TrackSegment Maker
753 // Need the version first
754 AliPHOSTrackSegmentMaker * tsmaker = 0 ;
755 tsmakerbranch->SetAddress(&tsmaker) ;
756 tsmakerbranch->GetEntry(0) ;
757 TString tsmakerName(fTrackSegmentsTitle) ;
758 tsmakerName.Append(tsmaker->Version()) ;
759 delete tsmaker ;
760 Post(fHeaderFile, "Ter", tsmakerName) ;
761
762 TClonesArray * tracksegments = TrackSegments(fTrackSegmentsTitle) ;
763 tracksegments->Clear() ;
764 tsbranch->SetAddress(&tracksegments) ;
765
766 tsmaker = TrackSegmentMaker(tsmakerName) ;
767 tsmakerbranch->SetAddress(&tsmaker) ;
768
769 tsmakerbranch ->GetEntry(0) ;
770 tsbranch ->GetEntry(0) ;
771
772 // RecParticles
773 next.Reset() ;
774 TBranch * rpabranch = 0 ;
775 TBranch * pidbranch = 0 ;
776 Bool_t phosrpafound = kFALSE, pidfound = kFALSE ;
777
778 while ( (branch = (TBranch*)next()) && (!phosrpafound || !pidfound) ) {
779 if ( (strcmp(branch->GetName(), "PHOSRP")==0) && (strcmp(branch->GetTitle(), fRecParticlesTitle)==0) ) {
780 rpabranch = branch ;
781 phosrpafound = kTRUE ;
782 }
783 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), fRecParticlesTitle)==0) ) {
784 pidbranch = branch ;
785 pidfound = kTRUE ;
786 }
787 }
788
789 if ( !phosrpafound || !pidfound ) {
790 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " << fRecParticlesTitle << endl ;
791 return ;
792 }
793
794 // Post the RecParticles
795 Post(fHeaderFile, "P", fRecParticlesTitle) ;
796
797 // Post the PID
798 // Need the version first
799 AliPHOSPID * pid = 0 ;
800 pidbranch->SetAddress(&pid) ;
801 pidbranch->GetEntry(0) ;
802 TString pidName(fRecParticlesTitle) ;
803 pidName.Append(pid->Version()) ;
804 delete pid ;
805
806 Post(fHeaderFile, "Per", pidName) ;
807
808 TClonesArray * recParticles = RecParticles(fRecParticlesTitle) ;
809 recParticles->Clear() ;
810 rpabranch->SetAddress(&recParticles) ;
811
812 pid = PID(pidName) ;
813 pidbranch->SetAddress(&pid) ;
814
815 pidbranch ->GetEntry(0) ;
816 rpabranch ->GetEntry(0) ;
817
818}
819
820//____________________________________________________________________________
821void AliPHOSGetter::ReadTreeS()
822{
823 // Read the summable digits tree gAlice->TreeS()
824
825 if(gAlice->TreeS()== 0){
826 cerr << "ERROR: AliPHOSGetter::ReadTreeS -> Cannot find TreeS " << endl ;
827 return ;
828 }
829
830 TObjArray * lob = (TObjArray*)gAlice->TreeS()->GetListOfBranches() ;
831 TIter next(lob) ;
832 TBranch * branch = 0 ;
833 TBranch * sdigitsbranch = 0 ;
834 TBranch * sdigitizerbranch = 0 ;
835 Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
836
837 while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
838 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
839 sdigitsbranch = branch ;
840 phosfound = kTRUE ;
841 }
842 else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
843 sdigitizerbranch = branch ;
844 sdigitizerfound = kTRUE ;
845 }
846 }
847
848 if ( !phosfound || !sdigitizerfound ) {
849 cerr << "WARNING: AliPHOSGetter::ReadTreeS -> Cannot find SDigits and/or SDigitizer with name " << fSDigitsTitle << endl ;
850 return ;
851 }
852
853 // -- the SDigits
854 Post(fHeaderFile, "S", fSDigitsTitle) ;
855
856 // Post the SDigitizer
857 Post(fHeaderFile, "Ser", fSDigitsTitle) ;
858
859 TClonesArray * sdigits = SDigits(fSDigitsTitle) ;
860 sdigits->Clear() ;
861 sdigitsbranch->SetAddress(&sdigits) ;
862
863 AliPHOSSDigitizer * sdigitizer = SDigitizer(fSDigitsTitle) ;
864 sdigitizerbranch->SetAddress(&sdigitizer) ;
865
866 sdigitsbranch->GetEvent(0) ;
867 sdigitizerbranch->GetEvent(0) ;
868
869}
870
871//____________________________________________________________________________
872void AliPHOSGetter::ReadPrimaries()
873{
874 // Reads specific branches of primaries
875
876 fNPrimaries = gAlice->GetNtrack();
877
878 // //Check, is it necessary to open new files
879 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
880 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
881// Int_t input ;
882// for(input = 0; input < filenames->GetEntriesFast(); input++){
883
884// TObjString * filename = (TObjString *) filenames->At(input) ;
885
886// //Test, if this file already open
887// TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
888// if(file == 0)
889// file = new TFile( filename->GetString()) ;
890// file->cd() ;
891
892// // Get Kine Tree from file
893// // char treeName[20];
894// // sprintf(treeName,"TreeK%d",events->At(input));
895// // TTree * treeK = (TTree*)gDirectory->Get(treeName);
896// // if (treeK)
897// // treeK->SetBranchAddress("Particles", &fParticleBuffer);
898// // else
899// // cout << "AliPHOSGetter: cannot find Kine Tree for event:" << events->At(input) << endl;
900
901// // // Create the particle stack
902// // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
903// // // Build the pointer list
904// // if(fParticleMap) { <----
905// // fParticleMap->Clear();
906// // fParticleMap->Expand(treeK->GetEntries());
907// // } else
908// // fParticleMap = new TObjArray(treeK->GetEntries());
909
910// // From gAlice->Particle(i)
911
912
913// // if(!(*fParticleMap)[i]) {
914// // Int_t nentries = fParticles->GetEntries();
915
916// // // algorithmic way of getting entry index
917// // // (primary particles are filled after secondaries)
918// // Int_t entry;
919// // if (i<fHeader.GetNprimary())
920// // entry = i+fHeader.GetNsecondary();
921// // else
922// // entry = i-fHeader.GetNprimary();
923
924// // // only check the algorithmic way and give
925// // // the fatal error if it is wrong
926// // if (entry != fParticleFileMap[i]) {
927// // Fatal("Particle",
928// // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
929// // entry, fParticleFileMap[i]);
930// // }
931
932// // fTreeK->GetEntry(fParticleFileMap[i]);
933// // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
934// // fParticleMap->AddAt((*fParticles)[nentries],i);
935// // }
936// // return (TParticle *) (*fParticleMap)[i];
937
938
939
940// }
941
942
943// //scan over opened files and read corresponding TreeK##
944
945 return ;
946}
947//____________________________________________________________________________
948void AliPHOSGetter::Event(Int_t event)
949{
950 // Reads the content of all Tree's S, D and R
951
952 if ( event > gAlice->TreeE()->GetEntries() ) {
953 cerr << "ERROR: AliPHOSGetter::Event -> There are only " << gAlice->TreeE()->GetEntries() << " events in this file" << endl ;
954 return ;
955 }
956
957 gAlice->GetEvent(event) ;
958
959 ReadTreeH() ;
960 ReadTreeS() ;
961 ReadTreeD() ;
962 ReadTreeR() ;
963 ReadTreeQA() ;
964 ReadPrimaries() ;
965
966}
967
968//____________________________________________________________________________
969const TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const
970{
971 // get the object named "what" from the folder
972 // folders are named like //YSAlice/WhiteBoard/what/PHOS/name
973
974 if ( file.IsNull() )
975 file = fHeaderFile ;
976 TString path("WhiteBoard/") ;
977 if ( name.IsNull() ) {
978 if ( what.CompareTo("Hits") == 0 ) {
979 path += what ;
980 path += "/PHOS/";
981 path += what ;
982 }
983 else if ( what.CompareTo("SDigits") == 0 ) {
984 path += what ;
985 path += "/PHOS/";
986 path += file ;
987 path += "/" ;
988 path += fSDigitsTitle ;
989 }
990 else if ( what.CompareTo("Digits") == 0 ){
991 path += what ;
992 path += "/PHOS/";
993 path += fDigitsTitle ;
994 }
995 else if ( what.CompareTo("EmcRecPoints") == 0 ) {
996 path += "RecPoints/PHOS/";
997 path += "emc/" ;
998 path += fRecPointsTitle ;
999 }
1000 else if ( what.CompareTo("CpvRecPoints") == 0 ) {
1001 path += "RecPoints/PHOS/";
1002 path += "cpv/" ;
1003 path += fRecPointsTitle ;
1004 }
1005 else if ( what.CompareTo("TrackSegments") == 0 ) {
1006 path += "TrackSegments/PHOS/";
1007 path += fTrackSegmentsTitle ;
1008 }
1009 else if ( what.CompareTo("RecParticles") == 0 ) {
1010 path += "RecParticles/PHOS/";
1011 path += fRecParticlesTitle ;
1012 }
1013 else if ( what.CompareTo("Alarms") == 0 ) {
1014 path += "QAAlarms/PHOS";
1015 }
1016 }
1017 else {
1018 if ( what.CompareTo("SDigits") == 0 ) {
1019 path += what ;
1020 path += "/PHOS/";
1021 path += file ;
1022 path += "/" ;
1023 path += name ;
1024 }
1025 else if ( what.CompareTo("Digits") == 0 ) {
1026 path += what ;
1027 path += "/PHOS/";
1028 path += name ;
1029 }
1030 else if ( what.CompareTo("EmcRecPoints") == 0 ) {
1031 path += "RecPoints/PHOS/";
1032 path += "emc/" ;
1033 path += name ;
1034 }
1035 else if ( what.CompareTo("CpvRecPoints") == 0 ) {
1036 path += "RecPoints/PHOS/";
1037 path += "cpv/" ;
1038 path += name ;
1039 }
1040 else if ( what.CompareTo("TrackSegments") == 0 ) {
1041 path += "TrackSegments/PHOS/";
1042 path += name ;
1043 }
1044 else if ( what.CompareTo("RecParticles") == 0 ) {
1045 path += "RecParticles/PHOS/";
1046 path += name ;
1047 }
1048 else if ( what.CompareTo("Alarms") == 0 ) {
1049 path += "QAAlarms/PHOS/";
1050 path += name ;
1051 }
1052 }
1053 path.Prepend("YSAlice/") ;
1054 TObject * phosO = (TObject*)gROOT->FindObjectAny(path) ;
1055 if (!phosO) {
1056 cerr << "ERROR : AliPHOSGetter::ReturnO -> Object " << path << " not found!" << endl ;
1057 abort() ;
1058 }
1059 return phosO ;
1060}
1061
1062//____________________________________________________________________________
1063const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const
1064{
1065 // get the TTask named "what" from the folder
1066 // folders are named like //YSAlice/Tasks/what/PHOS/name
1067
1068 TString path("tasks") ;
1069
1070 if ( what.CompareTo("SDigitizer") == 0 )
1071 path += "/SDigitizer" ;
1072 else if ( what.CompareTo("Digitizer") == 0 )
1073 path += "/Digitizer" ;
1074 else if ( what.CompareTo("Clusterizer") == 0 )
1075 path += "/Reconstructioner" ;
1076 else if ( what.CompareTo("TrackSegmentMaker") == 0 )
1077 path += "/Reconstructioner" ;
1078 else if ( what.CompareTo("PID") == 0 )
1079 path += "/Reconstructioner" ;
eb9763ac 1080 else if ( what.CompareTo("QATasks") == 0 )
1081 path += "/QA" ;
4ae78bb1 1082
1083 TFolder * aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice") ;
1084 TTask * aliceT = (TTask*)aliceF->FindObject(path) ;
1085
1086 if (!aliceT) {
1087 cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << path << " not found!" << endl ;
1088 abort() ;
1089 }
1090
1091 TTask * phosT = (TTask*)aliceT->GetListOfTasks()->FindObject("PHOS") ;
1092 if (!phosT) {
1093 cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << path << "/PHOS not found!" << endl ;
1094 abort() ;
1095 }
1096 TList * l = phosT->GetListOfTasks() ;
1097
1098 if (what.CompareTo("SDigitizer") == 0) {
1099 if ( name.IsNull() )
1100 name = fSDigitsTitle ;
1101 } else if (what.CompareTo("Digitizer") == 0){
1102 if ( name.IsNull() )
1103 name = fDigitsTitle ;
1104 } else if (what.CompareTo("Clusterizer") == 0){
1105 if ( name.IsNull() )
1106 name = fRecPointsTitle ;
1107 }
1108 else if (what.CompareTo("TrackSegmentMaker") == 0){
1109 if ( name.IsNull() )
1110 name = fTrackSegmentsTitle ;
1111 }
1112 else if (what.CompareTo("PID") == 0){
1113 if ( name.IsNull() )
1114 name = fRecParticlesTitle ;
1115 }
eb9763ac 1116 else if (what.CompareTo("QATasks") == 0){
1117 if ( name.IsNull() )
1118 return phosT ;
1119 }
1120
4ae78bb1 1121 TTask * task = (TTask*)l->FindObject(name) ;
1122
1123 if (!task)
1124 cout << "WARNING: AliPHOSGetter::ReturnT -> Task " << path << "/" << name << " not found!" << endl ;
1125
1126 return task ;
1127}