From 3fd20513356648fdf573b780d916fab8da10ab06 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 985b8e127..612cb4863 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2736,29 +2736,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(); @@ -2774,17 +2771,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 f24c7ec44c355b5259a44b7534a0b022e6660f4c 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 612cb4863..cbda04569 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2783,7 +2783,6 @@ void CAFMaker::endJob() { fFlatTreep->SetDirectory(fFlatFilep); } } - std::cout << "here4" << std::endl; fFlatFile->cd(); fFlatFile->Write(); From 7d314911653b45b690e2022b6998361b21910d22 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 cbda04569..0cc32a660 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -206,6 +206,8 @@ class CAFMaker : public art::EDProducer { std::string fSourceFile; std::uint32_t fSourceFileHash; + + bool fNewInputFile; bool fOverrideRealData; bool fFirstInSubRun; @@ -223,6 +225,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 @@ -782,6 +785,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) { // so should be less than or equal to 32-bit fSourceFileHash = static_cast(fSourceFileHashFull); + fNewInputFile = true; } //...................................................................... @@ -857,6 +861,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 @@ -1211,6 +1227,7 @@ void CAFMaker::InitializeOutfiles() fTotalEvents = 0; fBlindEvents = 0; fPrescaleEvents = 0; + fNGenEvents = 0; fIndexInFile = SRHeader::NoSourceIndex; fFirstInSubRun = false; fFirstBlindInSubRun = false; @@ -2704,11 +2721,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()); @@ -2720,13 +2737,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 2108fa864dff8237eb3e9827f928847cc346a66a 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 0cc32a660..bb1eeccd1 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -225,7 +225,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 @@ -868,7 +868,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; } } } @@ -1227,7 +1227,7 @@ void CAFMaker::InitializeOutfiles() fTotalEvents = 0; fBlindEvents = 0; fPrescaleEvents = 0; - fNGenEvents = 0; + fTotalGenEvents = 0; fIndexInFile = SRHeader::NoSourceIndex; fFirstInSubRun = false; fFirstBlindInSubRun = false; @@ -2725,7 +2725,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()); @@ -2737,7 +2737,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();