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