ATLAS Offline Software
GenBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef GENERATORMODULES_GENBASE_H
6 #define GENERATORMODULES_GENBASE_H
7 
9 #include "GaudiKernel/ServiceHandle.h"
10 #include "GaudiKernel/IPartPropSvc.h"
11 #include "GaudiKernel/IIncidentSvc.h"
16 
17 #include "AtlasHepMC/GenEvent.h"
18 #include "AtlasHepMC/GenVertex.h"
20 
21 #include "HepPDT/ParticleData.hh"
22 #include "HepPDT/ParticleDataTable.hh"
23 
24 #include <string>
25 #include <vector>
26 #include <map>
27 
28 
47 class GenBase : public AthAlgorithm {
48 public:
49 
51 
52 
54  GenBase(const std::string& name, ISvcLocator* pSvcLocator);
55 
57  virtual ~GenBase() { }
58 
60 
61 
63 
64  virtual StatusCode initialize() override;
65  virtual StatusCode execute() override { return StatusCode::SUCCESS; }
67 
68 
70 
71 
76  HepMC::GenEvent* event ATLAS_NOT_CONST_THREAD_SAFE () {
77  if (events()->empty())
78  ATH_MSG_ERROR("McEventCollection is empty during first event access");
79  return *(events()->begin());
80  }
81 
83  const HepMC::GenEvent* event_const() const {
84  if (events_const()->empty())
85  ATH_MSG_ERROR("Const McEventCollection is empty during first event access");
86  return *(events_const()->begin());
87  }
88 
94 
97  return events_const( getContext() );
98  }
99  const McEventCollection* events_const( const EventContext& ctx ) const {
101  if (!ret.isValid())
102  ATH_MSG_ERROR("No McEventCollection found in StoreGate with key " << m_mcevents_const.key());
103  return ret.cptr();
104  }
105 
107 
108 
110 
111 
114  return m_ppSvc;
115  }
116 
118  const HepPDT::ParticleDataTable& particleTable() const {
119  return *(m_ppSvc->PDT());
120  }
121 
123  const HepPDT::ParticleDataTable& pdt() const { return particleTable(); }
124 
126  const HepPDT::ParticleData* particleData(int pid) const {
127  return pdt().particle(HepPDT::ParticleID(std::abs(pid)));
128  }
130 
131 
132 protected:
133 
135 
136  std::string m_mcEventKey{};
139  BooleanProperty m_mkMcEvent{this, "MakeMcEvent", false, "Create a new MC event collection if it doesn't exist"};
141 
142 
145 
146  void GeVToMeV(HepMC::GenEvent* evt);
149  void MeVToGeV(HepMC::GenEvent* evt);
151  void cmTomm(HepMC::GenEvent* evt);
153  void mmTocm(HepMC::GenEvent* evt);
155 
156 
157 private:
158 
160  ServiceHandle<IPartPropSvc> m_ppSvc{this, "PartPropSvc", "PartPropSvc"};
161 
163  SG::ReadHandleKey<McEventCollection> m_mcevents_const{ this, "McEventKey", "GEN_EVENT", "StoreGate key of the MC event collection" };
164 
165 };
166 
167 
168 #endif
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
GenBase::~GenBase
virtual ~GenBase()
Virtual destructor.
Definition: GenBase.h:57
GenEvent.h
GenBase::mmTocm
void mmTocm(HepMC::GenEvent *evt)
Scale event lengths by x 1/10.
Definition: GenBase.cxx:87
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
GenBase::GeVToMeV
void GeVToMeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1000.
Definition: GenBase.cxx:58
GenBase::events_const
const McEventCollection * events_const() const
Access the current event's McEventCollection (const)
Definition: GenBase.h:96
SG::ReadHandle< McEventCollection >
GenBase::execute
virtual StatusCode execute() override
Definition: GenBase.h:65
GenBase::ATLAS_NOT_CONST_THREAD_SAFE
HepMC::GenEvent *event ATLAS_NOT_CONST_THREAD_SAFE()
Access the current signal event (first in the McEventCollection)
Definition: GenBase.h:76
GenVertex.h
GenBase::m_mcEventKey
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT)
Definition: GenBase.h:137
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey< McEventCollection >
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
GenBase::MeVToGeV
void MeVToGeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1/1000.
Definition: GenBase.cxx:68
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
AthAlgorithm.h
GenBase::m_mkMcEvent
BooleanProperty m_mkMcEvent
Flag to determine if a new MC event collection should be made if it doesn't exist.
Definition: GenBase.h:139
GenBase::m_ppSvc
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition: GenBase.h:160
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
GenBase
Base class for common behaviour of MC truth algorithms.
Definition: GenBase.h:47
McEventCollection.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
GenBase::m_mcevents_const
SG::ReadHandleKey< McEventCollection > m_mcevents_const
Const handle to the MC event collection.
Definition: GenBase.h:163
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
jobOptions.ParticleID
ParticleID
Definition: jobOptions.decayer.py:85
GenBase::ATLAS_NOT_CONST_THREAD_SAFE
McEventCollection *events ATLAS_NOT_CONST_THREAD_SAFE()
Access the current event's McEventCollection.
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
GenBase::particleTable
const HepPDT::ParticleDataTable & particleTable() const
Get a particle data table.
Definition: GenBase.h:118
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MagicNumbers.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
GenBase::partPropSvc
const ServiceHandle< IPartPropSvc > partPropSvc() const
Access the particle property service.
Definition: GenBase.h:113
GenBase::pdt
const HepPDT::ParticleDataTable & pdt() const
Shorter alias to get a particle data table.
Definition: GenBase.h:123
GenBase::GenBase
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: GenBase.cxx:11
GenBase::cmTomm
void cmTomm(HepMC::GenEvent *evt)
Scale event lengths by x 10.
Definition: GenBase.cxx:78
GenBase::events_const
const McEventCollection * events_const(const EventContext &ctx) const
Definition: GenBase.h:99
checker_macros.h
Define macros for attributes used to control the static checker.
GenBase::particleData
const HepPDT::ParticleData * particleData(int pid) const
Access an element in the particle data table.
Definition: GenBase.h:126
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17
GenBase::event_const
const HepMC::GenEvent * event_const() const
Access the current signal event (const)
Definition: GenBase.h:83
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ServiceHandle< IPartPropSvc >