Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions sbncode/CAFMaker/CAFMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class CAFMaker : public art::EDProducer {

std::string fSourceFile;
std::uint32_t fSourceFileHash;

bool fNewInputFile;

bool fOverrideRealData;
bool fFirstInSubRun;
Expand All @@ -223,6 +225,7 @@ class CAFMaker : public art::EDProducer {
double fTotalEvents;
double fBlindEvents;
double fPrescaleEvents;
double fTotalGenEvents;
std::vector<caf::SRBNBInfo> fBNBInfo; ///< Store detailed BNB info to save into the first StandardRecord of the output file
std::vector<caf::SRNuMIInfo> fNuMIInfo; ///< Store detailed NuMI info to save into the first StandardRecord of the output file
std::map<unsigned int,sbn::BNBSpillInfo> fBNBInfoEventMap; ///< Store detailed BNB info to save for the particular spills of events
Expand Down Expand Up @@ -782,6 +785,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) {
// so should be less than or equal to 32-bit
fSourceFileHash = static_cast<std::uint32_t>(fSourceFileHashFull);

fNewInputFile = true;
}

//......................................................................
Expand Down Expand Up @@ -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<fhicl::ParameterSet> 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<int>("source.maxEvents");
std::string module_type = gen_config->get<std::string>("source.module_type");
if (module_type == "EmptyEvent") {
fTotalGenEvents += max_events;
}
}
}
}

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

Expand Down Expand Up @@ -1211,6 +1227,7 @@ void CAFMaker::InitializeOutfiles()
fTotalEvents = 0;
fBlindEvents = 0;
fPrescaleEvents = 0;
fTotalGenEvents = 0;
fIndexInFile = SRHeader::NoSourceIndex;
fFirstInSubRun = false;
fFirstBlindInSubRun = false;
Expand Down Expand Up @@ -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("TotalGenEvents", "TotalGenEvents;; Events", 1, 0, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually confused by this feature.
Why is this an histogram? it looks it's just a number.


if (isBlindPOT) {
hPOT->Fill(0.5,fTotalPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale());
Expand All @@ -2720,13 +2737,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
hPOT->Fill(0.5,fTotalPOT);
}
hEvents->Fill(0.5,fTotalEvents);
hGen->Fill(0.5,fTotalGenEvents);

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();
Expand All @@ -2736,29 +2755,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();
Expand All @@ -2774,17 +2790,19 @@ 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);
}
}

fFlatFile->cd();
fFlatFile->Write();
if (fParams.CreateBlindedCAF()) {
Expand Down