![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
#include <xAODtoHepMCTool.h>
|
| xAODtoHepMCTool (const std::string &name) |
|
virtual | ~xAODtoHepMCTool () |
|
virtual StatusCode | initialize () override |
| Dummy implementation of the initialisation function. More...
|
|
StatusCode | finalize () override |
|
std::vector< HepMC::GenEvent > | getHepMCEvents (const xAOD::TruthEventContainer *xTruthEventContainer, const xAOD::EventInfo *eventInfo) const override |
|
virtual void | print () const |
| Print the state of the tool. More...
|
|
ServiceHandle< StoreGateSvc > & | evtStore () |
| The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
const ServiceHandle< StoreGateSvc > & | evtStore () const |
| The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
const ServiceHandle< StoreGateSvc > & | detStore () const |
| The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
virtual StatusCode | sysInitialize () override |
| Perform system initialization for an algorithm. More...
|
|
virtual StatusCode | sysStart () override |
| Handle START transition. More...
|
|
virtual std::vector< Gaudi::DataHandle * > | inputHandles () const override |
| Return this algorithm's input handles. More...
|
|
virtual std::vector< Gaudi::DataHandle * > | outputHandles () const override |
| Return this algorithm's output handles. More...
|
|
Gaudi::Details::PropertyBase & | declareProperty (Gaudi::Property< T > &t) |
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &) |
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, T &property, const std::string &doc="none") |
| Declare a new Gaudi property. More...
|
|
void | updateVHKA (Gaudi::Details::PropertyBase &) |
|
MsgStream & | msg () const |
|
MsgStream & | msg (const MSG::Level lvl) const |
|
bool | msgLvl (const MSG::Level lvl) const |
|
Definition at line 22 of file xAODtoHepMCTool.h.
◆ StoreGateSvc_t
◆ xAODtoHepMCTool()
xAODtoHepMCTool::xAODtoHepMCTool |
( |
const std::string & |
name | ) |
|
◆ ~xAODtoHepMCTool()
virtual xAODtoHepMCTool::~xAODtoHepMCTool |
( |
| ) |
|
|
inlinevirtual |
◆ createHepMCEvent()
EVENT LEVEL
Avoid double deletion
Definition at line 102 of file xAODtoHepMCTool.cxx.
106 HepMC::GenEvent genEvt;
112 genEvt.set_event_number(evtNum);
113 ATH_MSG_DEBUG(
"Start createHepMCEvent for event " << evtNum);
116 #ifndef XAOD_STANDALONE
117 const std::vector<float> weights = xEvt->
weights();
118 std::map<std::string, int> weightNameMap;
123 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>();
125 std::vector<std::string> wnames;
126 wnames.reserve(weights.size());
128 for (
const auto&
it : weightNameMap) {
129 if (
it.second ==
idx) {
130 wnames.push_back(
it.first);
135 genEvt.run_info()->set_weight_names(wnames);
136 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
137 genEvt.weights().push_back(*wgt);
140 if (weightNameMap.size()) {
141 HepMC::WeightContainer& wc = genEvt.weights();
144 for (
const auto&
it : weightNameMap) {
145 if (
it.second ==
idx) {
146 wc[
it.first ] = weights[
idx];
153 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
154 genEvt.weights().push_back(*wgt);
162 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
167 if (!tlink.isValid()) {
continue; }
171 if (xPart ==
nullptr) {
172 ATH_MSG_WARNING(
"xAOD TruthParticle is equal to NULL. This should not happen!");
195 hepmcParticle->set_status(2);
203 bool prodVtxSeenBefore(
false);
204 auto hepmcProdVtx =
vertexHelper(xAODProdVtx, vertexMap, prodVtxSeenBefore);
207 hepmcProdVtx->add_particle_out(hepmcParticle);
209 hepmcProdVtx->add_particle_out(hepmcParticle.get());
212 if (!prodVtxSeenBefore) {
213 genEvt.add_vertex(hepmcProdVtx);
235 if (xPart->
hasProdVtx()) { (void)hepmcParticle.release(); }
239 bool decayVtxSeenBefore(
false);
240 auto hepmcDecayVtx =
vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
243 hepmcDecayVtx->add_particle_in(hepmcParticle);
245 hepmcDecayVtx->add_particle_in(hepmcParticle.get());
248 if (!decayVtxSeenBefore) {
249 genEvt.add_vertex(hepmcDecayVtx);
258 ATH_MSG_DEBUG(
"suggest_barcode failed for particle " << bcpart);
265 (void)hepmcParticle.release();
◆ createHepMCParticle()
◆ createHepMCVertex()
◆ declareGaudiProperty() [1/4]
specialization for handling Gaudi::Property<SG::VarHandleKeyArray>
Definition at line 170 of file AthCommonDataStore.h.
175 hndl.documentation());
◆ declareGaudiProperty() [2/4]
specialization for handling Gaudi::Property<SG::VarHandleKey>
Definition at line 156 of file AthCommonDataStore.h.
161 hndl.documentation());
◆ declareGaudiProperty() [3/4]
specialization for handling Gaudi::Property<SG::VarHandleBase>
Definition at line 184 of file AthCommonDataStore.h.
189 hndl.documentation());
◆ declareGaudiProperty() [4/4]
◆ declareProperty() [1/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
hndl | Object holding the property value. |
doc | Documentation string for the property. |
This is the version for types that derive from SG::VarHandleBase
. The property value object is put on the input and output lists as appropriate; then we forward to the base class.
Definition at line 245 of file AthCommonDataStore.h.
250 this->declare(hndl.
vhKey());
251 hndl.
vhKey().setOwner(
this);
◆ declareProperty() [2/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
hndl | Object holding the property value. |
doc | Documentation string for the property. |
This is the version for types that derive from SG::VarHandleKey
. The property value object is put on the input and output lists as appropriate; then we forward to the base class.
Definition at line 221 of file AthCommonDataStore.h.
◆ declareProperty() [3/6]
◆ declareProperty() [4/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
property | Object holding the property value. |
doc | Documentation string for the property. |
This is the generic version, for types that do not derive from SG::VarHandleKey
. It just forwards to the base class version of declareProperty
.
Definition at line 333 of file AthCommonDataStore.h.
◆ declareProperty() [5/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
property | Object holding the property value. |
doc | Documentation string for the property. |
This dispatches to either the generic declareProperty
or the one for VarHandle/Key/KeyArray.
Definition at line 352 of file AthCommonDataStore.h.
◆ declareProperty() [6/6]
◆ detStore()
◆ evtStore() [1/2]
◆ evtStore() [2/2]
◆ extraDeps_update_handler()
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
◆ finalize()
StatusCode xAODtoHepMCTool::finalize |
( |
| ) |
|
|
overridevirtual |
Implements IxAODtoHepMCTool.
Definition at line 27 of file xAODtoHepMCTool.cxx.
29 ATH_MSG_INFO(
"==============================================================");
30 ATH_MSG_INFO(
"========== xAOD -> HepMC Tool :: Run Summary ==========");
31 ATH_MSG_INFO(
"==============================================================");
35 ATH_MSG_INFO(
" ... check input particle/vertex barcodes.");
52 ATH_MSG_INFO(
"Inconsistencies with the beam particles storage in the event record!");
59 ATH_MSG_INFO(
"==============================================================");
60 ATH_MSG_INFO(
"=================== End Run Summary ===================");
61 ATH_MSG_INFO(
"==============================================================");
62 return StatusCode::SUCCESS;
◆ getHepMCEvents()
Implements IxAODtoHepMCTool.
Definition at line 65 of file xAODtoHepMCTool.cxx.
70 std::vector<HepMC::GenEvent> mcEventCollection;
84 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>(*(hepmcEvent.run_info().get()));
87 mcEventCollection.push_back(std::move(hepmcEvent));
89 mcEventCollection[mcEventCollection.size()-1].set_run_info(
runinfo);
99 return mcEventCollection;
◆ getKey()
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
-
ptr | The 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.
121 #ifdef XAOD_STANDALONE
124 return evtStore()->event()->getKey( ptr );
127 return (
proxy ==
nullptr ? 0 :
proxy->sgkey() );
128 #endif // XAOD_STANDALONE
◆ 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
-
ptr | The 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.
108 #ifdef XAOD_STANDALONE
111 return evtStore()->event()->getName( ptr );
114 static const std::string
dummy =
"";
116 #endif // XAOD_STANDALONE
◆ getProperty()
template<class T >
const T* asg::AsgTool::getProperty |
( |
const std::string & |
name | ) |
const |
|
inherited |
Get one of the tool's properties.
◆ initialize()
StatusCode xAODtoHepMCTool::initialize |
( |
| ) |
|
|
overridevirtual |
Dummy implementation of the initialisation function.
It's here to allow the dual-use tools to skip defining an initialisation function. Since many are doing so...
Reimplemented from asg::AsgTool.
Definition at line 16 of file xAODtoHepMCTool.cxx.
24 return StatusCode::SUCCESS;
◆ inputHandles()
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.
◆ msg() [1/2]
◆ msg() [2/2]
◆ 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.
◆ msgLvl()
◆ outputHandles()
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.
◆ print()
void asg::AsgTool::print |
( |
| ) |
const |
|
virtualinherited |
Print the state of the tool.
Implements asg::IAsgTool.
Reimplemented in JetRecTool, JetFinder, JetModifiedMassDrop, JetFromPseudojet, JetReclusterer, JetReclusteringTool, JetTruthLabelingTool, JetPileupLabelingTool, HI::HIPileupTool, top::TopObjectSelection, JetDumper, JetBottomUpSoftDrop, JetRecursiveSoftDrop, JetSoftDrop, JetConstituentsRetriever, JetSubStructureMomentToolsBase, JetSplitter, JetToolRunner, JetPruner, JetPseudojetRetriever, JetTrimmer, AsgHelloTool, and KtDeltaRTool.
Definition at line 131 of file AsgTool.cxx.
◆ printxAODEvent()
Definition at line 321 of file xAODtoHepMCTool.cxx.
324 std::vector<int> uidPars;
325 std::vector<int> uidKids;
329 std::cout <<
"======================================================================================" << std::endl;
330 std::cout <<
"xAODTruth Event " << evtNum << std::endl;
331 std::cout <<
" UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
332 std::cout <<
" -----------------------------------------------------------------------------------" << std::endl;
334 int nPart =
event->nTruthParticles();
335 for (
int i = 0;
i < nPart; ++
i)
338 if (
part ==
nullptr)
continue;
340 int id =
part->pdgId();
341 if (
id != 25)
continue;
343 float px =
part->px() / 1000.;
344 float py =
part->py() / 1000.;
345 float pz =
part->pz() / 1000.;
346 float e =
part->e() / 1000.;
350 if (
part->hasProdVtx())
357 if (
part->hasDecayVtx())
365 << std::setw(8) <<
stat
366 << std::setprecision(2) << std::fixed
367 << std::setw(10) <<
px << std::setw(10) <<
py
368 << std::setw(10) <<
pz << std::setw(10) <<
e <<
" ";
370 for (
unsigned int k = 0;
k < uidPars.size(); ++
k)
372 std::cout << uidPars[
k] <<
" ";
375 for (
unsigned int k = 0;
k < uidKids.size(); ++
k)
377 std::cout << uidKids[
k] <<
" ";
379 std::cout << std::endl;
381 std::cout <<
"======================================================================================" << std::endl;
◆ renounce()
◆ renounceArray()
◆ sysInitialize()
◆ sysStart()
Handle START transition.
We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.
◆ updateVHKA()
◆ vertexHelper()
Definition at line 275 of file xAODtoHepMCTool.cxx.
282 vMapItr = vertexMap.find(xaodVertex);
284 if (vMapItr != vertexMap.end()) {
286 hepmcVertex = (*vMapItr).second;
292 hepmcVertex = vertexMap[xaodVertex];
◆ m_badBeams
int xAODtoHepMCTool::m_badBeams |
|
private |
◆ m_badSuggest
std::atomic<int> xAODtoHepMCTool::m_badSuggest |
|
mutableprivate |
◆ m_detStore
◆ m_evtCount
std::atomic<int> xAODtoHepMCTool::m_evtCount |
|
mutableprivate |
◆ m_evtStore
◆ m_lenFac
Gaudi::Property<float> xAODtoHepMCTool::m_lenFac |
|
private |
Initial value:{
this, "LengthFactor", 1.0,
"Scale factor to be applied to truth lengths to convert from mm, e.g. 0.01 to go to cm"}
Definition at line 46 of file xAODtoHepMCTool.h.
◆ m_maxCount
Gaudi::Property<int> xAODtoHepMCTool::m_maxCount |
|
private |
Initial value:{
this, "PrintNevents", 0,
"Maximum number of events to print out"}
Definition at line 52 of file xAODtoHepMCTool.h.
◆ m_momFac
Gaudi::Property<float> xAODtoHepMCTool::m_momFac |
|
private |
Initial value:{
this, "MomentFactor", 0.001,
"Scale factor to be applied to truth energy and momenta to convert from MeV, e.g. 0.001 to go to GeV"}
Input container key (job property)
Definition at line 43 of file xAODtoHepMCTool.h.
◆ m_noProdVtx
int xAODtoHepMCTool::m_noProdVtx |
|
private |
◆ m_signalOnly
Gaudi::Property<bool> xAODtoHepMCTool::m_signalOnly |
|
private |
Initial value:{
this, "SignalOnly", true,
"Convert only the signal event (true), or all events found"}
Definition at line 49 of file xAODtoHepMCTool.h.
◆ m_varHandleArraysDeclared
◆ m_vhka
The documentation for this class was generated from the following files:
HepMC::GenVertex * GenVertexPtr
JetConstituentVector::iterator iterator
bool suggest_barcode(T &p, int i)
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
uint64_t eventNumber() const
The current event's event number.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
#define ATH_MSG_VERBOSE(x)
void line(std::ostream &os, const GenEvent &e)
virtual void setOwner(IDataHandleHolder *o)=0
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
constexpr int SPECIALSTATUS
Constant that the meaning of which is currently lost, to be recovered...
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
GenVertexPtr newGenVertexPtr(const HepMC::FourVector &pos=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), const int i=0)
Class describing a truth particle in the MC record.
bool hasProdVtx() const
Check for a production vertex on this particle.
Class describing a signal truth event in the MC record.
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
virtual void renounce()=0
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
const std::vector< float > & weights() const
Const access to the weights vector.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Class describing a truth vertex in the MC record.
GenParticlePtr newGenParticlePtr(const HepMC::FourVector &mom=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
#define ATH_MSG_WARNING(x)
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
const TruthParticleLinks_t & truthParticleLinks() const
Get all the truth particles.
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>
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....