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