File indexing completed on 2025-08-06 08:18:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define TRKSINJETQA_CC
0012
0013
0014 #include "TrksInJetQA.h"
0015
0016
0017 #include <TStyle.h>
0018
0019
0020
0021
0022
0023
0024 TrksInJetQA::TrksInJetQA(const std::string& name)
0025 : SubsysReco(name)
0026 , m_moduleName(name)
0027 {};
0028
0029
0030
0031
0032 TrksInJetQA::~TrksInJetQA()
0033 {
0034
0035 if (m_config.doDebug && (m_config.verbose > 4))
0036 {
0037 std::cout << "TrksInJetQA::~TrksInJetQA() Calling dtor" << std::endl;
0038 }
0039
0040
0041
0042
0043 delete m_outFile;
0044 }
0045
0046
0047
0048
0049
0050
0051 void TrksInJetQA::Configure(const TrksInJetQAConfig& config,
0052 std::optional<TrksInJetQAHist> hist)
0053 {
0054
0055 if (config.doDebug && (config.verbose > 3))
0056 {
0057 std::cout << "TrksInJetQA::~TrksInJetQA() Calling dtor" << std::endl;
0058 }
0059 m_config = config;
0060
0061 if (hist.has_value())
0062 {
0063 m_hist = hist.value();
0064 }
0065 }
0066
0067
0068
0069
0070
0071
0072 int TrksInJetQA::Init(PHCompositeNode* )
0073 {
0074
0075 if (m_config.doDebug && (m_config.verbose > 0))
0076 {
0077 std::cout << "TrksInJetQA::Init(PHCompositeNode* /*topNode*/) Initializing" << std::endl;
0078 }
0079
0080
0081 InitOutput();
0082 InitHistograms();
0083
0084
0085 if (m_config.outMode == OutMode::QA)
0086 {
0087 RegisterHistograms();
0088 }
0089
0090
0091 delete m_analyzer;
0092 m_analyzer = new TriggerAnalyzer();
0093 return Fun4AllReturnCodes::EVENT_OK;
0094 }
0095
0096
0097
0098
0099 int TrksInJetQA::process_event(PHCompositeNode* topNode)
0100 {
0101
0102 if (m_config.doDebug && (m_config.verbose > 2))
0103 {
0104 std::cout << "TrksInJetQA::process_event(PHCompositeNode* topNode) Processing Event" << std::endl;
0105 }
0106
0107
0108 if (m_doTrgSelect)
0109 {
0110 m_analyzer->decodeTriggers(topNode);
0111 bool hasTrigger = JetQADefs::DidTriggerFire(m_trgToSelect, m_analyzer);
0112 if (!hasTrigger)
0113 {
0114 return Fun4AllReturnCodes::EVENT_OK;
0115 }
0116 }
0117
0118
0119 if (m_config.doInJet)
0120 {
0121 m_inJet->Fill(topNode);
0122 }
0123 if (m_config.doInclusive)
0124 {
0125 m_inclusive->Fill(topNode);
0126 }
0127 return Fun4AllReturnCodes::EVENT_OK;
0128 }
0129
0130
0131
0132
0133 int TrksInJetQA::End(PHCompositeNode* )
0134 {
0135
0136 if (m_config.doDebug && (m_config.verbose > 0))
0137 {
0138 std::cout << "TrksInJetQA::End(PHCompositeNode* /*topNode*/) This is the End..." << std::endl;
0139 }
0140
0141
0142 if (m_config.outMode == OutMode::File)
0143 {
0144
0145 if (m_config.doInJet)
0146 {
0147 m_inJet->SaveHistograms(m_outFile, "InJet");
0148 }
0149 if (m_config.doInclusive)
0150 {
0151 m_inclusive->SaveHistograms(m_outFile, "Inclusive");
0152 }
0153
0154
0155 m_outFile->cd();
0156 m_outFile->Close();
0157 }
0158 return Fun4AllReturnCodes::EVENT_OK;
0159 }
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 void TrksInJetQA::InitOutput()
0170 {
0171
0172 if (m_config.doDebug && (m_config.verbose > 1))
0173 {
0174 std::cout << "TrksInJetQA::InitOutput() Initializing outputs..." << std::endl;
0175 }
0176
0177
0178 switch (m_config.outMode)
0179 {
0180 case OutMode::File:
0181 m_outFile = new TFile(m_outFileName.data(), "RECREATE");
0182 if (!m_outFile)
0183 {
0184 std::cerr << PHWHERE << ": PANIC: couldn't create output file!" << std::endl;
0185 assert(m_outFile);
0186 }
0187 break;
0188
0189 case OutMode::QA:
0190 delete m_manager;
0191
0192 gStyle->SetOptTitle(0);
0193 m_manager = QAHistManagerDef::getHistoManager();
0194 if (!m_manager)
0195 {
0196 std::cerr << PHWHERE << ": PANIC: couldn't grab histogram manager!" << std::endl;
0197 assert(m_manager);
0198 }
0199 break;
0200
0201 default:
0202 std::cerr << PHWHERE << ": PANIC: unknown output mode specified!\n"
0203 << " Please set .outMode = OutMode::File OR OutMode::QA!"
0204 << std::endl;
0205 assert((m_config.outMode == OutMode::File) || (m_config.outMode == OutMode::QA));
0206 break;
0207 }
0208 }
0209
0210
0211
0212
0213 void TrksInJetQA::InitHistograms()
0214 {
0215
0216 if (m_config.doDebug && (m_config.verbose > 1))
0217 {
0218 std::cout << "TrksInJetQA::InitHistograms() Initializing histograms..." << std::endl;
0219 }
0220
0221
0222 std::string prefix = "h_";
0223 prefix += m_moduleName;
0224
0225
0226 if (m_histPrefix.has_value())
0227 {
0228 prefix += m_histPrefix.value();
0229 prefix += "_";
0230 }
0231
0232
0233 std::string inJetSuffix = "InJet";
0234 std::string inclusiveSuffix = "Inclusive";
0235 if (m_histSuffix.has_value() && !m_histSuffix.value().empty())
0236 {
0237 inJetSuffix += "_";
0238 inJetSuffix += m_histSuffix.value();
0239 inclusiveSuffix += "_";
0240 inclusiveSuffix += m_histSuffix.value();
0241 }
0242
0243
0244 if (m_config.doInJet)
0245 {
0246 m_inJet = std::make_unique<TrksInJetQAInJetFiller>(m_config, m_hist);
0247 m_inJet->MakeHistograms(prefix, inJetSuffix);
0248 }
0249 if (m_config.doInclusive)
0250 {
0251 m_inclusive = std::make_unique<TrksInJetQAInclusiveFiller>(m_config, m_hist);
0252 m_inclusive->MakeHistograms(prefix, inclusiveSuffix);
0253 }
0254 }
0255
0256
0257
0258
0259 void TrksInJetQA::RegisterHistograms()
0260 {
0261
0262 if (m_config.doDebug && (m_config.verbose > 1))
0263 {
0264 std::cout << "TrksInJetQA::RegisterHistograms() Registering histograms..." << std::endl;
0265 }
0266
0267 std::vector<TH1D*> vecHist1D;
0268 std::vector<TH2D*> vecHist2D;
0269 if (m_config.doInJet)
0270 {
0271 m_inJet->GrabHistograms(vecHist1D, vecHist2D);
0272 }
0273 if (m_config.doInclusive)
0274 {
0275 m_inclusive->GrabHistograms(vecHist1D, vecHist2D);
0276 }
0277
0278
0279 for (TH1D* hist1D : vecHist1D)
0280 {
0281 m_manager->registerHisto(hist1D);
0282 }
0283 for (TH2D* hist2D : vecHist2D)
0284 {
0285 m_manager->registerHisto(hist2D);
0286 }
0287 }
0288
0289