Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:13

0001 /// ===========================================================================
0002 /*! \file   CaloStatusMapperDefs.h
0003  *  \author Derek Anderson
0004  *  \date   05.22.2024
0005  *
0006  *  A Fun4All QA module to plot no. of towers per event
0007  *  and vs. eta, phi as a function of status.
0008  */
0009 /// ===========================================================================
0010 
0011 #ifndef CLUSTERSTATUSMAPPER_DEFS_H
0012 #define CLUSTERSTATUSMAPPER_DEFS_H
0013 
0014 // calobase libraries
0015 #include <calobase/TowerInfov2.h>
0016 
0017 // root libraries
0018 #include <TH1.h>
0019 #include <TH2.h>
0020 
0021 // c++ utilities
0022 #include <map>
0023 #include <string>
0024 #include <utility>
0025 #include <vector>
0026 
0027 
0028 
0029 // ============================================================================
0030 //! Miscellaneous definitions for CaloStatusMapper
0031 // ============================================================================
0032 /*! A namespace to collect various constants, helper
0033  *  methods, etc. used in the CaloStatusMapper
0034  *  module.
0035  */
0036 namespace CaloStatusMapperDefs
0037 {
0038 
0039   // convenience types
0040   typedef std::pair<std::string, int> NodeDef;
0041 
0042 
0043 
0044   // ==========================================================================
0045   //! Enumeration of calorimeters
0046   // ==========================================================================
0047   /*! This enumerates the different calorimeters one can
0048    *  map in the module.
0049    */
0050   enum Calo
0051   {
0052     EMCal,  ///!< EMCal geometry
0053     HCal,   ///!< I/OHCal geometry
0054     NONE  ///!< Unspecified geometry
0055   };
0056 
0057 
0058 
0059   // ==========================================================================
0060   //! Possible status codes
0061   // ==========================================================================
0062   /*! This enumerates possible status codes of towers.
0063    */
0064   enum Stat
0065   {
0066     Good,
0067     Hot,
0068     BadTime,
0069     BadChi,
0070     NotInstr,
0071     NoCalib,
0072     Unknown
0073   };
0074 
0075 
0076 
0077   // ==========================================================================
0078   //! Maps status codes onto labels
0079   // ==========================================================================
0080   inline std::map<Stat, std::string> const& StatLabels()
0081   {
0082     static std::map<Stat, std::string> mapStatLabels = {
0083       {Stat::Good,     "Good"},
0084       {Stat::Hot,      "Hot"},
0085       {Stat::BadTime,  "BadTime"},
0086       {Stat::BadChi,   "BadChi"},
0087       {Stat::NotInstr, "NotInstr"},
0088       {Stat::NoCalib,  "NoCalib"},
0089       {Stat::Unknown,  "Unknown"}
0090     };
0091     return mapStatLabels;
0092   }
0093 
0094 
0095 
0096   // ==========================================================================
0097   //! Helper struct to define an axis of a histogram
0098   // ==========================================================================
0099   /*! This is a lightweight struct to consolidate information
0100    *  necessary to define a histogram axis.
0101    */
0102   struct AxisDef
0103   {
0104 
0105     // members
0106     std::string label {""};  ///! axis label
0107     std::size_t nBins {10};  ///! no. of bins in an axis
0108     float       start {0.};  ///! low edge of 1st bin
0109     float       stop  {1.};  ///! high edge of last bin
0110 
0111   };  // end AxisDef
0112 
0113 
0114 
0115   // ==========================================================================
0116   //! Helper struct to define histograms
0117   // ==========================================================================
0118   /*! This is a lightweight struct to organize the axis definitions
0119    *  for status, eta, phi axes and make histograms using them.
0120    */ 
0121   template <std::size_t H, std::size_t F, std::size_t S>
0122   struct HistDef
0123   {
0124 
0125     // axis definitions
0126     AxisDef stat {"Status", S, -0.5, S - 0.5};
0127     AxisDef eta  {"i_{#eta}", H, -0.5, H - 0.5};
0128     AxisDef phi  {"i_{#phi}", F, -0.5, F - 0.5};
0129 
0130     //! make 1 1d status plot
0131     TH1D* MakeStatus1D(const std::string& name) const
0132     {
0133       const std::string title = ";" + stat.label;
0134       return new TH1D(name.data(), title.data(), stat.nBins, stat.start, stat.stop);
0135     }
0136 
0137     //! make a 1d eta plot
0138     TH1D* MakeEta1D(const std::string& name) const
0139     {
0140       const std::string title = ";" + eta.label;
0141       return new TH1D(name.data(), title.data(), eta.nBins, eta.start, eta.stop);
0142     }
0143 
0144     //! make a 1d phi plot
0145     TH1D* MakePhi1D(const std::string& name) const
0146     {
0147       const std::string title = ";" + phi.label;
0148       return new TH1D(name.data(), title.data(), phi.nBins, phi.start, phi.stop);
0149     }
0150 
0151     //! make a 2d eta-phi plot
0152     TH2D* MakePhiEta2D(const std::string& name) const
0153     {
0154       const std::string title = ";" + eta.label + ";" + phi.label;
0155       return new TH2D(name.data(), title.data(), eta.nBins, eta.start, eta.stop, phi.nBins, phi.start, phi.stop);
0156     }
0157 
0158   };  // end HistDef
0159 
0160   // -------------------------------------------------------------------------
0161   //! Maps for specific calorimeters
0162   // -------------------------------------------------------------------------
0163   typedef HistDef<96, 256, 7> EMCalHistDef;
0164   typedef HistDef<24, 64, 7> HCalHistDef;
0165 
0166 
0167 
0168   // ==========================================================================
0169   //! Returns enum corresponding to given tower status
0170   // ==========================================================================
0171   /*! This helper methods returns the associated code of
0172    *  the provided tower.
0173    */ 
0174   Stat GetTowerStatus(TowerInfo* tower)
0175   {
0176 
0177     Stat status = Stat::Unknown;
0178     if (tower -> get_isHot())
0179     {
0180       status = Stat::Hot;
0181     }
0182     else if (tower -> get_isBadTime())
0183     {
0184       status = Stat::BadTime;
0185     }
0186     else if (tower -> get_isBadChi2())
0187     {
0188       status = Stat::BadChi;
0189     }
0190     else if (tower -> get_isNotInstr())
0191     {
0192       status = Stat::NotInstr;
0193     }
0194     else if (tower -> get_isNoCalib())
0195     {
0196       status = Stat::NoCalib;
0197     }
0198     else
0199     {
0200       status = Stat::Good;
0201     }
0202     return status;
0203 
0204   }  // end 'GetTowerStatus(TowerInfo*)'
0205 
0206 
0207 
0208   // ==========================================================================
0209   //! Make QA-compliant histogram name
0210   // ==========================================================================
0211   /*! This helper method takes in a base name (e.g. some variable you want
0212    *  to histogram like "JetEne") and produces a histogram name compliant
0213    *  w/ the rest of the jet QA.
0214    *
0215    *  The format should always be:
0216    *      h_<module name>_<trigger tag>_<jet tag>_<base name> + <tag>
0217    *
0218    *  FIXME this should get moved into JetQADefs.h
0219    */
0220   inline std::string MakeQAHistName(
0221     const std::string& base,
0222     const std::string& module,
0223     const std::string& tag = "")
0224   {
0225 
0226     // set name to base
0227     std::string name = base;
0228 
0229     // inject module names, tags, etc.
0230     name.insert(0, "h_" + module + "_");
0231     if (!tag.empty())
0232     {
0233       name.append("_" + tag);
0234     }
0235     std::transform(
0236       name.begin(),
0237       name.end(),
0238       name.begin(),
0239       ::tolower
0240     );
0241     return name;
0242 
0243   }  // end 'MakeQAHistNames(std::string& x 3)'
0244 
0245 }  // end CaloStatusMapperDefs namespace
0246 
0247 #endif
0248 
0249 // end ========================================================================
0250