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