Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:04:20

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