1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 //_________________________________________________________________________
22 // A singleton. This class should be used in the analysis stage to get
23 // reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
24 // instead of directly reading them from galice.root file. This container
25 // ensures, that one reads Digits, made of these particular digits, RecPoints,
26 // made of these particular RecPoints, TrackSegments and RecParticles.
27 // This becomes non trivial if there are several identical branches, produced with
28 // different set of parameters. Currently This class only Retrieves Hits, Digits, and SDigits.
30 // An example of how to use (see also class AliEMCALAnalyser):
31 // AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
33 // please->GetEvent(event) ; // reads new event from galice.root
35 //*-- Author: Sahal Yacoob (LBL)
36 // based on : AliPHOSGetter
37 //////////////////////////////////////////////////////////////////////////////
40 // --- ROOT system ---
45 #include "TObjString.h"
48 // --- Standard library ---
51 // --- AliRoot header files ---
54 #include "AliConfig.h"
55 #include "AliEMCALGetter.h"
56 #include "AliEMCALv1.h"
57 #include "AliEMCALDigitizer.h"
58 #include "AliEMCALSDigitizer.h"
59 #include "AliEMCALGeometry.h"
61 ClassImp(AliEMCALGetter)
63 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
65 //____________________________________________________________________________
66 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle )
68 //Initialize all lists
70 fHeaderFile = headerFile ;
71 fBranchTitle = branchTitle ;
72 fSDigitsTitle = branchTitle ;
73 fDigitsTitle = branchTitle ;
75 fPrimaries = new TObjArray(1) ;
76 fModuleFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules"));
77 fHitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits"));
78 fSDigitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits"));
79 fDigitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data"));
80 fTasksFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ;
82 if ( fHeaderFile != "aliroot" ) { // to call the getter without a file
85 TFile * file = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
87 if(file == 0){ //if file was not opened yet, read gAlice
88 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
89 file = TFile::Open(fHeaderFile.Data(),"update") ;
91 file = new TFile(fHeaderFile.Data(),"update") ;
93 if (!file->IsOpen()) {
94 cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot open " << fHeaderFile.Data() << endl ;
98 gAlice = static_cast<AliRun *>(file->Get("gAlice")) ;
101 cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ;
105 cout << "INFO: AliEMCALGetter -> Posting EMCAL to Folders" << endl ;
106 AliConfig * conf = AliConfig::Instance() ;
107 conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ;
108 conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
114 //____________________________________________________________________________
115 AliEMCALGetter::~AliEMCALGetter(){
119 //____________________________________________________________________________
120 void AliEMCALGetter::CreateWhiteBoard() const
125 //____________________________________________________________________________
126 AliEMCALGetter * AliEMCALGetter::GetInstance()
128 // Returns the pointer of the unique instance already defined
130 AliEMCALGetter * rv = 0 ;
134 cout << "AliEMCALGetter::GetInstance ERROR: not yet initialized" << endl ;
139 //____________________________________________________________________________
140 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
141 const char* branchTitle)
143 // Creates and returns the pointer of the unique instance
144 // Must be called only when the environment has changed
147 if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0) &&
148 (fgObjGetter->fHeaderFile.CompareTo(headerFile)==0))
151 fgObjGetter->~AliEMCALGetter() ; // delete it if already exists another version
153 fgObjGetter = new AliEMCALGetter(headerFile,branchTitle) ;
155 // Posts a few item to the white board (folders)
156 // fgObjGetter->CreateWhiteBoard() ;
162 //____________________________________________________________________________
163 const AliEMCALv0 * AliEMCALGetter::EMCAL()
165 // returns the EMCAL object
166 //AliEMCALv0 * emcal = dynamic_cast<AliEMCALv0 *>(gAlice->GetDetector("EMCAL")) ;
167 AliEMCALv0 * emcal = dynamic_cast<AliEMCALv1 *>(fModuleFolder->FindObject("EMCAL")) ;
169 cout << "WARNING: AliEMCALGetter::EMCAL -> EMCAL module not found in Folders" << endl ;
173 //____________________________________________________________________________
174 const AliEMCALGeometry * AliEMCALGetter::EMCALGeometry()
176 AliEMCALGeometry * rv = 0 ;
178 rv = EMCAL()->GetGeometry() ;
182 //____________________________________________________________________________
183 Bool_t AliEMCALGetter::PostHits(void) const
184 { //------- Hits ----------------------
186 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
188 TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
189 if ( !emcalFolder ) {
190 cout << "WARNING: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
191 cout << "INFO: AliEMCALGetter::Post H -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
192 emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ;
194 TClonesArray *hits= new TClonesArray("AliEMCALHit",1000) ;
195 hits->SetName("Hits") ;
196 emcalFolder->Add(hits) ;
201 //____________________________________________________________________________
202 void * AliEMCALGetter::HitsRef(void) const
203 { //------- Hits ----------------------
206 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
207 if ( !fHitsFolder ) {
208 cerr << "ERROR: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << " not found!" << endl;
212 TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
213 if ( !emcalFolder ) {
214 cerr << "ERROR: AliEMCALGetter::Post HRef -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
218 TObject * h = emcalFolder->FindObject("Hits") ;
220 cerr << "ERROR: AliEMCALGetter::HRef -> " << emcalFolder->GetName() << "/Hits not found !" << endl ;
224 return static_cast<void *>(emcalFolder->GetListOfFolders()->GetObjectRef(h)) ;
227 //____________________________________________________________________________
228 Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const
229 { //---------- SDigits -------------------------
232 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
233 // because you can have sdigits from several hit files for mixing
235 TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
236 if ( !emcalFolder ) {
237 cout << "WARNING: AliEMCALGetter::Post S -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
238 cout << "INFO: AliEMCALGetter::Post S -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
239 emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
241 TString subdir(headerFile) ;
242 TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ;
243 if ( !emcalSubFolder )
244 emcalSubFolder = emcalFolder->AddFolder(subdir, "");
246 TObject * sd = emcalSubFolder->FindObject(name);
248 cerr <<"INFO: AliEMCALGetter::Post S -> Folder " << subdir
249 << " already exists!" << endl ;
251 TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1000) ;
252 sdigits->SetName(name) ;
253 emcalSubFolder->Add(sdigits) ;
258 //____________________________________________________________________________
259 void * AliEMCALGetter::SDigitsRef(const char * name, const char * file) const
260 { //------- SDigits ----------------------
262 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
264 if ( !fSDigitsFolder ) {
265 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
269 TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
270 if ( !emcalFolder ) {
271 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
275 TFolder * emcalSubFolder = 0 ;
277 emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
279 emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
281 if(!emcalSubFolder) {
282 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //Folders/RunMC/Event/Data/EMCAL/" << file << "not found!" << endl;
286 TObject * dis = emcalSubFolder->FindObject(name) ;
290 return static_cast<void *>(emcalSubFolder->GetListOfFolders()->GetObjectRef(dis)) ;
294 //____________________________________________________________________________
295 Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const
296 { //---------- SDigitizer -------------------------
298 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
301 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
304 cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
307 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
309 cout <<"WARNING: AliEMCALGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
310 cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL/" << endl;
311 emcal = new TTask("EMCAL", "") ;
314 AliEMCALSDigitizer * emcalsd = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() ));
316 cout << "INFO: AliEMCALGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ;
317 emcal->GetListOfTasks()->Remove(emcalsd) ;
319 emcal->Add(sdigitizer) ;
324 //____________________________________________________________________________
325 void * AliEMCALGetter::SDigitizerRef(const char * name) const
328 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
330 cerr << "ERROR: AliEMCALGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
334 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
336 cerr <<"ERROR: AliEMCALGetter::Post SerRef -> //" << fTasksFolder << "/SDigitizer/EMCAL not found!" << endl;
340 TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ;
342 return static_cast<void *>(emcal->GetListOfTasks()->GetObjectRef(task)) ;
346 //____________________________________________________________________________
347 Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const
348 { //---------- SDigitizer -------------------------
350 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
353 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
355 cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
359 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
361 cout <<"WARNING: AliEMCALGetter::Post Ser -> //" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
362 cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL" << endl;
363 emcal = new TTask("EMCAL", "") ;
367 TString sdname(name) ;
370 AliEMCALSDigitizer * emcalsd = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname ));
372 emcalsd = new AliEMCALSDigitizer() ;
373 //Note, we can not call constructor with parameters: it will call Getter and scrud up everething
374 emcalsd->SetName(sdname) ;
375 emcalsd->SetTitle(file) ;
376 emcal->Add(emcalsd) ;
382 //____________________________________________________________________________
383 Bool_t AliEMCALGetter::PostDigits(const char * name) const
384 { //---------- Digits -------------------------
386 // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
388 TFolder * emcalFolder = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
390 if ( !emcalFolder ) {
391 cout << "WARNING: AliEMCALGetter::Post D -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
392 cout << "INFO: AliEMCALGetter::Post D -> Adding Folder //" << fDigitsFolder << "/EMCAL/" << endl;
393 emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;
396 TObject* dig = emcalFolder->FindObject( name ) ;
398 TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
399 digits->SetName(name) ;
400 emcalFolder->Add(digits) ;
405 //____________________________________________________________________________
406 void * AliEMCALGetter::DigitsRef(const char * name) const
407 { //------- Digits ----------------------
409 // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
411 if ( !fDigitsFolder ) {
412 cerr << "ERROR: AliEMCALGetter::Post DRef -> Folder //" << fDigitsFolder << " not found!" << endl;
416 TFolder * emcalFolder = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
417 if ( !emcalFolder ) {
418 cerr << "ERROR: AliEMCALGetter::DRef -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
422 TObject * d = emcalFolder->FindObject(name) ;
426 return static_cast<void *>(emcalFolder->GetListOfFolders()->GetObjectRef(d)) ;
430 //____________________________________________________________________________
431 Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const
432 { //---------- Digitizer -------------------------
434 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
437 cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
440 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
442 cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
443 cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
444 emcal = new TTask("EMCAL", "") ;
448 AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ;
451 emcal->GetListOfTasks()->Remove(emcald) ;
453 emcal->Add(digitizer) ;
457 //____________________________________________________________________________
458 Bool_t AliEMCALGetter::PostDigitizer(const char * name) const
459 { //---------- Digitizer -------------------------
461 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
463 TTask * d = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
465 cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
469 TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ;
471 cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
472 cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
473 emcal = new TTask("EMCAL", "") ;
477 AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ;
479 emcald = new AliEMCALDigitizer() ;
480 emcald->SetName(fDigitsTitle) ;
481 emcald->SetTitle(fHeaderFile) ;
487 //____________________________________________________________________________
488 void * AliEMCALGetter::DigitizerRef(const char * name) const
490 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
492 cerr << "ERROR: AliEMCALGetter::Post DerRef -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
496 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
498 cerr <<"ERROR: AliEMCALGetter::Post DerRef -> //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
502 TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ;
504 return static_cast<void *>(emcal->GetListOfTasks()->GetObjectRef(task)) ;
508 //____________________________________________________________________________
509 const TParticle * AliEMCALGetter::Primary(Int_t index) const
511 // Return primary particle numbered by <index>
516 Int_t primaryIndex = index % 10000000 ;
517 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
519 if ( primaryList > 0 ) {
520 cout << " Getter does not support currently Mixing of primary " << endl ;
521 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
525 return gAlice->Particle(primaryIndex) ;
529 //____________________________________________________________________________
530 void AliEMCALGetter::ReadTreeD()
532 // Read the digit tree gAlice->TreeD()
533 if(gAlice->TreeD()== 0){
534 cerr << "ERROR: AliEMCALGetter::ReadTreeD: can not read TreeD " << endl ;
537 cout << "hello" << endl;
538 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeD()->GetListOfBranches()) ;
540 TBranch * branch = 0 ;
541 TBranch * digitsbranch = 0 ;
542 TBranch * digitizerbranch = 0 ;
543 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
545 while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
546 if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
547 digitsbranch = branch ;
550 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
551 digitizerbranch = branch ;
552 digitizerfound = kTRUE ;
556 if ( !emcalfound || !digitizerfound ) {
557 cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name "
558 << fDigitsTitle << endl ;
563 if(!Digits(fDigitsTitle) )
564 PostDigits(fDigitsTitle);
565 digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
566 digitsbranch->GetEntry(0) ;
569 // read the Digitizer
570 if(!Digitizer(fDigitsTitle))
571 PostDigitizer(fDigitsTitle) ;
572 digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
573 digitizerbranch->GetEntry(0) ;
578 //____________________________________________________________________________
579 void AliEMCALGetter::ReadTreeH()
581 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
583 if(gAlice->TreeH()== 0){
584 cerr << "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
588 TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
590 cout << "WARNING: AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ;
596 hitsbranch->SetAddress(HitsRef()) ;
598 hitsbranch->GetEntry(0) ;
602 //____________________________________________________________________________
603 void AliEMCALGetter::Track(Int_t itrack)
605 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
607 if(gAlice->TreeH()== 0){
608 cerr << "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
612 TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
614 cout << "WARNING: AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ;
619 hitsbranch->SetAddress(HitsRef()) ;
620 hitsbranch->GetEntry(itrack) ;
624 //____________________________________________________________________________
625 void AliEMCALGetter::ReadTreeS(Int_t event)
627 // Read the summable digits tree gAlice->TreeS()
629 // loop over all opened files and read their SDigits to the White Board
630 TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
632 emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
633 TCollection * folderslist = emcalF->GetListOfFolders() ;
635 //Add current file to list if it is not there yet
636 if ( (fHeaderFile != "aliroot") && ( !folderslist->Contains(fHeaderFile) ) ){
637 emcalF->AddFolder(fHeaderFile, "");
640 TIter next(folderslist) ;
641 TFolder * folder = 0 ;
644 while ( (folder = static_cast<TFolder*>(next())) ) {
645 if(fHeaderFile.CompareTo(folder->GetName()) == 0 )
646 {treeS=gAlice->TreeS() ;
647 cout << "ReadTreeS "<< gAlice->TreeS() <<endl ;}
649 cout << " AliEMCALGetter::ReadTreeS 2 " << folder->GetName() << endl ;
650 file = static_cast<TFile*>(gROOT->GetFile(folder->GetName()));
653 // Get SDigits Tree header from file
654 TString treeName("TreeS") ;
656 treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
659 cerr << "ERROR: AliEMCALGetter::ReadTreeS There is no SDigit Tree" << endl;
663 //set address of the SDigits and SDigitizer
664 TBranch * sdigitsBranch = 0;
665 TBranch * sdigitizerBranch = 0;
666 TBranch * branch = 0 ;
667 TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
669 Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ;
671 while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
673 if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
675 sdigitsBranch = branch ;
676 cout << "sdigitsbranch found = " << branch << endl ;
679 else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
680 sdigitizerfound = kTRUE ;
681 sdigitizerBranch = branch ;
682 cout << "sdigitizerbranch found = " << branch << endl ;
685 if ( !emcalfound || !sdigitizerfound ) {
686 cout << "WARNING: AliEMCALDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName()
687 << " not found" << endl ;
691 if ( !folder->FindObject(fSDigitsTitle) )
692 { PostSDigits(fSDigitsTitle,folder->GetName()) ;
693 cout << "Posting SDigits " << endl << endl ;}
694 sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
696 sdigitsBranch->GetEntry(0) ;
698 TString sdname(fSDigitsTitle) ;
699 cout << sdname << endl ;
701 sdname+=folder->GetName() ;
702 if(!SDigitizer(sdname) )
703 PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
704 sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
705 sdigitizerBranch->GetEntry(0) ;
709 // After SDigits have been read from all files, return to the first one
712 folder = static_cast<TFolder*>(next());
714 file = static_cast<TFile*>(gROOT->GetFile(folder->GetName()));
719 //____________________________________________________________________________
720 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
721 { // Read the summable digits fron treeS()
724 TString filename("mergefile") ;
727 TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
728 if ( !emcalFolder ) {
729 emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
731 TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
732 //set address of the SDigits and SDigitizer
733 TBranch * sdigitsBranch = 0;
734 TBranch * sdigitizerBranch = 0;
735 TBranch * branch = 0 ;
736 TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
738 Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ;
740 while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
741 if ( strcmp(branch->GetName(), "EMCAL")==0) {
743 sdigitsBranch = branch ;
746 else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
747 sdigitizerfound = kTRUE ;
748 sdigitizerBranch = branch ;
751 if ( !emcalfound || !sdigitizerfound ) {
752 cout << "WARNING: AliEMCALGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
756 if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
757 PostSDigits(sdigitsBranch->GetTitle(),filename) ;
759 sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
761 TString sdname(sdigitsBranch->GetTitle()) ;
764 if(!SDigitizer(sdigitsBranch->GetTitle()) )
765 PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
766 sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
768 sdigitsBranch->GetEntry(0) ;
769 sdigitizerBranch->GetEntry(0) ;
774 //____________________________________________________________________________
775 void AliEMCALGetter::ReadPrimaries()
777 // Reads specific branches of primaries
779 fNPrimaries = gAlice->GetNtrack();
781 // //Check, is it necessary to open new files
782 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
783 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
785 // for(input = 0; input < filenames->GetEntriesFast(); input++){
787 // TObjString * filename = (TObjString *) filenames->At(input) ;
789 // //Test, if this file already open
790 // TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
792 // file = new TFile( filename->GetString()) ;
795 // // Get Kine Tree from file
796 // // char treeName[20];
797 // // sprintf(treeName,"TreeK%d",events->At(input));
798 // // TTree * treeK = (TTree*)gDirectory->Get(treeName);
800 // // treeK->SetBranchAddress("Particles", &fParticleBuffer);
802 // // cout << "AliEMCALGetter: cannot find Kine Tree for event:" << events->At(input) << endl;
804 // // // Create the particle stack
805 // // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
806 // // // Build the pointer list
807 // // if(fParticleMap) { <----
808 // // fParticleMap->Clear();
809 // // fParticleMap->Expand(treeK->GetEntries());
811 // // fParticleMap = new TObjArray(treeK->GetEntries());
813 // // From gAlice->Particle(i)
816 // // if(!(*fParticleMap)[i]) {
817 // // Int_t nentries = fParticles->GetEntries();
819 // // // algorithmic way of getting entry index
820 // // // (primary particles are filled after secondaries)
822 // // if (i<fHeader.GetNprimary())
823 // // entry = i+fHeader.GetNsecondary();
825 // // entry = i-fHeader.GetNprimary();
827 // // // only check the algorithmic way and give
828 // // // the fatal error if it is wrong
829 // // if (entry != fParticleFileMap[i]) {
830 // // Fatal("Particle",
831 // // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
832 // // entry, fParticleFileMap[i]);
835 // // fTreeK->GetEntry(fParticleFileMap[i]);
836 // // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
837 // // fParticleMap->AddAt((*fParticles)[nentries],i);
839 // // return (TParticle *) (*fParticleMap)[i];
846 // //scan over opened files and read corresponding TreeK##
850 //____________________________________________________________________________
851 void AliEMCALGetter::Event(const Int_t event, const char* opt)
853 // Reads the content of all Tree's S, D and R
855 if (event >= gAlice->TreeE()->GetEntries() ) {
856 cerr << "ERROR: AliEMCALGetter::Event -> " << event << " not found in TreeE!" << endl ;
859 gAlice->GetEvent(event) ;
862 {cout<<"Reading TreeH" << endl ;
866 { cout << "Reading TreeS" << endl ;
869 if( strstr(opt,"D") )
872 if( strstr(opt,"R") )
875 if( strstr(opt,"Q") )
878 if( strstr(opt,"P") )
883 //____________________________________________________________________________
884 const TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const
886 // get the object named "what" from the folder
887 // folders are named like //Folders
892 TFolder * folder = 0 ;
893 TObject * emcalO = 0 ;
895 // if ( name.IsNull() ) {
896 if ( what.CompareTo("Hits") == 0 ) {
897 folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
899 emcalO = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;
901 else if ( what.CompareTo("SDigits") == 0 ) {
902 TString path = "EMCAL/" + file ;
903 folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ;
905 cout << "folder found" << endl ;
907 name = fSDigitsTitle ;
908 emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;
911 else if ( what.CompareTo("Digits") == 0 ){
912 folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ;
915 name = fDigitsTitle ;
916 emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;
920 cerr << "ERROR : AliEMCALGetter::ReturnO -> Object " << what << " not found in " << folder->GetName() << endl ;
926 //____________________________________________________________________________
927 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const
929 // get the TTask named "what" from the folder
930 // folders are named like //Folders/Tasks/what/EMCAL/name
932 TString search(what) ;
934 TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ;
937 cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << " not found!" << endl ;
941 TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ;
943 cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << "/EMCAL not found!" << endl ;
947 TList * list = emcalT->GetListOfTasks() ;
949 if (what.CompareTo("SDigitizer") == 0) {
951 name = fSDigitsTitle ;
952 } else if (what.CompareTo("Digitizer") == 0){
954 name = fDigitsTitle ;
959 while((task = static_cast<TTask *>(it.Next()) )){
960 TString taskname(task->GetName()) ;
961 if(taskname.BeginsWith(name))
965 cout << "WARNING: AliEMCALGetter::ReturnT -> Task " << search << "/" << name << " not found!" << endl ;