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