Skip to content
Closed
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
15 changes: 11 additions & 4 deletions sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Principal/SubRun.h"
#include "canvas/Utilities/InputTag.h"
#include "canvas/Utilities/Exception.h"
#include "fhiclcpp/types/Atom.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "larcorealg/CoreUtils/counter.h"
Expand Down Expand Up @@ -217,7 +218,7 @@ void sbn::BNBRetriever::produce(art::Event& e)

TriggerInfo_t const triggerInfo = extractTriggerInfo(e);

//We only want to process BNB gates, i.e. type 1
//We only want to process BNB gates or offbeam BNB gates, i.e. type 1 or 3, check this logic, just want to keep things like number of gates and total number of beam spills, etc.
if(triggerInfo.gate_type != 1) return;
// Keep track of the number of beam gates the DAQ thinks
// are in this job
Expand Down Expand Up @@ -257,13 +258,19 @@ sbn::BNBRetriever::TriggerInfo_t sbn::BNBRetriever::extractTriggerInfo(art::Even
char *buffer = const_cast<char*>(data.c_str());
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV2String(buffer);
triggerInfo.gate_type = datastream_info.gate_type;
triggerInfo.number_of_gates_since_previous_event = frag.getDeltaGatesBNB();

if(triggerInfo.gate_type == 1)
triggerInfo.number_of_gates_since_previous_event = frag.getDeltaGatesBNB();
else
{
throw art::Exception(art::errors::StdException) << "Unsupported gate type for BNBRetriever module: " << triggerInfo.gate_type << "! Aborting";
}
triggerInfo.t_current_event = static_cast<double>(artdaq_ts)/(1000000000.0); //check this offset...
if(triggerInfo.gate_type == 1)
triggerInfo.t_previous_event = (static_cast<double>(frag.getLastTimestampBNB()))/(1e9);
else
triggerInfo.t_previous_event = (static_cast<double>(frag.getLastTimestampOther()))/(1000000000.0);
{
throw art::Exception(art::errors::StdException) << "Unsupported gate type for BNBRetriever module: " << triggerInfo.gate_type << "! Aborting";
}

}

Expand Down
46 changes: 36 additions & 10 deletions sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "larcorealg/Geometry/Exceptions.h"

#include "artdaq-core/Data/Fragment.hh"
#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh"
#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerV2Fragment.hh"

#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
Expand Down Expand Up @@ -100,23 +100,46 @@ void sbn::EXTRetriever::produce(art::Event& e)
// 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event

int gate_type = 0;
auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label_, "ICARUSTriggerUDP" });
int trigger_type = 0;
auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label_, "ICARUSTriggerV2" });

unsigned int number_of_gates_since_previous_event = 0;

bool isBNBOffBeam = false;
bool isNuMIOffBeam = false;
bool isMajority = false;
bool isMinBias = false;

for(auto raw_datum : raw_data){

icarus::ICARUSTriggerUDPFragment frag(raw_datum);
icarus::ICARUSTriggerV2Fragment frag(raw_datum);
std::string data = frag.GetDataString();
char *buffer = const_cast<char*>(data.c_str());
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer);
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV2String(buffer);
gate_type = datastream_info.gate_type;
number_of_gates_since_previous_event = frag.getDeltaGatesBNB();

trigger_type = datastream_info.trigger_type;

if(gate_type == 3)
{
isBNBOffBeam = true;
number_of_gates_since_previous_event = frag.getDeltaGatesBNBOff();
}
else if(gate_type == 4)
{
isNuMIOffBeam = true;
number_of_gates_since_previous_event = frag.getDeltaGatesNuMIOff();
}
else
{
throw art::Exception(art::errors::StdException) << "Unsupported gate type for EXTRetriever Module: " << gate_type << "! Aborting";
}
if(trigger_type == 0)
isMajority = true;
if(trigger_type == 1)
isMinBias = true;
}

