ATLAS Offline Software
Loading...
Searching...
No Matches
TruthMetaDataWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TruthMetaDataWriter.cxx
7// Author: James Catmore (James.Catmore@cern.ch)
8
9// Header for this class
10#include "TruthMetaDataWriter.h"
11
12// EDM Objects that we need
15
17
18// For accessing the tagInfo
20
21// Athena initialize and finalize
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}
43
44// Selection and collection creation
45StatusCode DerivationFramework::TruthMetaDataWriter::addBranches(const EventContext& ctx) const
46{
47
48 //The mcChannelNumber is used as a unique identifier for which truth meta data belongs to
49 uint32_t mcChannelNumber = 0;
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)
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
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.
Gaudi::Property< std::string > m_metaName
SG key and name for meta data.
virtual StatusCode addBranches(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
ServiceHandle< StoreGateSvc > m_metaStore
Connection to the metadata store.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
bool isPresent() const
Is the referenced object present in SG?
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.
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.
TruthMetaData_v1 TruthMetaData
Typedef to implementation.