ATLAS Offline Software
Loading...
Searching...
No Matches
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"
20
21#include "HepPDT/ParticleData.hh"
22#include "HepPDT/ParticleDataTable.hh"
23
24#include <string>
25#include <vector>
26#include <map>
27
28
47class GenBase : public AthAlgorithm {
48public:
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 }
129
130
131
132protected:
133
135
136
137 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
147 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
157private:
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
#define ATH_MSG_ERROR(x)
Helpers for checking error return status codes and reporting errors.
Property holding a SG store/key/clid from which a ReadHandle is made.
static const Attributes_t empty
Define macros for attributes used to control the static checker.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const HepPDT::ParticleData * particleData(int pid) const
Access an element in the particle data table.
Definition GenBase.h:126
HepMC::GenEvent *event ATLAS_NOT_CONST_THREAD_SAFE()
Access the current signal event (first in the McEventCollection)
Definition GenBase.h:76
McEventCollection *events ATLAS_NOT_CONST_THREAD_SAFE()
Access the current event's McEventCollection.
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT)
Definition GenBase.h:137
void GeVToMeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1000.
Definition GenBase.cxx:58
const ServiceHandle< IPartPropSvc > partPropSvc() const
Access the particle property service.
Definition GenBase.h:113
virtual StatusCode initialize() override
Definition GenBase.cxx:17
const HepPDT::ParticleDataTable & particleTable() const
Get a particle data table.
Definition GenBase.h:118
virtual ~GenBase()
Virtual destructor.
Definition GenBase.h:57
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenBase.cxx:11
BooleanProperty m_mkMcEvent
Flag to determine if a new MC event collection should be made if it doesn't exist.
Definition GenBase.h:139
virtual StatusCode execute() override
Definition GenBase.h:65
const McEventCollection * events_const(const EventContext &ctx) const
Definition GenBase.h:99
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition GenBase.h:160
void MeVToGeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1/1000.
Definition GenBase.cxx:68
void cmTomm(HepMC::GenEvent *evt)
Scale event lengths by x 10.
Definition GenBase.cxx:78
void mmTocm(HepMC::GenEvent *evt)
Scale event lengths by x 1/10.
Definition GenBase.cxx:87
const McEventCollection * events_const() const
Access the current event's McEventCollection (const)
Definition GenBase.h:96
const HepPDT::ParticleDataTable & pdt() const
Shorter alias to get a particle data table.
Definition GenBase.h:123
const HepMC::GenEvent * event_const() const
Access the current signal event (const)
Definition GenBase.h:83
SG::ReadHandleKey< McEventCollection > m_mcevents_const
Const handle to the MC event collection.
Definition GenBase.h:163
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())