Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7c39515
first commit of offline pmtmetricsproducer (same as daq module), with…
lynnt20 Jan 17, 2025
c09be65
update to recent daq config
lynnt20 Feb 7, 2025
d6bffea
flash peak pe bug fix
lynnt20 Feb 26, 2025
dddb506
first commit of working MC software trigger producer
lynnt20 Nov 12, 2025
6c8f7e8
missing trig_ts in trig_metrics
lynnt20 Nov 12, 2025
d678d2e
create new subdirectory for software trigger thats in use
lynnt20 Nov 13, 2025
a3810cd
clean up cmakelists
lynnt20 Nov 14, 2025
ba13126
additions to keep offline same as online
lynnt20 Nov 14, 2025
98c76d5
remove ttree and update padding
lynnt20 Nov 14, 2025
a887bbb
simple readme
lynnt20 Nov 14, 2025
28647f5
clean up fcls, update metric labels to reflect current daq config
lynnt20 Nov 17, 2025
295670f
add config fcl for mc producer module
lynnt20 Nov 17, 2025
9c30759
add software trigger to detsim
lynnt20 Nov 17, 2025
736e8e2
add software trigger labels to cafmaker
lynnt20 Nov 17, 2025
62a399d
add software metric labels to cafmaker
lynnt20 Nov 17, 2025
1454ed4
update stream type to match daq config
lynnt20 Nov 17, 2025
7b4d608
undo changes AKA move fcls back to PMT subdirectory
lynnt20 Nov 17, 2025
7dfe7ce
restore deleted CMakeList
lynnt20 Nov 17, 2025
6d53206
rename producers to be consistent with daq config, add instance name …
lynnt20 Nov 17, 2025
30b810b
add fcl configurable ADC to PE conversion
lynnt20 Nov 17, 2025
634ad1c
add fcl configurable ADC to PE conversion
lynnt20 Nov 17, 2025
16bf1c4
update to the Run1 producer labels for pmtmetric in the DAQ
lynnt20 Nov 17, 2025
48c16c2
Merge branch 'develop' into feature/lynnt_Fall25_pmtmetrics
lynnt20 Nov 18, 2025
b938fe1
remove semicolon throwing fhicl error
lynnt20 Nov 18, 2025
12270a9
add pmtmetricmc config line and the `sbnd` tag to the config fcl
lynnt20 Nov 18, 2025
c498083
whoops
lynnt20 Nov 18, 2025
f9aac5d
add both run1/run2 daq labels
lynnt20 Nov 18, 2025
bc1008e
Merge branch 'develop' into feature/lynnt_Fall25_pmtmetrics
nathanielerowe Nov 21, 2025
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
3 changes: 3 additions & 0 deletions sbndcode/JobConfigurations/standard/caf/cafmakerjob_sbnd.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ physics.producers.cafmaker.FlashMatchSCECryoSuffixes: [""]
# Include 3D barycenter flahs matching
physics.producers.cafmaker.TPCPMTBarycenterMatchLabel: "tpcpmtbarycentermatching"

# Include MC version of PMT Software Trigger
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricmc"

# Overwrite weight_functions label:
physics.producers.fluxweight.weight_functions: @local::physics.producers.fluxweight.weight_functions_flux
physics.producers.geant4weight.weight_functions: @local::physics.producers.geant4weight.weight_functions_reint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_base.fcl"

physics.producers.cafmaker.BNBPOTDataLabel: "bnbinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricbnblight"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_base.fcl"

physics.producers.cafmaker.BNBPOTDataLabel: "sbndbnbzerobiasinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricbnbzero"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_base.fcl"

physics.producers.cafmaker.OffbeamBNBCountDataLabel: "bnbextinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricoffbeamlight"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_sce.fcl"

physics.producers.cafmaker.BNBPOTDataLabel: "bnbinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricbnblight"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_sce.fcl"

physics.producers.cafmaker.BNBPOTDataLabel: "sbndbnbzerobiasinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricbnbzero"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cafmakerjob_sbnd_data_sce.fcl"

