Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:44

0001 /// ===========================================================================
0002 /*! \file   TrksInJetQABaseManager.cc
0003  *  \author Derek Anderson
0004  *  \date   04.03.2024
0005  *
0006  *  Base hist manager submodule for the TrksInJetQA module which
0007  *  consolidates methods/data common to all of the hist managers
0008  */
0009 /// ===========================================================================
0010 
0011 #define TRKSINJETQABASEMANAGER_CC
0012 
0013 #include "TrksInJetQABaseManager.h"
0014 
0015 // ctor/dtor ==================================================================
0016 
0017 // ----------------------------------------------------------------------------
0018 //! Default ctor
0019 // ----------------------------------------------------------------------------
0020 TrksInJetQABaseManager::TrksInJetQABaseManager(TrksInJetQAConfig& config,
0021                                                TrksInJetQAHist& hist)
0022   : m_config(config)
0023   , m_hist(hist)
0024 {};
0025 
0026 // ----------------------------------------------------------------------------
0027 //! Default dtor
0028 // ----------------------------------------------------------------------------
0029 TrksInJetQABaseManager::~TrksInJetQABaseManager() {};
0030 
0031 // public methods =============================================================
0032 
0033 // ----------------------------------------------------------------------------
0034 //! Define and generate histograms for manager
0035 // ----------------------------------------------------------------------------
0036 void TrksInJetQABaseManager::MakeHistograms(const std::string& prefix,
0037                                             const std::string& suffix)
0038 {
0039   DefineHistograms();
0040   BuildHistograms(prefix, suffix);
0041 }  // end 'MakeHistograms(std::string)'
0042 
0043 // ----------------------------------------------------------------------------
0044 //! Save histograms to output file
0045 // ----------------------------------------------------------------------------
0046 /*! Note that this only relevant if output
0047  *  mode is OutMode::File.
0048  */
0049 void TrksInJetQABaseManager::SaveHistograms(TDirectory* topDir, const std::string& outDirName)
0050 {
0051   TDirectory* outDir = topDir->mkdir(outDirName.c_str());
0052   if (!outDir)
0053   {
0054     std::cerr << PHWHERE << ": PANIC: unable to make output directory!" << std::endl;
0055     exit(1);
0056   }
0057 
0058   outDir->cd();
0059   for (const auto& hist1D : m_mapHist1D)
0060   {
0061     hist1D.second->Write();
0062   }
0063   for (const auto& hist2D : m_mapHist2D)
0064   {
0065     hist2D.second->Write();
0066   }
0067 }  // end 'SaveHistograms(TDirectory*, std::string)'
0068 
0069 // ----------------------------------------------------------------------------
0070 //! Grab histograms from manager
0071 // ----------------------------------------------------------------------------
0072 void TrksInJetQABaseManager::GrabHistograms(std::vector<TH1D*>& vecOutHist1D,
0073                                             std::vector<TH2D*>& vecOutHist2D)
0074 {
0075   for (const auto& hist1D : m_mapHist1D)
0076   {
0077     vecOutHist1D.push_back(hist1D.second);
0078   }
0079   for (const auto& hist2D : m_mapHist2D)
0080   {
0081     vecOutHist2D.push_back(hist2D.second);
0082   }
0083 }  // end 'GrabHistograms(std::vector<TH1D*>&, std::vector<TH2D*>&)'
0084 
0085 // private methods ============================================================
0086 
0087 // ----------------------------------------------------------------------------
0088 //! Build histograms from definitions
0089 // ----------------------------------------------------------------------------
0090 /*! Note that the specific histogram definitions are
0091  *  implemented in the derived classes.
0092  */
0093 void TrksInJetQABaseManager::BuildHistograms(const std::string& prefix,
0094                                              const std::string& suffix)
0095 {
0096   // build 1d histograms
0097   for (const auto& histType : m_mapHistTypes)
0098   {
0099     for (const auto& histDef1D : m_mapHistDef1D)
0100     {
0101       // make name
0102       std::string sHistName(prefix + "_");
0103       sHistName += histType.second;
0104       sHistName += std::get<0>(histDef1D.second);
0105       sHistName += "_";
0106       sHistName += suffix;
0107 
0108       // make sure histogram name is lower case
0109       std::transform(sHistName.begin(),
0110                      sHistName.end(),
0111                      sHistName.begin(),
0112                      ::tolower);
0113       std::regex_replace(
0114           sHistName,
0115           std::regex("__"),
0116           "_");
0117 
0118       // create histogram
0119       m_mapHist1D.emplace(Index(histType.first, histDef1D.first),
0120                           new TH1D(sHistName.data(),
0121                                    "",
0122                                    std::get<1>(histDef1D.second).first,
0123                                    std::get<1>(histDef1D.second).second.first,
0124                                    std::get<1>(histDef1D.second).second.second));
0125     }  // end 1D hist loop
0126 
0127     // build 2d histograms
0128     for (const auto& histDef2D : m_mapHistDef2D)
0129     {
0130       // make name
0131       std::string sHistName(prefix + "_");
0132       sHistName += histType.second;
0133       sHistName += std::get<0>(histDef2D.second);
0134       sHistName += "_";
0135       sHistName += suffix;
0136 
0137       // make sure histogram name is lower case
0138       std::transform(sHistName.begin(),
0139                      sHistName.end(),
0140                      sHistName.begin(),
0141                      ::tolower);
0142       std::regex_replace(
0143           sHistName,
0144           std::regex("__"),
0145           "_");
0146 
0147       // create histogram
0148       m_mapHist2D.emplace(Index(histType.first, histDef2D.first),
0149                           new TH2D(sHistName.data(),
0150                                    "",
0151                                    std::get<1>(histDef2D.second).first,
0152                                    std::get<1>(histDef2D.second).second.first,
0153                                    std::get<1>(histDef2D.second).second.second,
0154                                    std::get<2>(histDef2D.second).first,
0155                                    std::get<2>(histDef2D.second).second.first,
0156                                    std::get<2>(histDef2D.second).second.second));
0157     }  // end hist loop
0158   }  // end type loop
0159 }  // end 'BuildHistograms(std::string)'
0160 
0161 // private helper methods =====================================================
0162 
0163 // ----------------------------------------------------------------------------
0164 //! Check if a layer is in the MVTX
0165 // ----------------------------------------------------------------------------
0166 bool TrksInJetQABaseManager::IsInMvtx(const uint16_t layer) const
0167 {
0168   return (layer < m_config.nMvtxLayer);
0169 }  // end 'IsInMvtx(uint16_t)'
0170 
0171 // ----------------------------------------------------------------------------
0172 //! Check if a layer is in the INTT
0173 // ----------------------------------------------------------------------------
0174 bool TrksInJetQABaseManager::IsInIntt(const uint16_t layer) const
0175 {
0176   return ((layer >= m_config.nMvtxLayer) &&
0177           (layer < m_config.nInttLayer + m_config.nMvtxLayer));
0178 }  // end 'IsInIntt(uint16_t)'
0179 
0180 // ----------------------------------------------------------------------------
0181 //! Check if a layer is in the TPC
0182 // ----------------------------------------------------------------------------
0183 bool TrksInJetQABaseManager::IsInTpc(const uint16_t layer) const
0184 {
0185   return (layer >= m_config.nMvtxLayer + m_config.nInttLayer);
0186 }  // end 'IsInTpc(uint16_t)'
0187 
0188 // ----------------------------------------------------------------------------
0189 //! Create an index based on object type and histogram index
0190 // ----------------------------------------------------------------------------
0191 int TrksInJetQABaseManager::Index(const int type, const int hist) const
0192 {
0193   return (100 * type) + hist;
0194 }  // end 'Index(int, int)'
0195 
0196 // end ========================================================================