ATLAS Offline Software
xAODTruthCnvAlg.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAODCREATORALGS_XAODTRUTHCNVALG_H
6 #define XAODCREATORALGS_XAODTRUTHCNVALG_H
7 
9 
10 #ifdef HEPMC3
11 // This form of ifdef is kept for convenience
12 #else
13 // The lines below I don't like. We should fix them when we update the
14 // the metadata to handles (ATLASRECTS-4162).
15 // Needs changes in HepMC to resolve.
16 #ifdef __clang__
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wkeyword-macro"
19 #endif
20 #define private public
22 #undef private
23 #ifdef __clang__
24 #pragma clang diagnostic pop
25 #endif
26 #endif
27 
30 
31 #include "xAODTruth/TruthEvent.h"
38 #include "StoreGate/StoreGateSvc.h"
42 #include "GaudiKernel/IIncidentListener.h"
43 
44 #include <unordered_set>
45 
46 
51 
53 
54 namespace xAODMaker {
55 
65  : public AthReentrantAlgorithm
66  , virtual public IIncidentListener
67 {
68  public:
69 
71  xAODTruthCnvAlg( const std::string& name, ISvcLocator* svcLoc );
72 
74  virtual StatusCode initialize() override;
76  virtual StatusCode execute (const EventContext& ctx) const override;
77 
79  virtual void handle(const Incident& incident) override;
80 
81  private:
82  // Truth metadata fields retrieved from TagInfo
83  struct MetadataFields {
84  std::string lhefGenerator;
85  std::string generators;
86  std::string evgenProcess;
87  std::string evgenTune;
88  std::string hardPDF;
89  std::string softPDF;
90  };
91 
95  {
96  public:
98  const std::string& metaName);
100  const HepMC::GenEvent& genEvt,
101  const MetadataFields& metaFields);
102 
103  private:
106  typedef std::lock_guard<std::mutex> lock_t;
107 
110 
112  std::unordered_set<uint32_t> m_existingMetaDataChan;
113  };
114 
117  std::vector<xAOD::TruthParticle*> incoming;
118  std::vector<ElementLink<xAOD::TruthParticleContainer> > incomingEL;
119  std::vector<xAOD::TruthParticle*> outgoing;
120  std::vector<ElementLink<xAOD::TruthParticleContainer> > outgoingEL;
121  };
123  typedef std::map<HepMC::ConstGenVertexPtr, VertexParticles> VertexMap;
124 
126  static void fillVertex(xAOD::TruthVertex *tv, const HepMC::ConstGenVertexPtr& gv);
128 
131  this, "AODContainerName", "GEN_AOD", "The input McEvenCollection"};
132 
135  this, "xAODTruthEventContainerName", "TruthEvents", "Output TruthEvents container"};
137  this, "xAODTruthPileupEventContainerName", "TruthPileupEvents", "Output TruthPileupEvents container"};
139  this, "xAODTruthParticleContainerName", "TruthParticles", "Output TruthParticles container"};
141  this, "xAODTruthVertexContainerName", "TruthVertices", "Output TruthVertices container"};
143  this, "TruthLinks", "xAODTruthLinks", "Output xAODTruthLinks container"};
144 
146  Gaudi::Property<bool> m_doAllPileUp{this, "WriteAllPileUpTruth", false};
147  Gaudi::Property<bool> m_doInTimePileUp{this, "WriteInTimePileUpTruth", false};
148 
153 
157  std::string m_metaName;
158 
160  Gaudi::Property<bool> m_writeMetaData{this, "WriteTruthMetaData", true};
161 
163  SG::ReadHandleKey<xAOD::EventInfo> m_evtInfo {this, "EventInfo", "EventInfo", "" };
164 
168  }; // class xAODTruthCnvAlg
169 
170 
171 } // namespace xAODMaker
172 
173 #endif // XAODCREATORALGS_XAODTRUTHCNVALG_H
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
TruthParticleContainerFwd.h
xAODMaker::xAODTruthCnvAlg::VertexParticles::incomingEL
std::vector< ElementLink< xAOD::TruthParticleContainer > > incomingEL
Definition: xAODTruthCnvAlg.h:118
TruthVertexContainerFwd.h
xAODMaker::xAODTruthCnvAlg::m_xaodTruthParticleContainerKey
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerKey
Definition: xAODTruthCnvAlg.h:138
xAODMaker::xAODTruthCnvAlg::m_xaodTruthEventContainerKey
SG::WriteHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerKey
The key for the output xAOD truth containers.
Definition: xAODTruthCnvAlg.h:134
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
xAODMaker::xAODTruthCnvAlg::MetadataFields::lhefGenerator
std::string lhefGenerator
Definition: xAODTruthCnvAlg.h:84
TruthPileupEvent.h
ParticleTest.tp
tp
Definition: ParticleTest.py:25
GenParticle_fwd.h
xAODMaker::xAODTruthCnvAlg::MetadataFields
Definition: xAODTruthCnvAlg.h:83
xAODMaker::xAODTruthCnvAlg::MetaDataWriter
Factor out the pieces dealing with writing to meta data.
Definition: xAODTruthCnvAlg.h:95
SG::ReadHandleKey< McEventCollection >
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::xAODTruthCnvAlg::m_metaName
std::string m_metaName
SG key and name for meta data.
Definition: xAODTruthCnvAlg.h:157
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::lock_t
std::lock_guard< std::mutex > lock_t
Definition: xAODTruthCnvAlg.h:106
TruthPileupEventContainer.h
xAOD::mcChannelNumber
mcChannelNumber
Definition: EventInfo_v1.cxx:197
xAODMaker::xAODTruthCnvAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition: xAODTruthCnvAlg.cxx:105
xAODMaker::xAODTruthCnvAlg::fillParticle
static void fillParticle(xAOD::TruthParticle *tp, const HepMC::ConstGenParticlePtr &gp)
Definition: xAODTruthCnvAlg.cxx:542
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAODMaker::xAODTruthCnvAlg::m_doInTimePileUp
Gaudi::Property< bool > m_doInTimePileUp
Definition: xAODTruthCnvAlg.h:147
xAODMaker::xAODTruthCnvAlg::MetadataFields::generators
std::string generators
Definition: xAODTruthCnvAlg.h:85
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_mutex
std::mutex m_mutex
Mutex to control access to meta data writing.
Definition: xAODTruthCnvAlg.h:105
xAODMaker::xAODTruthCnvAlg::fillVertex
static void fillVertex(xAOD::TruthVertex *tv, const HepMC::ConstGenVertexPtr &gv)
These functions do not set up ELs, just the other variables.
Definition: xAODTruthCnvAlg.cxx:530
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
McEventCollection.h
xAODMaker::xAODTruthCnvAlg::m_firstBeginRun
bool m_firstBeginRun
Tag Info.
Definition: xAODTruthCnvAlg.h:166
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
GenVertex_fwd.h
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::maybeWrite
StatusCode maybeWrite(uint32_t mcChannelNumber, const HepMC::GenEvent &genEvt, const MetadataFields &metaFields)
Definition: xAODTruthCnvAlg.cxx:581
xAODMaker::xAODTruthCnvAlg::m_xaodTruthPUEventContainerKey
SG::WriteHandleKey< xAOD::TruthPileupEventContainer > m_xaodTruthPUEventContainerKey
Definition: xAODTruthCnvAlg.h:136
xAODMaker::xAODTruthCnvAlg::VertexParticles::outgoing
std::vector< xAOD::TruthParticle * > outgoing
Definition: xAODTruthCnvAlg.h:119
xAODMaker::xAODTruthCnvAlg::MetadataFields::evgenTune
std::string evgenTune
Definition: xAODTruthCnvAlg.h:87
xAODMaker::xAODTruthCnvAlg::MetadataFields::softPDF
std::string softPDF
Definition: xAODTruthCnvAlg.h:89
xAODMaker::xAODTruthCnvAlg::handle
virtual void handle(const Incident &incident) override
Incident handler.
Definition: xAODTruthCnvAlg.cxx:480
xAODMaker::xAODTruthCnvAlg::m_aodContainerKey
SG::ReadHandleKey< McEventCollection > m_aodContainerKey
The key of the input AOD truth container.
Definition: xAODTruthCnvAlg.h:130
xAODMaker::xAODTruthCnvAlg::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: xAODTruthCnvAlg.cxx:65
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODMaker::xAODTruthCnvAlg::MetadataFields::evgenProcess
std::string evgenProcess
Definition: xAODTruthCnvAlg.h:86
xAODMaker::xAODTruthCnvAlg::m_xaodTruthVertexContainerKey
SG::WriteHandleKey< xAOD::TruthVertexContainer > m_xaodTruthVertexContainerKey
Definition: xAODTruthCnvAlg.h:140
AthReentrantAlgorithm.h
xAODMaker::xAODTruthCnvAlg::m_metaFields
MetadataFields m_metaFields
Definition: xAODTruthCnvAlg.h:167
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
xAODMaker::xAODTruthCnvAlg::ATLAS_THREAD_SAFE
MetaDataWriter m_meta ATLAS_THREAD_SAFE
Helper for writing to the meta data store.
Definition: xAODTruthCnvAlg.h:152
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:41
xAODMaker::xAODTruthCnvAlg::m_evtInfo
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfo
Event Info.
Definition: xAODTruthCnvAlg.h:163
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODMaker::xAODTruthCnvAlg::MetadataFields::hardPDF
std::string hardPDF
Definition: xAODTruthCnvAlg.h:88
xAODMaker::xAODTruthCnvAlg::VertexParticles
Type for tracking particles connected to a single vertex.
Definition: xAODTruthCnvAlg.h:116
xAODMaker::xAODTruthCnvAlg::m_truthLinkContainerKey
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
Definition: xAODTruthCnvAlg.h:142
xAODMaker::xAODTruthCnvAlg::VertexMap
std::map< HepMC::ConstGenVertexPtr, VertexParticles > VertexMap
Convenience handle for a map of vtx ptrs -> connected particles.
Definition: xAODTruthCnvAlg.h:123
EventInfo.h
xAODMaker::xAODTruthCnvAlg::m_writeMetaData
Gaudi::Property< bool > m_writeMetaData
option to disable writing of metadata (e.g. if running a filter on xAOD in generators)
Definition: xAODTruthCnvAlg.h:160
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::initialize
StatusCode initialize(ServiceHandle< StoreGateSvc > &metaStore, const std::string &metaName)
Definition: xAODTruthCnvAlg.cxx:562
WeightContainer.h
xAODMaker::xAODTruthCnvAlg::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Connection to the metadata store.
Definition: xAODTruthCnvAlg.h:155
xAODMaker::xAODTruthCnvAlg::VertexParticles::incoming
std::vector< xAOD::TruthParticle * > incoming
Definition: xAODTruthCnvAlg.h:117
xAODMaker::xAODTruthCnvAlg::m_doAllPileUp
Gaudi::Property< bool > m_doAllPileUp
Pile-up options.
Definition: xAODTruthCnvAlg.h:146
xAODMaker::xAODTruthCnvAlg::VertexParticles::outgoingEL
std::vector< ElementLink< xAOD::TruthParticleContainer > > outgoingEL
Definition: xAODTruthCnvAlg.h:120
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
Polarization.h
TruthEventContainer.h
checker_macros.h
Define macros for attributes used to control the static checker.
TruthMetaDataContainer.h
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_tmd
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.
Definition: xAODTruthCnvAlg.h:109
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_existingMetaDataChan
std::unordered_set< uint32_t > m_existingMetaDataChan
Set for tracking the mc channels for which we already added meta data.
Definition: xAODTruthCnvAlg.h:112
StoreGateSvc.h
TruthEvent.h
xAODMaker::xAODTruthCnvAlg::xAODTruthCnvAlg
xAODTruthCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthCnvAlg.cxx:54
ServiceHandle< StoreGateSvc >
xAODMaker::xAODTruthCnvAlg
Algorithm creating xAOD truth from HepMC.
Definition: xAODTruthCnvAlg.h:67