From c0b9c7dc93563cac282114b1422355baeb1ab420 Mon Sep 17 00:00:00 2001 From: lynnt20 Date: Fri, 24 Oct 2025 10:35:40 -0500 Subject: [PATCH 1/4] add histograms to file even when total events are 0 for POT accounting --- sbncode/CAFMaker/CAFMaker_module.cc | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 7baf6ef0c..bd8026ca0 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2802,29 +2802,26 @@ void CAFMaker::endSubRun(art::SubRun& sr) { //...................................................................... void CAFMaker::endJob() { - if (fTotalEvents == 0) { - std::cerr << "No events processed in this file. Aborting rather than " - "produce an empty CAF." + // Only produce empty recTree/GenieTree since it relies on non-zero art events. + // Still want to keep POT histograms. + if (fTotalEvents == 0) { + std::cerr << "No events processed in this file. Producing empty recTree/GenieTree." << std::endl; - // n.b. changed abort() to return so that eny exceptions thrown during startup - // still get printed to the user by art - return; } - - if(fFile){ - AddHistogramsToFile(fFile); - fRecTree->SetDirectory(fFile); - if(fGenieTree){ - fGenieTree->BuildIndex("SourceFileHash", "GENIEEntry"); - fGenieTree->SetDirectory(fFile); - } - if (fParams.CreateBlindedCAF()) { - fRecTreeb->SetDirectory(fFileb); - fRecTreep->SetDirectory(fFilep); + if (fTotalEvents > 0) { + if(fGenieTree){ + fGenieTree->BuildIndex("SourceFileHash", "GENIEEntry"); + fGenieTree->SetDirectory(fFile); + } + fRecTree->SetDirectory(fFile); + if (fParams.CreateBlindedCAF()) { + fRecTreeb->SetDirectory(fFileb); + fRecTreep->SetDirectory(fFilep); + } } fFile->cd(); fFile->Write(); @@ -2840,17 +2837,20 @@ void CAFMaker::endJob() { } if(fFlatFile){ - AddHistogramsToFile(fFlatFile); - fFlatTree->SetDirectory(fFlatFile); - if(fFlatGenieTree){ - fFlatGenieTree->BuildIndex("SourceFileHash", "GENIEEntry"); - fFlatGenieTree->SetDirectory(fFlatFile); - } - if (fParams.CreateBlindedCAF() && fFlatFileb) { - fFlatTreeb->SetDirectory(fFlatFileb); - fFlatTreep->SetDirectory(fFlatFilep); + if (fTotalEvents > 0) { + if(fFlatGenieTree){ + fFlatGenieTree->BuildIndex("SourceFileHash", "GENIEEntry"); + fFlatGenieTree->SetDirectory(fFlatFile); + } + fFlatTree->SetDirectory(fFlatFile); + if (fParams.CreateBlindedCAF() && fFlatFileb) { + fFlatTreeb->SetDirectory(fFlatFileb); + fFlatTreep->SetDirectory(fFlatFilep); + } } + std::cout << "here4" << std::endl; + fFlatFile->cd(); fFlatFile->Write(); if (fParams.CreateBlindedCAF()) { From 78a102fce196b683de7a3629c361b2e2bbd9cd1a Mon Sep 17 00:00:00 2001 From: lynnt20 Date: Mon, 27 Oct 2025 10:26:56 -0500 Subject: [PATCH 2/4] remove debug cout --- sbncode/CAFMaker/CAFMaker_module.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index bd8026ca0..691087a0e 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2849,7 +2849,6 @@ void CAFMaker::endJob() { fFlatTreep->SetDirectory(fFlatFilep); } } - std::cout << "here4" << std::endl; fFlatFile->cd(); fFlatFile->Write(); From c7dde1e4099b61fe3d12ccfb3332f6be3a2d01df Mon Sep 17 00:00:00 2001 From: lynnt20 Date: Mon, 3 Nov 2025 11:03:35 -0600 Subject: [PATCH 3/4] add functionality to save ngenevt on a run-level in new histogram - add check for opening a new file - access the run process history to get the number of generated events - add new histogram to save ngenevt, paralleling fTotalPOT --- sbncode/CAFMaker/CAFMaker_module.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 691087a0e..80f909ab8 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -207,6 +207,8 @@ class CAFMaker : public art::EDProducer { std::string fSourceFile; std::uint32_t fSourceFileHash; + + bool fNewInputFile; bool fOverrideRealData; bool fFirstInSubRun; @@ -224,6 +226,7 @@ class CAFMaker : public art::EDProducer { double fTotalEvents; double fBlindEvents; double fPrescaleEvents; + double fNGenEvents; std::vector fBNBInfo; ///< Store detailed BNB info to save into the first StandardRecord of the output file std::vector fNuMIInfo; ///< Store detailed NuMI info to save into the first StandardRecord of the output file std::map fBNBInfoEventMap; ///< Store detailed BNB info to save for the particular spills of events @@ -783,6 +786,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) { // so should be less than or equal to 32-bit fSourceFileHash = static_cast(fSourceFileHashFull); + fNewInputFile = true; } //...................................................................... @@ -858,6 +862,18 @@ void CAFMaker::beginRun(art::Run& run) { fDet = override; } + if (std::exchange(fNewInputFile, false)){ + for (const art::ProcessConfiguration &process: run.processHistory()) { + std::optional gen_config = run.getProcessParameterSet(process.processName()); + if (gen_config && gen_config->has_key("source") && gen_config->has_key("source.maxEvents") && gen_config->has_key("source.module_type") ) { + int max_events = gen_config->get("source.maxEvents"); + std::string module_type = gen_config->get("source.module_type"); + if (module_type == "EmptyEvent") { + fNGenEvents += max_events; + } + } + } + } if(fParams.SystWeightLabels().empty()) return; // no need for globalTree @@ -1212,6 +1228,7 @@ void CAFMaker::InitializeOutfiles() fTotalEvents = 0; fBlindEvents = 0; fPrescaleEvents = 0; + fNGenEvents = 0; fIndexInFile = SRHeader::NoSourceIndex; fFirstInSubRun = false; fFirstBlindInSubRun = false; @@ -2770,11 +2787,11 @@ void CAFMaker::endSubRun(art::SubRun& sr) { //...................................................................... void CAFMaker::AddHistogramsToFile(TFile* outfile,bool isBlindPOT = false, bool isPrescalePOT = false) const { - outfile->cd(); TH1* hPOT = new TH1D("TotalPOT", "TotalPOT;; POT", 1, 0, 1); TH1* hEvents = new TH1D("TotalEvents", "TotalEvents;; Events", 1, 0, 1); + TH1* hGen = new TH1D("NGenEvents", "NGenEvents;; Events", 1, 0, 1); if (isBlindPOT) { hPOT->Fill(0.5,fTotalPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale()); @@ -2786,13 +2803,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) { hPOT->Fill(0.5,fTotalPOT); } hEvents->Fill(0.5,fTotalEvents); + hGen->Fill(0.5,fNGenEvents); hPOT->Write(); hEvents->Write(); + hGen->Write(); if (fParams.CreateBlindedCAF()) { TH1*hBlindEvents = new TH1D("BlindEvents", "BlindEvents;; Events", 1, 0, 1); - TH1* hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1); + TH1*hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1); hBlindEvents->Fill(0.5, fBlindEvents); hPrescaleEvents->Fill(0.5, fPrescaleEvents); hBlindEvents->Write(); From 5ee3fb2bfe1795a4d8173e2a1f14ba932ac9ee28 Mon Sep 17 00:00:00 2001 From: lynnt20 Date: Mon, 3 Nov 2025 11:41:57 -0600 Subject: [PATCH 4/4] rename NGenEvents to TotalGenEvents to share similar syntax with POT and Events variables --- sbncode/CAFMaker/CAFMaker_module.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 80f909ab8..74f53df06 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -226,7 +226,7 @@ class CAFMaker : public art::EDProducer { double fTotalEvents; double fBlindEvents; double fPrescaleEvents; - double fNGenEvents; + double fTotalGenEvents; std::vector fBNBInfo; ///< Store detailed BNB info to save into the first StandardRecord of the output file std::vector fNuMIInfo; ///< Store detailed NuMI info to save into the first StandardRecord of the output file std::map fBNBInfoEventMap; ///< Store detailed BNB info to save for the particular spills of events @@ -869,7 +869,7 @@ void CAFMaker::beginRun(art::Run& run) { int max_events = gen_config->get("source.maxEvents"); std::string module_type = gen_config->get("source.module_type"); if (module_type == "EmptyEvent") { - fNGenEvents += max_events; + fTotalGenEvents += max_events; } } } @@ -1228,7 +1228,7 @@ void CAFMaker::InitializeOutfiles() fTotalEvents = 0; fBlindEvents = 0; fPrescaleEvents = 0; - fNGenEvents = 0; + fTotalGenEvents = 0; fIndexInFile = SRHeader::NoSourceIndex; fFirstInSubRun = false; fFirstBlindInSubRun = false; @@ -2791,7 +2791,7 @@ void CAFMaker::endSubRun(art::SubRun& sr) { TH1* hPOT = new TH1D("TotalPOT", "TotalPOT;; POT", 1, 0, 1); TH1* hEvents = new TH1D("TotalEvents", "TotalEvents;; Events", 1, 0, 1); - TH1* hGen = new TH1D("NGenEvents", "NGenEvents;; Events", 1, 0, 1); + TH1* hGen = new TH1D("TotalGenEvents", "TotalGenEvents;; Events", 1, 0, 1); if (isBlindPOT) { hPOT->Fill(0.5,fTotalPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale()); @@ -2803,7 +2803,7 @@ void CAFMaker::endSubRun(art::SubRun& sr) { hPOT->Fill(0.5,fTotalPOT); } hEvents->Fill(0.5,fTotalEvents); - hGen->Fill(0.5,fNGenEvents); + hGen->Fill(0.5,fTotalGenEvents); hPOT->Write(); hEvents->Write();