ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
DerivationFramework::TruthMetaDataWriter Class Reference

#include <TruthMetaDataWriter.h>

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

Public Member Functions

 TruthMetaDataWriter (const std::string &t, const std::string &n, const IInterface *p)
 
 ~TruthMetaDataWriter ()
 
virtual StatusCode initialize () override
 
virtual StatusCode addBranches () const override
 

Private Attributes

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

Detailed Description

Definition at line 32 of file TruthMetaDataWriter.h.

Constructor & Destructor Documentation

◆ TruthMetaDataWriter()

DerivationFramework::TruthMetaDataWriter::TruthMetaDataWriter ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 25 of file TruthMetaDataWriter.cxx.

28  : base_class(t,n,p)
29  , m_metaStore( "MetaDataStore", n )
30  , m_weightSvc( "HepMCWeightSvc/HepMCWeightSvc" , n )
31 {
32  declareProperty( "MetaObjectName", m_metaName = "TruthMetaData" );
33  declareProperty( "MetaDataStore", m_metaStore );
34 }

◆ ~TruthMetaDataWriter()

DerivationFramework::TruthMetaDataWriter::~TruthMetaDataWriter ( )

Definition at line 37 of file TruthMetaDataWriter.cxx.

37  {
38 }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TruthMetaDataWriter::addBranches ( ) const
overridevirtual

Definition at line 64 of file TruthMetaDataWriter.cxx.

65 {
66  const EventContext& ctx = Gaudi::Hive::currentContext();
67 
68  //The mcChannelNumber is used as a unique identifier for which truth meta data belongs to
70  // If this fails, we are running on a datatype with no EventInfo. Such data types should
71  // definitely not be mixing MC samples, so this should be safe (will fall back to 0 above)
73  if (eventInfo.isPresent()) {
74  mcChannelNumber = eventInfo->mcChannelNumber();
75  }
76 
77  //Inserting in a (unordered_)set returns an <iterator, boolean> pair, where the boolean
78  //is used to check if the key already exists (returns false in the case it exists)
79  if( m_existingMetaDataChan.insert(mcChannelNumber).second ) {
81  m_tmd->push_back( md );
82 
83  // Get the list of weights from the metadata
84  std::map<std::string,std::size_t> weight_name_map = m_weightSvc->weightNames();
85 
86  std::vector<std::string> orderedWeightNameVec;
87  orderedWeightNameVec.reserve( weight_name_map.size() );
88  for (auto& entry: weight_name_map) {
89  orderedWeightNameVec.push_back(entry.first);
90  }
91 
92  //The map from the HepMC record pairs the weight names with a corresponding index,
93  //it is not guaranteed that the indices are ascending when iterating over the map
94  std::sort(orderedWeightNameVec.begin(), orderedWeightNameVec.end(),
95  [&](const std::string& i, const std::string& j){return weight_name_map.at(i) < weight_name_map.at(j);});
96 
98  md->setWeightNames( orderedWeightNameVec );
99 
101  md->setLhefGenerator( m_tagInfoMgr->findTag("lhefGenerator") );
102  md->setGenerators( m_tagInfoMgr->findTag("generators") );
103  md->setEvgenProcess( m_tagInfoMgr->findTag("evgenProcess") );
104  md->setEvgenTune( m_tagInfoMgr->findTag("evgenTune") );
105  md->setHardPDF( m_tagInfoMgr->findTag("hardPDF") );
106  md->setSoftPDF( m_tagInfoMgr->findTag("softPDF") );
107  // Done getting things from the TagInfo
108 
109  } // Done making the new truth metadata object
110  return StatusCode::SUCCESS;
111 }

◆ initialize()

StatusCode DerivationFramework::TruthMetaDataWriter::initialize ( )
overridevirtual

Definition at line 41 of file TruthMetaDataWriter.cxx.

42 {
43  ATH_MSG_VERBOSE("initialize() ...");
44 
46 
47  // Initialize the service handles
48  CHECK( m_metaStore.retrieve() );
49  CHECK( m_weightSvc.retrieve() );
50  CHECK( m_tagInfoMgr.retrieve() );
51 
52  // Create an empty truth meta data container:
55  m_tmd->setStore( aux );
56  // Record it in the metadata store
57  CHECK( m_metaStore->record( aux, m_metaName + "Aux." ) );
58  CHECK( m_metaStore->record( m_tmd, m_metaName ) );
59 
60  return StatusCode::SUCCESS;
61 }

