Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:46

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef G4DETECTORS_PHG4DETECTORGROUPSUBSYSTEM_H
0004 #define G4DETECTORS_PHG4DETECTORGROUPSUBSYSTEM_H
0005 
0006 #include <g4main/PHG4Subsystem.h>
0007 
0008 #include <map>
0009 #include <set>
0010 #include <string>
0011 #include <utility>  // for make_pair, pair
0012 
0013 class PHCompositeNode;
0014 class PHParametersContainer;
0015 
0016 class PHG4DetectorGroupSubsystem : public PHG4Subsystem
0017 {
0018  public:
0019   enum FILE_TYPE
0020   {
0021     none = 0,
0022     xml = 1,
0023     root = 2
0024   };
0025 
0026   ~PHG4DetectorGroupSubsystem() override = default;
0027   int Init(PHCompositeNode *) final;
0028   int InitRun(PHCompositeNode *) final;
0029 
0030   virtual int InitRunSubsystem(PHCompositeNode *)
0031   {
0032     return 0;
0033   }
0034   virtual int InitSubsystem(PHCompositeNode *) { return 0; }
0035   void OverlapCheck(const bool chk = true) { m_OverlapCheckFlag = chk; }
0036   bool CheckOverlap() const { return m_OverlapCheckFlag; }
0037   PHParametersContainer *GetParamsContainer() const { return m_ParamsContainer; }
0038   // Get/Set parameters from macro
0039   void set_double_param(const int detid, const std::string &name, const double dval);
0040   double get_double_param(const int detid, const std::string &name) const;
0041   void set_int_param(const int detid, const std::string &name, const int ival);
0042   int get_int_param(const int detid, const std::string &name) const;
0043   void set_string_param(const int detid, const std::string &name, const std::string &sval);
0044   std::string get_string_param(const int detid, const std::string &name) const;
0045 
0046   void UseDB(const int i = 1) { m_UseDBFlag = i; }
0047   int ReadDB() const { return m_UseDBFlag; }
0048   FILE_TYPE get_filetype() const { return m_FileType; }
0049   void UseCalibFiles(const FILE_TYPE ftyp) { m_FileType = ftyp; }
0050   int SaveParamsToFile(const FILE_TYPE ftyp);
0051   int ReadParamsFromFile(const std::string &name, const FILE_TYPE ftyp, const int issuper);
0052   void SetCalibrationFileDir(const std::string &calibdir) { m_CalibFileDir = calibdir; }
0053   void UpdateParametersWithMacro();
0054 
0055   void SetActive(const int detid, const int i);
0056   void SetActive(const int i = 1);
0057   void SetAbsorberActive(const int detid, const int i);
0058   void SetAbsorberActive(const int i = 1);
0059   void SetAbsorberTruth(const int detid, const int i);
0060   void SetAbsorberTruth(const int i = 1);
0061   void SetSupportActive(const int detid, const int i = 1);
0062   void SetSupportActive(const int i = 1);
0063 
0064   void BlackHole(const int detid, const int i);
0065   void BlackHole(const int i = 1);
0066   void SuperDetector(const std::string &name);
0067   const std::string &SuperDetector() const { return m_SuperDetector; }
0068   int GetLayer() const { return m_Layer; }
0069   virtual void SetDefaultParameters() = 0;  // this one has to be implemented by the daughter
0070 
0071  protected:  // those cannot be executed on the cmd line
0072   PHG4DetectorGroupSubsystem(const std::string &name = "GenericSubsystem", const int lyr = 0);
0073   // these initialize the defaults and add new entries to the
0074   // list of variables. This should not be possible from the macro to
0075   // prevent abuse (this makes the list of possible parameters deterministic)
0076   void InitializeParameters();
0077   void AddDetId(const int i) { m_LayerSet.insert(i); }
0078   std::pair<std::set<int>::const_iterator, std::set<int>::const_iterator> GetDetIds() const
0079   {
0080     return std::make_pair(m_LayerSet.begin(), m_LayerSet.end());
0081   }
0082   void set_default_double_param(const int detid, const std::string &name, const double dval);
0083   void set_default_int_param(const int detid, const std::string &name, const int ival);
0084   void set_default_string_param(const int detid, const std::string &name, const std::string &sval);
0085   int BeginRunExecuted() const { return m_BeginRunExecutedFlag; }
0086   void PrintDefaultParams() const;
0087   void PrintMacroParams() const;
0088 
0089  private:
0090   PHParametersContainer *m_ParamsContainer = nullptr;
0091   PHParametersContainer *m_ParamsContainerDefault = nullptr;
0092   PHCompositeNode *m_SaveTopNode = nullptr;
0093   bool m_OverlapCheckFlag = false;
0094   int m_Layer = 0;
0095   int m_UseDBFlag = 0;
0096   int m_BeginRunExecutedFlag = 0;
0097   FILE_TYPE m_FileType = PHG4DetectorGroupSubsystem::none;
0098   std::string m_SuperDetector = "NONE";
0099   std::string m_CalibFileDir = "./";
0100 
0101   std::set<int> m_LayerSet;
0102 
0103   std::map<int, std::map<const std::string, double>> m_MacroDoubleParamsMap;
0104   std::map<int, std::map<const std::string, int>> m_MacroIntegerParamsMap;
0105   std::map<int, std::map<const std::string, std::string>> m_MacroStringParamsMap;
0106 
0107   std::map<int, std::map<const std::string, double>> m_DefaultDoubleParamsMap;
0108   std::map<int, std::map<const std::string, int>> m_DefaultIntegerParamsMap;
0109   std::map<int, std::map<const std::string, std::string>> m_DefaultStringParamsMap;
0110 };
0111 
0112 #endif