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