40 #include "Randomize.hh" 45 typedef std::vector<std::shared_ptr<SimProducer> >
Producers;
95 class StaticRandomEngineSetUnset {
98 explicit StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine);
99 ~StaticRandomEngineSetUnset();
101 CLHEP::HepRandomEngine* currentEngine() {
return m_currentEngine; }
104 CLHEP::HepRandomEngine* m_currentEngine;
105 CLHEP::HepRandomEngine* m_previousEngine;
110 : m_handoff{
p.getUntrackedParameter<
int>(
"workerThreadStackSize", 10 * 1024 * 1024)}, m_psetID{
p.id()} {
111 m_verbose =
p.getParameter<
int>(
"EventVerbose");
113 StaticRandomEngineSetUnset random(
nullptr);
116 m_handoff.runAndWait([
this, &
p,
token]() {
118 StaticRandomEngineSetUnset random(
nullptr);
119 m_runManagerWorker = std::make_unique<RunManagerMTWorker>(
p, consumesCollector());
121 m_masterThread = ms ? ms : s_masterThread;
123 m_masterThread->callConsumes(consumesCollector());
126 produces<edm::SimTrackContainer>().setBranchAlias(
"SimTracks");
127 produces<edm::SimVertexContainer>().setBranchAlias(
"SimVertices");
128 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelLowTof");
129 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelHighTof");
130 produces<edm::PSimHitContainer>(
"TrackerHitsTIBLowTof");
131 produces<edm::PSimHitContainer>(
"TrackerHitsTIBHighTof");
132 produces<edm::PSimHitContainer>(
"TrackerHitsTIDLowTof");
133 produces<edm::PSimHitContainer>(
"TrackerHitsTIDHighTof");
134 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapLowTof");
135 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapHighTof");
136 produces<edm::PSimHitContainer>(
"TrackerHitsTOBLowTof");
137 produces<edm::PSimHitContainer>(
"TrackerHitsTOBHighTof");
138 produces<edm::PSimHitContainer>(
"TrackerHitsTECLowTof");
139 produces<edm::PSimHitContainer>(
"TrackerHitsTECHighTof");
141 produces<edm::PSimHitContainer>(
"TotemHitsT1");
142 produces<edm::PSimHitContainer>(
"TotemHitsT2Gem");
143 produces<edm::PSimHitContainer>(
"TotemHitsRP");
144 produces<edm::PSimHitContainer>(
"CTPPSPixelHits");
145 produces<edm::PSimHitContainer>(
"CTPPSTimingHits");
146 produces<edm::PSimHitContainer>(
"FP420SI");
147 produces<edm::PSimHitContainer>(
"BSCHits");
148 produces<edm::PSimHitContainer>(
"PLTHits");
149 produces<edm::PSimHitContainer>(
"BCM1FHits");
150 produces<edm::PSimHitContainer>(
"BHMHits");
151 produces<edm::PSimHitContainer>(
"FastTimerHitsBarrel");
152 produces<edm::PSimHitContainer>(
"FastTimerHitsEndcap");
154 produces<edm::PCaloHitContainer>(
"EcalHitsEB");
155 produces<edm::PCaloHitContainer>(
"EcalHitsEE");
156 produces<edm::PCaloHitContainer>(
"EcalHitsES");
157 produces<edm::PCaloHitContainer>(
"HcalHits");
158 produces<edm::PCaloHitContainer>(
"CaloHitsTk");
159 produces<edm::PCaloHitContainer>(
"HGCHitsEE");
160 produces<edm::PCaloHitContainer>(
"HGCHitsHEfront");
161 produces<edm::PCaloHitContainer>(
"HGCHitsHEback");
163 produces<edm::PSimHitContainer>(
"MuonDTHits");
164 produces<edm::PSimHitContainer>(
"MuonCSCHits");
165 produces<edm::PSimHitContainer>(
"MuonRPCHits");
166 produces<edm::PSimHitContainer>(
"MuonGEMHits");
167 produces<edm::PSimHitContainer>(
"MuonME0Hits");
168 produces<edm::PCaloHitContainer>(
"CastorPL");
169 produces<edm::PCaloHitContainer>(
"CastorFI");
170 produces<edm::PCaloHitContainer>(
"CastorBU");
171 produces<edm::PCaloHitContainer>(
"CastorTU");
172 produces<edm::PCaloHitContainer>(
"EcalTBH4BeamHits");
173 produces<edm::PCaloHitContainer>(
"HcalTB06BeamHits");
174 produces<edm::PCaloHitContainer>(
"ZDCHITS");
175 produces<edm::PCaloHitContainer>(
"ChamberHits");
176 produces<edm::PCaloHitContainer>(
"FibreHits");
177 produces<edm::PCaloHitContainer>(
"WedgeHits");
178 produces<edm::PCaloHitContainer>(
"HFNoseHits");
179 produces<edm::PCaloHitContainer>(
"TotemHitsT2Scint");
182 auto&
producers = m_runManagerWorker->producers();
184 ptr->registerProducts(producesCollector());
186 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer is constructed";
199 StaticRandomEngineSetUnset random(
nullptr);
200 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::initializeGlobalCache";
202 auto ret = std::make_unique<OscarMTMasterThread>(iConfig);
214 StaticRandomEngineSetUnset random(
nullptr);
215 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun";
219 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun done";
220 return std::shared_ptr<int>();
224 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndRun";
225 if (
nullptr != iContext->
global()) {
226 iContext->
global()->endRun();
231 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndJob";
240 <<
"At least two different OscarMTProducer instances have been" 241 "loaded into the job and they have different configurations.\n" 242 " All OscarMTProducers in a job must have exactly the same configuration.";
245 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun threadID=" <<
id;
252 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun done threadID=" <<
id;
256 StaticRandomEngineSetUnset random(
nullptr);
258 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun threadID=" <<
id;
264 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun done threadID=" <<
id;
268 StaticRandomEngineSetUnset random(
e.streamID());
269 auto engine = random.currentEngine();
273 <<
"Produce event " <<
e.id() <<
" stream " <<
e.streamID() <<
" threadID=" <<
id;
284 StaticRandomEngineSetUnset random(engine);
294 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p2->size() <<
" SimVertex objects";
297 for (
int i = 0;
i <
nn; ++
i) {
301 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p1->size() <<
" SimTrack objects";
304 for (
int i = 0;
i <
nn; ++
i) {
305 edm::LogVerbatim(
"Track") <<
" " <<
i <<
". " << (*p1)[
i] <<
" " << (*p1)[
i].crossedBoundary() <<
" " 306 << (*p1)[
i].getIDAtBoundary();
314 const std::vector<std::string>&
v =
tracker->getNames();
315 for (
auto&
name :
v) {
318 if (0 <
m_verbose && product !=
nullptr && !product->empty())
319 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" tracker hits <" <<
name <<
">";
323 for (
auto&
calo : sCalo) {
324 const std::vector<std::string>&
v =
calo->getNames();
325 for (
auto&
name :
v) {
328 if (0 <
m_verbose && product !=
nullptr && !product->empty())
329 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" calo hits <" <<
name <<
">";
336 prod.get()->produce(
e, es);
340 <<
"Event is produced event " <<
e.id() <<
" streamID=" <<
e.streamID() <<
" threadID=" <<
id;
345 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(
edm::StreamID const& streamID) {
349 <<
"The OscarMTProducer module requires the RandomNumberGeneratorService\n" 350 "which is not present in the configuration file. You must add the service\n" 351 "in the configuration file if you want to run OscarMTProducer";
353 m_currentEngine = &(rng->
getEngine(streamID));
355 m_previousEngine = G4Random::getTheEngine();
356 G4Random::setTheEngine(m_currentEngine);
359 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine) {
360 m_currentEngine = engine;
361 m_previousEngine = G4Random::getTheEngine();
362 G4Random::setTheEngine(m_currentEngine);
365 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
ret
prodAgent to be discontinued
OscarMTProducer(edm::ParameterSet const &p, const OscarMTMasterThread *)
void beginRun(const edm::EventSetup &iSetup) const
~OscarMTProducer() override
std::vector< std::shared_ptr< SimProducer > > Producers
static edm::ParameterSetID s_psetID
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void load(edm::SimTrackContainer &c) const
static const OscarMTMasterThread * s_masterThread
RunManagerMT & runManagerMaster() const
ParameterSetID id() const
const OscarMTMasterThread * m_masterThread
const edm::ParameterSetID m_psetID
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