]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
Correction in efficiency for p < 0.5.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:  */
17 /* $Log:
18    29.05.2001 Yuri Kharlov:
19               Everywhere reading the treese TTree->GetEvent(i)
20               is replaced by reading the branches TBranch->GetEntry(0)
21 */
22
23 /* $Log:
24    08.2002 Dmitri Peressounko:
25 */
26
27 //_________________________________________________________________________
28 //  A singleton. This class should be used in the analysis stage to get 
29 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
30 //  instead of directly reading them from galice.root file. This container 
31 //  ensures, that one reads Digits, made of these particular digits, RecPoints,
32 //  made of these particular RecPoints, TrackSegments and RecParticles. 
33 //  This becomes non trivial if there are several identical branches, produced with
34 //  different set of parameters. 
35 //
36 //  An example of how to use (see also class AliEMCALAnalyser):
37 //  AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
38 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
39 //     AliEMCALRecParticle * part = gime->RecParticle(1) ;
40 //     ................
41 //  please->GetEvent(event) ;    // reads new event from galice.root
42 //                  
43 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
44 //*--         Completely redesigned by Dmitri Peressounko March 2001  
45 //
46 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
47 //*--         systematic usage of TFolders without changing the interface     
48 //*-- YS August 2002 : clone PHOS as closely as possible and intoduction
49 //                     of new  IO (à la PHOS)
50
51 //////////////////////////////////////////////////////////////////////////////
52
53
54
55 // --- ROOT system ---
56
57 #include "TFile.h"
58 #include "TTree.h"
59 #include "TROOT.h"
60 #include "TObjString.h"
61 #include "TFolder.h"
62 #include "TParticle.h"
63
64 // --- Standard library ---
65
66 #include <Riostream.h>
67
68 // --- AliRoot header files ---
69
70 #include "AliRun.h"
71 #include "AliConfig.h"
72 #include "AliEMCALGetter.h"
73 #include "AliEMCAL.h"
74 #include "AliEMCALDigitizer.h"
75 #include "AliEMCALSDigitizer.h"
76 #include "AliEMCALClusterizerv1.h"
77 #include "AliEMCALGeometry.h"
78
79 ClassImp(AliEMCALGetter)
80
81   AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
82   TFile * AliEMCALGetter::fFile = 0 ; 
83
84 //____________________________________________________________________________ 
85
86 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle, const Bool_t toSplit)
87 {
88   // This is the ctor called by GetInstance and the only one that can be used 
89
90   if ( fHeaderFile.Contains("_") ) {
91     Fatal("AliEMCALGetter","Invalid file name (_ not allowed) %s",fHeaderFile.Data()) ;
92   }
93
94   //Initialize  all data
95
96   fFailed = kFALSE ;   
97   fDebug  = 0 ; 
98   fAlice  = 0 ; 
99
100   fToSplit    = toSplit ;
101   fHeaderFile = headerFile ; 
102
103   fPrimaries = new TObjArray(1) ;
104
105   fModuleFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
106   fPrimariesFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data")); 
107   fHitsFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
108   fSDigitsFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
109   fDigitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
110   fRecoFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
111   //fQAFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
112   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
113
114   //Set titles to branches and create EMCAL specific folders
115
116   SetTitle(branchTitle) ;
117
118   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
119
120     //open headers file
121
122     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
123
124     if(!fFile){    //if file was not opened yet, read gAlice
125       fFile = TFile::Open(fHeaderFile.Data(), "update") ;   
126       if (!fFile->IsOpen()) {
127         Error("AliEMCALGetter","Cannot open %s",fHeaderFile.Data()) ; 
128         fFailed = kTRUE ;
129         return ;  
130       }
131     }
132     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
133   }
134
135   if (!gAlice) {
136     Error("AliEMCALGetter","Cannot find gAlice in %s",fHeaderFile.Data()) ; 
137     fFailed = kTRUE ;
138     return ; 
139   }
140   if (!EMCAL()) {
141     if (fDebug)
142       Info("AliEMCALGetter","Posting EMCAL to Folders") ; 
143
144     if (gAlice->GetDetector("EMCAL")) {
145       AliConfig * conf = AliConfig::Instance() ;
146       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ; 
147       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
148     }
149     else 
150       Error("AliEMCALGetter"," Detector EMCAL not found");
151   }
152
153   fDebug=0;
154 }
155
156 //____________________________________________________________________________ 
157
158 AliEMCALGetter::~AliEMCALGetter()
159 {
160   if (fPrimaries) {
161     fPrimaries->Delete() ; 
162     delete fPrimaries ; 
163   }
164
165   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
166   TCollection * folderslist = emcalF->GetListOfFolders() ; 
167   TIter next(folderslist) ; 
168   TFolder * folder = 0 ; 
169
170   while ( (folder = static_cast<TFolder*>(next())) ) 
171     emcalF->Remove(folder) ; 
172
173   if (fFile) { 
174     fFile->Close() ;  
175     delete fFile ; 
176     fFile = 0 ;
177   }
178
179   fgObjGetter = 0 ; 
180 }
181
182 //____________________________________________________________________________ 
183
184 void AliEMCALGetter::CloseFile()
185 {
186   delete gAlice ;  
187   gAlice = 0 ; 
188   delete fAlice ; 
189   fAlice = 0 ; 
190 }
191
192 //____________________________________________________________________________ 
193
194 const TFolder * AliEMCALGetter::Folder(const TString what) const {
195
196   // returns the EMCAL folder required by what
197   // what = hits, sdigits, digits
198
199   if ( what == "hits" ) 
200     return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
201   else if ( what == "sdigits" ) 
202     return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ; 
203   else if ( what == "digits" ) 
204     return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("EMCAL")) ;
205   else {
206     Error("GetFolder","%s illegal option (hits, sdigits, digits) ", what.Data()) ; 
207     return 0 ; 
208   }
209 }
210
211 //____________________________________________________________________________ 
212
213 AliEMCALGetter * AliEMCALGetter::GetInstance()
214 {
215   // Returns the pointer of the unique instance already defined
216
217   if ( fgObjGetter ) {
218     return fgObjGetter ;
219   }
220   else {
221     return 0 ;
222   }
223 }
224
225 //____________________________________________________________________________ 
226
227 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
228                                              const char* branchTitle,
229                                              const Bool_t toSplit)
230 {
231   // Creates and returns the pointer of the unique instance
232   // Must be called only when the environment has changed 
233
234   if(!fgObjGetter){
235     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
236     if(fgObjGetter->fFailed)
237       return 0;
238     else
239       return fgObjGetter ;
240   }
241
242   //First checks, if header file already opened
243
244   if(!fgObjGetter->fFile){
245      fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
246     if(fgObjGetter->fFailed)
247       return 0;
248     else
249       return fgObjGetter ;
250   }
251
252   if(fgObjGetter->fHeaderFile.CompareTo(headerFile)==0){ //Opened the same header file   
253     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0)&&   //Open the same branch title
254        (toSplit==fgObjGetter->fToSplit)){                          //Nothing should be cleaned
255     }
256     else{ //Clean all data and AliEMCAL...zers
257       if(fgObjGetter->fToSplit)
258         fgObjGetter->CloseSplitFiles() ;          
259       //fgObjGetter->CleanWhiteBoard() ;
260       fgObjGetter->fToSplit = toSplit ;
261       fgObjGetter->SetTitle(branchTitle) ;
262     }
263   }
264   else{  //Close already opened files, clean memory and open new header file
265     if(gAlice){ //should first delete gAlice, then close file
266       //Should be in dtor of EMCAL, but if one changes path ...
267       fgObjGetter->fModuleFolder->Remove(fgObjGetter->fModuleFolder->FindObject("EMCAL")) ; 
268       delete gAlice ;
269     }
270     if(fgObjGetter->fFile){
271       fgObjGetter->fFile->Close() ;
272       fgObjGetter->fFile=0;
273     }
274     if(fgObjGetter->fToSplit)
275       fgObjGetter->CloseSplitFiles() ;
276     fgObjGetter->CleanWhiteBoard() ;    
277     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
278   }
279
280   return fgObjGetter ; 
281
282 }
283
284 //____________________________________________________________________________ 
285
286 const Bool_t AliEMCALGetter::BranchExists(const TString recName) const
287 {
288   //Looks in the tree Tree"name" if branch with current name olready exists
289
290   TString filename("") ;
291   TString name, dataname, zername;
292   if(recName == "SDigits"){
293     filename=fSDigitsFileName ;
294     name = "TreeS0" ;
295     dataname = "EMCAL" ;
296     zername = "AliEMCALSDigitizer" ;
297   }
298   else if(recName == "Digits"){
299     filename=fDigitsFileName ;
300     name = "TreeD0" ;
301     dataname = "EMCAL" ;
302     zername = "AliEMCALDigitizer" ;
303   }
304   else if(recName =="RecPoints"){
305         filename=fRecPointsFileName ;
306         name = "TreeR0" ;
307         dataname = "EMCALEmcRP" ;
308         zername = "AliEMCALClusterizer" ;
309   }
310   else if(recName == "TrackSegments"){
311     filename=fTrackSegmentsFileName ;
312     name = "TreeR0" ;
313     dataname = "EMCALTS" ;
314     zername = "AliEMCALTrackSegmentMaker" ;
315   }      
316   else if(recName == "RecParticles"){
317     filename= fRecParticlesFileName ;
318     name = "TreeR0" ;
319     dataname = "EMCALRP" ;
320     zername = "AliEMCALPID" ;
321   }
322   else
323     return kFALSE ;
324
325   TFile * file ;
326   TTree * tree ;
327   if(fToSplit){
328     file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
329     if(!file)
330       file = TFile::Open(fSDigitsFileName.Data(),"update");
331   }
332   else
333     file = fFile ;
334
335   tree = (TTree *)file->Get(name.Data()) ;
336
337   if(!tree ) 
338     return kFALSE ;
339
340   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
341   TIter next(lob) ; 
342   TBranch * branch = 0 ;  
343   TString titleName(fBranchTitle);
344   titleName+=":";
345
346   while ((branch = (static_cast<TBranch*>(next())))) {
347     TString branchName(branch->GetName() ) ; 
348     TString branchTitle(branch->GetTitle() ) ;  
349     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
350       Warning("BranchExists", "branch %s with title %s already exits in %s", dataname.Data(), fBranchTitle.Data(), name.Data());
351       return kTRUE ;
352     }
353
354     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
355       Warning("BranchExists","Branch AliEMCAL... with title %s already exits in %s",branch->GetTitle(), name.Data());     
356       return kTRUE ; 
357     }
358   }
359
360     //We can't delete three if gAlice points to it... To be redisigned somehow???!!!
361
362   if(!fToSplit){
363     if(name.Contains("TreeS"))
364       if(tree!=gAlice->TreeS())
365         tree->Delete();
366     if(name.Contains("TreeD"))
367       if(tree!=gAlice->TreeD())
368         tree->Delete();
369     if(name.Contains("TreeR"))
370       if(tree!=gAlice->TreeR())
371         tree->Delete();    
372   }
373
374   return kFALSE ;
375 }
376
377 //____________________________________________________________________________ 
378
379 void AliEMCALGetter::ListBranches(Int_t event) const  
380 {
381   TBranch * branch = 0 ; 
382   if (gAlice->GetEvent(event) == -1)
383     return ; 
384
385   TTree * t =  gAlice->TreeH() ; 
386
387   if(t){
388     Info("ListBranches"," -> ****** Hits    : "); 
389     TObjArray * lob = t->GetListOfBranches() ;
390     TIter next(lob) ; 
391
392     while ( (branch = static_cast<TBranch*>(next())) )
393       Info("ListBranches","         %s", branch->GetName());
394
395   } else 
396     Warning("ListBranches"," -> TreeH not found for event %d",event);  
397
398   t = gAlice->TreeS() ;
399
400   if(t){
401     Info("ListBranches"," -> ****** SDigits : "); 
402     TObjArray * lob = t->GetListOfBranches() ;
403     TIter next(lob) ; 
404
405     while ( (branch = static_cast<TBranch*>(next())) )
406       Info("ListBranches","             %s %s",branch->GetName(),branch->GetTitle()); 
407   } else 
408     Warning("ListBranches"," -> TreeS not found for event %d",event);  
409
410   t = gAlice->TreeD() ;
411
412   if(t){
413     Info("ListBranches"," -> ****** Digits  : "); 
414     TObjArray * lob = t->GetListOfBranches() ;
415     TIter next(lob) ; 
416
417     while ( (branch = static_cast<TBranch*>(next())) )
418       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
419   } else 
420     Warning("ListBranches"," -> TreeD not found for event %d", event);  
421
422   t = gAlice->TreeR() ;
423
424   if(t){
425     Info("ListBranches"," -> ****** Recon   : "); 
426     TObjArray * lob = t->GetListOfBranches() ;
427     TIter next(lob) ; 
428     while ( (branch = static_cast<TBranch*>(next())) )
429       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
430   } else 
431     Warning("ListBranches"," -> TreeR not found for event %d",event);  
432 }
433
434 //____________________________________________________________________________ 
435
436 void AliEMCALGetter::NewBranch(TString name, Int_t event)  
437 {
438   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
439   Event(event) ; 
440 }
441
442 //____________________________________________________________________________ 
443
444 Bool_t AliEMCALGetter::NewFile(TString name)  
445 {
446   fHeaderFile = name ; 
447   fFile->Close() ; 
448   fFailed = kFALSE; 
449
450   fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
451
452   if(!fFile) {    //if file was not opened yet, read gAlice
453     fFile = TFile::Open(fHeaderFile.Data(),"update") ;
454     if (!fFile->IsOpen()) {
455       Error("NewFile", " -> Cannot open %s", fHeaderFile.Data()); 
456       fFailed = kTRUE ;
457       return fFailed ;  
458     }
459     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
460   } 
461
462   if (!gAlice) {
463     Error("NewFile"," -> Cannot find gAlice in %s", fHeaderFile.Data());
464     fFailed = kTRUE ;
465     return fFailed ; 
466   }
467   return fFailed ; 
468 }
469
470 //____________________________________________________________________________ 
471
472 const AliEMCAL * AliEMCALGetter::EMCAL() 
473 {
474   // returns the EMCAL object 
475
476   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(fModuleFolder->FindObject("EMCAL")) ;  
477
478   if (!emcal) 
479     if (fDebug)
480       Warning("EMCAL"," -> EMCAL module not found in Folders" );
481   return emcal ; 
482 }  
483
484 //____________________________________________________________________________ 
485
486 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() 
487 {
488   AliEMCALGeometry * rv = 0 ; 
489   if (EMCAL() )
490     rv =  EMCAL()->GetGeometry() ;
491   return rv ; 
492
493
494 //____________________________________________________________________________ 
495
496 const Bool_t AliEMCALGetter::PostPrimaries(void) const 
497 {  
498   //------- Primaries ----------------------
499   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
500
501   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
502   if ( !primariesFolder ) {
503     if (fDebug) {
504       Warning("PostPrimaries", "-> Folder //%s/Primaries/ not found!", fPrimariesFolder->GetName());
505       Info("PostPrimaries", "-> Adding Folder //%s/Primaries/",fPrimariesFolder->GetName());
506     }
507     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
508   }    
509
510   TClonesArray *primaries=  new TClonesArray("TParticle",1000) ;
511   primaries->SetName("Primaries") ;
512   primariesFolder->Add(primaries) ; 
513
514   return kTRUE;
515
516
517 //____________________________________________________________________________ 
518
519 TObject** AliEMCALGetter::PrimariesRef(void) const 
520 {  
521   //------- Primaries ----------------------
522   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
523
524   if ( !fPrimariesFolder ) {
525     Fatal("PrimariesRef", "-> Folder //%s not found!",fPrimariesFolder);
526   }    
527
528   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
529
530   if ( !primariesFolder ) {
531     Fatal("PrimariesRef", "-> Folder //%s/Primaries/ not found!",fPrimariesFolder);  
532   }
533
534   TObject * p = primariesFolder->FindObject("Primaries") ;
535
536   if(!p) {
537     Fatal("PrimariesRef", "-> %s/Primaries not found !",primariesFolder->GetName()); 
538   }
539
540   return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
541 }
542
543 //____________________________________________________________________________ 
544
545 const Bool_t AliEMCALGetter::PostHits(void) const 
546 {  
547   //------- Hits ----------------------
548   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
549
550   TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
551
552   if ( !emcalFolder ) {
553     if (fDebug) {
554       Warning("PostHits", "-> Folder //%s/EMCAL/ not found!", fHitsFolder);
555       Info("PostHits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
556     }
557     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
558   }    
559
560   TClonesArray *hits=  new TClonesArray("AliEMCALHit",1000) ;
561   hits->SetName("Hits") ;
562   emcalFolder->Add(hits) ; 
563
564   return kTRUE;
565
566
567 //____________________________________________________________________________ 
568
569 TObject ** AliEMCALGetter::HitsRef(void) const 
570 {  
571   //------- Hits ----------------------
572   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
573
574   if ( !fHitsFolder ) {
575     Error("HitsRef", "-> Folder //%s not found!",fHitsFolder);
576     return 0;
577   }    
578
579   TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
580   if ( !emcalFolder ) {
581     Error("HitsRef", "-> Folder //%s/EMCAL/ not found!",fHitsFolder);
582     return 0;
583   }
584
585   TObject * h = emcalFolder->FindObject("Hits") ;
586
587   if(!h) {
588     Error("HitsRef", "-> %s/Hits not found !",emcalFolder->GetName());
589     return 0 ;
590   }
591   else
592     return emcalFolder->GetListOfFolders()->GetObjectRef(h) ;
593 }
594
595 //____________________________________________________________________________ 
596
597 const Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const 
598 {  
599   //---------- SDigits -------------------------
600   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
601   // because you can have sdigits from several hit files for mixing
602
603   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
604
605   if ( !emcalFolder ) {
606     if (fDebug) {
607       Warning("PostSDigits", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
608       Info("PostSDigits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
609     }
610     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
611   }    
612
613   TString subdir(headerFile) ;
614   subdir.ReplaceAll("/", "_") ; 
615   TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ; 
616   if ( !emcalSubFolder ) 
617     emcalSubFolder = emcalFolder->AddFolder(subdir, ""); 
618
619   TObject * sd  = emcalSubFolder->FindObject(name); 
620
621   if ( !sd ) {
622     TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1) ;
623     sdigits->SetName(name) ;
624     emcalSubFolder->Add(sdigits) ;
625   }
626
627   return kTRUE;
628
629
630 //____________________________________________________________________________ 
631
632 TObject ** AliEMCALGetter::SDigitsRef(const char * name, const char * file) const 
633 {  
634   //------- SDigits ----------------------
635   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
636
637   if ( !fSDigitsFolder ) {
638     Fatal("SDigitsRef", "-> Folder //%s not found!", fSDigitsFolder);
639   }    
640
641   TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
642
643   if ( !emcalFolder ) {
644     Fatal("SDigitsRef", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
645   }
646
647   TFolder * emcalSubFolder = 0 ;
648
649   if(file)
650     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
651   else
652     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
653
654   if(!emcalSubFolder) {
655     Fatal("SDigitsRef", "-> Folder //Folders/RunMC/Event/Data/EMCAL/%s not found!", file);
656   }
657
658   TObject * dis = emcalSubFolder->FindObject(name) ;
659
660   if(!dis) {
661     Fatal("SDigitsRef", "-> object %s not found!", name);
662   }
663
664   return emcalSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
665 }
666
667 //____________________________________________________________________________ 
668
669 const Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const 
670 {  
671   //---------- SDigitizer -------------------------
672   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
673
674   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
675
676   if ( !sd ) {
677     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!",fTasksFolder);
678     return kFALSE ;
679   }        
680
681   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
682
683   if ( !emcal )  {
684     if (fDebug) {
685       Warning("PostSDigitizer", "->//%s/SDigitizer/EMCAL/ not found!",fTasksFolder);
686       Info("PostSDigitizer", "-> Adding //%s/SDigitizer/EMCAL/", fTasksFolder);
687     }
688     emcal = new TTask("EMCAL", "") ; 
689     sd->Add(emcal) ; 
690   } 
691
692   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
693
694   if (emcalsd) { 
695     if (fDebug)
696       Info("PostSDigitizer", "-> Task %s already exists",sdigitizer->GetName());
697     emcal->GetListOfTasks()->Remove(emcalsd) ;
698   }
699
700   emcal->Add(sdigitizer) ;      
701
702   return kTRUE; 
703 }
704
705 //____________________________________________________________________________ 
706
707 TObject ** AliEMCALGetter::SDigitizerRef(const char * name) const 
708 {  
709   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
710
711   if ( !sd ) {
712     Fatal("SDigitizerRef", "-> Task //%s/SDigitizer not found!", fTasksFolder);
713   }        
714
715   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
716
717   if ( !emcal )  {
718     Fatal("SDigitizerRef", "->  //%s/SDigitizer/EMCAL not found!", fTasksFolder);
719   }        
720
721   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
722
723   return emcal->GetListOfTasks()->GetObjectRef(task) ;
724 }
725
726 //____________________________________________________________________________ 
727
728 const Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const 
729 {  
730   //---------- SDigitizer -------------------------
731   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
732
733   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
734
735   if ( !sd ) {
736     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!", fTasksFolder);
737     return kFALSE ;
738   }        
739
740   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
741
742   if ( !emcal )  {
743     if (fDebug) {
744       Warning("PostSDigitizer", "->  //%s/SDigitizer/EMCAL/ not found!", fTasksFolder);
745
746       Info("PostSDigitizer", "-> Adding  //%s/SDigitizer/EMCAL", fTasksFolder);
747
748     }
749     emcal = new TTask("EMCAL", "") ; 
750     sd->Add(emcal) ; 
751   } 
752
753   TString sdname(name) ;
754   sdname.Append(":") ;
755   sdname.Append(file);
756   sdname.ReplaceAll("/","_") ; 
757   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname )); 
758
759   if (!emcalsd) {
760     emcalsd = new AliEMCALSDigitizer() ;  
761
762     //Note, we can not call constructor with parameters: it will call Getter and screw up everething
763
764     emcalsd->SetName(sdname) ;
765     emcalsd->SetTitle(file) ;
766     emcal->Add(emcalsd) ;       
767   }
768
769   return kTRUE; 
770 }
771
772 //____________________________________________________________________________ 
773
774 const Bool_t AliEMCALGetter::PostDigits(const char * name) const 
775 {  
776   //---------- Digits -------------------------
777   // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
778
779   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
780
781   if ( !emcalFolder ) {
782     if (fDebug) {
783       Warning("PostDigits", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
784       Info("PostDigits", "-> Adding Folder //%s/EMCAL/", fDigitsFolder);
785     }
786     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
787   }    
788
789   TObject*  dig = emcalFolder->FindObject( name ) ;
790
791   if ( !dig ) {
792     TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
793     digits->SetName(name) ;
794     emcalFolder->Add(digits) ;  
795   }
796
797   return kTRUE; 
798 }
799
800 //____________________________________________________________________________ 
801
802 TObject ** AliEMCALGetter::DigitsRef(const char * name) const 
803
804   //------- Digits ----------------------
805   // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
806
807   if ( !fDigitsFolder ) {
808     Fatal("DigitsRef", "-> Folder //%s not found!", fDigitsFolder);
809   }    
810
811   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ; 
812
813   if ( !emcalFolder ) {
814     Fatal("DigitsRef", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
815   }    
816
817   TObject * d = emcalFolder->FindObject(name) ;
818
819   if(!d) {
820     Fatal("DigitsRef", "-> object %s not found!", name);
821   }   
822
823   return emcalFolder->GetListOfFolders()->GetObjectRef(d) ;
824 }
825
826 //____________________________________________________________________________ 
827
828 const Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const
829 {  
830   //---------- Digitizer -------------------------
831
832   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
833
834   if ( !sd ) {
835     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
836     return kFALSE ;
837   }        
838
839   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
840
841   if ( !emcal )  {
842     if (fDebug) {
843       Warning("PostDigitizer", "->  //%s/Digitizer/EMCAL not found!", fTasksFolder);
844       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
845     }
846     emcal = new TTask("EMCAL", "") ; 
847     sd->Add(emcal) ; 
848   } 
849
850     AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
851
852     if (emcald) { 
853       emcald->Delete() ;
854       emcal->GetListOfTasks()->Remove(emcald) ;
855     }
856
857     emcal->Add(digitizer) ; 
858
859     return kTRUE; 
860 }  
861
862 //____________________________________________________________________________ 
863
864 const Bool_t AliEMCALGetter::PostDigitizer(const char * name) const 
865 {  
866   //---------- Digitizer -------------------------
867   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
868
869   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
870
871   if ( !d ) {
872
873     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
874     return kFALSE ;
875   }        
876
877   TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ; 
878
879   if ( !emcal )  {
880     if (fDebug) {
881       Warning("PostDigitizer", "-> //%s/Digitizer/EMCAL not found!", fTasksFolder);
882
883       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
884     }
885     emcal = new TTask("EMCAL", "") ; 
886     d->Add(emcal) ; 
887
888
889   AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ; 
890
891   if (!emcald) { 
892     emcald = new AliEMCALDigitizer() ;
893     emcald->SetName(fDigitsTitle) ;
894     emcald->SetTitle(fHeaderFile) ;
895     emcal->Add(emcald) ;
896   }
897
898   return kTRUE;  
899 }
900
901 //____________________________________________________________________________ 
902
903 TObject ** AliEMCALGetter::DigitizerRef(const char * name) const 
904 {  
905
906   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
907
908   if ( !sd ) {
909     Fatal("DigitizerRef", "-> Task //%s/Digitizer not found!", fTasksFolder->GetName());
910   }        
911
912   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
913
914   if ( !emcal )  {
915     Fatal("DigitizerRef", "->  //%s/Digitizer/EMCAL", fTasksFolder->GetName());
916   }        
917
918   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
919
920   return emcal->GetListOfTasks()->GetObjectRef(task) ;
921 }
922
923 //____________________________________________________________________________ 
924
925 const Bool_t AliEMCALGetter::PostRecPoints(const char * name) const 
926
927   // -------------- RecPoints -------------------------------------------
928   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
929   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
930
931   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
932
933   if ( !emcalFolder ) {
934     if (fDebug) {
935       Warning("PostRecPoints", "-> Folder //%s/EMCAL/ not found!", fRecoFolder);
936       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/", fRecoFolder);
937     }
938     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
939   }    
940
941   // Tower RecPoints 
942
943   TFolder * emcalRPoTowerFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TowerRecPoints")) ;
944
945   if ( !emcalRPoTowerFolder ) {
946     if (fDebug) {
947
948       Warning("PostRecPoints", "-> Folder //%s/EMCAL/TowerRecPoints/ not found!", fRecoFolder);
949       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/TowerRecPoints not found!", fRecoFolder);
950     }
951     emcalRPoTowerFolder = emcalFolder->AddFolder("TowerRecPoints", "Tower RecPoints from EMCAL") ;  
952   }    
953
954   TObject * erp = emcalFolder->FindObject( name ) ;
955
956   if ( !erp )   {
957     TObjArray * towerrp = new TObjArray(100) ;
958     towerrp->SetName(name) ;
959     emcalRPoTowerFolder->Add(towerrp) ;  
960   }
961
962   // Pre Shower RecPoints 
963
964   TFolder * emcalRPoPreShoFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("PreShowerRecPoints")) ;
965
966   if ( !emcalRPoPreShoFolder ) {
967     if (fDebug) {
968       Warning("PostRecPoints", "-> Folder //%s/EMCAL/PreShowerRecPoints/ not found!", fRecoFolder);
969       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/PreShowerRecPoints/", fRecoFolder);
970     }
971     emcalRPoPreShoFolder = emcalFolder->AddFolder("PreShowerRecPoints", "PreSho RecPoints from EMCAL") ;  
972   }    
973
974   TObject * crp =  emcalRPoPreShoFolder->FindObject( name ) ;
975
976   if ( !crp )   {
977     TObjArray * preshorp = new TObjArray(100) ;
978     preshorp->SetName(name) ;
979     emcalRPoPreShoFolder->Add(preshorp) ;  
980   }
981
982   return kTRUE; 
983 }
984
985 //____________________________________________________________________________ 
986
987 TObject ** AliEMCALGetter::TowerRecPointsRef(const char * name) const 
988
989   // -------------- RecPoints -------------------------------------------
990   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
991
992   if ( !fRecoFolder ) {
993     Fatal("TowerRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
994   }    
995
996   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
997
998   if ( !towerFolder ) {
999     Fatal("TowerRecPointsRef", "-> Folder //%s/EMCAL/TowerRecPoints/ not found!", fRecoFolder);
1000   }    
1001
1002   TObject * trp = towerFolder->FindObject(name ) ;
1003
1004   if ( !trp )   {
1005     Fatal("TowerRecPointsRef", "-> Object %s not found!", name);
1006   }
1007
1008   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
1009
1010
1011 //____________________________________________________________________________ 
1012
1013 TObject ** AliEMCALGetter::PreShowerRecPointsRef(const char * name) const 
1014
1015   // -------------- RecPoints -------------------------------------------
1016   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
1017
1018   if ( !fRecoFolder ) {
1019     Fatal("PreShowerRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
1020   }    
1021
1022   TFolder * preshoFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1023
1024   if ( !preshoFolder ) {
1025     Fatal("PreShowerRecPointsRef", "-> Folder //%s/EMCAL/PreShowerRecPoints/", fRecoFolder);
1026   }    
1027
1028
1029
1030   TObject * prp = preshoFolder->FindObject(name ) ;
1031
1032   if ( !prp )   {
1033     Fatal("PreShowerRecPointsRef", "-> Object %s not found!", name);
1034   }
1035
1036   return preshoFolder->GetListOfFolders()->GetObjectRef(prp) ;
1037
1038
1039 //____________________________________________________________________________ 
1040
1041 const Bool_t AliEMCALGetter::PostClusterizer(AliEMCALClusterizer * clu) const 
1042
1043   // ------------------ AliEMCALClusterizer ------------------------
1044   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1045
1046   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1047
1048   if ( !tasks ) {
1049     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder);
1050     return kFALSE ;
1051   }        
1052
1053   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1054
1055   if ( !emcal )  {
1056     if (fDebug) {
1057       Warning("PostClusterizer", "-> //%s/ReconstructionerEMCAL not found!", fTasksFolder);
1058       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1059     }
1060     emcal = new TTask("EMCAL", "") ; 
1061     tasks->Add(emcal) ; 
1062   } 
1063
1064   AliEMCALClusterizerv1 * emcalcl = dynamic_cast<AliEMCALClusterizerv1*>(emcal->GetListOfTasks()->FindObject(clu->GetName())) ; 
1065
1066   if (emcalcl) { 
1067     if (fDebug)
1068       Info("PostClusterizer", "-> Task %s already exists", clu->GetName());
1069     emcalcl->Delete() ; 
1070     emcal->GetListOfTasks()->Remove(emcalcl) ;
1071   }
1072   emcal->Add(clu) ;      
1073
1074   return kTRUE; 
1075
1076
1077 //____________________________________________________________________________ 
1078
1079 TObject ** AliEMCALGetter::ClusterizerRef(const char * name) const 
1080
1081   // ------------------ AliEMCALClusterizer ------------------------
1082
1083   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1084
1085   if ( !tasks ) {
1086     Fatal("ClusterizerRef", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1087   }        
1088
1089   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1090
1091   if ( !emcal )  {
1092     Fatal("ClusterizerRef", "-> //%s/Reconstructioner/EMCAL", fTasksFolder->GetName());
1093   }   
1094
1095   TList * l = emcal->GetListOfTasks() ; 
1096   TIter it(l) ;
1097   TTask * task ;
1098   TTask * clu = 0 ;
1099   TString cluname(name) ;
1100   cluname+=":clu-" ;
1101
1102   while((task = static_cast<TTask *>(it.Next()) )){
1103     TString taskname(task->GetName()) ;
1104     if(taskname.BeginsWith(cluname)){
1105       clu = task ;
1106       break ;
1107     }
1108   }
1109
1110   if(!clu) {
1111     Fatal("ClusterizerRef", "-> task %s not found!", task->GetName());
1112   }
1113
1114   return l->GetObjectRef(clu) ;
1115 }
1116
1117 //____________________________________________________________________________ 
1118
1119 const Bool_t AliEMCALGetter::PostClusterizer(const char * name) const 
1120
1121   // ------------------ AliEMCALClusterizer ------------------------
1122   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1123   
1124
1125   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1126
1127   if ( !tasks ) {
1128     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1129     return kFALSE ;
1130   }        
1131
1132   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1133
1134   if ( !emcal )  {
1135     if (fDebug) {
1136       Warning("PostClusterizer", "-> //%s/Reconstructioner/EMCAL not found!", fTasksFolder);
1137       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1138     }
1139     emcal = new TTask("EMCAL", "") ; 
1140     tasks->Add(emcal) ; 
1141   } 
1142
1143   TList * l = emcal->GetListOfTasks() ;   
1144   TIter it(l) ;
1145   TString clun(name) ;
1146   clun+=":clu" ; 
1147   TTask * task ;
1148
1149   while((task = static_cast<TTask *>(it.Next()) )){
1150     TString taskname(task->GetName()) ;
1151
1152     if(taskname.BeginsWith(clun))
1153       return kTRUE ;
1154   }
1155
1156   AliEMCALClusterizerv1 * emcalcl = new AliEMCALClusterizerv1() ;
1157
1158   clun+="-v1" ; 
1159   emcalcl->SetName(clun) ;
1160   emcalcl->SetTitle(fHeaderFile) ; 
1161   emcal->Add(emcalcl) ;
1162
1163   return kTRUE; 
1164 }
1165
1166 //____________________________________________________________________________ 
1167
1168 TTree * AliEMCALGetter::TreeK(TString filename)  
1169 {
1170   // returns TreeK from file filename
1171   // usefull in case of split file
1172
1173   if ( filename.IsNull() ) 
1174     filename = fHeaderFile ; 
1175
1176   TFile * file = 0 ; 
1177
1178   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1179
1180   if (!file || !file->IsOpen())  // file not yet open 
1181     file = TFile::Open(filename.Data(), "read") ; 
1182   
1183   if(filename != fHeaderFile ){
1184     fAlice = dynamic_cast<AliRun *>(file->Get("gAlice")) ;
1185   }
1186
1187   TString treeName("TreeK") ; 
1188   treeName += EventNumber()  ; 
1189   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1190
1191   if (!tree && fDebug)  
1192     Warning("TreeK", "-> %s not found in %s", treeName.Data(),filename.Data());
1193
1194   return tree ;                       
1195 }
1196
1197 //____________________________________________________________________________ 
1198
1199 TTree * AliEMCALGetter::TreeH(TString filename)  
1200 {
1201   // returns TreeH from file filename
1202   // usefull in case of split file
1203
1204   if ( filename.IsNull() ) 
1205     filename = fHeaderFile ; 
1206
1207   TFile * file = 0 ; 
1208   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1209
1210   if (!file) { // file not open yet
1211     file = TFile::Open(filename.Data(), "read") ; 
1212   }
1213
1214   TString treeName("TreeH") ; 
1215   treeName += EventNumber()  ; 
1216   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1217
1218   if (!tree && fDebug)  
1219     Warning("TreeH", "-> %s not found in %s", treeName.Data(), filename.Data());
1220   return tree ;                       
1221 }
1222
1223 //____________________________________________________________________________ 
1224
1225 TTree * AliEMCALGetter::TreeS(TString filename)  
1226 {
1227   // returns TreeS from file filename
1228   // usefull in case of split file
1229
1230   if ( filename.IsNull() ) 
1231     filename = fHeaderFile ; 
1232
1233   TFile * file = 0 ; 
1234   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1235
1236   if (!file) { // file not open yet
1237     file = TFile::Open(filename.Data(), "read") ; 
1238   }
1239
1240   TString treeName("TreeS") ; 
1241   treeName += EventNumber()  ; 
1242   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1243
1244   if (!tree && fDebug)  
1245     Warning("TreeS", "-> %s not found in %s", treeName.Data(), filename.Data());
1246   return tree ;                       
1247 }
1248
1249 //____________________________________________________________________________ 
1250
1251 TTree * AliEMCALGetter::TreeD(TString filename)  
1252 {
1253   // returns TreeD from file filename
1254   // usefull in case of split file
1255
1256   if ( filename.IsNull() ) 
1257     filename = fHeaderFile ; 
1258
1259   TFile * file = 0 ; 
1260   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1261
1262   if (!file) { // file not open yet
1263     file = TFile::Open(filename.Data(), "read") ; 
1264   }
1265
1266   TString treeName("TreeD") ; 
1267   treeName += EventNumber()  ; 
1268   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1269
1270   if (!tree && fDebug)  
1271     Warning("TreeD", "-> %s not found in %s", treeName.Data(), filename.Data());
1272   return tree ;                       
1273 }
1274
1275 //____________________________________________________________________________ 
1276
1277 const TParticle * AliEMCALGetter::Primary(Int_t index) const
1278 {
1279   // Return primary particle numbered by <index>
1280
1281   if(index < 0) 
1282     return 0 ;
1283
1284   TParticle *  p = 0 ;
1285     if (fAlice) 
1286       p = fAlice->Particle(index) ; 
1287     else
1288       p = gAlice->Particle(index) ; 
1289  
1290   return p ; 
1291 }
1292
1293 //____________________________________________________________________________ 
1294
1295 const TParticle * AliEMCALGetter::Secondary(TParticle* p, Int_t index) const
1296 {
1297   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
1298
1299   if(index <= 0) 
1300     return 0 ;
1301   if(index > 2)
1302     return 0 ;
1303
1304   if(p) {
1305     Int_t daughterIndex = p->GetDaughter(index-1) ; 
1306     return  gAlice->Particle(daughterIndex) ; 
1307   }
1308   else
1309     return 0 ;
1310 }
1311
1312 //____________________________________________________________________________ 
1313
1314 Int_t AliEMCALGetter::ReadTreeD(const Int_t event)
1315 {
1316   // Read the digit tree gAlice->TreeD()  
1317
1318   TTree * treeD ;
1319   if(fToSplit){
1320     TFile * file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName)); 
1321     if(!file) 
1322       file = TFile::Open(fDigitsFileName) ;      
1323
1324     // Get Digits Tree header from file
1325
1326     TString treeName("TreeD") ;
1327     treeName += event ; 
1328     treeD = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1329
1330     if(!treeD){ // TreeD not found in header file
1331       if (fDebug)
1332         Warning("ReadTreeD", "-> Cannot find TreeD in %s", fDigitsFileName.Data());
1333       return 1;
1334     }
1335   }
1336   else
1337     treeD = gAlice->TreeD() ;
1338
1339   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
1340   TIter next(lob) ; 
1341   TBranch * branch = 0 ; 
1342   TBranch * digitsbranch = 0 ; 
1343   TBranch * digitizerbranch = 0 ; 
1344
1345   Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
1346
1347   while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
1348     if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1349       digitsbranch = branch ; 
1350       emcalfound = kTRUE ;
1351     }
1352     else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1353       digitizerbranch = branch ; 
1354       digitizerfound = kTRUE ; 
1355     }
1356   }
1357
1358   if ( !emcalfound || !digitizerfound ) {
1359     if (fDebug)
1360       Warning("ReadTreeD", "-> Cannot find Digits and/or Digitizer with name %s", fDigitsTitle.Data());
1361     return 2; 
1362   }   
1363
1364   //read digits
1365
1366   if(!Digits(fDigitsTitle) ) 
1367     PostDigits(fDigitsTitle);
1368   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1369   digitsbranch->GetEntry(0) ;
1370
1371   // read  the Digitizer
1372
1373   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
1374   if(!Digitizer(fDigitsTitle))
1375     PostDigitizer(fDigitsTitle) ;
1376   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1377   digitizerbranch->GetEntry(0) ;
1378
1379   lob->Delete();
1380
1381   if(gAlice->TreeD()!=treeD)
1382     treeD->Delete();
1383
1384   return 0 ; 
1385 }
1386
1387 //____________________________________________________________________________ 
1388
1389 Int_t AliEMCALGetter::ReadTreeH()
1390 {
1391   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1392
1393   TTree * treeH = gAlice->TreeH() ;
1394
1395   if(!treeH) {// TreeH not found in header file
1396     if (fDebug) 
1397       Warning("ReadTreeH", "-> Cannot find TreeH in %s", fHeaderFile.Data());
1398
1399     TString searchFileName("EMCAL.HITS") ; 
1400     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
1401       searchFileName+="." ;
1402       searchFileName += fBranchTitle ;
1403     }
1404
1405     searchFileName+=".root" ;
1406
1407     if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
1408       if (fDebug) 
1409         Info("ReadTreeH", "-> TreeH found in %s", searchFileName.Data());
1410     } else {
1411       Error("ReadTreeH", "-> TreeH not found "); 
1412       return 1;
1413     }  
1414   }
1415
1416   TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
1417
1418   if ( !hitsbranch ) {
1419     if (fDebug)
1420       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1421     return 2;
1422   }
1423
1424   if(!Hits())
1425     PostHits() ;
1426
1427   if (hitsbranch->GetEntries() > 1 ) {
1428     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1429     TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000) ;
1430     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1431     hitsbranch->SetAddress(&tempo) ;
1432
1433     Int_t index = 0 ; 
1434     Int_t i = 0 ;
1435
1436     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1437       hitsbranch->GetEntry(i) ;
1438       Int_t j = 0 ; 
1439       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1440         const AliEMCALHit * hit = static_cast<const AliEMCALHit *>(tempo->At(j)) ; 
1441         new((*hits)[index]) AliEMCALHit( *hit ) ;
1442         index++ ; 
1443       }
1444     }
1445     delete tempo ; 
1446   }
1447   else {
1448     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1449     hitsbranch->SetAddress(HitsRef()) ;
1450     hitsbranch->GetEntry(0) ;
1451   }
1452   return 0 ; 
1453 }
1454
1455 //____________________________________________________________________________ 
1456
1457 void AliEMCALGetter::Track(const Int_t itrack)
1458 {
1459   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1460   if(gAlice->TreeH()== 0){
1461     Error("ReadTreeH", "-> Cannot read TreeH ");
1462     return ;
1463   }
1464
1465   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
1466
1467   if ( !hitsbranch ) {
1468     if (fDebug)
1469       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1470     return ;
1471   }  
1472
1473   if(!Hits())
1474     PostHits() ;
1475
1476   (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1477   hitsbranch->SetAddress(HitsRef()) ;
1478   hitsbranch->GetEntry(itrack) ;
1479 }
1480
1481 //____________________________________________________________________________ 
1482
1483 void AliEMCALGetter::ReadTreeQA()
1484 {
1485   if (fDebug)
1486     Warning("ReadTreeQA", "-> %s not implemented", ClassName());
1487 }
1488
1489   
1490
1491 //____________________________________________________________________________ 
1492
1493 Int_t AliEMCALGetter::ReadTreeR(const Int_t event)
1494
1495 {
1496   // Read the reconstrunction tree gAlice->TreeR()
1497   // A particularity has been introduced here :
1498   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
1499   //   being for example give in AliEMCALPID(fileName, title)
1500   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
1501   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
1502   // from a given set of TrackSegments (with a given name)
1503   // This is why any is NOT used to read the branch of RecParticles
1504   // any migh have become obsolete : to be checked
1505   // See AliEMCALPIDv1    
1506
1507   TTree * treeR ;
1508
1509   if(fToSplit){
1510     TFile * file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName)); 
1511     if(!file) 
1512       file = TFile::Open(fRecPointsFileName) ;      
1513     // Get Digits Tree header from file
1514
1515     TString treeName("TreeR") ;
1516     treeName += event ; 
1517     treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1518
1519     if(!treeR){ // TreeR not found in header file
1520       if (fDebug)
1521         Warning("ReadTreeD", "-> Cannot find TreeR in %s", fRecPointsFileName.Data());
1522       return 1;
1523     }
1524   }
1525   else
1526     treeR = gAlice->TreeR() ;
1527
1528   // RecPoints 
1529
1530   TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
1531   TIter next(lob) ; 
1532   TBranch * branch = 0 ; 
1533   TBranch * towerbranch = 0 ; 
1534   TBranch * preshowerbranch = 0 ; 
1535   TBranch * clusterizerbranch = 0 ; 
1536
1537   Bool_t emcalTowerRPfound = kFALSE, emcalPreShoRPfound = kFALSE, clusterizerfound = kFALSE ; 
1538
1539   while ( (branch = static_cast<TBranch*>(next())) && (!emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) ) {
1540     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
1541       if ( strcmp(branch->GetName(), "EMCALTowerRP")==0) {
1542         towerbranch = branch ; 
1543         emcalTowerRPfound = kTRUE ;
1544       }
1545       else if ( strcmp(branch->GetName(), "EMCALPreShoRP")==0) {
1546         preshowerbranch = branch ; 
1547         emcalPreShoRPfound = kTRUE ;
1548       }
1549       else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
1550         clusterizerbranch = branch ; 
1551         clusterizerfound = kTRUE ; 
1552       }
1553     }
1554   }
1555
1556   if ( !emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) {
1557     if (fDebug)
1558       Warning("ReadTreeR", "-> Cannot find RecPoints and/or Clusterizer with name %s", fRecPointsTitle.Data());
1559   } 
1560   else { 
1561     if(!TowerRecPoints(fRecPointsTitle) ) 
1562       PostRecPoints(fRecPointsTitle) ;
1563     towerbranch->SetAddress(TowerRecPointsRef(fRecPointsTitle)) ;
1564     towerbranch->GetEntry(0) ;
1565
1566     preshowerbranch->SetAddress(PreShowerRecPointsRef(fRecPointsTitle)) ; 
1567     preshowerbranch->GetEntry(0) ;  
1568
1569     if(!Clusterizer(fRecPointsTitle) )
1570       PostClusterizer(fRecPointsTitle) ;
1571
1572     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1573     clusterizerbranch->GetEntry(0) ;
1574   }
1575
1576   if(gAlice->TreeR()!=treeR)
1577     treeR->Delete();
1578   return 0 ; 
1579 }
1580
1581 //____________________________________________________________________________ 
1582
1583 Int_t AliEMCALGetter::ReadTreeS(const Int_t event)
1584 {
1585   // Reads the SDigits treeS from all files  
1586   // Files, which should be opened are listed in emcalF
1587   // So, first get list of files
1588
1589   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
1590
1591   if (!emcalF) 
1592     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1593
1594   TCollection * folderslist = emcalF->GetListOfFolders() ; 
1595
1596   // Now iterate over the list of files and read TreeS into Whiteboard
1597
1598   TIter next(folderslist) ; 
1599   TFolder * folder = 0 ; 
1600   TFile * file; 
1601   TTree * treeS = 0;
1602
1603   while ( (folder = static_cast<TFolder*>(next())) ) {
1604     TString fileName("") ;
1605     if(fToSplit)
1606       fileName = folder->GetTitle() ;
1607     else
1608       fileName = folder->GetName() ; 
1609
1610     fileName.ReplaceAll("_","/") ; 
1611     file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1612
1613     if(!file) 
1614       file = TFile::Open(fileName) ;      
1615
1616     // Get SDigits Tree header from file
1617
1618     TString treeName("TreeS") ;
1619     treeName += event ; 
1620     treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1621
1622     if(!treeS){ // TreeS not found in header file
1623       if (fDebug)
1624         Warning("ReadTreeS", "-> Cannot find TreeS in %s", fileName.Data());
1625       return 1;
1626     }
1627
1628     //set address of the SDigits and SDigitizer
1629
1630     TBranch   * sdigitsBranch    = 0;
1631     TBranch   * sdigitizerBranch = 0;
1632     TBranch   * branch           = 0 ;  
1633     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1634     TIter next(lob) ; 
1635
1636     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1637
1638     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
1639       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1640         emcalfound = kTRUE ;
1641         sdigitsBranch = branch ; 
1642       }
1643       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && 
1644                 (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1645         sdigitizerfound = kTRUE ; 
1646         sdigitizerBranch = branch ;
1647       }
1648     }
1649     if ( !emcalfound || !sdigitizerfound ) {
1650       if (fDebug)
1651         Warning("ReadSDigits", "-> Digits and/or Digitizer branch with name %s not found", GetName());
1652       return 2; 
1653     }   
1654
1655     if ( !folder->FindObject(fSDigitsTitle) )  
1656       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1657
1658     ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
1659
1660     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1661     sdigitsBranch->GetEntry(0) ;
1662
1663     TString sdname(fSDigitsTitle) ;
1664     sdname+=":" ;
1665     sdname+=folder->GetName() ;
1666
1667     if(!SDigitizer(sdname) ) 
1668       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1669
1670     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1671     sdigitizerBranch->GetEntry(0) ; 
1672
1673     if(gAlice->TreeS()!=treeS)
1674       treeS->Delete();
1675   }    
1676    return 0 ;  
1677 }
1678
1679 //____________________________________________________________________________ 
1680
1681 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
1682 {  
1683   // Read the summable digits fron treeS()  
1684
1685   TString filename("mergefile") ;
1686   filename+= input ;
1687
1688   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
1689   if ( !emcalFolder ) { 
1690     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1691   } 
1692
1693   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
1694
1695   //set address of the SDigits and SDigitizer
1696
1697   TBranch   * sdigitsBranch    = 0;
1698   TBranch   * sdigitizerBranch = 0;
1699   TBranch   * branch           = 0 ;  
1700   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1701   TIter next(lob) ; 
1702
1703   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1704
1705   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
1706     if ( strcmp(branch->GetName(), "EMCAL")==0) {
1707       emcalfound = kTRUE ;
1708       sdigitsBranch = branch ; 
1709     }
1710     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
1711       sdigitizerfound = kTRUE ; 
1712       sdigitizerBranch = branch ;
1713     }
1714   }
1715
1716   if ( !emcalfound || !sdigitizerfound ) {
1717     if (fDebug)
1718       Warning("ReadTreeS", "-> Digits and/or Digitizer branch not found");
1719     return ; 
1720   }   
1721
1722   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1723     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1724
1725   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1726   sdigitsBranch->GetEntry(0) ;
1727
1728   TString sdname(sdigitsBranch->GetTitle()) ;
1729   sdname+=":" ;
1730   sdname+=filename ;
1731
1732   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1733     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1734
1735   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1736   sdigitizerBranch->GetEntry(0) ;
1737
1738   if(gAlice->TreeS()!=treeS)
1739     treeS->Delete();
1740 }    
1741
1742 //____________________________________________________________________________ 
1743
1744 void AliEMCALGetter::ReadPrimaries()
1745 {
1746
1747   // Reads specific branches of primaries
1748
1749   TClonesArray * ar = 0  ; 
1750
1751   if(! (ar = Primaries()) ) { 
1752     PostPrimaries() ;
1753     ar = Primaries() ; 
1754   }
1755
1756   ar->Delete() ; 
1757
1758   if (TreeK(fHeaderFile)) { // treeK found in header file
1759     if (fDebug) 
1760       Info("ReadPrimaries", "-> TreeK found in %s", fHeaderFile.Data());
1761     fNPrimaries = gAlice->GetNtrack() ; 
1762     fAlice = 0 ; 
1763   } 
1764   else { // treeK not found in header file
1765     Error("ReadPrimaries", "-> TreeK not  found ");
1766     return ;
1767   }
1768
1769   Int_t index = 0 ; 
1770
1771   for (index = 0 ; index < fNPrimaries; index++) { 
1772     new ((*ar)[index]) TParticle(*(Primary(index)));
1773   }
1774 }
1775
1776 //____________________________________________________________________________ 
1777
1778 void AliEMCALGetter::Event(const Int_t event, const char* opt)
1779 {
1780   // Reads the content of all Tree's S, D and R
1781
1782   if (event >= gAlice->TreeE()->GetEntries() ) {
1783     Error("Event", "-> %d not found in TreeE!", event);
1784     return ; 
1785   }
1786
1787   Bool_t any = kFALSE ; 
1788
1789   if (strstr(opt,"A") ) // do not check the title of the branches
1790     any = kTRUE; 
1791
1792   gAlice->GetEvent(event) ; 
1793
1794   if( strstr(opt,"R") )
1795     ReadTreeR(event) ;
1796
1797   if( strstr(opt,"D") )
1798     ReadTreeD(event) ;
1799
1800   if(strstr(opt,"S") )
1801     ReadTreeS(event) ;
1802
1803   if(strstr(opt,"H") )
1804     ReadTreeH() ;
1805
1806   if( strstr(opt,"Q") )
1807     ReadTreeQA() ;
1808
1809   if( strstr(opt,"P") )
1810     ReadPrimaries() ;
1811 }
1812
1813 //____________________________________________________________________________ 
1814
1815 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
1816 {
1817   // get the object named "what" from the folder
1818   // folders are named like //Folders
1819
1820   if ( file.IsNull() ) 
1821     file = fHeaderFile ; 
1822
1823   TFolder * folder = 0 ;
1824   TObject * emcalO  = 0 ; 
1825
1826   if ( what.CompareTo("Primaries") == 0 ) {
1827     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
1828     if (folder) 
1829       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
1830     else 
1831       return 0 ; 
1832   }
1833   else if ( what.CompareTo("Hits") == 0 ) {
1834     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
1835     if (folder) 
1836       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
1837   }
1838   else if ( what.CompareTo("SDigits") == 0 ) { 
1839     file.ReplaceAll("/","_") ; 
1840     TString path = "EMCAL/" + file  ; 
1841     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
1842     if (folder) { 
1843       if (name.IsNull())
1844         name = fSDigitsTitle ; 
1845       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1846     }
1847   }
1848   else if ( what.CompareTo("Digits") == 0 ){
1849     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
1850     if (folder) { 
1851       if (name.IsNull())
1852         name = fDigitsTitle ; 
1853       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1854     } 
1855   }
1856   else if ( what.CompareTo("TowerRecPoints") == 0 ) {
1857     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
1858     if (folder) { 
1859       if (name.IsNull())
1860         name = fRecPointsTitle ; 
1861       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1862     } 
1863   }
1864   else if ( what.CompareTo("PreShowerRecPoints") == 0 ) {
1865     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1866     if (folder) { 
1867       if (name.IsNull())
1868         name = fRecPointsTitle ; 
1869       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1870     }   
1871   }
1872
1873   if (!emcalO) {
1874     if(fDebug)
1875       Warning("ReturnO", "-> Object %s  not found in %s", what.Data(), folder->GetName());
1876     return 0 ;
1877   }
1878
1879   return emcalO ;
1880 }
1881
1882 //____________________________________________________________________________ 
1883
1884 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
1885 {
1886   // get the TTask named "what" from the folder
1887   // folders are named like //Folders/Tasks/what/EMCAL/name
1888
1889   TString search(what) ; 
1890   if ( what.CompareTo("Clusterizer") == 0 ) 
1891     search = "Reconstructioner" ; 
1892   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
1893     search = "Reconstructioner" ; 
1894   else if ( what.CompareTo("PID") == 0 ) 
1895     search = "Reconstructioner" ; 
1896   else if ( what.CompareTo("QATasks") == 0 ) 
1897     search = "QA" ; 
1898   
1899   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
1900
1901   if (!tasks) {
1902     Error("AliReturnT", "-> Task %s not found!", what.Data());
1903     return 0 ; 
1904   }
1905
1906   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1907
1908   if (!emcalT) { 
1909     Error("ReturnT", "-> Task %s/EMCAL not found!", what.Data());
1910     return 0 ; 
1911   }
1912
1913   TList * list = emcalT->GetListOfTasks() ; 
1914
1915   if (what.CompareTo("SDigitizer") == 0) {  
1916     if ( name.IsNull() )
1917       name =  fSDigitsTitle ; 
1918   }
1919   else  if (what.CompareTo("Digitizer") == 0){ 
1920     if ( name.IsNull() )
1921       name =  fDigitsTitle ;
1922   }
1923   else  if (what.CompareTo("Clusterizer") == 0){ 
1924     if ( name.IsNull() )
1925       name =  fRecPointsTitle ;
1926     name.Append(":clu") ;
1927   }
1928
1929   TIter it(list) ;
1930   TTask * task = 0 ; 
1931
1932   while((task = static_cast<TTask *>(it.Next()) )){
1933     TString taskname(task->GetName()) ;
1934     if(taskname.BeginsWith(name)){
1935     return task ;}
1936   }
1937
1938   if(fDebug)
1939     Warning("ReturnT", "-> Task %s/%s not found!", search.Data(), name.Data());
1940   return 0 ;
1941 }
1942
1943 //____________________________________________________________________________ 
1944
1945 void AliEMCALGetter::RemoveTask(TString opt, TString name) const 
1946
1947 {
1948   // remove a task from the folder
1949   // path is fTasksFolder/SDigitizer/EMCAL/name
1950
1951   TTask * task  = 0 ; 
1952   TTask * emcal = 0 ; 
1953   TList * lofTasks = 0 ; 
1954
1955   if (opt == "S") { // SDigitizer
1956     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
1957     if (!task) 
1958       return ; 
1959   } 
1960   else if (opt == "D") { // Digitizer
1961     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
1962     if (!task) 
1963       return ; 
1964   }
1965   else if (opt == "C") { // Clusterizer
1966     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
1967     if (!task) 
1968       return ; 
1969   }
1970   else {
1971     Warning("RemoveTask", "-> Unknown option %s");
1972     return ; 
1973   }    
1974
1975   emcal =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
1976
1977   if (!emcal)
1978     return ; 
1979
1980   lofTasks = emcal->GetListOfTasks() ;
1981
1982   if (!lofTasks) 
1983     return ; 
1984
1985   TObject * obj = lofTasks->FindObject(name) ; 
1986   if (obj) 
1987
1988     lofTasks->Remove(obj) ;
1989 }
1990
1991 //____________________________________________________________________________ 
1992
1993 void AliEMCALGetter::RemoveObjects(TString opt, TString name) const 
1994 {
1995   // remove SDigits from the folder
1996   // path is fSDigitsFolder/fHeaderFileName/name
1997
1998   TFolder * emcal     = 0 ; 
1999   TFolder * emcalmain = 0 ; 
2000
2001   if (opt == "H") { // Hits
2002     emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2003     if (!emcal) 
2004       return ;
2005     name = "Hits" ; 
2006   }
2007   else if ( opt == "S") { // SDigits
2008     emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2009     if (!emcalmain) 
2010       return ;
2011     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2012     if (!emcal) 
2013       return ;
2014   }
2015   else if (opt == "D") { // Digits
2016     emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2017     if (!emcal) 
2018       return ;
2019   }
2020   else if (opt == "RT") { // Tower RecPoints
2021     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2022     if (!emcal) 
2023       return ;
2024   }
2025   else if (opt == "RP") { // Preshower RecPoints
2026     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2027     if (!emcal) 
2028       return ;
2029   }
2030   else if (opt == "T") { // TrackSegments
2031     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2032     if (!emcal) 
2033       return ;
2034   }
2035   else if (opt == "P") { // RecParticles
2036     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2037     if (!emcal) 
2038       return ;
2039   }
2040   else {
2041     Warning("RemoveObjects", "-> Unknown option %s", opt.Data());
2042     return ; 
2043   }
2044
2045   TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject(name)) ; 
2046
2047   if (ar) { 
2048     emcal->Remove(ar) ;
2049     ar->Delete() ; 
2050     delete ar ; 
2051   }
2052
2053   if (opt == "S") 
2054     emcalmain->Remove(emcal) ; 
2055 }
2056
2057 //____________________________________________________________________________ 
2058
2059 void AliEMCALGetter::RemoveSDigits() const 
2060 {
2061   TFolder * emcal= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2062
2063   if (!emcal) 
2064     return ;
2065
2066   emcal->SetOwner() ; 
2067   emcal->Clear() ; 
2068 }
2069
2070 //____________________________________________________________________________ 
2071
2072 void AliEMCALGetter::CleanWhiteBoard(void){
2073
2074   TFolder * emcalmain = 0 ; 
2075   TFolder * emcal ;
2076   TObjArray * ar ;
2077   TList * lofTasks = 0 ; 
2078   TTask * task = 0 ; 
2079   TTask * emcalt = 0 ; 
2080
2081   // Hits  
2082
2083   emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2084
2085   if (emcal){  
2086     TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject("Hits")) ; 
2087     if (ar) { 
2088       emcal->Remove(ar) ;
2089       ar->Delete() ; 
2090       delete ar ; 
2091     }
2092   }
2093
2094   // SDigits
2095
2096   emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2097
2098   if (emcalmain){ 
2099     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2100     if (emcal) {
2101       ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fSDigitsTitle)) ; 
2102       if (ar) { 
2103         emcal->Remove(ar) ;
2104         ar->Delete() ; 
2105         delete ar ; 
2106       }
2107     }
2108     emcalmain->Remove(emcal) ; 
2109   }
2110
2111   // Digits
2112
2113   emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2114
2115   if (emcal){ 
2116     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fDigitsTitle)) ; 
2117     if (ar) { 
2118       emcal->Remove(ar) ;
2119       ar->Delete() ; 
2120       delete ar ; 
2121     }
2122   }
2123
2124   // TowerRecPoints
2125
2126   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2127
2128   if (emcal){ 
2129     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2130     if (ar) { 
2131       emcal->Remove(ar) ;
2132       ar->Delete() ; 
2133       delete ar ; 
2134     }
2135   }
2136
2137   // PreShowerRecPoints
2138
2139   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2140
2141   if (emcal){ 
2142     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2143     if (ar) { 
2144       emcal->Remove(ar) ;
2145       ar->Delete() ; 
2146       delete ar ; 
2147     }
2148   }  
2149
2150   // TrackSegments
2151
2152   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2153
2154   if (emcal) { 
2155     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fTrackSegmentsTitle)) ; 
2156     if (ar) { 
2157       emcal->Remove(ar) ;
2158       ar->Delete() ; 
2159       delete ar ; 
2160     }
2161   }
2162
2163   // RecParticles
2164
2165   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2166
2167   if (emcal){ 
2168     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecParticlesTitle)) ; 
2169     if (ar) { 
2170       emcal->Remove(ar) ;
2171       ar->Delete() ; 
2172       delete ar ; 
2173     }
2174   }
2175
2176   //---- Now Tasks ----------- 
2177
2178   TObject * obj ;
2179   TString sdname(fSDigitsTitle);
2180
2181   // Digitizer
2182
2183   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2184
2185   if (task){ 
2186     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2187     if (emcalt){
2188       lofTasks = emcalt->GetListOfTasks() ;
2189       if (lofTasks){ 
2190         obj = lofTasks->FindObject(sdname.Data()) ; 
2191         if (obj) 
2192           lofTasks->Remove(obj) ;
2193       }
2194     }      
2195   }
2196
2197   sdname.Append(":") ;
2198
2199   // Clusterizer, TrackSegmentMaker, PID
2200
2201   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2202
2203   if (task){ 
2204     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2205     if (emcalt){
2206       lofTasks = emcalt->GetListOfTasks() ;
2207       TIter next(lofTasks);
2208       while((obj=next())){ 
2209         TString oname(obj->GetName()) ;
2210         if (oname.BeginsWith(sdname)){ 
2211           lofTasks->Remove(obj) ;
2212         }
2213       }
2214     }  
2215   }
2216
2217   // SDigitizer
2218
2219   sdname.Append(fHeaderFile) ;
2220   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2221
2222   if (task) {
2223     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2224     if (emcalt){
2225       lofTasks = emcalt->GetListOfTasks() ;
2226       if (lofTasks){ 
2227         obj = lofTasks->FindObject(sdname.Data()) ; 
2228         if (obj) 
2229           lofTasks->Remove(obj) ;
2230       }
2231     }
2232   }  
2233 }
2234
2235 //____________________________________________________________________________ 
2236
2237 void AliEMCALGetter::SetTitle(const char * branchTitle ) 
2238
2239 {
2240   fBranchTitle        = branchTitle ;
2241   fSDigitsTitle       = branchTitle ; 
2242   fDigitsTitle        = branchTitle ; 
2243   fRecPointsTitle     = branchTitle ; 
2244   fRecParticlesTitle  = branchTitle ; 
2245   fTrackSegmentsTitle = branchTitle ; 
2246
2247   if(fToSplit){
2248
2249     //First - extract full path if necessary
2250
2251     TString sFileName(fHeaderFile) ;
2252     Ssiz_t islash = sFileName.Last('/') ;
2253
2254     if(islash<sFileName.Length())
2255       sFileName.Remove(islash+1,sFileName.Length()) ;
2256     else
2257       sFileName="" ;
2258
2259     //Now construct file names
2260
2261     fSDigitsFileName       = sFileName ;
2262     fDigitsFileName        = sFileName ; 
2263     fRecPointsFileName     = sFileName ; 
2264     fRecParticlesFileName  = sFileName ; 
2265     fTrackSegmentsFileName = sFileName ; 
2266     fSDigitsFileName      += "EMCAL.SDigits." ;
2267     fDigitsFileName       += "EMCAL.Digits." ; 
2268     fRecPointsFileName    += "EMCAL.RecData." ; 
2269     fTrackSegmentsFileName+= "EMCAL.RecData." ; 
2270     fRecParticlesFileName += "EMCAL.RecData." ; 
2271
2272     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
2273       fSDigitsFileName      += fBranchTitle ;
2274       fSDigitsFileName      += "." ;
2275       fDigitsFileName       += fBranchTitle ; 
2276       fDigitsFileName       += "." ; 
2277       fRecPointsFileName    += fBranchTitle ; 
2278       fRecPointsFileName    += "." ; 
2279       fRecParticlesFileName += fBranchTitle ; 
2280       fRecParticlesFileName += "." ; 
2281       fTrackSegmentsFileName+= fBranchTitle ; 
2282       fTrackSegmentsFileName+= "." ; 
2283     }
2284
2285     fSDigitsFileName      += "root" ;
2286     fDigitsFileName       += "root" ; 
2287     fRecPointsFileName    += "root" ; 
2288     fRecParticlesFileName += "root" ; 
2289     fTrackSegmentsFileName+= "root" ; 
2290   }
2291   else{
2292     fSDigitsFileName       = "" ; 
2293     fDigitsFileName        = "" ; 
2294     fRecPointsFileName     = "" ; 
2295     fRecParticlesFileName  = "" ; 
2296     fTrackSegmentsFileName = "" ; 
2297   }
2298
2299   TFolder * emcalFolder ; 
2300   emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
2301
2302   if ( !emcalFolder ) 
2303     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
2304
2305   emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2306
2307   if ( !emcalFolder ) 
2308     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2309
2310   //Make folder for SDigits
2311
2312   TString subdir(fHeaderFile) ;
2313   subdir.ReplaceAll("/","_") ;
2314
2315   emcalFolder->AddFolder(subdir, fSDigitsFileName.Data());
2316   emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2317
2318   if ( !emcalFolder ) 
2319     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
2320
2321   emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2322
2323   if ( !emcalFolder )
2324     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2325 }
2326
2327 //____________________________________________________________________________ 
2328
2329 void AliEMCALGetter::CloseSplitFiles(void){
2330
2331   TFile * file ;
2332   file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
2333
2334   if(file)
2335     file->Close() ;
2336
2337   file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
2338
2339   if(file)
2340     file->Close() ;
2341
2342   file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
2343
2344   if(file)
2345     file->Close() ;
2346
2347   file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
2348
2349   if(file)
2350     file->Close() ;
2351
2352   file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
2353
2354   if(file)
2355     file->Close() ;
2356 }
2357
2358
2359
2360
2361
2362