ATLAS Offline Software
Loading...
Searching...
No Matches
PMGTools::PMGTruthWeightTool Class Reference

Implementation for the xAOD truth meta data weight tool. More...

#include <PMGTruthWeightTool.h>

Inheritance diagram for PMGTools::PMGTruthWeightTool:
Collaboration diagram for PMGTools::PMGTruthWeightTool:

Public Types

Definition of the StoreGate-like object's definition
typedef ServiceHandle< StoreGateSvcMetaStore_t
 Type of the metadata store object in Athena.
typedef const ServiceHandle< StoreGateSvc > & MetaStorePtr_t
 Type of the metadata store pointer in standalone mode.

Public Member Functions

 PMGTruthWeightTool (const std::string &name)
 Create a proper constructor for Athena.
virtual StatusCode sysInitialize ()
 Function initialising the tool in the correct way in Athena.
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Function(s) implementing the asg::IAsgTool interface
virtual StatusCode initialize () override
 Function initialising the tool.
Function(s) implementing the IPMGTruthWeightTool interface
virtual const std::vector< std::string > & getWeightNames () const override
 Implements interface from IPMGTruthWeightTool.
virtual float getWeight (const xAOD::EventInfo *evtInfo, const std::string &weightName) const override
 Implements interface from IPMGTruthWeightTool.
virtual bool hasWeight (const std::string &weightName) const override
 Implements interface from IPMGTruthWeightTool.
virtual float getSysWeight (const xAOD::EventInfo *evtInfo, const CP::SystematicSet &sys) const override
 Implements interface from IPMGTruthWeightTool.
virtual size_t getSysWeightIndex (const CP::SystematicSet &sys) const override
 Implements interface from IPMGTruthWeightTool.
Function(s) implementing the ISystematicsTool interface
virtual CP::SystematicSet affectingSystematics () const override
 Implements interface from ISystematicsTool.
virtual CP::SystematicSet recommendedSystematics () const override
 Implements interface from ISystematicsTool.
Functions providing access to the input/output metadata
MetaStorePtr_t inputMetaStore () const
 Accessor for the input metadata store.
MetaStorePtr_t outputMetaStore () const
 Accessor for the output metadata store.
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

StatusCode getMCChannelNumber (uint32_t &mcChannelNumber)
 Helper function for retrieving MC channel number from file metadata.
StatusCode loadMetaData ()
 Loads weight information from xAOD::TruthMetaDataContainer.
StatusCode loadPOOLMetaData ()
 Loads weight information from POOL using HepMCWeightNames.
StatusCode validateWeightLocationCaches ()
 Validate weight caches.
void clearWeightLocationCaches ()
 Clear caches.
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.
Callback function(s) from AsgMetadataTool
virtual StatusCode beginInputFile () override
 Function called when a new input file is opened.
Callback functions helping in metadata reading/writing
void setUseIncidents (const bool flag)
virtual void handle (const Incident &inc)
 Function receiving incidents from IncidentSvc/TEvent.
virtual StatusCode endInputFile ()
 Function called when the currently open input file got completely processed.
virtual StatusCode beginEvent ()
 Function called when a new events is loaded.
virtual StatusCode metaDataStop ()
 Function called when the tool should write out its metadata.

Protected Attributes

std::string m_metaName
 Stores the meta data record name.
uint32_t m_mcChannelNumber {}
 Current MC channel number.
const xAOD::TruthMetaDataContainerm_metaDataContainer {nullptr}
 Ptr to the meta data container for this file.
bool m_useChannelZeroInMetaData {false}
 Flag to indicate whether the xAOD::TruthMetaData objects have incorrect McChannelNumber.
std::vector< std::string > m_weightNames
 Available weight names for this file.
std::unordered_map< std::string, size_t > m_weightIndices
 Weight names to indices of available weights in this file.
CP::SystematicsCache< std::size_t > m_calibCache {this}
 Systematics to indices of available weights.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

MetaStore_t m_inputMetaStore
 Object accessing the input metadata store.
MetaStore_t m_outputMetaStore
 Object accessing the output metadata store.
bool m_beginInputFileCalled
 Flag helping to discover when the tool misses the opening of the first input file.
bool m_useIncidents
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Implementation for the xAOD truth meta data weight tool.

