Skip to content
Draft
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
11 changes: 11 additions & 0 deletions sbndcode/Decoders/PTB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_config.fcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN_PROLOG

SBNDPTBGateCountFilterConfig: {
module_type: SBNDPTBGateCountFilter
PTBInputLabel: "ptbdecoder"
Verbose: 0
}

END_PROLOG

115 changes: 115 additions & 0 deletions sbndcode/Decoders/PTB/SBNDPTBGateCountFilter_module.cc
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <string>
#include <vector>

// 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 <bitset>


#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<std::string>("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<std::vector<raw::ptb::sbndptb>> 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<art::Ptr<raw::ptb::sbndptb>> 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)
11 changes: 8 additions & 3 deletions sbndcode/PTBAna/PTBAnalysis_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ class sbnd::ptb::PTBAnalysis : public art::EDAnalyzer {
int _subrun;
int _event;


// HLTs
std::vector<uint64_t> _ptb_hlt_trigger;
std::vector<uint64_t> _ptb_hlt_timestamp;
std::vector<uint32_t> _ptb_hlt_gatecount;
std::vector<int> _ptb_hlt_trunmask;
std::vector<uint64_t> _ptb_hlt_unmask_timestamp;
std::vector<uint64_t> _ptb_llt_unmask_timestamp;
std::vector<int> _ptb_hlt_trunmask;
// LLTs
std::vector<uint64_t> _ptb_llt_trigger;
std::vector<uint64_t> _ptb_llt_timestamp;
std::vector<int> _ptb_llt_trunmask;
std::vector<uint64_t> _ptb_llt_unmask_timestamp;

std::vector<uint64_t> _ptb_chStatus_timestamp;
std::vector<uint64_t> _ptb_chStatus_beam;
Expand Down Expand Up @@ -123,6 +125,7 @@ sbnd::ptb::PTBAnalysis::PTBAnalysis(fhicl::ParameterSet const& p)
fTree->Branch("ptb_hlt_trunmask", "std::vector<int>", &_ptb_hlt_trunmask);
fTree->Branch("ptb_hlt_timestamp", "std::vector<uint64_t>", &_ptb_hlt_timestamp);
fTree->Branch("ptb_hlt_unmask_timestamp", "std::vector<uint64_t>", &_ptb_hlt_unmask_timestamp);
fTree->Branch("ptb_hlt_gatecount", "std::vector<uint32_t>", &_ptb_hlt_gatecount);
fTree->Branch("ptb_llt_unmask_timestamp", "std::vector<uint64_t>", &_ptb_llt_unmask_timestamp);
fTree->Branch("ptb_llt_trigger", "std::vector<uint64_t>", &_ptb_llt_trigger);
fTree->Branch("ptb_chStatus_timestamp", "std::vector<uint64_t>", &_ptb_chStatus_timestamp);
Expand Down Expand Up @@ -515,6 +518,7 @@ void sbnd::ptb::PTBAnalysis::AnalysePTBs(std::vector<art::Ptr<raw::ptb::sbndptb>

_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);

Expand All @@ -527,6 +531,7 @@ void sbnd::ptb::PTBAnalysis::AnalysePTBs(std::vector<art::Ptr<raw::ptb::sbndptb>
{
_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;
Expand Down