Skip to content

Commit c7dde1e

Browse files
committed
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
1 parent 78a102f commit c7dde1e

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class CAFMaker : public art::EDProducer {
207207

208208
std::string fSourceFile;
209209
std::uint32_t fSourceFileHash;
210+
211+
bool fNewInputFile;
210212

211213
bool fOverrideRealData;
212214
bool fFirstInSubRun;
@@ -224,6 +226,7 @@ class CAFMaker : public art::EDProducer {
224226
double fTotalEvents;
225227
double fBlindEvents;
226228
double fPrescaleEvents;
229+
double fNGenEvents;
227230
std::vector<caf::SRBNBInfo> fBNBInfo; ///< Store detailed BNB info to save into the first StandardRecord of the output file
228231
std::vector<caf::SRNuMIInfo> fNuMIInfo; ///< Store detailed NuMI info to save into the first StandardRecord of the output file
229232
std::map<unsigned int,sbn::BNBSpillInfo> fBNBInfoEventMap; ///< Store detailed BNB info to save for the particular spills of events
@@ -783,6 +786,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) {
783786
// so should be less than or equal to 32-bit
784787
fSourceFileHash = static_cast<std::uint32_t>(fSourceFileHashFull);
785788

789+
fNewInputFile = true;
786790
}
787791

788792
//......................................................................
@@ -858,6 +862,18 @@ void CAFMaker::beginRun(art::Run& run) {
858862
fDet = override;
859863
}
860864

865+
if (std::exchange(fNewInputFile, false)){
866+
for (const art::ProcessConfiguration &process: run.processHistory()) {
867+
std::optional<fhicl::ParameterSet> gen_config = run.getProcessParameterSet(process.processName());
868+
if (gen_config && gen_config->has_key("source") && gen_config->has_key("source.maxEvents") && gen_config->has_key("source.module_type") ) {
869+
int max_events = gen_config->get<int>("source.maxEvents");
870+
std::string module_type = gen_config->get<std::string>("source.module_type");
871+
if (module_type == "EmptyEvent") {
872+
fNGenEvents += max_events;
873+
}
874+
}
875+
}
876+
}
861877

862878
if(fParams.SystWeightLabels().empty()) return; // no need for globalTree
863879

@@ -1212,6 +1228,7 @@ void CAFMaker::InitializeOutfiles()
12121228
fTotalEvents = 0;
12131229
fBlindEvents = 0;
12141230
fPrescaleEvents = 0;
1231+
fNGenEvents = 0;
12151232
fIndexInFile = SRHeader::NoSourceIndex;
12161233
fFirstInSubRun = false;
12171234
fFirstBlindInSubRun = false;
@@ -2770,11 +2787,11 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27702787
//......................................................................
27712788
void CAFMaker::AddHistogramsToFile(TFile* outfile,bool isBlindPOT = false, bool isPrescalePOT = false) const
27722789
{
2773-
27742790
outfile->cd();
27752791

27762792
TH1* hPOT = new TH1D("TotalPOT", "TotalPOT;; POT", 1, 0, 1);
27772793
TH1* hEvents = new TH1D("TotalEvents", "TotalEvents;; Events", 1, 0, 1);
2794+
TH1* hGen = new TH1D("NGenEvents", "NGenEvents;; Events", 1, 0, 1);
27782795

27792796
if (isBlindPOT) {
27802797
hPOT->Fill(0.5,fTotalPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale());
@@ -2786,13 +2803,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27862803
hPOT->Fill(0.5,fTotalPOT);
27872804
}
27882805
hEvents->Fill(0.5,fTotalEvents);
2806+
hGen->Fill(0.5,fNGenEvents);
27892807

27902808
hPOT->Write();
27912809
hEvents->Write();
2810+
hGen->Write();
27922811

27932812
if (fParams.CreateBlindedCAF()) {
27942813
TH1*hBlindEvents = new TH1D("BlindEvents", "BlindEvents;; Events", 1, 0, 1);
2795-
TH1* hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1);
2814+
TH1*hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1);
27962815
hBlindEvents->Fill(0.5, fBlindEvents);
27972816
hPrescaleEvents->Fill(0.5, fPrescaleEvents);
27982817
hBlindEvents->Write();

0 commit comments

Comments
 (0)