Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // ----------------------------------------------------------------------------
0002 // 'TrksInJetQA.cc'
0003 // Derek Anderson
0004 // 03.25.2024
0005 //
0006 // A "small" Fun4All module to produce QA plots for tracks,
0007 // hits, and more.
0008 // ----------------------------------------------------------------------------
0009 
0010 #define TRKSINJETQA_CC
0011 
0012 // module defintion
0013 #include "TrksInJetQA.h"
0014 
0015 
0016 
0017 // ctor/dtor ------------------------------------------------------------------
0018 
0019 TrksInJetQA::TrksInJetQA(const std::string& name) : SubsysReco(name) {
0020 
0021   /* nothing to do */
0022 
0023 }  // end ctor
0024 
0025 
0026 
0027 TrksInJetQA::~TrksInJetQA() {
0028 
0029   // print debug messages
0030   if (m_config.doDebug && (m_config.verbose > 4)) {
0031     std::cout << "TrksInJetQA::~TrksInJetQA() Calling dtor" << std::endl;
0032   }
0033 
0034   // clean up any dangling pointers
0035   //   - FIXME use smart pointers instead!
0036   if (m_outFile) {
0037     delete m_outFile;
0038     m_outFile = NULL;
0039   }
0040 
0041 }  // end dtor
0042 
0043 
0044 
0045 // public methods -------------------------------------------------------------
0046 
0047 void TrksInJetQA::Configure(
0048   TrksInJetQAConfig config,
0049   std::optional<TrksInJetQAHist> hist
0050 ) {
0051 
0052   // print debug messages
0053   if (m_config.doDebug && (m_config.verbose > 3)) {
0054     std::cout << "TrksInJetQA::~TrksInJetQA() Calling dtor" << std::endl;
0055   }
0056 
0057   m_config = config;
0058   if (hist.has_value()) {
0059     m_hist = hist.value();
0060   }
0061   return;
0062 
0063 }  // end 'Configure(TrksInJetQAConfig, std::optional<TrksInJetQAHist>)'
0064 
0065 
0066 
0067 // fun4all methods ------------------------------------------------------------
0068 
0069 int TrksInJetQA::Init(PHCompositeNode* /*topNode*/) {
0070 
0071   // print debug message
0072   if (m_config.doDebug && (m_config.verbose > 0)) {
0073     std::cout << "TrksInJetQA::Init(PHCompositeNode* /*topNode*/) Initializing" << std::endl;
0074   }
0075 
0076   // initialize output & histograms
0077   InitOutput();
0078   InitHistograms();
0079 
0080   // register histograms with manager if needed
0081   if (m_config.outMode == OutMode::QA) {
0082     RegisterHistograms();
0083   }
0084   return Fun4AllReturnCodes::EVENT_OK;
0085 
0086 }  // end 'Init(PHCompositeNode*)'
0087 
0088 
0089 
0090 int TrksInJetQA::process_event(PHCompositeNode* topNode) {
0091 
0092   // print debug message
0093   if (m_config.doDebug && (m_config.verbose > 2)) {
0094     std::cout << "TrksInJetQA::process_event(PHCompositeNode* topNode) Processing Event" << std::endl;
0095   }
0096 
0097   // run submodules
0098   if (m_config.doInJet)     m_inJet     -> Fill(topNode);
0099   if (m_config.doInclusive) m_inclusive -> Fill(topNode);
0100   return Fun4AllReturnCodes::EVENT_OK;
0101 
0102 }  // end 'process_event(PHCompositeNode*)'
0103 
0104 
0105 
0106 int TrksInJetQA::End(PHCompositeNode* /*topNode*/) {
0107 
0108   // print debug message
0109   if (m_config.doDebug && (m_config.verbose > 0)) {
0110     std::cout << "TrksInJetQA::End(PHCompositeNode* /*topNode*/) This is the End..." << std::endl;
0111   }
0112 
0113   // save hists to file if needed
0114   if (m_config.outMode == OutMode::File) {
0115 
0116     // save histograms
0117     if (m_config.doInJet)     m_inJet     -> SaveHistograms(m_outFile, "InJet");
0118     if (m_config.doInclusive) m_inclusive -> SaveHistograms(m_outFile, "Inclusive");
0119 
0120     // close file
0121     m_outFile -> cd();
0122     m_outFile -> Close();
0123   }
0124   return Fun4AllReturnCodes::EVENT_OK;
0125 
0126 }  // end 'End(PHCompositeNode*)'
0127 
0128 
0129 
0130 // private methods ------------------------------------------------------------
0131 
0132 void TrksInJetQA::InitOutput() {
0133 
0134   // print debug message
0135   if (m_config.doDebug && (m_config.verbose > 1)) {
0136     std::cout << "TrksInJetQA::InitOutput() Initializing outputs..." << std::endl;
0137   }
0138 
0139   // initialize relevent outputs
0140   switch (m_config.outMode) {
0141 
0142     case OutMode::File:
0143       m_outFile = new TFile(m_outFileName.data(), "RECREATE");
0144       if (!m_outFile) {
0145         std::cerr << PHWHERE << ": PANIC: couldn't create output file!" << std::endl;
0146         assert(m_outFile); 
0147       }
0148       break;
0149 
0150     case OutMode::QA:
0151       m_manager = QAHistManagerDef::getHistoManager();
0152       if (!m_manager) {
0153         std::cerr << PHWHERE << ": PANIC: couldn't grab histogram manager!" << std::endl;
0154         assert(m_manager);
0155       }
0156       break;
0157 
0158     default:
0159       std::cerr << PHWHERE << ": PANIC: unknown output mode specified!\n"
0160                 << "  Please set .outMode = OutMode::File OR OutMode::QA!"
0161                 << std::endl;
0162       assert((m_config.outMode == OutMode::File) || (m_config.outMode == OutMode::QA));
0163       break;
0164   }
0165   return;
0166 
0167 }  // end 'InitOutput()'
0168 
0169 
0170 
0171 void TrksInJetQA::InitHistograms() {
0172 
0173   // print debug message
0174   if (m_config.doDebug && (m_config.verbose > 1)) {
0175     std::cout << "TrksInJetQA::InitHistograms() Initializing histograms..." << std::endl;
0176   }
0177 
0178   // make labels
0179   std::string inJetLabel     = "InJet";
0180   std::string inclusiveLabel = "Inclusive";
0181   if (m_histSuffix.has_value()) {
0182     inJetLabel     += "_";
0183     inJetLabel     += m_histSuffix.value();
0184     inclusiveLabel += "_";
0185     inclusiveLabel += m_histSuffix.value();
0186   }
0187 
0188   // initialize submodules, as needed
0189   if (m_config.doInJet) {
0190     m_inJet = std::make_unique<TrksInJetQAInJetFiller>(m_config, m_hist);
0191     m_inJet -> MakeHistograms(inJetLabel);
0192   }
0193   if (m_config.doInclusive) {
0194     m_inclusive = std::make_unique<TrksInJetQAInclusiveFiller>(m_config, m_hist);
0195     m_inclusive -> MakeHistograms(inclusiveLabel);
0196   }
0197   return;
0198 
0199 }  // end 'InitHistograms()'
0200 
0201 
0202 
0203 void TrksInJetQA::RegisterHistograms() {
0204 
0205   // print debug message
0206   if (m_config.doDebug && (m_config.verbose > 1)) {
0207     std::cout << "TrksInJetQA::RegisterHistograms() Registering histograms..." << std::endl;
0208   }
0209 
0210   std::vector<TH1D*> vecHist1D;
0211   std::vector<TH2D*> vecHist2D;
0212   if (m_config.doInJet)     m_inJet     -> GrabHistograms(vecHist1D, vecHist2D);
0213   if (m_config.doInclusive) m_inclusive -> GrabHistograms(vecHist1D, vecHist2D);
0214 
0215   // register w/ manager
0216   for (TH1D* hist1D : vecHist1D) {
0217     m_manager -> registerHisto(hist1D);
0218   }
0219   for (TH2D* hist2D : vecHist2D) {
0220     m_manager -> registerHisto(hist2D);
0221   }
0222   return;
0223 
0224 }  // end 'RegisterHistograms()'
0225 
0226 // end ------------------------------------------------------------------------