Skip to content

Commit eac229b

Browse files
authored
Ability to access MCEventHeader information in digitization (#13294)
This commit provides: * Modifications to MCKinematicsReader to allow construction from an existing DigitizationContext object * Demonstrating use of MCKinematicsReader in EMCAL digitization to access the Monte-Carlo header information.
1 parent 2ba8cfc commit eac229b

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

Detectors/EMCAL/workflow/include/EMCALWorkflow/EMCALDigitizerSpec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class TChain;
2929
namespace o2
3030
{
3131

32+
namespace steer
33+
{
34+
class MCKinematicsReader;
35+
}
36+
3237
namespace ctp
3338
{
3439
class CTPConfiguration;
@@ -84,6 +89,7 @@ class DigitizerSpec final : public o2::base::BaseDPLDigitizer, public o2::framew
8489
std::vector<Hit> mHits; ///< Vector with input hits
8590
std::vector<TChain*> mSimChains;
8691
o2::ctp::CTPConfiguration* mCTPConfig; ///< CTP configuration
92+
o2::steer::MCKinematicsReader* mcReader; ///< reader to access MC collision information
8793
};
8894

8995
/// \brief Create new digitizer spec

Detectors/EMCAL/workflow/src/EMCALDigitizerSpec.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "DataFormatsEMCAL/TriggerRecord.h"
3333
#include "DataFormatsFT0/Digit.h"
3434
#include "DataFormatsFV0/Digit.h"
35+
#include <Steer/MCKinematicsReader.h>
3536

3637
using namespace o2::framework;
3738
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
@@ -86,6 +87,12 @@ void DigitizerSpec::run(framework::ProcessingContext& ctx)
8687
// get interaction rate ... so that it can be used in digitization
8788
auto intRate = context->getDigitizerInteractionRate();
8889
context->initSimChains(o2::detectors::DetID::EMC, mSimChains);
90+
91+
// init the MCKinematicsReader from the digitization context
92+
if (mcReader == nullptr) {
93+
mcReader = new o2::steer::MCKinematicsReader(context.get());
94+
}
95+
8996
auto& timesview = context->getEventRecords();
9097
LOG(debug) << "GOT " << timesview.size() << " COLLISSION TIMES";
9198

@@ -195,6 +202,10 @@ void DigitizerSpec::run(framework::ProcessingContext& ctx)
195202
mSumDigitizer.setCurrEvID(part.entryID);
196203
mSumDigitizer.setCurrSrcID(part.sourceID);
197204

205+
// retrieve information about the MC collision via the MCEventHeader
206+
auto& mcEventHeader = mcReader->getMCEventHeader(part.sourceID, part.entryID);
207+
mcEventHeader.print();
208+
198209
// get the hits for this event and this source
199210
mHits.clear();
200211
context->retrieveHits(mSimChains, "EMCHit", part.sourceID, part.entryID, &mHits);

Steer/include/Steer/MCKinematicsReader.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,18 @@ class MCKinematicsReader
5555
}
5656
}
5757

58+
/// constructing directly from a digitization context
59+
MCKinematicsReader(o2::steer::DigitizationContext const* context)
60+
{
61+
initFromDigitContext(context);
62+
}
63+
5864
/// inits the reader from a digitization context
5965
/// returns true if successful
6066
bool initFromDigitContext(std::string_view filename);
6167

68+
bool initFromDigitContext(o2::steer::DigitizationContext const* digicontext);
69+
6270
/// inits the reader from a simple kinematics file
6371
bool initFromKinematics(std::string_view filename);
6472

@@ -120,6 +128,7 @@ class MCKinematicsReader
120128
void initIndexedTrackRefs(std::vector<o2::TrackReference>& refs, o2::dataformats::MCTruthContainer<o2::TrackReference>& indexedrefs) const;
121129

122130
DigitizationContext const* mDigitizationContext = nullptr;
131+
bool mOwningDigiContext = false;
123132

124133
// chains for each source
125134
std::vector<TChain*> mInputChains;

Steer/src/MCKinematicsReader.cxx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MCKinematicsReader::~MCKinematicsReader()
2626
}
2727
mInputChains.clear();
2828

29-
if (mDigitizationContext) {
29+
if (mDigitizationContext && mOwningDigiContext) {
3030
delete mDigitizationContext;
3131
}
3232
}
@@ -132,17 +132,13 @@ void MCKinematicsReader::loadTrackRefsForSource(int source) const
132132
}
133133
}
134134

135-
bool MCKinematicsReader::initFromDigitContext(std::string_view name)
135+
bool MCKinematicsReader::initFromDigitContext(o2::steer::DigitizationContext const* context)
136136
{
137137
if (mInitialized) {
138138
LOG(info) << "MCKinematicsReader already initialized; doing nothing";
139139
return false;
140140
}
141141

142-
auto context = DigitizationContext::loadFromFile(name);
143-
if (!context) {
144-
return false;
145-
}
146142
mInitialized = true;
147143
mDigitizationContext = context;
148144

@@ -160,6 +156,21 @@ bool MCKinematicsReader::initFromDigitContext(std::string_view name)
160156
return true;
161157
}
162158

159+
bool MCKinematicsReader::initFromDigitContext(std::string_view name)
160+
{
161+
if (mInitialized) {
162+
LOG(info) << "MCKinematicsReader already initialized; doing nothing";
163+
return false;
164+
}
165+
166+
auto context = DigitizationContext::loadFromFile(name);
167+
if (!context) {
168+
return false;
169+
}
170+
mOwningDigiContext = true;
171+
return initFromDigitContext(context);
172+
}
173+
163174
bool MCKinematicsReader::initFromKinematics(std::string_view name)
164175
{
165176
if (mInitialized) {

0 commit comments

Comments
 (0)