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