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