//We only want to process EXT gates, i.e. type 3
if(gate_type == 3)
//We only want to process EXT gates, i.e. type 3 (BNBOffBeam) or 4 (NuMIOffBeam)
if(gate_type == 3 || gate_type == 4)
{
// Keep track of the number of beam gates the DAQ thinks
// are in this file
Expand All @@ -125,7 +148,10 @@ void sbn::EXTRetriever::produce(art::Event& e)
//Store everything in our data-product
sbn::EXTCountInfo extInfo;
extInfo.gates_since_last_trigger = number_of_gates_since_previous_event;

extInfo.isBNBOffBeam = isBNBOffBeam;
extInfo.isNuMIOffBeam = isNuMIOffBeam;
extInfo.isMajority = isMajority;
extInfo.isMinBias = isMinBias;
fOutExtInfos.push_back(extInfo);
// We do not write these to the art::Events because
// we can filter events but want to keep all the POT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,23 @@ void sbn::NuMIRetriever::produce(art::Event &e)
char *buffer = const_cast<char*>(data.c_str());
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV2String(buffer);
gate_type = datastream_info.gate_type;
number_of_gates_since_previous_event = frag.getDeltaGatesNuMI();

if(gate_type == 2)
number_of_gates_since_previous_event = frag.getDeltaGatesNuMI();
else
{
throw art::Exception(art::errors::StdException) << "Unsupported gate type for NuMIRetriever Module: " << gate_type << "! Aborting";
}
t_current_event = static_cast<double>(artdaq_ts)/(1000000000.); //check this offset...
if(gate_type == 2)
t_previous_event = (static_cast<double>(frag.getLastTimestampNuMI()))/(1000000000.);
else
t_previous_event = (static_cast<double>(frag.getLastTimestampOther()))/(1000000000.);

{
throw art::Exception(art::errors::StdException) << "Unsupported gate type for NuMIRetriever Module: " << gate_type << "! Aborting";
}
}

