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