Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ void sbn::NuMIRetriever::produce(art::Event &e)
e.getByLabel(raw_data_label_, "ICARUSTriggerV3", raw_data_ptr);
auto const & raw_data = (*raw_data_ptr);

// NOTE: Really we should skip the first event of each trigger type, so let's make this look at that too...
if ( raw_data.empty() ) return;
else {
icarus::ICARUSTriggerV3Fragment frag(raw_data.at(0));
if ( frag.getTotalTriggerNuMIMaj() <= 1 ) return;
}

double t_current_event = 0;
double t_previous_event = 0;
double number_of_gates_since_previous_event = 0;
Expand Down Expand Up @@ -163,8 +170,8 @@ void sbn::NuMIRetriever::produce(art::Event &e)
// plus or minus some time padding, currently using 3.3 ms
// which is half the Booster Rep Rate
if(e.event() != 1){//We already addressed the "first event" above
if(times_temps[i] > t_current_event){continue;}
if(times_temps[i] <= t_previous_event){continue;}
if(times_temps[i] > t_current_event+fTimePad){continue;}
if(times_temps[i] <= t_previous_event+fTimePad){continue;}
}

//count found spills
Expand Down
54 changes: 54 additions & 0 deletions sbncode/CAFMaker/CAFMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ namespace sbn{

namespace caf {

/// Function to calculate a timestamp from the spill info product
template <typename SpillInfo>
double spillInfoToTimestamp(SpillInfo const& info) {
return static_cast<double>(info.spill_time_s) +
static_cast<double>(info.spill_time_ns)*1.0e-9;
}

/// Module to create Common Analysis Files from ART files
class CAFMaker : public art::EDProducer {
public:
Expand Down Expand Up @@ -195,6 +202,10 @@ class CAFMaker : public art::EDProducer {
double fPrescaleEvents;
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
std::map<unsigned int,sbn::NuMISpillInfo> fNuMIInfoEventMap; ///< Store detailed NuMI info to save for the particular spills of events
bool fHasBNBInfo;
bool fHasNuMIInfo;

// int fCycle;
// int fBatch;
Expand Down Expand Up @@ -745,6 +756,12 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
// get POT information
fBNBInfo.clear();
fNuMIInfo.clear();

fBNBInfoEventMap.clear();
fNuMIInfoEventMap.clear();
fHasBNBInfo = false;
fHasNuMIInfo = false;

fSubRunPOT = 0;
fOffbeamBNBGates = 0;
fOffbeamNuMIGates = 0;
Expand All @@ -769,10 +786,32 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
if(bnb_spill){
FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT);
fTotalPOT += fSubRunPOT;

// Find the spill for each event and fill the event map:
// We take the latest spill for a given event number to be the one to keep
fHasBNBInfo = true;
for(const sbn::BNBSpillInfo& info: *bnb_spill)
{
auto& storedInfo = fBNBInfoEventMap[info.event]; // creates if needed
if ( (storedInfo.event == UINT_MAX) || spillInfoToTimestamp(info) > spillInfoToTimestamp(storedInfo) ) {
storedInfo = std::move(info);
}
}
}
else if (numi_spill) {
FillExposureNuMI(*numi_spill, fNuMIInfo, fSubRunPOT);
fTotalPOT += fSubRunPOT;

// Find the spill for each event and fill the event map:
// We take the latest spill for a given event number to be the one to keep
fHasNuMIInfo = true;
for(const sbn::NuMISpillInfo& info: *numi_spill)
{
auto& storedInfo = fNuMIInfoEventMap[info.event]; // creates if needed
if ( (storedInfo.event == UINT_MAX) || spillInfoToTimestamp(info) > spillInfoToTimestamp(storedInfo) ) {
storedInfo = std::move(info);
}
}
}
else if (bnb_offbeam_spill){
for(const auto& spill: *bnb_offbeam_spill) {
Expand Down Expand Up @@ -1984,6 +2023,21 @@ void CAFMaker::produce(art::Event& evt) noexcept {
// rec.hdr.blind = 0;
// rec.hdr.filt = rb::IsFiltered(evt, slices, sliceID);

// Fill the header info for the given event's spill quality info
if ( fHasBNBInfo && fHasNuMIInfo ) {
std::cout << "Found > 0 BNBInfo size and NuMIInfo size, which seems strange. Throwing..." << std::endl;
abort();
}
unsigned int const eventNo = evt.id().event();
if ( fBNBInfoEventMap.count(eventNo) > 0 ) {
rec.hdr.spillbnbinfo = makeSRBNBInfo(fBNBInfoEventMap.at(eventNo));
}
else if ( fNuMIInfoEventMap.count(eventNo) > 0 ) {
rec.hdr.spillnumiinfo = makeSRNuMIInfo(fNuMIInfoEventMap.at(eventNo));
}
else {
std::cout << "Did not find this event in the spill info map." << std::endl;
}

if(fRecTree){
// Save the standard-record
Expand Down
30 changes: 30 additions & 0 deletions sbncode/CAFMaker/FillExposure.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,34 @@ namespace caf
NuMIInfo.back().daq_gates = info.daq_gates;
}
}

caf::SRNuMIInfo makeSRNuMIInfo(sbn::NuMISpillInfo const& info)
{
caf::SRNuMIInfo single_store;

single_store.HP121 = info.HP121;
single_store.VP121 = info.VP121;
single_store.HPTGT = info.HPTGT;
single_store.VPTGT = info.VPTGT;
single_store.HITGT = info.HITGT;
single_store.VITGT = info.VITGT;
single_store.MTGTDS = info.MTGTDS;
single_store.HRNDIR = info.HRNDIR;
single_store.NSLINA = info.NSLINA;
single_store.NSLINB = info.NSLINB;
single_store.NSLINC = info.NSLINC;
single_store.NSLIND = info.NSLIND;
single_store.TRTGTD = info.TRTGTD;
single_store.TR101D = info.TR101D;
single_store.TORTGT = info.TORTGT;
single_store.TOR101 = info.TOR101;
single_store.time = info.time;
single_store.spill_time_s = info.spill_time_s;
single_store.spill_time_ns = info.spill_time_ns;
single_store.event = info.event;
single_store.daq_gates = info.daq_gates;

return single_store;
}

}
1 change: 1 addition & 0 deletions sbncode/CAFMaker/FillExposure.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace caf
std::vector<caf::SRNuMIInfo>& NuMIInfo,
double& subRunPOT);

caf::SRNuMIInfo makeSRNuMIInfo(sbn::NuMISpillInfo const& info);

}

Expand Down