/* $Id$ */
#include "AliMUONDataInterface.h"
-#include "AliMUONDigit.h"
#include "AliMUONGeometryTransformer.h"
-#include "AliMUONGlobalTrigger.h"
-#include "AliMUONHit.h"
-#include "AliMUONLocalTrigger.h"
+#include "AliMUONVDigit.h"
#include "AliMUONRawCluster.h"
#include "AliMUONTrack.h"
+#include "AliMUONLocalTrigger.h"
+#include "AliMUONRegionalTrigger.h"
+#include "AliMUONGlobalTrigger.h"
+#include "AliMUONTriggerTrack.h"
#include "AliMUONTriggerCircuit.h"
#include "AliMUONVClusterStore.h"
#include "AliMUONVDigitStore.h"
#include "AliMUONVTriggerTrackStore.h"
#include "AliMpCDB.h"
+#include "AliMpIntPair.h"
+#include "AliMpDEManager.h"
+#include "AliMpConstants.h"
+#include "AliMpSegmentation.h"
+
#include "AliLoader.h"
#include "AliLog.h"
-#include "AliLog.h"
#include "AliRunLoader.h"
#include <TError.h>
#include <TList.h>
#include <TNtuple.h>
#include <TSystem.h>
+#include <TIterator.h>
+#include <cstdlib>
+#include <cassert>
//-----------------------------------------------------------------------------
/// \class AliMUONDataInterface
/// This interface in not necessarily the fastest way to fetch the data but
/// it is the easiest.
///
-/// \author Laurent Aphecetche, Subatech
+/// \author Laurent Aphecetche, Subatech & Artur Szostak <artursz@iafrica.com> (University of Cape Town)
//-----------------------------------------------------------------------------
/// \cond CLASSIMP
ClassImp(AliMUONDataInterface)
/// \endcond
-//AliLoader* fLoader; //!< Tree accessor
-//AliMUONVDigitStore* fDigitStore; //!< current digit store (owner)
-//AliMUONVTriggerStore* fTriggerStore; //!< current trigger store (owner)
-//AliMUONVClusterStore* fClusterStore; //!< current cluster store (owner)
-//AliMUONVTrackStore* fTrackStore; //!< current track store (owner)
-//AliMUONVTriggerTrackStore* fTriggerTrackStore; //!< current trigger track store (owner)
-//Int_t fCurrentEvent; //!< Current event we've read in
-//Bool_t fIsValid; //!< whether we were initialized properly or not
Int_t AliMUONDataInterface::fgInstanceCounter(0);
fTrackStore(0x0),
fTriggerTrackStore(0x0),
fCurrentEvent(-1),
-fIsValid(kFALSE)
+fIsValid(kFALSE),
+fCurrentIteratorType(kNoIterator),
+fCurrentIndex(-1),
+fDataX(-1),
+fDataY(-1),
+fIterator(0x0)
{
/// ctor
/// @param filename should be the full path to a valid galice.root file
AliMUONDataInterface::~AliMUONDataInterface()
{
/// dtor
- if ( fLoader )
+ ResetStores();
+ if ( fLoader != 0x0 )
{
delete fLoader->GetRunLoader();
}
--fgInstanceCounter;
}
+//______________________________________________________________________________
+AliMUONVDigitStore*
+AliMUONDataInterface::DigitStore(Int_t event)
+{
+ /// Return digitStore for a given event.
+ /// Return 0x0 if event not found.
+ /// Returned pointer should not be deleted
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ fLoader->LoadDigits();
+
+ TTree* treeD = fLoader->TreeD();
+ if (treeD == 0x0)
+ {
+ AliError("Could not get treeD");
+ return 0x0;
+ }
+
+ fDigitStore = AliMUONVDigitStore::Create(*treeD);
+ if ( fDigitStore != 0x0 )
+ {
+ fDigitStore->Clear();
+ fDigitStore->Connect(*treeD);
+ treeD->GetEvent(0);
+ }
+
+ fLoader->UnloadDigits();
+
+ return fDigitStore;
+}
+
//______________________________________________________________________________
AliMUONVClusterStore*
AliMUONDataInterface::ClusterStore(Int_t event)
/// Return 0x0 if event not found.
/// Returned pointer should not be deleted
- if ( LoadEvent(event) ) return 0x0;
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fClusterStore != 0x0) return fClusterStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
fLoader->LoadRecPoints();
TTree* treeR = fLoader->TreeR();
-
- if (!treeR)
+ if (treeR == 0x0)
{
AliError("Could not get treeR");
return 0x0;
}
- if (!fClusterStore)
- {
- fClusterStore = AliMUONVClusterStore::Create(*treeR);
- }
-
- if ( fClusterStore )
+ fClusterStore = AliMUONVClusterStore::Create(*treeR);
+ if ( fClusterStore != 0x0 )
{
fClusterStore->Clear();
fClusterStore->Connect(*treeR);
}
//______________________________________________________________________________
-AliMUONVDigitStore*
-AliMUONDataInterface::DigitStore(Int_t event)
+AliMUONVTrackStore*
+AliMUONDataInterface::TrackStore(Int_t event)
{
- /// Return digitStore for a given event.
+ /// Return the trackStore for a given event.
/// Return 0x0 if event not found.
/// Returned pointer should not be deleted
- if ( LoadEvent(event) ) return 0x0;
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fTrackStore != 0x0) return fTrackStore;
- fLoader->LoadDigits();
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
- TTree* treeD = fLoader->TreeD();
+ fLoader->LoadTracks();
- if (!treeD)
+ TTree* treeT = fLoader->TreeT();
+ if (treeT == 0x0)
{
- AliError("Could not get treeD");
+ AliError("Could not get treeT");
return 0x0;
}
- if (!fDigitStore)
+ fTrackStore = AliMUONVTrackStore::Create(*treeT);
+ if ( fTrackStore != 0x0 )
{
- fDigitStore = AliMUONVDigitStore::Create(*treeD);
+ fTrackStore->Clear();
+ fTrackStore->Connect(*treeT);
+ treeT->GetEvent(0);
}
- if ( fDigitStore )
+ fLoader->UnloadTracks();
+
+ return fTrackStore;
+}
+
+//______________________________________________________________________________
+AliMUONVTriggerTrackStore*
+AliMUONDataInterface::TriggerTrackStore(Int_t event)
+{
+ /// Return the triggerTrackStore for a given event.
+ /// Return 0x0 if event not found.
+ /// Returned pointer should not be deleted
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fTriggerTrackStore != 0x0) return fTriggerTrackStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ fLoader->LoadTracks();
+
+ TTree* treeT = fLoader->TreeT();
+ if (treeT == 0x0)
{
- fDigitStore->Clear();
- fDigitStore->Connect(*treeD);
- treeD->GetEvent(0);
+ AliError("Could not get treeT");
+ return 0x0;
}
- fLoader->UnloadDigits();
+ fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
+ if ( fTriggerTrackStore != 0x0 )
+ {
+ fTriggerTrackStore->Clear();
+ fTriggerTrackStore->Connect(*treeT);
+ treeT->GetEvent(0);
+ }
- return fDigitStore;
+ fLoader->UnloadTracks();
+
+ return fTriggerTrackStore;
+}
+
+//_____________________________________________________________________________
+AliMUONVTriggerStore*
+AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
+{
+ /// Return the triggerStore for a given event.
+ /// Return 0x0 if event not found.
+ /// Returned pointer should not be deleted
+ /// treeLetter can be R or D to tell from which tree to read the information
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ TTree* tree(0x0);
+
+ TString stree(treeLetter);
+ stree.ToUpper();
+
+ if ( stree == "D" )
+ {
+ fLoader->LoadDigits();
+ tree = fLoader->TreeD();
+ }
+ else if ( stree == "R" )
+ {
+ fLoader->LoadRecPoints();
+ tree = fLoader->TreeR();
+ }
+
+ if ( tree == 0x0 )
+ {
+ AliError(Form("Could not get tree%s",treeLetter));
+ return 0x0;
+ }
+
+ fTriggerStore = AliMUONVTriggerStore::Create(*tree);
+ if ( fTriggerStore != 0x0 )
+ {
+ fTriggerStore->Clear();
+ fTriggerStore->Connect(*tree);
+ tree->GetEvent(0);
+ }
+
+ if ( stree == "D" )
+ {
+ fLoader->UnloadDigits();
+ }
+ else if ( stree == "R" )
+ {
+ fLoader->UnloadRecPoints();
+ }
+
+ return fTriggerStore;
}
//______________________________________________________________________________
{
/// Dump the digits for a given event, sorted if so required
DigitStore(event);
- if ( fDigitStore )
+ if ( fDigitStore != 0x0 )
{
if ( sorted )
{
{
/// Dump the recpoints for a given event, sorted if so required
ClusterStore(event);
- if ( fClusterStore )
+ if ( fClusterStore != 0x0 )
{
if ( sorted )
{
TrackStore(event);
- if ( fTrackStore )
+ if ( fTrackStore != 0x0 )
{
if ( sorted )
{
TriggerTrackStore(event);
- if ( fTriggerTrackStore )
+ if ( fTriggerTrackStore != 0x0 )
{
if ( sorted )
{
{
TriggerStore(event,treeLetter);
- if ( fTriggerStore )
+ if ( fTriggerStore != 0x0 )
{
fTriggerStore->Print();
}
myFile.Close();
}
-//______________________________________________________________________________
-Bool_t
-AliMUONDataInterface::IsValid() const
-{
- /// Whether we were properly initialized from a valid galice.root file
- return fIsValid;
-}
-
//_____________________________________________________________________________
-Int_t
+Bool_t
AliMUONDataInterface::LoadEvent(Int_t event)
{
/// Load event if different from the current one.
- if ( event != fCurrentEvent )
+ /// Returns kFALSE on error and kTRUE if the event was loaded.
+
+ assert( IsValid() );
+
+ AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
+ if (fLoader->GetRunLoader()->GetEvent(event) == 0)
{
fCurrentEvent = event;
- AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
- if ( event < NumberOfEvents() )
- {
- return fLoader->GetRunLoader()->GetEvent(event);
- }
- else
- {
- return 1;
- }
+ return kTRUE;
}
- return 0;
+ else
+ return kFALSE;
}
//______________________________________________________________________________
AliMUONDataInterface::NumberOfEvents() const
{
/// Number of events in the current galice.root file we're attached to
- if (!IsValid()) return 0;
+ if (not IsValid()) return -1;
return fLoader->GetRunLoader()->GetNumberOfEvents();
}
{
/// Connect to a given galice.root file
- delete fDigitStore;
- fDigitStore=0x0;
- delete fTriggerStore;
- fTriggerStore=0x0;
- delete fClusterStore;
- fClusterStore=0x0;
- delete fTrackStore;
- fTrackStore=0x0;
- delete fTriggerTrackStore;
- fTriggerTrackStore=0x0;
+ ResetStores();
fCurrentEvent=-1;
- if ( fLoader )
+ if ( fLoader != 0x0 )
{
delete fLoader->GetRunLoader();
}
TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
- while (AliRunLoader::GetRunLoader(foldername))
+ while (AliRunLoader::GetRunLoader(foldername) != 0x0)
{
delete AliRunLoader::GetRunLoader(foldername);
}
AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
- if (!runLoader)
+ if (runLoader == 0x0)
{
AliError(Form("Cannot open file %s",filename));
fIsValid = kFALSE;
}
fLoader = runLoader->GetDetectorLoader("MUON");
- if (!fLoader)
+ if (fLoader == 0x0)
{
AliError("Cannot get AliMUONLoader");
fIsValid = kFALSE;
}
- if (!IsValid())
+ if (not IsValid())
{
AliError(Form("Could not access %s filename. Object is unuseable",filename));
}
}
-//______________________________________________________________________________
-AliMUONVTrackStore*
-AliMUONDataInterface::TrackStore(Int_t event)
-{
- /// Return the trackStore for a given event.
- /// Return 0x0 if event not found.
- /// Returned pointer should not be deleted
-
- if ( LoadEvent(event) ) return 0x0;
-
- fLoader->LoadTracks();
-
- TTree* treeT = fLoader->TreeT();
-
- if (!treeT)
- {
- AliError("Could not get treeT");
- return 0x0;
- }
-
- if (!fTrackStore)
- {
- fTrackStore = AliMUONVTrackStore::Create(*treeT);
- }
-
- if ( fTrackStore )
- {
- fTrackStore->Clear();
- fTrackStore->Connect(*treeT);
- treeT->GetEvent(0);
- }
-
- fLoader->UnloadTracks();
-
- return fTrackStore;
-}
-
-//______________________________________________________________________________
-AliMUONVTriggerTrackStore*
-AliMUONDataInterface::TriggerTrackStore(Int_t event)
-{
- /// Return the triggerTrackStore for a given event.
- /// Return 0x0 if event not found.
- /// Returned pointer should not be deleted
-
- if ( LoadEvent(event) ) return 0x0;
-
- fLoader->LoadTracks();
-
- TTree* treeT = fLoader->TreeT();
-
- if (!treeT)
- {
- AliError("Could not get treeT");
- return 0x0;
- }
-
- if (!fTriggerTrackStore)
- {
- fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
- }
-
- if ( fTriggerTrackStore )
- {
- fTriggerTrackStore->Clear();
- fTriggerTrackStore->Connect(*treeT);
- treeT->GetEvent(0);
- }
-
- fLoader->UnloadTracks();
-
- return fTriggerTrackStore;
-}
-
//_____________________________________________________________________________
-AliMUONVTriggerStore*
-AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
-{
- /// Return the triggerStore for a given event.
- /// Return 0x0 if event not found.
- /// Returned pointer should not be deleted
- /// treeLetter can be R or D to tell from which tree to read the information
-
- if ( LoadEvent(event) ) return 0x0;
-
- TTree* tree(0x0);
-
- TString stree(treeLetter);
- stree.ToUpper();
-
- if ( stree == "D" )
- {
- fLoader->LoadDigits();
- tree = fLoader->TreeD();
- }
- else if ( stree == "R" )
- {
- fLoader->LoadRecPoints();
- tree = fLoader->TreeR();
- }
-
- if ( !tree )
- {
- AliError(Form("Could not get tree%s",treeLetter));
- return 0x0;
- }
-
- if (!fTriggerStore)
- {
- fTriggerStore = AliMUONVTriggerStore::Create(*tree);
- }
-
- if ( fTriggerStore )
- {
- fTriggerStore->Clear();
- fTriggerStore->Connect(*tree);
- tree->GetEvent(0);
- }
-
- if ( stree == "D" )
- {
- fLoader->UnloadDigits();
- }
- else if ( stree == "R" )
- {
- fLoader->UnloadRecPoints();
- }
-
- return fTriggerStore;
-}
-
-//______________________________________________________________________________
-//______________________________________________________________________________
-//______________________________________________________________________________
-//______________________________________________________________________________
-
-void AliMUONDataInterface::Reset()
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
-}
-
-Bool_t AliMUONDataInterface::UseCurrentRunLoader()
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return kFALSE;
-}
-
-Int_t AliMUONDataInterface::NumberOfEvents(TString , TString )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfParticles(TString , TString , Int_t )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-TParticle* AliMUONDataInterface::Particle(
- TString , TString , Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfTracks(TString , TString , Int_t )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfHits(
- TString , TString , Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-AliMUONHit* AliMUONDataInterface::Hit(
- TString , TString , Int_t ,
- Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfSDigits(
- TString , TString , Int_t ,
- Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-AliMUONDigit* AliMUONDataInterface::SDigit(
- TString , TString , Int_t ,
- Int_t , Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfDigits(
- TString , TString , Int_t ,
- Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-AliMUONDigit* AliMUONDataInterface::Digit(
- TString , TString , Int_t ,
- Int_t , Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfRawClusters(
- TString , TString , Int_t , Int_t
- )
-{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-AliMUONRawCluster* AliMUONDataInterface::RawCluster(
- TString , TString , Int_t ,
- Int_t , Int_t
- )
+Bool_t AliMUONDataInterface::GetEvent(Int_t event)
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Loads all reconstructed data for the given event.
+
+ if (DigitStore(event) == 0x0) return kFALSE;
+ if (ClusterStore(event) == 0x0) return kFALSE;
+ if (TrackStore(event) == 0x0) return kFALSE;
+ if (TriggerStore(event) == 0x0) return kFALSE;
+ if (TriggerTrackStore(event) == 0x0) return kFALSE;
+ return kTRUE;
}
-
-Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString , TString , Int_t )
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfDigits(Int_t detElemId)
{
-/// \deprecated Method is going to be removed
+/// Returns the number of digits to be found on a given detector element.
+/// @param detElemId The detector element ID number to search on.
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
+ return CountObjects(iter);
}
-
-AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
- TString , TString , Int_t , Int_t
- )
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONDataInterface::Digit(Int_t detElemId, Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Returns the a pointer to the index'th digit on the specified detector element.
+/// @param detElemId The detector element ID number to search on.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(detElemId)
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
}
-Bool_t AliMUONDataInterface::SetFile(TString , TString )
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
{
-/// \deprecated Method is going to be removed
+/// Returns the number of digits to be found on a specific chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
+ return CountObjects(iter);
}
-
-Bool_t AliMUONDataInterface::GetEvent(Int_t )
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Returns the a pointer to the index'th digit on the specified chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(chamber, cathode)
+
+ TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
}
-Int_t AliMUONDataInterface::NumberOfParticles()
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
{
-/// \deprecated Method is going to be removed
+/// Returns the number of reconstructed raw clusters on the specified chamber.
+/// @param chamber The chamber number in the range [0 .. 13].
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kRawClusterIterator, chamber);
+ return CountObjects(iter);
}
-
-TParticle* AliMUONDataInterface::Particle(Int_t )
+//_____________________________________________________________________________
+AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Returns a pointer to the index'th raw cluster on the specified chamber.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param index The index number of the raw cluster to fetch in the range [0 .. N-1],
+/// where N = NumberOfRawClusters(chamber)
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kRawClusterIterator, chamber);
+ return static_cast<AliMUONRawCluster*>( FetchObject(iter, index) );
}
-
+//_____________________________________________________________________________
Int_t AliMUONDataInterface::NumberOfTracks()
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfHits(Int_t )
-{
-/// \deprecated Method is going to be removed
+/// Returns the number of reconstructed tracks.
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kTrackIterator);
+ return CountObjects(iter);
}
-
-AliMUONHit*
-AliMUONDataInterface::Hit(Int_t , Int_t )
+//_____________________________________________________________________________
+AliMUONTrack* AliMUONDataInterface::Track(Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Returns a pointer to the index'th reconstructed track.
+/// @param index The index number of the track to fetch in the range [0 .. N-1],
+/// where N = NumberOfTracks()
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kTrackIterator);
+ return static_cast<AliMUONTrack*>( FetchObject(iter, index) );
}
-
-Int_t AliMUONDataInterface::NumberOfSDigits(Int_t , Int_t )
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfLocalTriggers()
{
-/// \deprecated Method is going to be removed
+/// Returns the number of reconstructed local trigger objects.
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kLocalTriggerIterator);
+ return CountObjects(iter);
}
-
-AliMUONDigit* AliMUONDataInterface::SDigit(Int_t , Int_t , Int_t )
+//_____________________________________________________________________________
+AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t index)
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Returns a pointer to the index'th local trigger object.
+/// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
+/// where N = NumberOfLocalTriggers()
+ TIterator* iter = GetIterator(kLocalTriggerIterator);
+ return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
}
-
-Int_t AliMUONDataInterface::NumberOfDigits(Int_t , Int_t )
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfRegionalTriggers()
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Returns the number of regional trigger objects reconstructed.
+ TIterator* iter = GetIterator(kRegionalTriggerIterator);
+ return CountObjects(iter);
}
-
-AliMUONDigit* AliMUONDataInterface::Digit(Int_t , Int_t , Int_t )
+//_____________________________________________________________________________
+AliMUONRegionalTrigger* AliMUONDataInterface::RegionalTrigger(Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Returns a pointer to the index'th regional trigger object.
+/// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
+/// where N = NumberOfRegionalTriggers()
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kRegionalTriggerIterator);
+ return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
}
-
-Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t )
+//_____________________________________________________________________________
+AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger()
{
-/// \deprecated Method is going to be removed
+/// Returns a pointer to the reconstructed global trigger object for the event.
- AliFatal("Deprecated");
- return 0;
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ return store->Global();
}
-
-AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t , Int_t )
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::NumberOfTriggerTracks()
{
-/// \deprecated Method is going to be removed
+/// Returns the number of reconstructed tracks in the trigger chambers.
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kTriggerTrackIterator);
+ return CountObjects(iter);
}
-
-Int_t AliMUONDataInterface::NumberOfLocalTriggers()
+//_____________________________________________________________________________
+AliMUONTriggerTrack* AliMUONDataInterface::TriggerTrack(Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Returns a pointer to the index'th reconstructed trigger track object.
+/// @param index The index number of the trigger track to fetch in the range [0 .. N-1],
+/// where N = NumberOfTriggerTracks()
- AliFatal("Deprecated");
- return 0;
+ TIterator* iter = GetIterator(kTriggerTrackIterator);
+ return static_cast<AliMUONTriggerTrack*>( FetchObject(iter, index) );
}
-
-AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t )
+//_____________________________________________________________________________
+void AliMUONDataInterface::ResetStores()
{
-/// \deprecated Method is going to be removed
+/// Deletes all the store objects that have been created and resets the pointers to 0x0.
+/// The temporary iterator object is automatically reset. See ResetIterator for more details.
- AliFatal("Deprecated");
- return 0;
+ ResetIterator();
+ if (fDigitStore != 0x0)
+ {
+ delete fDigitStore;
+ fDigitStore = 0x0;
+ }
+ if (fTriggerStore != 0x0)
+ {
+ delete fTriggerStore;
+ fTriggerStore = 0x0;
+ }
+ if (fClusterStore != 0x0)
+ {
+ delete fClusterStore;
+ fClusterStore = 0x0;
+ }
+ if (fTrackStore != 0x0)
+ {
+ delete fTrackStore;
+ fTrackStore = 0x0;
+ }
+ if (fTriggerTrackStore != 0x0)
+ {
+ delete fTriggerTrackStore;
+ fTriggerTrackStore = 0x0;
+ }
}
-Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
+//_____________________________________________________________________________
+TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Creates an appropriate iterator object and returns it.
+/// If the iterator has already been created then that one is returned otherwise
+/// a new object is created.
+/// Depending on the value of 'type' the semantics of parameters x and y can change.
+/// @param type The type of iterator to create.
+/// @param x This is the detector element ID if type == kDigitIteratorByDetectorElement
+/// If type equals kDigitIteratorByChamberAndCathode or kRawClusterIterator
+/// then this is the chamber number. In all other cases this parameter is
+/// ignored.
+/// @param y If type == kDigitIteratorByChamberAndCathode then this parameter is the
+/// cathode number. In all other cases this parameter is
+/// ignored.
+
+ if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
+ return fIterator;
+
+ if (fCurrentEvent == -1)
+ {
+ AliError("No event was selected. Try first using GetEvent().");
+ return 0x0;
+ }
+
+ ResetIterator();
+
+ switch (type)
+ {
+ case kDigitIteratorByDetectorElement:
+ {
+ Int_t detElem = x;
+ AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ fIterator = store->CreateIterator(detElem, detElem, 2);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kDigitIteratorByDetectorElement;
+ fDataX = detElem;
+ return fIterator;
+ }
+
+ case kDigitIteratorByChamberAndCathode:
+ {
+ Int_t chamber = x;
+ Int_t cathode = y;
+ if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
+ {
+ AliError(Form(
+ "Must have give a chamber value in the range [0..%d], but got a value of: %d",
+ AliMpConstants::NofChambers() - 1,
+ chamber
+ ));
+ return 0x0;
+ }
+ if (cathode < 0 or 1 < cathode)
+ {
+ AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
+ return 0x0;
+ }
+
+ AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
+ fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
+ fDataX = chamber;
+ fDataY = cathode;
+ return fIterator;
+ }
+
+ case kRawClusterIterator:
+ {
+ Int_t chamber = x;
+ AliMUONVClusterStore* store = ClusterStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateChamberIterator(chamber, chamber);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kRawClusterIterator;
+ fDataX = chamber;
+ return fIterator;
+ }
+
+ case kTrackIterator:
+ {
+ AliMUONVTrackStore* store = TrackStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kTrackIterator;
+ return fIterator;
+ }
+
+ case kLocalTriggerIterator:
+ {
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateLocalIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kLocalTriggerIterator;
+ return fIterator;
+ }
+
+ case kRegionalTriggerIterator:
+ {
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateRegionalIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kRegionalTriggerIterator;
+ return fIterator;
+ }
+
+ case kTriggerTrackIterator:
+ {
+ AliMUONVTriggerTrackStore* store = TriggerTrackStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kTriggerTrackIterator;
+ return fIterator;
+ }
+
+ default:
+ return 0x0;
+ }
}
-AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t )
+//_____________________________________________________________________________
+void AliMUONDataInterface::ResetIterator()
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
+/// The iterator type and temporary data indicating the state of the iterator are
+/// also reset.
+
+ if (fIterator != 0x0) delete fIterator;
+ fCurrentIteratorType = kNoIterator;
+ fCurrentIndex = fDataX = fDataY = -1;
+ fIterator = 0x0;
}
-Int_t AliMUONDataInterface::NumberOfRecTracks()
+//_____________________________________________________________________________
+Int_t AliMUONDataInterface::CountObjects(TIterator* iter)
{
-/// \deprecated Method is going to be removed
-
- AliFatal("Deprecated");
- return 0;
+/// Counts the number of objects in the iterator and resets it.
+/// @return The number of objects in 'iter'.
+
+ if (iter == 0x0) return -1;
+ Int_t count = 0;
+ iter->Reset();
+ while ( iter->Next() != 0x0 ) count++;
+ iter->Reset();
+ fCurrentIndex = -1;
+ return count;
}
-AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t )
+//_____________________________________________________________________________
+TObject* AliMUONDataInterface::FetchObject(TIterator* iter, Int_t index)
{
-/// \deprecated Method is going to be removed
+/// Fetches the index'th object from the iterator counting the first object
+/// returned by iterator after it is reset as index == 0. The next object
+/// has index == 1 and so on where the last object returned by the iterator
+/// has index == N-1 where N = CountObjects(iter)
+/// This method will only reset the iterator if index is smaller than
+/// fCurrentIndex, which is used to track the iteration progress and is
+/// updated when a new object if returned by this method.
+/// @param iter The iterator to fetch an object from.
+/// @param index The index number of the object to fetch in the range [0 .. N-1]
+/// where N = CountObjects(iter)
+
+ if (index < 0)
+ {
+ AliError(Form("Index is out of bounds. Got a value of %d.", index));
+ return 0x0;
+ }
- AliFatal("Deprecated");
- return 0;
+ if (iter == 0x0) return 0x0;
+ if (index <= fCurrentIndex)
+ {
+ iter->Reset();
+ fCurrentIndex = -1;
+ }
+
+ TObject* object = 0x0;
+ while (fCurrentIndex < index)
+ {
+ object = iter->Next();
+ if (object == 0x0)
+ {
+ AliError(Form("Index is out of bounds. Got a value of %d.", index));
+ iter->Reset();
+ fCurrentIndex = -1;
+ return 0x0;
+ }
+ fCurrentIndex++;
+ }
+ return object;
}
-#ifndef ALI_MUON_DATA_INTERFACE_H
-#define ALI_MUON_DATA_INTERFACE_H
+#ifndef ALIMUONDATAINTERFACE_H
+#define ALIMUONDATAINTERFACE_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* See cxx source for full Copyright notice */
/// \class AliMUONDataInterface
/// \brief An easy to use interface to MUON data
-// Author: Artur Szostak
-// email: artur@alice.phy.uct.ac.za
+// Author: Artur Szostak (University of Cape Town)
+// email: artursz@iafrica.com
//
// Updated to MUON module w/o MUONData by Laurent Aphecetche, Subatech
//
#include <TObject.h>
-#include <TString.h>
+class TIterator;
class AliLoader;
-class AliMUONVClusterStore;
-class AliMUONVDigitStore;
class AliMUONVStore;
+class AliMUONVDigitStore;
+class AliMUONVClusterStore;
class AliMUONVTrackStore;
class AliMUONVTriggerStore;
class AliMUONVTriggerTrackStore;
-
-// >>LA should not needed (once we remove deprecated methods)
-class AliMUONHit;
-class AliMUONDigit;
-class AliMUONLocalTrigger;
-class AliMUONGlobalTrigger;
+class AliMUONVDigit;
class AliMUONRawCluster;
class AliMUONTrack;
-class TParticle;
-// <<LA
+class AliMUONLocalTrigger;
+class AliMUONRegionalTrigger;
+class AliMUONGlobalTrigger;
+class AliMUONTriggerTrack;
+
class AliMUONDataInterface : public TObject
{
- public:
+public:
AliMUONDataInterface(const char* filename="galice.root");
virtual ~AliMUONDataInterface();
- Bool_t IsValid() const;
+ /// Returns true if the data interface was able to open the root file correctly.
+ Bool_t IsValid() const { return fIsValid; };
void Open(const char* filename);
Int_t NumberOfEvents() const;
+
+ /// Returns the index number of the current event as used int GetEvent(Int_t).
+ Int_t CurrentEvent() const { return fCurrentEvent; }
AliMUONVDigitStore* DigitStore(Int_t event);
AliMUONVClusterStore* ClusterStore(Int_t event);
void DumpTrigger(Int_t event, const char* treeLetter="R");
void DumpTriggerTracks(Int_t event, Bool_t sorted=kFALSE);
- // all the methods below are deprecated.
-
- // Sets all internal pointers to NULL without releasing the current runloader.
- void Reset();
-
- Bool_t UseCurrentRunLoader();
-
- 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 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);
-
+ // Note the following methods can be extremely slow. Remember they are only
+ // here for end user convenience for his/her small tests and macros.
+ // If you want speed then don't use these methods. If you really want peak
+ // performance then you should be talking to the AliRunLoader and Store
+ // objects directly.
+ Int_t NumberOfDigits(Int_t detElemId);
+ AliMUONVDigit* Digit(Int_t detElemId, Int_t index);
Int_t NumberOfDigits(Int_t chamber, Int_t cathode);
- AliMUONDigit* Digit(Int_t chamber, Int_t cathode, Int_t digit);
-
+ AliMUONVDigit* Digit(Int_t chamber, Int_t cathode, Int_t index);
Int_t NumberOfRawClusters(Int_t chamber);
- AliMUONRawCluster* RawCluster(Int_t chamber, Int_t cluster);
-
+ AliMUONRawCluster* RawCluster(Int_t chamber, Int_t index);
+ Int_t NumberOfTracks();
+ AliMUONTrack* Track(Int_t index);
Int_t NumberOfLocalTriggers();
- AliMUONLocalTrigger* LocalTrigger(Int_t trigger);
-
- Int_t NumberOfGlobalTriggers();
- AliMUONGlobalTrigger* GlobalTrigger(Int_t trigger);
- // Returns the name of the currently selected file.
-
- Int_t NumberOfRecTracks();
- AliMUONTrack* RecTrack(Int_t rectrack);
-
- /// Returns the file name from which we are fetching data
- TString CurrentFile() const { return ""; }
-
- /// Returns the name of the currently selected folder.
- TString CurrentFolder() const { return ""; }
-
- /// Returns the number of the currently selected event.
- Int_t CurrentEvent() const { return 0; }
-
- /// Returns the currently selected track.
- Int_t CurrentTrack() const { return 0; }
+ AliMUONLocalTrigger* LocalTrigger(Int_t index);
+ Int_t NumberOfRegionalTriggers();
+ AliMUONRegionalTrigger* RegionalTrigger(Int_t index);
+ AliMUONGlobalTrigger* GlobalTrigger();
+ Int_t NumberOfTriggerTracks();
+ AliMUONTriggerTrack* TriggerTrack(Int_t index);
- /// Returns the currently selected cathode in TreeS.
- Int_t CurrentSCathode() const { return 0; }
-
- /// Returns the currently selected cathode in TreeD.
- Int_t CurrentDCathode() const { return 0; }
-
- private:
+private:
+
+ enum IteratorType
+ {
+ kNoIterator,
+ kDigitIteratorByDetectorElement,
+ kDigitIteratorByChamberAndCathode,
+ kRawClusterIterator,
+ kTrackIterator,
+ kLocalTriggerIterator,
+ kRegionalTriggerIterator,
+ kTriggerTrackIterator
+ };
void DumpSorted(const AliMUONVStore& store) const;
- Int_t LoadEvent(Int_t event);
+ Bool_t LoadEvent(Int_t event);
void NtupleTrigger(const char* treeLetter);
+ void ResetStores();
+
+ TIterator* GetIterator(IteratorType type, Int_t x = 0, Int_t y = 0);
+ void ResetIterator();
+
+ Int_t CountObjects(TIterator* iter);
+ TObject* FetchObject(TIterator* iter, Int_t index);
+
/// Not implemented
AliMUONDataInterface(const AliMUONDataInterface& rhs);
/// Not implemented
AliMUONDataInterface& operator=(const AliMUONDataInterface& rhs);
-
-private:
+
AliLoader* fLoader; //!< Tree accessor
AliMUONVDigitStore* fDigitStore; //!< current digit store (owner)
Int_t fCurrentEvent; //!< Current event we've read in
Bool_t fIsValid; //!< whether we were initialized properly or not
+ IteratorType fCurrentIteratorType; //!< The type of iterator that is currently set.
+ Int_t fCurrentIndex; //!< A current index number maintained for certain iteration operations.
+ Int_t fDataX; //!< Extra data parameter about the iterator, can be the chamber number or detector element.
+ Int_t fDataY; //!< Extra data parameter about the iterator, can be the cathode number.
+ TIterator* fIterator; //!< Iterator for various iteration operations.
+
static Int_t fgInstanceCounter; //!< To build unique folder name for each instance
- ClassDef(AliMUONDataInterface, 0) // An easy to use interface to MUON data
+ ClassDef(AliMUONDataInterface, 0) // An easy to use interface to MUON reconstructed data
};
-#endif // ALI_MUON_DATA_INTERFACE_H
+#endif // ALIMUONDATAINTERFACE_H
/// Easy to use MC data accessor
///
/// \author Laurent Aphecetche, Subatech
+///
+// Moved parts of old AliMUONDataInterface interface to AliMUONMCDataInterface
+// Artur Szostak <artursz@iafrica.com> (University of Cape Town)
//-----------------------------------------------------------------------------
#include "AliMUONMCDataInterface.h"
#include "AliMUONVDigitStore.h"
#include "AliMUONVHitStore.h"
-#include "AliMUONVStore.h"
#include "AliMUONVTriggerStore.h"
+#include "AliMUONHit.h"
+#include "AliMUONVDigit.h"
+#include "AliMUONLocalTrigger.h"
+#include "AliMUONRegionalTrigger.h"
+#include "AliMUONGlobalTrigger.h"
+
+#include "AliMpIntPair.h"
+#include "AliMpDEManager.h"
+#include "AliMpConstants.h"
+#include "AliMpSegmentation.h"
#include "AliLog.h"
#include "AliRunLoader.h"
#include <TClonesArray.h>
#include <TList.h>
#include <TParticle.h>
+#include <TIterator.h>
+#include <cstdlib>
+#include <cassert>
/// \cond CLASSIMP
ClassImp(AliMUONMCDataInterface)
fTriggerStore(0x0),
fTrackRefs(0x0),
fCurrentEvent(-1),
-fIsValid(kFALSE)
+fIsValid(kFALSE),
+fCurrentIteratorType(kNoIterator),
+fCurrentIndex(-1),
+fDataX(-1),
+fDataY(-1),
+fIterator(0x0)
{
/// ctor
--fgInstanceCounter;
}
+//_____________________________________________________________________________
+AliMUONVHitStore*
+AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
+{
+ /// Return the hitStore for a given track of one event
+ /// Return 0x0 if event and/or track not found
+ /// Returned pointer should not be deleted
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent
+ and fDataX == track // using fDataX as track number.
+ and fHitStore != 0x0
+ )
+ return fHitStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ fLoader->LoadHits();
+
+ TTree* treeH = fLoader->TreeH();
+ if (treeH == 0x0)
+ {
+ AliError("Could not get treeH");
+ return 0x0;
+ }
+
+ fHitStore = AliMUONVHitStore::Create(*treeH);
+ AliDebug(1,"Creating hitStore from treeH");
+ if ( fHitStore != 0x0 )
+ {
+ fHitStore->Connect(*treeH);
+ if ( treeH->GetEvent(track) == 0 )
+ {
+ AliError(Form("Could not read track %d",track));
+ fHitStore->Clear();
+ return 0x0;
+ }
+ fDataX = track; // using fDataX as track number.
+ }
+
+ fLoader->UnloadHits();
+
+ return fHitStore;
+}
+
+//_____________________________________________________________________________
+AliMUONVDigitStore*
+AliMUONMCDataInterface::SDigitStore(Int_t event)
+{
+ /// Return the SDigit store for a given event.
+ /// Return 0 if event not found
+ /// Returned pointer should not be deleted
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fSDigitStore != 0x0) return fSDigitStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ fLoader->LoadSDigits();
+
+ TTree* treeS = fLoader->TreeS();
+ if (treeS == 0x0)
+ {
+ AliError("Could not get treeS");
+ return 0x0;
+ }
+
+ fSDigitStore = AliMUONVDigitStore::Create(*treeS);
+ if ( fSDigitStore != 0x0 )
+ {
+ fSDigitStore->Clear();
+ fSDigitStore->Connect(*treeS);
+ treeS->GetEvent(0);
+ }
+
+ fLoader->UnloadSDigits();
+
+ return fSDigitStore;
+}
+
//_____________________________________________________________________________
AliMUONVDigitStore*
AliMUONMCDataInterface::DigitStore(Int_t event)
/// Return a pointer to the digitStore for a given event (or 0 if not found)
/// Returned pointer should not be deleted
- if ( LoadEvent(event) ) return 0x0;
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
fLoader->LoadDigits();
TTree* treeD = fLoader->TreeD();
-
- if (!treeD)
+ if (treeD == 0x0)
{
AliError("Could not get treeD");
return 0x0;
}
- if (!fDigitStore)
- {
- fDigitStore = AliMUONVDigitStore::Create(*treeD);
- }
-
- if ( fDigitStore )
+ fDigitStore = AliMUONVDigitStore::Create(*treeD);
+ if ( fDigitStore != 0x0 )
{
fDigitStore->Clear();
fDigitStore->Connect(*treeD);
return fDigitStore;
}
+//_____________________________________________________________________________
+AliStack*
+AliMUONMCDataInterface::Stack(Int_t event)
+{
+ /// Get the Stack (list of generated particles) for one event
+ /// Returned pointer should not be deleted
+
+ if ( not IsValid() ) return 0x0;
+
+ if (event != fCurrentEvent)
+ {
+ ResetStores();
+ if ( not LoadEvent(event) ) return 0x0;
+ }
+
+ fLoader->GetRunLoader()->LoadKinematics();
+
+ return fLoader->GetRunLoader()->Stack();
+}
+
+//_____________________________________________________________________________
+TClonesArray*
+AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
+{
+ /// Get the track references for a given (generated) track of one event
+ /// Returned pointer should not be deleted
+
+ if ( not IsValid() ) return 0x0;
+
+ if (event != fCurrentEvent)
+ {
+ ResetStores();
+ if ( not LoadEvent(event) ) return 0x0;
+ }
+
+ if (track == fDataX) // using fDataX as track number.
+ return fTrackRefs;
+
+ fLoader->GetRunLoader()->LoadTrackRefs();
+
+ TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
+
+ if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
+
+ if (treeTR != 0x0)
+ {
+ if ( treeTR->GetEvent(track) > 0 )
+ {
+ TBranch* branch = treeTR->GetBranch("MUON");
+ branch->SetAddress(&fTrackRefs);
+ branch->GetEvent(track);
+ fDataX = track; // using fDataX as track number.
+ }
+ }
+ else
+ {
+ AliError("Could not get TreeTR");
+ }
+
+ fLoader->GetRunLoader()->UnloadTrackRefs();
+
+ return fTrackRefs;
+}
+
+//_____________________________________________________________________________
+AliMUONVTriggerStore*
+AliMUONMCDataInterface::TriggerStore(Int_t event)
+{
+ /// Return the triggerStore for a given event.
+ /// Return 0x0 if event not found.
+ /// Returned pointer should not be deleted.
+
+ if (not IsValid()) return 0x0;
+ if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
+
+ ResetStores();
+ if (not LoadEvent(event)) return 0x0;
+
+ fLoader->LoadDigits();
+
+ TTree* treeD = fLoader->TreeD();
+ if ( treeD == 0x0 )
+ {
+ AliError("Could not get treeD");
+ return 0x0;
+ }
+
+ fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
+ if ( fTriggerStore != 0x0 )
+ {
+ fTriggerStore->Clear();
+ fTriggerStore->Connect(*treeD);
+ treeD->GetEvent(0);
+ }
+
+ fLoader->UnloadDigits();
+
+ return fTriggerStore;
+}
+
//_____________________________________________________________________________
void
AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
/// Dump the digits for a given event, sorted if requested.
DigitStore(event);
- if ( fDigitStore )
+ if ( fDigitStore != 0x0 )
{
if ( sorted )
{
/// Dump all generated particles for one event
AliStack* stack = Stack(event);
- if ( stack )
+ if ( stack != 0x0 )
{
Int_t nparticles = (Int_t) stack->GetNtrack();
/// Dump the SDigits for a given event, sorted if requested
SDigitStore(event);
- if ( fSDigitStore )
+ if ( fSDigitStore != 0x0 )
{
if ( sorted )
{
for ( Int_t i = 0; i < ntrackrefs; ++i )
{
TrackRefs(event,i);
- if ( fTrackRefs )
+ if ( fTrackRefs != 0x0 )
{
fTrackRefs->Print("","*");
}
TriggerStore(event);
- if ( fTriggerStore )
+ if ( fTriggerStore != 0x0 )
{
fTriggerStore->Print();
}
}
-//_____________________________________________________________________________
-AliMUONVHitStore*
-AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
-{
- /// Return the hitStore for a given track of one event
- /// Return 0 if event and/or track not found
- /// Returned pointer should not be deleted
-
- if ( !IsValid() ) return 0x0;
-
- if ( LoadEvent(event) ) return 0x0;
-
- if ( fHitStore) fHitStore->Clear();
-
- fLoader->LoadHits();
-
- TTree* treeH = fLoader->TreeH();
-
- if (!treeH)
- {
- AliError("Could not get treeH");
- return 0x0;
- }
-
- if ( !fHitStore )
- {
- fHitStore = AliMUONVHitStore::Create(*treeH);
- AliDebug(1,"Creating hitStore from treeH");
- }
-
- if ( fHitStore )
- {
- fHitStore->Connect(*treeH);
- if ( treeH->GetEvent(track) == 0 )
- {
- AliError(Form("Could not read track %d",track));
- fHitStore->Clear();
- }
- }
-
- fLoader->UnloadHits();
-
- return fHitStore;
-}
-
//_____________________________________________________________________________
Bool_t
-AliMUONMCDataInterface::IsValid() const
-{
- /// Whether we were initialized properly or not
- return fIsValid;
-}
-
-//_____________________________________________________________________________
-Int_t
AliMUONMCDataInterface::LoadEvent(Int_t event)
{
/// Load event if different from the current one.
- if ( event != fCurrentEvent )
+ /// Returns kFALSE on error and kTRUE if the event was loaded.
+
+ assert( IsValid() );
+
+ AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
+ if (fLoader->GetRunLoader()->GetEvent(event) == 0)
{
fCurrentEvent = event;
- AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
- if ( event < NumberOfEvents() )
- {
- return fLoader->GetRunLoader()->GetEvent(event);
- }
- else
- {
- return 1;
- }
+ return kTRUE;
}
- return 0;
+ else
+ return kFALSE;
}
AliMUONMCDataInterface::NumberOfEvents() const
{
/// Number of events in the file we're connected to
- if (!IsValid()) return 0;
+ if (not IsValid()) return -1;
return fLoader->GetRunLoader()->GetNumberOfEvents();
}
AliMUONMCDataInterface::NumberOfTracks(Int_t event)
{
/// Number of tracks in the event
- if (!IsValid()) return 0;
+ if ( not IsValid()) return -1;
- if ( LoadEvent(event) ) return 0;
+ if (event != fCurrentEvent)
+ {
+ ResetStores();
+ if ( not LoadEvent(event) ) return -1;
+ }
fLoader->LoadHits();
- Int_t rv(0);
+ Int_t rv(-1);
TTree* treeH = fLoader->TreeH();
- if (treeH)
+ if (treeH != 0x0)
{
rv = static_cast<Int_t>(treeH->GetEntries());
}
AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
{
/// Number of track references in the event
- if (!IsValid()) return 0;
+ if ( not IsValid()) return -1;
- if ( LoadEvent(event) ) return 0;
+ if (event != fCurrentEvent)
+ {
+ ResetStores();
+ if ( not LoadEvent(event) ) return -1;
+ }
fLoader->GetRunLoader()->LoadTrackRefs();
- Int_t rv(0);
+ Int_t rv(-1);
TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
- if (treeTR)
+ if (treeTR != 0x0)
{
rv = static_cast<Int_t>(treeTR->GetEntries());
}
{
/// Connect to a given galice.root file
- delete fHitStore;
- fHitStore=0x0;
- delete fSDigitStore;
- fSDigitStore=0x0;
- delete fDigitStore;
- fDigitStore=0x0;
- delete fTrackRefs;
- fTrackRefs=0x0;
- delete fTriggerStore;
- fTriggerStore=0x0;
+ ResetStores();
fCurrentEvent=-1;
- if ( fLoader )
+ if ( fLoader != 0x0 )
{
delete fLoader->GetRunLoader();
}
}
AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
- if (!runLoader)
+ if (runLoader == 0x0)
{
AliError(Form("Cannot open file %s",filename));
fIsValid = kFALSE;
}
fLoader = runLoader->GetDetectorLoader("MUON");
- if (!fLoader)
+ if (fLoader == 0x0)
{
AliError("Cannot get AliMUONLoader");
fIsValid = kFALSE;
}
- if (!IsValid())
+ if (not IsValid())
{
AliError(Form("Could not access %s filename. Object is unuseable",filename));
}
}
//_____________________________________________________________________________
-AliMUONVDigitStore*
-AliMUONMCDataInterface::SDigitStore(Int_t event)
+Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
{
- /// Return the SDigit store for a given event.
- /// Return 0 if event not found
- /// Returned pointer should not be deleted
-
- if ( LoadEvent(event) ) return 0x0;
-
- fLoader->LoadSDigits();
-
- TTree* treeS = fLoader->TreeS();
-
- if (!treeS)
+/// Loads all simulated data for the given event.
+
+ if (HitStore(event, 0) == 0x0) return kFALSE;
+ if (SDigitStore(event) == 0x0) return kFALSE;
+ if (DigitStore(event) == 0x0) return kFALSE;
+ if (TriggerStore(event) == 0x0) return kFALSE;
+ if (TrackRefs(event, 0) == 0x0) return kFALSE;
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfParticles()
+{
+/// Returns the total number of particles in the kinematics tree.
+
+ AliStack* stack = Stack(fCurrentEvent);
+ if ( stack == 0x0 ) return -1;
+ return (Int_t) stack->GetNtrack();
+}
+
+//_____________________________________________________________________________
+TParticle* AliMUONMCDataInterface::Particle(Int_t index)
+{
+/// Returns the index'th particle in the kinematics tree.
+/// @param index The index number of the particle in the range [0 ... N-1]
+/// where N = NumberOfParticles()
+
+ AliStack* stack = Stack(fCurrentEvent);
+ if ( stack == 0x0 ) return 0x0;
+ return static_cast<TParticle*>( stack->Particle(index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfTracks()
+{
+/// Returns the number of primary tracks (from primary particles) in the current event.
+
+ return NumberOfTracks(fCurrentEvent);
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
+{
+/// Returns the number of hits for a given primary track/particle.
+/// @param track The track number in the range [0 .. N-1]
+/// where N = NumberOfTracks()
+
+ TIterator* iter = GetIterator(kHitIterator, track);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONHit*
+AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
+{
+/// Returns a pointer to the index'th hit object.
+/// @param track The track number in the range [0 .. N-1]
+/// where N = NumberOfTracks()
+/// @param index The index number of the hit in the range [0 ... M-1]
+/// where M = NumberOfHits(track)
+
+ TIterator* iter = GetIterator(kHitIterator, track);
+ return static_cast<AliMUONHit*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
+{
+/// Returns the number of summable digits to be found on a given detector element.
+/// @param detElemId The detector element ID number to search on.
+
+ TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
+{
+/// Returns the a pointer to the index'th summable digit on the specified detector element.
+/// @param detElemId The detector element ID number to search on.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(detElemId)
+
+ TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
+{
+/// Returns the number of summable digits to be found on a specific chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
+
+ TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
+{
+/// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(chamber, cathode)
+
+ TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
+{
+/// Returns the number of simulated digits to be found on a given detector element.
+/// @param detElemId The detector element ID number to search on.
+
+ TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
+{
+/// Returns the a pointer to the index'th simulated digit on the specified detector element.
+/// @param detElemId The detector element ID number to search on.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(detElemId)
+
+ TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
+{
+/// Returns the number of simulated digits to be found on a specific chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
+
+ TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
+{
+/// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
+/// @param chamber The chamber number in the range [0 .. 13].
+/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
+/// 1 is the non-bending plane.
+/// @param index The index number of the digit to fetch in the range [0 .. N-1],
+/// where N = NumberOfDigits(chamber, cathode)
+
+ TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
+ return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
+{
+/// Returns the number of simulated local trigger objects.
+
+ TIterator* iter = GetIterator(kLocalTriggerIterator);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
+{
+/// Returns a pointer to the index'th simulated local trigger object.
+/// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
+/// where N = NumberOfLocalTriggers()
+
+ TIterator* iter = GetIterator(kLocalTriggerIterator);
+ return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
+{
+/// Returns the number of simulated regional trigger objects.
+
+ TIterator* iter = GetIterator(kRegionalTriggerIterator);
+ return CountObjects(iter);
+}
+
+//_____________________________________________________________________________
+AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
+{
+/// Returns a pointer to the index'th simulated regional trigger object.
+/// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
+/// where N = NumberOfRegionalTriggers()
+
+ TIterator* iter = GetIterator(kRegionalTriggerIterator);
+ return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
+}
+
+//_____________________________________________________________________________
+AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
+{
+/// Returns a pointer to the simulated global trigger object for the event.
+
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ return store->Global();
+}
+
+//_____________________________________________________________________________
+Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
+{
+/// Number of track references in the currently selected event.
+
+ return NumberOfTrackRefs(fCurrentEvent);
+}
+
+//_____________________________________________________________________________
+TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
+{
+/// Returns the track references for a given track in the current event.
+/// @param track The track to returns track references for. In the range [0 .. N-1]
+/// where N = NumberOfTrackRefs()
+
+ return TrackRefs(fCurrentEvent, track);
+}
+
+//_____________________________________________________________________________
+void AliMUONMCDataInterface::ResetStores()
+{
+/// Deletes all the store objects that have been created and resets the pointers to 0x0.
+/// The temporary iterator object is automatically reset. See ResetIterator for more details.
+
+ ResetIterator();
+ if (fHitStore != 0x0)
{
- AliError("Could not get treeS");
- return 0x0;
+ delete fHitStore;
+ fHitStore = 0x0;
}
-
- if (!fSDigitStore)
+ if (fSDigitStore != 0x0)
+ {
+ delete fSDigitStore;
+ fSDigitStore = 0x0;
+ }
+ if (fDigitStore != 0x0)
+ {
+ delete fDigitStore;
+ fDigitStore = 0x0;
+ }
+ if (fTrackRefs != 0x0)
{
- fSDigitStore = AliMUONVDigitStore::Create(*treeS);
+ delete fTrackRefs;
+ fTrackRefs = 0x0;
}
+ if (fTriggerStore != 0x0)
+ {
+ delete fTriggerStore;
+ fTriggerStore = 0x0;
+ }
+}
+
+//_____________________________________________________________________________
+TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
+{
+/// Creates an appropriate iterator object and returns it.
+/// If the iterator has already been created then that one is returned otherwise
+/// a new object is created.
+/// Depending on the value of 'type' the semantics of parameters x and y can change.
+/// @param type The type of iterator to create.
+/// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
+/// or kSDigitIteratorByDetectorElement.
+/// If type equals kDigitIteratorByChamberAndCathode or
+/// kSDigitIteratorByChamberAndCathode then this is the chamber number.
+/// For type == kHitIterator the parameter x is the track number.
+/// In all other cases this parameter is ignored.
+/// @param y If type equals kDigitIteratorByChamberAndCathode or
+/// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
+/// number. In all other cases this parameter is ignored.
+
+ if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
+ return fIterator;
- if ( fSDigitStore )
+ if (fCurrentEvent == -1)
{
- fSDigitStore->Clear();
- fSDigitStore->Connect(*treeS);
- treeS->GetEvent(0);
+ AliError("No event was selected. Try first using GetEvent().");
+ return 0x0;
}
- fLoader->UnloadSDigits();
+ ResetIterator();
- return fSDigitStore;
+ switch (type)
+ {
+ case kHitIterator:
+ {
+ Int_t track = x;
+ AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kHitIterator;
+ return fIterator;
+ }
+
+ case kSDigitIteratorByDetectorElement:
+ {
+ Int_t detElem = x;
+ AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ fIterator = store->CreateIterator(detElem, detElem, 2);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kSDigitIteratorByDetectorElement;
+ fDataX = detElem;
+ return fIterator;
+ }
+
+ case kSDigitIteratorByChamberAndCathode:
+ {
+ Int_t chamber = x;
+ Int_t cathode = y;
+ if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
+ {
+ AliError(Form(
+ "Must have give a chamber value in the range [0..%d], but got a value of: %d",
+ AliMpConstants::NofChambers() - 1,
+ chamber
+ ));
+ return 0x0;
+ }
+ if (cathode < 0 or 1 < cathode)
+ {
+ AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
+ return 0x0;
+ }
+
+ AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
+ fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
+ fDataX = chamber;
+ fDataY = cathode;
+ return fIterator;
+ }
+
+ case kDigitIteratorByDetectorElement:
+ {
+ Int_t detElem = x;
+ AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ fIterator = store->CreateIterator(detElem, detElem, 2);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kDigitIteratorByDetectorElement;
+ fDataX = detElem;
+ return fIterator;
+ }
+
+ case kDigitIteratorByChamberAndCathode:
+ {
+ Int_t chamber = x;
+ Int_t cathode = y;
+ if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
+ {
+ AliError(Form(
+ "Must have give a chamber value in the range [0..%d], but got a value of: %d",
+ AliMpConstants::NofChambers() - 1,
+ chamber
+ ));
+ return 0x0;
+ }
+ if (cathode < 0 or 1 < cathode)
+ {
+ AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
+ return 0x0;
+ }
+
+ AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
+ AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
+ fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
+ fDataX = chamber;
+ fDataY = cathode;
+ return fIterator;
+ }
+
+ case kLocalTriggerIterator:
+ {
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateLocalIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kLocalTriggerIterator;
+ return fIterator;
+ }
+
+ case kRegionalTriggerIterator:
+ {
+ AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
+ if (store == 0x0) return 0x0;
+ fIterator = store->CreateRegionalIterator();
+ if (fIterator == 0x0) return 0x0;
+ fCurrentIteratorType = kRegionalTriggerIterator;
+ return fIterator;
+ }
+
+ default:
+ return 0x0;
+ }
}
//_____________________________________________________________________________
-AliStack*
-AliMUONMCDataInterface::Stack(Int_t event)
+void AliMUONMCDataInterface::ResetIterator()
{
- /// Get the Stack (list of generated particles) for one event
- /// Returned pointer should not be deleted
-
- if (!IsValid()) return 0x0;
+/// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
+/// The iterator type and temporary data indicating the state of the iterator are
+/// also reset.
- if ( LoadEvent(event) ) return 0;
-
- fLoader->GetRunLoader()->LoadKinematics();
-
- return fLoader->GetRunLoader()->Stack();
+ if (fIterator != 0x0) delete fIterator;
+ fCurrentIteratorType = kNoIterator;
+ fCurrentIndex = fDataX = fDataY = -1;
+ fIterator = 0x0;
}
//_____________________________________________________________________________
-TClonesArray*
-AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
+Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
{
- /// Get the track references for a given (generated) track of one event
- /// Returned pointer should not be deleted
-
- if ( !IsValid() ) return 0x0;
+/// Counts the number of objects in the iterator and resets it.
+/// @return The number of objects in 'iter'.
- if ( LoadEvent(event) ) return 0;
-
- fLoader->GetRunLoader()->LoadTrackRefs();
-
- TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
-
- if ( fTrackRefs ) fTrackRefs->Clear("C");
-
- if (treeTR)
- {
- if ( treeTR->GetEvent(track) > 0 )
- {
- TBranch* branch = treeTR->GetBranch("MUON");
- branch->SetAddress(&fTrackRefs);
- branch->GetEvent(track);
- }
- }
- else
- {
- AliError("Could not get TreeTR");
- }
-
- fLoader->GetRunLoader()->UnloadTrackRefs();
-
- return fTrackRefs;
+ if (iter == 0x0) return -1;
+ Int_t count = 0;
+ iter->Reset();
+ while ( iter->Next() != 0x0 ) count++;
+ iter->Reset();
+ fCurrentIndex = -1;
+ return count;
}
//_____________________________________________________________________________
-AliMUONVTriggerStore*
-AliMUONMCDataInterface::TriggerStore(Int_t event)
+TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
{
- /// Return the triggerStore for a given event.
- /// Return 0x0 if event not found.
- /// Returned pointer should not be deleted.
-
- if ( LoadEvent(event) ) return 0x0;
-
- fLoader->LoadDigits();
-
- TTree* treeD = fLoader->TreeD();
-
- if ( !treeD )
+/// Fetches the index'th object from the iterator counting the first object
+/// returned by iterator after it is reset as index == 0. The next object
+/// has index == 1 and so on where the last object returned by the iterator
+/// has index == N-1 where N = CountObjects(iter)
+/// This method will only reset the iterator if index is smaller than
+/// fCurrentIndex, which is used to track the iteration progress and is
+/// updated when a new object if returned by this method.
+/// @param iter The iterator to fetch an object from.
+/// @param index The index number of the object to fetch in the range [0 .. N-1]
+/// where N = CountObjects(iter)
+
+ if (index < 0)
{
- AliError("Could not get treeD");
+ AliError(Form("Index is out of bounds. Got a value of %d.", index));
return 0x0;
}
-
- if (!fTriggerStore)
+
+ if (iter == 0x0) return 0x0;
+ if (index <= fCurrentIndex)
{
- fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
+ iter->Reset();
+ fCurrentIndex = -1;
}
- if ( fTriggerStore )
+ TObject* object = 0x0;
+ while (fCurrentIndex < index)
{
- fTriggerStore->Clear();
- fTriggerStore->Connect(*treeD);
- treeD->GetEvent(0);
+ object = iter->Next();
+ if (object == 0x0)
+ {
+ AliError(Form("Index is out of bounds. Got a value of %d.", index));
+ iter->Reset();
+ fCurrentIndex = -1;
+ return 0x0;
+ }
+ fCurrentIndex++;
}
-
- fLoader->UnloadDigits();
-
- return fTriggerStore;
+ return object;
}
/// \brief Easy to use data access to MC information
///
// Author Laurent Aphecetche
+//
+// Moved parts of old AliMUONDataInterface interface to AliMUONMCDataInterface
+// Artur Szostak <artursz@iafrica.com> (University of Cape Town)
#ifndef ROOT_TObject
# include "TObject.h"
#endif
-class AliLoader;
-class AliMUONVDigitStore;
-class AliMUONVHitStore;
class AliMUONVStore;
+class AliMUONVHitStore;
+class AliMUONVDigitStore;
class AliMUONVTriggerStore;
+class AliMUONHit;
+class AliMUONVDigit;
+class AliMUONLocalTrigger;
+class AliMUONRegionalTrigger;
+class AliMUONGlobalTrigger;
+
+class AliLoader;
class AliStack;
+
+class TIterator;
class TClonesArray;
+class TParticle;
class AliMUONMCDataInterface : public TObject
{
void Open(const char* filename);
- Bool_t IsValid() const;
+ /// Returns true if the data interface was able to open the root file correctly.
+ Bool_t IsValid() const { return fIsValid; };
Int_t NumberOfEvents() const;
+ /// Returns the index number of the current event as used int GetEvent(Int_t).
+ Int_t CurrentEvent() const { return fCurrentEvent; }
+
Int_t NumberOfTracks(Int_t event);
Int_t NumberOfTrackRefs(Int_t event);
AliMUONVHitStore* HitStore(Int_t event, Int_t track);
AliMUONVDigitStore* SDigitStore(Int_t event);
AliMUONVDigitStore* DigitStore(Int_t event);
- AliStack* Stack(Int_t event);
+ AliStack* Stack(Int_t event);
TClonesArray* TrackRefs(Int_t event, Int_t track);
AliMUONVTriggerStore* TriggerStore(Int_t event);
void DumpTrackRefs(Int_t event);
void DumpTrigger(Int_t event);
+ Bool_t GetEvent(Int_t event = 0);
+
+ // Note the following methods can be extremely slow. Remember they are only
+ // here for end user convenience for his/her small tests and macros.
+ // If you want speed then don't use these methods. If you really want peak
+ // performance then you should be talking to the AliRunLoader and Store
+ // objects directly.
+ Int_t NumberOfParticles();
+ TParticle* Particle(Int_t index);
+ Int_t NumberOfTracks();
+ Int_t NumberOfHits(Int_t track);
+ AliMUONHit* Hit(Int_t track, Int_t index);
+ Int_t NumberOfSDigits(Int_t detElemId);
+ AliMUONVDigit* SDigit(Int_t detElemId, Int_t index);
+ Int_t NumberOfSDigits(Int_t chamber, Int_t cathode);
+ AliMUONVDigit* SDigit(Int_t chamber, Int_t cathode, Int_t index);
+ Int_t NumberOfDigits(Int_t detElemId);
+ AliMUONVDigit* Digit(Int_t detElemId, Int_t index);
+ Int_t NumberOfDigits(Int_t chamber, Int_t cathode);
+ AliMUONVDigit* Digit(Int_t chamber, Int_t cathode, Int_t index);
+ Int_t NumberOfLocalTriggers();
+ AliMUONLocalTrigger* LocalTrigger(Int_t index);
+ Int_t NumberOfRegionalTriggers();
+ AliMUONRegionalTrigger* RegionalTrigger(Int_t index);
+ AliMUONGlobalTrigger* GlobalTrigger();
+ Int_t NumberOfTrackRefs();
+ TClonesArray* TrackRefs(Int_t track);
+
private:
+
+ enum IteratorType
+ {
+ kNoIterator,
+ kHitIterator,
+ kSDigitIteratorByDetectorElement,
+ kSDigitIteratorByChamberAndCathode,
+ kDigitIteratorByDetectorElement,
+ kDigitIteratorByChamberAndCathode,
+ kLocalTriggerIterator,
+ kRegionalTriggerIterator
+ };
+
/// Not implemented
AliMUONMCDataInterface(const AliMUONMCDataInterface&);
/// Not implemented
AliMUONMCDataInterface& operator=(const AliMUONMCDataInterface&);
void DumpSorted(const AliMUONVStore& store) const;
- Int_t LoadEvent(Int_t event);
+ Bool_t LoadEvent(Int_t event);
+
+ void ResetStores();
+
+ TIterator* GetIterator(IteratorType type, Int_t x = 0, Int_t y = 0);
+ void ResetIterator();
+
+ Int_t CountObjects(TIterator* iter);
+ TObject* FetchObject(TIterator* iter, Int_t index);
-private:
AliLoader* fLoader; //!< Tree accessor
AliMUONVHitStore* fHitStore; //!< current hit store (owner)
Int_t fCurrentEvent; //!< Current event we've read in
Bool_t fIsValid; //!< whether we were initialized properly or not
+ IteratorType fCurrentIteratorType; //!< The type of iterator that is currently set.
+ Int_t fCurrentIndex; //!< A current index number maintained for certain iteration operations.
+ Int_t fDataX; //!< Extra data parameter about the iterator, can be the chamber number, detector element or track number.
+ Int_t fDataY; //!< Extra data parameter about the iterator, can be the cathode number.
+ TIterator* fIterator; //!< Iterator for various iteration operations.
+
static Int_t fgInstanceCounter; //!< To build unique folder name for each instance
ClassDef(AliMUONMCDataInterface,0) // Easy to use MC data accessor