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