physics.producers.cafmaker.OffbeamBNBCountDataLabel: "bnbextinfo"
physics.producers.cafmaker.SBNDSoftwareTriggerLabel: "pmtmetricoffbeamlight"
12 changes: 7 additions & 5 deletions sbndcode/JobConfigurations/standard/standard_detsim_sbnd.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "crtsimmodules_sbnd.fcl"
#include "opdetdigitizer_sbnd.fcl"
#include "rootoutput_sbnd.fcl"
#include "pmtmcmetricproducer.fcl"

process_name: DetSim

Expand Down Expand Up @@ -62,14 +63,15 @@ physics:

producers:
{
rns: { module_type: "RandomNumberSaver" }
simtpc2d: @local::sbnd_wcls_simsp_bothrois
crtsim: @local::sbnd_crtsim
opdaq: @local::sbnd_opdetdigitizer
rns: { module_type: "RandomNumberSaver" }
simtpc2d: @local::sbnd_wcls_simsp_bothrois
crtsim: @local::sbnd_crtsim
opdaq: @local::sbnd_opdetdigitizer
pmtmetricmc: @local::sbnd_pmtmcmetricproducer
}

#define the producer and filter modules for this path, order matters,
simulate: [rns, simtpc2d, crtsim, opdaq]
simulate: [rns, simtpc2d, crtsim, opdaq, pmtmetricmc]

