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