]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSLoader.cxx
defects fixed
[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/tasks
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 = dynamic_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(SDigitsRef());
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   Int_t maxemc = emca->GetEntries() ; 
591   for ( ii= 0 ; ii < maxemc ; ii++ ) 
592     EmcRecPoints()->Add(emca->At(ii)) ;
593  
594   Int_t maxcpv = cpva->GetEntries() ;
595   for ( ii= 0 ; ii < maxcpv ; ii++ )
596     CpvRecPoints()->Add(cpva->At(ii)) ; 
597
598   return retval;
599 }
600
601 //____________________________________________________________________________ 
602 Int_t AliPHOSLoader::ReadTracks()
603 {
604 //Creates and posts to folder an array container, 
605 //connects branch in tree (if exists), and reads data to arry
606
607   TObject** trkref = TracksRef();
608   if ( trkref == 0x0 )   
609    {//Create and post array
610     MakeTrackSegmentsArray();
611     trkref = TracksRef();
612    }
613
614   TTree * treeT = TreeT();
615   if(treeT==0)
616    {
617      //May happen if file is truncated or new in LoadSDigits, or the file is in update mode, 
618      //but tracking was not performed yet for a current event
619      //AliError("There is no Tree with Tracks");
620      return 0;
621    }
622   
623   TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
624 //   AliInfo(Form("Branch named %s is opened: 0x%z",
625 //                fgkTrackSegmentsBranchName.Data(),branch));
626   if (branch == 0) 
627    {//easy, maybe just a new tree
628     AliError(Form("Cannot find branch named %s",
629                   fgkTrackSegmentsBranchName.Data()));
630     return 0;
631   }
632
633   branch->SetAddress(trkref);//connect branch to buffer sitting in folder
634   branch->GetEntry(0);//get first event 
635   
636   return 0;
637 }
638 //____________________________________________________________________________ 
639
640 Int_t AliPHOSLoader::ReadRecParticles()
641 {
642 //Reads Reconstructed  Particles from file
643 //Creates and posts to folder an array container, 
644 //connects branch in tree (if exists), and reads data to arry
645   
646   TObject** recpartref = RecParticlesRef();
647   
648   if ( recpartref == 0x0 )   
649    {//Create and post array
650     MakeRecParticlesArray();
651     recpartref = RecParticlesRef();
652    }
653
654   TTree * treeP = TreeP();
655   if(treeP==0)
656    {
657      //May happen if file is truncated or new in LoadSDigits, 
658      //or the file is in update mode, 
659      //but tracking was not performed yet for a current event
660      //     AliError("There is no Tree with Tracks and Reconstructed Particles");
661      return 0;
662    }
663   
664   TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
665   if (branch == 0) 
666    {//easy, maybe just a new tree
667     AliError(Form("Cannot find branch %s",
668                   fgkRecParticlesBranchName.Data())); 
669     return 0;
670   }
671
672   branch->SetAddress(recpartref);//connect branch to buffer sitting in folder
673   branch->GetEntry(0);//get first event 
674   
675   return 0;
676 }
677
678
679 /***************************************************************************************/
680
681 AliPHOSLoader* AliPHOSLoader::GetPHOSLoader(const  char* eventfoldername)
682 {
683   // Return PHOS loader
684   AliRunLoader* rn  = AliRunLoader::GetRunLoader(eventfoldername);
685   if (rn == 0x0) {
686     printf("Can not find Run Loader in folder %s", eventfoldername);
687     return 0x0 ; 
688   }
689   return dynamic_cast<AliPHOSLoader*>(rn->GetLoader("PHOSLoader"));
690 }
691 /***************************************************************************************/
692
693 Bool_t AliPHOSLoader::BranchExists(const TString& recName)
694 {
695   // Check if a branch named redName exists
696   if (fBranchTitle.IsNull()) return kFALSE;
697   TString dataname, zername ;
698   TTree* tree;
699   if(recName == "SDigits")
700    {
701     tree = TreeS();
702     dataname = GetDetectorName();
703     zername = "AliPHOSSDigitizer" ;
704    }
705   else
706     if(recName == "Digits"){
707       tree = TreeD();
708       dataname = GetDetectorName();
709       zername = "AliPHOSDigitizer" ;
710     }
711     else
712       if(recName == "RecPoints"){
713        tree = TreeR();
714        dataname = fgkEmcRecPointsBranchName;
715        zername = "AliPHOSClusterizer" ;
716       }
717       else
718        if(recName == "TrackSegments"){
719          tree = TreeT();
720          dataname = fgkTrackSegmentsBranchName;
721          zername = "AliPHOSTrackSegmentMaker";
722        }        
723        else
724          if(recName == "RecParticles"){
725            tree = TreeP();
726            dataname = fgkRecParticlesBranchName;
727            zername = "AliPHOSPID";
728          }
729          else
730            return kFALSE ;
731
732   
733   if(!tree ) 
734     return kFALSE ;
735
736   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
737   TIter next(lob) ; 
738   TBranch * branch = 0 ;  
739   TString titleName(fBranchTitle);
740   titleName+=":";
741
742   while ((branch = (static_cast<TBranch*>(next())))) {
743     TString branchName(branch->GetName() ) ; 
744     TString branchTitle(branch->GetTitle() ) ;  
745     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
746       AliWarning(Form("branch %s  with title  %s ",
747                       dataname.Data(),fBranchTitle.Data()));
748       return kTRUE ;
749     }
750     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
751       AliWarning(Form("branch AliPHOS... with title  %s ",
752                       branch->GetTitle()));
753       return kTRUE ; 
754     }
755   }
756   return kFALSE ;
757
758  }
759
760 void AliPHOSLoader::SetBranchTitle(const TString& btitle)
761 {
762   // Set branch title
763   if (btitle.CompareTo(fBranchTitle) == 0) return;
764   fBranchTitle = btitle;
765   ReloadAll();
766  }
767  
768 //____________________________________________________________________________ 
769 //Again, must be const not to hide virtual functions from AliLoader
770 //but there are calls to non-const functions, so I have to const_cast this pointer
771 void AliPHOSLoader::CleanHits()const
772 {
773   // Clean Hits array
774   AliLoader::CleanHits();
775   //Clear an array 
776   TClonesArray* hits = const_cast<AliPHOSLoader *>(this)->Hits();
777   if (hits) hits->Clear();
778 }
779 //____________________________________________________________________________ 
780
781 void AliPHOSLoader::CleanSDigits()const
782 {
783   // Clean SDigits array
784   AliLoader::CleanSDigits();
785   TClonesArray* sdigits = const_cast<AliPHOSLoader *>(this)->SDigits();
786   if (sdigits) sdigits->Clear();
787   
788 }
789 //____________________________________________________________________________ 
790
791 void AliPHOSLoader::CleanDigits()const
792 {
793   // Clean Digits array
794   AliLoader::CleanDigits();
795   TClonesArray* digits = const_cast<AliPHOSLoader *>(this)->Digits();
796   if (digits) digits->Clear();
797 }
798 //____________________________________________________________________________ 
799
800 void AliPHOSLoader::CleanRecPoints()const
801 {
802   // Clean RecPoints array
803   AliLoader::CleanRecPoints();
804   TObjArray* recpoints = const_cast<AliPHOSLoader *>(this)->EmcRecPoints();
805   if (recpoints) recpoints->Clear();
806   recpoints = const_cast<AliPHOSLoader *>(this)->CpvRecPoints();
807   if (recpoints) recpoints->Clear();
808 }
809 //____________________________________________________________________________ 
810
811 void AliPHOSLoader::CleanTracks()const
812 {
813   //Cleans Tracks stuff
814   AliLoader::CleanTracks();//tree
815   
816   //and clear the array
817   TClonesArray* tracks = const_cast<AliPHOSLoader *>(this)->TrackSegments();
818   if (tracks) tracks->Clear();
819
820 }
821 //____________________________________________________________________________ 
822
823 void AliPHOSLoader::CleanRecParticles()
824  {
825    // Clean RecParticles array
826    TClonesArray *recpar = RecParticles();
827    if (recpar) recpar->Clear();
828   
829  
830  }
831 //____________________________________________________________________________ 
832
833 void AliPHOSLoader::MakeHitsArray()
834 {
835   // Add Hits array to the data folder
836   if (Hits()) return;
837   TClonesArray* hits = new TClonesArray("AliPHOSHit",1000);
838   hits->SetName(fgkHitsName);
839   GetDetectorDataFolder()->Add(hits);
840 }
841
842 //____________________________________________________________________________ 
843 void AliPHOSLoader::MakeSDigitsArray()
844 {
845   // Add SDigits array to the data folder
846   if ( SDigits()) return;
847   TClonesArray* sdigits = new TClonesArray("AliPHOSDigit",1);
848   sdigits->SetName(fgkSDigitsName);
849   GetDetectorDataFolder()->Add(sdigits);
850 }
851
852 //____________________________________________________________________________ 
853 void AliPHOSLoader::MakeDigitsArray()
854 {
855   // Add Digits array to the data folder
856   if ( Digits()) return;
857   TClonesArray* digits = new TClonesArray("AliPHOSDigit",1);
858   digits->SetName(fgkDigitsName);
859   GetDetectorDataFolder()->Add(digits);
860   
861 }
862
863 //____________________________________________________________________________ 
864 void AliPHOSLoader::MakeRecPointsArray()
865 {
866   // Add RecPoints array to the data folder
867   if ( EmcRecPoints() == 0x0)
868    {
869      AliDebug(9, "Making array for EMC");
870     TObjArray* emc = new TObjArray(100) ;
871     emc->SetName(fgkEmcRecPointsName) ;
872     GetDetectorDataFolder()->Add(emc);
873    }
874
875   if ( CpvRecPoints() == 0x0)
876    { 
877      AliDebug(9, "Making array for CPV");
878      TObjArray* cpv = new TObjArray(100) ;
879      cpv->SetName(fgkCpvRecPointsName);
880      GetDetectorDataFolder()->Add(cpv);
881    }
882 }
883
884 //____________________________________________________________________________ 
885 void AliPHOSLoader::MakeTrackSegmentsArray()
886 {
887   // Add TrackSegments array to the data folder
888   if ( TrackSegments()) return;
889   TClonesArray * ts = new TClonesArray("AliPHOSTrackSegment",100) ;
890   ts->SetName(fgkTracksName);
891   GetDetectorDataFolder()->Add(ts);
892
893 }
894
895 //____________________________________________________________________________ 
896 void AliPHOSLoader::MakeRecParticlesArray()
897 {
898   // Add RecParticles array to the data folder
899   if ( RecParticles()) return;
900   TClonesArray * rp = new TClonesArray("AliPHOSRecParticle",100) ;
901   rp->SetName(fgkRecParticlesName);
902   GetDetectorDataFolder()->Add(rp);
903 }