40 #include "Randomize.hh" 45 typedef std::vector<std::shared_ptr<SimProducer> >
Producers;
89 class StaticRandomEngineSetUnset {
92 explicit StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine);
93 ~StaticRandomEngineSetUnset();
95 CLHEP::HepRandomEngine* currentEngine() {
return m_currentEngine; }
98 CLHEP::HepRandomEngine* m_currentEngine;
99 CLHEP::HepRandomEngine* m_previousEngine;
104 : m_handoff{
p.getUntrackedParameter<
int>(
"workerThreadStackSize", 10 * 1024 * 1024)} {
105 m_verbose =
p.getParameter<
int>(
"EventVerbose");
107 StaticRandomEngineSetUnset random(
nullptr);
110 m_handoff.runAndWait([
this, &
p,
token]() {
112 StaticRandomEngineSetUnset random(
nullptr);
113 m_runManagerWorker = std::make_unique<RunManagerMTWorker>(
p, consumesCollector());
116 m_masterThread->callConsumes(consumesCollector());
119 produces<edm::SimTrackContainer>().setBranchAlias(
"SimTracks");
120 produces<edm::SimVertexContainer>().setBranchAlias(
"SimVertices");
121 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelLowTof");
122 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelHighTof");
123 produces<edm::PSimHitContainer>(
"TrackerHitsTIBLowTof");
124 produces<edm::PSimHitContainer>(
"TrackerHitsTIBHighTof");
125 produces<edm::PSimHitContainer>(
"TrackerHitsTIDLowTof");
126 produces<edm::PSimHitContainer>(
"TrackerHitsTIDHighTof");
127 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapLowTof");
128 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapHighTof");
129 produces<edm::PSimHitContainer>(
"TrackerHitsTOBLowTof");
130 produces<edm::PSimHitContainer>(
"TrackerHitsTOBHighTof");
131 produces<edm::PSimHitContainer>(
"TrackerHitsTECLowTof");
132 produces<edm::PSimHitContainer>(
"TrackerHitsTECHighTof");
134 produces<edm::PSimHitContainer>(
"TotemHitsT1");
135 produces<edm::PSimHitContainer>(
"TotemHitsT2Gem");
136 produces<edm::PSimHitContainer>(
"TotemHitsRP");
137 produces<edm::PSimHitContainer>(
"CTPPSPixelHits");
138 produces<edm::PSimHitContainer>(
"CTPPSTimingHits");
139 produces<edm::PSimHitContainer>(
"FP420SI");
140 produces<edm::PSimHitContainer>(
"BSCHits");
141 produces<edm::PSimHitContainer>(
"PLTHits");
142 produces<edm::PSimHitContainer>(
"BCM1FHits");
143 produces<edm::PSimHitContainer>(
"BHMHits");
144 produces<edm::PSimHitContainer>(
"FastTimerHitsBarrel");
145 produces<edm::PSimHitContainer>(
"FastTimerHitsEndcap");
147 produces<edm::PCaloHitContainer>(
"EcalHitsEB");
148 produces<edm::PCaloHitContainer>(
"EcalHitsEE");
149 produces<edm::PCaloHitContainer>(
"EcalHitsES");
150 produces<edm::PCaloHitContainer>(
"HcalHits");
151 produces<edm::PCaloHitContainer>(
"CaloHitsTk");
152 produces<edm::PCaloHitContainer>(
"HGCHitsEE");
153 produces<edm::PCaloHitContainer>(
"HGCHitsHEfront");
154 produces<edm::PCaloHitContainer>(
"HGCHitsHEback");
156 produces<edm::PSimHitContainer>(
"MuonDTHits");
157 produces<edm::PSimHitContainer>(
"MuonCSCHits");
158 produces<edm::PSimHitContainer>(
"MuonRPCHits");
159 produces<edm::PSimHitContainer>(
"MuonGEMHits");
160 produces<edm::PSimHitContainer>(
"MuonME0Hits");
161 produces<edm::PCaloHitContainer>(
"CastorPL");
162 produces<edm::PCaloHitContainer>(
"CastorFI");
163 produces<edm::PCaloHitContainer>(
"CastorBU");
164 produces<edm::PCaloHitContainer>(
"CastorTU");
165 produces<edm::PCaloHitContainer>(
"EcalTBH4BeamHits");
166 produces<edm::PCaloHitContainer>(
"HcalTB06BeamHits");
167 produces<edm::PCaloHitContainer>(
"ZDCHITS");
168 produces<edm::PCaloHitContainer>(
"ChamberHits");
169 produces<edm::PCaloHitContainer>(
"FibreHits");
170 produces<edm::PCaloHitContainer>(
"WedgeHits");
171 produces<edm::PCaloHitContainer>(
"HFNoseHits");
172 produces<edm::PCaloHitContainer>(
"TotemHitsT2Scint");
175 auto&
producers = m_runManagerWorker->producers();
177 ptr->registerProducts(producesCollector());
179 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer is constructed";
192 StaticRandomEngineSetUnset random(
nullptr);
193 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::initializeGlobalCache";
195 return std::make_unique<OscarMTMasterThread>(iConfig);
202 StaticRandomEngineSetUnset random(
nullptr);
203 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun";
205 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun done";
206 return std::shared_ptr<int>();
210 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndRun";
211 iContext->
global()->endRun();
215 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndJob";
221 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun threadID=" <<
id;
228 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun done threadID=" <<
id;
232 StaticRandomEngineSetUnset random(
nullptr);
234 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun threadID=" <<
id;
240 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun done threadID=" <<
id;
244 StaticRandomEngineSetUnset random(
e.streamID());
245 auto engine = random.currentEngine();
249 <<
"Produce event " <<
e.id() <<
" stream " <<
e.streamID() <<
" threadID=" <<
id;
260 StaticRandomEngineSetUnset random(engine);
270 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p2->size() <<
" SimVertex objects";
273 for (
int i = 0;
i <
nn; ++
i) {
277 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p1->size() <<
" SimTrack objects";
280 for (
int i = 0;
i <
nn; ++
i) {
281 edm::LogVerbatim(
"Track") <<
" " <<
i <<
". " << (*p1)[
i] <<
" " << (*p1)[
i].crossedBoundary() <<
" " 282 << (*p1)[
i].getIDAtBoundary();
290 const std::vector<std::string>&
v =
tracker->getNames();
291 for (
auto&
name :
v) {
294 if (0 <
m_verbose && product !=
nullptr && !product->empty())
295 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" tracker hits <" <<
name <<
">";
299 for (
auto&
calo : sCalo) {
300 const std::vector<std::string>&
v =
calo->getNames();
301 for (
auto&
name :
v) {
304 if (0 <
m_verbose && product !=
nullptr && !product->empty())
305 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" calo hits <" <<
name <<
">";
312 prod.get()->produce(
e, es);
316 <<
"Event is produced event " <<
e.id() <<
" streamID=" <<
e.streamID() <<
" threadID=" <<
id;
321 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(
edm::StreamID const& streamID) {
325 <<
"The OscarMTProducer module requires the RandomNumberGeneratorService\n" 326 "which is not present in the configuration file. You must add the service\n" 327 "in the configuration file if you want to run OscarMTProducer";
329 m_currentEngine = &(rng->
getEngine(streamID));
331 m_previousEngine = G4Random::getTheEngine();
332 G4Random::setTheEngine(m_currentEngine);
335 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine) {
336 m_currentEngine = engine;
337 m_previousEngine = G4Random::getTheEngine();
338 G4Random::setTheEngine(m_currentEngine);
341 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
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.
void load(edm::SimTrackContainer &c) const
const OscarMTMasterThread * m_masterThread
static ServiceRegistry & instance()
#define DEFINE_FWK_MODULE(type)
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