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