ATLAS Offline Software
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 #ifdef HEPMC3
11 #include "Photos/PhotosHepMC3Event.h"
12 namespace Photospp {
13 using PhotosHepMCEvent=PhotosHepMC3Event;
14 }
15 #else
16 #include "Photos/PhotosHepMCEvent.h"
17 #endif
18 #include "Photos/Log.h"
19 
22 
23 #include "CLHEP/Random/RandFlat.h"
25 
26 using namespace Photospp;
27 
28 // Pointer to random engine
29 CLHEP::HepRandomEngine* Photospp_i::p_rndmEngine = nullptr;
30 
32 
33 extern "C" double phoranc_(int *idum) {
35  return CLHEP::RandFlat::shoot(Photospp_i::p_rndmEngine);
36 }
37 
39 Photospp_i::Photospp_i(const std::string& name, ISvcLocator* pSvcLocator) :
40  AthAlgorithm(name, pSvcLocator) {
41 }
42 
45  ATH_MSG_DEBUG("Photospp_i initializing");
46 
47  ATH_CHECK(m_rndmSvc.retrieve());
48  p_rndmEngine = getRandomEngineDuringInitialize("PHOTOSPP_INIT", m_randomSeed, m_dsid);
49 
50  if(!m_delayInitialisation) setupPhotos();
51 
52  return StatusCode::SUCCESS;
53 }
54 
56 
58  Photos::setAlphaQED(m_alphaQED);
59  Photos::setInterference(true);
60  Photos::setCorrectionWtForW(true);
61  Photos::maxWtInterference(m_maxWtInterference);
62  Photos::setMeCorrectionWtForW(m_WMECorrection);
63  Photos::setMeCorrectionWtForZ(m_ZMECorrection);
64  Photos::setPairEmission(m_photonSplitting);
65  Photos::forceMassFrom4Vector(true);
66  Photos::forceMassFromEventRecord(13);
67  Photos::forceMassFromEventRecord(15);
68  Photos::forceMass(11, 0.510998910); // The assumption that unots are MEV will be checked later
69  Photos::forceMassFromEventRecord(211);
70  Photos::setTopProcessRadiation(false);
71  Photos::createHistoryEntries(m_createHistory, 3);
72 
73  if(m_exponentiation) {
74  Photos::setExponentiation(true);
75  } else {
76  Photos::setInfraredCutOff(0.01);
77  Photos::setDoubleBrem(true);
78  Photos::setQuatroBrem(false);
79  phokey.iexp = 0;
80  }
81 
82  // over-ride default IR cutoff if user has set a specific value
83  if(m_infraRedCutOff > 0.) {
84  Photos::setInfraredCutOff(m_infraRedCutOff);
85  }
86 
87  Photospp::Log::LogWarning(false);
88  Photospp::Photos::setStopAtCriticalError(m_stopCritical);
89 
90  Photos::iniInfo();
91 
92  return;
93 }
94 
95 
96 void Photospp_i::reseedRandomEngine(const std::string& streamName, const EventContext& ctx)
97 {
98  long seeds[7];
99  ATHRNG::calculateSeedsMC21(seeds, streamName, ctx.eventID().event_number(), m_dsid, m_randomSeed);
100  p_rndmEngine->setSeeds(seeds, 0); // NOT THREAD-SAFE
101 }
102 
103 
104 CLHEP::HepRandomEngine* Photospp_i::getRandomEngine(const std::string& streamName, unsigned long int randomSeedOffset,
105  const EventContext& ctx) const
106 {
107  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
108  rngWrapper->setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
109  return rngWrapper->getEngine(ctx);
110 }
111 
112 
113 CLHEP::HepRandomEngine* Photospp_i::getRandomEngineDuringInitialize(const std::string& streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun, unsigned int lbn) const
114 {
115  const size_t slot=0;
116  EventContext ctx;
117  ctx.setSlot( slot );
118  ctx.setEventID (EventIDBase (conditionsRun,
119  EventIDBase::UNDEFEVT, // event
120  EventIDBase::UNDEFNUM, // timestamp
121  EventIDBase::UNDEFNUM, // timestamp ns
122  lbn));
124  Atlas::ExtendedEventContext( evtStore()->hiveProxyDict(),
125  conditionsRun) );
126  return getRandomEngine(streamName, randomSeedOffset, ctx);
127 }
128 
129 
131 
132  // initialise if not done already
133 
134  if(m_delayInitialisation) {
135  setupPhotos();
136  m_delayInitialisation = false;
137  }
138 
139  //Re-seed the random number stream
140  const EventContext& ctx = Gaudi::Hive::currentContext();
141  reseedRandomEngine("PHOTOSPP", ctx);
142 
143  // Get the event collection
144  // FIXME should be using Read/WriteHandles here
145  McEventCollection* eventCollection = nullptr;
146  StatusCode sc = evtStore()->retrieve(eventCollection, m_genEventKey);
147  if (sc.isFailure() || eventCollection == 0) {
148  ATH_MSG_ERROR("Unable to retrieve event collection from StoreGate with key " << m_genEventKey);
149  return StatusCode::FAILURE;
150  } else {
151  ATH_MSG_DEBUG("Retrieved event collection from StoreGate with key " << m_genEventKey);
152  }
153 
154  // Get the event most recently added to the event collection
155  HepMC::GenEvent *event = eventCollection->back();
156  if(event == 0) {
157  ATH_MSG_ERROR("Photospp_i received a null HepMC event");
158  return StatusCode::FAILURE;
159  }
160  switch(event->momentum_unit()) {
161 #ifdef HEPMC3
163  Photos::setMomentumUnit(Photos::GEV);
164  Photos::forceMass(11, 0.000510998910);
165  break;
166  case HepMC3::Units::MomentumUnit::MEV:
167  Photos::setMomentumUnit(Photos::MEV);
168  Photos::forceMass(11, 0.510998910);
169  break;
170 #else
171  case HepMC::Units::GEV:
172  Photos::setMomentumUnit(Photos::GEV);
173  Photos::forceMass(11, 0.000510998910);
174  break;
175  case HepMC::Units::MEV:
176  Photos::setMomentumUnit(Photos::MEV);
177  Photos::forceMass(11, 0.510998910);
178  break;
179 #endif
180  default:
181  ATH_MSG_ERROR("Photospp_i received a event with unknown units.");
182  Photos::setMomentumUnit(Photos::DEFAULT_MOMENTUM);
183  break;
184  };
185  PhotosHepMCEvent photosEvent(event);
186  photosEvent.process();
187 
188  return StatusCode::SUCCESS;
189 }
Photospp_i::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
Definition: Photospp_i.cxx:104
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
Photospp_i::getRandomEngineDuringInitialize
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
Definition: Photospp_i.cxx:113
initialize
void initialize()
Definition: run_EoverP.cxx:894
McEventCollection
McEventCollection
Definition: GeneratorObjectsTPCnv.cxx:60
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
McEventCollection.h
Photospp_i::Photospp_i
Photospp_i(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena algorithm constructor.
Definition: Photospp_i.cxx:39
Atlas::ExtendedEventContext
Definition: ExtendedEventContext.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
GEV
#define GEV
Definition: PrintPhotonSF.cxx:24
Photospp_i.h
AthAlgorithm
Definition: AthAlgorithm.h:47
phoranc_
double phoranc_(int *idum)
Definition: Photospp_i.cxx:33
Photospp_i::initialize
StatusCode initialize()
Initialise the Photospp_i algorithm and required services.
Definition: Photospp_i.cxx:44
Photospp_i::reseedRandomEngine
void reseedRandomEngine(const std::string &streamName, const EventContext &ctx)
Definition: Photospp_i.cxx:96
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
Photospp_i::setupPhotos
void setupPhotos()
Set up the Photos class This may be called in the initialize method or directly before the generation...
Definition: Photospp_i.cxx:55
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
Photospp_i::p_rndmEngine
static CLHEP::HepRandomEngine * p_rndmEngine
Definition: Photospp_i.h:39
Photospp_i::execute
StatusCode execute()
Run Photos on one event Will require a pre-existing HepMC event in Storegate.
Definition: Photospp_i.cxx:130
ATHRNG::calculateSeedsMC21
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.
Definition: RNGWrapper.cxx:37
ignore_unused_variable_warning
void ignore_unused_variable_warning(int *)
Definition: Photospp_i.cxx:31
Atlas::setExtendedEventContext
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
Definition: ExtendedEventContext.cxx:50
LB_AnalMapSplitter.lbn
lbn
Definition: LB_AnalMapSplitter.py:28