ATLAS Offline Software
Loading...
Searching...
No Matches
Photospp_i.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8#include "Photos/Photos.h"
9
10#include "Photos/PhotosHepMC3Event.h"
11namespace Photospp {
12using PhotosHepMCEvent=PhotosHepMC3Event;
13}
14#include "Photos/Log.h"
15
18
19#include "CLHEP/Random/RandFlat.h"
22
23using namespace Photospp;
24
25// Pointer to random engine
26CLHEP::HepRandomEngine* Photospp_i::p_rndmEngine = nullptr;
27
29
30extern "C" double phoranc_(int *idum) {
32 return CLHEP::RandFlat::shoot(Photospp_i::p_rndmEngine);
33}
34
36Photospp_i::Photospp_i(const std::string& name, ISvcLocator* pSvcLocator) :
37 AthAlgorithm(name, pSvcLocator) {
38}
39
42 ATH_MSG_DEBUG("Photospp_i initializing");
43
44 ATH_CHECK(m_rndmSvc.retrieve());
46
48
49 return StatusCode::SUCCESS;
50}
51
53
54 Photos::initialize();
55 Photos::setAlphaQED(m_alphaQED);
56 Photos::setInterference(true);
57 Photos::setCorrectionWtForW(true);
58 Photos::maxWtInterference(m_maxWtInterference);
59 Photos::setMeCorrectionWtForW(m_WMECorrection);
60 Photos::setMeCorrectionWtForZ(m_ZMECorrection);
61 Photos::setPairEmission(m_photonSplitting);
62 Photos::forceMassFrom4Vector(true);
63 Photos::forceMassFromEventRecord(13);
64 Photos::forceMassFromEventRecord(15);
65 Photos::forceMass(11, ParticleConstants::electronMassInMeV); // The assumption that units are MEV will be checked later
66 Photos::forceMassFromEventRecord(211);
67 Photos::setTopProcessRadiation(false);
68 Photos::createHistoryEntries(m_createHistory, 0);
69
71 Photos::setExponentiation(true);
72 } else {
73 Photos::setInfraredCutOff(0.01);
74 Photos::setDoubleBrem(true);
75 Photos::setQuatroBrem(false);
76 phokey.iexp = 0;
77 }
78
79 // over-ride default IR cutoff if user has set a specific value
80 if(m_infraRedCutOff > 0.) {
81 Photos::setInfraredCutOff(m_infraRedCutOff);
82 }
83
84 Photospp::Log::LogWarning(false);
85 Photospp::Photos::setStopAtCriticalError(m_stopCritical);
86
87 Photos::iniInfo();
88
89 return;
90}
91
92
93void Photospp_i::reseedRandomEngine(const std::string& streamName, const EventContext& ctx)
94{
95 long seeds[7];
96 ATHRNG::calculateSeedsMC21(seeds, streamName, ctx.eventID().event_number(), m_dsid, m_randomSeed);
97 p_rndmEngine->setSeeds(seeds, 0); // NOT THREAD-SAFE
98}
99
100
101CLHEP::HepRandomEngine* Photospp_i::getRandomEngine(const std::string& streamName, unsigned long int randomSeedOffset,
102 const EventContext& ctx) const
103{
104 ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
105 rngWrapper->setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
106 return rngWrapper->getEngine(ctx);
107}
108
109
110CLHEP::HepRandomEngine* Photospp_i::getRandomEngineDuringInitialize(const std::string& streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun, unsigned int lbn) const
111{
112 const size_t slot=0;
113 EventContext ctx;
114 ctx.setSlot( slot );
115 ctx.setEventID (EventIDBase (conditionsRun,
116 EventIDBase::UNDEFEVT, // event
117 EventIDBase::UNDEFNUM, // timestamp
118 EventIDBase::UNDEFNUM, // timestamp ns
119 lbn));
121 Atlas::ExtendedEventContext( evtStore()->hiveProxyDict(),
122 conditionsRun) );
123 return getRandomEngine(streamName, randomSeedOffset, ctx);
124}
125
126
127StatusCode Photospp_i::execute(const EventContext& ctx) {
128
129 // initialise if not done already
130
132 setupPhotos();
133 m_delayInitialisation = false;
134 }
135
136 //Re-seed the random number stream
137 reseedRandomEngine("PHOTOSPP", ctx);
138
139 // Get the event collection
140 // FIXME should be using Read/WriteHandles here
141 McEventCollection* eventCollection = nullptr;
142 StatusCode sc = evtStore()->retrieve(eventCollection, m_genEventKey);
143 if (sc.isFailure() || eventCollection == 0) {
144 ATH_MSG_ERROR("Unable to retrieve event collection from StoreGate with key " << m_genEventKey);
145 return StatusCode::FAILURE;
146 } else {
147 ATH_MSG_DEBUG("Retrieved event collection from StoreGate with key " << m_genEventKey);
148 }
149
150 // Get the event most recently added to the event collection
151 HepMC::GenEvent *event = eventCollection->back();
152 if(event == 0) {
153 ATH_MSG_ERROR("Photospp_i received a null HepMC event");
154 return StatusCode::FAILURE;
155 }
156 switch(event->momentum_unit()) {
157 case HepMC3::Units::MomentumUnit::GEV:
158 Photos::setMomentumUnit(Photos::GEV);
159 Photos::forceMass(11, ParticleConstants::electronMassInMeV/1000.); // Convert MeV to GeV
160 break;
161 case HepMC3::Units::MomentumUnit::MEV:
162 Photos::setMomentumUnit(Photos::MEV);
163 Photos::forceMass(11, ParticleConstants::electronMassInMeV);
164 break;
165 default:
166 ATH_MSG_ERROR("Photospp_i received a event with unknown units.");
167 Photos::setMomentumUnit(Photos::DEFAULT_MOMENTUM);
168 break;
169 };
170 PhotosHepMCEvent photosEvent(event);
171 photosEvent.process();
172
173 return StatusCode::SUCCESS;
174}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
static Double_t sc
A number of constexpr particle constants to avoid hardcoding them directly in various places.
void ignore_unused_variable_warning(int *)
double phoranc_(int *idum)
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:154
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:108
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< StoreGateSvc > & evtStore()
const T * back() const
Access the last element in the collection as an rvalue.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
BooleanProperty m_createHistory
Whether to create history entries (default = yes).
Definition Photospp_i.h:66
BooleanProperty m_photonSplitting
Whether to include photon splitting.
Definition Photospp_i.h:81
void setupPhotos()
Set up the Photos class This may be called in the initialize method or directly before the generation...
BooleanProperty m_stopCritical
Whether to stop on critical error (default = no).
Definition Photospp_i.h:69
Photospp_i(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena algorithm constructor.
BooleanProperty m_delayInitialisation
Delay initialisation until just before first event execution (default = no).
Definition Photospp_i.h:72
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition Photospp_i.h:51
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
BooleanProperty m_WMECorrection
Whether to apply ME correction to W decays (default = no, until validated).
Definition Photospp_i.h:78
IntegerProperty m_randomSeed
Seed for random number engine.
Definition Photospp_i.h:57
DoubleProperty m_maxWtInterference
Definition Photospp_i.h:86
void reseedRandomEngine(const std::string &streamName, const EventContext &ctx)
IntegerProperty m_dsid
Definition Photospp_i.h:54
StatusCode execute(const EventContext &ctx)
Run Photos on one event Will require a pre-existing HepMC event in Storegate.
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
DoubleProperty m_infraRedCutOff
Definition Photospp_i.h:84
StringProperty m_genEventKey
The GenEvent StoreGate key - FIXME should be using Read/WriteHandles here.
Definition Photospp_i.h:60
BooleanProperty m_ZMECorrection
Whether to apply ME correction to Z decays (default = no, until validated).
Definition Photospp_i.h:75
static CLHEP::HepRandomEngine * p_rndmEngine
Definition Photospp_i.h:39
BooleanProperty m_exponentiation
Whether to use exponentiation mode (default = yes).
Definition Photospp_i.h:63
StatusCode initialize()
Initialise the Photospp_i algorithm and required services.
DoubleProperty m_alphaQED
Value of alpha_QED.
Definition Photospp_i.h:89
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
constexpr double electronMassInMeV
the mass of the electron (in MeV)
PhotosHepMC3Event PhotosHepMCEvent