From 48b32e42af8fb8fd8f0205313dd29dc1170ee8d6 Mon Sep 17 00:00:00 2001 From: martinez Date: Thu, 8 Apr 2004 15:49:46 +0000 Subject: [PATCH] Inhereted RemapTrackHitIDs(Int_t* map) method in AliMUON. New MUONData interface (Artur) --- MUON/AliMUON.cxx | 27 + MUON/AliMUON.h | 3 + MUON/AliMUONDataInterface.cxx | 926 ++++++++++++++++++++++++++++++++++ MUON/AliMUONDataInterface.h | 138 +++++ MUON/MUONLinkDef.h | 1 + MUON/libMUON.pkg | 2 +- 6 files changed, 1096 insertions(+), 1 deletion(-) create mode 100644 MUON/AliMUONDataInterface.cxx create mode 100644 MUON/AliMUONDataInterface.h diff --git a/MUON/AliMUON.cxx b/MUON/AliMUON.cxx index 679599f21f2..eb184bdcfcc 100644 --- a/MUON/AliMUON.cxx +++ b/MUON/AliMUON.cxx @@ -638,3 +638,30 @@ AliMUON& AliMUON::operator = (const AliMUON& /*rhs*/) // dummy version return *this; } +//________________________________________________________________________ +void AliMUON::RemapTrackHitIDs(Int_t* map) +{ +// Remaps the track numbers in the hits arrays, so that they correspond +// to the entry indices in the Kine tree. +// The correspondance is not direct. To get the real index into the Kine tree +// compute the particle index as follows: +// +// num_primaries = AliStack::GetNprimary(); +// num_tracks = AliStack::GetNtracks(); +// track = AliMUONHit::Track() +// +// if (track < num_primaries) +// particleindex = track + num_tracks - num_primaries; +// else +// particleindex = track - num_primaries; + + // Remap the track numbers based on the specified map. + AliMUONData* data = GetMUONData(); + TClonesArray* hits = data->Hits(); + for (Int_t i = 0; i < hits->GetEntriesFast(); i++) + { + AliMUONHit* hit = static_cast( hits->At(i) ); + hit->SetTrack( map[hit->Track()] ); + }; +}; + diff --git a/MUON/AliMUON.h b/MUON/AliMUON.h index 163659c98ca..f1ce9cf7597 100644 --- a/MUON/AliMUON.h +++ b/MUON/AliMUON.h @@ -114,6 +114,9 @@ class AliMUON : public AliDetector { // Copy Operator AliMUON& operator = (const AliMUON& rhs); + // Inherited and overridden from AliModule: + virtual void RemapTrackHitIDs(Int_t * map); + protected: Int_t fNCh; // Number of chambers Int_t fNTrackingCh; // Number of tracking chambers* diff --git a/MUON/AliMUONDataInterface.cxx b/MUON/AliMUONDataInterface.cxx new file mode 100644 index 00000000000..1224affc9b4 --- /dev/null +++ b/MUON/AliMUONDataInterface.cxx @@ -0,0 +1,926 @@ + +// Author: Artur Szostak +// email: artur@alice.phy.uct.ac.za + +#include + +#include "AliRunLoader.h" +#include "AliLoader.h" + +#include "AliMUONDataInterface.h" +#include "AliMUONData.h" + + +ClassImp(AliMUONDataInterface) + + +AliMUONDataInterface::AliMUONDataInterface() + : TObject(), fData(NULL, "MUON", "MUON") +{ +// Set all internal pointers to NULL and indices to -1. + + Reset(); +}; + + +AliMUONDataInterface::~AliMUONDataInterface() +{ +// Delete the runloader when done. +// If the runloader is not to be deleted then call Reset just before +// the destructor is called. + + if (fRunloader != NULL) + delete fRunloader; +}; + + +void AliMUONDataInterface::Reset() +{ +// Sets all internal pointers to NULL and indices to -1. +// Note: No resources are released! +// Specificaly AliRunLoader is not deleted. + + fRunloader = NULL; + fMuonloader = NULL; + fEventnumber = -1; + fTrack = -1; + fSCathode = -1; + fCathode = -1; + fHitAddressSet = kFALSE; + fSDigitAddressSet = kFALSE; + fDigitAddressSet = kFALSE; + fClusterAddressSet = kFALSE; + fTriggerAddressSet = kFALSE; +}; + + +Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername) +{ +// Load the run and muon loaders from the specified file and folder. +// kTRUE is returned on success and kFALSE on failure. + + fRunloader = AliRunLoader::Open(filename, foldername, "READ"); + if (fRunloader == NULL) + { + Error("LoadLoaders", "Could not find or load the run loader for the file: %s and folder: %s", + (const char*)filename, (const char*)foldername); + return kFALSE; + }; + fMuonloader = fRunloader->GetLoader("MUONLoader"); + if (fMuonloader == NULL) + { + Error("LoadLoaders", "Could not find the MUON loader in file: %s and folder: %s", + (const char*)filename, (const char*)foldername); + fRunloader = NULL; + return kFALSE; + }; + + // Need to connect the muon loader to the AliMUONData object, + // else class to fData will return NULL. + fData.SetLoader(fMuonloader); + + fFilename = filename; + fFoldername = foldername; + fEventnumber = -1; // Reset the event number to force the event to be loaded. + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername) +{ +// Fetch the run loader and muon loader objects from memory if they already exist, +// or from memory if they do not. +// If the currently loaded run loader (if any) is not refering to the file and folder +// we are interested in then it is deleted and reopened with the required file and +// folder names. + + if (fRunloader == NULL) + { + fRunloader = AliRunLoader::GetRunLoader(); + if (fRunloader == NULL) + return LoadLoaders(filename, foldername); + + // Fetch the current file and folder names. + fFilename = fRunloader->GetFileName(); + fFoldername = fRunloader->GetEventFolder()->GetName(); + }; + + // If filename or foldername are not the same as the ones currently selected then + // reopen the file. + if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 ) + { + delete fRunloader; + return LoadLoaders(filename, foldername); + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchEvent(Int_t event) +{ +// Fetch the specified event from the runloader and reset all the track, cathode +// and address flags to force them to be reloaded. + + if (fEventnumber < 0) + { + fEventnumber = fRunloader->GetEventNumber(); + fTrack = -1; + fSCathode = -1; + fCathode = -1; + fHitAddressSet = kFALSE; + fSDigitAddressSet = kFALSE; + fDigitAddressSet = kFALSE; + fClusterAddressSet = kFALSE; + fTriggerAddressSet = kFALSE; + }; + if ( event != fEventnumber ) + { + if ( fRunloader->GetEvent(event) < 0 ) return kFALSE; + fEventnumber = event; + fTrack = -1; + fSCathode = -1; + fCathode = -1; + fHitAddressSet = kFALSE; + fSDigitAddressSet = kFALSE; + fDigitAddressSet = kFALSE; + fClusterAddressSet = kFALSE; + fTriggerAddressSet = kFALSE; + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchTreeK() +{ +// Fetch the Kine tree from the current run loader. + + if (fRunloader->TreeK() == NULL) + { + fRunloader->LoadKinematics("READ"); + if (fRunloader->TreeK() == NULL) + { + Error("FetchTreeK", "Could not load TreeK."); + return kFALSE; + }; + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchTreeH() +{ +// Fetch the Hits tree from the current muon loader. +// Set all the required addresses etc... + + if (fMuonloader->TreeH() == NULL) + { + fMuonloader->LoadHits("READ"); + if (fMuonloader->TreeH() == NULL) + { + Error("FetchTreeH", "Could not load TreeH."); + return kFALSE; + }; + fData.SetTreeAddress("H"); + fHitAddressSet = kTRUE; + } + else if ( ! fHitAddressSet ) + { + fData.SetTreeAddress("H"); + fHitAddressSet = kTRUE; + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchTreeS() +{ +// Fetch the S-Digits tree from the current muon loader. +// Set all the required addresses etc... + + if (fMuonloader->TreeS() == NULL) + { + fMuonloader->LoadSDigits("READ"); + if (fMuonloader->TreeS() == NULL) + { + Error("FetchTreeS", "Could not load TreeS."); + return kFALSE; + }; + fData.SetTreeAddress("S"); + fSDigitAddressSet = kTRUE; + } + else if ( ! fSDigitAddressSet ) + { + fData.SetTreeAddress("S"); + fSDigitAddressSet = kTRUE; + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchTreeD() +{ +// Fetch the digits tree from the current muon loader. +// Set all the required addresses etc... + + if (fMuonloader->TreeD() == NULL) + { + fMuonloader->LoadDigits("READ"); + if (fMuonloader->TreeD() == NULL) + { + Error("FetchTreeD", "Could not load TreeD."); + return kFALSE; + }; + fData.SetTreeAddress("D"); + fDigitAddressSet = kTRUE; + } + else if ( ! fDigitAddressSet ) + { + fData.SetTreeAddress("D"); + fDigitAddressSet = kTRUE; + }; + return kTRUE; +}; + + +Bool_t AliMUONDataInterface::FetchTreeR() +{ +// Fetch the reconstructed objects tree from the current muon loader. +// Nore: The addresses must still be set. + + if (fMuonloader->TreeR() == NULL) + { + fMuonloader->LoadRecPoints("READ"); + if (fMuonloader->TreeR() == NULL) + { + Error("FetchTreeR", "Could not load TreeR."); + return kFALSE; + }; + + // Need to reset these flags so that the cluster and trigger address + // gets reset after this method. + fClusterAddressSet = kFALSE; + fTriggerAddressSet = kFALSE; + }; + return kTRUE; +}; + + +Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername) +{ +// Returns the number of events in the specified file/folder, and -1 on error. + + if ( ! FetchLoaders(filename, foldername) ) return -1; + return fRunloader->GetNumberOfEvents(); +}; + + +Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event) +{ +// Returns the number of events in the specified file/folder, and -1 on error. + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeK() ) return -1; + return (Int_t) fRunloader->TreeK()->GetEntriesFast(); +}; + + +TParticle* AliMUONDataInterface::Particle( + TString filename, TString foldername, Int_t event, Int_t particle + ) +{ +// Returns the specified particle in the given file, folder and event. +// NULL is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeK() ) return NULL; + + TTree* treeK = fRunloader->TreeK(); + TParticle* p = NULL; + treeK->GetBranch("Particles")->SetAddress(&p); + treeK->GetEvent(particle); + return p; +}; + + +Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event) +{ +// Returns the number of tracks in the specified file/folder and event. +// -1 is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeH() ) return -1; + return fData.GetNtracks(); +}; + + +Int_t AliMUONDataInterface::NumberOfHits( + TString filename, TString foldername, Int_t event, Int_t track + ) +{ +// Returns the number of hits in the specified file/folder, event and track. +// -1 is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeH() ) return -1; + + if (fTrack < 0 || fTrack != track) + { + fData.ResetHits(); + fData.GetTrack(track); + fTrack = track; + }; + return fData.Hits()->GetEntriesFast(); +}; + + +AliMUONHit* AliMUONDataInterface::Hit( + TString filename, TString foldername, Int_t event, + Int_t track, Int_t hit + ) +{ +// Returns the specified hit in the given file, folder, event and track. +// NULL is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeH() ) return NULL; + + if (fTrack < 0 || fTrack != track) + { + fData.ResetHits(); + fData.GetTrack(track); + fTrack = track; + }; + return static_cast( fData.Hits()->At(hit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfSDigits( + TString filename, TString foldername, Int_t event, + Int_t chamber, Int_t cathode + ) +{ +// Returns the number of s-digits in the given file, folder, event, +// chamber and cathode. -1 is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeS() ) return -1; + + if ( fSCathode != cathode ) + { + fData.ResetSDigits(); + fData.GetCathodeS(cathode); + fSCathode = cathode; + }; + return fData.SDigits(chamber)->GetEntriesFast(); +}; + + +AliMUONDigit* AliMUONDataInterface::SDigit( + TString filename, TString foldername, Int_t event, + Int_t chamber, Int_t cathode, Int_t sdigit + ) +{ +// Returns the specified s-digit in the given file, folder, event, +// chamber and cathode. NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeS() ) return NULL; + + if ( fSCathode != cathode ) + { + fData.ResetSDigits(); + fData.GetCathodeS(cathode); + fSCathode = cathode; + }; + return static_cast( fData.SDigits(chamber)->At(sdigit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfDigits( + TString filename, TString foldername, Int_t event, + Int_t chamber, Int_t cathode + ) +{ +// Returns the number of digits in the given file, folder, event, +// chamber and cathode. -1 is returned on error. + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeD() ) return -1; + + if ( fCathode != cathode ) + { + fData.ResetDigits(); + fData.GetCathode(cathode); + fCathode = cathode; + }; + return fData.Digits(chamber)->GetEntriesFast(); +}; + + +AliMUONDigit* AliMUONDataInterface::Digit( + TString filename, TString foldername, Int_t event, + Int_t chamber, Int_t cathode, Int_t digit + ) +{ +// Returns the specified digit in the given file, folder, event, +// chamber and cathode. NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeD() ) return NULL; + + if ( fCathode != cathode ) + { + fData.ResetDigits(); + fData.GetCathode(cathode); + fCathode = cathode; + }; + return static_cast( fData.Digits(chamber)->At(digit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfRawClusters( + TString filename, TString foldername, Int_t event, Int_t chamber + ) +{ +// Returns the number of raw clusters in the specified file, folder, event and chamber. +// -1 is returned or error. + + Assert( 0 <= chamber && chamber <= 13 ); + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeR() ) return -1; + if ( ! fClusterAddressSet ) + { + // If the raw cluster address in TreeR is not set yet then set it now. + fData.SetTreeAddress("RC"); + fData.ResetRawClusters(); + fData.GetRawClusters(); + fClusterAddressSet = kTRUE; + }; + return fData.RawClusters(chamber)->GetEntriesFast(); +}; + + +AliMUONRawCluster* AliMUONDataInterface::RawCluster( + TString filename, TString foldername, Int_t event, + Int_t chamber, Int_t cluster + ) +{ +// Fetch the specified raw cluster from the given file, folder, event and chamber number. +// NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeR() ) return NULL; + if ( ! fClusterAddressSet ) + { + // If the raw cluster address in TreeR is not set yet then set it now. + fData.SetTreeAddress("RC"); + fData.ResetRawClusters(); + fData.GetRawClusters(); + fClusterAddressSet = kTRUE; + }; + return static_cast( fData.RawClusters(chamber)->At(cluster) ); +}; + + +Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event) +{ +// Return the number of local trigger objects in the specified file, folder and +// event number. -1 is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return -1; + if ( ! FetchEvent(event) ) return -1; + if ( ! FetchTreeR() ) return -1; + if ( ! fTriggerAddressSet ) + { + // If the local trigger address in TreeR is not set yet then set it now. + fData.SetTreeAddress("GLT"); + fData.ResetTrigger(); + fData.GetTrigger(); + fTriggerAddressSet = kTRUE; + }; + return fData.LocalTrigger()->GetEntriesFast(); +}; + + +AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger( + TString filename, TString foldername, Int_t event, Int_t trigger + ) +{ +// Fetch the specified local trigger object from the given file, folder and event number. +// NULL is returned on error. + + if ( ! FetchLoaders(filename, foldername) ) return NULL; + if ( ! FetchEvent(event) ) return NULL; + if ( ! FetchTreeR() ) return NULL; + if ( ! fTriggerAddressSet ) + { + // If the local trigger address in TreeR is not set yet then set it now. + fData.SetTreeAddress("GLT"); + fData.ResetTrigger(); + fData.GetTrigger(); + fTriggerAddressSet = kTRUE; + }; + return static_cast( fData.LocalTrigger()->At(trigger) ); +}; + + +Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername) +{ +// Set the current file and folder from which to fetch data. +// kTRUE is returned if the run and muon loaders were found, else kFALSE. + + return FetchLoaders(filename, foldername); +}; + + +Bool_t AliMUONDataInterface::GetEvent(Int_t event) +{ +// Select the current event from which to fetch data. +// kTRUE is returned if the event was found, else kFALSE is returned. + + return FetchEvent(event); +}; + + +Int_t AliMUONDataInterface::NumberOfEvents() +{ +// Get the number of events in the currently selected file. +// -1 is returned on error. + + if (fRunloader == NULL) + { + Error("NumberOfEvents", "File not set."); + return -1; + }; + return fRunloader->GetNumberOfEvents(); +}; + + +Int_t AliMUONDataInterface::NumberOfParticles() +{ +// Get the number of particles in the current event. +// -1 is returned on error. + + if (fRunloader == NULL) + { + Error("NumberOfParticles", "File not set."); + return -1; + }; + if ( ! FetchTreeK() ) return -1; + return (Int_t) fRunloader->TreeK()->GetEntriesFast(); +}; + + +TParticle* AliMUONDataInterface::Particle(Int_t particle) +{ +// Fetch the specified particle from the current event. +// NULL is returned on error. + + if (fRunloader == NULL) + { + Error("Particle", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("Particle", "Event not chosen."); + return NULL; + }; + if ( ! FetchTreeK() ) return NULL; + TTree* treeK = fRunloader->TreeK(); + TParticle* p = NULL; + treeK->GetBranch("Particles")->SetAddress(&p); + treeK->GetEvent(particle); + return p; +}; + + +Int_t AliMUONDataInterface::NumberOfTracks() +{ +// Get the number of tracks in the current event. +// -1 is returned on error. + + if (fRunloader == NULL) + { + Error("NumberOfTracks", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfTracks", "Event not chosen."); + return -1; + }; + if ( ! FetchTreeH() ) return -1; + return fData.GetNtracks(); +}; + + +Int_t AliMUONDataInterface::NumberOfHits(Int_t track) +{ +// Get the number of hits for the given track in the current event. +// -1 is returned on error. + + if (fRunloader == NULL) + { + Error("NumberOfHits", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfHits", "Event not chosen."); + return -1; + }; + if ( ! FetchTreeH() ) return -1; + if (fTrack < 0 || fTrack != track) + { + fData.ResetHits(); + fData.GetTrack(track); + fTrack = track; + }; + return fData.Hits()->GetEntriesFast(); +}; + + +AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit) +{ +// Fetch the specified hit from the current event. +// NULL is returned on error. + + if (fRunloader == NULL) + { + Error("Hit", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("Hit", "Event not chosen."); + return NULL; + }; + if ( ! FetchTreeH() ) return NULL; + if (fTrack < 0 || fTrack != track) + { + fData.ResetHits(); + fData.GetTrack(track); + fTrack = track; + }; + return static_cast( fData.Hits()->At(hit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode) +{ +// Get the number of s-digits on the chamber, cathode in the current event. +// -1 is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if (fRunloader == NULL) + { + Error("NumberOfSDigits", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfSDigits", "Event not chosen."); + return -1; + }; + + if ( ! FetchTreeS() ) return -1; + if ( fSCathode != cathode ) + { + fData.ResetSDigits(); + fData.GetCathodeS(cathode); + fSCathode = cathode; + }; + return fData.SDigits(chamber)->GetEntriesFast(); +}; + + +AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit) +{ +// Fetch the specified s-digits on the chamber, cathode from the current event. +// NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if (fRunloader == NULL) + { + Error("SDigit", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("SDigit", "Event not chosen."); + return NULL; + }; + + if ( ! FetchTreeS() ) return NULL; + if ( fSCathode != cathode ) + { + fData.ResetSDigits(); + fData.GetCathodeS(cathode); + fSCathode = cathode; + }; + return static_cast( fData.SDigits(chamber)->At(sdigit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode) +{ +// Get the number of digits on the chamber, cathode in the current event. +// -1 is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if (fRunloader == NULL) + { + Error("NumberOfDigits", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfDigits", "Event not chosen."); + return -1; + }; + + if ( ! FetchTreeD() ) return -1; + if ( fCathode != cathode ) + { + fData.ResetDigits(); + fData.GetCathode(cathode); + fCathode = cathode; + }; + return fData.Digits(chamber)->GetEntriesFast(); +}; + + +AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit) +{ +// Fetch the specified digits on the chamber, cathode from the current event. +// NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + Assert( 0 <= cathode && cathode <= 1 ); + + if (fRunloader == NULL) + { + Error("Digit", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("Digit", "Event not chosen."); + return NULL; + }; + + if ( ! FetchTreeD() ) return NULL; + if ( fCathode != cathode ) + { + fData.ResetDigits(); + fData.GetCathode(cathode); + fCathode = cathode; + }; + return static_cast( fData.Digits(chamber)->At(digit) ); +}; + + +Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber) +{ +// Get the number of raw clusters on the given chamber in the current event. +// -1 is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + + if (fRunloader == NULL) + { + Error("NumberOfRawClusters", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfRawClusters", "Event not chosen."); + return -1; + }; + + if ( ! FetchTreeR() ) return -1; + if ( ! fClusterAddressSet ) + { + fData.SetTreeAddress("RC"); + fData.ResetRawClusters(); + fData.GetRawClusters(); + fClusterAddressSet = kTRUE; + }; + return fData.RawClusters(chamber)->GetEntriesFast(); +}; + + +AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster) +{ +// Fetch the specified raw cluster on the given chamber from the current event. +// NULL is returned on error. + + Assert( 0 <= chamber && chamber <= 13 ); + + if (fRunloader == NULL) + { + Error("RawCluster", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("RawCluster", "Event not chosen."); + return NULL; + }; + + if ( ! FetchTreeR() ) return NULL; + if ( ! fClusterAddressSet ) + { + fData.SetTreeAddress("RC"); + fData.ResetRawClusters(); + fData.GetRawClusters(); + fClusterAddressSet = kTRUE; + }; + return static_cast( fData.RawClusters(chamber)->At(cluster) ); +}; + + +Int_t AliMUONDataInterface::NumberOfLocalTriggers() +{ +// Get the number of local trigger objects in the current event. +// -1 is returned on error. + + if (fRunloader == NULL) + { + Error("NumberOfLocalTriggers", "File not set."); + return -1; + }; + if (fEventnumber < 0) + { + Error("NumberOfLocalTriggers", "Event not chosen."); + return -1; + }; + + if ( ! FetchTreeR() ) return -1; + if ( ! fTriggerAddressSet ) + { + fData.SetTreeAddress("GLT"); + fData.ResetTrigger(); + fData.GetTrigger(); + fTriggerAddressSet = kTRUE; + }; + return fData.LocalTrigger()->GetEntriesFast(); +}; + + +AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger) +{ +// Fetch the specified local trigger object from the current event. +// NULL is returned on error. + + if (fRunloader == NULL) + { + Error("LocalTrigger", "File not set."); + return NULL; + }; + if (fEventnumber < 0) + { + Error("LocalTrigger", "Event not chosen."); + return NULL; + }; + + if ( ! FetchTreeR() ) return NULL; + if ( ! fTriggerAddressSet ) + { + fData.SetTreeAddress("GLT"); + fData.ResetTrigger(); + fData.GetTrigger(); + fTriggerAddressSet = kTRUE; + }; + return static_cast( fData.LocalTrigger()->At(trigger) ); +}; diff --git a/MUON/AliMUONDataInterface.h b/MUON/AliMUONDataInterface.h new file mode 100644 index 00000000000..e7a8f142c37 --- /dev/null +++ b/MUON/AliMUONDataInterface.h @@ -0,0 +1,138 @@ +#ifndef ALI_MUON_DATA_INTERFACE_CLASS_H +#define ALI_MUON_DATA_INTERFACE_CLASS_H + +// Author: Artur Szostak +// email: artur@alice.phy.uct.ac.za + +#include +#include +#include + +#include "AliRunLoader.h" +#include "AliLoader.h" +#include "AliMUONData.h" + +#include "AliMUONHit.h" +#include "AliMUONDigit.h" +#include "AliMUONRawCluster.h" +#include "AliMUONLocalTrigger.h" + + +// An easy to use interface to the MUON module data stored in TreeK, TreeH, TreeS, TreeD and TreeR +// One can fetch any of the data objects with all the calls to runloader, muon loader and AliMUONData +// done behind the scenes and automatically. +// This interface in not necessarily the fastest way to fetch the data but it is the easiest. +// Note: If independant calls to the run loader, muon loader or AliMUONData objects are interspersed +// with calls to the AliMUONDataInterface to fetch data, one might need to call the Reset method +// between these method calls at some point to prevent AliMUONDataInterface from getting confused. +// This is necessary since this object assumes the state of runloader, muon loader nor AliMUONData +// has not changed between calls. If the state has changes then one must call Reset so that +// AliMUONDataInterface refreshes what it knows about the state of the loader and AliMUONData objects. +// +class AliMUONDataInterface : public TObject +{ +public: + + AliMUONDataInterface(); + ~AliMUONDataInterface(); + + // Sets all internal pointers to NULL without releasing the current runloader. + void Reset(); + + Int_t NumberOfEvents(TString filename, TString foldername); + + Int_t NumberOfParticles(TString filename, TString foldername, Int_t event); + TParticle* Particle(TString filename, TString foldername, Int_t event, Int_t particle); + + Int_t NumberOfTracks(TString filename, TString foldername, Int_t event); + Int_t NumberOfHits(TString filename, TString foldername, Int_t event, Int_t track); + AliMUONHit* Hit(TString filename, TString foldername, Int_t event, Int_t track, Int_t hit); + + Int_t NumberOfSDigits(TString filename, TString foldername, Int_t event, Int_t chamber, Int_t cathode); + AliMUONDigit* SDigit(TString filename, TString foldername, Int_t event, Int_t chamber, Int_t cathode, Int_t sdigit); + + Int_t NumberOfDigits(TString filename, TString foldername, Int_t event, Int_t chamber, Int_t cathode); + AliMUONDigit* Digit(TString filename, TString foldername, Int_t event, Int_t chamber, Int_t cathode, Int_t digit); + + Int_t NumberOfRawClusters(TString filename, TString foldername, Int_t event, Int_t chamber); + AliMUONRawCluster* RawCluster(TString filename, TString foldername, Int_t event, Int_t chamber, Int_t cluster); + + Int_t NumberOfLocalTriggers(TString filename, TString foldername, Int_t event); + AliMUONLocalTrigger* LocalTrigger(TString filename, TString foldername, Int_t event, Int_t trigger); + + Bool_t SetFile(TString filename = "galice.root", TString foldername = "MUONFolder"); + Bool_t GetEvent(Int_t event = 0); + + Int_t NumberOfEvents(); + + Int_t NumberOfParticles(); + TParticle* Particle(Int_t particle); + + Int_t NumberOfTracks(); + Int_t NumberOfHits(Int_t track); + AliMUONHit* Hit(Int_t track, Int_t hit); + + Int_t NumberOfSDigits(Int_t chamber, Int_t cathode); + AliMUONDigit* SDigit(Int_t chamber, Int_t cathode, Int_t sdigit); + + Int_t NumberOfDigits(Int_t chamber, Int_t cathode); + AliMUONDigit* Digit(Int_t chamber, Int_t cathode, Int_t digit); + + Int_t NumberOfRawClusters(Int_t chamber); + AliMUONRawCluster* RawCluster(Int_t chamber, Int_t cluster); + + Int_t NumberOfLocalTriggers(); + AliMUONLocalTrigger* LocalTrigger(Int_t trigger); + + + // Returns the name of the currently selected file. + TString CurrentFile() { return fFilename; }; + + // Returns the name of the currently selected folder. + TString CurrentFolder() { return fFoldername; }; + + // Returns the number of the currently selected event. + Int_t CurrentEvent() { return fEventnumber; }; + + // Returns the currently selected track. + Int_t CurrentTrack() { return fTrack; }; + + // Returns the currently selected cathode in TreeS. + Int_t CurrentSCathode() { return fSCathode; }; + + // Returns the currently selected cathode in TreeD. + Int_t CurrentDCathode() { return fCathode; }; + +private: + + Bool_t LoadLoaders(TString filename, TString foldername); + Bool_t FetchLoaders(TString filename, TString foldername); + Bool_t FetchEvent(Int_t event); + Bool_t FetchTreeK(); + Bool_t FetchTreeH(); + Bool_t FetchTreeS(); + Bool_t FetchTreeD(); + Bool_t FetchTreeR(); + + + Bool_t fHitAddressSet; //! Flag specifying if the TTree address for the hit tree was set. + Bool_t fSDigitAddressSet; //! Flag specifying if the TTree address for the s-digit tree was set. + Bool_t fDigitAddressSet; //! Flag specifying if the TTree address for the digit tree was set. + Bool_t fClusterAddressSet; //! Flag specifying if the TTree address for the cluster tree was set. + Bool_t fTriggerAddressSet; //! Flag specifying if the TTree address for the trigger tree was set. + + AliRunLoader* fRunloader; //! Pointer to the runloader object used. + AliLoader* fMuonloader; //! Pointer to the muon loader object used. + AliMUONData fData; //! Pointer to the muon raw data interface. + TString fFilename; //! The file name from which we are fetching data. + TString fFoldername; //! The folder name from which we are fetching data. + Int_t fEventnumber; //! The currently selected event. + Int_t fTrack; //! The currently selected track. + Int_t fSCathode; //! The currently selected cathode in TreeS. + Int_t fCathode; //! The currently selected cathode in TreeD. + + ClassDef(AliMUONDataInterface, 0) // A easy to use interface to data in the MUON module. +}; + + +#endif // ALI_MUON_DATA_INTERFACE_CLASS_H diff --git a/MUON/MUONLinkDef.h b/MUON/MUONLinkDef.h index 65f3ac59b45..3845c073a18 100644 --- a/MUON/MUONLinkDef.h +++ b/MUON/MUONLinkDef.h @@ -7,6 +7,7 @@ #pragma link C++ class AliMUONv1+; #pragma link C++ class AliMUONv3+; #pragma link C++ class AliMUONData+; +#pragma link C++ class AliMUONDataInterface+; #pragma link C++ class AliMUONLoader+; #pragma link C++ class AliMUONHit+; #pragma link C++ class AliMUONPadHit+; diff --git a/MUON/libMUON.pkg b/MUON/libMUON.pkg index fef4670e99f..6aac350bf77 100644 --- a/MUON/libMUON.pkg +++ b/MUON/libMUON.pkg @@ -35,7 +35,7 @@ SRCS = AliMUONChamber.cxx AliMUONChamberTrigger.cxx \ AliMUONRecoEvent.cxx AliMUONRecoDisplay.cxx \ AliMUONMerger.cxx AliMUONFactory.cxx AliMUONDigitizer.cxx AliMUONDigitizerv1.cxx AliMUONDigitizerv2.cxx AliMUONSDigitizerv1.cxx \ AliMUONTrackK.cxx AliMUONClusterFinderAZ.cxx AliMUONPixel.cxx \ - AliMUONLoader.cxx AliMUONData.cxx + AliMUONLoader.cxx AliMUONData.cxx AliMUONDataInterface.cxx SRCS += AliMUONSt1Segmentation.cxx AliMUONSt1Response.cxx \ AliMUONSt1ElectronicElement.cxx AliMUONSt1SpecialMotif.cxx \ -- 2.39.3