std::cout << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl;
//We only want to process NuMI gates, i.e. type 2
//We only want to process NuMI or offbeam NumI gates, i.e. type 2 or type 4. For offbeam spills, mainly want to keep track of total spills expected
if(gate_type == 2)
{
// Keep track of the number of beam gates the DAQ thinks
Expand Down
3 changes: 2 additions & 1 deletion sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ physics: {
extinfo: @local::extcountinfo
}

simulate: [extinfo ]
simulate: [ extinfo ]
trigger_paths: [ simulate ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

art does not require the definition of trigger_paths when there is only one producer path defined.
It does not hurt to leave it though.

stream1: [ out1 ]

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "run_extinfo_sbn.fcl"

outputs.out1.outputCommands: [
"keep *_*_*_EXTInfoGen"
]
6 changes: 6 additions & 0 deletions sbncode/CAFMaker/CAFMakerParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ namespace caf
"numiinfo"
};

Atom<string> EXTCountDataLabel {
Name("EXTCountDataLabel"),
Comment("Label of EXTRetriever module"),
"extinfo"
};

Atom<string> G4Label {
Name("G4Label"),
Comment("Label of G4 module."),
Expand Down
27 changes: 24 additions & 3 deletions sbncode/CAFMaker/CAFMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#include "sbnobj/Common/Reco/StoppingChi2Fit.h"
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
#include "sbnobj/Common/POTAccounting/NuMISpillInfo.h"
#include "sbnobj/Common/POTAccounting/EXTCountInfo.h"
#include "sbnobj/Common/Trigger/ExtraTriggerInfo.h"
#include "sbnobj/Common/Reco/CRUMBSResult.h"

Expand Down Expand Up @@ -182,12 +183,15 @@ class CAFMaker : public art::EDProducer {
int fFileNumber;
double fTotalPOT;
double fSubRunPOT;
double fEXTGateCount;
double fTotalEXTGateCount;
double fTotalSinglePOT;
double fTotalEvents;
double fBlindEvents;
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::vector<caf::SREXTInfo> fEXTInfo;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The description of the meaning of this field is missing.

std::vector<caf::SRTrigger> fSRTrigger; ///< Store trigger and beam gate information

// int fCycle;
Expand Down Expand Up @@ -673,7 +677,9 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
// get POT information
fBNBInfo.clear();
fNuMIInfo.clear();
fEXTInfo.clear();
fSubRunPOT = 0;
fEXTGateCount = 0;

if(auto bnb_spill = sr.getHandle<std::vector<sbn::BNBSpillInfo>>(fParams.BNBPOTDataLabel())){
FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT);
Expand All @@ -683,16 +689,23 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
FillExposureNuMI(*numi_spill, fNuMIInfo, fSubRunPOT);
fTotalPOT += fSubRunPOT;
}
else if(auto ext_spill = sr.getHandle<std::vector<sbn::EXTCountInfo>>(fParams.EXTCountDataLabel()))
{
FillExposureEXT(*ext_spill, fEXTInfo, fEXTGateCount);
fTotalEXTGateCount += fEXTGateCount;
}
else if(auto pot_handle = sr.getHandle<sumdata::POTSummary>(fParams.GenLabel())){
fSubRunPOT = pot_handle->totgoodpot;
fTotalPOT += fSubRunPOT;
}
else{
if(!fParams.BNBPOTDataLabel().empty() || !fParams.GenLabel().empty() || !fParams.NuMIPOTDataLabel().empty()){
if(!fParams.BNBPOTDataLabel().empty() || !fParams.GenLabel().empty() || !fParams.NuMIPOTDataLabel().empty() ||!fParams.EXTCountDataLabel().empty()){
std::cout << "Found neither BNB data POT info under '"
<< fParams.BNBPOTDataLabel()
<< "' not NuMIdata POT info under '"
<< "' nor NuMI data POT info under '"
<< fParams.NuMIPOTDataLabel()
<< "' nor EXT data count info under '"
<< fParams.EXTCountDataLabel()
<< "' nor MC POT info under '"
<< fParams.GenLabel() << "'"
<< std::endl;
Expand All @@ -702,7 +715,8 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
// Otherwise, if one label is blank, maybe no POT was the expected result
}

std::cout << "POT: " << fSubRunPOT << std::endl;
std::cout << "POT (for Beam files): " << fSubRunPOT << std::endl;
std::cout << "OffBeam Gate Count (for OffBeam files): " << fEXTGateCount << std::endl;

fFirstInSubRun = true;
}
Expand Down Expand Up @@ -860,6 +874,8 @@ void CAFMaker::InitializeOutfiles()
fTotalPOT = 0;
fSubRunPOT = 0;
fTotalSinglePOT = 0;
fEXTGateCount = 0;
fTotalEXTGateCount = 0;
fTotalEvents = 0;
fBlindEvents = 0;
fPrescaleEvents = 0;
Expand Down Expand Up @@ -1818,10 +1834,14 @@ void CAFMaker::produce(art::Event& evt) noexcept {
rec.hdr.fno = fFileNumber;
if(fFirstInFile)
{
rec.hdr.pot = fSubRunPOT;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Already present at the end of this scope.

Suggested change
rec.hdr.pot = fSubRunPOT;

rec.hdr.extcount = fEXTGateCount;
rec.hdr.nbnbinfo = fBNBInfo.size();
rec.hdr.bnbinfo = fBNBInfo;
rec.hdr.nnumiinfo = fNuMIInfo.size();
rec.hdr.numiinfo = fNuMIInfo;
rec.hdr.nextinfo = fEXTInfo.size();
rec.hdr.extinfo = fEXTInfo;
rec.hdr.pot = fSubRunPOT;
}

Expand Down Expand Up @@ -1907,6 +1927,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {

fBNBInfo.clear();
fNuMIInfo.clear();
fEXTInfo.clear();
fSRTrigger.clear();
rec.hdr.pot = 0;
}
Expand Down
15 changes: 15 additions & 0 deletions sbncode/CAFMaker/FillExposure.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@ namespace caf
NuMIInfo.back().daq_gates = info.daq_gates;
}
}

void FillExposureEXT(const std::vector<sbn::EXTCountInfo>& ext_count_info,
std::vector<caf::SREXTInfo>& EXTInfo,
double& subRunEXTGateCount) {
for (const sbn::EXTCountInfo &info: ext_count_info) {
subRunEXTGateCount += info.gates_since_last_trigger;
EXTInfo.emplace_back();
EXTInfo.back().gates_since_last_trigger = info.gates_since_last_trigger;
EXTInfo.back().isBNBOffBeam = info.isBNBOffBeam;
EXTInfo.back().isNuMIOffBeam = info.isNuMIOffBeam;
EXTInfo.back().isMajority = info.isMajority;
EXTInfo.back().isMinBias = info.isMinBias;
}
}

}
6 changes: 5 additions & 1 deletion sbncode/CAFMaker/FillExposure.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
#include "sbnanaobj/StandardRecord/SRNuMIInfo.h"
#include "sbnobj/Common/POTAccounting/NuMISpillInfo.h"
#include "sbnanaobj/StandardRecord/SREXTInfo.h"
#include "sbnobj/Common/POTAccounting/EXTCountInfo.h"

#include <vector>

Expand All @@ -20,7 +22,9 @@ namespace caf
std::vector<caf::SRNuMIInfo>& NuMIInfo,
double& subRunPOT);


void FillExposureEXT(const std::vector<sbn::EXTCountInfo>& ext_count_info,
std::vector<caf::SREXTInfo>& EXTInfo,
double& subRunEXTGateCount);
}

#endif