2 // Author: Artur Szostak
3 // email: artur@alice.phy.uct.ac.za
8 #include "AliRunLoader.h"
11 #include "AliMUONDataInterface.h"
12 #include "AliMUONLocalTrigger.h"
13 #include "AliMUONHit.h"
14 #include "AliMUONDigit.h"
15 #include "AliMUONRawCluster.h"
19 ClassImp(AliMUONDataInterface)
22 AliMUONDataInterface::AliMUONDataInterface()
23 : TObject(), fData(NULL, "MUON", "MUON")
25 // Set all internal pointers to NULL and indices to -1.
30 AliMUONDataInterface::AliMUONDataInterface(const AliMUONDataInterface& rhs)
33 // Protected copy constructor
35 AliFatal("Not implemented.");
38 AliMUONDataInterface::~AliMUONDataInterface()
40 // Delete the runloader when done.
41 // If the runloader is not to be deleted then call Reset just before
42 // the destructor is called.
44 if (fRunloader != NULL)
49 AliMUONDataInterface::operator=(const AliMUONDataInterface& rhs)
51 // Protected assignement operator
53 if (this == &rhs) return *this;
55 AliFatal("Not implemented.");
61 void AliMUONDataInterface::Reset()
63 // Sets all internal pointers to NULL and indices to -1.
64 // Note: No resources are released!
65 // Specificaly AliRunLoader is not deleted.
73 fHitAddressSet = kFALSE;
74 fSDigitAddressSet = kFALSE;
75 fDigitAddressSet = kFALSE;
76 fClusterAddressSet = kFALSE;
77 fTriggerAddressSet = kFALSE;
81 Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
83 // Load the run and muon loaders from the specified file and folder.
84 // kTRUE is returned on success and kFALSE on failure.
86 fRunloader = AliRunLoader::Open(filename, foldername, "READ");
87 if (fRunloader == NULL)
89 AliError(Form("Could not find or load the run loader for the file: %s and folder: %s",
90 (const char*)filename, (const char*)foldername));
93 fMuonloader = fRunloader->GetLoader("MUONLoader");
94 if (fMuonloader == NULL)
96 AliError(Form("Could not find the MUON loader in file: %s and folder: %s",
97 (const char*)filename, (const char*)foldername));
102 // Need to connect the muon loader to the AliMUONData object,
103 // else class to fData will return NULL.
104 fData.SetLoader(fMuonloader);
106 fFilename = filename;
107 fFoldername = foldername;
108 fEventnumber = -1; // Reset the event number to force the event to be loaded.
113 Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
115 // Fetch the run loader and muon loader objects from memory if they already exist,
116 // or from memory if they do not.
117 // If the currently loaded run loader (if any) is not refering to the file and folder
118 // we are interested in then it is deleted and reopened with the required file and
121 if (fRunloader == NULL)
123 fRunloader = AliRunLoader::GetRunLoader();
124 if (fRunloader == NULL)
125 return LoadLoaders(filename, foldername);
127 // Fetch the current file and folder names.
128 fFilename = fRunloader->GetFileName();
129 fFoldername = fRunloader->GetEventFolder()->GetName();
132 // If filename or foldername are not the same as the ones currently selected then
134 if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
137 return LoadLoaders(filename, foldername);
143 Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
145 // Fetch the specified event from the runloader and reset all the track, cathode
146 // and address flags to force them to be reloaded.
148 if (fEventnumber < 0)
150 fEventnumber = fRunloader->GetEventNumber();
154 fHitAddressSet = kFALSE;
155 fSDigitAddressSet = kFALSE;
156 fDigitAddressSet = kFALSE;
157 fClusterAddressSet = kFALSE;
158 fTriggerAddressSet = kFALSE;
160 if ( event != fEventnumber )
162 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
163 fEventnumber = event;
167 fHitAddressSet = kFALSE;
168 fSDigitAddressSet = kFALSE;
169 fDigitAddressSet = kFALSE;
170 fClusterAddressSet = kFALSE;
171 fTriggerAddressSet = kFALSE;
177 Bool_t AliMUONDataInterface::FetchTreeK()
179 // Fetch the Kine tree from the current run loader.
181 if (fRunloader->TreeK() == NULL)
183 fRunloader->LoadKinematics("READ");
184 if (fRunloader->TreeK() == NULL)
186 AliError("Could not load TreeK.");
194 Bool_t AliMUONDataInterface::FetchTreeH()
196 // Fetch the Hits tree from the current muon loader.
197 // Set all the required addresses etc...
199 if (fMuonloader->TreeH() == NULL)
201 fMuonloader->LoadHits("READ");
202 if (fMuonloader->TreeH() == NULL)
204 AliError("Could not load TreeH.");
207 fData.SetTreeAddress("H");
208 fHitAddressSet = kTRUE;
210 else if ( ! fHitAddressSet )
212 fData.SetTreeAddress("H");
213 fHitAddressSet = kTRUE;
219 Bool_t AliMUONDataInterface::FetchTreeS()
221 // Fetch the S-Digits tree from the current muon loader.
222 // Set all the required addresses etc...
224 if (fMuonloader->TreeS() == NULL)
226 fMuonloader->LoadSDigits("READ");
227 if (fMuonloader->TreeS() == NULL)
229 AliError("Could not load TreeS.");
232 fData.SetTreeAddress("S");
233 fSDigitAddressSet = kTRUE;
235 else if ( ! fSDigitAddressSet )
237 fData.SetTreeAddress("S");
238 fSDigitAddressSet = kTRUE;
244 Bool_t AliMUONDataInterface::FetchTreeD()
246 // Fetch the digits tree from the current muon loader.
247 // Set all the required addresses etc...
249 if (fMuonloader->TreeD() == NULL)
251 fMuonloader->LoadDigits("READ");
252 if (fMuonloader->TreeD() == NULL)
254 AliError("Could not load TreeD.");
257 fData.SetTreeAddress("D");
258 fDigitAddressSet = kTRUE;
260 else if ( ! fDigitAddressSet )
262 fData.SetTreeAddress("D");
263 fDigitAddressSet = kTRUE;
269 Bool_t AliMUONDataInterface::FetchTreeR()
271 // Fetch the reconstructed objects tree from the current muon loader.
272 // Nore: The addresses must still be set.
274 if (fMuonloader->TreeR() == NULL)
276 fMuonloader->LoadRecPoints("READ");
277 if (fMuonloader->TreeR() == NULL)
279 AliError("Could not load TreeR.");
283 // Need to reset these flags so that the cluster and trigger address
284 // gets reset after this method.
285 fClusterAddressSet = kFALSE;
286 fTriggerAddressSet = kFALSE;
292 Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
294 // Returns the number of events in the specified file/folder, and -1 on error.
296 if ( ! FetchLoaders(filename, foldername) ) return -1;
297 return fRunloader->GetNumberOfEvents();
301 Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
303 // Returns the number of events in the specified file/folder, and -1 on error.
305 if ( ! FetchLoaders(filename, foldername) ) return -1;
306 if ( ! FetchEvent(event) ) return -1;
307 if ( ! FetchTreeK() ) return -1;
308 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
312 TParticle* AliMUONDataInterface::Particle(
313 TString filename, TString foldername, Int_t event, Int_t particle
316 // Returns the specified particle in the given file, folder and event.
317 // NULL is returned on error.
319 if ( ! FetchLoaders(filename, foldername) ) return NULL;
320 if ( ! FetchEvent(event) ) return NULL;
321 if ( ! FetchTreeK() ) return NULL;
323 TTree* treeK = fRunloader->TreeK();
325 treeK->GetBranch("Particles")->SetAddress(&p);
326 treeK->GetEvent(particle);
331 Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
333 // Returns the number of tracks in the specified file/folder and event.
334 // -1 is returned on error.
336 if ( ! FetchLoaders(filename, foldername) ) return -1;
337 if ( ! FetchEvent(event) ) return -1;
338 if ( ! FetchTreeH() ) return -1;
339 return fData.GetNtracks();
343 Int_t AliMUONDataInterface::NumberOfHits(
344 TString filename, TString foldername, Int_t event, Int_t track
347 // Returns the number of hits in the specified file/folder, event and track.
348 // -1 is returned on error.
350 if ( ! FetchLoaders(filename, foldername) ) return -1;
351 if ( ! FetchEvent(event) ) return -1;
352 if ( ! FetchTreeH() ) return -1;
354 if (fTrack < 0 || fTrack != track)
357 fData.GetTrack(track);
360 return fData.Hits()->GetEntriesFast();
364 AliMUONHit* AliMUONDataInterface::Hit(
365 TString filename, TString foldername, Int_t event,
366 Int_t track, Int_t hit
369 // Returns the specified hit in the given file, folder, event and track.
370 // NULL is returned on error.
372 if ( ! FetchLoaders(filename, foldername) ) return NULL;
373 if ( ! FetchEvent(event) ) return NULL;
374 if ( ! FetchTreeH() ) return NULL;
376 if (fTrack < 0 || fTrack != track)
379 fData.GetTrack(track);
382 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
386 Int_t AliMUONDataInterface::NumberOfSDigits(
387 TString filename, TString foldername, Int_t event,
388 Int_t chamber, Int_t cathode
391 // Returns the number of s-digits in the given file, folder, event,
392 // chamber and cathode. -1 is returned on error.
394 Assert( 0 <= chamber && chamber <= 13 );
395 Assert( 0 <= cathode && cathode <= 1 );
397 if ( ! FetchLoaders(filename, foldername) ) return -1;
398 if ( ! FetchEvent(event) ) return -1;
399 if ( ! FetchTreeS() ) return -1;
401 if ( fSCathode != cathode )
403 fData.ResetSDigits();
404 fData.GetCathodeS(cathode);
407 return fData.SDigits(chamber)->GetEntriesFast();
411 AliMUONDigit* AliMUONDataInterface::SDigit(
412 TString filename, TString foldername, Int_t event,
413 Int_t chamber, Int_t cathode, Int_t sdigit
416 // Returns the specified s-digit in the given file, folder, event,
417 // chamber and cathode. NULL is returned on error.
419 Assert( 0 <= chamber && chamber <= 13 );
420 Assert( 0 <= cathode && cathode <= 1 );
422 if ( ! FetchLoaders(filename, foldername) ) return NULL;
423 if ( ! FetchEvent(event) ) return NULL;
424 if ( ! FetchTreeS() ) return NULL;
426 if ( fSCathode != cathode )
428 fData.ResetSDigits();
429 fData.GetCathodeS(cathode);
432 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
436 Int_t AliMUONDataInterface::NumberOfDigits(
437 TString filename, TString foldername, Int_t event,
438 Int_t chamber, Int_t cathode
441 // Returns the number of digits in the given file, folder, event,
442 // chamber and cathode. -1 is returned on error.
443 Assert( 0 <= chamber && chamber <= 13 );
444 Assert( 0 <= cathode && cathode <= 1 );
446 if ( ! FetchLoaders(filename, foldername) ) return -1;
447 if ( ! FetchEvent(event) ) return -1;
448 if ( ! FetchTreeD() ) return -1;
450 if ( fCathode != cathode )
453 fData.GetCathode(cathode);
456 return fData.Digits(chamber)->GetEntriesFast();
460 AliMUONDigit* AliMUONDataInterface::Digit(
461 TString filename, TString foldername, Int_t event,
462 Int_t chamber, Int_t cathode, Int_t digit
465 // Returns the specified digit in the given file, folder, event,
466 // chamber and cathode. NULL is returned on error.
468 Assert( 0 <= chamber && chamber <= 13 );
469 Assert( 0 <= cathode && cathode <= 1 );
471 if ( ! FetchLoaders(filename, foldername) ) return NULL;
472 if ( ! FetchEvent(event) ) return NULL;
473 if ( ! FetchTreeD() ) return NULL;
475 if ( fCathode != cathode )
478 fData.GetCathode(cathode);
481 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
485 Int_t AliMUONDataInterface::NumberOfRawClusters(
486 TString filename, TString foldername, Int_t event, Int_t chamber
489 // Returns the number of raw clusters in the specified file, folder, event and chamber.
490 // -1 is returned or error.
492 Assert( 0 <= chamber && chamber <= 13 );
493 if ( ! FetchLoaders(filename, foldername) ) return -1;
494 if ( ! FetchEvent(event) ) return -1;
495 if ( ! FetchTreeR() ) return -1;
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 fData.RawClusters(chamber)->GetEntriesFast();
508 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
509 TString filename, TString foldername, Int_t event,
510 Int_t chamber, Int_t cluster
513 // Fetch the specified raw cluster from the given file, folder, event and chamber number.
514 // NULL is returned on error.
516 Assert( 0 <= chamber && chamber <= 13 );
517 if ( ! FetchLoaders(filename, foldername) ) return NULL;
518 if ( ! FetchEvent(event) ) return NULL;
519 if ( ! FetchTreeR() ) return NULL;
520 if ( ! fClusterAddressSet )
522 // If the raw cluster address in TreeR is not set yet then set it now.
523 fData.SetTreeAddress("RC");
524 fData.ResetRawClusters();
525 fData.GetRawClusters();
526 fClusterAddressSet = kTRUE;
528 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
532 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
534 // Return the number of local trigger objects in the specified file, folder and
535 // event number. -1 is returned on error.
537 if ( ! FetchLoaders(filename, foldername) ) return -1;
538 if ( ! FetchEvent(event) ) return -1;
539 if ( ! FetchTreeR() ) return -1;
540 if ( ! fTriggerAddressSet )
542 // If the local trigger address in TreeR is not set yet then set it now.
543 fData.SetTreeAddress("GLT");
544 fData.ResetTrigger();
546 fTriggerAddressSet = kTRUE;
548 return fData.LocalTrigger()->GetEntriesFast();
552 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
553 TString filename, TString foldername, Int_t event, Int_t trigger
556 // Fetch the specified local trigger object from the given file, folder and event number.
557 // NULL is returned on error.
559 if ( ! FetchLoaders(filename, foldername) ) return NULL;
560 if ( ! FetchEvent(event) ) return NULL;
561 if ( ! FetchTreeR() ) return NULL;
562 if ( ! fTriggerAddressSet )
564 // If the local trigger address in TreeR is not set yet then set it now.
565 fData.SetTreeAddress("GLT");
566 fData.ResetTrigger();
568 fTriggerAddressSet = kTRUE;
570 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
574 Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
576 // Set the current file and folder from which to fetch data.
577 // kTRUE is returned if the run and muon loaders were found, else kFALSE.
579 return FetchLoaders(filename, foldername);
583 Bool_t AliMUONDataInterface::GetEvent(Int_t event)
585 // Select the current event from which to fetch data.
586 // kTRUE is returned if the event was found, else kFALSE is returned.
588 return FetchEvent(event);
592 Int_t AliMUONDataInterface::NumberOfEvents()
594 // Get the number of events in the currently selected file.
595 // -1 is returned on error.
597 if (fRunloader == NULL)
599 AliError("File not set.");
602 return fRunloader->GetNumberOfEvents();
606 Int_t AliMUONDataInterface::NumberOfParticles()
608 // Get the number of particles in the current event.
609 // -1 is returned on error.
611 if (fRunloader == NULL)
613 AliError("File not set.");
616 if ( ! FetchTreeK() ) return -1;
617 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
621 TParticle* AliMUONDataInterface::Particle(Int_t particle)
623 // Fetch the specified particle from the current event.
624 // NULL is returned on error.
626 if (fRunloader == NULL)
628 AliError("File not set.");
631 if (fEventnumber < 0)
633 AliError("Event not chosen.");
636 if ( ! FetchTreeK() ) return NULL;
637 TTree* treeK = fRunloader->TreeK();
639 treeK->GetBranch("Particles")->SetAddress(&p);
640 treeK->GetEvent(particle);
645 Int_t AliMUONDataInterface::NumberOfTracks()
647 // Get the number of tracks in the current event.
648 // -1 is returned on error.
650 if (fRunloader == NULL)
652 AliError("File not set.");
655 if (fEventnumber < 0)
657 AliError( "Event not chosen.");
660 if ( ! FetchTreeH() ) return -1;
661 return fData.GetNtracks();
665 Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
667 // Get the number of hits for the given track in the current event.
668 // -1 is returned on error.
670 if (fRunloader == NULL)
672 AliError("File not set.");
675 if (fEventnumber < 0)
677 AliError("Event not chosen.");
680 if ( ! FetchTreeH() ) return -1;
681 if (fTrack < 0 || fTrack != track)
684 fData.GetTrack(track);
687 return fData.Hits()->GetEntriesFast();
691 AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
693 // Fetch the specified hit from the current event.
694 // NULL is returned on error.
696 if (fRunloader == NULL)
698 AliError("File not set.");
701 if (fEventnumber < 0)
703 AliError("Event not chosen.");
706 if ( ! FetchTreeH() ) return NULL;
707 if (fTrack < 0 || fTrack != track)
710 fData.GetTrack(track);
713 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
717 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
719 // Get the number of s-digits on the chamber, cathode in the current event.
720 // -1 is returned on error.
722 Assert( 0 <= chamber && chamber <= 13 );
723 Assert( 0 <= cathode && cathode <= 1 );
725 if (fRunloader == NULL)
727 AliError("File not set.");
730 if (fEventnumber < 0)
732 AliError("Event not chosen.");
736 if ( ! FetchTreeS() ) return -1;
737 if ( fSCathode != cathode )
739 fData.ResetSDigits();
740 fData.GetCathodeS(cathode);
743 return fData.SDigits(chamber)->GetEntriesFast();
747 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
749 // Fetch the specified s-digits on the chamber, cathode from the current event.
750 // NULL is returned on error.
752 Assert( 0 <= chamber && chamber <= 13 );
753 Assert( 0 <= cathode && cathode <= 1 );
755 if (fRunloader == NULL)
757 AliError("File not set.");
760 if (fEventnumber < 0)
762 AliError("Event not chosen.");
766 if ( ! FetchTreeS() ) return NULL;
767 if ( fSCathode != cathode )
769 fData.ResetSDigits();
770 fData.GetCathodeS(cathode);
773 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
777 Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
779 // Get the number of digits on the chamber, cathode in the current event.
780 // -1 is returned on error.
782 Assert( 0 <= chamber && chamber <= 13 );
783 Assert( 0 <= cathode && cathode <= 1 );
785 if (fRunloader == NULL)
787 AliError("File not set.");
790 if (fEventnumber < 0)
792 AliError("Event not chosen.");
796 if ( ! FetchTreeD() ) return -1;
797 if ( fCathode != cathode )
800 fData.GetCathode(cathode);
803 return fData.Digits(chamber)->GetEntriesFast();
807 AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
809 // Fetch the specified digits on the chamber, cathode from the current event.
810 // NULL is returned on error.
812 Assert( 0 <= chamber && chamber <= 13 );
813 Assert( 0 <= cathode && cathode <= 1 );
815 if (fRunloader == NULL)
817 AliError("File not set.");
820 if (fEventnumber < 0)
822 AliError("Event not chosen.");
826 if ( ! FetchTreeD() ) return NULL;
827 if ( fCathode != cathode )
830 fData.GetCathode(cathode);
833 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
837 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
839 // Get the number of raw clusters on the given chamber in the current event.
840 // -1 is returned on error.
842 Assert( 0 <= chamber && chamber <= 13 );
844 if (fRunloader == NULL)
846 AliError("File not set.");
849 if (fEventnumber < 0)
851 AliError("Event not chosen.");
855 if ( ! FetchTreeR() ) return -1;
856 if ( ! fClusterAddressSet )
858 fData.SetTreeAddress("RC");
859 fData.ResetRawClusters();
860 fData.GetRawClusters();
861 fClusterAddressSet = kTRUE;
863 return fData.RawClusters(chamber)->GetEntriesFast();
867 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
869 // Fetch the specified raw cluster on the given chamber from the current event.
870 // NULL is returned on error.
872 Assert( 0 <= chamber && chamber <= 13 );
874 if (fRunloader == NULL)
876 AliError("File not set.");
879 if (fEventnumber < 0)
881 AliError("Event not chosen.");
885 if ( ! FetchTreeR() ) return NULL;
886 if ( ! fClusterAddressSet )
888 fData.SetTreeAddress("RC");
889 fData.ResetRawClusters();
890 fData.GetRawClusters();
891 fClusterAddressSet = kTRUE;
893 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
897 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
899 // Get the number of local trigger objects in the current event.
900 // -1 is returned on error.
902 if (fRunloader == NULL)
904 AliError("File not set.");
907 if (fEventnumber < 0)
909 AliError("Event not chosen.");
913 if ( ! FetchTreeR() ) return -1;
914 if ( ! fTriggerAddressSet )
916 fData.SetTreeAddress("GLT");
917 fData.ResetTrigger();
919 fTriggerAddressSet = kTRUE;
921 return fData.LocalTrigger()->GetEntriesFast();
925 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
927 // Fetch the specified local trigger object from the current event.
928 // NULL is returned on error.
930 if (fRunloader == NULL)
932 AliError("File not set.");
935 if (fEventnumber < 0)
937 AliError( "Event not chosen.");
941 if ( ! FetchTreeR() ) return NULL;
942 if ( ! fTriggerAddressSet )
944 fData.SetTreeAddress("GLT");
945 fData.ResetTrigger();
947 fTriggerAddressSet = kTRUE;
949 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );