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