Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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...
 

Detailed Description

Definition at line 30 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 24 of file TruthMetaDataWriter.cxx.

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

◆ ~TruthMetaDataWriter()

DerivationFramework::TruthMetaDataWriter::~TruthMetaDataWriter ( )

Definition at line 36 of file TruthMetaDataWriter.cxx.

36  {
37 }

Member Function Documentation

◆ addBranches()

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

Definition at line 60 of file TruthMetaDataWriter.cxx.

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

◆ initialize()

StatusCode DerivationFramework::TruthMetaDataWriter::initialize ( )
overridevirtual

Definition at line 40 of file TruthMetaDataWriter.cxx.

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

Member Data Documentation

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

◆ m_metaName

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

SG key and name for meta data.

Definition at line 46 of file TruthMetaDataWriter.h.

◆ m_metaStore

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

Connection to the metadata store.

Definition at line 40 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 50 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 44 of file TruthMetaDataWriter.h.

◆ m_weightSvc

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

Service for retrieving the weight names.

Definition at line 42 of file TruthMetaDataWriter.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DerivationFramework::TruthMetaDataWriter::m_metaName
std::string m_metaName
SG key and name for meta data.
Definition: TruthMetaDataWriter.h:46
DerivationFramework::TruthMetaDataWriter::m_tmd
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.
Definition: TruthMetaDataWriter.h:44
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
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:42
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:40
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:210
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:50
xAOD::TruthMetaData_v1::setMcChannelNumber
void setMcChannelNumber(uint32_t value)
beamspotman.n
n
Definition: beamspotman.py:731
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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)
columnar::ContainerId::eventInfo
@ eventInfo
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
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:48
xAOD::TruthMetaData_v1::setEvgenProcess
void setEvgenProcess(const std::string &value)