File indexing completed on 2024-12-01 23:40:41
0001 #ifndef SimG4Core_Application_RunManagerMTWorker_H
0002 #define SimG4Core_Application_RunManagerMTWorker_H
0003
0004 #include "FWCore/Utilities/interface/EDGetToken.h"
0005
0006 #include "DataFormats/Provenance/interface/RunID.h"
0007 #include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"
0008
0009 #include "SimG4Core/Generators/interface/Generator.h"
0010 #include "SimG4Core/Generators/interface/Generator3.h"
0011 #include "SimG4Core/Notification/interface/TmpSimEvent.h"
0012
0013 #include "MagneticField/Engine/interface/MagneticField.h"
0014 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0015
0016 #include <memory>
0017 #include <unordered_map>
0018 #include <string>
0019
0020 namespace edm {
0021 class ParameterSet;
0022 class Event;
0023 class EventSetup;
0024 class ConsumesCollector;
0025 class HepMCProduct;
0026 class HepMC3Product;
0027 }
0028
0029 class Generator;
0030 class RunManagerMT;
0031
0032 class G4Event;
0033 class G4Run;
0034 class SimTrackManager;
0035 class CustomUIsession;
0036
0037 class RunAction;
0038 class EventAction;
0039 class TrackingAction;
0040 class SteppingAction;
0041 class Phase2SteppingAction;
0042 class CMSSteppingVerbose;
0043 class CMSSimEventManager;
0044 class G4Field;
0045
0046 class SensitiveTkDetector;
0047 class SensitiveCaloDetector;
0048 class SensitiveDetectorMakerBase;
0049
0050 class SimWatcher;
0051 class SimProducer;
0052
0053 class RunManagerMTWorker {
0054 public:
0055 explicit RunManagerMTWorker(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC);
0056 ~RunManagerMTWorker();
0057
0058 void beginRun(const edm::EventSetup&);
0059 void endRun();
0060
0061 TmpSimEvent* produce(const edm::Event& inpevt, const edm::EventSetup& es, RunManagerMT& runManagerMaster);
0062
0063 void abortEvent();
0064 void abortRun(bool softAbort = false);
0065
0066 void Connect(RunAction*);
0067 void Connect(EventAction*);
0068 void Connect(TrackingAction*);
0069 void Connect(SteppingAction*);
0070 void Connect(Phase2SteppingAction*);
0071
0072 SimTrackManager* getSimTrackManager();
0073 std::vector<SensitiveTkDetector*>& sensTkDetectors();
0074 std::vector<SensitiveCaloDetector*>& sensCaloDetectors();
0075 std::vector<std::shared_ptr<SimProducer>>& producers();
0076
0077 void initializeG4(RunManagerMT* runManagerMaster, const edm::EventSetup& es);
0078
0079 inline TmpSimEvent* simEvent() { return &m_simEvent; }
0080 inline int getThreadIndex() const { return m_thread_index; }
0081
0082 private:
0083 void initializeTLS();
0084 void initializeUserActions();
0085 void initializeRun();
0086 void terminateRun();
0087
0088 G4Event* generateEvent(const edm::Event& inpevt);
0089 void resetGenParticleId(const edm::Event& inpevt);
0090
0091 void DumpMagneticField(const G4Field*, const std::string&) const;
0092
0093 Generator m_generator;
0094 Generator3 m_generator3;
0095 edm::EDGetTokenT<edm::HepMCProduct> m_InToken;
0096 edm::EDGetTokenT<edm::HepMC3Product> m_InToken3;
0097 edm::EDGetTokenT<edm::HepMCProduct> m_LHCToken;
0098 edm::EDGetTokenT<edm::LHCTransportLinkContainer> m_theLHCTlinkToken;
0099 edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> m_MagField;
0100 const MagneticField* m_pMagField{nullptr};
0101
0102 bool m_nonBeam{false};
0103 bool m_UseG4EventManager{true};
0104 bool m_pUseMagneticField{true};
0105 bool m_hasWatchers{false};
0106 bool m_LHCTransport{false};
0107 bool m_dumpMF{false};
0108 bool m_dumpGDML{false};
0109 bool m_endOfRun{false};
0110 bool m_isPhase2{false};
0111
0112 const int m_thread_index{-1};
0113
0114 edm::ParameterSet m_pField;
0115 edm::ParameterSet m_pRunAction;
0116 edm::ParameterSet m_pEventAction;
0117 edm::ParameterSet m_pStackingAction;
0118 edm::ParameterSet m_pTrackingAction;
0119 edm::ParameterSet m_pSteppingAction;
0120 std::vector<std::string> m_G4Commands;
0121 std::vector<std::string> m_G4CommandsEndRun;
0122 edm::ParameterSet m_p;
0123
0124 struct TLSData;
0125 TLSData* m_tls{nullptr};
0126
0127 CustomUIsession* m_UIsession{nullptr};
0128 TmpSimEvent m_simEvent;
0129 std::unique_ptr<CMSSimEventManager> m_evtManager;
0130 std::unique_ptr<CMSSteppingVerbose> m_sVerbose;
0131 std::unordered_map<std::string, std::unique_ptr<SensitiveDetectorMakerBase>> m_sdMakers;
0132 };
0133
0134 #endif