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