Member Data Documentation

◆ m_eventInfoKey

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

Definition at line 55 of file TruthMetaDataWriter.h.

◆ 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 50 of file TruthMetaDataWriter.h.

◆ m_metaName

std::string DerivationFramework::TruthMetaDataWriter::m_metaName
private

SG key and name for meta data.

Definition at line 48 of file TruthMetaDataWriter.h.

◆ m_metaStore

ServiceHandle< StoreGateSvc > DerivationFramework::TruthMetaDataWriter::m_metaStore
private

Connection to the metadata store.

Definition at line 42 of file TruthMetaDataWriter.h.

◆ m_tagInfoMgr

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

TagInfoMgr to get information out of /TagInfo.

Definition at line 52 of file TruthMetaDataWriter.h.

◆ m_tmd

xAOD::TruthMetaDataContainer* DerivationFramework::TruthMetaDataWriter::m_tmd = nullptr
private

The meta data container to be written out.

Definition at line 46 of file TruthMetaDataWriter.h.

◆ m_weightSvc

ServiceHandle< IHepMCWeightSvc > DerivationFramework::TruthMetaDataWriter::m_weightSvc
private

Service for retrieving the weight names.

Definition at line 44 of file TruthMetaDataWriter.h.


The documentation for this class was generated from the following files:
DerivationFramework::TruthMetaDataWriter::m_metaName
std::string m_metaName
SG key and name for meta data.
Definition: TruthMetaDataWriter.h:48
DerivationFramework::TruthMetaDataWriter::m_tmd
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.
Definition: TruthMetaDataWriter.h:46
xAOD::TruthMetaDataAuxContainer_v1
Auxiliary store for the truth meta data.
Definition: TruthMetaDataAuxContainer_v1.h:30
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::TruthMetaDataWriter::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: TruthMetaDataWriter.h:55
xAOD::TruthMetaDataContainer
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
Definition: TruthMetaDataContainer.h:17
xAOD::TruthMetaData_v1::setSoftPDF
void setSoftPDF(const std::string &value)
DerivationFramework::TruthMetaDataWriter::m_weightSvc
ServiceHandle< IHepMCWeightSvc > m_weightSvc
Service for retrieving the weight names.
Definition: TruthMetaDataWriter.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::mcChannelNumber
mcChannelNumber
Definition: EventInfo_v1.cxx:197
DerivationFramework::TruthMetaDataWriter::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Connection to the metadata store.
Definition: TruthMetaDataWriter.h:42
xAOD::TruthMetaData
TruthMetaData_v1 TruthMetaData
Typedef to implementation.
Definition: TruthMetaData.h:15
xAOD::TruthMetaData_v1::setWeightNames
void setWeightNames(const std::vector< std::string > &value)
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
lumiFormat.i
int i
Definition: lumiFormat.py:85
DerivationFramework::TruthMetaDataWriter::m_tagInfoMgr
ServiceHandle< ITagInfoMgr > m_tagInfoMgr
TagInfoMgr to get information out of /TagInfo.
Definition: TruthMetaDataWriter.h:52
xAOD::TruthMetaData_v1::setMcChannelNumber
void setMcChannelNumber(uint32_t value)
beamspotman.n
n
Definition: beamspotman.py:727
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::TruthMetaData_v1::setGenerators
void setGenerators(const std::string &value)
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TruthMetaData_v1
Class describing meta data for truth records.
Definition: TruthMetaData_v1.h:28
xAOD::TruthMetaDataAuxContainer
TruthMetaDataAuxContainer_v1 TruthMetaDataAuxContainer
Declare the latest version of the truth vertex auxiliary container.
Definition: TruthMetaDataAuxContainer.h:16
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthMetaData_v1::setHardPDF
void setHardPDF(const std::string &value)
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
xAOD::TruthMetaData_v1::setLhefGenerator
void setLhefGenerator(const std::string &value)
xAOD::TruthMetaData_v1::setEvgenTune
void setEvgenTune(const std::string &value)
DerivationFramework::TruthMetaDataWriter::m_existingMetaDataChan
std::unordered_set< uint32_t > m_existingMetaDataChan
Set for tracking the mc channels for which we already added meta data.
Definition: TruthMetaDataWriter.h:50
xAOD::TruthMetaData_v1::setEvgenProcess
void setEvgenProcess(const std::string &value)