]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
Splitting loader class to have proper debug messages
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.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 //_________________________________________________________________________
19 //  A singleton. This class should be used in the analysis stage to get 
20 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21 //  instead of directly reading them from galice.root file. This container 
22 //  ensures, that one reads Digits, made of these particular digits, RecPoints, 
23 //  made of these particular RecPoints, TrackSegments and RecParticles. 
24 //  This becomes non trivial if there are several identical branches, produced with
25 //  different set of parameters. 
26 //
27 //  An example of how to use (see also class AliEMCALAnalyser):
28 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
29 //     AliEMCALRecParticle * part = gime->RecParticle(1) ;
30 //     ................
31 //  please->GetEvent(event) ;    // reads new event from galice.root
32 //                  
33 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
34 //*--         Completely redesigned by Dmitri Peressounko March 2001  
35 //
36 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
37 //*--         systematic usage of TFolders without changing the interface        
38 //////////////////////////////////////////////////////////////////////////////
39
40
41 // --- ROOT system ---
42
43 #include "TTree.h"
44
45 // --- Standard library ---
46
47 // --- AliRoot header files ---
48 #include "AliEMCAL.h"
49 #include "AliEMCALGetter.h"
50 #include "AliEMCALHit.h"
51 #include "AliEMCALLoader.h"
52 #include "AliLog.h"
53 #include "AliObjectLoader.h"
54
55 ClassImp(AliEMCALLoader)
56   
57   
58 const TString AliEMCALLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event
59 const TString AliEMCALLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray 
60 const TString AliEMCALLoader::fgkDigitsName("DIGITS");//Name for TClonesArray 
61 const TString AliEMCALLoader::fgkECARecPointsName("ECARECPOINTS");//Name for TClonesArray 
62 const TString AliEMCALLoader::fgkTracksName("TRACKS");//Name for TClonesArray 
63 const TString AliEMCALLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray
64
65 const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
66 const TString AliEMCALLoader::fgkTrackSegmentsBranchName("EMCALTS");//Name for branch with TrackSegments
67 const TString AliEMCALLoader::fgkRecParticlesBranchName("EMCALRP");//Name for branch with Reconstructed Particles
68
69 //____________________________________________________________________________ 
70 AliEMCALLoader::AliEMCALLoader()
71 {
72   fDebug = 0;
73   fRecParticlesLoaded = kFALSE;
74 }
75
76 //____________________________________________________________________________ 
77 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
78   AliLoader(detname,eventfoldername)
79 {
80   fDebug=0;
81   fRecParticlesLoaded = kFALSE;
82 }
83
84 //____________________________________________________________________________ 
85 AliEMCALLoader::~AliEMCALLoader()
86 {
87   //remove and delete arrays
88   Clean(fgkHitsName);
89   Clean(fgkSDigitsName);
90   Clean(fgkDigitsName);
91   Clean(fgkECARecPointsName);
92   Clean(fgkTracksName);
93   Clean(fgkRecParticlesName);
94   CleanFolders() ; 
95  // set to 0x0 the objgetter in AliGetter ... weird isn it !
96   /* 
97   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
98   if (gime) 
99     gime->Reset() ;
100   */
101 }
102
103 //____________________________________________________________________________ 
104 void AliEMCALLoader::CleanFolders()
105 {
106   CleanRecParticles();
107   AliLoader::CleanFolders();
108 }
109
110 //____________________________________________________________________________ 
111 Int_t AliEMCALLoader::SetEvent()
112 {
113   //Cleans loaded stuff and and sets Files and Directories
114   // do not post any data to folder/tasks
115
116   
117   Int_t retval = AliLoader::SetEvent();
118   if (retval)
119    {
120      Error("SetEvent","AliLoader::SetEvent returned error");
121      return retval;
122    }
123
124
125   if (Hits()) Hits()->Clear();
126   if (SDigits()) SDigits()->Clear();
127   if (Digits()) Digits()->Clear();
128   if (ECARecPoints()) ECARecPoints()->Clear();
129   if (TrackSegments()) TrackSegments()->Clear();
130   if (RecParticles()) RecParticles()->Clear();
131    
132   return 0;
133 }
134
135 //____________________________________________________________________________ 
136 Int_t AliEMCALLoader::GetEvent()
137 {
138   //Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method
139   //to add Rec Particles specific for EMCAL
140   
141   //First call the original method to get whatever from std. setup is needed
142   Int_t retval;
143   
144   retval = AliLoader::GetEvent();
145   if (retval)
146     {
147       Error("GetEvent","AliLoader::GetEvent returned error");
148       return retval;
149     }
150   
151   if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits();
152   if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits();
153   if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits();
154   if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints();
155   if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks();
156   if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles();
157
158
159   //Now, check if RecPart were loaded  
160   return 0;
161 }
162
163 //____________________________________________________________________________ 
164 const AliEMCAL * AliEMCALLoader::EMCAL() 
165 {
166   // returns the EMCAL object 
167   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(GetModulesFolder()->FindObject(fDetectorName));
168   if ( emcal == 0x0) 
169     if (fDebug)
170       cout << "WARNING: AliEMCALLoader::EMCAL -> EMCAL module not found in Folders" << endl ; 
171   return emcal ; 
172 }  
173
174 //____________________________________________________________________________ 
175 const AliEMCALGeometry * AliEMCALLoader::EMCALGeometry() 
176 {
177   // Gets the EMCAL Geometry object 
178   AliEMCALGeometry * rv = 0 ; 
179   if (EMCAL() )
180     rv =  EMCAL()->GetGeometry();
181   return rv ; 
182
183
184 //____________________________________________________________________________ 
185 Int_t AliEMCALLoader::LoadHits(Option_t* opt)
186 {  
187   //------- Hits ----------------------
188   //Overload (extends) LoadHits implemented in AliLoader
189   //
190   Int_t res;
191   
192   //First call the AliLoader's method to send the TreeH to folder
193   res = AliLoader::LoadHits(opt);
194   
195   if (res)
196    {//oops, error
197      AliError("returned error");
198      return res;
199    }
200
201   //read the data from tree in folder and send it to folder
202   res = ReadHits();
203   return 0;
204 }
205
206 //____________________________________________________________________________ 
207 Int_t AliEMCALLoader::LoadSDigits(Option_t* opt)
208 {  
209   // Loads the SDigits array in the folder structure
210   Int_t res;
211   //First call the AliLoader's method to send the TreeS to folder
212   res = AliLoader::LoadSDigits(opt);
213   if (res)
214     {//oops, error
215       Error("PostSDigits","AliLoader::LoadSDigits returned error");
216       return res;
217     }
218   return ReadSDigits();
219   
220
221
222 //____________________________________________________________________________ 
223 Int_t AliEMCALLoader::LoadDigits(Option_t* opt)
224
225   // Loads the Digits array in the folder structure
226   
227   Int_t res;
228   //First call the AliLoader's method to send the TreeS to folder
229   res = AliLoader::LoadDigits(opt);
230   if (res)
231     {//oops, error
232       Error("LoadDigits","AliLoader::LoadDigits returned error");
233       return res;
234     }
235   return ReadDigits();
236 }
237
238 //____________________________________________________________________________ 
239 Int_t AliEMCALLoader::LoadRecPoints(Option_t* opt) 
240
241   // Loads the RecPoints array in the folder structure
242   Int_t res;
243   //First call the AliLoader's method to send the TreeR to folder
244   res = AliLoader::LoadRecPoints(opt);
245   if (res)
246     {//oops, error
247       Error("LoadRecPoints","AliLoader::LoadRecPoints returned error");
248       return res;
249     }
250   
251   TFolder * emcalFolder = GetDetectorDataFolder();
252   if ( emcalFolder  == 0x0 ) 
253     {
254       Error("LoadRecPoints","Can not get detector data folder");
255       return 1;
256     }
257   return ReadRecPoints();
258 }
259
260 //____________________________________________________________________________ 
261 Int_t  AliEMCALLoader::LoadTracks(Option_t* opt)
262 {
263   //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts
264   AliDebug(1, Form("opt = %s",opt));
265   Int_t res;
266   res = AliLoader::LoadTracks(opt);
267   if (res)
268     {//oops, error
269       AliError("returned error");
270       return res;
271     }  
272   return ReadTracks();
273   
274 }
275
276 //____________________________________________________________________________ 
277 Int_t AliEMCALLoader::LoadRecParticles(Option_t* opt) 
278
279   // Loads the RecParticles array in the folder structure
280   Int_t res;
281   //First call the AliLoader's method to send the TreeS to folder
282   res = AliLoader::LoadRecParticles(opt);
283   if (res)
284     {//oops, error
285       Error("LoadRecParticles","AliLoader::LoadRecParticles returned error");
286       return res;
287     }
288   
289   TFolder * emcalFolder = GetDetectorDataFolder();
290   if ( emcalFolder  == 0x0 ) 
291     {
292       Error("PostDigits","Can not get detector data folder");
293       return 1;
294     }
295   return ReadRecParticles();
296 }
297
298 //____________________________________________________________________________ 
299 Int_t AliEMCALLoader::PostHits()
300 {
301   // Post Hits
302   Int_t reval = AliLoader::PostHits();
303   if (reval)
304     {
305      Error("PostHits","AliLoader::  returned error");
306      return reval;
307     }
308   return ReadHits();
309 }
310
311 //____________________________________________________________________________ 
312 Int_t AliEMCALLoader::PostSDigits()
313 {
314   // Posts the SDigits array to the folder structure
315   Int_t reval = AliLoader::PostSDigits();
316   if (reval)
317    {
318      Error("PostSDigits","AliLoader::PostSDigits  returned error");
319      return reval;
320    }
321   return ReadSDigits();
322 }
323
324 //____________________________________________________________________________ 
325 Int_t AliEMCALLoader::PostDigits()
326 {
327   // Posts the Digits array to the folder structure
328   Int_t reval = AliLoader::PostDigits();
329   if (reval)
330     {
331       Error("PostDigits","AliLoader::PostDigits  returned error");
332       return reval;
333     }
334   return ReadDigits();
335 }
336
337 //____________________________________________________________________________ 
338 Int_t AliEMCALLoader::PostRecPoints()
339 {
340   // Posts the RecPoints array to the folder structure
341   Int_t reval = AliLoader::PostRecPoints();
342   if (reval)
343    {
344      Error("PostRecPoints","AliLoader::PostRecPoints  returned error");
345      return reval;
346    }
347   return ReadRecPoints();
348 }
349
350 //____________________________________________________________________________ 
351 Int_t AliEMCALLoader::PostRecParticles()
352 {
353   // Posts the RecParticles array to the folder structure
354   
355   Int_t reval = AliLoader::PostRecParticles();
356   if (reval)
357     {
358       Error("PostRecParticles","AliLoader::PostRecParticles  returned error");
359       return reval;
360     }
361   return ReadRecParticles();
362 }
363
364 //____________________________________________________________________________ 
365 Int_t AliEMCALLoader::PostTracks()
366 {
367   // Posts the Tracks array to the folder structure
368   Int_t reval = AliLoader::PostTracks();
369   if (reval)
370     {
371       Error("PostTracks","AliLoader::PostTracks  returned error");
372       return reval;
373     }
374   return ReadTracks();
375 }
376
377 //____________________________________________________________________________ 
378 Int_t AliEMCALLoader::ReadHits()
379 {
380   // If there is no Clones Array in folder creates it and sends to folder
381   // then tries to read
382   // Reads the first entry of EMCAL branch in hit tree TreeH()
383   // Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder
384   //
385   TObject** hitref = HitsRef();
386   if(hitref == 0x0)
387     {
388       MakeHitsArray();
389      hitref = HitsRef();
390     }
391   
392   TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref);
393   
394   TTree* treeh = TreeH();
395   
396   if(treeh == 0)
397     {
398       AliError("Cannot read TreeH from folder");
399       return 1;
400     }
401   
402   TBranch * hitsbranch = treeh->GetBranch(fDetectorName);
403   if (hitsbranch == 0) 
404     {
405       AliError("Cannot find branch EMCAL"); 
406       return 1;
407     }
408   
409   AliDebug(1, "Reading Hits");
410   
411   if (hitsbranch->GetEntries() > 1)
412     {
413       TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000);
414       
415       hitsbranch->SetAddress(&tempo);
416       Int_t index = 0 ; 
417       Int_t i = 0 ;
418       for (i = 0 ; i < hitsbranch->GetEntries(); i++) 
419         {
420           hitsbranch->GetEntry(i) ;
421           Int_t j = 0 ;
422           for ( j = 0 ; j < tempo->GetEntries() ; j++) 
423             {
424               AliEMCALHit* hit = (AliEMCALHit*)tempo->At(j); 
425               new((*hits)[index]) AliEMCALHit( *hit ) ;
426               index++ ; 
427             }
428         }
429       tempo->Delete() ; 
430       delete tempo;
431     }
432   else 
433     {
434       hitsbranch->SetAddress(hitref);
435       hitsbranch->GetEntry(0) ;
436     }
437   
438   return 0;
439 }
440
441 //____________________________________________________________________________ 
442 Int_t AliEMCALLoader::ReadSDigits()
443 {
444   // Read the summable digits tree TreeS():
445   // Check if TClones is in folder
446   // if not create and add to folder
447   // connect to tree if available
448   // Read the data
449   
450   TObject** sdref = SDigitsRef();
451   if(sdref == 0x0)
452     {
453       MakeSDigitsArray();
454       sdref = SDigitsRef();
455     }
456   
457   TTree * treeS = TreeS();
458   if(treeS==0)
459     {
460       //May happen if file is truncated or new in LoadSDigits
461       //Error("ReadSDigits","There is no SDigit Tree");
462       return 0;
463     }
464   
465   TBranch * branch = treeS->GetBranch(fDetectorName);
466   if (branch == 0) 
467     {//easy, maybe just a new tree
468       //Error("ReadSDigits"," Cannot find branch EMCAL"); 
469       return 0;
470     }
471   
472   branch->SetAddress(SDigitsRef());
473   branch->GetEntry(0);
474   return 0;
475 }
476
477 //____________________________________________________________________________ 
478 Int_t AliEMCALLoader::ReadDigits()
479 {
480   // Read the summable digits tree TreeS():
481   // Check if TClones is in folder
482   // if not create and add to folder
483   // connect to tree if available
484   // Read the data
485   
486   TObject** dref = DigitsRef();
487   if(dref == 0x0)
488     {//if there is not array in folder, create it and put it there
489       MakeDigitsArray();
490       dref = DigitsRef();
491     }
492   
493   TTree * treeD = TreeD();
494   if(treeD==0)
495     {
496       //May happen if file is truncated or new in LoadSDigits
497       //Error("ReadDigits","There is no Digit Tree");
498       return 0;
499     }
500   
501   TBranch * branch = treeD->GetBranch(fDetectorName);
502   if (branch == 0) 
503     {//easy, maybe just a new tree
504       //Error("ReadDigits"," Cannot find branch ",fDetectorName.Data()); 
505       return 0;
506     }
507   
508   branch->SetAddress(dref);//connect branch to buffer sitting in folder
509   branch->GetEntry(0);//get first event 
510   
511   return 0;  
512 }
513
514 //____________________________________________________________________________ 
515 void AliEMCALLoader::UnloadRecParticles()
516 {
517   // Unloads the RecParticles array fromthe folder structure
518   fRecParticlesLoaded = kFALSE;
519   CleanRecParticles();
520   if (fTracksLoaded == kFALSE) UnloadTracks();
521 }
522
523 //____________________________________________________________________________ 
524 void AliEMCALLoader::UnloadTracks()
525 {
526   // Unloads the Tracks array fromthe folder structure
527   CleanTracks();//free the memory
528   //in case RecPart are loaded we can not onload tree and close the file
529   if (fRecParticlesLoaded == kFALSE) AliLoader::UnloadTracks();
530   fTracksLoaded = kFALSE;//mark that nobody needs them
531 }
532
533 //____________________________________________________________________________ 
534 void AliEMCALLoader::Track(Int_t itrack)
535 {
536   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
537   if(TreeH()== 0)
538     {
539       if (LoadHits())
540         {
541           Error("Track","Can not load hits.");
542           return;
543         } 
544     }
545   
546   TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
547   if ( !hitsbranch ) {
548     if (fDebug)
549       cout << "WARNING:  AliEMCALLoader::ReadTreeH -> Cannot find branch EMCAL" << endl ; 
550     return ;
551   }  
552   if(!Hits()) PostHits();
553   
554   hitsbranch->SetAddress(HitsRef());
555   hitsbranch->GetEntry(itrack);
556   
557 }
558
559 //____________________________________________________________________________ 
560 Int_t AliEMCALLoader::ReadRecPoints()
561 {
562   //Creates and posts to folder an array container, 
563   //connects branch in tree (if exists), and reads data to array
564   
565   MakeRecPointsArray();
566    
567   TObjArray * eca = 0x0 ;  
568
569   TTree * treeR = TreeR();
570   
571   if(treeR==0)
572     {
573       //May happen if file is truncated or new in LoadSDigits
574       return 0;
575     }
576   
577   Int_t retval = 0;
578
579   TBranch * ecabranch = treeR->GetBranch(fgkECARecPointsBranchName);
580   if (ecabranch == 0x0)
581     {
582       Error("ReadRecPoints","Can not get branch with ECA Rec. Points named %s",fgkECARecPointsBranchName.Data());
583       retval = 2;
584     }
585   else
586    {
587      ecabranch->SetAddress(&eca);
588      ecabranch->GetEntry(0) ;
589    }
590
591
592   Int_t ii ; 
593
594   Int_t maxeca = eca->GetEntries() ; 
595   for ( ii= 0 ; ii < maxeca ; ii++ ) 
596     ECARecPoints()->Add(eca->At(ii)) ;
597
598   return retval;
599 }
600
601 //____________________________________________________________________________ 
602 Int_t AliEMCALLoader::ReadTracks()
603 {
604   //Creates and posts to folder an array container, 
605   //connects branch in tree (if exists), and reads data to arry
606   
607   TObject** trkref = TracksRef();
608   if ( trkref == 0x0 )   
609     {//Create and post array
610       MakeTrackSegmentsArray();
611       trkref = TracksRef();
612     }
613   
614   TTree * treeT = TreeT();
615   if(treeT==0)
616     {
617       //May happen if file is truncated or new in LoadSDigits, or the file is in update mode, 
618       //but tracking was not performed yet for a current event
619       //Error("ReadTracks","There is no Tree with Tracks");
620       return 0;
621     }
622   
623   TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
624   if (branch == 0) 
625     {//easy, maybe just a new tree
626       Error("ReadTracks"," Cannot find branch named %s",fgkTrackSegmentsBranchName.Data());
627       return 0;
628     }
629   
630   branch->SetAddress(trkref);//connect branch to buffer sitting in folder
631   branch->GetEntry(0);//get first event 
632   
633   return 0;
634 }
635
636 //____________________________________________________________________________ 
637 Int_t AliEMCALLoader::ReadRecParticles()
638 {
639   //Reads Reconstructed  Particles from file
640   //Creates and posts to folder an array container, 
641   //connects branch in tree (if exists), and reads data to arry
642   
643   TObject** recpartref = RecParticlesRef();
644   
645   if ( recpartref == 0x0 )   
646     {//Create and post array
647       MakeRecParticlesArray();
648       recpartref = RecParticlesRef();
649     }
650   
651   TTree * treeP = TreeP();
652   if(treeP==0)
653     {
654       //May happen if file is truncated or new in LoadSDigits, 
655       //or the file is in update mode, 
656       //but tracking was not performed yet for a current event
657       //     Error("ReadRecParticles","There is no Tree with Tracks and Reconstructed Particles");
658       return 0;
659     }
660   
661   TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
662   if (branch == 0) 
663     {//easy, maybe just a new tree
664       Error("ReadRecParticles"," Cannot find branch %s",fgkRecParticlesBranchName.Data()); 
665       return 0;
666     }
667   
668   branch->SetAddress(recpartref);//connect branch to buffer sitting in folder
669   branch->GetEntry(0);//get first event 
670   
671   return 0;
672 }
673
674 //____________________________________________________________________________ 
675 AliEMCALGeometry* AliEMCALLoader::GetEMCALGeometry()
676 {
677   //returns EMCAL geometry from gAlice 
678   //static Method used by some classes where it is not convienient to pass eventfoldername
679   if (gAlice == 0x0)
680     return 0x0;
681   AliEMCAL* emcal=dynamic_cast<AliEMCAL*>(gAlice->GetDetector("EMCAL"));
682   if (emcal == 0x0)
683     return 0x0;
684   return emcal->GetGeometry();
685 }
686
687 //____________________________________________________________________________ 
688 AliEMCALLoader* AliEMCALLoader::GetEMCALLoader(const  char* eventfoldername)
689 {
690   // Get an instance of the EMCALLoader object
691   AliRunLoader* rn  = AliRunLoader::GetRunLoader(eventfoldername);
692   if (rn == 0x0)
693     {
694       cerr<<"Error: <AliEMCALLoader::GetEMCALLoader>: "
695           << "Can not find Run Loader in folder "<<eventfoldername<<endl;
696       return 0x0;
697     }
698   return dynamic_cast<AliEMCALLoader*>(rn->GetLoader("EMCALLoader"));
699 }
700
701 //____________________________________________________________________________ 
702 Bool_t AliEMCALLoader::BranchExists(const TString& recName)
703
704   // Check is branch exists
705   if (fBranchTitle.IsNull()) return kFALSE;
706   TString dataname, zername ;
707   TTree* tree;
708   if(recName == "SDigits") {
709     tree = TreeS();
710     dataname = GetDetectorName();
711     zername = "AliEMCALSDigitizer" ;
712   }
713   else if(recName == "Digits"){
714     tree = TreeD();
715     dataname = GetDetectorName();
716     zername = "AliEMCALDigitizer" ;
717   }
718   else if(recName == "ECARecPoints"){
719     tree = TreeR();
720     dataname = fgkECARecPointsBranchName;
721     zername = "AliEMCALClusterizer" ;
722   }
723   else if(recName == "TrackSegments"){
724     tree = TreeT();
725     dataname = fgkTrackSegmentsBranchName;
726     zername = "AliEMCALTrackSegmentMaker";
727   }        
728   else if(recName == "RecParticles"){
729     tree = TreeP();
730     dataname = fgkRecParticlesBranchName;
731     zername = "AliEMCALPID";
732   }
733   else
734     return kFALSE ;
735   
736   if(!tree ) 
737     return kFALSE ;
738   
739   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
740   TIter next(lob) ; 
741   TBranch * branch = 0 ;  
742   TString titleName(fBranchTitle);
743   titleName+=":";
744   
745   while ((branch = (static_cast<TBranch*>(next())))) {
746     TString branchName(branch->GetName() ) ; 
747     TString branchTitle(branch->GetTitle() ) ;  
748     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
749       Warning("BranchExists","branch %s  with title  %s ",dataname.Data(),fBranchTitle.Data());
750       return kTRUE ;
751     }
752     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
753       Warning("BranchExists","branch AliEMCAL... with title  %s ",branch->GetTitle());
754       return kTRUE ; 
755     }
756   }
757   return kFALSE ;
758   
759 }
760
761 //____________________________________________________________________________ 
762 void AliEMCALLoader::SetBranchTitle(const TString& btitle)
763 {
764   // Gives a name to a branch in the folder structure
765   if (btitle.CompareTo(fBranchTitle) == 0) return;
766   fBranchTitle = btitle;
767   ReloadAll();
768 }
769
770 //____________________________________________________________________________ 
771 void AliEMCALLoader::CleanHits()
772 {
773   // Clean hits 
774   AliLoader::CleanHits();
775   //Clear an array 
776   TClonesArray* hits = Hits();
777   if (hits) 
778     hits->Clear();
779 }
780
781 //____________________________________________________________________________ 
782 void AliEMCALLoader::CleanSDigits()
783 {
784   // Cleans the SDigits array in the folder structure
785   AliLoader::CleanSDigits();
786   TClonesArray* sdigits = SDigits();
787   if (sdigits) sdigits->Clear();
788   
789 }
790 //____________________________________________________________________________ 
791
792 void AliEMCALLoader::CleanDigits()
793 {
794   // Cleans the Digits array in the folder structure
795   AliLoader::CleanDigits();
796   TClonesArray* digits = Digits();
797   if (digits) digits->Clear();
798 }
799
800 //____________________________________________________________________________ 
801 void AliEMCALLoader::CleanRecPoints()
802 {
803   // Cleans the RecPoints array in the folder structure
804   AliLoader::CleanRecPoints();
805   TObjArray* recpoints = ECARecPoints();
806   if (recpoints) recpoints->Clear();
807
808 }
809
810 //____________________________________________________________________________ 
811 void AliEMCALLoader::CleanTracks()
812 {
813   // Cleans the Tracks array in the folder structure
814   AliLoader::CleanTracks();//tree
815   //and clear the array
816   TClonesArray* tracks = TrackSegments();
817   if (tracks) 
818     tracks->Clear();  
819 }
820
821 //____________________________________________________________________________ 
822 void AliEMCALLoader::CleanRecParticles()
823 {
824   // Cleans the RecParticles array in the folder structure
825   TClonesArray *recpar = RecParticles();
826   if (recpar) 
827     recpar->Clear();
828 }
829
830 //____________________________________________________________________________ 
831 // void AliEMCALLoader::ReadCalibrationDB(const char * database,const char * filename)
832 // {
833
834 //   if(fcdb && (strcmp(database,fcdb->GetTitle())==0))
835 //     return ;
836
837 //   TFile * file = gROOT->GetFile(filename) ;
838 //   if(!file)
839 //     file = TFile::Open(filename);
840 //   if(!file){
841 //     Error ("ReadCalibrationDB", "Cannot open file %s", filename) ;
842 //     return ;
843 //   }
844 //   if(fcdb)
845 //     fcdb->Delete() ;
846 //   fcdb = dynamic_cast<AliEMCALCalibrationDB *>(file->Get("AliEMCALCalibrationDB")) ;
847 //   if(!fcdb)
848 //     Error ("ReadCalibrationDB", "No database %s in file %s", database, filename) ;
849 // }
850 //____________________________________________________________________________ 
851
852 // AliEMCALSDigitizer*  AliEMCALLoader::EMCALSDigitizer() 
853 // { 
854 // //return EMCAL SDigitizer
855 //  return  dynamic_cast<AliEMCALSDigitizer*>(SDigitizer()) ;
856 // }
857
858 //____________________________________________________________________________ 
859 void AliEMCALLoader::MakeHitsArray()
860 {
861   // Create the array for Hits
862   if (Hits()) return;
863   TClonesArray* hits = new TClonesArray("AliEMCALHit",1000);
864   hits->SetName(fgkHitsName);
865   GetDetectorDataFolder()->Add(hits);
866 }
867
868 //____________________________________________________________________________ 
869 void AliEMCALLoader::MakeSDigitsArray()
870 {
871   // Create the array for SDigits
872   if ( SDigits()) return;
873   TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",1);
874   sdigits->SetName(fgkSDigitsName);
875   GetDetectorDataFolder()->Add(sdigits);
876 }
877
878 //____________________________________________________________________________ 
879 void AliEMCALLoader::MakeDigitsArray()
880 {
881   // Create the array for Digits
882   if ( Digits()) return;
883   TClonesArray* digits = new TClonesArray("AliEMCALDigit",1);
884   digits->SetName(fgkDigitsName);
885   GetDetectorDataFolder()->Add(digits);
886   
887 }
888
889 //____________________________________________________________________________ 
890 void AliEMCALLoader::MakeRecPointsArray()
891 {
892   // Make recpoints array
893   if ( ECARecPoints() == 0x0) 
894     {
895       AliDebug(9, "Making array for ECA");
896       TObjArray* eca = new TObjArray(100) ;
897       eca->SetName(fgkECARecPointsName) ;
898       GetDetectorDataFolder()->Add(eca);
899     }
900 }
901
902 //____________________________________________________________________________ 
903 void AliEMCALLoader::MakeTrackSegmentsArray()
904 {
905   // Create the array for TrackSegments
906   if ( TrackSegments()) 
907     return;
908   TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
909   ts->SetName(fgkTracksName);
910   GetDetectorDataFolder()->Add(ts);
911 }
912
913 //____________________________________________________________________________ 
914 void AliEMCALLoader::MakeRecParticlesArray()
915 {  
916   // Create the array for RecParticles
917   if ( RecParticles()) return;
918   TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
919   rp->SetName(fgkRecParticlesName);
920   GetDetectorDataFolder()->Add(rp);
921 }