]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSLoader.cxx
Updated histogram limits (PHOS energy)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSLoader.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 /* History of cvs commits:
19  *
20  * $Log$
21  * Revision 1.18  2006/08/28 10:01:56  kharlov
22  * Effective C++ warnings fixed (Timur Pocheptsov)
23  *
24  * Revision 1.17  2006/08/25 16:00:53  kharlov
25  * Compliance with Effective C++AliPHOSHit.cxx
26  *
27  * Revision 1.16  2006/08/01 12:15:04  cvetan
28  * Adding a constructor from TFolder. Needed by AliReconstruction plugin scheme
29  *
30  * Revision 1.15  2005/07/12 20:07:35  hristov
31  * Changes needed to run simulation and reconstrruction in the same AliRoot session
32  *
33  * Revision 1.14  2005/05/28 14:19:04  schutz
34  * Compilation warnings fixed by T.P.
35  *
36  */
37
38 //_________________________________________________________________________
39 //  A singleton. This class should be used in the analysis stage to get 
40 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
41 //  instead of directly reading them from galice.root file. This container 
42 //  ensures, that one reads Digits, made of these particular digits, RecPoints, 
43 //  made of these particular RecPoints, TrackSegments and RecParticles. 
44 //  This becomes non trivial if there are several identical branches, produced with
45 //  different set of parameters. 
46 //
47 //  An example of how to use (see also class AliPHOSAnalyser):
48 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
49 //     AliPHOSRecParticle * part = gime->RecParticle(1) ;
50 //     ................
51 //  please->GetEvent(event) ;    // reads new event from galice.root
52 //                  
53 //-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
54 //--         Completely redesigned by Dmitri Peressounko March 2001  
55 //
56 //-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
57 //--         systematic usage of TFolders without changing the interface        
58 //////////////////////////////////////////////////////////////////////////////
59
60
61 // --- ROOT system ---
62
63 #include "TFile.h"
64 #include "TTree.h"
65 #include "TROOT.h"
66
67 // --- Standard library ---
68
69 // --- AliRoot header files ---
70 #include "AliObjectLoader.h"
71 #include "AliLog.h"
72 #include "AliPHOSLoader.h"
73 #include "AliPHOS.h"
74 #include "AliPHOSHit.h"
75 #include "AliPHOSCalibrationDB.h"
76
77 ClassImp(AliPHOSLoader)
78
79
80 const TString AliPHOSLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event
81 const TString AliPHOSLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray 
82 const TString AliPHOSLoader::fgkDigitsName("DIGITS");//Name for TClonesArray 
83 const TString AliPHOSLoader::fgkEmcRecPointsName("EMCRECPOINTS");//Name for TClonesArray 
84 const TString AliPHOSLoader::fgkCpvRecPointsName("CPVRECPOINTS");//Name for TClonesArray 
85 const TString AliPHOSLoader::fgkTracksName("TRACKS");//Name for TClonesArray 
86 const TString AliPHOSLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray
87
88 const TString AliPHOSLoader::fgkEmcRecPointsBranchName("PHOSEmcRP");//Name for branch with EMC Reconstructed Points
89 const TString AliPHOSLoader::fgkCpvRecPointsBranchName("PHOSCpvRP");//Name for branch with CPV Reconstructed Points
90 const TString AliPHOSLoader::fgkTrackSegmentsBranchName("PHOSTS");//Name for branch with TrackSegments
91 const TString AliPHOSLoader::fgkRecParticlesBranchName("PHOSRP");//Name for branch with Reconstructed Particles
92 //____________________________________________________________________________ 
93 AliPHOSLoader::AliPHOSLoader() : fBranchTitle(), fcdb(0), fDebug(0), fTmpHits(0x0)
94 {
95   //def ctor
96   fTmpHits =  new TClonesArray("AliPHOSHit",1000);
97 }
98 //____________________________________________________________________________ 
99 AliPHOSLoader::AliPHOSLoader(const Char_t *detname,const Char_t *eventfoldername) :
100       AliLoader(detname, eventfoldername),
101       fBranchTitle(), fcdb(0), fDebug(0), fTmpHits(0x0)
102 {
103   //ctor
104 }
105 //____________________________________________________________________________ 
106 AliPHOSLoader::AliPHOSLoader(const Char_t *detname,TFolder *topfolder):
107   AliLoader(detname,topfolder),
108   fBranchTitle(), fcdb(0), fDebug(0), fTmpHits(0x0)
109
110 {
111   //ctor
112   fTmpHits =  new TClonesArray("AliPHOSHit",1000);
113 }
114 //____________________________________________________________________________ 
115 AliPHOSLoader::AliPHOSLoader(const AliPHOSLoader & obj):
116   AliLoader(obj),fBranchTitle(obj.GetBranchTitle()),fcdb(obj.CalibrationDB()),
117   fDebug(obj.GetDebug()),fTmpHits(obj.fTmpHits)
118 {
119   // Copy constructor
120 }
121 //____________________________________________________________________________ 
122
123 AliPHOSLoader::~AliPHOSLoader()
124 {
125   //remove and delete arrays
126   Clean(fgkHitsName);
127   Clean(fgkSDigitsName);
128   Clean(fgkDigitsName);
129   Clean(fgkEmcRecPointsName);
130   Clean(fgkCpvRecPointsName);
131   Clean(fgkTracksName);
132   Clean(fgkRecParticlesName);
133   CleanFolders() ;
134 }
135
136 //____________________________________________________________________________ 
137 void AliPHOSLoader::CleanFolders()
138  {
139    CleanRecParticles();
140    AliLoader::CleanFolders();
141  }
142
143 //____________________________________________________________________________ 
144 Int_t AliPHOSLoader::SetEvent()
145 {
146 //Cleans loaded stuff and and sets Files and Directories
147 // do not post any data to folder/tasks
148
149
150  Int_t retval = AliLoader::SetEvent();
151   if (retval)
152    {
153      AliError("returned error");
154      return retval;
155    }
156
157
158   if (Hits()) Hits()->Clear();
159   if (SDigits()) SDigits()->Clear();
160   if (Digits()) Digits()->Clear();
161   if (EmcRecPoints()) EmcRecPoints()->Clear();
162   if (CpvRecPoints()) CpvRecPoints()->Clear();
163   if (TrackSegments()) TrackSegments()->Clear();
164   if (RecParticles()) RecParticles()->Clear();
165    
166   return 0;
167 }
168
169 //____________________________________________________________________________ 
170 Int_t AliPHOSLoader::GetEvent()
171 {
172 //Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method
173 //to add Rec Particles specific for PHOS
174
175 //First call the original method to get whatever from std. setup is needed
176   Int_t retval;
177   
178   retval = AliLoader::GetEvent();
179   if (retval)
180    {
181      AliError("returned error");
182      return retval;
183    }
184   
185   if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits();
186   if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits();
187   if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits();
188   if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints();
189   if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks();
190   if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles();
191
192
193 //Now, check if RecPart were loaded  
194   return 0;
195 }
196
197 // //____________________________________________________________________________ 
198 // const AliPHOS * AliPHOSLoader::PHOS() 
199 // {
200 //   // returns the PHOS object 
201 //   AliPHOS * phos = dynamic_cast<AliPHOS*>(GetModulesFolder()->FindObject(fDetectorName));
202 //   if ( phos == 0x0) 
203 //     if (fDebug)
204 //       cout << "WARNING: AliPHOSLoader::PHOS -> PHOS module not found in Folders" << endl ; 
205 //   return phos ; 
206 // }  
207
208 //____________________________________________________________________________ 
209 Int_t AliPHOSLoader::LoadHits(Option_t* opt)
210 {  
211 //------- Hits ----------------------
212 //Overload (extends) LoadHits implemented in AliLoader
213 //
214   Int_t res;
215   
216   //First call the AliLoader's method to send the TreeH to folder
217   res = AliLoader::LoadHits(opt);
218   
219   if (res)
220    {//oops, error
221      AliError("returned error");
222      return res;
223    }
224
225   //read the data from tree in folder and send it to folder
226   res = ReadHits();
227   return 0;
228 }
229
230
231 //____________________________________________________________________________ 
232 Int_t AliPHOSLoader::LoadSDigits(Option_t* opt)
233 {
234   //---------- SDigits -------------------------
235   Int_t res;
236   //First call the AliLoader's method to send the TreeS to folder
237   res = AliLoader::LoadSDigits(opt);
238   if (res)
239    {//oops, error
240      AliError("returned error");
241      return res;
242    }
243   return ReadSDigits();
244    
245
246 //____________________________________________________________________________ 
247 Int_t AliPHOSLoader::LoadDigits(Option_t* opt)
248
249   //---------- Digits -------------------------
250   Int_t res;
251   //First call the AliLoader's method to send the TreeS to folder
252   res = AliLoader::LoadDigits(opt);
253   if (res)
254    {//oops, error
255      AliError("returned error");
256      return res;
257    }
258   return ReadDigits();
259 }
260 //____________________________________________________________________________ 
261 Int_t AliPHOSLoader::LoadRecPoints(Option_t* opt) 
262 {
263   // -------------- RecPoints -------------------------------------------
264   Int_t res;
265   //First call the AliLoader's method to send the TreeR to folder
266   res = AliLoader::LoadRecPoints(opt);
267   if (res)
268    {//oops, error
269      AliError("returned error");
270      return res;
271    }
272
273   TFolder * phosFolder = GetDetectorDataFolder();
274   if ( phosFolder  == 0x0 ) 
275    {
276      AliError("Can not get detector data folder");
277      return 1;
278    }
279   return ReadRecPoints();
280 }
281 //____________________________________________________________________________ 
282
283 Int_t  AliPHOSLoader::LoadTracks(Option_t* opt)
284 {
285  //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts
286   AliDebug(1, Form("opt = %s",opt));
287  Int_t res;
288  res = AliLoader::LoadTracks(opt);
289  if (res)
290    {//oops, error
291       AliError("returned error");
292       return res;
293    }  
294  return ReadTracks();
295 }
296
297 //____________________________________________________________________________ 
298 Int_t AliPHOSLoader::LoadRecParticles(Option_t* opt) 
299 {
300   // -------------- RecPoints -------------------------------------------
301   Int_t res;
302   //First call the AliLoader's method to send the TreeT to folder
303   res = AliLoader::LoadRecParticles(opt);
304   if (res)
305    {//oops, error
306      AliError("returned error");
307      return res;
308    }
309   return ReadRecParticles();
310 }
311
312 //____________________________________________________________________________ 
313 //PostHits etc. PostXXX must be const - not to hide virtual functions
314 //from base class AliLoader, but they call non-constant functions ReadXXX
315 //so I have to const_cast this pointer
316 Int_t AliPHOSLoader::PostHits()const
317 {
318   // -------------- Hits -------------------------------------------
319   Int_t reval = AliLoader::PostHits();
320   if (reval)
321    {
322      AliError("returned error");
323      return reval;
324    }
325    
326   return const_cast<AliPHOSLoader *>(this)->ReadHits();
327 }
328 //____________________________________________________________________________ 
329
330 Int_t AliPHOSLoader::PostSDigits()const
331 {
332   // -------------- SDigits -------------------------------------------
333   Int_t reval = AliLoader::PostSDigits();
334   if (reval)
335    {
336      AliError("returned error");
337      return reval;
338    }
339   return const_cast<AliPHOSLoader *>(this)->ReadSDigits();
340 }
341 //____________________________________________________________________________ 
342
343 Int_t AliPHOSLoader::PostDigits()const
344 {
345   // -------------- Digits -------------------------------------------
346   Int_t reval = AliLoader::PostDigits();
347   if (reval)
348    {
349      AliError("returned error");
350      return reval;
351    }
352   return const_cast<AliPHOSLoader *>(this)->ReadDigits();
353 }
354 //____________________________________________________________________________ 
355
356 Int_t AliPHOSLoader::PostRecPoints()const
357 {
358   // -------------- RecPoints -------------------------------------------
359   Int_t reval = AliLoader::PostRecPoints();
360   if (reval)
361    {
362      AliError("returned error");
363      return reval;
364    }
365   return const_cast<AliPHOSLoader *>(this)->ReadRecPoints();
366 }
367
368 //____________________________________________________________________________ 
369
370 Int_t AliPHOSLoader::PostRecParticles()const
371 {
372   // -------------- RecParticles -------------------------------------------
373   Int_t reval = AliLoader::PostRecParticles();
374   if (reval)
375    {
376      AliError("returned error");
377      return reval;
378    }
379   return const_cast<AliPHOSLoader *>(this)->ReadRecParticles();
380 }
381 //____________________________________________________________________________ 
382
383 Int_t AliPHOSLoader::PostTracks()const
384 {
385   // -------------- Tracks -------------------------------------------
386   Int_t reval = AliLoader::PostTracks();
387   if (reval)
388    {
389      AliError("returned error");
390      return reval;
391    }
392   return const_cast<AliPHOSLoader *>(this)->ReadTracks();
393 }
394 //____________________________________________________________________________ 
395
396
397
398 //____________________________________________________________________________ 
399 Int_t AliPHOSLoader::ReadHits()
400 {
401 // If there is no Clones Array in folder creates it and sends to folder
402 // then tries to read
403 // Reads the first entry of PHOS branch in hit tree TreeH()
404 // Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder
405 //
406   TObject** hitref = HitsRef();
407   if(hitref == 0x0) {
408     MakeHitsArray();
409     hitref = HitsRef();
410   }
411
412   TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref);
413
414   TTree* treeh = TreeH();
415   
416   if(treeh == 0) {
417     AliError("Cannot read TreeH from folder");
418     return 1;
419   }
420   
421   TBranch * hitsbranch = treeh->GetBranch(fDetectorName);
422   if (hitsbranch == 0) {
423     AliError("Cannot find branch PHOS"); 
424     return 1;
425   }
426
427   AliDebug(1, "Reading Hits");
428   
429   if (hitsbranch->GetEntries() > 1) {
430
431     hitsbranch->SetAddress(&fTmpHits);
432     Int_t index = 0 ; 
433     for (Int_t i = 0 ; i < hitsbranch->GetEntries(); i++) {
434       hitsbranch->GetEntry(i) ;
435       for (Int_t j = 0 ; j < fTmpHits->GetEntriesFast() ; j++) {
436         AliPHOSHit* hit = (AliPHOSHit*)fTmpHits->At(j); 
437         new((*hits)[index]) AliPHOSHit( *hit ) ;
438         index++ ; 
439       }
440     }
441     fTmpHits->Clear();
442   }
443   else {
444     hitsbranch->SetAddress(hitref);
445     hitsbranch->GetEntry(0) ;
446   }
447   
448   return 0;
449 }
450 //____________________________________________________________________________ 
451 Int_t AliPHOSLoader::ReadSDigits()
452 {
453 // Read the summable digits tree TreeS():
454 // Check if TClones is in folder
455 // if not create and add to folder
456 // connect to tree if available
457 // Read the data
458
459   TObject** sdref = SDigitsRef();
460   if(sdref == 0x0)
461    {
462      MakeSDigitsArray();
463      sdref = SDigitsRef();
464    }
465    
466   TTree * treeS = TreeS();
467   if(treeS==0)
468    {
469      //May happen if file is truncated or new in LoadSDigits
470      //AliError("There is no SDigit Tree");
471      return 0;
472    }
473   
474   TBranch * branch = treeS->GetBranch(fDetectorName);
475   if (branch == 0) 
476    {//easy, maybe just a new tree
477     //AliError("Cannot find branch PHOS"); 
478     return 0;
479   }
480     
481   branch->SetAddress(SDigitsRef());
482   branch->GetEntry(0);
483   return 0;
484 }
485
486 //____________________________________________________________________________ 
487 Int_t AliPHOSLoader::ReadDigits()
488 {
489 // Read the summable digits tree TreeS():
490 // Check if TClones is in folder
491 // if not create and add to folder
492 // connect to tree if available
493 // Read the data
494   
495   TObject** dref = DigitsRef();
496   if(dref == 0x0)
497    {//if there is not array in folder, create it and put it there
498      MakeDigitsArray();
499      dref = DigitsRef();
500    }
501
502   TTree * treeD = TreeD();
503   if(treeD==0)
504    {
505      //May happen if file is truncated or new in LoadSDigits
506      //AliError("There is no Digit Tree");
507      return 0;
508    }
509
510   TBranch * branch = treeD->GetBranch(fDetectorName);
511   if (branch == 0) 
512    {//easy, maybe just a new tree
513     //AliError("Cannot find branch ",fDetectorName.Data()); 
514     return 0;
515    }
516   
517   branch->SetAddress(dref);//connect branch to buffer sitting in folder
518   branch->GetEntry(0);//get first event 
519
520   return 0;  
521 }
522
523 //____________________________________________________________________________ 
524
525 void AliPHOSLoader::Track(Int_t itrack)
526 {
527 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
528   if(TreeH()== 0)
529    {
530      if (LoadHits())
531       {
532         AliError("Can not load hits.");
533         return;
534       } 
535    }
536   
537   TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("PHOS")) ;
538   if ( !hitsbranch ) {
539     if (fDebug)
540       cout << "WARNING:  AliPHOSLoader::ReadTreeH -> Cannot find branch PHOS" << endl ; 
541     return ;
542   }  
543   if(!Hits()) PostHits();
544
545   hitsbranch->SetAddress(HitsRef());
546   hitsbranch->GetEntry(itrack);
547
548 }
549
550 //____________________________________________________________________________ 
551 Int_t AliPHOSLoader::ReadRecPoints()
552 {
553 //Creates and posts to folder an array container, 
554 //connects branch in tree (if exists), and reads data to array
555   
556   MakeRecPointsArray();
557   
558   TObjArray * cpva = 0x0 ; 
559   TObjArray * emca = 0x0 ; 
560   
561   TTree * treeR = TreeR();
562  
563   if(treeR==0)
564    {
565      //May happen if file is truncated or new in LoadSDigits
566      return 0;
567    }
568
569   Int_t retval = 0;
570   TBranch * emcbranch = treeR->GetBranch(fgkEmcRecPointsBranchName);
571
572   if (emcbranch == 0x0)
573    {
574      AliError(Form("Can not get branch with EMC Rec. Points named %s",
575                    fgkEmcRecPointsBranchName.Data()));
576      retval = 1;
577    }
578   else
579    {
580      emcbranch->SetAddress(&emca) ;
581      emcbranch->GetEntry(0) ;
582    }
583   TBranch * cpvbranch = treeR->GetBranch(fgkCpvRecPointsBranchName);
584   if (cpvbranch == 0x0)
585    {
586      AliError(Form("Can not get branch with CPV Rec. Points named %s",
587                    fgkCpvRecPointsBranchName.Data()));
588      retval = 2;
589    }
590   else
591    {
592      cpvbranch->SetAddress(&cpva);
593      cpvbranch->GetEntry(0) ;
594    }
595
596   Int_t ii ; 
597   Int_t maxemc = emca->GetEntries() ; 
598   for ( ii= 0 ; ii < maxemc ; ii++ ) 
599     EmcRecPoints()->Add(emca->At(ii)) ;
600  
601   Int_t maxcpv = cpva->GetEntries() ;
602   for ( ii= 0 ; ii < maxcpv ; ii++ )
603     CpvRecPoints()->Add(cpva->At(ii)) ; 
604
605   return retval;
606 }
607
608 //____________________________________________________________________________ 
609 Int_t AliPHOSLoader::ReadTracks()
610 {
611 //Creates and posts to folder an array container, 
612 //connects branch in tree (if exists), and reads data to arry
613
614   TObject** trkref = TracksRef();
615   if ( trkref == 0x0 )   
616    {//Create and post array
617     MakeTrackSegmentsArray();
618     trkref = TracksRef();
619    }
620
621   TTree * treeT = TreeT();
622   if(treeT==0)
623    {
624      //May happen if file is truncated or new in LoadSDigits, or the file is in update mode, 
625      //but tracking was not performed yet for a current event
626      //AliError("There is no Tree with Tracks");
627      return 0;
628    }
629   
630   TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
631 //   AliInfo(Form("Branch named %s is opened: 0x%z",
632 //                fgkTrackSegmentsBranchName.Data(),branch));
633   if (branch == 0) 
634    {//easy, maybe just a new tree
635     AliError(Form("Cannot find branch named %s",
636                   fgkTrackSegmentsBranchName.Data()));
637     return 0;
638   }
639
640   branch->SetAddress(trkref);//connect branch to buffer sitting in folder
641   branch->GetEntry(0);//get first event 
642   
643   return 0;
644 }
645 //____________________________________________________________________________ 
646
647 Int_t AliPHOSLoader::ReadRecParticles()
648 {
649 //Reads Reconstructed  Particles from file
650 //Creates and posts to folder an array container, 
651 //connects branch in tree (if exists), and reads data to arry
652   
653   TObject** recpartref = RecParticlesRef();
654   
655   if ( recpartref == 0x0 )   
656    {//Create and post array
657     MakeRecParticlesArray();
658     recpartref = RecParticlesRef();
659    }
660
661   TTree * treeP = TreeP();
662   if(treeP==0)
663    {
664      //May happen if file is truncated or new in LoadSDigits, 
665      //or the file is in update mode, 
666      //but tracking was not performed yet for a current event
667      //     AliError("There is no Tree with Tracks and Reconstructed Particles");
668      return 0;
669    }
670   
671   TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
672   if (branch == 0) 
673    {//easy, maybe just a new tree
674     AliError(Form("Cannot find branch %s",
675                   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 /***************************************************************************************/
687
688 AliPHOSLoader* AliPHOSLoader::GetPHOSLoader(const  char* eventfoldername)
689 {
690   // Return PHOS loader
691   AliRunLoader* rn  = AliRunLoader::GetRunLoader(eventfoldername);
692   if (rn == 0x0) {
693     printf("Can not find Run Loader in folder %s", eventfoldername);
694     return 0x0 ; 
695   }
696   return dynamic_cast<AliPHOSLoader*>(rn->GetLoader("PHOSLoader"));
697 }
698 /***************************************************************************************/
699
700 Bool_t AliPHOSLoader::BranchExists(const TString& recName)
701 {
702   // Check if a branch named redName exists
703   if (fBranchTitle.IsNull()) return kFALSE;
704   TString dataname, zername ;
705   TTree* tree;
706   if(recName == "SDigits")
707    {
708     tree = TreeS();
709     dataname = GetDetectorName();
710     zername = "AliPHOSSDigitizer" ;
711    }
712   else
713     if(recName == "Digits"){
714       tree = TreeD();
715       dataname = GetDetectorName();
716       zername = "AliPHOSDigitizer" ;
717     }
718     else
719       if(recName == "RecPoints"){
720        tree = TreeR();
721        dataname = fgkEmcRecPointsBranchName;
722        zername = "AliPHOSClusterizer" ;
723       }
724       else
725        if(recName == "TrackSegments"){
726          tree = TreeT();
727          dataname = fgkTrackSegmentsBranchName;
728          zername = "AliPHOSTrackSegmentMaker";
729        }        
730        else
731          if(recName == "RecParticles"){
732            tree = TreeP();
733            dataname = fgkRecParticlesBranchName;
734            zername = "AliPHOSPID";
735          }
736          else
737            return kFALSE ;
738
739   
740   if(!tree ) 
741     return kFALSE ;
742
743   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
744   TIter next(lob) ; 
745   TBranch * branch = 0 ;  
746   TString titleName(fBranchTitle);
747   titleName+=":";
748
749   while ((branch = (static_cast<TBranch*>(next())))) {
750     TString branchName(branch->GetName() ) ; 
751     TString branchTitle(branch->GetTitle() ) ;  
752     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
753       AliWarning(Form("branch %s  with title  %s ",
754                       dataname.Data(),fBranchTitle.Data()));
755       return kTRUE ;
756     }
757     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
758       AliWarning(Form("branch AliPHOS... with title  %s ",
759                       branch->GetTitle()));
760       return kTRUE ; 
761     }
762   }
763   return kFALSE ;
764
765  }
766
767 void AliPHOSLoader::SetBranchTitle(const TString& btitle)
768 {
769   // Set branch title
770   if (btitle.CompareTo(fBranchTitle) == 0) return;
771   fBranchTitle = btitle;
772   ReloadAll();
773  }
774  
775 //____________________________________________________________________________ 
776 //Again, must be const not to hide virtual functions from AliLoader
777 //but there are calls to non-const functions, so I have to const_cast this pointer
778 void AliPHOSLoader::CleanHits()const
779 {
780   // Clean Hits array
781   AliLoader::CleanHits();
782   //Clear an array 
783   TClonesArray* hits = const_cast<AliPHOSLoader *>(this)->Hits();
784   if (hits) hits->Clear();
785 }
786 //____________________________________________________________________________ 
787
788 void AliPHOSLoader::CleanSDigits()const
789 {
790   // Clean SDigits array
791   AliLoader::CleanSDigits();
792   TClonesArray* sdigits = const_cast<AliPHOSLoader *>(this)->SDigits();
793   if (sdigits) sdigits->Clear();
794   
795 }
796 //____________________________________________________________________________ 
797
798 void AliPHOSLoader::CleanDigits()const
799 {
800   // Clean Digits array
801   AliLoader::CleanDigits();
802   TClonesArray* digits = const_cast<AliPHOSLoader *>(this)->Digits();
803   if (digits) digits->Clear();
804 }
805 //____________________________________________________________________________ 
806
807 void AliPHOSLoader::CleanRecPoints()const
808 {
809   // Clean RecPoints array
810   AliLoader::CleanRecPoints();
811   TObjArray* recpoints = const_cast<AliPHOSLoader *>(this)->EmcRecPoints();
812   if (recpoints) recpoints->Clear();
813   recpoints = const_cast<AliPHOSLoader *>(this)->CpvRecPoints();
814   if (recpoints) recpoints->Clear();
815 }
816 //____________________________________________________________________________ 
817
818 void AliPHOSLoader::CleanTracks()const
819 {
820   //Cleans Tracks stuff
821   AliLoader::CleanTracks();//tree
822   
823   //and clear the array
824   TClonesArray* tracks = const_cast<AliPHOSLoader *>(this)->TrackSegments();
825   if (tracks) tracks->Clear();
826
827 }
828 //____________________________________________________________________________ 
829
830 void AliPHOSLoader::CleanRecParticles()
831  {
832    // Clean RecParticles array
833    TClonesArray *recpar = RecParticles();
834    if (recpar) recpar->Clear();
835   
836  
837  }
838 //____________________________________________________________________________ 
839
840 void AliPHOSLoader::ReadCalibrationDB(const char * database,const char * filename)
841 {
842   // Read calibration data base from file
843   if(fcdb && (strcmp(database,fcdb->GetTitle())==0))
844     return ;
845
846   TFile * file = gROOT->GetFile(filename) ;
847   if(!file)
848     file = TFile::Open(filename);
849   if(!file){
850     AliError(Form("Cannot open file %s", filename)) ;
851     return ;
852   }
853   if(fcdb)
854     fcdb->Delete() ;
855   fcdb = dynamic_cast<AliPHOSCalibrationDB *>(file->Get("AliPHOSCalibrationDB")) ;
856   if(!fcdb)
857     AliError(Form("No database %s in file %s", database, filename)) ;
858 }
859 //____________________________________________________________________________ 
860
861 // AliPHOSSDigitizer*  AliPHOSLoader::PHOSSDigitizer() 
862 // { 
863 // //return PHOS SDigitizer
864 //  return  dynamic_cast<AliPHOSSDigitizer*>(SDigitizer()) ;
865 // }
866
867 //____________________________________________________________________________ 
868 void AliPHOSLoader::MakeHitsArray()
869 {
870   // Add Hits array to the data folder
871   if (Hits()) return;
872   TClonesArray* hits = new TClonesArray("AliPHOSHit",1000);
873   hits->SetName(fgkHitsName);
874   GetDetectorDataFolder()->Add(hits);
875 }
876
877 //____________________________________________________________________________ 
878 void AliPHOSLoader::MakeSDigitsArray()
879 {
880   // Add SDigits array to the data folder
881   if ( SDigits()) return;
882   TClonesArray* sdigits = new TClonesArray("AliPHOSDigit",1);
883   sdigits->SetName(fgkSDigitsName);
884   GetDetectorDataFolder()->Add(sdigits);
885 }
886
887 //____________________________________________________________________________ 
888 void AliPHOSLoader::MakeDigitsArray()
889 {
890   // Add Digits array to the data folder
891   if ( Digits()) return;
892   TClonesArray* digits = new TClonesArray("AliPHOSDigit",1);
893   digits->SetName(fgkDigitsName);
894   GetDetectorDataFolder()->Add(digits);
895   
896 }
897
898 //____________________________________________________________________________ 
899 void AliPHOSLoader::MakeRecPointsArray()
900 {
901   // Add RecPoints array to the data folder
902   if ( EmcRecPoints() == 0x0)
903    {
904      AliDebug(9, "Making array for EMC");
905     TObjArray* emc = new TObjArray(100) ;
906     emc->SetName(fgkEmcRecPointsName) ;
907     GetDetectorDataFolder()->Add(emc);
908    }
909
910   if ( CpvRecPoints() == 0x0)
911    { 
912      AliDebug(9, "Making array for CPV");
913      TObjArray* cpv = new TObjArray(100) ;
914      cpv->SetName(fgkCpvRecPointsName);
915      GetDetectorDataFolder()->Add(cpv);
916    }
917 }
918
919 //____________________________________________________________________________ 
920 void AliPHOSLoader::MakeTrackSegmentsArray()
921 {
922   // Add TrackSegments array to the data folder
923   if ( TrackSegments()) return;
924   TClonesArray * ts = new TClonesArray("AliPHOSTrackSegment",100) ;
925   ts->SetName(fgkTracksName);
926   GetDetectorDataFolder()->Add(ts);
927
928 }
929
930 //____________________________________________________________________________ 
931 void AliPHOSLoader::MakeRecParticlesArray()
932 {
933   // Add RecParticles array to the data folder
934   if ( RecParticles()) return;
935   TClonesArray * rp = new TClonesArray("AliPHOSRecParticle",100) ;
936   rp->SetName(fgkRecParticlesName);
937   GetDetectorDataFolder()->Add(rp);
938 }