Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-30 23:17:20

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