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