Skip to content

Commit

Permalink
MCKinematicsReader: Allow to use with Hit/Kinematics file
Browse files Browse the repository at this point in the history
This allows to fetch a track when one is just given
an eventID + trackID (in a hit).
  • Loading branch information
sawenzel authored and shahor02 committed Apr 25, 2020
1 parent 7fb94fb commit 4a0b344
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
42 changes: 37 additions & 5 deletions Steer/include/Steer/MCKinematicsReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,54 @@ namespace steer
class MCKinematicsReader
{
public:
enum class Mode {
kDigiContext,
kMCKine
};

/// default constructor
MCKinematicsReader() = default;

/// constructor taking context and auto-initializing
MCKinematicsReader(std::string_view filename)
/// constructor taking a name and mode (either kDigiContext or kMCKine)
/// In case of "context", the name is the filename of the digitization context.
/// In case of MCKine mode, the name is the "prefix" referencing a single simulation production.
/// The default mode is kDigiContext.
MCKinematicsReader(std::string_view name, Mode mode = Mode::kDigiContext)
{
init(filename);
if (mode == Mode::kMCKine) {
initFromKinematics(name);
} else if (mode == Mode::kDigiContext) {
initFromDigitContext(name);
}
}

/// inits the reader from a digitization context
/// returns true if successful
bool init(std::string_view filename);
bool initFromDigitContext(std::string_view filename);

/// inits the reader from a simple kinematics file
bool initFromKinematics(std::string_view filename);

bool isInitialized() const { return mInitialized; }

/// query an MC track given a basic label object
/// returns nullptr if no track was found
MCTrack const* getTrack(o2::MCCompLabel const&) const;

/// query an MC track given a basic label object
/// query an MC track given source, event, track IDs
/// returns nullptr if no track was found
MCTrack const* getTrack(int source, int event, int track) const;

/// query an MC track given event, track IDs
/// returns nullptr if no track was found
MCTrack const* getTrack(int event, int track) const;

/// variant returning all tracks for source and event at once
std::vector<MCTrack> const& getTracks(int source, int event) const;

/// variant returning all tracks for source and event at once
std::vector<MCTrack> const& getTracks(int event) const;

/// get all primaries for a certain event

/// get all secondaries of the given label
Expand Down Expand Up @@ -85,6 +107,11 @@ inline MCTrack const* MCKinematicsReader::getTrack(int source, int event, int tr
return &mTracks[source][event][track];
}

inline MCTrack const* MCKinematicsReader::getTrack(int event, int track) const
{
return getTrack(0, event, track);
}

inline std::vector<MCTrack> const& MCKinematicsReader::getTracks(int source, int event) const
{
if (mTracks[source].size() == 0) {
Expand All @@ -93,5 +120,10 @@ inline std::vector<MCTrack> const& MCKinematicsReader::getTracks(int source, int
return mTracks[source][event];
}

inline std::vector<MCTrack> const& MCKinematicsReader::getTracks(int event) const
{
return getTracks(0, event);
}

} // namespace steer
} // namespace o2
22 changes: 21 additions & 1 deletion Steer/src/MCKinematicsReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "DetectorsCommonDataFormats/NameConf.h"
#include "Steer/MCKinematicsReader.h"
#include <TChain.h>
#include <vector>
Expand All @@ -34,8 +35,13 @@ void MCKinematicsReader::loadTracksForSource(int source) const
}
}

bool MCKinematicsReader::init(std::string_view name)
bool MCKinematicsReader::initFromDigitContext(std::string_view name)
{
if (mInitialized) {
LOG(INFO) << "MCKinematicsReader already initialized; doing nothing";
return false;
}

auto context = DigitizationContext::loadFromFile(name);
if (!context) {
return false;
Expand All @@ -54,3 +60,17 @@ bool MCKinematicsReader::init(std::string_view name)

return true;
}

bool MCKinematicsReader::initFromKinematics(std::string_view name)
{
if (mInitialized) {
LOG(INFO) << "MCKinematicsReader already initialized; doing nothing";
return false;
}
mInputChains.emplace_back(new TChain("o2sim"));
mInputChains.back()->AddFile(o2::base::NameConf::getMCKinematicsFileName(name.data()).c_str());
mTracks.resize(1);
mInitialized = true;

return true;
}

0 comments on commit 4a0b344

Please sign in to comment.