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