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