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.
25 AliMUONDataInterface::AliMUONDataInterface(const AliMUONDataInterface& rhs)
28 // Protected copy constructor
30 Fatal("AliMUONDataInterface", "Not implemented.");
33 AliMUONDataInterface::~AliMUONDataInterface()
35 // Delete the runloader when done.
36 // If the runloader is not to be deleted then call Reset just before
37 // the destructor is called.
39 if (fRunloader != NULL)
44 AliMUONDataInterface::operator=(const AliMUONDataInterface& rhs)
46 // Protected assignement operator
48 if (this == &rhs) return *this;
50 Fatal("operator=", "Not implemented.");
56 void AliMUONDataInterface::Reset()
58 // Sets all internal pointers to NULL and indices to -1.
59 // Note: No resources are released!
60 // Specificaly AliRunLoader is not deleted.
68 fHitAddressSet = kFALSE;
69 fSDigitAddressSet = kFALSE;
70 fDigitAddressSet = kFALSE;
71 fClusterAddressSet = kFALSE;
72 fTriggerAddressSet = kFALSE;
76 Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
78 // Load the run and muon loaders from the specified file and folder.
79 // kTRUE is returned on success and kFALSE on failure.
81 fRunloader = AliRunLoader::Open(filename, foldername, "READ");
82 if (fRunloader == NULL)
84 Error("LoadLoaders", "Could not find or load the run loader for the file: %s and folder: %s",
85 (const char*)filename, (const char*)foldername);
88 fMuonloader = fRunloader->GetLoader("MUONLoader");
89 if (fMuonloader == NULL)
91 Error("LoadLoaders", "Could not find the MUON loader in file: %s and folder: %s",
92 (const char*)filename, (const char*)foldername);
97 // Need to connect the muon loader to the AliMUONData object,
98 // else class to fData will return NULL.
99 fData.SetLoader(fMuonloader);
101 fFilename = filename;
102 fFoldername = foldername;
103 fEventnumber = -1; // Reset the event number to force the event to be loaded.
108 Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
110 // Fetch the run loader and muon loader objects from memory if they already exist,
111 // or from memory if they do not.
112 // If the currently loaded run loader (if any) is not refering to the file and folder
113 // we are interested in then it is deleted and reopened with the required file and
116 if (fRunloader == NULL)
118 fRunloader = AliRunLoader::GetRunLoader();
119 if (fRunloader == NULL)
120 return LoadLoaders(filename, foldername);
122 // Fetch the current file and folder names.
123 fFilename = fRunloader->GetFileName();
124 fFoldername = fRunloader->GetEventFolder()->GetName();
127 // If filename or foldername are not the same as the ones currently selected then
129 if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
132 return LoadLoaders(filename, foldername);
138 Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
140 // Fetch the specified event from the runloader and reset all the track, cathode
141 // and address flags to force them to be reloaded.
143 if (fEventnumber < 0)
145 fEventnumber = fRunloader->GetEventNumber();
149 fHitAddressSet = kFALSE;
150 fSDigitAddressSet = kFALSE;
151 fDigitAddressSet = kFALSE;
152 fClusterAddressSet = kFALSE;
153 fTriggerAddressSet = kFALSE;
155 if ( event != fEventnumber )
157 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
158 fEventnumber = event;
162 fHitAddressSet = kFALSE;
163 fSDigitAddressSet = kFALSE;
164 fDigitAddressSet = kFALSE;
165 fClusterAddressSet = kFALSE;
166 fTriggerAddressSet = kFALSE;
172 Bool_t AliMUONDataInterface::FetchTreeK()
174 // Fetch the Kine tree from the current run loader.
176 if (fRunloader->TreeK() == NULL)
178 fRunloader->LoadKinematics("READ");
179 if (fRunloader->TreeK() == NULL)
181 Error("FetchTreeK", "Could not load TreeK.");
189 Bool_t AliMUONDataInterface::FetchTreeH()
191 // Fetch the Hits tree from the current muon loader.
192 // Set all the required addresses etc...
194 if (fMuonloader->TreeH() == NULL)
196 fMuonloader->LoadHits("READ");
197 if (fMuonloader->TreeH() == NULL)
199 Error("FetchTreeH", "Could not load TreeH.");
202 fData.SetTreeAddress("H");
203 fHitAddressSet = kTRUE;
205 else if ( ! fHitAddressSet )
207 fData.SetTreeAddress("H");
208 fHitAddressSet = kTRUE;
214 Bool_t AliMUONDataInterface::FetchTreeS()
216 // Fetch the S-Digits tree from the current muon loader.
217 // Set all the required addresses etc...
219 if (fMuonloader->TreeS() == NULL)
221 fMuonloader->LoadSDigits("READ");
222 if (fMuonloader->TreeS() == NULL)
224 Error("FetchTreeS", "Could not load TreeS.");
227 fData.SetTreeAddress("S");
228 fSDigitAddressSet = kTRUE;
230 else if ( ! fSDigitAddressSet )
232 fData.SetTreeAddress("S");
233 fSDigitAddressSet = kTRUE;
239 Bool_t AliMUONDataInterface::FetchTreeD()
241 // Fetch the digits tree from the current muon loader.
242 // Set all the required addresses etc...
244 if (fMuonloader->TreeD() == NULL)
246 fMuonloader->LoadDigits("READ");
247 if (fMuonloader->TreeD() == NULL)
249 Error("FetchTreeD", "Could not load TreeD.");
252 fData.SetTreeAddress("D");
253 fDigitAddressSet = kTRUE;
255 else if ( ! fDigitAddressSet )
257 fData.SetTreeAddress("D");
258 fDigitAddressSet = kTRUE;
264 Bool_t AliMUONDataInterface::FetchTreeR()
266 // Fetch the reconstructed objects tree from the current muon loader.
267 // Nore: The addresses must still be set.
269 if (fMuonloader->TreeR() == NULL)
271 fMuonloader->LoadRecPoints("READ");
272 if (fMuonloader->TreeR() == NULL)
274 Error("FetchTreeR", "Could not load TreeR.");
278 // Need to reset these flags so that the cluster and trigger address
279 // gets reset after this method.
280 fClusterAddressSet = kFALSE;
281 fTriggerAddressSet = kFALSE;
287 Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
289 // Returns the number of events in the specified file/folder, and -1 on error.
291 if ( ! FetchLoaders(filename, foldername) ) return -1;
292 return fRunloader->GetNumberOfEvents();
296 Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
298 // Returns the number of events in the specified file/folder, and -1 on error.
300 if ( ! FetchLoaders(filename, foldername) ) return -1;
301 if ( ! FetchEvent(event) ) return -1;
302 if ( ! FetchTreeK() ) return -1;
303 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
307 TParticle* AliMUONDataInterface::Particle(
308 TString filename, TString foldername, Int_t event, Int_t particle
311 // Returns the specified particle in the given file, folder and event.
312 // NULL is returned on error.
314 if ( ! FetchLoaders(filename, foldername) ) return NULL;
315 if ( ! FetchEvent(event) ) return NULL;
316 if ( ! FetchTreeK() ) return NULL;
318 TTree* treeK = fRunloader->TreeK();
320 treeK->GetBranch("Particles")->SetAddress(&p);
321 treeK->GetEvent(particle);
326 Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
328 // Returns the number of tracks in the specified file/folder and event.
329 // -1 is returned on error.
331 if ( ! FetchLoaders(filename, foldername) ) return -1;
332 if ( ! FetchEvent(event) ) return -1;
333 if ( ! FetchTreeH() ) return -1;
334 return fData.GetNtracks();
338 Int_t AliMUONDataInterface::NumberOfHits(
339 TString filename, TString foldername, Int_t event, Int_t track
342 // Returns the number of hits in the specified file/folder, event and track.
343 // -1 is returned on error.
345 if ( ! FetchLoaders(filename, foldername) ) return -1;
346 if ( ! FetchEvent(event) ) return -1;
347 if ( ! FetchTreeH() ) return -1;
349 if (fTrack < 0 || fTrack != track)
352 fData.GetTrack(track);
355 return fData.Hits()->GetEntriesFast();
359 AliMUONHit* AliMUONDataInterface::Hit(
360 TString filename, TString foldername, Int_t event,
361 Int_t track, Int_t hit
364 // Returns the specified hit in the given file, folder, event and track.
365 // NULL is returned on error.
367 if ( ! FetchLoaders(filename, foldername) ) return NULL;
368 if ( ! FetchEvent(event) ) return NULL;
369 if ( ! FetchTreeH() ) return NULL;
371 if (fTrack < 0 || fTrack != track)
374 fData.GetTrack(track);
377 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
381 Int_t AliMUONDataInterface::NumberOfSDigits(
382 TString filename, TString foldername, Int_t event,
383 Int_t chamber, Int_t cathode
386 // Returns the number of s-digits in the given file, folder, event,
387 // chamber and cathode. -1 is returned on error.
389 Assert( 0 <= chamber && chamber <= 13 );
390 Assert( 0 <= cathode && cathode <= 1 );
392 if ( ! FetchLoaders(filename, foldername) ) return -1;
393 if ( ! FetchEvent(event) ) return -1;
394 if ( ! FetchTreeS() ) return -1;
396 if ( fSCathode != cathode )
398 fData.ResetSDigits();
399 fData.GetCathodeS(cathode);
402 return fData.SDigits(chamber)->GetEntriesFast();
406 AliMUONDigit* AliMUONDataInterface::SDigit(
407 TString filename, TString foldername, Int_t event,
408 Int_t chamber, Int_t cathode, Int_t sdigit
411 // Returns the specified s-digit in the given file, folder, event,
412 // chamber and cathode. NULL is returned on error.
414 Assert( 0 <= chamber && chamber <= 13 );
415 Assert( 0 <= cathode && cathode <= 1 );
417 if ( ! FetchLoaders(filename, foldername) ) return NULL;
418 if ( ! FetchEvent(event) ) return NULL;
419 if ( ! FetchTreeS() ) return NULL;
421 if ( fSCathode != cathode )
423 fData.ResetSDigits();
424 fData.GetCathodeS(cathode);
427 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
431 Int_t AliMUONDataInterface::NumberOfDigits(
432 TString filename, TString foldername, Int_t event,
433 Int_t chamber, Int_t cathode
436 // Returns the number of digits in the given file, folder, event,
437 // chamber and cathode. -1 is returned on error.
438 Assert( 0 <= chamber && chamber <= 13 );
439 Assert( 0 <= cathode && cathode <= 1 );
441 if ( ! FetchLoaders(filename, foldername) ) return -1;
442 if ( ! FetchEvent(event) ) return -1;
443 if ( ! FetchTreeD() ) return -1;
445 if ( fCathode != cathode )
448 fData.GetCathode(cathode);
451 return fData.Digits(chamber)->GetEntriesFast();
455 AliMUONDigit* AliMUONDataInterface::Digit(
456 TString filename, TString foldername, Int_t event,
457 Int_t chamber, Int_t cathode, Int_t digit
460 // Returns the specified digit in the given file, folder, event,
461 // chamber and cathode. NULL is returned on error.
463 Assert( 0 <= chamber && chamber <= 13 );
464 Assert( 0 <= cathode && cathode <= 1 );
466 if ( ! FetchLoaders(filename, foldername) ) return NULL;
467 if ( ! FetchEvent(event) ) return NULL;
468 if ( ! FetchTreeD() ) return NULL;
470 if ( fCathode != cathode )
473 fData.GetCathode(cathode);
476 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
480 Int_t AliMUONDataInterface::NumberOfRawClusters(
481 TString filename, TString foldername, Int_t event, Int_t chamber
484 // Returns the number of raw clusters in the specified file, folder, event and chamber.
485 // -1 is returned or error.
487 Assert( 0 <= chamber && chamber <= 13 );
488 if ( ! FetchLoaders(filename, foldername) ) return -1;
489 if ( ! FetchEvent(event) ) return -1;
490 if ( ! FetchTreeR() ) return -1;
491 if ( ! fClusterAddressSet )
493 // If the raw cluster address in TreeR is not set yet then set it now.
494 fData.SetTreeAddress("RC");
495 fData.ResetRawClusters();
496 fData.GetRawClusters();
497 fClusterAddressSet = kTRUE;
499 return fData.RawClusters(chamber)->GetEntriesFast();
503 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
504 TString filename, TString foldername, Int_t event,
505 Int_t chamber, Int_t cluster
508 // Fetch the specified raw cluster from the given file, folder, event and chamber number.
509 // NULL is returned on error.
511 Assert( 0 <= chamber && chamber <= 13 );
512 if ( ! FetchLoaders(filename, foldername) ) return NULL;
513 if ( ! FetchEvent(event) ) return NULL;
514 if ( ! FetchTreeR() ) return NULL;
515 if ( ! fClusterAddressSet )
517 // If the raw cluster address in TreeR is not set yet then set it now.
518 fData.SetTreeAddress("RC");
519 fData.ResetRawClusters();
520 fData.GetRawClusters();
521 fClusterAddressSet = kTRUE;
523 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
527 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
529 // Return the number of local trigger objects in the specified file, folder and
530 // event number. -1 is returned on error.
532 if ( ! FetchLoaders(filename, foldername) ) return -1;
533 if ( ! FetchEvent(event) ) return -1;
534 if ( ! FetchTreeR() ) return -1;
535 if ( ! fTriggerAddressSet )
537 // If the local trigger address in TreeR is not set yet then set it now.
538 fData.SetTreeAddress("GLT");
539 fData.ResetTrigger();
541 fTriggerAddressSet = kTRUE;
543 return fData.LocalTrigger()->GetEntriesFast();
547 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
548 TString filename, TString foldername, Int_t event, Int_t trigger
551 // Fetch the specified local trigger object from the given file, folder and event number.
552 // NULL is returned on error.
554 if ( ! FetchLoaders(filename, foldername) ) return NULL;
555 if ( ! FetchEvent(event) ) return NULL;
556 if ( ! FetchTreeR() ) return NULL;
557 if ( ! fTriggerAddressSet )
559 // If the local trigger address in TreeR is not set yet then set it now.
560 fData.SetTreeAddress("GLT");
561 fData.ResetTrigger();
563 fTriggerAddressSet = kTRUE;
565 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
569 Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
571 // Set the current file and folder from which to fetch data.
572 // kTRUE is returned if the run and muon loaders were found, else kFALSE.
574 return FetchLoaders(filename, foldername);
578 Bool_t AliMUONDataInterface::GetEvent(Int_t event)
580 // Select the current event from which to fetch data.
581 // kTRUE is returned if the event was found, else kFALSE is returned.
583 return FetchEvent(event);
587 Int_t AliMUONDataInterface::NumberOfEvents()
589 // Get the number of events in the currently selected file.
590 // -1 is returned on error.
592 if (fRunloader == NULL)
594 Error("NumberOfEvents", "File not set.");
597 return fRunloader->GetNumberOfEvents();
601 Int_t AliMUONDataInterface::NumberOfParticles()
603 // Get the number of particles in the current event.
604 // -1 is returned on error.
606 if (fRunloader == NULL)
608 Error("NumberOfParticles", "File not set.");
611 if ( ! FetchTreeK() ) return -1;
612 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
616 TParticle* AliMUONDataInterface::Particle(Int_t particle)
618 // Fetch the specified particle from the current event.
619 // NULL is returned on error.
621 if (fRunloader == NULL)
623 Error("Particle", "File not set.");
626 if (fEventnumber < 0)
628 Error("Particle", "Event not chosen.");
631 if ( ! FetchTreeK() ) return NULL;
632 TTree* treeK = fRunloader->TreeK();
634 treeK->GetBranch("Particles")->SetAddress(&p);
635 treeK->GetEvent(particle);
640 Int_t AliMUONDataInterface::NumberOfTracks()
642 // Get the number of tracks in the current event.
643 // -1 is returned on error.
645 if (fRunloader == NULL)
647 Error("NumberOfTracks", "File not set.");
650 if (fEventnumber < 0)
652 Error("NumberOfTracks", "Event not chosen.");
655 if ( ! FetchTreeH() ) return -1;
656 return fData.GetNtracks();
660 Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
662 // Get the number of hits for the given track in the current event.
663 // -1 is returned on error.
665 if (fRunloader == NULL)
667 Error("NumberOfHits", "File not set.");
670 if (fEventnumber < 0)
672 Error("NumberOfHits", "Event not chosen.");
675 if ( ! FetchTreeH() ) return -1;
676 if (fTrack < 0 || fTrack != track)
679 fData.GetTrack(track);
682 return fData.Hits()->GetEntriesFast();
686 AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
688 // Fetch the specified hit from the current event.
689 // NULL is returned on error.
691 if (fRunloader == NULL)
693 Error("Hit", "File not set.");
696 if (fEventnumber < 0)
698 Error("Hit", "Event not chosen.");
701 if ( ! FetchTreeH() ) return NULL;
702 if (fTrack < 0 || fTrack != track)
705 fData.GetTrack(track);
708 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
712 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
714 // Get the number of s-digits on the chamber, cathode in the current event.
715 // -1 is returned on error.
717 Assert( 0 <= chamber && chamber <= 13 );
718 Assert( 0 <= cathode && cathode <= 1 );
720 if (fRunloader == NULL)
722 Error("NumberOfSDigits", "File not set.");
725 if (fEventnumber < 0)
727 Error("NumberOfSDigits", "Event not chosen.");
731 if ( ! FetchTreeS() ) return -1;
732 if ( fSCathode != cathode )
734 fData.ResetSDigits();
735 fData.GetCathodeS(cathode);
738 return fData.SDigits(chamber)->GetEntriesFast();
742 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
744 // Fetch the specified s-digits on the chamber, cathode from the current event.
745 // NULL is returned on error.
747 Assert( 0 <= chamber && chamber <= 13 );
748 Assert( 0 <= cathode && cathode <= 1 );
750 if (fRunloader == NULL)
752 Error("SDigit", "File not set.");
755 if (fEventnumber < 0)
757 Error("SDigit", "Event not chosen.");
761 if ( ! FetchTreeS() ) return NULL;
762 if ( fSCathode != cathode )
764 fData.ResetSDigits();
765 fData.GetCathodeS(cathode);
768 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
772 Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
774 // Get the number of digits on the chamber, cathode in the current event.
775 // -1 is returned on error.
777 Assert( 0 <= chamber && chamber <= 13 );
778 Assert( 0 <= cathode && cathode <= 1 );
780 if (fRunloader == NULL)
782 Error("NumberOfDigits", "File not set.");
785 if (fEventnumber < 0)
787 Error("NumberOfDigits", "Event not chosen.");
791 if ( ! FetchTreeD() ) return -1;
792 if ( fCathode != cathode )
795 fData.GetCathode(cathode);
798 return fData.Digits(chamber)->GetEntriesFast();
802 AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
804 // Fetch the specified digits on the chamber, cathode from the current event.
805 // NULL is returned on error.
807 Assert( 0 <= chamber && chamber <= 13 );
808 Assert( 0 <= cathode && cathode <= 1 );
810 if (fRunloader == NULL)
812 Error("Digit", "File not set.");
815 if (fEventnumber < 0)
817 Error("Digit", "Event not chosen.");
821 if ( ! FetchTreeD() ) return NULL;
822 if ( fCathode != cathode )
825 fData.GetCathode(cathode);
828 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
832 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
834 // Get the number of raw clusters on the given chamber in the current event.
835 // -1 is returned on error.
837 Assert( 0 <= chamber && chamber <= 13 );
839 if (fRunloader == NULL)
841 Error("NumberOfRawClusters", "File not set.");
844 if (fEventnumber < 0)
846 Error("NumberOfRawClusters", "Event not chosen.");
850 if ( ! FetchTreeR() ) return -1;
851 if ( ! fClusterAddressSet )
853 fData.SetTreeAddress("RC");
854 fData.ResetRawClusters();
855 fData.GetRawClusters();
856 fClusterAddressSet = kTRUE;
858 return fData.RawClusters(chamber)->GetEntriesFast();
862 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
864 // Fetch the specified raw cluster on the given chamber from the current event.
865 // NULL is returned on error.
867 Assert( 0 <= chamber && chamber <= 13 );
869 if (fRunloader == NULL)
871 Error("RawCluster", "File not set.");
874 if (fEventnumber < 0)
876 Error("RawCluster", "Event not chosen.");
880 if ( ! FetchTreeR() ) return NULL;
881 if ( ! fClusterAddressSet )
883 fData.SetTreeAddress("RC");
884 fData.ResetRawClusters();
885 fData.GetRawClusters();
886 fClusterAddressSet = kTRUE;
888 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
892 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
894 // Get the number of local trigger objects in the current event.
895 // -1 is returned on error.
897 if (fRunloader == NULL)
899 Error("NumberOfLocalTriggers", "File not set.");
902 if (fEventnumber < 0)
904 Error("NumberOfLocalTriggers", "Event not chosen.");
908 if ( ! FetchTreeR() ) return -1;
909 if ( ! fTriggerAddressSet )
911 fData.SetTreeAddress("GLT");
912 fData.ResetTrigger();
914 fTriggerAddressSet = kTRUE;
916 return fData.LocalTrigger()->GetEntriesFast();
920 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
922 // Fetch the specified local trigger object from the current event.
923 // NULL is returned on error.
925 if (fRunloader == NULL)
927 Error("LocalTrigger", "File not set.");
930 if (fEventnumber < 0)
932 Error("LocalTrigger", "Event not chosen.");
936 if ( ! FetchTreeR() ) return NULL;
937 if ( ! fTriggerAddressSet )
939 fData.SetTreeAddress("GLT");
940 fData.ResetTrigger();
942 fTriggerAddressSet = kTRUE;
944 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );