Coding conventions (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
CommitLineData
48b32e42 1
2// Author: Artur Szostak
3// email: artur@alice.phy.uct.ac.za
4
5#include <TError.h>
30178c30 6#include <TParticle.h>
48b32e42 7
8#include "AliRunLoader.h"
9#include "AliLoader.h"
10
11#include "AliMUONDataInterface.h"
30178c30 12#include "AliMUONLocalTrigger.h"
554b38a6 13#include "AliMUONGlobalTrigger.h"
30178c30 14#include "AliMUONHit.h"
15#include "AliMUONDigit.h"
16#include "AliMUONRawCluster.h"
554b38a6 17#include "AliMUONTrack.h"
8c343c7c 18#include "AliLog.h"
48b32e42 19
6d149c9e 20#include <iostream>
21using std::endl;
22using std::cout;
23
48b32e42 24
25ClassImp(AliMUONDataInterface)
26
85fec35d 27///
28/// \class AliMUONDataInterface
29///
30/// An easy to use interface to the MUON module data stored in
31/// TreeK, TreeH, TreeS, TreeD and TreeR
32/// One can fetch any of the data objects with all the calls to runloader,
33/// muon loader and AliMUONData done behind the scenes and automatically.
34///
35/// This interface in not necessarily the fastest way to fetch the data but
36/// it is the easiest.
37/// Note: If independant calls to the run loader, muon loader or
38/// AliMUONData objects are interspersed with calls to the
39/// AliMUONDataInterface to fetch data, one might need to call the Reset
40/// method between these method calls at some point to prevent
41/// AliMUONDataInterface from getting confused.
42/// This is necessary since this object assumes the state of runloader,
43/// muon loader nor AliMUONData has not changed between calls.
44/// If the state has changes then one must call Reset so that
45/// AliMUONDataInterface refreshes what it knows about the state
46/// of the loader and AliMUONData objects.
47///
48/// \deprecated We have to revisit all this AliMUONData stuff anyway,
49/// and probably make a real AliMUONLoader instead...
50///
48b32e42 51
52AliMUONDataInterface::AliMUONDataInterface()
53 : TObject(), fData(NULL, "MUON", "MUON")
54{
55// Set all internal pointers to NULL and indices to -1.
56
57 Reset();
925e6570 58}
48b32e42 59
11ca64ac 60AliMUONDataInterface::AliMUONDataInterface(const AliMUONDataInterface& rhs)
61 : TObject(rhs)
62{
63// Protected copy constructor
64
8c343c7c 65 AliFatal("Not implemented.");
11ca64ac 66}
48b32e42 67
68AliMUONDataInterface::~AliMUONDataInterface()
69{
6d149c9e 70// Delete the runloader if we created it.
48b32e42 71// If the runloader is not to be deleted then call Reset just before
72// the destructor is called.
73
6d149c9e 74 if (fRunloader != NULL && fCreatedRunLoader)
48b32e42 75 delete fRunloader;
925e6570 76}
48b32e42 77
11ca64ac 78AliMUONDataInterface&
79AliMUONDataInterface::operator=(const AliMUONDataInterface& rhs)
80{
81// Protected assignement operator
82
83 if (this == &rhs) return *this;
84
8c343c7c 85 AliFatal("Not implemented.");
11ca64ac 86
87 return *this;
88}
89
48b32e42 90
91void AliMUONDataInterface::Reset()
92{
93// Sets all internal pointers to NULL and indices to -1.
94// Note: No resources are released!
95// Specificaly AliRunLoader is not deleted.
96
6d149c9e 97 fCreatedRunLoader = kFALSE;
48b32e42 98 fRunloader = NULL;
99 fMuonloader = NULL;
100 fEventnumber = -1;
101 fTrack = -1;
102 fSCathode = -1;
103 fCathode = -1;
104 fHitAddressSet = kFALSE;
105 fSDigitAddressSet = kFALSE;
106 fDigitAddressSet = kFALSE;
107 fClusterAddressSet = kFALSE;
108 fTriggerAddressSet = kFALSE;
554b38a6 109 fRecTracksAddressSet = kFALSE;
925e6570 110}
48b32e42 111
112
6d149c9e 113Bool_t AliMUONDataInterface::UseCurrentRunLoader()
114{
115// Tries to fetch the current runloader with AliRunLoader::GetRunLoader. If nothing is
116// currently loaded then kFALSE is returned and AliMUONDataInterface is reset.
117
118 Reset();
119 fRunloader = AliRunLoader::GetRunLoader();
120 if (fRunloader == NULL) return kFALSE;
121 // Fetch the current file name, folder name and event number.
122 fFilename = fRunloader->GetFileName();
123 fFoldername = fRunloader->GetEventFolder()->GetName();
124 fEventnumber = fRunloader->GetEventNumber();
125
126 if ( ! FetchMuonLoader(fFilename.Data(), fFoldername.Data()) )
127 {
128 Reset();
129 return kFALSE;
130 }
131
132 return kTRUE;
133}
134
135
136Bool_t AliMUONDataInterface::FetchMuonLoader(TString filename, TString foldername)
137{
85fec35d 138 // fetches the muon loader for the given filename/foldername
139
6d149c9e 140 fMuonloader = fRunloader->GetLoader("MUONLoader");
141 if (fMuonloader == NULL)
142 {
143 AliError(Form("Could not find the MUON loader in file: %s and folder: %s",
144 (const char*)filename, (const char*)foldername));
145 return kFALSE;
146 }
147
148 // Need to connect the muon loader to the AliMUONData object,
149 // else class to fData will return NULL.
150 fData.SetLoader(fMuonloader);
151 return kTRUE;
152}
153
154
48b32e42 155Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
156{
157// Load the run and muon loaders from the specified file and folder.
158// kTRUE is returned on success and kFALSE on failure.
159
160 fRunloader = AliRunLoader::Open(filename, foldername, "READ");
161 if (fRunloader == NULL)
162 {
8c343c7c 163 AliError(Form("Could not find or load the run loader for the file: %s and folder: %s",
164 (const char*)filename, (const char*)foldername));
48b32e42 165 return kFALSE;
925e6570 166 }
6d149c9e 167 fCreatedRunLoader = kTRUE;
168 if ( ! FetchMuonLoader(filename, foldername) )
48b32e42 169 {
48b32e42 170 fRunloader = NULL;
171 return kFALSE;
925e6570 172 }
48b32e42 173
48b32e42 174 fFilename = filename;
175 fFoldername = foldername;
176 fEventnumber = -1; // Reset the event number to force the event to be loaded.
177 return kTRUE;
925e6570 178}
48b32e42 179
180
181Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
182{
183// Fetch the run loader and muon loader objects from memory if they already exist,
184// or from memory if they do not.
185// If the currently loaded run loader (if any) is not refering to the file and folder
186// we are interested in then it is deleted and reopened with the required file and
187// folder names.
188
189 if (fRunloader == NULL)
190 {
191 fRunloader = AliRunLoader::GetRunLoader();
192 if (fRunloader == NULL)
193 return LoadLoaders(filename, foldername);
6d149c9e 194 else
195 {
196 if (fMuonloader == NULL)
197 {
198 if ( ! FetchMuonLoader(filename, foldername) )
199 {
200 fRunloader = NULL;
201 return kFALSE;
202 }
203 }
204 }
48b32e42 205
206 // Fetch the current file and folder names.
207 fFilename = fRunloader->GetFileName();
208 fFoldername = fRunloader->GetEventFolder()->GetName();
925e6570 209 }
48b32e42 210
211 // If filename or foldername are not the same as the ones currently selected then
212 // reopen the file.
213 if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
214 {
215 delete fRunloader;
216 return LoadLoaders(filename, foldername);
925e6570 217 }
48b32e42 218 return kTRUE;
925e6570 219}
48b32e42 220
221
222Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
223{
224// Fetch the specified event from the runloader and reset all the track, cathode
225// and address flags to force them to be reloaded.
6d149c9e 226// If a negative event number is specified then the current runloader event
227// number is used.
48b32e42 228
229 if (fEventnumber < 0)
230 {
231 fEventnumber = fRunloader->GetEventNumber();
232 fTrack = -1;
233 fSCathode = -1;
234 fCathode = -1;
235 fHitAddressSet = kFALSE;
236 fSDigitAddressSet = kFALSE;
237 fDigitAddressSet = kFALSE;
238 fClusterAddressSet = kFALSE;
239 fTriggerAddressSet = kFALSE;
554b38a6 240 fRecTracksAddressSet = kFALSE;
925e6570 241 }
48b32e42 242 if ( event != fEventnumber )
243 {
244 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
245 fEventnumber = event;
246 fTrack = -1;
247 fSCathode = -1;
248 fCathode = -1;
249 fHitAddressSet = kFALSE;
250 fSDigitAddressSet = kFALSE;
251 fDigitAddressSet = kFALSE;
252 fClusterAddressSet = kFALSE;
253 fTriggerAddressSet = kFALSE;
554b38a6 254 fRecTracksAddressSet = kFALSE;
925e6570 255 }
48b32e42 256 return kTRUE;
925e6570 257}
48b32e42 258
259
260Bool_t AliMUONDataInterface::FetchTreeK()
261{
262// Fetch the Kine tree from the current run loader.
263
264 if (fRunloader->TreeK() == NULL)
265 {
266 fRunloader->LoadKinematics("READ");
267 if (fRunloader->TreeK() == NULL)
268 {
8c343c7c 269 AliError("Could not load TreeK.");
48b32e42 270 return kFALSE;
925e6570 271 }
272 }
48b32e42 273 return kTRUE;
925e6570 274}
48b32e42 275
276
277Bool_t AliMUONDataInterface::FetchTreeH()
278{
279// Fetch the Hits tree from the current muon loader.
280// Set all the required addresses etc...
281
282 if (fMuonloader->TreeH() == NULL)
283 {
284 fMuonloader->LoadHits("READ");
285 if (fMuonloader->TreeH() == NULL)
286 {
8c343c7c 287 AliError("Could not load TreeH.");
48b32e42 288 return kFALSE;
925e6570 289 }
48b32e42 290 fData.SetTreeAddress("H");
291 fHitAddressSet = kTRUE;
292 }
293 else if ( ! fHitAddressSet )
294 {
295 fData.SetTreeAddress("H");
296 fHitAddressSet = kTRUE;
925e6570 297 }
48b32e42 298 return kTRUE;
925e6570 299}
48b32e42 300
301
302Bool_t AliMUONDataInterface::FetchTreeS()
303{
304// Fetch the S-Digits tree from the current muon loader.
305// Set all the required addresses etc...
306
307 if (fMuonloader->TreeS() == NULL)
308 {
309 fMuonloader->LoadSDigits("READ");
310 if (fMuonloader->TreeS() == NULL)
311 {
8c343c7c 312 AliError("Could not load TreeS.");
48b32e42 313 return kFALSE;
925e6570 314 }
48b32e42 315 fData.SetTreeAddress("S");
316 fSDigitAddressSet = kTRUE;
317 }
318 else if ( ! fSDigitAddressSet )
319 {
320 fData.SetTreeAddress("S");
321 fSDigitAddressSet = kTRUE;
925e6570 322 }
48b32e42 323 return kTRUE;
925e6570 324}
48b32e42 325
326
327Bool_t AliMUONDataInterface::FetchTreeD()
328{
329// Fetch the digits tree from the current muon loader.
330// Set all the required addresses etc...
331
332 if (fMuonloader->TreeD() == NULL)
333 {
334 fMuonloader->LoadDigits("READ");
335 if (fMuonloader->TreeD() == NULL)
336 {
8c343c7c 337 AliError("Could not load TreeD.");
48b32e42 338 return kFALSE;
925e6570 339 }
48b32e42 340 fData.SetTreeAddress("D");
341 fDigitAddressSet = kTRUE;
342 }
343 else if ( ! fDigitAddressSet )
344 {
345 fData.SetTreeAddress("D");
346 fDigitAddressSet = kTRUE;
925e6570 347 }
48b32e42 348 return kTRUE;
925e6570 349}
48b32e42 350
351
352Bool_t AliMUONDataInterface::FetchTreeR()
353{
554b38a6 354 // Fetch the reconstructed objects tree from the current muon loader.
355 // Note: The addresses must still be set.
356
357 if (fMuonloader->TreeR() == NULL)
358 {
359 fMuonloader->LoadRecPoints("READ");
360 if (fMuonloader->TreeR() == NULL)
48b32e42 361 {
554b38a6 362 AliError("Could not load TreeR.");
363 return kFALSE;
925e6570 364 }
554b38a6 365
366 // Need to reset these flags so that the cluster and trigger address
367 // gets reset after this method.
368 fClusterAddressSet = kFALSE;
369 fTriggerAddressSet = kFALSE;
370 }
371 return kTRUE;
925e6570 372}
48b32e42 373
554b38a6 374Bool_t AliMUONDataInterface::FetchTreeT()
375{
376 // fetch the reconstructed tracks tree from the current muon loader
377 // note : the addresses must still be set.
378 if (fMuonloader->TreeT() == NULL)
379 {
380 fMuonloader->LoadTracks("READ");
381 if (fMuonloader->TreeT() == NULL)
382 {
383 AliError("Could not load TreeT.");
384 return kFALSE;
385 }
386
387 // Need to reset these flags so that the rec tracks address
388 // gets reset after this method.
389 fRecTracksAddressSet = kFALSE;
390 }
391 return kTRUE;
392}
393
48b32e42 394Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
395{
396// Returns the number of events in the specified file/folder, and -1 on error.
397
398 if ( ! FetchLoaders(filename, foldername) ) return -1;
399 return fRunloader->GetNumberOfEvents();
925e6570 400}
48b32e42 401
402
403Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
404{
405// Returns the number of events in the specified file/folder, and -1 on error.
406
407 if ( ! FetchLoaders(filename, foldername) ) return -1;
408 if ( ! FetchEvent(event) ) return -1;
409 if ( ! FetchTreeK() ) return -1;
410 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
925e6570 411}
48b32e42 412
413
414TParticle* AliMUONDataInterface::Particle(
415 TString filename, TString foldername, Int_t event, Int_t particle
416 )
417{
418// Returns the specified particle in the given file, folder and event.
419// NULL is returned on error.
420
421 if ( ! FetchLoaders(filename, foldername) ) return NULL;
422 if ( ! FetchEvent(event) ) return NULL;
423 if ( ! FetchTreeK() ) return NULL;
424
425 TTree* treeK = fRunloader->TreeK();
426 TParticle* p = NULL;
427 treeK->GetBranch("Particles")->SetAddress(&p);
428 treeK->GetEvent(particle);
429 return p;
925e6570 430}
48b32e42 431
432
433Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
434{
435// Returns the number of tracks in the specified file/folder and event.
436// -1 is returned on error.
437
438 if ( ! FetchLoaders(filename, foldername) ) return -1;
439 if ( ! FetchEvent(event) ) return -1;
440 if ( ! FetchTreeH() ) return -1;
441 return fData.GetNtracks();
925e6570 442}
48b32e42 443
444
445Int_t AliMUONDataInterface::NumberOfHits(
446 TString filename, TString foldername, Int_t event, Int_t track
447 )
448{
449// Returns the number of hits in the specified file/folder, event and track.
450// -1 is returned on error.
451
452 if ( ! FetchLoaders(filename, foldername) ) return -1;
453 if ( ! FetchEvent(event) ) return -1;
454 if ( ! FetchTreeH() ) return -1;
455
456 if (fTrack < 0 || fTrack != track)
457 {
458 fData.ResetHits();
459 fData.GetTrack(track);
460 fTrack = track;
925e6570 461 }
48b32e42 462 return fData.Hits()->GetEntriesFast();
925e6570 463}
48b32e42 464
465
466AliMUONHit* AliMUONDataInterface::Hit(
467 TString filename, TString foldername, Int_t event,
468 Int_t track, Int_t hit
469 )
470{
471// Returns the specified hit in the given file, folder, event and track.
472// NULL is returned on error.
473
474 if ( ! FetchLoaders(filename, foldername) ) return NULL;
475 if ( ! FetchEvent(event) ) return NULL;
476 if ( ! FetchTreeH() ) return NULL;
477
478 if (fTrack < 0 || fTrack != track)
479 {
480 fData.ResetHits();
481 fData.GetTrack(track);
482 fTrack = track;
925e6570 483 }
48b32e42 484 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
925e6570 485}
48b32e42 486
487
488Int_t AliMUONDataInterface::NumberOfSDigits(
489 TString filename, TString foldername, Int_t event,
490 Int_t chamber, Int_t cathode
491 )
492{
493// Returns the number of s-digits in the given file, folder, event,
494// chamber and cathode. -1 is returned on error.
495
496 Assert( 0 <= chamber && chamber <= 13 );
497 Assert( 0 <= cathode && cathode <= 1 );
498
499 if ( ! FetchLoaders(filename, foldername) ) return -1;
500 if ( ! FetchEvent(event) ) return -1;
501 if ( ! FetchTreeS() ) return -1;
502
503 if ( fSCathode != cathode )
504 {
505 fData.ResetSDigits();
935b9895 506 fData.GetSDigits();
48b32e42 507 fSCathode = cathode;
925e6570 508 }
48b32e42 509 return fData.SDigits(chamber)->GetEntriesFast();
925e6570 510}
48b32e42 511
512
513AliMUONDigit* AliMUONDataInterface::SDigit(
514 TString filename, TString foldername, Int_t event,
515 Int_t chamber, Int_t cathode, Int_t sdigit
516 )
517{
518// Returns the specified s-digit in the given file, folder, event,
519// chamber and cathode. NULL is returned on error.
520
521 Assert( 0 <= chamber && chamber <= 13 );
522 Assert( 0 <= cathode && cathode <= 1 );
523
524 if ( ! FetchLoaders(filename, foldername) ) return NULL;
525 if ( ! FetchEvent(event) ) return NULL;
526 if ( ! FetchTreeS() ) return NULL;
527
528 if ( fSCathode != cathode )
529 {
530 fData.ResetSDigits();
935b9895 531 fData.GetSDigits();
48b32e42 532 fSCathode = cathode;
925e6570 533 }
48b32e42 534 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
925e6570 535}
48b32e42 536
537
538Int_t AliMUONDataInterface::NumberOfDigits(
539 TString filename, TString foldername, Int_t event,
540 Int_t chamber, Int_t cathode
541 )
542{
543// Returns the number of digits in the given file, folder, event,
544// chamber and cathode. -1 is returned on error.
545 Assert( 0 <= chamber && chamber <= 13 );
546 Assert( 0 <= cathode && cathode <= 1 );
547
548 if ( ! FetchLoaders(filename, foldername) ) return -1;
549 if ( ! FetchEvent(event) ) return -1;
550 if ( ! FetchTreeD() ) return -1;
551
552 if ( fCathode != cathode )
553 {
554 fData.ResetDigits();
935b9895 555 fData.GetDigits();
48b32e42 556 fCathode = cathode;
925e6570 557 }
48b32e42 558 return fData.Digits(chamber)->GetEntriesFast();
925e6570 559}
48b32e42 560
561
562AliMUONDigit* AliMUONDataInterface::Digit(
563 TString filename, TString foldername, Int_t event,
564 Int_t chamber, Int_t cathode, Int_t digit
565 )
566{
567// Returns the specified digit in the given file, folder, event,
568// chamber and cathode. NULL is returned on error.
569
570 Assert( 0 <= chamber && chamber <= 13 );
571 Assert( 0 <= cathode && cathode <= 1 );
572
573 if ( ! FetchLoaders(filename, foldername) ) return NULL;
574 if ( ! FetchEvent(event) ) return NULL;
575 if ( ! FetchTreeD() ) return NULL;
576
577 if ( fCathode != cathode )
578 {
579 fData.ResetDigits();
935b9895 580 fData.GetDigits();
48b32e42 581 fCathode = cathode;
925e6570 582 }
48b32e42 583 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
925e6570 584}
48b32e42 585
586
587Int_t AliMUONDataInterface::NumberOfRawClusters(
588 TString filename, TString foldername, Int_t event, Int_t chamber
589 )
590{
591// Returns the number of raw clusters in the specified file, folder, event and chamber.
592// -1 is returned or error.
593
594 Assert( 0 <= chamber && chamber <= 13 );
595 if ( ! FetchLoaders(filename, foldername) ) return -1;
596 if ( ! FetchEvent(event) ) return -1;
597 if ( ! FetchTreeR() ) return -1;
598 if ( ! fClusterAddressSet )
599 {
600 // If the raw cluster address in TreeR is not set yet then set it now.
601 fData.SetTreeAddress("RC");
602 fData.ResetRawClusters();
603 fData.GetRawClusters();
604 fClusterAddressSet = kTRUE;
925e6570 605 }
48b32e42 606 return fData.RawClusters(chamber)->GetEntriesFast();
925e6570 607}
48b32e42 608
609
610AliMUONRawCluster* AliMUONDataInterface::RawCluster(
611 TString filename, TString foldername, Int_t event,
612 Int_t chamber, Int_t cluster
613 )
614{
615// Fetch the specified raw cluster from the given file, folder, event and chamber number.
616// NULL is returned on error.
617
618 Assert( 0 <= chamber && chamber <= 13 );
619 if ( ! FetchLoaders(filename, foldername) ) return NULL;
620 if ( ! FetchEvent(event) ) return NULL;
621 if ( ! FetchTreeR() ) return NULL;
622 if ( ! fClusterAddressSet )
623 {
624 // If the raw cluster address in TreeR is not set yet then set it now.
625 fData.SetTreeAddress("RC");
626 fData.ResetRawClusters();
627 fData.GetRawClusters();
628 fClusterAddressSet = kTRUE;
925e6570 629 }
48b32e42 630 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
925e6570 631}
48b32e42 632
633
634Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
635{
636// Return the number of local trigger objects in the specified file, folder and
637// event number. -1 is returned on error.
638
639 if ( ! FetchLoaders(filename, foldername) ) return -1;
640 if ( ! FetchEvent(event) ) return -1;
6d149c9e 641 if ( ! FetchTreeD() ) return -1;
48b32e42 642 if ( ! fTriggerAddressSet )
643 {
935b9895 644 // If the local trigger address in TreeR is not set yet then set it now.
48b32e42 645 fData.SetTreeAddress("GLT");
646 fData.ResetTrigger();
6d149c9e 647 fData.GetTriggerD();
48b32e42 648 fTriggerAddressSet = kTRUE;
925e6570 649 }
48b32e42 650 return fData.LocalTrigger()->GetEntriesFast();
925e6570 651}
48b32e42 652
653
654AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
655 TString filename, TString foldername, Int_t event, Int_t trigger
656 )
657{
658// Fetch the specified local trigger object from the given file, folder and event number.
659// NULL is returned on error.
660
661 if ( ! FetchLoaders(filename, foldername) ) return NULL;
662 if ( ! FetchEvent(event) ) return NULL;
6d149c9e 663 if ( ! FetchTreeD() ) return NULL;
48b32e42 664 if ( ! fTriggerAddressSet )
665 {
935b9895 666 // If the local trigger address in TreeR is not set yet then set it now.
48b32e42 667 fData.SetTreeAddress("GLT");
668 fData.ResetTrigger();
6d149c9e 669 fData.GetTriggerD();
48b32e42 670 fTriggerAddressSet = kTRUE;
925e6570 671 }
48b32e42 672 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
925e6570 673}
48b32e42 674
48b32e42 675Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
676{
677// Set the current file and folder from which to fetch data.
678// kTRUE is returned if the run and muon loaders were found, else kFALSE.
679
680 return FetchLoaders(filename, foldername);
925e6570 681}
48b32e42 682
683
684Bool_t AliMUONDataInterface::GetEvent(Int_t event)
685{
686// Select the current event from which to fetch data.
687// kTRUE is returned if the event was found, else kFALSE is returned.
688
382c2b3f 689 if (fRunloader == NULL)
690 {
691 AliError("File not set.");
692 return kFALSE;
693 }
694 else
695 return FetchEvent(event);
925e6570 696}
48b32e42 697
698
699Int_t AliMUONDataInterface::NumberOfEvents()
700{
701// Get the number of events in the currently selected file.
702// -1 is returned on error.
703
704 if (fRunloader == NULL)
705 {
8c343c7c 706 AliError("File not set.");
48b32e42 707 return -1;
925e6570 708 }
48b32e42 709 return fRunloader->GetNumberOfEvents();
925e6570 710}
48b32e42 711
712
713Int_t AliMUONDataInterface::NumberOfParticles()
714{
715// Get the number of particles in the current event.
716// -1 is returned on error.
717
718 if (fRunloader == NULL)
719 {
8c343c7c 720 AliError("File not set.");
48b32e42 721 return -1;
925e6570 722 }
48b32e42 723 if ( ! FetchTreeK() ) return -1;
724 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
925e6570 725}
48b32e42 726
727
728TParticle* AliMUONDataInterface::Particle(Int_t particle)
729{
730// Fetch the specified particle from the current event.
731// NULL is returned on error.
732
733 if (fRunloader == NULL)
734 {
8c343c7c 735 AliError("File not set.");
48b32e42 736 return NULL;
925e6570 737 }
48b32e42 738 if (fEventnumber < 0)
739 {
8c343c7c 740 AliError("Event not chosen.");
48b32e42 741 return NULL;
925e6570 742 }
48b32e42 743 if ( ! FetchTreeK() ) return NULL;
744 TTree* treeK = fRunloader->TreeK();
745 TParticle* p = NULL;
746 treeK->GetBranch("Particles")->SetAddress(&p);
747 treeK->GetEvent(particle);
748 return p;
925e6570 749}
48b32e42 750
751
752Int_t AliMUONDataInterface::NumberOfTracks()
753{
754// Get the number of tracks in the current event.
755// -1 is returned on error.
756
757 if (fRunloader == NULL)
758 {
8c343c7c 759 AliError("File not set.");
48b32e42 760 return -1;
925e6570 761 }
48b32e42 762 if (fEventnumber < 0)
763 {
8c343c7c 764 AliError( "Event not chosen.");
48b32e42 765 return -1;
925e6570 766 }
48b32e42 767 if ( ! FetchTreeH() ) return -1;
768 return fData.GetNtracks();
925e6570 769}
48b32e42 770
771
772Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
773{
774// Get the number of hits for the given track in the current event.
775// -1 is returned on error.
776
777 if (fRunloader == NULL)
778 {
8c343c7c 779 AliError("File not set.");
48b32e42 780 return -1;
925e6570 781 }
48b32e42 782 if (fEventnumber < 0)
783 {
8c343c7c 784 AliError("Event not chosen.");
48b32e42 785 return -1;
925e6570 786 }
48b32e42 787 if ( ! FetchTreeH() ) return -1;
788 if (fTrack < 0 || fTrack != track)
789 {
790 fData.ResetHits();
791 fData.GetTrack(track);
792 fTrack = track;
925e6570 793 }
48b32e42 794 return fData.Hits()->GetEntriesFast();
925e6570 795}
48b32e42 796
797
798AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
799{
800// Fetch the specified hit from the current event.
801// NULL is returned on error.
802
803 if (fRunloader == NULL)
804 {
8c343c7c 805 AliError("File not set.");
48b32e42 806 return NULL;
925e6570 807 }
48b32e42 808 if (fEventnumber < 0)
809 {
8c343c7c 810 AliError("Event not chosen.");
48b32e42 811 return NULL;
925e6570 812 }
48b32e42 813 if ( ! FetchTreeH() ) return NULL;
814 if (fTrack < 0 || fTrack != track)
815 {
816 fData.ResetHits();
817 fData.GetTrack(track);
818 fTrack = track;
925e6570 819 }
48b32e42 820 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
925e6570 821}
48b32e42 822
823
824Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
825{
826// Get the number of s-digits on the chamber, cathode in the current event.
827// -1 is returned on error.
828
829 Assert( 0 <= chamber && chamber <= 13 );
830 Assert( 0 <= cathode && cathode <= 1 );
831
832 if (fRunloader == NULL)
833 {
8c343c7c 834 AliError("File not set.");
48b32e42 835 return -1;
925e6570 836 }
48b32e42 837 if (fEventnumber < 0)
838 {
8c343c7c 839 AliError("Event not chosen.");
48b32e42 840 return -1;
925e6570 841 }
48b32e42 842
843 if ( ! FetchTreeS() ) return -1;
844 if ( fSCathode != cathode )
845 {
846 fData.ResetSDigits();
935b9895 847 fData.GetSDigits();
48b32e42 848 fSCathode = cathode;
925e6570 849 }
48b32e42 850 return fData.SDigits(chamber)->GetEntriesFast();
925e6570 851}
48b32e42 852
853
854AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
855{
856// Fetch the specified s-digits on the chamber, cathode from the current event.
857// NULL is returned on error.
858
859 Assert( 0 <= chamber && chamber <= 13 );
860 Assert( 0 <= cathode && cathode <= 1 );
861
862 if (fRunloader == NULL)
863 {
8c343c7c 864 AliError("File not set.");
48b32e42 865 return NULL;
925e6570 866 }
48b32e42 867 if (fEventnumber < 0)
868 {
8c343c7c 869 AliError("Event not chosen.");
48b32e42 870 return NULL;
925e6570 871 }
48b32e42 872
873 if ( ! FetchTreeS() ) return NULL;
874 if ( fSCathode != cathode )
875 {
876 fData.ResetSDigits();
935b9895 877 fData.GetSDigits();
48b32e42 878 fSCathode = cathode;
925e6570 879 }
48b32e42 880 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
925e6570 881}
48b32e42 882
883
884Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
885{
886// Get the number of digits on the chamber, cathode in the current event.
887// -1 is returned on error.
888
889 Assert( 0 <= chamber && chamber <= 13 );
890 Assert( 0 <= cathode && cathode <= 1 );
891
892 if (fRunloader == NULL)
893 {
8c343c7c 894 AliError("File not set.");
48b32e42 895 return -1;
925e6570 896 }
48b32e42 897 if (fEventnumber < 0)
898 {
8c343c7c 899 AliError("Event not chosen.");
48b32e42 900 return -1;
925e6570 901 }
48b32e42 902
903 if ( ! FetchTreeD() ) return -1;
904 if ( fCathode != cathode )
905 {
906 fData.ResetDigits();
935b9895 907 fData.GetDigits();
48b32e42 908 fCathode = cathode;
925e6570 909 }
48b32e42 910 return fData.Digits(chamber)->GetEntriesFast();
925e6570 911}
48b32e42 912
913
914AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
915{
916// Fetch the specified digits on the chamber, cathode from the current event.
917// NULL is returned on error.
918
919 Assert( 0 <= chamber && chamber <= 13 );
920 Assert( 0 <= cathode && cathode <= 1 );
921
922 if (fRunloader == NULL)
923 {
8c343c7c 924 AliError("File not set.");
48b32e42 925 return NULL;
925e6570 926 }
48b32e42 927 if (fEventnumber < 0)
928 {
8c343c7c 929 AliError("Event not chosen.");
48b32e42 930 return NULL;
925e6570 931 }
48b32e42 932
933 if ( ! FetchTreeD() ) return NULL;
934 if ( fCathode != cathode )
935 {
936 fData.ResetDigits();
935b9895 937 fData.GetDigits();
48b32e42 938 fCathode = cathode;
925e6570 939 }
48b32e42 940 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
925e6570 941}
48b32e42 942
943
944Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
945{
946// Get the number of raw clusters on the given chamber in the current event.
947// -1 is returned on error.
948
949 Assert( 0 <= chamber && chamber <= 13 );
950
951 if (fRunloader == NULL)
952 {
8c343c7c 953 AliError("File not set.");
48b32e42 954 return -1;
925e6570 955 }
48b32e42 956 if (fEventnumber < 0)
957 {
8c343c7c 958 AliError("Event not chosen.");
48b32e42 959 return -1;
925e6570 960 }
48b32e42 961
962 if ( ! FetchTreeR() ) return -1;
963 if ( ! fClusterAddressSet )
964 {
965 fData.SetTreeAddress("RC");
966 fData.ResetRawClusters();
967 fData.GetRawClusters();
968 fClusterAddressSet = kTRUE;
925e6570 969 }
48b32e42 970 return fData.RawClusters(chamber)->GetEntriesFast();
925e6570 971}
48b32e42 972
973
974AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
975{
976// Fetch the specified raw cluster on the given chamber from the current event.
977// NULL is returned on error.
978
979 Assert( 0 <= chamber && chamber <= 13 );
980
981 if (fRunloader == NULL)
982 {
8c343c7c 983 AliError("File not set.");
48b32e42 984 return NULL;
925e6570 985 }
48b32e42 986 if (fEventnumber < 0)
987 {
8c343c7c 988 AliError("Event not chosen.");
48b32e42 989 return NULL;
925e6570 990 }
48b32e42 991
992 if ( ! FetchTreeR() ) return NULL;
993 if ( ! fClusterAddressSet )
994 {
995 fData.SetTreeAddress("RC");
996 fData.ResetRawClusters();
997 fData.GetRawClusters();
998 fClusterAddressSet = kTRUE;
925e6570 999 }
48b32e42 1000 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
925e6570 1001}
48b32e42 1002
1003
1004Int_t AliMUONDataInterface::NumberOfLocalTriggers()
1005{
1006// Get the number of local trigger objects in the current event.
1007// -1 is returned on error.
1008
1009 if (fRunloader == NULL)
1010 {
8c343c7c 1011 AliError("File not set.");
48b32e42 1012 return -1;
925e6570 1013 }
48b32e42 1014 if (fEventnumber < 0)
1015 {
8c343c7c 1016 AliError("Event not chosen.");
48b32e42 1017 return -1;
925e6570 1018 }
48b32e42 1019
6d149c9e 1020 if ( ! FetchTreeD() ) return -1;
48b32e42 1021 if ( ! fTriggerAddressSet )
1022 {
1023 fData.SetTreeAddress("GLT");
1024 fData.ResetTrigger();
6d149c9e 1025 fData.GetTriggerD();
48b32e42 1026 fTriggerAddressSet = kTRUE;
925e6570 1027 }
48b32e42 1028 return fData.LocalTrigger()->GetEntriesFast();
925e6570 1029}
48b32e42 1030
1031
1032AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
1033{
1034// Fetch the specified local trigger object from the current event.
1035// NULL is returned on error.
1036
1037 if (fRunloader == NULL)
1038 {
8c343c7c 1039 AliError("File not set.");
48b32e42 1040 return NULL;
925e6570 1041 }
48b32e42 1042 if (fEventnumber < 0)
1043 {
8c343c7c 1044 AliError( "Event not chosen.");
48b32e42 1045 return NULL;
925e6570 1046 }
48b32e42 1047
6d149c9e 1048 if ( ! FetchTreeD() ) return NULL;
48b32e42 1049 if ( ! fTriggerAddressSet )
1050 {
1051 fData.SetTreeAddress("GLT");
1052 fData.ResetTrigger();
6d149c9e 1053 fData.GetTriggerD();
48b32e42 1054 fTriggerAddressSet = kTRUE;
925e6570 1055 }
48b32e42 1056 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
925e6570 1057}
554b38a6 1058
1059Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
1060{
1061
1062 // Get the number of local trigger objects in the current event.
1063 // -1 is returned on error.
1064
1065 if (fRunloader == NULL)
1066 {
1067 AliError("File not set.");
1068 return -1;
1069 }
1070 if (fEventnumber < 0)
1071 {
1072 AliError("Event not chosen.");
1073 return -1;
1074 }
1075
1076 if ( ! FetchTreeD() ) return -1;
1077 if ( ! fTriggerAddressSet )
1078 {
1079 fData.SetTreeAddress("GLT");
1080 fData.ResetTrigger();
1081 fData.GetTriggerD();
1082 fTriggerAddressSet = kTRUE;
1083 }
1084 return fData.GlobalTrigger()->GetEntriesFast();
1085}
1086
1087AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t trigger)
1088{
1089 // Fetch the specified local trigger object from the current event.
1090 // NULL is returned on error.
1091
1092 if (fRunloader == NULL)
1093 {
1094 AliError("File not set.");
1095 return NULL;
1096 }
1097 if (fEventnumber < 0)
1098 {
1099 AliError( "Event not chosen.");
1100 return NULL;
1101 }
1102
1103 if ( ! FetchTreeD() ) return NULL;
1104 if ( ! fTriggerAddressSet )
1105 {
1106 fData.SetTreeAddress("GLT");
1107 fData.ResetTrigger();
1108 fData.GetTriggerD();
1109 fTriggerAddressSet = kTRUE;
1110 }
1111 return static_cast<AliMUONGlobalTrigger*>( fData.GlobalTrigger()->At(trigger) );
1112}
1113
1114Int_t AliMUONDataInterface::NumberOfRecTracks()
1115{
1116 // Fetch the number of reconstructed tracks from the current event.
1117 // NULL is returned on error.
1118
1119 if (fRunloader == NULL)
1120 {
1121 AliError("File not set.");
1122 return -1;
1123 }
1124 if (fEventnumber < 0)
1125 {
1126 AliError( "Event not chosen.");
1127 return -1;
1128 }
1129
1130 if ( ! FetchTreeT() ) return -1;
1131 if ( ! fRecTracksAddressSet )
1132 {
1133 fData.SetTreeAddress("RT");
1134 fData.ResetRecTracks();
1135 fData.GetRecTracks();
1136 fRecTracksAddressSet = kTRUE;
1137 }
1138 return fData.RecTracks()->GetEntriesFast();
1139}
1140
1141AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t rectrack)
1142{
1143 // Fetch the specified reconstructed track object from the current event.
1144 // NULL is returned on error.
1145
1146 if (fRunloader == NULL)
1147 {
1148 AliError("File not set.");
1149 return NULL;
1150 }
1151 if (fEventnumber < 0)
1152 {
1153 AliError( "Event not chosen.");
1154 return NULL;
1155 }
1156
1157 if ( ! FetchTreeT() ) return NULL;
1158 if ( ! fRecTracksAddressSet )
1159 {
1160 fData.SetTreeAddress("RT");
1161 fData.ResetRecTracks();
1162 fData.GetRecTracks();
1163 fRecTracksAddressSet = kTRUE;
1164 }
1165 return static_cast<AliMUONTrack*>( fData.RecTracks()->At(rectrack) );
1166 // return (AliMUONTrack*)(fData.RecTracks()->At(rectrack));
1167}