From b9f0b6c8cad1db94954b9c123d83bac33dc3ce6e Mon Sep 17 00:00:00 2001 From: Fran Nicolas Date: Tue, 11 Aug 2026 17:33:12 -0500 Subject: [PATCH 1/2] Add filter for PTB HLT with corrupted exposure accounting --- sbndcode/Decoders/PTB/CMakeLists.txt | 11 ++ .../PTB/SBNDPTBGateCountFilter_config.fcl | 10 ++ .../PTB/SBNDPTBGateCountFilter_module.cc | 115 ++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_config.fcl create mode 100644 sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_module.cc diff --git a/sbndcode/Decoders/PTB/CMakeLists.txt b/sbndcode/Decoders/PTB/CMakeLists.txt index 721fc406c..c8c337878 100644 --- a/sbndcode/Decoders/PTB/CMakeLists.txt +++ b/sbndcode/Decoders/PTB/CMakeLists.txt @@ -16,6 +16,17 @@ cet_build_plugin( SBNDPTBDecoder art::module ROOT::Core ) +cet_build_plugin( SBNDPTBGateCountFilter art::module + SOURCE SBNDPTBGateCountFilter_module.cc + LIBRARIES + artdaq_core::artdaq-core_Utilities + art::Utilities + fhiclcpp::fhiclcpp + messagefacility::MF_MessageLogger + art::Framework_Core + ROOT::Core +) + cet_make_library(SOURCE SBNDPTBRawUtils.cxx LIBRARIES diff --git a/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_config.fcl b/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_config.fcl new file mode 100644 index 000000000..b347c60b4 --- /dev/null +++ b/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_config.fcl @@ -0,0 +1,10 @@ +BEGIN_PROLOG + +SBNDPTBGateCountFilterConfig: { + module_type: SBNDPTBGateCountFilter + PTBInputLabel: "ptbdecoder" + Verbose: 0 +} + +END_PROLOG + diff --git a/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_module.cc b/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_module.cc new file mode 100644 index 000000000..6a57883d2 --- /dev/null +++ b/sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_module.cc @@ -0,0 +1,115 @@ +//////////////////////////////////////////////////////////////////////// +// Class: SBNDPTBGateCountFilter +// Plugin Type: art::EDFilter +// File: SBNDPTBGateCountFilter_module.cc +// Purpose: Filter events from the BNBLight stream with +// corrupted POT normalization data +//////////////////////////////////////////////////////////////////////// + +// C++ includes +#include +#include +#include + +// art includes +//#include "canvas/Utilities/InputTag.h" +#include "canvas/Persistency/Common/FindOneP.h" +#include "canvas/Persistency/Common/FindManyP.h" +#include "canvas/Persistency/Common/Ptr.h" +#include "art/Framework/Core/EDFilter.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" +#include + + +#include "sbndcode/Decoders/PTB/sbndptb.h" + + + +class SBNDPTBGateCountFilter : public art::EDFilter { + public: + + explicit SBNDPTBGateCountFilter(fhicl::ParameterSet const & pset); + virtual bool filter(art::Event& evt) override; + + private: + + // Fhicl parameters + std::string fPTBInputLabel; + int fVerbose; + + const int bnbLightHLT_id = 2; // HLT2 + const int bnbLowLightLLT_id = 6; // HLT6 + + int run; + int subrun; + int event; + +}; + + +SBNDPTBGateCountFilter::SBNDPTBGateCountFilter(fhicl::ParameterSet const & pset) +: EDFilter(pset), +fPTBInputLabel(pset.get("PTBInputLabel")) +{ + std::cout << "SBNDPTBGateCountFilter configured with PTBInputLabel: " << fPTBInputLabel << std::endl; +} + + +bool SBNDPTBGateCountFilter::filter(art::Event & evt){ + + run = evt.id().run(); + subrun = evt.id().subRun(); + event = evt.id().event(); + + + std::cout << "SBNDPTBGateCountFilter::Processing event: " << run << ":" << subrun << ":" << event << std::endl; + + // Get PTB decoded data + art::Handle> ptbHandle; + evt.getByLabel(fPTBInputLabel, ptbHandle); + if(!ptbHandle.isValid()){ + // If the handle is not valid, thow an exception + throw art::Exception(art::errors::ProductNotFound) + << "Could not find PTB data with label: " << fPTBInputLabel << std::endl; + } + std::vector> ptbVec; + art::fill_ptr_vector(ptbVec, ptbHandle); + + // Loop over PTB data and check for HLT2 and HLT6 triggers + for (auto const& ptb : ptbVec) { + + // Loop over HLT trigger words in the PTB data + for (unsigned i = 0; i < ptb->GetNHLTriggers(); ++i) { + auto const& hlt = ptb->GetHLTrigger(i); + int hlt_word = hlt.trigger_word; + uint64_t timestamp = hlt.timestamp; + + std::cout << "HLT word: " << std::bitset<32>(hlt_word) + << ", timestamp: " << timestamp << std::endl; + + // Look for the first HLT2 (BNBLight) instance in the event + if (hlt_word & (1 << bnbLightHLT_id)) { + + // If first HLT2 instance in the event — decision point + // Check if HLT6 (BNBLowLight) is also present in the same trigger word + bool hasHLT6 = hlt_word & (1 << bnbLowLightLLT_id); + std::cout << "Event " << run << ":" << subrun << ":" << event + << " - first HLT2 instance" + << (hasHLT6 ? ", coincident with HLT6. Filtering out." : ".") + << std::endl; + return !hasHLT6; // false filters out, true keeps event + } + } + } + + return true; // return true for other data streams (i.e. not BNBLight HLT2) + +} + +DEFINE_ART_MODULE(SBNDPTBGateCountFilter) From 98ecff3505a2422923c4e36c066df3ed4a885ede Mon Sep 17 00:00:00 2001 From: Fran Nicolas Date: Tue, 11 Aug 2026 17:35:21 -0500 Subject: [PATCH 2/2] Add gate counter to PTBAna for offline analysis --- sbndcode/PTBAna/PTBAnalysis_module.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sbndcode/PTBAna/PTBAnalysis_module.cc b/sbndcode/PTBAna/PTBAnalysis_module.cc index 2343f5fab..281323ffd 100644 --- a/sbndcode/PTBAna/PTBAnalysis_module.cc +++ b/sbndcode/PTBAna/PTBAnalysis_module.cc @@ -61,15 +61,17 @@ class sbnd::ptb::PTBAnalysis : public art::EDAnalyzer { int _subrun; int _event; - + // HLTs std::vector _ptb_hlt_trigger; std::vector _ptb_hlt_timestamp; + std::vector _ptb_hlt_gatecount; + std::vector _ptb_hlt_trunmask; std::vector _ptb_hlt_unmask_timestamp; - std::vector _ptb_llt_unmask_timestamp; - std::vector _ptb_hlt_trunmask; + // LLTs std::vector _ptb_llt_trigger; std::vector _ptb_llt_timestamp; std::vector _ptb_llt_trunmask; + std::vector _ptb_llt_unmask_timestamp; std::vector _ptb_chStatus_timestamp; std::vector _ptb_chStatus_beam; @@ -123,6 +125,7 @@ sbnd::ptb::PTBAnalysis::PTBAnalysis(fhicl::ParameterSet const& p) fTree->Branch("ptb_hlt_trunmask", "std::vector", &_ptb_hlt_trunmask); fTree->Branch("ptb_hlt_timestamp", "std::vector", &_ptb_hlt_timestamp); fTree->Branch("ptb_hlt_unmask_timestamp", "std::vector", &_ptb_hlt_unmask_timestamp); + fTree->Branch("ptb_hlt_gatecount", "std::vector", &_ptb_hlt_gatecount); fTree->Branch("ptb_llt_unmask_timestamp", "std::vector", &_ptb_llt_unmask_timestamp); fTree->Branch("ptb_llt_trigger", "std::vector", &_ptb_llt_trigger); fTree->Branch("ptb_chStatus_timestamp", "std::vector", &_ptb_chStatus_timestamp); @@ -515,6 +518,7 @@ void sbnd::ptb::PTBAnalysis::AnalysePTBs(std::vector _ptb_hlt_trigger.resize(nHLTs); _ptb_hlt_timestamp.resize(nHLTs); + _ptb_hlt_gatecount.resize(nHLTs); _ptb_hlt_trunmask.resize(nHLTs); _ptb_hlt_unmask_timestamp.resize(nHLTs); @@ -527,6 +531,7 @@ void sbnd::ptb::PTBAnalysis::AnalysePTBs(std::vector { _ptb_hlt_trigger[h_i] = ptb->GetHLTrigger(i).trigger_word; _ptb_hlt_timestamp[h_i] = ptb->GetHLTrigger(i).timestamp; //Units can be found in the Decoder Module + _ptb_hlt_gatecount[h_i] = ptb->GetHLTrigger(i).gate_counter; h_i++; int val = ptb->GetHLTrigger(i).trigger_word;