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