Author
James Robinson james.nosp@m..rob.nosp@m.inson.nosp@m.@cer.nosp@m.n.ch

Definition at line 25 of file PMGTruthWeightTool.h.

Member Typedef Documentation

◆ MetaStore_t

Type of the metadata store object in Athena.

Definition at line 66 of file AsgMetadataTool.h.

◆ MetaStorePtr_t

Type of the metadata store pointer in standalone mode.

Definition at line 68 of file AsgMetadataTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ PMGTruthWeightTool()

PMGTools::PMGTruthWeightTool::PMGTruthWeightTool ( const std::string & name)

Create a proper constructor for Athena.

Create a constructor for standalone usage

Definition at line 22 of file PMGTruthWeightTool.cxx.

23 : asg::AsgMetadataTool(name)
24 {
25 declareProperty("MetaObjectName", m_metaName = "TruthMetaData");
26 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::string m_metaName
Stores the meta data record name.

Member Function Documentation

◆ affectingSystematics()

CP::SystematicSet PMGTools::PMGTruthWeightTool::affectingSystematics ( ) const
overridevirtual

Implements interface from ISystematicsTool.

Implements CP::IReentrantSystematicsTool.

Definition at line 154 of file PMGTruthWeightTool.cxx.

155 {
156 return m_calibCache.affectingSystematics();
157 }
CP::SystematicsCache< std::size_t > m_calibCache
Systematics to indices of available weights.

◆ beginEvent()

StatusCode asg::AsgMetadataTool::beginEvent ( )
protectedvirtualinherited

◆ beginInputFile()

StatusCode PMGTools::PMGTruthWeightTool::beginInputFile ( )
overrideprotectedvirtual

Function called when a new input file is opened.

Reimplemented from asg::AsgMetadataTool.

Definition at line 183 of file PMGTruthWeightTool.cxx.

184 {
185 // Detect possible MC channel number change
187 ATH_CHECK(getMCChannelNumber(mcChannelNumber));
188
189 if (m_mcChannelNumber != uint32_t(-1) && mcChannelNumber != uint32_t(-1) && mcChannelNumber != m_mcChannelNumber) {
190 ATH_MSG_ERROR("MC channel number from a new file does not match the previously processed files.");
191 return StatusCode::FAILURE;
192 }
193
194 return StatusCode::SUCCESS;
195 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
StatusCode getMCChannelNumber(uint32_t &mcChannelNumber)
Helper function for retrieving MC channel number from file metadata.
uint32_t m_mcChannelNumber
Current MC channel number.
setEventNumber uint32_t

◆ clearWeightLocationCaches()

void PMGTools::PMGTruthWeightTool::clearWeightLocationCaches ( )
protected

Clear caches.

Definition at line 271 of file PMGTruthWeightTool.cxx.

271 {
272 m_weightNames.clear();
273 m_weightIndices.clear();
274 }
std::unordered_map< std::string, size_t > m_weightIndices
Weight names to indices of available weights in this file.
std::vector< std::string > m_weightNames
Available weight names for this file.

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ endInputFile()

StatusCode asg::AsgMetadataTool::endInputFile ( )
protectedvirtualinherited

Function called when the currently open input file got completely processed.

Dummy implementation that can be overridden by the derived tool.

Reimplemented in BookkeeperDumperTool, BookkeeperTool, xAODMaker::TriggerMenuMetaDataTool, and xAODMaker::TruthMetaDataTool.

Definition at line 193 of file AsgMetadataTool.cxx.

193 {
194
195 // Return gracefully:
196 return StatusCode::SUCCESS;
197 }

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getMCChannelNumber()

StatusCode PMGTools::PMGTruthWeightTool::getMCChannelNumber ( uint32_t & mcChannelNumber)
protected

Helper function for retrieving MC channel number from file metadata.

Definition at line 166 of file PMGTruthWeightTool.cxx.

166 {
167 mcChannelNumber = static_cast<uint32_t>(-1);
168
169 // Try to load MC channel number from file metadata
170 ATH_MSG_INFO("Attempting to retrieve MC channel number...");
171 const xAOD::FileMetaData *fmd = nullptr;
172 if (inputMetaStore()->contains<xAOD::FileMetaData>("FileMetaData")) {
173 ATH_CHECK(inputMetaStore()->retrieve(fmd, "FileMetaData"));
174 float fltChannelNumber(-1);
175 if (fmd->value(xAOD::FileMetaData::mcProcID, fltChannelNumber)) {
176 mcChannelNumber = static_cast<uint32_t>(fltChannelNumber);
177 return StatusCode::SUCCESS;
178 }
179 }
180 return StatusCode::FAILURE;
181 }
#define ATH_MSG_INFO(x)
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
@ mcProcID
Same as mc_channel_number [float].
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
retrieve(aClass, aKey=None)
Definition PyKernel.py:110
FileMetaData_v1 FileMetaData
Declare the latest version of the class.

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ getSysWeight()

float PMGTools::PMGTruthWeightTool::getSysWeight ( const xAOD::EventInfo * evtInfo,
const CP::SystematicSet & sys ) const
overridevirtual

Implements interface from IPMGTruthWeightTool.

Implements PMGTools::IPMGTruthWeightTool.

Definition at line 138 of file PMGTruthWeightTool.cxx.

139 {
140 const std::size_t *res;
142 return evtInfo->mcEventWeight(*res);
143 }
#define ANA_CHECK_THROW(EXP)
check whether the given expression was successful, throwing an exception on failure
std::pair< std::vector< unsigned int >, bool > res
float mcEventWeight(size_t i=0) const
The weight of one specific MC event used in the simulation.

◆ getSysWeightIndex()

size_t PMGTools::PMGTruthWeightTool::getSysWeightIndex ( const CP::SystematicSet & sys) const
overridevirtual

Implements interface from IPMGTruthWeightTool.

Implements PMGTools::IPMGTruthWeightTool.

Definition at line 146 of file PMGTruthWeightTool.cxx.

147 {
148 const std::size_t *res;
150 return *res;
151 }

◆ getWeight()

float PMGTools::PMGTruthWeightTool::getWeight ( const xAOD::EventInfo * evtInfo,
const std::string & weightName ) const
overridevirtual

Implements interface from IPMGTruthWeightTool.

Implements PMGTools::IPMGTruthWeightTool.

Definition at line 109 of file PMGTruthWeightTool.cxx.

109 {
110 // Return appropriate weight from EventInfo: this should be identical to the TruthEvent
111 try {
112 return evtInfo->mcEventWeight(m_weightIndices.at(weightName));
113 } catch (const std::out_of_range& e) {
114 // Before throwing an exception, try to recover with bad naming conventions
115 std::string strippedName = std::regex_replace(weightName, std::regex(" "), "_");
116 std::transform(strippedName.begin(), strippedName.end(), strippedName.begin(),
117 [](unsigned char c){ return std::tolower(c); });
118 for (const std::string &weight : m_weightNames) {
119 std::string modifiedName = std::regex_replace(weight, std::regex(" "), "_");
120 std::transform(modifiedName.begin(), modifiedName.end(), modifiedName.begin(),
121 [](unsigned char c){ return std::tolower(c); });
122 if (strippedName == modifiedName){
123 ATH_MSG_WARNING("Using weight name \"" << weight << "\" instead of requested \"" << weightName << "\"");
124 return getWeight(evtInfo, weight);
125 }
126 }
127 ATH_MSG_FATAL("Weight \"" + weightName + "\" could not be found");
128 throw std::runtime_error(name() + ": Weight \"" + weightName + "\" could not be found");
129 }
130 }
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
virtual float getWeight(const xAOD::EventInfo *evtInfo, const std::string &weightName) const override
Implements interface from IPMGTruthWeightTool.

◆ getWeightNames()

const std::vector< std::string > & PMGTools::PMGTruthWeightTool::getWeightNames ( ) const
overridevirtual

Implements interface from IPMGTruthWeightTool.

Implements PMGTools::IPMGTruthWeightTool.

Definition at line 104 of file PMGTruthWeightTool.cxx.

104 {
105 return m_weightNames;
106 }

◆ handle()

void asg::AsgMetadataTool::handle ( const Incident & inc)
protectedvirtualinherited

Function receiving incidents from IncidentSvc/TEvent.

Reimplemented in Trig::TrigDecisionTool.

Definition at line 135 of file AsgMetadataTool.cxx.

135 {
136
137 // Tell the user what's happening:
138 ATH_MSG_VERBOSE( "Callback received with incident: " << inc.type() );
139
140 // Call the appropriate member function:
141 if( inc.type() == IncidentType::BeginInputFile ) {
143 if( beginInputFile().isFailure() ) {
144 ATH_MSG_FATAL( "Failed to call beginInputFile()" );
145 throw std::runtime_error( "Couldn't call beginInputFile()" );
146 }
147 } else if( inc.type() == IncidentType::EndInputFile ) {
148 if( endInputFile().isFailure() ) {
149 ATH_MSG_FATAL( "Failed to call endInputFile()" );
150 throw std::runtime_error( "Couldn't call endInputFile()" );
151 }
152 } else if( inc.type() == IncidentType::BeginEvent ) {
153 // If the tool didn't catch the begin input file incident for the
154 // first input file of the job, then call the appropriate function
155 // now.
156 if( ! m_beginInputFileCalled ) {
158 if( beginInputFile().isFailure() ) {
159 ATH_MSG_FATAL( "Failed to call beginInputFile()" );
160 throw std::runtime_error( "Couldn't call beginInputFile()" );
161 }
162 }
163 if( beginEvent().isFailure() ) {
164 ATH_MSG_FATAL( "Failed to call beginEvent()" );
165 throw std::runtime_error( "Couldn't call beginEvent()" );
166 }
167
168 #ifdef XAOD_STANDALONE
169 } else if( inc.type() == IncidentType::MetaDataStop ) {
170 if( metaDataStop().isFailure() ) {
171 ATH_MSG_FATAL( "Failed to call metaDataStop()" );
172 throw std::runtime_error( "Couldn't call metaDataStop()" );
173 }
174
175 #endif // XAOD_STANDALONE
176 } else {
177 ATH_MSG_WARNING( "Unknown incident type received in AsgMetaDataTool: " << inc.type() );
178 }
179
180 return;
181 }
#define ATH_MSG_VERBOSE(x)
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
virtual StatusCode beginEvent()
Function called when a new events is loaded.
bool m_beginInputFileCalled
Flag helping to discover when the tool misses the opening of the first input file.
virtual StatusCode endInputFile()
Function called when the currently open input file got completely processed.
virtual StatusCode metaDataStop()
Function called when the tool should write out its metadata.

◆ hasWeight()

bool PMGTools::PMGTruthWeightTool::hasWeight ( const std::string & weightName) const
overridevirtual

Implements interface from IPMGTruthWeightTool.

Implements PMGTools::IPMGTruthWeightTool.

Definition at line 133 of file PMGTruthWeightTool.cxx.

133 {
134 return (m_weightIndices.count(weightName) > 0);
135 }

◆ initialize()

StatusCode PMGTools::PMGTruthWeightTool::initialize ( void )
overridevirtual

Function initialising the tool.

Reimplemented from asg::AsgTool.

Definition at line 29 of file PMGTruthWeightTool.cxx.

30 {
31 ATH_MSG_DEBUG("Initialising...");
32
33 ATH_MSG_INFO("Attempting to retrieve truth meta data from the first file...");
34
35 // Clear cached weights
37
38 CP::SystematicSet affSysts = CP::SystematicSet();
39 m_calibCache.initialize (std::move (affSysts),
40 [this] (const CP::SystematicSet& sys,
41 std::size_t& idx) {
42 if (!sys.name().empty()) ATH_MSG_WARNING("Mapping for " << sys.name() << " missing, setting to index 0.");
43 idx = 0;
44 return StatusCode::SUCCESS;
45 });
46
47 // Try to load MC channel number from file metadata
49
50 if (m_mcChannelNumber == uint32_t(-1)) {
51 ATH_MSG_WARNING("... MC channel number could not be loaded");
52 } else {
53 ATH_MSG_INFO("... MC channel number identified as " << m_mcChannelNumber);
54 }
55
56 // Start by trying to load metadata from the store
57 m_metaDataContainer = nullptr;
60 ATH_MSG_INFO("Loaded xAOD::TruthMetaDataContainer");
61
62 // Check for incorrectly stored McChannelNumber
64 for (auto truthMetaData : *m_metaDataContainer) {
65 if (truthMetaData->mcChannelNumber() != 0) { m_useChannelZeroInMetaData = false; }
66 }
67 // If we only have one metadata item take MC channel from there if needed
68 if (m_mcChannelNumber == uint32_t(-1) && m_metaDataContainer->size() == 1) {
69 m_mcChannelNumber = m_metaDataContainer->at(0)->mcChannelNumber();
70 ATH_MSG_WARNING("... MC channel number taken from the metadata as " << m_mcChannelNumber);
71 }
72 if (m_useChannelZeroInMetaData) { ATH_MSG_WARNING("MC channel number in TruthMetaData is invalid - assuming that channel 0 has the correct information."); }
73
74 // Load metadata from TruthMetaDataContainer if we have a valid channel number or if we're going to use 0 anyway
75 // ... otherwise wait until we can load a channel number from EventInfo
77 if (loadMetaData().isFailure()) {
78 ATH_MSG_ERROR("Could not load metadata for MC channel number " << m_mcChannelNumber);
79 return StatusCode::FAILURE;
80 }
81 }
82 } else {
83 // ... now try to load the weight container using the POOL metadata (not possible in AnalysisBase)
84 // see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/AthAnalysisBase#How_to_read_the_truth_weight_nam
85 if (loadPOOLMetaData().isFailure()) {
86 ATH_MSG_ERROR("Could not load POOL HepMCWeightNames");
87 return StatusCode::FAILURE;
88 }
89 }
90
91 // Add the affecting systematics to the global registry
92 CP::SystematicRegistry& registry = CP::SystematicRegistry::getInstance();
93 if (!registry.registerSystematics(*this)) {
94 ATH_MSG_ERROR("unable to register the systematics");
95 return StatusCode::FAILURE;
96 }
97
98 ATH_MSG_DEBUG("Successfully initialized!");
99
100 return StatusCode::SUCCESS;
101 }
#define ATH_MSG_DEBUG(x)
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
void clearWeightLocationCaches()
Clear caches.
StatusCode loadPOOLMetaData()
Loads weight information from POOL using HepMCWeightNames.
bool m_useChannelZeroInMetaData
Flag to indicate whether the xAOD::TruthMetaData objects have incorrect McChannelNumber.
StatusCode loadMetaData()
Loads weight information from xAOD::TruthMetaDataContainer.
const xAOD::TruthMetaDataContainer * m_metaDataContainer
Ptr to the meta data container for this file.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ inputMetaStore()

AsgMetadataTool::MetaStorePtr_t asg::AsgMetadataTool::inputMetaStore ( ) const
inherited

Accessor for the input metadata store.

Definition at line 93 of file AsgMetadataTool.cxx.

93 {
94
95#ifdef XAOD_STANDALONE
96 return &m_inputMetaStore;
97#else // XAOD_STANDALONE
98 return m_inputMetaStore;
99#endif // XAOD_STANDALONE
100 }
MetaStore_t m_inputMetaStore
Object accessing the input metadata store.

◆ loadMetaData()

StatusCode PMGTools::PMGTruthWeightTool::loadMetaData ( )
protected

Loads weight information from xAOD::TruthMetaDataContainer.

Definition at line 198 of file PMGTruthWeightTool.cxx.

198 {
199 // Find the correct truth meta data object
200 uint32_t targetChannelNumber = (m_useChannelZeroInMetaData ? 0 : m_mcChannelNumber);
201 ATH_MSG_INFO("Attempting to load weight meta data from xAOD TruthMetaData for channel " << targetChannelNumber);
202 auto itTruthMetaDataPtr = std::find_if(m_metaDataContainer->begin(), m_metaDataContainer->end(),
203 [targetChannelNumber] (const auto& it) { return it->mcChannelNumber() == targetChannelNumber; }
204 );
205
206 // If no such object is found then return
207 if (itTruthMetaDataPtr == m_metaDataContainer->end()) {
208 ATH_MSG_ERROR("Could not load weight meta data!");
209 return StatusCode::FAILURE;
210 }
211
212 // Update cached weight data
213 const std::vector<std::string> &truthWeightNames = (*itTruthMetaDataPtr)->weightNames();
214 for(std::size_t idx = 0; idx < truthWeightNames.size(); ++idx ) {
215 m_weightNames.push_back(truthWeightNames.at(idx));
216 m_weightIndices[truthWeightNames.at(idx)] = idx;
217
218 std::string sysName = weightNameWithPrefix(truthWeightNames.at(idx));
219 if (!sysName.empty()) {
220 ANA_CHECK (m_calibCache.add(CP::SystematicVariation(sysName),idx));
221 }
222
223 ANA_MSG_VERBOSE(" " << truthWeightNames.at(idx) << " " << sysName);
224 }
225 return this->validateWeightLocationCaches();
226 }
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
StatusCode validateWeightLocationCaches()
Validate weight caches.
std::string weightNameWithPrefix(const std::string &name)
cleanup the weight name and add prefix

◆ loadPOOLMetaData()

StatusCode PMGTools::PMGTruthWeightTool::loadPOOLMetaData ( )
protected

Loads weight information from POOL using HepMCWeightNames.

Definition at line 229 of file PMGTruthWeightTool.cxx.

229 {
230 // AnalysisBase can only use the xAOD::TruthMetaDataContainer, so skip this
231#ifdef XAOD_STANDALONE
232 return StatusCode::SUCCESS;
233#else
234 ATH_MSG_INFO("Looking for POOL HepMC IOVMetaData...");
235 std::map<std::string, int> hepMCWeightNamesMap;
236 if (AAH::retrieveMetadata("/Generation/Parameters", "HepMCWeightNames", hepMCWeightNamesMap, inputMetaStore()).isFailure()) {
237 ATH_MSG_FATAL("Cannot access metadata " << m_metaName << " and failed to get names from IOVMetadata");
238 return StatusCode::FAILURE;
239 }
240
241 // Use input map to fill the index map and the weight names
242 ATH_MSG_INFO("Attempting to load weight meta data from HepMC IOVMetaData container");
243 for (auto& kv : hepMCWeightNamesMap) {
244 m_weightNames.push_back(kv.first);
245 m_weightIndices[kv.first] = kv.second;
246
247 std::string sysName = weightNameWithPrefix(kv.first);
248 if (!sysName.empty()) {
249 ANA_CHECK (m_calibCache.add(CP::SystematicVariation(sysName), kv.second));
250 }
251
252 ANA_MSG_VERBOSE(" " << kv.first << " " << sysName);
253 }
254 return this->validateWeightLocationCaches();
255#endif // XAOD_STANDALONE
256 }
static std::string retrieveMetadata(const std::string &folder, const std::string &key, const ServiceHandle< StoreGateSvc > &inputMetaStore)
method that always returns as a string you can use from, e.g, pyROOT with evt = ROOT....

◆ metaDataStop()

StatusCode asg::AsgMetadataTool::metaDataStop ( )
protectedvirtualinherited

Function called when the tool should write out its metadata.

Dummy implementation that can be overridden by the derived tool.

Reimplemented in BookkeeperDumperTool, BookkeeperTool, xAODMaker::TriggerMenuMetaDataTool, and xAODMaker::TruthMetaDataTool.

Definition at line 209 of file AsgMetadataTool.cxx.

209 {
210
211 // Return gracefully:
212 return StatusCode::SUCCESS;
213 }

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ outputMetaStore()

AsgMetadataTool::MetaStorePtr_t asg::AsgMetadataTool::outputMetaStore ( ) const
inherited

Accessor for the output metadata store.

Definition at line 102 of file AsgMetadataTool.cxx.

102 {
103
104#ifdef XAOD_STANDALONE
105 return &m_outputMetaStore;
106#else // XAOD_STANDALONE
107 return m_outputMetaStore;
108#endif // XAOD_STANDALONE
109 }
MetaStore_t m_outputMetaStore
Object accessing the output metadata store.

◆ print()

◆ recommendedSystematics()

CP::SystematicSet PMGTools::PMGTruthWeightTool::recommendedSystematics ( ) const
overridevirtual

Implements interface from ISystematicsTool.

Implements CP::IReentrantSystematicsTool.

Definition at line 160 of file PMGTruthWeightTool.cxx.

161 {
162 return affectingSystematics();
163 }
virtual CP::SystematicSet affectingSystematics() const override
Implements interface from ISystematicsTool.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setUseIncidents()

void asg::AsgMetadataTool::setUseIncidents ( const bool flag)
inlineprotectedinherited

Definition at line 132 of file AsgMetadataTool.h.

133 {
135 }
bool flag
Definition master.py:29

◆ sysInitialize()

StatusCode asg::AsgMetadataTool::sysInitialize ( )
virtualinherited

Function initialising the tool in the correct way in Athena.

This function is used to set up the callbacks from IncidentSvc in Athena at the right time during initialisation, without the user having to do anything special in his/her code.

Reimplemented from AthCommonDataStore< AthCommonMsg< AlgTool > >.

Definition at line 115 of file AsgMetadataTool.cxx.

115 {
116
117#ifndef XAOD_STANDALONE
118 if (m_useIncidents) {
119 // Connect to the IncidentSvc:
120 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
121 ATH_CHECK( incSvc.retrieve() );
122
123 // Set up the right callbacks: don't rethrow exceptions, any failure and we should end
124 incSvc->addListener( this, IncidentType::BeginEvent, 0, false );
125 }
126 // Let the base class do its thing:
127 ATH_CHECK( AlgTool::sysInitialize() );
128
129#endif // not XAOD_STANDALONE
130
131 // Return gracefully:
132 return StatusCode::SUCCESS;
133 }

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

◆ validateWeightLocationCaches()

StatusCode PMGTools::PMGTruthWeightTool::validateWeightLocationCaches ( )
protected

Validate weight caches.

Definition at line 259 of file PMGTruthWeightTool.cxx.

259 {
260 // Validate weight caches against one another
261 if (m_weightNames.size() != m_weightIndices.size()) {
262 ATH_MSG_ERROR("Found " << m_weightNames.size() << " but " << m_weightIndices.size() << " weight indices!");
263 return StatusCode::FAILURE;
264 }
265
266 ATH_MSG_INFO("Successfully loaded information about " << m_weightNames.size() << " weights");
267 return StatusCode::SUCCESS;
268 }

Member Data Documentation

◆ m_beginInputFileCalled

bool asg::AsgMetadataTool::m_beginInputFileCalled
privateinherited

Flag helping to discover when the tool misses the opening of the first input file.

Definition at line 126 of file AsgMetadataTool.h.

◆ m_calibCache

CP::SystematicsCache<std::size_t> PMGTools::PMGTruthWeightTool::m_calibCache {this}
protected

Systematics to indices of available weights.

Definition at line 116 of file PMGTruthWeightTool.h.

116{this};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_inputMetaStore

MetaStore_t asg::AsgMetadataTool::m_inputMetaStore
privateinherited

Object accessing the input metadata store.

Definition at line 119 of file AsgMetadataTool.h.

◆ m_mcChannelNumber

uint32_t PMGTools::PMGTruthWeightTool::m_mcChannelNumber {}
protected

Current MC channel number.

Definition at line 101 of file PMGTruthWeightTool.h.

101{};

◆ m_metaDataContainer

const xAOD::TruthMetaDataContainer* PMGTools::PMGTruthWeightTool::m_metaDataContainer {nullptr}
protected

Ptr to the meta data container for this file.

Definition at line 104 of file PMGTruthWeightTool.h.

104{nullptr};

◆ m_metaName

std::string PMGTools::PMGTruthWeightTool::m_metaName
protected

Stores the meta data record name.

Definition at line 98 of file PMGTruthWeightTool.h.

◆ m_outputMetaStore

MetaStore_t asg::AsgMetadataTool::m_outputMetaStore
privateinherited

Object accessing the output metadata store.

Definition at line 121 of file AsgMetadataTool.h.

◆ m_useChannelZeroInMetaData

bool PMGTools::PMGTruthWeightTool::m_useChannelZeroInMetaData {false}
protected

Flag to indicate whether the xAOD::TruthMetaData objects have incorrect McChannelNumber.

Definition at line 107 of file PMGTruthWeightTool.h.

107{false};

◆ m_useIncidents

bool asg::AsgMetadataTool::m_useIncidents
privateinherited

Definition at line 128 of file AsgMetadataTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ m_weightIndices

std::unordered_map<std::string, size_t> PMGTools::PMGTruthWeightTool::m_weightIndices
protected

Weight names to indices of available weights in this file.

Definition at line 113 of file PMGTruthWeightTool.h.

◆ m_weightNames

std::vector<std::string> PMGTools::PMGTruthWeightTool::m_weightNames
protected

Available weight names for this file.

Definition at line 110 of file PMGTruthWeightTool.h.


The documentation for this class was generated from the following files: