38 #include "Randomize.hh" 43 typedef std::vector<std::shared_ptr<SimProducer> >
Producers;
86 class StaticRandomEngineSetUnset {
89 explicit StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine);
90 ~StaticRandomEngineSetUnset();
92 CLHEP::HepRandomEngine* currentEngine() {
return m_currentEngine; }
95 CLHEP::HepRandomEngine* m_currentEngine;
96 CLHEP::HepRandomEngine* m_previousEngine;
101 : m_handoff{
p.getUntrackedParameter<
int>(
"workerThreadStackSize", 10 * 1024 * 1024)} {
103 StaticRandomEngineSetUnset random(
nullptr);
106 m_handoff.runAndWait([
this, &
p,
token]() {
108 StaticRandomEngineSetUnset random(
nullptr);
109 m_runManagerWorker = std::make_unique<RunManagerMTWorker>(
p, consumesCollector());
112 m_masterThread->callConsumes(consumesCollector());
115 produces<edm::SimTrackContainer>().setBranchAlias(
"SimTracks");
116 produces<edm::SimVertexContainer>().setBranchAlias(
"SimVertices");
117 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelLowTof");
118 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelHighTof");
119 produces<edm::PSimHitContainer>(
"TrackerHitsTIBLowTof");
120 produces<edm::PSimHitContainer>(
"TrackerHitsTIBHighTof");
121 produces<edm::PSimHitContainer>(
"TrackerHitsTIDLowTof");
122 produces<edm::PSimHitContainer>(
"TrackerHitsTIDHighTof");
123 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapLowTof");
124 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapHighTof");
125 produces<edm::PSimHitContainer>(
"TrackerHitsTOBLowTof");
126 produces<edm::PSimHitContainer>(
"TrackerHitsTOBHighTof");
127 produces<edm::PSimHitContainer>(
"TrackerHitsTECLowTof");
128 produces<edm::PSimHitContainer>(
"TrackerHitsTECHighTof");
130 produces<edm::PSimHitContainer>(
"TotemHitsT1");
131 produces<edm::PSimHitContainer>(
"TotemHitsT2Gem");
132 produces<edm::PSimHitContainer>(
"TotemHitsRP");
133 produces<edm::PSimHitContainer>(
"CTPPSPixelHits");
134 produces<edm::PSimHitContainer>(
"CTPPSTimingHits");
135 produces<edm::PSimHitContainer>(
"FP420SI");
136 produces<edm::PSimHitContainer>(
"BSCHits");
137 produces<edm::PSimHitContainer>(
"PLTHits");
138 produces<edm::PSimHitContainer>(
"BCM1FHits");
139 produces<edm::PSimHitContainer>(
"BHMHits");
140 produces<edm::PSimHitContainer>(
"FastTimerHitsBarrel");
141 produces<edm::PSimHitContainer>(
"FastTimerHitsEndcap");
143 produces<edm::PCaloHitContainer>(
"EcalHitsEB");
144 produces<edm::PCaloHitContainer>(
"EcalHitsEE");
145 produces<edm::PCaloHitContainer>(
"EcalHitsES");
146 produces<edm::PCaloHitContainer>(
"HcalHits");
147 produces<edm::PCaloHitContainer>(
"CaloHitsTk");
148 produces<edm::PCaloHitContainer>(
"HGCHitsEE");
149 produces<edm::PCaloHitContainer>(
"HGCHitsHEfront");
150 produces<edm::PCaloHitContainer>(
"HGCHitsHEback");
152 produces<edm::PSimHitContainer>(
"MuonDTHits");
153 produces<edm::PSimHitContainer>(
"MuonCSCHits");
154 produces<edm::PSimHitContainer>(
"MuonRPCHits");
155 produces<edm::PSimHitContainer>(
"MuonGEMHits");
156 produces<edm::PSimHitContainer>(
"MuonME0Hits");
157 produces<edm::PCaloHitContainer>(
"CastorPL");
158 produces<edm::PCaloHitContainer>(
"CastorFI");
159 produces<edm::PCaloHitContainer>(
"CastorBU");
160 produces<edm::PCaloHitContainer>(
"CastorTU");
161 produces<edm::PCaloHitContainer>(
"EcalTBH4BeamHits");
162 produces<edm::PCaloHitContainer>(
"HcalTB06BeamHits");
163 produces<edm::PCaloHitContainer>(
"ZDCHITS");
164 produces<edm::PCaloHitContainer>(
"ChamberHits");
165 produces<edm::PCaloHitContainer>(
"FibreHits");
166 produces<edm::PCaloHitContainer>(
"WedgeHits");
167 produces<edm::PCaloHitContainer>(
"HFNoseHits");
168 produces<edm::PCaloHitContainer>(
"TotemHitsT2Scint");
171 auto&
producers = m_runManagerWorker->producers();
173 ptr->registerProducts(producesCollector());
175 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer is constructed";
188 StaticRandomEngineSetUnset random(
nullptr);
189 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::initializeGlobalCache";
191 return std::make_unique<OscarMTMasterThread>(iConfig);
198 StaticRandomEngineSetUnset random(
nullptr);
199 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun";
201 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun done";
202 return std::shared_ptr<int>();
206 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndRun";
207 iContext->
global()->endRun();
211 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndJob";
223 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun done";
228 StaticRandomEngineSetUnset random(
nullptr);
232 StaticRandomEngineSetUnset random(
nullptr);
240 StaticRandomEngineSetUnset random(
e.streamID());
241 auto engine = random.currentEngine();
242 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produce event " <<
e.id() <<
" stream " <<
e.streamID();
248 std::unique_ptr<G4SimEvent> evt;
252 StaticRandomEngineSetUnset random(engine);
265 const std::vector<std::string>&
v =
tracker->getNames();
266 for (
auto&
name :
v) {
269 if (product !=
nullptr && !product->empty())
270 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" tracker hits <" <<
name <<
">";
274 for (
auto&
calo : sCalo) {
275 const std::vector<std::string>&
v =
calo->getNames();
276 for (
auto&
name :
v) {
279 if (product !=
nullptr && !product->empty())
280 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" calo hits <" <<
name <<
">";
287 prod.get()->produce(
e, es);
289 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Event is produced " <<
e.id() <<
" stream " <<
e.streamID();
293 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(
edm::StreamID const& streamID) {
297 <<
"The OscarMTProducer module requires the RandomNumberGeneratorService\n" 298 "which is not present in the configuration file. You must add the service\n" 299 "in the configuration file if you want to run OscarMTProducer";
301 m_currentEngine = &(rng->
getEngine(streamID));
303 m_previousEngine = G4Random::getTheEngine();
304 G4Random::setTheEngine(m_currentEngine);
307 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine) {
308 m_currentEngine = engine;
309 m_previousEngine = G4Random::getTheEngine();
310 G4Random::setTheEngine(m_currentEngine);
313 StaticRandomEngineSetUnset::~StaticRandomEngineSetUnset() { G4Random::setTheEngine(m_previousEngine); }
Log< level::Info, true > LogVerbatim
RunManagerMT * runManagerMasterPtr() const
std::vector< PCaloHit > PCaloHitContainer
static std::shared_ptr< int > globalBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup, const OscarMTMasterThread *masterThread)
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
#define DEFINE_FWK_MODULE(type)
OscarMTProducer(edm::ParameterSet const &p, const OscarMTMasterThread *)
void beginRun(const edm::EventSetup &iSetup) const
~OscarMTProducer() override
std::vector< std::shared_ptr< SimProducer > > Producers
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const OscarMTMasterThread * m_masterThread
static ServiceRegistry & instance()
void produce(edm::Event &e, const edm::EventSetup &c) override
static void globalEndRun(const edm::Run &iRun, const edm::EventSetup &iSetup, const RunContext *iContext)
static std::unique_ptr< OscarMTMasterThread > initializeGlobalCache(const edm::ParameterSet &iConfig)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< SimVertex > SimVertexContainer
std::vector< PSimHit > PSimHitContainer
omt::ThreadHandoff m_handoff
static void globalEndJob(OscarMTMasterThread *masterThread)
std::vector< SimTrack > SimTrackContainer
ServiceToken presentToken() const
void beginRun(const edm::Run &r, const edm::EventSetup &c) override