Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:18

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/TowerInfo.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 //! Miscellaneous definitions for CaloStatusMapper
0029 // ============================================================================
0030 /*! A namespace to collect various constants, helper
0031  *  methods, etc. used in the CaloStatusMapper
0032  *  module.
0033  */
0034 namespace CaloStatusMapperDefs
0035 {
0036 
0037   // convenience types
0038   typedef std::pair<std::string, int> NodeDef;
0039 
0040   // ==========================================================================
0041   //! Enumeration of calorimeters
0042   // ==========================================================================
0043   /*! This enumerates the different calorimeters one can
0044    *  map in the module.
0045    */
0046   enum Calo
0047   {
0048     EMCal,  ///!< EMCal geometry
0049     HCal,   ///!< I/OHCal geometry
0050     NONE    ///!< Unspecified geometry
0051   };
0052 
0053   // ==========================================================================
0054   //! Possible status codes
0055   // ==========================================================================
0056   /*! This enumerates possible status codes of towers.
0057    */
0058   enum Stat
0059   {
0060     Good,
0061     Hot,
0062     BadTime,
0063     BadChi,
0064     NotInstr,
0065     NoCalib,
0066     Unknown
0067   };
0068 
0069   // ==========================================================================
0070   //! Maps status codes onto labels
0071   // ==========================================================================
0072   inline std::map<Stat, std::string> const& StatLabels()
0073   {
0074     static std::map<Stat, std::string> mapStatLabels = {
0075         {Stat::Good, "Good"},
0076         {Stat::Hot, "Hot"},
0077         {Stat::BadTime, "BadTime"},
0078         {Stat::BadChi, "BadChi"},
0079         {Stat::NotInstr, "NotInstr"},
0080         {Stat::NoCalib, "NoCalib"},
0081         {Stat::Unknown, "Unknown"}};
0082     return mapStatLabels;
0083   }
0084 
0085   // ==========================================================================
0086   //! Helper struct to define an axis of a histogram
0087   // ==========================================================================
0088   /*! This is a lightweight struct to consolidate information
0089    *  necessary to define a histogram axis.
0090    */
0091   struct AxisDef
0092   {
0093     // members
0094     std::string label{""};  ///! axis label
0095     std::size_t nBins{10};  ///! no. of bins in an axis
0096     float start{0.};        ///! low edge of 1st bin
0097     float stop{1.};         ///! high edge of last bin
0098 
0099   };  // end AxisDef
0100 
0101   // ==========================================================================
0102   //! Helper struct to define histograms
0103   // ==========================================================================
0104   /*! This is a lightweight struct to organize the axis definitions
0105    *  for status, eta, phi axes and make histograms using them.
0106    */
0107   template <std::size_t H, std::size_t F, std::size_t S, std::size_t E>
0108   struct HistDef
0109   {
0110     // axis definitions
0111     AxisDef stat{"Status", S + 1, -0.5, S + 0.5};
0112     //! AxisDef stat {"Status", S, -0.5, S - 0.5};
0113     AxisDef eta{"i_{#eta}", H, -0.5, H - 0.5};
0114     AxisDef phi{"i_{#phi}", F, -0.5, F - 0.5};
0115     AxisDef towere{"Tower E", (E + 100) / 10, -100, E};
0116 
0117     //! make 1 1d status plot
0118     TH1* MakeStatus1D(const std::string& name) const
0119     {
0120       const std::string title = ";" + stat.label;
0121       return new TH1D(name.data(), title.data(), stat.nBins, stat.start, stat.stop);
0122     }
0123 
0124     //! make a 1d eta plot
0125     TH1* MakeEta1D(const std::string& name) const
0126     {
0127       const std::string title = ";" + eta.label;
0128       return new TH1D(name.data(), title.data(), eta.nBins, eta.start, eta.stop);
0129     }
0130 
0131     //! make a 1d phi plot
0132     TH1* MakePhi1D(const std::string& name) const
0133     {
0134       const std::string title = ";" + phi.label;
0135       return new TH1D(name.data(), title.data(), phi.nBins, phi.start, phi.stop);
0136     }
0137 
0138     //! make a 2d eta-phi plot
0139     TH2* MakePhiEta2D(const std::string& name) const
0140     {
0141       const std::string title = ";" + eta.label + ";" + phi.label;
0142       return new TH2D(name.data(), title.data(), eta.nBins, eta.start, eta.stop, phi.nBins, phi.start, phi.stop);
0143     }
0144 
0145     //! make a 1d tower energy plot
0146     TH1* MakeEnergy1D(const std::string& name) const
0147     {
0148       const std::string title = ";" + towere.label;
0149       return new TH1D(name.data(), title.data(), towere.nBins, towere.start, towere.stop);
0150     }
0151   };  // end HistDef
0152 
0153   // -------------------------------------------------------------------------
0154   //! Maps for specific calorimeters
0155   // -------------------------------------------------------------------------
0156   typedef HistDef<96, 256, 7, 2000> EMCalHistDef;
0157   typedef HistDef<24, 64, 7, 500> HCalHistDef;
0158 
0159   // ==========================================================================
0160   //! Returns enum corresponding to given tower status
0161   // ==========================================================================
0162   /*! This helper methods returns the associated code of
0163    *  the provided tower.
0164    */
0165   Stat GetTowerStatus(TowerInfo* tower)
0166   {
0167     Stat status = Stat::Unknown;
0168     if (tower->get_isHot())
0169     {
0170       status = Stat::Hot;
0171     }
0172     else if (tower->get_isBadTime())
0173     {
0174       status = Stat::BadTime;
0175     }
0176     else if (tower->get_isBadChi2())
0177     {
0178       status = Stat::BadChi;
0179     }
0180     else if (tower->get_isNotInstr())
0181     {
0182       status = Stat::NotInstr;
0183     }
0184     else if (tower->get_isNoCalib())
0185     {
0186       status = Stat::NoCalib;
0187     }
0188     else
0189     {
0190       status = Stat::Good;
0191     }
0192     return status;
0193 
0194   }  // end 'GetTowerStatus(TowerInfo*)'
0195 
0196   // ==========================================================================
0197   //! Checks if a status code is optional for histogramming
0198   // ==========================================================================
0199   bool IsStatusSkippable(const std::string& label)
0200   {
0201     bool skip = false;
0202     if ((label == "Hot") ||
0203         (label == "BadTime") ||
0204         (label == "BadChi") ||
0205         (label == "NoCalib") ||
0206         (label == "NotInstr") ||
0207         (label == "Unknown"))
0208     {
0209       skip = true;
0210     }
0211     return skip;
0212 
0213   }  // end 'IsStatusSkippable(std::string&)'
0214 
0215 }  // namespace CaloStatusMapperDefs
0216 
0217 #endif
0218 
0219 // end ========================================================================