2 // Author: Artur Szostak
3 // email: artur@alice.phy.uct.ac.za
7 #include "AliRunLoader.h"
10 #include "AliMUONDataInterface.h"
11 #include "AliMUONData.h"
14 ClassImp(AliMUONDataInterface)
17 AliMUONDataInterface::AliMUONDataInterface()
18 : TObject(), fData(NULL, "MUON", "MUON")
20 // Set all internal pointers to NULL and indices to -1.
26 AliMUONDataInterface::~AliMUONDataInterface()
28 // Delete the runloader when done.
29 // If the runloader is not to be deleted then call Reset just before
30 // the destructor is called.
32 if (fRunloader != NULL)
37 void AliMUONDataInterface::Reset()
39 // Sets all internal pointers to NULL and indices to -1.
40 // Note: No resources are released!
41 // Specificaly AliRunLoader is not deleted.
49 fHitAddressSet = kFALSE;
50 fSDigitAddressSet = kFALSE;
51 fDigitAddressSet = kFALSE;
52 fClusterAddressSet = kFALSE;
53 fTriggerAddressSet = kFALSE;
57 Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
59 // Load the run and muon loaders from the specified file and folder.
60 // kTRUE is returned on success and kFALSE on failure.
62 fRunloader = AliRunLoader::Open(filename, foldername, "READ");
63 if (fRunloader == NULL)
65 Error("LoadLoaders", "Could not find or load the run loader for the file: %s and folder: %s",
66 (const char*)filename, (const char*)foldername);
69 fMuonloader = fRunloader->GetLoader("MUONLoader");
70 if (fMuonloader == NULL)
72 Error("LoadLoaders", "Could not find the MUON loader in file: %s and folder: %s",
73 (const char*)filename, (const char*)foldername);
78 // Need to connect the muon loader to the AliMUONData object,
79 // else class to fData will return NULL.
80 fData.SetLoader(fMuonloader);
83 fFoldername = foldername;
84 fEventnumber = -1; // Reset the event number to force the event to be loaded.
89 Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
91 // Fetch the run loader and muon loader objects from memory if they already exist,
92 // or from memory if they do not.
93 // If the currently loaded run loader (if any) is not refering to the file and folder
94 // we are interested in then it is deleted and reopened with the required file and
97 if (fRunloader == NULL)
99 fRunloader = AliRunLoader::GetRunLoader();
100 if (fRunloader == NULL)
101 return LoadLoaders(filename, foldername);
103 // Fetch the current file and folder names.
104 fFilename = fRunloader->GetFileName();
105 fFoldername = fRunloader->GetEventFolder()->GetName();
108 // If filename or foldername are not the same as the ones currently selected then
110 if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
113 return LoadLoaders(filename, foldername);
119 Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
121 // Fetch the specified event from the runloader and reset all the track, cathode
122 // and address flags to force them to be reloaded.
124 if (fEventnumber < 0)
126 fEventnumber = fRunloader->GetEventNumber();
130 fHitAddressSet = kFALSE;
131 fSDigitAddressSet = kFALSE;
132 fDigitAddressSet = kFALSE;
133 fClusterAddressSet = kFALSE;
134 fTriggerAddressSet = kFALSE;
136 if ( event != fEventnumber )
138 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
139 fEventnumber = event;
143 fHitAddressSet = kFALSE;
144 fSDigitAddressSet = kFALSE;
145 fDigitAddressSet = kFALSE;
146 fClusterAddressSet = kFALSE;
147 fTriggerAddressSet = kFALSE;
153 Bool_t AliMUONDataInterface::FetchTreeK()
155 // Fetch the Kine tree from the current run loader.
157 if (fRunloader->TreeK() == NULL)
159 fRunloader->LoadKinematics("READ");
160 if (fRunloader->TreeK() == NULL)
162 Error("FetchTreeK", "Could not load TreeK.");
170 Bool_t AliMUONDataInterface::FetchTreeH()
172 // Fetch the Hits tree from the current muon loader.
173 // Set all the required addresses etc...
175 if (fMuonloader->TreeH() == NULL)
177 fMuonloader->LoadHits("READ");
178 if (fMuonloader->TreeH() == NULL)
180 Error("FetchTreeH", "Could not load TreeH.");
183 fData.SetTreeAddress("H");
184 fHitAddressSet = kTRUE;
186 else if ( ! fHitAddressSet )
188 fData.SetTreeAddress("H");
189 fHitAddressSet = kTRUE;
195 Bool_t AliMUONDataInterface::FetchTreeS()
197 // Fetch the S-Digits tree from the current muon loader.
198 // Set all the required addresses etc...
200 if (fMuonloader->TreeS() == NULL)
202 fMuonloader->LoadSDigits("READ");
203 if (fMuonloader->TreeS() == NULL)
205 Error("FetchTreeS", "Could not load TreeS.");
208 fData.SetTreeAddress("S");
209 fSDigitAddressSet = kTRUE;
211 else if ( ! fSDigitAddressSet )
213 fData.SetTreeAddress("S");
214 fSDigitAddressSet = kTRUE;
220 Bool_t AliMUONDataInterface::FetchTreeD()
222 // Fetch the digits tree from the current muon loader.
223 // Set all the required addresses etc...
225 if (fMuonloader->TreeD() == NULL)
227 fMuonloader->LoadDigits("READ");
228 if (fMuonloader->TreeD() == NULL)
230 Error("FetchTreeD", "Could not load TreeD.");
233 fData.SetTreeAddress("D");
234 fDigitAddressSet = kTRUE;
236 else if ( ! fDigitAddressSet )
238 fData.SetTreeAddress("D");
239 fDigitAddressSet = kTRUE;
245 Bool_t AliMUONDataInterface::FetchTreeR()
247 // Fetch the reconstructed objects tree from the current muon loader.
248 // Nore: The addresses must still be set.
250 if (fMuonloader->TreeR() == NULL)
252 fMuonloader->LoadRecPoints("READ");
253 if (fMuonloader->TreeR() == NULL)
255 Error("FetchTreeR", "Could not load TreeR.");
259 // Need to reset these flags so that the cluster and trigger address
260 // gets reset after this method.
261 fClusterAddressSet = kFALSE;
262 fTriggerAddressSet = kFALSE;
268 Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
270 // Returns the number of events in the specified file/folder, and -1 on error.
272 if ( ! FetchLoaders(filename, foldername) ) return -1;
273 return fRunloader->GetNumberOfEvents();
277 Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
279 // Returns the number of events in the specified file/folder, and -1 on error.
281 if ( ! FetchLoaders(filename, foldername) ) return -1;
282 if ( ! FetchEvent(event) ) return -1;
283 if ( ! FetchTreeK() ) return -1;
284 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
288 TParticle* AliMUONDataInterface::Particle(
289 TString filename, TString foldername, Int_t event, Int_t particle
292 // Returns the specified particle in the given file, folder and event.
293 // NULL is returned on error.
295 if ( ! FetchLoaders(filename, foldername) ) return NULL;
296 if ( ! FetchEvent(event) ) return NULL;
297 if ( ! FetchTreeK() ) return NULL;
299 TTree* treeK = fRunloader->TreeK();
301 treeK->GetBranch("Particles")->SetAddress(&p);
302 treeK->GetEvent(particle);
307 Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
309 // Returns the number of tracks in the specified file/folder and event.
310 // -1 is returned on error.
312 if ( ! FetchLoaders(filename, foldername) ) return -1;
313 if ( ! FetchEvent(event) ) return -1;
314 if ( ! FetchTreeH() ) return -1;
315 return fData.GetNtracks();
319 Int_t AliMUONDataInterface::NumberOfHits(
320 TString filename, TString foldername, Int_t event, Int_t track
323 // Returns the number of hits in the specified file/folder, event and track.
324 // -1 is returned on error.
326 if ( ! FetchLoaders(filename, foldername) ) return -1;
327 if ( ! FetchEvent(event) ) return -1;
328 if ( ! FetchTreeH() ) return -1;
330 if (fTrack < 0 || fTrack != track)
333 fData.GetTrack(track);
336 return fData.Hits()->GetEntriesFast();
340 AliMUONHit* AliMUONDataInterface::Hit(
341 TString filename, TString foldername, Int_t event,
342 Int_t track, Int_t hit
345 // Returns the specified hit in the given file, folder, event and track.
346 // NULL is returned on error.
348 if ( ! FetchLoaders(filename, foldername) ) return NULL;
349 if ( ! FetchEvent(event) ) return NULL;
350 if ( ! FetchTreeH() ) return NULL;
352 if (fTrack < 0 || fTrack != track)
355 fData.GetTrack(track);
358 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
362 Int_t AliMUONDataInterface::NumberOfSDigits(
363 TString filename, TString foldername, Int_t event,
364 Int_t chamber, Int_t cathode
367 // Returns the number of s-digits in the given file, folder, event,
368 // chamber and cathode. -1 is returned on error.
370 Assert( 0 <= chamber && chamber <= 13 );
371 Assert( 0 <= cathode && cathode <= 1 );
373 if ( ! FetchLoaders(filename, foldername) ) return -1;
374 if ( ! FetchEvent(event) ) return -1;
375 if ( ! FetchTreeS() ) return -1;
377 if ( fSCathode != cathode )
379 fData.ResetSDigits();
380 fData.GetCathodeS(cathode);
383 return fData.SDigits(chamber)->GetEntriesFast();
387 AliMUONDigit* AliMUONDataInterface::SDigit(
388 TString filename, TString foldername, Int_t event,
389 Int_t chamber, Int_t cathode, Int_t sdigit
392 // Returns the specified s-digit in the given file, folder, event,
393 // chamber and cathode. NULL is returned on error.
395 Assert( 0 <= chamber && chamber <= 13 );
396 Assert( 0 <= cathode && cathode <= 1 );
398 if ( ! FetchLoaders(filename, foldername) ) return NULL;
399 if ( ! FetchEvent(event) ) return NULL;
400 if ( ! FetchTreeS() ) return NULL;
402 if ( fSCathode != cathode )
404 fData.ResetSDigits();
405 fData.GetCathodeS(cathode);
408 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
412 Int_t AliMUONDataInterface::NumberOfDigits(
413 TString filename, TString foldername, Int_t event,
414 Int_t chamber, Int_t cathode
417 // Returns the number of digits in the given file, folder, event,
418 // chamber and cathode. -1 is returned on error.
419 Assert( 0 <= chamber && chamber <= 13 );
420 Assert( 0 <= cathode && cathode <= 1 );
422 if ( ! FetchLoaders(filename, foldername) ) return -1;
423 if ( ! FetchEvent(event) ) return -1;
424 if ( ! FetchTreeD() ) return -1;
426 if ( fCathode != cathode )
429 fData.GetCathode(cathode);
432 return fData.Digits(chamber)->GetEntriesFast();
436 AliMUONDigit* AliMUONDataInterface::Digit(
437 TString filename, TString foldername, Int_t event,
438 Int_t chamber, Int_t cathode, Int_t digit
441 // Returns the specified digit in the given file, folder, event,
442 // chamber and cathode. NULL is returned on error.
444 Assert( 0 <= chamber && chamber <= 13 );
445 Assert( 0 <= cathode && cathode <= 1 );
447 if ( ! FetchLoaders(filename, foldername) ) return NULL;
448 if ( ! FetchEvent(event) ) return NULL;
449 if ( ! FetchTreeD() ) return NULL;
451 if ( fCathode != cathode )
454 fData.GetCathode(cathode);
457 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
461 Int_t AliMUONDataInterface::NumberOfRawClusters(
462 TString filename, TString foldername, Int_t event, Int_t chamber
465 // Returns the number of raw clusters in the specified file, folder, event and chamber.
466 // -1 is returned or error.
468 Assert( 0 <= chamber && chamber <= 13 );
469 if ( ! FetchLoaders(filename, foldername) ) return -1;
470 if ( ! FetchEvent(event) ) return -1;
471 if ( ! FetchTreeR() ) return -1;
472 if ( ! fClusterAddressSet )
474 // If the raw cluster address in TreeR is not set yet then set it now.
475 fData.SetTreeAddress("RC");
476 fData.ResetRawClusters();
477 fData.GetRawClusters();
478 fClusterAddressSet = kTRUE;
480 return fData.RawClusters(chamber)->GetEntriesFast();
484 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
485 TString filename, TString foldername, Int_t event,
486 Int_t chamber, Int_t cluster
489 // Fetch the specified raw cluster from the given file, folder, event and chamber number.
490 // NULL is returned on error.
492 Assert( 0 <= chamber && chamber <= 13 );
493 if ( ! FetchLoaders(filename, foldername) ) return NULL;
494 if ( ! FetchEvent(event) ) return NULL;
495 if ( ! FetchTreeR() ) return NULL;
496 if ( ! fClusterAddressSet )
498 // If the raw cluster address in TreeR is not set yet then set it now.
499 fData.SetTreeAddress("RC");
500 fData.ResetRawClusters();
501 fData.GetRawClusters();
502 fClusterAddressSet = kTRUE;
504 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
508 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
510 // Return the number of local trigger objects in the specified file, folder and
511 // event number. -1 is returned on error.
513 if ( ! FetchLoaders(filename, foldername) ) return -1;
514 if ( ! FetchEvent(event) ) return -1;
515 if ( ! FetchTreeR() ) return -1;
516 if ( ! fTriggerAddressSet )
518 // If the local trigger address in TreeR is not set yet then set it now.
519 fData.SetTreeAddress("GLT");
520 fData.ResetTrigger();
522 fTriggerAddressSet = kTRUE;
524 return fData.LocalTrigger()->GetEntriesFast();
528 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
529 TString filename, TString foldername, Int_t event, Int_t trigger
532 // Fetch the specified local trigger object from the given file, folder and event number.
533 // NULL is returned on error.
535 if ( ! FetchLoaders(filename, foldername) ) return NULL;
536 if ( ! FetchEvent(event) ) return NULL;
537 if ( ! FetchTreeR() ) return NULL;
538 if ( ! fTriggerAddressSet )
540 // If the local trigger address in TreeR is not set yet then set it now.
541 fData.SetTreeAddress("GLT");
542 fData.ResetTrigger();
544 fTriggerAddressSet = kTRUE;
546 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
550 Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
552 // Set the current file and folder from which to fetch data.
553 // kTRUE is returned if the run and muon loaders were found, else kFALSE.
555 return FetchLoaders(filename, foldername);
559 Bool_t AliMUONDataInterface::GetEvent(Int_t event)
561 // Select the current event from which to fetch data.
562 // kTRUE is returned if the event was found, else kFALSE is returned.
564 return FetchEvent(event);
568 Int_t AliMUONDataInterface::NumberOfEvents()
570 // Get the number of events in the currently selected file.
571 // -1 is returned on error.
573 if (fRunloader == NULL)
575 Error("NumberOfEvents", "File not set.");
578 return fRunloader->GetNumberOfEvents();
582 Int_t AliMUONDataInterface::NumberOfParticles()
584 // Get the number of particles in the current event.
585 // -1 is returned on error.
587 if (fRunloader == NULL)
589 Error("NumberOfParticles", "File not set.");
592 if ( ! FetchTreeK() ) return -1;
593 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
597 TParticle* AliMUONDataInterface::Particle(Int_t particle)
599 // Fetch the specified particle from the current event.
600 // NULL is returned on error.
602 if (fRunloader == NULL)
604 Error("Particle", "File not set.");
607 if (fEventnumber < 0)
609 Error("Particle", "Event not chosen.");
612 if ( ! FetchTreeK() ) return NULL;
613 TTree* treeK = fRunloader->TreeK();
615 treeK->GetBranch("Particles")->SetAddress(&p);
616 treeK->GetEvent(particle);
621 Int_t AliMUONDataInterface::NumberOfTracks()
623 // Get the number of tracks in the current event.
624 // -1 is returned on error.
626 if (fRunloader == NULL)
628 Error("NumberOfTracks", "File not set.");
631 if (fEventnumber < 0)
633 Error("NumberOfTracks", "Event not chosen.");
636 if ( ! FetchTreeH() ) return -1;
637 return fData.GetNtracks();
641 Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
643 // Get the number of hits for the given track in the current event.
644 // -1 is returned on error.
646 if (fRunloader == NULL)
648 Error("NumberOfHits", "File not set.");
651 if (fEventnumber < 0)
653 Error("NumberOfHits", "Event not chosen.");
656 if ( ! FetchTreeH() ) return -1;
657 if (fTrack < 0 || fTrack != track)
660 fData.GetTrack(track);
663 return fData.Hits()->GetEntriesFast();
667 AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
669 // Fetch the specified hit from the current event.
670 // NULL is returned on error.
672 if (fRunloader == NULL)
674 Error("Hit", "File not set.");
677 if (fEventnumber < 0)
679 Error("Hit", "Event not chosen.");
682 if ( ! FetchTreeH() ) return NULL;
683 if (fTrack < 0 || fTrack != track)
686 fData.GetTrack(track);
689 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
693 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
695 // Get the number of s-digits on the chamber, cathode in the current event.
696 // -1 is returned on error.
698 Assert( 0 <= chamber && chamber <= 13 );
699 Assert( 0 <= cathode && cathode <= 1 );
701 if (fRunloader == NULL)
703 Error("NumberOfSDigits", "File not set.");
706 if (fEventnumber < 0)
708 Error("NumberOfSDigits", "Event not chosen.");
712 if ( ! FetchTreeS() ) return -1;
713 if ( fSCathode != cathode )
715 fData.ResetSDigits();
716 fData.GetCathodeS(cathode);
719 return fData.SDigits(chamber)->GetEntriesFast();
723 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
725 // Fetch the specified s-digits on the chamber, cathode from the current event.
726 // NULL is returned on error.
728 Assert( 0 <= chamber && chamber <= 13 );
729 Assert( 0 <= cathode && cathode <= 1 );
731 if (fRunloader == NULL)
733 Error("SDigit", "File not set.");
736 if (fEventnumber < 0)
738 Error("SDigit", "Event not chosen.");
742 if ( ! FetchTreeS() ) return NULL;
743 if ( fSCathode != cathode )
745 fData.ResetSDigits();
746 fData.GetCathodeS(cathode);
749 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
753 Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
755 // Get the number of digits on the chamber, cathode in the current event.
756 // -1 is returned on error.
758 Assert( 0 <= chamber && chamber <= 13 );
759 Assert( 0 <= cathode && cathode <= 1 );
761 if (fRunloader == NULL)
763 Error("NumberOfDigits", "File not set.");
766 if (fEventnumber < 0)
768 Error("NumberOfDigits", "Event not chosen.");
772 if ( ! FetchTreeD() ) return -1;
773 if ( fCathode != cathode )
776 fData.GetCathode(cathode);
779 return fData.Digits(chamber)->GetEntriesFast();
783 AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
785 // Fetch the specified digits on the chamber, cathode from the current event.
786 // NULL is returned on error.
788 Assert( 0 <= chamber && chamber <= 13 );
789 Assert( 0 <= cathode && cathode <= 1 );
791 if (fRunloader == NULL)
793 Error("Digit", "File not set.");
796 if (fEventnumber < 0)
798 Error("Digit", "Event not chosen.");
802 if ( ! FetchTreeD() ) return NULL;
803 if ( fCathode != cathode )
806 fData.GetCathode(cathode);
809 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
813 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
815 // Get the number of raw clusters on the given chamber in the current event.
816 // -1 is returned on error.
818 Assert( 0 <= chamber && chamber <= 13 );
820 if (fRunloader == NULL)
822 Error("NumberOfRawClusters", "File not set.");
825 if (fEventnumber < 0)
827 Error("NumberOfRawClusters", "Event not chosen.");
831 if ( ! FetchTreeR() ) return -1;
832 if ( ! fClusterAddressSet )
834 fData.SetTreeAddress("RC");
835 fData.ResetRawClusters();
836 fData.GetRawClusters();
837 fClusterAddressSet = kTRUE;
839 return fData.RawClusters(chamber)->GetEntriesFast();
843 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
845 // Fetch the specified raw cluster on the given chamber from the current event.
846 // NULL is returned on error.
848 Assert( 0 <= chamber && chamber <= 13 );
850 if (fRunloader == NULL)
852 Error("RawCluster", "File not set.");
855 if (fEventnumber < 0)
857 Error("RawCluster", "Event not chosen.");
861 if ( ! FetchTreeR() ) return NULL;
862 if ( ! fClusterAddressSet )
864 fData.SetTreeAddress("RC");
865 fData.ResetRawClusters();
866 fData.GetRawClusters();
867 fClusterAddressSet = kTRUE;
869 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
873 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
875 // Get the number of local trigger objects in the current event.
876 // -1 is returned on error.
878 if (fRunloader == NULL)
880 Error("NumberOfLocalTriggers", "File not set.");
883 if (fEventnumber < 0)
885 Error("NumberOfLocalTriggers", "Event not chosen.");
889 if ( ! FetchTreeR() ) return -1;
890 if ( ! fTriggerAddressSet )
892 fData.SetTreeAddress("GLT");
893 fData.ResetTrigger();
895 fTriggerAddressSet = kTRUE;
897 return fData.LocalTrigger()->GetEntriesFast();
901 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
903 // Fetch the specified local trigger object from the current event.
904 // NULL is returned on error.
906 if (fRunloader == NULL)
908 Error("LocalTrigger", "File not set.");
911 if (fEventnumber < 0)
913 Error("LocalTrigger", "Event not chosen.");
917 if ( ! FetchTreeR() ) return NULL;
918 if ( ! fTriggerAddressSet )
920 fData.SetTreeAddress("GLT");
921 fData.ResetTrigger();
923 fTriggerAddressSet = kTRUE;
925 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );