ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::TruthMetaDataWriter Class Reference

#include <TruthMetaDataWriter.h>

Inheritance diagram for DerivationFramework::TruthMetaDataWriter:
Collaboration diagram for DerivationFramework::TruthMetaDataWriter:

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode addBranches (const EventContext &ctx) const override final

Private Attributes

ServiceHandle< StoreGateSvcm_metaStore {this, "MetaDataStore", "MetaDataStore"}
 Connection to the metadata store.
ServiceHandle< IHepMCWeightSvcm_weightSvc {this, "HepMCWeightSvc", "HepMCWeightSvc/HepMCWeightSvc"}
 Service for retrieving the weight names.
xAOD::TruthMetaDataContainerm_tmd {}
 The meta data container to be written out.
Gaudi::Property< std::string > m_metaName {this, "MetaObjectName", "TruthMetaData"}
 SG key and name for meta data.
std::unordered_set< uint32_t > m_existingMetaDataChan
 Set for tracking the mc channels for which we already added meta data.
ServiceHandle< ITagInfoMgrm_tagInfoMgr
 TagInfoMgr to get information out of /TagInfo.
SG::ReadHandleKey< xAOD::EventInfom_eventInfoKey {this, "EventInfoKey", "EventInfo", "EventInfo key"}

Detailed Description

Definition at line 35 of file TruthMetaDataWriter.h.

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TruthMetaDataWriter::addBranches ( const EventContext & ctx) const
finaloverridevirtual

Definition at line 45 of file TruthMetaDataWriter.cxx.

46{
47
48 //The mcChannelNumber is used as a unique identifier for which truth meta data belongs to
50 // If this fails, we are running on a datatype with no EventInfo. Such data types should
51 // definitely not be mixing MC samples, so this should be safe (will fall back to 0 above)
52 SG::ReadHandle<xAOD::EventInfo> eventInfo(m_eventInfoKey, ctx);
53 if (eventInfo.isPresent()) {
54 mcChannelNumber = eventInfo->mcChannelNumber();
55 }
56
57 //Inserting in a (unordered_)set returns an <iterator, boolean> pair, where the boolean
58 //is used to check if the key already exists (returns false in the case it exists)
59 if( m_existingMetaDataChan.insert(mcChannelNumber).second ) {
61 m_tmd->push_back( md );
62
63 // Get the list of weights from the metadata
64 std::map<std::string,std::size_t> weight_name_map = m_weightSvc->weightNames(ctx);
65
66 std::vector<std::string> orderedWeightNameVec;
67 orderedWeightNameVec.reserve( weight_name_map.size() );
68 for (auto& entry: weight_name_map) {
69 orderedWeightNameVec.push_back(entry.first);
70 }
71
72 //The map from the HepMC record pairs the weight names with a corresponding index,
73 //it is not guaranteed that the indices are ascending when iterating over the map
74 std::sort(orderedWeightNameVec.begin(), orderedWeightNameVec.end(),
75 [&](const std::string& i, const std::string& j){return weight_name_map.at(i) < weight_name_map.at(j);});
76
77 md->setMcChannelNumber(mcChannelNumber);
78 md->setWeightNames( orderedWeightNameVec );
79
81 md->setLhefGenerator( m_tagInfoMgr->findTag("lhefGenerator") );
82 md->setGenerators( m_tagInfoMgr->findTag("generators") );
83 md->setEvgenProcess( m_tagInfoMgr->findTag("evgenProcess") );
84 md->setEvgenTune( m_tagInfoMgr->findTag("evgenTune") );
85 md->setHardPDF( m_tagInfoMgr->findTag("hardPDF") );
86 md->setSoftPDF( m_tagInfoMgr->findTag("softPDF") );
87 // Done getting things from the TagInfo
88
89 } // Done making the new truth metadata object
90 return StatusCode::SUCCESS;
91}
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.
std::unordered_set< uint32_t > m_existingMetaDataChan
Set for tracking the mc channels for which we already added meta data.
ServiceHandle< IHepMCWeightSvc > m_weightSvc
Service for retrieving the weight names.
ServiceHandle< ITagInfoMgr > m_tagInfoMgr
TagInfoMgr to get information out of /TagInfo.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
void setGenerators(const std::string &value)
void setLhefGenerator(const std::string &value)
void setEvgenTune(const std::string &value)
void setHardPDF(const std::string &value)
void setMcChannelNumber(uint32_t value)
void setSoftPDF(const std::string &value)
void setWeightNames(const std::vector< std::string > &value)
void setEvgenProcess(const std::string &value)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
setEventNumber uint32_t
TruthMetaData_v1 TruthMetaData
Typedef to implementation.

◆ initialize()

StatusCode DerivationFramework::TruthMetaDataWriter::initialize ( )
finaloverridevirtual

Definition at line 22 of file TruthMetaDataWriter.cxx.

23{
24 ATH_MSG_VERBOSE("initialize() ...");
25
26 ATH_CHECK( m_eventInfoKey.initialize() );
27
28 // Initialize the service handles
29 CHECK( m_metaStore.retrieve() );
30 CHECK( m_weightSvc.retrieve() );
31 CHECK( m_tagInfoMgr.retrieve() );
32
33 // Create an empty truth meta data container:
36 m_tmd->setStore( aux );
37 // Record it in the metadata store
38 CHECK( m_metaStore->record( aux, m_metaName + "Aux." ) );
39 CHECK( m_metaStore->record( m_tmd, m_metaName ) );
40
41 return StatusCode::SUCCESS;
42}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Gaudi::Property< std::string > m_metaName
SG key and name for meta data.
ServiceHandle< StoreGateSvc > m_metaStore
Connection to the metadata store.
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
TruthMetaDataAuxContainer_v1 TruthMetaDataAuxContainer
Declare the latest version of the truth vertex auxiliary container.

Member Data Documentation

◆ m_eventInfoKey

SG::ReadHandleKey<xAOD::EventInfo> DerivationFramework::TruthMetaDataWriter::m_eventInfoKey {this, "EventInfoKey", "EventInfo", "EventInfo key"}
private

Definition at line 59 of file TruthMetaDataWriter.h.

59{this, "EventInfoKey", "EventInfo", "EventInfo key"};

◆ m_existingMetaDataChan

std::unordered_set<uint32_t> DerivationFramework::TruthMetaDataWriter::m_existingMetaDataChan
mutableprivate

Set for tracking the mc channels for which we already added meta data.

Definition at line 54 of file TruthMetaDataWriter.h.

◆ m_metaName

Gaudi::Property<std::string> DerivationFramework::TruthMetaDataWriter::m_metaName {this, "MetaObjectName", "TruthMetaData"}
private

SG key and name for meta data.

Definition at line 52 of file TruthMetaDataWriter.h.

52{this, "MetaObjectName", "TruthMetaData"}; // FIXME WriteHandle???

◆ m_metaStore

ServiceHandle< StoreGateSvc > DerivationFramework::TruthMetaDataWriter::m_metaStore {this, "MetaDataStore", "MetaDataStore"}
private

Connection to the metadata store.

Definition at line 46 of file TruthMetaDataWriter.h.

46{this, "MetaDataStore", "MetaDataStore"};

◆ m_tagInfoMgr

ServiceHandle< ITagInfoMgr > DerivationFramework::TruthMetaDataWriter::m_tagInfoMgr
private
Initial value:
{
"TagInfoMgr", name()}

TagInfoMgr to get information out of /TagInfo.

Definition at line 56 of file TruthMetaDataWriter.h.

56 {
57 "TagInfoMgr", name()};

◆ m_tmd

xAOD::TruthMetaDataContainer* DerivationFramework::TruthMetaDataWriter::m_tmd {}
private

The meta data container to be written out.

Definition at line 50 of file TruthMetaDataWriter.h.

50{};

◆ m_weightSvc

ServiceHandle< IHepMCWeightSvc > DerivationFramework::TruthMetaDataWriter::m_weightSvc {this, "HepMCWeightSvc", "HepMCWeightSvc/HepMCWeightSvc"}
private

Service for retrieving the weight names.

Definition at line 48 of file TruthMetaDataWriter.h.

48{this, "HepMCWeightSvc", "HepMCWeightSvc/HepMCWeightSvc"};

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