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