Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-20 01:53:49

0001 #ifndef SimG4Core_RunManagerMT_H
0002 #define SimG4Core_RunManagerMT_H
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "SimG4Core/Geometry/interface/SensitiveDetectorCatalog.h"
0008 #include "SimG4Core/Notification/interface/SimActivityRegistry.h"
0009 
0010 #include <memory>
0011 
0012 class PrimaryTransformer;
0013 class Generator;
0014 class PhysicsList;
0015 class CustomUIsession;
0016 
0017 class SimWatcher;
0018 class SimProducer;
0019 class G4SimEvent;
0020 class G4LogicalVolume;
0021 
0022 class RunAction;
0023 
0024 class DDCompactView;
0025 
0026 namespace cms {
0027   class DDCompactView;
0028 }
0029 
0030 class DDDWorld;
0031 
0032 class G4MTRunManagerKernel;
0033 class G4Run;
0034 class G4Event;
0035 class G4StateManager;
0036 class RunAction;
0037 
0038 class SimRunInterface;
0039 
0040 namespace HepPDT {
0041   class ParticleDataTable;
0042 }
0043 
0044 /**
0045  * RunManagerMT should be constructed in a newly spanned thread
0046  * (acting as the Geant4 master thread), and there should be exactly
0047  * one instance of it. 
0048  */
0049 class RunManagerMTWorker;
0050 
0051 class RunManagerMT {
0052   friend class RunManagerMTWorker;
0053 
0054 public:
0055   explicit RunManagerMT(edm::ParameterSet const&);
0056   ~RunManagerMT();
0057 
0058   void initG4(const DDCompactView*, const cms::DDCompactView*, const HepPDT::ParticleDataTable*);
0059 
0060   void initializeUserActions();
0061 
0062   void stopG4();
0063 
0064   void Connect(RunAction*);
0065 
0066   // Keep this to keep ExceptionHandler to compile, probably removed
0067   // later (or functionality moved to RunManagerMTWorker).
0068   //  inline void abortRun(bool softAbort = false) {}
0069 
0070   inline const DDDWorld& world() const { return *m_world; }
0071 
0072   inline const SensitiveDetectorCatalog& catalog() const { return m_catalog; }
0073 
0074   inline const std::vector<std::string>& G4Commands() const { return m_G4Commands; }
0075 
0076   // In order to share the physics list with the worker threads, we
0077   // need a non-const pointer. Thread-safety is handled inside Geant4.
0078   inline PhysicsList* physicsListForWorker() const { return m_physicsList.get(); }
0079 
0080   inline bool isPhase2() const { return m_isPhase2; }
0081 
0082 private:
0083   void terminateRun();
0084 
0085   void checkVoxels();
0086 
0087   void setupVoxels();
0088 
0089   void runForPhase2();
0090 
0091   void addRegions();
0092 
0093   void addG4Region(const std::vector<G4LogicalVolume*>&,
0094                    const std::string& regName,
0095                    double cutg,
0096                    double cute,
0097                    double cutp,
0098                    double cuti);
0099 
0100   G4MTRunManagerKernel* m_kernel;
0101 
0102   CustomUIsession* m_UIsession;
0103   std::unique_ptr<PhysicsList> m_physicsList;
0104   bool m_managerInitialized{false};
0105   bool m_runTerminated{false};
0106   RunAction* m_userRunAction{nullptr};
0107   G4Run* m_currentRun{nullptr};
0108   G4StateManager* m_stateManager;
0109 
0110   std::unique_ptr<SimRunInterface> m_runInterface;
0111 
0112   const std::string m_PhysicsTablesDir;
0113   bool m_StorePhysicsTables;
0114   bool m_RestorePhysicsTables;
0115   bool m_check;
0116   bool m_geoFromDD4hep;
0117   bool m_score;
0118   bool m_isPhase2{false};
0119   int m_stepverb;
0120   std::string m_regionFile{""};
0121   edm::ParameterSet m_pPhysics;
0122   edm::ParameterSet m_pRunAction;
0123   edm::ParameterSet m_CheckOverlap;
0124   edm::ParameterSet m_Init;
0125   std::vector<std::string> m_G4Commands;
0126 
0127   std::unique_ptr<DDDWorld> m_world;
0128   SimActivityRegistry m_registry;
0129   SensitiveDetectorCatalog m_catalog;
0130 };
0131 
0132 #endif