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