#define the output stream, there could be more than one if using filters
stream1: [ out1 ]
Expand Down
7 changes: 3 additions & 4 deletions sbndcode/Trigger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(
MODULE_LIBRARIES
sbndcode_OpDetSim
larcorealg::Geometry
larcorealg::Geometry
larcore::Geometry_Geometry_service
lardataobj::Simulation
lardata::Utilities
Expand All @@ -16,7 +16,7 @@ set(
art::Framework_Services_Registry
art_root_io::tfile_support
art_root_io::TFileService_service
artdaq_core::artdaq-core_Data
artdaq_core::artdaq-core_Data
artdaq_core::artdaq-core_Utilities
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_Common
Expand All @@ -40,11 +40,10 @@ set(

add_subdirectory(CRT)
add_subdirectory(PMT)
add_subdirectory(PMTSoftware)

cet_build_plugin(ArtdaqFragmentProducer art::module SOURCE ArtdaqFragmentProducer_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(MetricProducer art::module SOURCE MetricProducer_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(MetricAnalyzer art::module SOURCE MetricAnalyzer_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(MetricFilter art::module SOURCE MetricFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})

install_headers()
install_fhicl()
Expand Down
4 changes: 1 addition & 3 deletions sbndcode/Trigger/PMT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ cet_build_plugin(pmtTriggerProducer art::module SOURCE pmtTriggerProducer_module

install_headers()
install_fhicl()
install_source()


install_source()
35 changes: 35 additions & 0 deletions sbndcode/Trigger/PMTSoftware/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
set(
MODULE_LIBRARIES
sbndcode_OpDetSim
lardataobj::RawData
art::Framework_Core
art::Framework_Principal
art::Framework_Services_Registry
art_root_io::tfile_support
art_root_io::TFileService_service
artdaq_core::artdaq-core_Data
artdaq_core::artdaq-core_Utilities
sbnobj::SBND_Timing
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_Common
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_SBND
sbndaq_artdaq_core::sbndaq-artdaq-core_Obj_SBND
canvas::canvas
messagefacility::MF_MessageLogger
fhiclcpp::fhiclcpp
cetlib::cetlib
CLHEP::CLHEP
ROOT::Core
ROOT::Tree
)

cet_build_plugin(MetricAnalyzer art::module SOURCE MetricAnalyzer_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(MetricFilter art::module SOURCE MetricFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(PMTMetricProducer art::module SOURCE PMTMetricProducer_module.cc LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(PMTMCMetricProducer art::module SOURCE PMTMCMetricProducer_module.cc LIBRARIES ${MODULE_LIBRARIES})

add_subdirectory(fcls)

install_headers()
install_fhicl()
install_source()
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ sbndaq::MetricAnalyzer::MetricAnalyzer(fhicl::ParameterSet const& p)
"pmtmetricbnblight",
"pmtmetricoffbeamzero",
"pmtmetricoffbeamlight",
"pmtmetriccrossingsmuon"});
fstream_labels = p.get<std::vector<int>>("stream_labels",{0,1,2,3,4,5});
"pmtmetriccrossingmuon",
"pmtmetricbnb",
"pmtmetricoffbeam"});
fstream_labels = p.get<std::vector<int>>("stream_labels",{0,1,2,3,4,5,6,7});
fmetric_instance_name = p.get<std::string>("metric_instance_name","");
fspectdc_module_label = p.get<std::string>("spectdc_module_name","tdcdecoder");
fspectdc_etrig_ch = p.get<uint32_t>("spectdc_etrig_ch",4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ sbndaq::MetricFilter::MetricFilter(fhicl::ParameterSet const& p)
// More initializers here.
{
fmetric_module_labels = p.get<std::vector<std::string>>("metric_module_labels",{"pmtmetricproducer",
"pmtmetricbnbzero",
"pmtmetricbnblight",
"pmtmetricoffbeamzero",
"pmtmetricoffbeamlight",
"pmtmetriccrossingmuon"});
"pmtmetricbnb",
"pmtmetricoffbeam",
"pmtmetriccrossingmuon"});
fmetric_instance_name = p.get<std::string>("metric_instance_name","");
ftime_min = p.get<float>("time_min",0);
ftime_max = p.get<float>("time_max",3);
Expand Down
171 changes: 171 additions & 0 deletions sbndcode/Trigger/PMTSoftware/PMTMCMetricProducer_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
////////////////////////////////////////////////////////////////////////
// Class: PMTMCMetricProducer
// Plugin Type: producer (Unknown Unknown)
// File: PMTMCMetricProducer_module.cc
//
// Generated at Mon Nov 10 11:37:29 2025 by Lynn Tung using cetskelgen
// from cetlib version 3.18.02.
// An MC version of the PMTMetricProducer (PMT Software Trigger).
// Creates a 10 us "flash" by summing waveforms around the beam spill.
// Input: raw::OpDetWaveforms from optical simualtion
// Output:: std::vector<sbnd::trigger::pmtSoftwareTrigger>>
////////////////////////////////////////////////////////////////////////

#include "art/Framework/Core/EDProducer.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 "canvas/Utilities/InputTag.h"
#include "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"

#include "sbndcode/OpDetSim/sbndPDMapAlg.hh"

#include "lardataobj/RawData/OpDetWaveform.h"
#include "sbndaq-artdaq-core/Obj/SBND/pmtSoftwareTrigger.hh"

#include <algorithm>
#include <memory>

#include <TTree.h>
#include <string.h>
#include "TH1D.h"
#include "TFile.h"

namespace sbnd {
namespace trigger {
class PMTMCMetricProducer;
}
}

class sbnd::trigger::PMTMCMetricProducer : public art::EDProducer {
public:
explicit PMTMCMetricProducer(fhicl::ParameterSet const& p);
// The compiler-generated destructor is fine for non-base
// classes without bare pointers or other resource use.

// Plugins should not be copied or assigned.
PMTMCMetricProducer(PMTMCMetricProducer const&) = delete;
PMTMCMetricProducer(PMTMCMetricProducer&&) = delete;
PMTMCMetricProducer& operator=(PMTMCMetricProducer const&) = delete;
PMTMCMetricProducer& operator=(PMTMCMetricProducer&&) = delete;

// Required functions.
void produce(art::Event& e) override;

private:

art::ServiceHandle<art::TFileService> tfs;
std::vector <std::string> fPDTypes;
std::string OpDetWaveformsLabel;
opdet::sbndPDMapAlg fPDSMap;
float fStartTime;
float fADCtoPE;

float us_to_ticks = 500.;
float ticks_to_us = 1./us_to_ticks;

std::vector <int> fChannelsToIgnore;
std::vector<uint32_t> sumWvfms(const std::vector<uint32_t>& v1, const std::vector<int16_t>& v2);
float estimateBaseline(std::vector<uint32_t> wvfm);
};


sbnd::trigger::PMTMCMetricProducer::PMTMCMetricProducer(fhicl::ParameterSet const& p)
: EDProducer{p} // ,
// More initializers here.
{
fPDTypes = p.get<std::vector<std::string>>("PDTypes");
OpDetWaveformsLabel = p.get< std::string >("OpDetWaveformsLabel");
fStartTime = p.get<float>("StartTime");
fChannelsToIgnore = p.get<std::vector<int>>("ChannelsToIgnore",{});
fADCtoPE = p.get<float>("ADCtoPE");

// Call appropriate produces<>() functions here.
produces< std::vector<sbnd::trigger::pmtSoftwareTrigger>>();
// Call appropriate consumes<>() for any products to be retrieved by this module.
}

void sbnd::trigger::PMTMCMetricProducer::produce(art::Event& e)
{

std::unique_ptr<std::vector<sbnd::trigger::pmtSoftwareTrigger>> trig_metrics_v = std::make_unique<std::vector<sbnd::trigger::pmtSoftwareTrigger>>();
sbnd::trigger::pmtSoftwareTrigger trig_metrics;

art::Handle< std::vector< raw::OpDetWaveform > > wvfHandle;
e.getByLabel(OpDetWaveformsLabel, wvfHandle);
if(!wvfHandle.isValid() || wvfHandle->size() == 0){
std::cout << "RawWaveform with label " << OpDetWaveformsLabel << " not found..." << std::endl;
e.put(std::move(trig_metrics_v));
return;
}

// hardcoded to match match data!
size_t flash_len=5000;
std::vector<uint32_t> flash(flash_len, 0);

float readout_start = fStartTime;
float readout_end = readout_start + flash_len*ticks_to_us;

int counter=0;
for(auto const& wvf : (*wvfHandle)) {
int wvf_ch = wvf.ChannelNumber();
auto wvf_ts = wvf.TimeStamp();
auto wvf_end = wvf_ts+wvf.Waveform().size()*ticks_to_us;

if (wvf_end < readout_start || wvf_ts > readout_end ) continue;
if (std::find(fChannelsToIgnore.begin(), fChannelsToIgnore.end(), wvf_ch) != fChannelsToIgnore.end() ) continue;
if (std::find(fPDTypes.begin(), fPDTypes.end(), fPDSMap.pdType(wvf_ch) ) == fPDTypes.end() ) continue;

// find where readout_start is
if (wvf_ts <= readout_start && wvf_end >= readout_end){
int offset = int((readout_start - wvf_ts)*us_to_ticks);
std::vector<short> wvfm_snippet(wvf.Waveform().begin() + offset, wvf.Waveform().begin() + offset + flash_len);
flash = sumWvfms(flash, wvfm_snippet);
counter++;
}
}

auto flash_baseline = estimateBaseline(flash);
auto flash_peak_it = std::min_element(flash.begin(),flash.end());
auto flash_peakpe = (flash_baseline-(*flash_peak_it))/fADCtoPE;
auto flash_peaktime = ((flash_peak_it-flash.begin()))*ticks_to_us + readout_start;

trig_metrics.foundBeamTrigger = true;
trig_metrics.nAboveThreshold = counter;
trig_metrics.promptPE = 0;
trig_metrics.prelimPE = 0;
trig_metrics.peakPE = flash_peakpe;
trig_metrics.peaktime = flash_peaktime;
trig_metrics.trig_ts = 0;
trig_metrics_v->push_back(trig_metrics);

e.put(std::move(trig_metrics_v));
}


std::vector<uint32_t> sbnd::trigger::PMTMCMetricProducer::sumWvfms(const std::vector<uint32_t>& v1,
const std::vector<int16_t>& v2)
{
size_t result_len = (v1.size() > v2.size()) ? v1.size() : v2.size();
std::vector<uint32_t> result(result_len,0);
for (size_t i = 0; i < result_len; i++){
auto value1 = (i < v1.size()) ? v1[i] : 2e4;
auto value2 = (i < v2.size()) ? v2[i] : 2e4;
result.at(i) = value1 + uint32_t(value2);
}
return result;
}


float sbnd::trigger::PMTMCMetricProducer::estimateBaseline(std::vector<uint32_t> wvfm){
// use a copy of 'wvfm' because nth_element might do something weird!
const auto median_it = wvfm.begin() + wvfm.size() / 2;
std::nth_element(wvfm.begin(), median_it , wvfm.end());
auto median = *median_it;
return median;
}

DEFINE_ART_MODULE(sbnd::trigger::PMTMCMetricProducer)
Loading