Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:14:22

0001 // ----------------------------------------------------------------------------
0002 // 'TrksInJetQABaseManager.cc'
0003 // Derek Anderson
0004 // 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 #define TRKSINJETQABASEMANAGER_CC
0011 
0012 // submodule definition
0013 #include "TrksInJetQABaseManager.h"
0014 
0015 
0016 
0017 // ctor/dtor ------------------------------------------------------------------
0018 
0019 TrksInJetQABaseManager::TrksInJetQABaseManager(
0020   TrksInJetQAConfig& config,
0021   TrksInJetQAHist& hist
0022 ) {
0023 
0024   ResetVectors();
0025 
0026   // grab vectors
0027   m_config = config;
0028   m_hist   = hist;
0029 
0030 }  // end ctor(TrksInJetQAConfig&, TrksInJetQAHist&)
0031 
0032 
0033 
0034 TrksInJetQABaseManager::~TrksInJetQABaseManager() {
0035 
0036   ResetVectors();
0037 
0038 }  // end dtor
0039 
0040 
0041 
0042 // public methods -------------------------------------------------------------
0043 
0044 void TrksInJetQABaseManager::MakeHistograms(std::string label) {
0045 
0046   DefineHistograms();
0047   BuildHistograms(label);
0048   return;
0049 
0050 }  // end 'MakeHistograms(std::string)'
0051 
0052 
0053 
0054 void TrksInJetQABaseManager::SaveHistograms(TDirectory* topDir, std::string outDirName) {
0055 
0056   TDirectory* outDir = topDir -> mkdir(outDirName.data());
0057   if (!outDir) {
0058     std::cerr << PHWHERE << ": PANIC: unable to make output directory!" << std::endl;
0059     assert(outDir);
0060   }
0061 
0062   outDir -> cd();
0063   for (auto hist1Ds : m_vecHist1D) {
0064     for (TH1D* hist1D : hist1Ds) {
0065       hist1D -> Write();
0066     }
0067   }
0068   for (auto hist2Ds : m_vecHist2D) {
0069     for (TH2D* hist2D : hist2Ds) {
0070       hist2D -> Write();
0071     }
0072   }
0073   return;
0074 
0075 }  // end 'SaveHistograms(TDirectory*, std::string)'
0076 
0077 
0078 
0079 void TrksInJetQABaseManager::GrabHistograms(
0080   std::vector<TH1D*>& vecOutHist1D,
0081   std::vector<TH2D*>& vecOutHist2D
0082 ) {
0083 
0084   for (auto hist1Ds : m_vecHist1D) {
0085     for (TH1D* hist1D : hist1Ds) {
0086       vecOutHist1D.push_back(hist1D);
0087     }
0088   }
0089   for (auto hist2Ds : m_vecHist2D) {
0090     for (TH2D* hist2D : hist2Ds) {
0091       vecOutHist2D.push_back(hist2D);
0092     }
0093   }
0094   return;
0095 
0096 }  // end 'GrabHistograms(std::vector<TH1D*>&, std::vector<TH2D*>&)'
0097 
0098 
0099 
0100 // private methods ------------------------------------------------------------
0101 
0102 void TrksInJetQABaseManager::BuildHistograms(std::string label) {
0103 
0104   // build 1d histograms
0105   m_vecHist1D.resize( m_vecHistTypes.size() );
0106   for (size_t iType = 0; iType < m_vecHistTypes.size(); iType++) {
0107     for (HistDef1D histDef1D : m_vecHistDef1D) {
0108 
0109       // make name
0110       std::string sHistName("h");
0111       sHistName += m_vecHistTypes.at(iType);
0112       sHistName += std::get<0>(histDef1D);
0113       sHistName += "_";
0114       sHistName += label;
0115 
0116       // create histogram
0117       m_vecHist1D.at(iType).push_back(
0118         new TH1D(
0119           sHistName.data(),
0120           "",
0121           std::get<1>(histDef1D).first,
0122           std::get<1>(histDef1D).second.first,
0123           std::get<1>(histDef1D).second.second
0124         )
0125       );
0126     }  // end hist loop
0127   }  // end type loop
0128 
0129   // build 2d histograms
0130   m_vecHist2D.resize( m_vecHistTypes.size() );
0131   for (size_t iType = 0; iType < m_vecHistTypes.size(); iType++) {
0132     for (HistDef2D histDef2D : m_vecHistDef2D) {
0133 
0134       // make name
0135       std::string sHistName("h");
0136       sHistName += m_vecHistTypes.at(iType);
0137       sHistName += std::get<0>(histDef2D);
0138       sHistName += "_";
0139       sHistName += label;
0140 
0141       // create histogram
0142       m_vecHist2D.at(iType).push_back(
0143         new TH2D(
0144           sHistName.data(),
0145           "",
0146           std::get<1>(histDef2D).first,
0147           std::get<1>(histDef2D).second.first,
0148           std::get<1>(histDef2D).second.second,
0149           std::get<2>(histDef2D).first,
0150           std::get<2>(histDef2D).second.first,
0151           std::get<2>(histDef2D).second.second
0152         )
0153       );
0154     }  // end hist loop
0155   }  // end type loop
0156   return;
0157 
0158 }  // end 'BuildHistograms(std::string)'
0159 
0160 
0161 
0162 void TrksInJetQABaseManager::ResetVectors() {
0163 
0164   m_vecHist1D.clear();
0165   m_vecHist2D.clear();
0166   m_vecHistTypes.clear();
0167   m_vecHistDef1D.clear();
0168   m_vecHistDef2D.clear();
0169   return;
0170 
0171 }  // end 'ResetVectors()'
0172 
0173 
0174 
0175 // private helper methods -----------------------------------------------------
0176 
0177 bool TrksInJetQABaseManager::IsInMvtx(const uint16_t layer) {
0178 
0179   return (layer < m_config.nMvtxLayer);
0180 
0181 }  // end 'IsInMvtx(uint16_t)'
0182 
0183 
0184 
0185 bool TrksInJetQABaseManager::IsInIntt(const uint16_t layer) {
0186 
0187   return (
0188     (layer >= m_config.nMvtxLayer) &&
0189     (layer <  m_config.nInttLayer + m_config.nMvtxLayer)
0190   );
0191 
0192 }  // end 'IsInIntt(uint16_t)'
0193 
0194 
0195 
0196 bool TrksInJetQABaseManager::IsInTpc(const uint16_t layer) {
0197 
0198   return (layer >= m_config.nMvtxLayer + m_config.nInttLayer);
0199 
0200 }  // end 'IsInTpc(uint16_t)'
0201 
0202 // end ------------------------------------------------------------------------