Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
151b2c9
Setup to start extended fragments feature
aliciavr Oct 9, 2025
1e492fd
Shift timing function
aliciavr Oct 9, 2025
3f93ceb
Waveforms decoding function
aliciavr Oct 9, 2025
b416a56
Add dump waveforms function
aliciavr Oct 9, 2025
0d9f644
Combine waveforms and correctly differentiates nominal from extended
aliciavr Oct 10, 2025
c1a42c0
Combine all extended fragments succesfully
aliciavr Oct 14, 2025
e165606
Add new comments for code documenting. New variable for debugging the…
aliciavr Oct 15, 2025
60036c5
Update SBN Document for reference
aliciavr Oct 15, 2025
2f7ff45
Add version number and update number of debug waveforms to 0
aliciavr Nov 5, 2025
15f34cd
First version of timing check implemented (some extended fragments do…
aliciavr Nov 6, 2025
3f44697
Add jittering debug option and combine fragments option
aliciavr Nov 7, 2025
f527fb8
refactor frameshift module to run at decode stage
VCLanNguyen Nov 11, 2025
7e7c3c4
add timing channel
VCLanNguyen Nov 12, 2025
8d8d8a1
add initialisation as max uint64_t
VCLanNguyen Nov 22, 2025
daa63dc
Use namespace and enumeration
henrylay97 Nov 24, 2025
6739521
Begin functionalisation
henrylay97 Nov 24, 2025
f7dead4
Make constexpr for regularly used cast
henrylay97 Nov 24, 2025
34e6ffe
Make function for formatting timestamp
henrylay97 Nov 24, 2025
500d130
Functionalise frame TDC/PTB definitions
henrylay97 Nov 24, 2025
a21b73f
Reduce duplication in final logic
henrylay97 Nov 24, 2025
4697328
Consistent indentation
henrylay97 Nov 24, 2025
8102b2e
Clean up fcl parameters and document
henrylay97 Nov 24, 2025
ce18cbd
Merge pull request #883 from SBNSoftware/feature/frameshift_refactor_…
VCLanNguyen Nov 24, 2025
43f7614
Update combination condition with timing features integrating the exp…
aliciavr Nov 24, 2025
6a24518
adjust fcl parameters
VCLanNguyen Nov 24, 2025
177f2b4
Add warning for some unexpected types of fragments and fix fragments …
aliciavr Nov 25, 2025
2d93ca4
Move constexpr upstream
henrylay97 Nov 25, 2025
857c9ed
Use FrameShiftInfo object in CRT data reconstruction
henrylay97 Nov 25, 2025
3ca8e1b
Add catch for NoShift and allow cutting on ETrig frame
henrylay97 Nov 25, 2025
d849488
add frameshift functionality instead of direclty referencing spec tdc…
lynnt20 Jan 23, 2026
370cd81
use the pmt calibdb to create the channel mapping
lynnt20 Jan 28, 2026
6dcca71
vectors are initialized with size,value using parantheses, not braces...
lynnt20 Jan 28, 2026
761ef7c
add sbnd services to include pmt calibdb + trigger emulation
lynnt20 Jan 28, 2026
c66aaa3
Merge pull request #912 from SBNSoftware/feature/frameshift_refactor_…
VCLanNguyen Feb 5, 2026
a32bc3d
update subsystem decoder fcl to include frameshift
VCLanNguyen Feb 5, 2026
57b8b56
Update LightPropagation module for new timing frmae
asanchezcastillo Feb 6, 2026
825c07d
clarify fcl param to only count the number of PMT channels per CAEN, …
lynnt20 Feb 6, 2026
c621ba3
update to include Run 2 HLT
VCLanNguyen Feb 6, 2026
f2bc6f9
Merge branch 'feature/frameshift_refactor_v10_11_01' of https://githu…
VCLanNguyen Feb 7, 2026
9e19ef9
Merge branch 'feature/frameshift_refactor_v10_11_01' of https://githu…
VCLanNguyen Feb 7, 2026
0ab99f6
grab the nanosecond part of timestemp
VCLanNguyen Feb 7, 2026
a27480d
Merge branch 'feature/aliciavr_XARAPUCA_offline_decoder_v4.0-extended…
aliciavr Feb 8, 2026
bb1ac48
feat (frameshift): Add frameshift module to the configuration and acc…
aliciavr Feb 12, 2026
7951a66
chore(frameshift): refactor get_frameshift_timestamp to improve funct…
aliciavr Feb 13, 2026
a2ea22b
clean up Frame Shift module
VCLanNguyen Feb 13, 2026
4356756
refactor(timing)\!: Remove access to SPEC-TDC and PTB. Change timing …
aliciavr Feb 13, 2026
d0c37f8
fix(debug): fix last sample time of the waveforms shown in the decode…
aliciavr Feb 13, 2026
a6ecce2
chore(cleaning): Clean output and restore to default configuration (c…
aliciavr Feb 13, 2026
39e8ff4
update Waveform Alignment module with the new frameshift module
VCLanNguyen Feb 13, 2026
07d5fbc
Merge pull request #914 from SBNSoftware/feature/aliciavr-XARAPUCA-of…
VCLanNguyen Feb 13, 2026
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
211 changes: 53 additions & 158 deletions sbndcode/CRT/CRTReco/CRTStripHitProducer_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@

#include "sbnobj/SBND/CRT/FEBData.hh"
#include "sbnobj/SBND/CRT/CRTStripHit.hh"
#include "sbnobj/SBND/Timing/DAQTimestamp.hh"
#include "sbnobj/SBND/Timing/FrameShiftInfo.hh"

#include "sbndcode/Geometry/GeometryWrappers/CRTGeoService.h"
#include "sbndcode/Decoders/PTB/sbndptb.h"
#include "sbndcode/Timing/SBNDRawTimingObj.h"
#include "sbndcode/ChannelMaps/CRT/CRTChannelMapService.h"

Expand All @@ -50,20 +49,23 @@ class sbnd::crt::CRTStripHitProducer : public art::EDProducer {
void produce(art::Event& e) override;

std::vector<CRTStripHit> CreateStripHits(art::Ptr<FEBData> &data, const uint32_t ref_time_s,
const uint32_t ref_time_ns);
const uint32_t ref_time_ns, const uint32_t etrig_time_s,
const uint32_t etrig_time_ns);
std::set<uint32_t> UnixSet(const std::vector<art::Ptr<FEBData>> &datas);
bool SPECTDCReference(art::Event& e, const uint64_t &raw_ts, uint64_t &ref_time);
bool PTBHLTReference(art::Event& e, const uint64_t &raw_ts, uint64_t &ref_time, uint32_t &hlt_code);

private:

art::ServiceHandle<CRTGeoService> fCRTGeoService;
art::ServiceHandle<SBND::CRTChannelMapService> fCRTChannelMapService;

std::string fFEBDataModuleLabel;
std::string fFrameShiftModuleLabel;
uint16_t fADCThreshold;
std::vector<double> fErrorCoeff;
bool fAllowFlag1;
bool fApplyETrigWindow;
double fETrigMin;
double fETrigMax;
bool fApplyTs0Window;
double fTs0Min;
double fTs0Max;
Expand All @@ -72,24 +74,19 @@ class sbnd::crt::CRTStripHitProducer : public art::EDProducer {
double fTs1Max;
bool fCorrectForDifferentSecond;
bool fReferenceTs0;
int fTimingType;
std::string fDAQHeaderModuleLabel;
std::string fDAQHeaderInstanceLabel;
uint32_t fRawTSCorrection;
uint32_t fMaxAllowedRefTimeDiff;
std::string fSPECTDCModuleLabel;
uint32_t fSPECTDCETrigChannel;
std::string fPTBModuleLabel;
std::vector<uint32_t> fAllowedPTBHLTs;
};


sbnd::crt::CRTStripHitProducer::CRTStripHitProducer(fhicl::ParameterSet const& p)
: EDProducer{p}
, fFEBDataModuleLabel(p.get<std::string>("FEBDataModuleLabel"))
, fFrameShiftModuleLabel(p.get<std::string>("FrameShiftModuleLabel"))
, fADCThreshold(p.get<uint16_t>("ADCThreshold"))
, fErrorCoeff(p.get<std::vector<double>>("ErrorCoeff"))
, fAllowFlag1(p.get<bool>("AllowFlag1"))
, fApplyETrigWindow(p.get<bool>("ApplyETrigWindow"))
, fETrigMin(p.get<double>("ETrigMin", 0))
, fETrigMax(p.get<double>("ETrigMax", std::numeric_limits<double>::max()))
, fApplyTs0Window(p.get<bool>("ApplyTs0Window"))
, fTs0Min(p.get<double>("Ts0Min", 0))
, fTs0Max(p.get<double>("Ts0Max", std::numeric_limits<double>::max()))
Expand All @@ -98,15 +95,6 @@ sbnd::crt::CRTStripHitProducer::CRTStripHitProducer(fhicl::ParameterSet const& p
, fTs1Max(p.get<double>("Ts1Max", std::numeric_limits<double>::max()))
, fCorrectForDifferentSecond(p.get<bool>("CorrectForDifferentSecond"))
, fReferenceTs0(p.get<bool>("ReferenceTs0"))
, fTimingType(p.get<int>("TimingType", 0))
, fDAQHeaderModuleLabel(p.get<std::string>("DAQHeaderModuleLabel", ""))
, fDAQHeaderInstanceLabel(p.get<std::string>("DAQHeaderInstanceLabel", ""))
, fRawTSCorrection(p.get<uint32_t>("RawTSCorrection", 0))
, fMaxAllowedRefTimeDiff(p.get<uint32_t>("MaxAllowedRefTimeDiff", 0))
, fSPECTDCModuleLabel(p.get<std::string>("SPECTDCModuleLabel", ""))
, fSPECTDCETrigChannel(p.get<uint32_t>("SPECTDCETrigChannel", 4))
, fPTBModuleLabel(p.get<std::string>("PTBModuleLabel", ""))
, fAllowedPTBHLTs(p.get<std::vector<uint32_t>>("AllowedPTBHLTs", {}))
{
produces<std::vector<CRTStripHit>>();
produces<art::Assns<FEBData, CRTStripHit>>();
Expand All @@ -127,66 +115,39 @@ void sbnd::crt::CRTStripHitProducer::produce(art::Event& e)
std::vector<art::Ptr<FEBData>> FEBDataVec;
art::fill_ptr_vector(FEBDataVec, FEBDataHandle);

uint64_t raw_ts = 0, ref_time = 0;
uint32_t ref_time_s = 0, ref_time_ns = 0;
uint32_t ref_time_s = 0, ref_time_ns = 0, etrig_time_s = 0, etrig_time_ns = 0;

if(fReferenceTs0)
{
art::Handle<artdaq::detail::RawEventHeader> DAQHeaderHandle;
e.getByLabel(fDAQHeaderModuleLabel, fDAQHeaderInstanceLabel, DAQHeaderHandle);
art::Handle<sbnd::timing::FrameShiftInfo> frameShiftHandle;
e.getByLabel(fFrameShiftModuleLabel, frameShiftHandle);

if(DAQHeaderHandle.isValid())
{
artdaq::RawEvent rawHeaderEvent = artdaq::RawEvent(*DAQHeaderHandle);
raw_ts = rawHeaderEvent.timestamp() - fRawTSCorrection;
}
if(!frameShiftHandle.isValid())
throw std::runtime_error("Frame Shift Info object is invalid, check data quality");

int timingType = fTimingType;
int timingCh = 0;
uint64_t ref_time = frameShiftHandle->FrameDefault();

if(timingType == 0)
{
uint64_t spec_tdc_ref_time = 0;

if(SPECTDCReference(e, raw_ts, spec_tdc_ref_time))
{
ref_time = spec_tdc_ref_time;
timingCh = fSPECTDCETrigChannel;
}
else
++timingType;
}
ref_time_s = ref_time / sbnd::timing::kSecondInNanoseconds;
ref_time_ns = ref_time % sbnd::timing::kSecondInNanoseconds;

if(timingType == 1)
{
uint64_t ptb_hlt_ref_time = 0;
uint32_t hlt_code = 0;

if(PTBHLTReference(e, raw_ts, ptb_hlt_ref_time, hlt_code))
{
ref_time = ptb_hlt_ref_time;
timingCh = hlt_code;
}
else
++timingType;
}
timingReferenceInfo->timingType = frameShiftHandle->TimingTypeDefault();
timingReferenceInfo->timingChannel = frameShiftHandle->TimingChannelDefault();

if(timingType == 2)
{
std::set<uint32_t> unix_set = UnixSet(FEBDataVec);
ref_time = unix_set.size() ? *unix_set.rbegin() * static_cast<uint64_t>(1e9) : 0;
}
if(timingReferenceInfo->timingType == sbnd::timing::kNoShiftType)
{
std::set<uint32_t> unix_set = UnixSet(FEBDataVec);
ref_time_s = unix_set.size() ? *unix_set.rbegin(): 0;
}

ref_time_s = ref_time / static_cast<uint64_t>(1e9);
ref_time_ns = ref_time % static_cast<uint64_t>(1e9);
uint64_t etrig_time = frameShiftHandle->FrameEtrig();

timingReferenceInfo->timingType = timingType;
timingReferenceInfo->timingChannel = timingCh;
etrig_time_s = etrig_time / sbnd::timing::kSecondInNanoseconds;
etrig_time_ns = etrig_time % sbnd::timing::kSecondInNanoseconds;
}

for(auto data : FEBDataVec)
{
std::vector<CRTStripHit> newStripHits = CreateStripHits(data, ref_time_s, ref_time_ns);
std::vector<CRTStripHit> newStripHits = CreateStripHits(data, ref_time_s, ref_time_ns, etrig_time_s, etrig_time_ns);

for(auto hit : newStripHits)
{
Expand All @@ -203,7 +164,8 @@ void sbnd::crt::CRTStripHitProducer::produce(art::Event& e)
}

std::vector<sbnd::crt::CRTStripHit> sbnd::crt::CRTStripHitProducer::CreateStripHits(art::Ptr<FEBData> &data, const uint32_t ref_time_s,
const uint32_t ref_time_ns)
const uint32_t ref_time_ns, const uint32_t etrig_time_s,
const uint32_t etrig_time_ns)
{
std::vector<CRTStripHit> stripHits;

Expand Down Expand Up @@ -249,6 +211,27 @@ std::vector<sbnd::crt::CRTStripHit> sbnd::crt::CRTStripHitProducer::CreateStripH
if(fReferenceTs0)
t0 -= ref_time_ns;

if(fApplyETrigWindow)
{
double t0_etrig = (int)data->Ts0() + module.t0DelayCorrection;
const int64_t unix_diff = static_cast<int64_t>(ref_time_s) - static_cast<int64_t>(etrig_time_s);

if(unix_diff < -1 || unix_diff > 1)
{
throw std::runtime_error(Form("Unix timestamps differ by more than 1 (%li)", unix_diff));
}

t0_etrig -= etrig_time_ns;

if(unix_diff == 1)
t0_etrig -= 1e9;
else if(unix_diff == -1)
t0_etrig += 1e9;

if(t0_etrig < fETrigMin || t0_etrig > fETrigMax)
return stripHits;
}

if(fApplyTs0Window && (t0 < fTs0Min || t0 > fTs0Max))
return stripHits;

Expand Down Expand Up @@ -309,92 +292,4 @@ std::set<uint32_t> sbnd::crt::CRTStripHitProducer::UnixSet(const std::vector<art
return set;
}

bool sbnd::crt::CRTStripHitProducer::SPECTDCReference(art::Event& e, const uint64_t &raw_ts, uint64_t &ref_time)
{
bool found = false;

art::Handle<std::vector<sbnd::timing::DAQTimestamp>> TDCHandle;
e.getByLabel(fSPECTDCModuleLabel, TDCHandle);

if(!TDCHandle.isValid() || TDCHandle->size() == 0)
return found;

std::vector<art::Ptr<sbnd::timing::DAQTimestamp>> TDCVec;
art::fill_ptr_vector(TDCVec, TDCHandle);

uint64_t min_diff = std::numeric_limits<int64_t>::max();
uint64_t min_diff_ts = 0;

for(auto ts : TDCVec)
{
if(ts->Channel() == fSPECTDCETrigChannel)
{
uint64_t diff = raw_ts > ts->Timestamp() ? raw_ts - ts->Timestamp() : ts->Timestamp() - raw_ts;

if(diff < min_diff)
{
min_diff = diff;
min_diff_ts = ts->Timestamp();
found = true;
}
}
}

if(min_diff > fMaxAllowedRefTimeDiff)
return false;

ref_time = min_diff_ts;

return found;
}

bool sbnd::crt::CRTStripHitProducer::PTBHLTReference(art::Event& e, const uint64_t &raw_ts, uint64_t &ref_time, uint32_t &hlt_code)
{
bool found = false;

art::Handle<std::vector<raw::ptb::sbndptb>> PTBHandle;
e.getByLabel(fPTBModuleLabel, PTBHandle);

if(!PTBHandle.isValid() || PTBHandle->size() == 0)
return found;

std::vector<art::Ptr<raw::ptb::sbndptb>> PTBVec;
art::fill_ptr_vector(PTBVec, PTBHandle);

uint64_t min_diff = std::numeric_limits<int64_t>::max();
uint64_t min_diff_ts = 0;

for(auto ptb : PTBVec)
{
for(auto hlt : ptb->GetHLTriggers())
{
uint64_t hlt_timestamp = (hlt.timestamp * 20);
std::bitset<32> hlt_word_bitset = std::bitset<32>(hlt.trigger_word);

for(uint32_t allowed_hlt : fAllowedPTBHLTs)
{
if(hlt_word_bitset[allowed_hlt])
{
uint64_t diff = raw_ts > hlt_timestamp ? raw_ts - hlt_timestamp : hlt_timestamp - raw_ts;

if(diff < min_diff)
{
min_diff = diff;
min_diff_ts = hlt_timestamp;
hlt_code = allowed_hlt;
found = true;
}
}
}
}
}

if(min_diff > fMaxAllowedRefTimeDiff)
return false;

ref_time = min_diff_ts;

return found;
}

DEFINE_ART_MODULE(sbnd::crt::CRTStripHitProducer)
16 changes: 5 additions & 11 deletions sbndcode/CRT/CRTReco/crtrecoproducers_sbnd.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BEGIN_PROLOG
crtstriphitproducer_sbnd:
{
FEBDataModuleLabel: "crtsim"
FrameShiftModuleLabel: ""
ADCThreshold: 60
ErrorCoeff: [ 0.26, -0.27, 0.025 ]
AllowFlag1: false
Expand All @@ -17,20 +18,13 @@ crtstriphitproducer_sbnd:

crtstriphitproducer_data_sbnd: @local::crtstriphitproducer_sbnd
crtstriphitproducer_data_sbnd.FEBDataModuleLabel: "crtdecoder"
crtstriphitproducer_data_sbnd.FrameShiftModuleLabel: "frameshift"
crtstriphitproducer_data_sbnd.AllowFlag1: true
crtstriphitproducer_data_sbnd.CorrectForDifferentSecond: true
crtstriphitproducer_data_sbnd.ReferenceTs0: true
crtstriphitproducer_data_sbnd.TimingType: 0
crtstriphitproducer_data_sbnd.DAQHeaderModuleLabel: "daq"
crtstriphitproducer_data_sbnd.DAQHeaderInstanceLabel: "RawEventHeader"
crtstriphitproducer_data_sbnd.RawTSCorrection: 367000
crtstriphitproducer_data_sbnd.MaxAllowedRefTimeDiff: 3000000
crtstriphitproducer_data_sbnd.SPECTDCModuleLabel: "tdcdecoder"
crtstriphitproducer_data_sbnd.PTBModuleLabel: "ptbdecoder"
crtstriphitproducer_data_sbnd.AllowedPTBHLTs: [ 1, 2, 3, 4, 5, 14, 15 ]
crtstriphitproducer_data_sbnd.ApplyTs0Window: true
crtstriphitproducer_data_sbnd.Ts0Min: -1.71e6
crtstriphitproducer_data_sbnd.Ts0Max: 1.51e6
crtstriphitproducer_data_sbnd.ApplyETrigWindow: true
crtstriphitproducer_data_sbnd.ETrigMin: -1.71e6
crtstriphitproducer_data_sbnd.ETrigMax: 1.51e6

crtclusterproducer_sbnd:
{
Expand Down
42 changes: 0 additions & 42 deletions sbndcode/Decoders/CRT/run_crt_ptb_decoder_sbnd.fcl

This file was deleted.

4 changes: 3 additions & 1 deletion sbndcode/Decoders/CRT/run_crt_ptb_tdc_decoder_sbnd.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "crt_channel_map_service_sbnd.fcl"
#include "SBNDPTBDecoderDefaults.fcl"
#include "spectdc_decoder_sbnd.fcl"
#include "frameshift_sbnd_data.fcl"

process_name: Decoders

Expand Down Expand Up @@ -34,9 +35,10 @@ physics:
crtdecoder: @local::crt_decoder
ptbdecoder: @local::SBNDPTBDecoderDefaults
tdcdecoder: @local::spec_tdc_decoder_sbnd
frameshift: @local::frameshift_data
}

decoders: [ crtdecoder, ptbdecoder, tdcdecoder ]
decoders: [ crtdecoder, ptbdecoder, tdcdecoder, frameshift ]
trigger_paths: [ decoders ]

stream1: [ out1 ]
Expand Down
Loading