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