Skip to content

Commit bd76936

Browse files
authored
Merge pull request #597 from SBNSoftware/feature/lynnt_cafpot_dev
CAF POT Histogram (develop)
2 parents b1f47a8 + 63bd2b4 commit bd76936

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 46 additions & 28 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 fTotalGenEvents;
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
@@ -785,6 +788,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) {
785788
// so should be less than or equal to 32-bit
786789
fSourceFileHash = static_cast<std::uint32_t>(fSourceFileHashFull);
787790

791+
fNewInputFile = true;
788792
}
789793

790794
//......................................................................
@@ -860,6 +864,18 @@ void CAFMaker::beginRun(art::Run& run) {
860864
fDet = override;
861865
}
862866

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

864880
if(fParams.SystWeightLabels().empty()) return; // no need for globalTree
865881

@@ -1216,6 +1232,7 @@ void CAFMaker::InitializeOutfiles()
12161232
fTotalEvents = 0;
12171233
fBlindEvents = 0;
12181234
fPrescaleEvents = 0;
1235+
fTotalGenEvents = 0;
12191236
fIndexInFile = SRHeader::NoSourceIndex;
12201237
fFirstInSubRun = false;
12211238
fFirstBlindInSubRun = false;
@@ -2796,11 +2813,11 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27962813
//......................................................................
27972814
void CAFMaker::AddHistogramsToFile(TFile* outfile,bool isBlindPOT = false, bool isPrescalePOT = false) const
27982815
{
2799-
28002816
outfile->cd();
28012817

28022818
TH1* hPOT = new TH1D("TotalPOT", "TotalPOT;; POT", 1, 0, 1);
28032819
TH1* hEvents = new TH1D("TotalEvents", "TotalEvents;; Events", 1, 0, 1);
2820+
TH1* hGen = new TH1D("TotalGenEvents", "TotalGenEvents;; Events", 1, 0, 1);
28042821

28052822
if (isBlindPOT) {
28062823
hPOT->Fill(0.5,fTotalPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale());
@@ -2812,13 +2829,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
28122829
hPOT->Fill(0.5,fTotalPOT);
28132830
}
28142831
hEvents->Fill(0.5,fTotalEvents);
2832+
hGen->Fill(0.5,fTotalGenEvents);
28152833

28162834
hPOT->Write();
28172835
hEvents->Write();
2836+
hGen->Write();
28182837

28192838
if (fParams.CreateBlindedCAF()) {
28202839
TH1*hBlindEvents = new TH1D("BlindEvents", "BlindEvents;; Events", 1, 0, 1);
2821-
TH1* hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1);
2840+
TH1*hPrescaleEvents = new TH1D("PrescaleEvents", "PrescaleEvents;; Events", 1, 0, 1);
28222841
hBlindEvents->Fill(0.5, fBlindEvents);
28232842
hPrescaleEvents->Fill(0.5, fPrescaleEvents);
28242843
hBlindEvents->Write();
@@ -2828,29 +2847,26 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
28282847

28292848
//......................................................................
28302849
void CAFMaker::endJob() {
2831-
if (fTotalEvents == 0) {
28322850

2833-
std::cerr << "No events processed in this file. Aborting rather than "
2834-
"produce an empty CAF."
2851+
// Only produce empty recTree/GenieTree since it relies on non-zero art events.
2852+
// Still want to keep POT histograms.
2853+
if (fTotalEvents == 0) {
2854+
std::cerr << "No events processed in this file. Producing empty recTree/GenieTree."
28352855
<< std::endl;
2836-
// n.b. changed abort() to return so that eny exceptions thrown during startup
2837-
// still get printed to the user by art
2838-
return;
28392856
}
28402857

2841-
2842-
28432858
if(fFile){
2844-
28452859
AddHistogramsToFile(fFile);
2846-
fRecTree->SetDirectory(fFile);
2847-
if(fGenieTree){
2848-
fGenieTree->BuildIndex("SourceFileHash", "GENIEEntry");
2849-
fGenieTree->SetDirectory(fFile);
2850-
}
2851-
if (fParams.CreateBlindedCAF()) {
2852-
fRecTreeb->SetDirectory(fFileb);
2853-
fRecTreep->SetDirectory(fFilep);
2860+
if (fTotalEvents > 0) {
2861+
if(fGenieTree){
2862+
fGenieTree->BuildIndex("SourceFileHash", "GENIEEntry");
2863+
fGenieTree->SetDirectory(fFile);
2864+
}
2865+
fRecTree->SetDirectory(fFile);
2866+
if (fParams.CreateBlindedCAF()) {
2867+
fRecTreeb->SetDirectory(fFileb);
2868+
fRecTreep->SetDirectory(fFilep);
2869+
}
28542870
}
28552871
fFile->cd();
28562872
fFile->Write();
@@ -2866,17 +2882,19 @@ void CAFMaker::endJob() {
28662882
}
28672883

28682884
if(fFlatFile){
2869-
28702885
AddHistogramsToFile(fFlatFile);
2871-
fFlatTree->SetDirectory(fFlatFile);
2872-
if(fFlatGenieTree){
2873-
fFlatGenieTree->BuildIndex("SourceFileHash", "GENIEEntry");
2874-
fFlatGenieTree->SetDirectory(fFlatFile);
2875-
}
2876-
if (fParams.CreateBlindedCAF() && fFlatFileb) {
2877-
fFlatTreeb->SetDirectory(fFlatFileb);
2878-
fFlatTreep->SetDirectory(fFlatFilep);
2886+
if (fTotalEvents > 0) {
2887+
if(fFlatGenieTree){
2888+
fFlatGenieTree->BuildIndex("SourceFileHash", "GENIEEntry");
2889+
fFlatGenieTree->SetDirectory(fFlatFile);
2890+
}
2891+
fFlatTree->SetDirectory(fFlatFile);
2892+
if (fParams.CreateBlindedCAF() && fFlatFileb) {
2893+
fFlatTreeb->SetDirectory(fFlatFileb);
2894+
fFlatTreep->SetDirectory(fFlatFilep);
2895+
}
28792896
}
2897+
28802898
fFlatFile->cd();
28812899
fFlatFile->Write();
28822900
if (fParams.CreateBlindedCAF()) {

0 commit comments

Comments
 (0)