Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:18:42

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef G4MAIN_PHG4RECO_H
0004 #define G4MAIN_PHG4RECO_H
0005 
0006 #include <g4decayer/EDecayType.hh>
0007 
0008 #include <fun4all/SubsysReco.h>
0009 
0010 #include <phfield/PHFieldConfig.h>
0011 
0012 #include <list>
0013 #include <string>  // for string
0014 
0015 // Forward declerations
0016 class G4RunManager;
0017 class G4TBMagneticFieldSetup;
0018 class G4UImanager;
0019 class G4UImessenger;
0020 class G4VisManager;
0021 class PHCompositeNode;
0022 class PHG4DisplayAction;
0023 class PHG4PhenixDetector;
0024 class PHG4PhenixEventAction;
0025 class PHG4PhenixStackingAction;
0026 class PHG4PhenixSteppingAction;
0027 class PHG4PhenixTrackingAction;
0028 class PHG4PrimaryGeneratorAction;
0029 class PHG4Subsystem;
0030 class PHG4UIsession;
0031 
0032 /*!
0033   \class   PHG4Reco
0034   \ingroup supermodules
0035   \brief   Runs G4 as a subsystem
0036 */
0037 class PHG4Reco : public SubsysReco
0038 {
0039  public:
0040   enum DecayerOptions
0041   {
0042     kGEANTInternalDecayer = 0,
0043     kPYTHIA6Decayer = 1,
0044     kEvtGenDecayer = 2,
0045 
0046   };  // Decayer Option for User to Choose: 0 - GEANT 4 Internal Decayer (with momentum conservation issues), 1, PYTHIA 6 Decayer, 2 - EvtGen Decayer
0047 
0048   //! constructor
0049   explicit PHG4Reco(const std::string &name = "PHG4RECO");
0050 
0051   //! destructor
0052   ~PHG4Reco() override;
0053 
0054   //! full initialization
0055   int Init(PHCompositeNode *) override;
0056 
0057   int InitRun(PHCompositeNode *topNode) override;
0058 
0059   //! event processing method
0060   int process_event(PHCompositeNode *) override;
0061 
0062   //! Clean up after each event.
0063   int ResetEvent(PHCompositeNode *) override;
0064 
0065   //! print info
0066   void Print(const std::string &what = std::string()) const override;
0067 
0068   //! register subsystem
0069   void registerSubsystem(PHG4Subsystem *subsystem)
0070   {
0071     m_SubsystemList.push_back(subsystem);
0072   }
0073 
0074   //! interface to G4 cmd interpreter
0075   int ApplyCommand(const std::string &cmd);
0076 
0077   //! start the gui
0078   int StartGui();
0079 
0080   int InitField(PHCompositeNode *topNode);
0081 
0082   //! set default magnetic field strength with a constant magnetic field. Only valid if set_field_map() is not used. If available, Field map setting on DST take higher priority.
0083   void set_field(const float tesla)
0084   {
0085     m_MagneticField = tesla;
0086   }
0087 
0088   //! Set default field map. If available, Field map setting on DST take higher priority.
0089   //! \param[in] fmap  Field map ROOT file
0090   //! \param[in] dim   Field map format. See PHFieldConfig::FieldConfigTypes for available formats.
0091   void set_field_map(const std::string &fmap, const PHFieldConfig::FieldConfigTypes dim)
0092   {
0093     m_FieldMapFile = fmap;
0094     m_FieldConfigType = dim;
0095   }
0096 
0097   //! set default scaling factor for input magnetic field map. If available, Field map setting on DST take higher priority.
0098   void set_field_rescale(const float rescale) { m_MagneticFieldRescale = rescale; }
0099 
0100   void set_force_decay(EDecayType force_decay_type)
0101   {
0102     m_ActiveForceDecayFlag = true;
0103     m_ForceDecayType = force_decay_type;
0104   }
0105 
0106   void set_decayer(DecayerOptions type) { m_Decayer = type; }
0107 
0108   //! export geometry to root file
0109   void export_geometry(bool b, const std::string &filename = "sPHENIXGeom.root")
0110   {
0111     m_ExportGeometry = b;
0112     m_ExportGeomFilename = filename;
0113   }
0114 
0115   //! Save geometry from Geant4 to DST
0116   void save_DST_geometry(bool b) { m_SaveDstGeometryFlag = b; }
0117   void SetWorldSizeX(const double sx) { m_WorldSize[0] = sx; }
0118   void SetWorldSizeY(const double sy) { m_WorldSize[1] = sy; }
0119   void SetWorldSizeZ(const double sz) { m_WorldSize[2] = sz; }
0120   double GetWorldSizeX() const { return m_WorldSize[0]; }
0121   double GetWorldSizeY() const { return m_WorldSize[1]; }
0122   double GetWorldSizeZ() const { return m_WorldSize[2]; }
0123   void SetWorldShape(const std::string &s) { m_WorldShape = s; }
0124   void SetWorldMaterial(const std::string &s) { m_WorldMaterial = s; }
0125   void SetPhysicsList(const std::string &s) { m_PhysicsList = s; }
0126   void set_rapidity_coverage(const double eta);
0127 
0128   int setupInputEventNodeReader(PHCompositeNode *);
0129 
0130   static void G4Seed(const unsigned int i);
0131 
0132   PHG4Subsystem *getSubsystem(const std::string &name);
0133   PHG4DisplayAction *GetDisplayAction() { return m_DisplayAction; }
0134   void Dump_GDML(const std::string &filename);
0135   void Dump_G4_GDML(const std::string &filename);
0136 
0137   void G4Verbosity(const int i);
0138 
0139   //! disable event/track/stepping actions to reduce resource consumption for G4 running only. E.g. dose analysis
0140   void setDisableUserActions(bool b = true) { m_disableUserActions = b; }
0141   void ApplyDisplayAction();
0142 
0143   void CustomizeEvtGenDecay(const std::string &DecayFile)
0144   {
0145     EvtGenDecayFile = DecayFile;
0146     if (!EvtGenDecayFile.empty()) CustomizeDecay = true;
0147   }
0148 
0149  private:
0150   static void g4guithread(void *ptr);
0151   int InitUImanager();
0152   void DefineMaterials();
0153   void DefineRegions();
0154 
0155   float m_MagneticField{std::numeric_limits<float>::signaling_NaN()};
0156   float m_MagneticFieldRescale = 1.0;
0157   double m_WorldSize[3]{1000., 1000., 1000.};
0158 
0159   //! magnetic field
0160   G4TBMagneticFieldSetup *m_Field = nullptr;
0161 
0162   //! pointer to geant run manager
0163   G4RunManager *m_RunManager = nullptr;
0164 
0165   //! pointer to geant ui session
0166   PHG4UIsession *m_UISession = nullptr;
0167 
0168   //! pointer to detector
0169   PHG4PhenixDetector *m_Detector = nullptr;
0170 
0171   //! pointer to main event action
0172   PHG4PhenixEventAction *m_EventAction = nullptr;
0173 
0174   //! pointer to main stacking action
0175   PHG4PhenixStackingAction *m_StackingAction = nullptr;
0176 
0177   //! pointer to main stepping action
0178   PHG4PhenixSteppingAction *m_SteppingAction = nullptr;
0179 
0180   //! pointer to main tracking action
0181   PHG4PhenixTrackingAction *m_TrackingAction = nullptr;
0182 
0183   //! display attribute setting
0184   /*! derives from PHG4DisplayAction */
0185   PHG4DisplayAction *m_DisplayAction = nullptr;
0186 
0187   //! event generator (read from PHG4INEVENT node)
0188   PHG4PrimaryGeneratorAction *m_GeneratorAction = nullptr;
0189 
0190   //! list of subsystems
0191   std::list<PHG4Subsystem *> m_SubsystemList;
0192 
0193   // visualization
0194   G4VisManager *m_VisManager = nullptr;
0195 
0196   // Message interface to Fun4All
0197   G4UImessenger *m_Fun4AllMessenger = nullptr;
0198 
0199   // for the G4 cmd line interface
0200   G4UImanager *m_UImanager = nullptr;
0201   double m_EtaCoverage = 1.0;
0202   PHFieldConfig::FieldConfigTypes m_FieldConfigType = PHFieldConfig::kFieldUniform;
0203   std::string m_FieldMapFile = "NONE";
0204   std::string m_WorldShape = "G4Tubs";
0205   std::string m_WorldMaterial = "G4_AIR";
0206   std::string m_PhysicsList = "FTFP_BERT";
0207 
0208   bool m_ExportGeometry = false;
0209   std::string m_ExportGeomFilename = "sPHENIXGeom.root";
0210 
0211   // settings for the external Pythia6 decayer
0212   // bool m_ActiveDecayerFlag = true;     //< turn on/off decayer
0213   bool m_ActiveForceDecayFlag = false;  //< turn on/off force decay channels
0214 
0215   DecayerOptions m_Decayer = kEvtGenDecayer;  // Here we use EvtGen as default
0216   std::string EvtGenDecayFile = "";
0217   bool CustomizeDecay = false;
0218 
0219   EDecayType m_ForceDecayType = kAll;  //< forced decay channel setting
0220 
0221   bool m_SaveDstGeometryFlag = true;
0222   bool m_disableUserActions = false;
0223 };
0224 
0225 #endif