From f8687208a3025120eba677efa5f8a79d68324ad4 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 12 Aug 2025 20:06:49 -0500 Subject: [PATCH 01/13] first commit --- sbncode/CAFMaker/CAFMakerParams.h | 12 ++++++++++++ sbncode/CAFMaker/CAFMaker_module.cc | 25 +++++++++++++++++++++++++ sbncode/CAFMaker/FillReco.cxx | 25 +++++++++++++++++++++++++ sbncode/CAFMaker/FillReco.h | 9 +++++++++ 4 files changed, 71 insertions(+) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index 253f0d4c2..2f44fea03 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -338,6 +338,18 @@ namespace caf "crttracks" // sbnd }; + Atom SBNDFrameShiftInfoLabel { + Name("SBNDFrameShiftInfoLabel"), + Comment("Label of sbnd frame shift."), + "reco1" // sbnd + }; + + Atom SBNDTimingInfoLabel { + Name("SBNDTimingInfoLabel"), + Comment("Label of sbnd timing shift."), + "reco1" // sbnd + }; + Atom CRTPMTLabel { Name("CRTPMTLabel"), Comment("Label for the CRTPMT Matched variables from the crtpmt data product"), diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 48da84e8f..cb99173a9 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1603,6 +1603,8 @@ void CAFMaker::produce(art::Event& evt) noexcept { std::vector srcrttracks; std::vector srcrtspacepoints; std::vector srsbndcrttracks; + std::vector srsbndframeshiftinfo; + std::vector srsbndtiminginfo; if(fDet == kICARUS) { @@ -1651,6 +1653,29 @@ void CAFMaker::produce(art::Event& evt) noexcept { FillSBNDCRTTrack(sbndcrttracks[i], srsbndcrttracks.back()); } } + + art::Handle> sbndframeshiftinfo_handle; + GetByLabelStrict(evt, fParams.SBNDFrameShiftInfoLabel(), sbndframeshiftinfo_handle); + // fill into event + if (sbndframeshiftinfo_handle.isValid()) { + const std::vector &sbndframeshiftinfo = *sbndframeshiftinfo_handle; + for (unsigned i = 0; i < sbndframeshiftinfo.size(); i++) { + srsbndframeshiftinfo.emplace_back(); + FillSBNDFrameShiftInfo(sbndframeshiftinfo[i], srsbndframeshiftinfo.back()); + } + } + + art::Handle> sbndtiminginfo_handle; + GetByLabelStrict(evt, fParams.SBNDTimingInfoLabel(), sbndtiminginfo_handle); + // fill into event + if (sbndtiminginfo_handle.isValid()) { + const std::vector &sbndtiminginfo = *sbndtiminginfo_handle; + for (unsigned i = 0; i < sbndtiminginfo.size(); i++) { + srsbndtiminginfo.emplace_back(); + FillSBNDTimingInfo(sbndtiminginfo[i], srsbndtiminginfo.back()); + } + } + } // Get all of the CRTPMT Matches diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index d81cb5890..89b6e378e 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -141,6 +141,31 @@ namespace caf srsbndcrttrack.tof = track.ToF(); } + void FillSBNDFrameShiftInfo(const raw::FrameShiftInfo &frame, + caf::SRSBNDFrameShiftInfo &srsbndframe, + bool allowEmpty) + { + srsbndframe.frameTdcCrtt1 = frame.frameTdcCrtt1; + srsbndframe.frameTdcBes = frame.frameTdcBes; + srsbndframe.frameTdcRwm = frame.frameTdcRwm; + srsbndframe.frameHltCrtt1 = frame.frameHltCrtt1; + srsbndframe.frameHltBeamGate = frame.frameHltBeamGate; + srsbndframe.frameDataToMC = frame.frameDataToMC; + } + + void FillSBNDTimingInfo(const raw::TimingInfo &timing, + caf::SRSBNDTimingInfo &srsbndtiming, + bool allowEmpty) + { + srsbndtiming.tdcCrtt1 = timing.tdcCrtt1; + srsbndtiming.tdcBes = timing.tdcBes; + srsbndtiming.tdcRwm = timing.tdcRwm; + srsbndtiming.tdcEtrig = timing.tdcEtrig; + srsbndtiming.hltCrtt1 = timing.hltCrtt1; + srsbndtiming.hltEtrig = timing.hltEtrig; + srsbndtiming.hltBeamGate = timing.hltBeamGate; + } + void FillCRTPMTMatch(const sbn::crt::CRTPMTMatching &match, caf::SRCRTPMTMatch &srmatch, bool allowEmpty){ diff --git a/sbncode/CAFMaker/FillReco.h b/sbncode/CAFMaker/FillReco.h index 6e8ecf292..a301faba5 100644 --- a/sbncode/CAFMaker/FillReco.h +++ b/sbncode/CAFMaker/FillReco.h @@ -44,6 +44,7 @@ #include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh" #include "nusimdata/SimulationBase/MCParticle.h" #include "nusimdata/SimulationBase/MCTruth.h" +#include "sbndcode/Timing/SBNDRawTimingObj.h" #include "sbnanaobj/StandardRecord/SRSlice.h" #include "sbnanaobj/StandardRecord/StandardRecord.h" @@ -279,6 +280,14 @@ namespace caf caf::SRPFP& srpfp, bool allowEmpty = false); + void FillSBNDFrameShiftInfo(const raw::FrameShiftInfo &frame, + caf::SRSBNDFrameShiftInfo &srsbndframe, + bool allowEmpty = false); + + void FillSBNDTimingInfo(const raw::TimingInfo &timing, + caf::SRSBNDTimingInfo &srsbndtiming, + bool allowEmpty = false); + template void CopyPropertyIfSet( const std::map& props, const std::string& search, U& value ); } From b0dd48bfc485f35f5ba2043c78ba407aa61fee28 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Mon, 25 Aug 2025 19:35:52 -0500 Subject: [PATCH 02/13] correct timing in Caf --- sbncode/CAFMaker/CAFMakerParams.h | 4 +- sbncode/CAFMaker/CAFMaker_module.cc | 65 ++++++++++++++++++++++++++++- sbncode/CAFMaker/FillReco.cxx | 3 +- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index 2f44fea03..adc0ae0df 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -341,13 +341,13 @@ namespace caf Atom SBNDFrameShiftInfoLabel { Name("SBNDFrameShiftInfoLabel"), Comment("Label of sbnd frame shift."), - "reco1" // sbnd + "framshift" // sbnd }; Atom SBNDTimingInfoLabel { Name("SBNDTimingInfoLabel"), Comment("Label of sbnd timing shift."), - "reco1" // sbnd + "frameshift" // sbnd }; Atom CRTPMTLabel { diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index cb99173a9..68b3fb529 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -316,6 +316,9 @@ class CAFMaker : public art::EDProducer { void FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time); void FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_time, double CRTT1_reference_time); + void SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame); + void SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame); + /// Equivalent of FindManyP except a return that is !isValid() prints a /// messsage and aborts if StrictMode is true. template @@ -499,6 +502,41 @@ void CAFMaker::BlindEnergyParameters(StandardRecord* brec) { } } +void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame){ + + //CRT Space Point + for (SRCRTSpacePoint &sp: rec.crt_spacepoints){ + sp.time += SBNDFrame; //ns + } + + //CRT Track + for (SRSBNDCRTTrack &trk: rec.sbnd_crt_tracks){ + trk.time += SBNDFrame; //ns + } + + //CRT Space Point and Track Match + for (SRPFP &pfp: rec.reco.pfp) { + pfp.trk.crtspacepoint.spacepoint.time += SBNDFrame; + pfp.trk.crtsbndtrack.track.time += SBNDFrame; + } +} + +void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame){ + + double SBNDFrame_us = SBNDFrame / 1000.0; //convert ns to us + + //Op Flash + for (SROpFlash &opf: rec.opflashes) { + opf.time += SBNDFrame_us; + opf.firsttime += SBNDFrame_us; + } + + //OpT0 match to slice + for (SRSlice &s: rec.slc) { + s.opt0.time += SBNDFrame_us; + } +} + void CAFMaker::FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time) { // Fix the flashes for (SROpFlash &f: rec.opflashes) { @@ -2382,6 +2420,11 @@ void CAFMaker::produce(art::Event& evt) noexcept { rec.nsbnd_crt_tracks = srsbndcrttracks.size(); rec.opflashes = srflashes; rec.nopflashes = srflashes.size(); + rec.sbnd_frames = srsbndframeshiftinfo; + rec.nsbnd_frames = srsbndframeshiftinfo.size(); + rec.sbnd_timings = srsbndtiminginfo; + rec.nsbnd_timings = srsbndtiminginfo.size(); + if (fParams.FillTrueParticles()) { rec.true_particles = true_particles; } @@ -2389,7 +2432,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { rec.crtpmt_matches = srcrtpmtmatches; rec.ncrtpmt_matches = srcrtpmtmatches.size(); - // Fix the Reference time + // ICARUS: Fix the Reference time // // We want MC and Data to have the same reference time. // In MC/LArSoft the "reference time" is canonically defined @@ -2421,6 +2464,26 @@ void CAFMaker::produce(art::Event& evt) noexcept { FixPMTReferenceTimes(rec, PMT_reference_time); // TODO: TPC? + + // SBND: Fix the Reference time (See docdb# ????? and FrameShift module on sbndcode repo) + + if (isRealData & (fDet == kSBND)) + { + mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND" ; + + //Should only be 1 set of frame per event, if not, something is really wrong and nothing should be corrected + if (rec.nsbnd_frames == 1) + { + SRSBNDFrameShiftInfo frame = rec.sbnd_frames.at(0); + + //shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match + SBNDShiftCRTReference(rec, frame.frameApplyAtCaf); + + //shift reference frame for PMT objects: opflash, opt0 + SBNDShiftPMTReference(rec, frame.frameApplyAtCaf); + } + + } // Get metadata information for header unsigned int run = evt.run(); diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index 89b6e378e..29cb2bf5a 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -145,12 +145,13 @@ namespace caf caf::SRSBNDFrameShiftInfo &srsbndframe, bool allowEmpty) { + srsbndframe.timingType = frame.timingType; srsbndframe.frameTdcCrtt1 = frame.frameTdcCrtt1; srsbndframe.frameTdcBes = frame.frameTdcBes; srsbndframe.frameTdcRwm = frame.frameTdcRwm; srsbndframe.frameHltCrtt1 = frame.frameHltCrtt1; srsbndframe.frameHltBeamGate = frame.frameHltBeamGate; - srsbndframe.frameDataToMC = frame.frameDataToMC; + srsbndframe.frameApplyAtCaf = frame.frameApplyAtCaf; } void FillSBNDTimingInfo(const raw::TimingInfo &timing, From 4f49aba2eb0be7ec0a15782c6c81d437c2780731 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 26 Aug 2025 15:30:41 -0500 Subject: [PATCH 03/13] add fixes --- sbncode/CAFMaker/CAFMakerParams.h | 2 +- sbncode/CAFMaker/CAFMaker_module.cc | 50 ++++++++++------------------- sbncode/CAFMaker/FillReco.cxx | 1 + 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index adc0ae0df..2ee91d866 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -341,7 +341,7 @@ namespace caf Atom SBNDFrameShiftInfoLabel { Name("SBNDFrameShiftInfoLabel"), Comment("Label of sbnd frame shift."), - "framshift" // sbnd + "frameshift" // sbnd }; Atom SBNDTimingInfoLabel { diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 68b3fb529..0cc74b544 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1641,8 +1641,8 @@ void CAFMaker::produce(art::Event& evt) noexcept { std::vector srcrttracks; std::vector srcrtspacepoints; std::vector srsbndcrttracks; - std::vector srsbndframeshiftinfo; - std::vector srsbndtiminginfo; + caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo; + caf::SRSBNDTimingInfo srsbndtiminginfo; if(fDet == kICARUS) { @@ -1691,29 +1691,22 @@ void CAFMaker::produce(art::Event& evt) noexcept { FillSBNDCRTTrack(sbndcrttracks[i], srsbndcrttracks.back()); } } - - art::Handle> sbndframeshiftinfo_handle; + + art::Handle sbndframeshiftinfo_handle; GetByLabelStrict(evt, fParams.SBNDFrameShiftInfoLabel(), sbndframeshiftinfo_handle); // fill into event if (sbndframeshiftinfo_handle.isValid()) { - const std::vector &sbndframeshiftinfo = *sbndframeshiftinfo_handle; - for (unsigned i = 0; i < sbndframeshiftinfo.size(); i++) { - srsbndframeshiftinfo.emplace_back(); - FillSBNDFrameShiftInfo(sbndframeshiftinfo[i], srsbndframeshiftinfo.back()); - } + raw::FrameShiftInfo const& sbndframeshiftinfo(*sbndframeshiftinfo_handle); + FillSBNDFrameShiftInfo(sbndframeshiftinfo, srsbndframeshiftinfo); } - art::Handle> sbndtiminginfo_handle; + art::Handle sbndtiminginfo_handle; GetByLabelStrict(evt, fParams.SBNDTimingInfoLabel(), sbndtiminginfo_handle); // fill into event if (sbndtiminginfo_handle.isValid()) { - const std::vector &sbndtiminginfo = *sbndtiminginfo_handle; - for (unsigned i = 0; i < sbndtiminginfo.size(); i++) { - srsbndtiminginfo.emplace_back(); - FillSBNDTimingInfo(sbndtiminginfo[i], srsbndtiminginfo.back()); - } + raw::TimingInfo const& sbndtiminginfo(*sbndtiminginfo_handle); + FillSBNDTimingInfo(sbndtiminginfo, srsbndtiminginfo); } - } // Get all of the CRTPMT Matches @@ -2421,9 +2414,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { rec.opflashes = srflashes; rec.nopflashes = srflashes.size(); rec.sbnd_frames = srsbndframeshiftinfo; - rec.nsbnd_frames = srsbndframeshiftinfo.size(); rec.sbnd_timings = srsbndtiminginfo; - rec.nsbnd_timings = srsbndtiminginfo.size(); if (fParams.FillTrueParticles()) { rec.true_particles = true_particles; @@ -2465,24 +2456,17 @@ void CAFMaker::produce(art::Event& evt) noexcept { // TODO: TPC? - // SBND: Fix the Reference time (See docdb# ????? and FrameShift module on sbndcode repo) - + // SBND: Fix the Reference time in data depending on the stream (See FrameShift module on sbndcode repo) if (isRealData & (fDet == kSBND)) { - mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND" ; - - //Should only be 1 set of frame per event, if not, something is really wrong and nothing should be corrected - if (rec.nsbnd_frames == 1) - { - SRSBNDFrameShiftInfo frame = rec.sbnd_frames.at(0); - - //shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match - SBNDShiftCRTReference(rec, frame.frameApplyAtCaf); - - //shift reference frame for PMT objects: opflash, opt0 - SBNDShiftPMTReference(rec, frame.frameApplyAtCaf); - } + mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" + << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; + + //shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match + SBNDShiftCRTReference(rec, rec.sbnd_frames.frameApplyAtCaf); + //shift reference frame for PMT objects: opflash, opt0 + SBNDShiftPMTReference(rec, rec.sbnd_frames.frameApplyAtCaf); } // Get metadata information for header diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index 29cb2bf5a..15356240e 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -158,6 +158,7 @@ namespace caf caf::SRSBNDTimingInfo &srsbndtiming, bool allowEmpty) { + srsbndtiming.rawDAQHeaderTimestamp = timing.rawDAQHeaderTimestamp; srsbndtiming.tdcCrtt1 = timing.tdcCrtt1; srsbndtiming.tdcBes = timing.tdcBes; srsbndtiming.tdcRwm = timing.tdcRwm; From ce919163e2ec245bd6e3e65bc3aa7f6d0b9b66ed Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Wed, 27 Aug 2025 23:56:33 -0500 Subject: [PATCH 04/13] undo frame shift for crt matched --- sbncode/CAFMaker/CAFMaker_module.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 0cc74b544..5965e0e2a 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -514,11 +514,11 @@ void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame){ trk.time += SBNDFrame; //ns } - //CRT Space Point and Track Match - for (SRPFP &pfp: rec.reco.pfp) { - pfp.trk.crtspacepoint.spacepoint.time += SBNDFrame; - pfp.trk.crtsbndtrack.track.time += SBNDFrame; - } + //TODO: CRT Space Point and Track Match + //for (SRPFP &pfp: rec.reco.pfp) { + // pfp.trk.crtspacepoint.spacepoint.time += SBNDFrame; + // pfp.trk.crtsbndtrack.track.time += SBNDFrame; + //} } void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame){ From 40d50a15de35aa9a9d47d8cf4cf7a0ed573d0384 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Fri, 29 Aug 2025 17:27:29 -0500 Subject: [PATCH 05/13] move products from sbndcode to sbnobj --- sbncode/CAFMaker/CAFMaker_module.cc | 10 +++++---- sbncode/CAFMaker/CMakeLists.txt | 1 + sbncode/CAFMaker/FillReco.cxx | 34 ++++++++++++++--------------- sbncode/CAFMaker/FillReco.h | 8 ++++--- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 5965e0e2a..870c813be 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -118,6 +118,8 @@ #include "sbnobj/Common/Trigger/ExtraTriggerInfo.h" #include "sbnobj/Common/Reco/CRUMBSResult.h" #include "sbnobj/Common/Reco/OpT0FinderResult.h" +#include "sbnobj/SBND/Timing/TimingInfo.hh" +#include "sbnobj/SBND/Timing/FrameShiftInfo.hh" // GENIE #include "Framework/EventGen/EventRecord.h" @@ -1692,19 +1694,19 @@ void CAFMaker::produce(art::Event& evt) noexcept { } } - art::Handle sbndframeshiftinfo_handle; + art::Handle sbndframeshiftinfo_handle; GetByLabelStrict(evt, fParams.SBNDFrameShiftInfoLabel(), sbndframeshiftinfo_handle); // fill into event if (sbndframeshiftinfo_handle.isValid()) { - raw::FrameShiftInfo const& sbndframeshiftinfo(*sbndframeshiftinfo_handle); + sbnd::timing::FrameShiftInfo const& sbndframeshiftinfo(*sbndframeshiftinfo_handle); FillSBNDFrameShiftInfo(sbndframeshiftinfo, srsbndframeshiftinfo); } - art::Handle sbndtiminginfo_handle; + art::Handle sbndtiminginfo_handle; GetByLabelStrict(evt, fParams.SBNDTimingInfoLabel(), sbndtiminginfo_handle); // fill into event if (sbndtiminginfo_handle.isValid()) { - raw::TimingInfo const& sbndtiminginfo(*sbndtiminginfo_handle); + sbnd::timing::TimingInfo const& sbndtiminginfo(*sbndtiminginfo_handle); FillSBNDTimingInfo(sbndtiminginfo, srsbndtiminginfo); } } diff --git a/sbncode/CAFMaker/CMakeLists.txt b/sbncode/CAFMaker/CMakeLists.txt index 76c3903d4..c141efa72 100644 --- a/sbncode/CAFMaker/CMakeLists.txt +++ b/sbncode/CAFMaker/CMakeLists.txt @@ -36,6 +36,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker sbnobj::Common_Reco sbnobj::Common_Analysis sbnobj::SBND_CRT + sbnobj::SBND_Timing lardataalg::DetectorInfo art::Framework_Services_System_TriggerNamesService_service sbncode_Metadata_MetadataSBN_service diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index 15356240e..94d1f3c9d 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -141,31 +141,31 @@ namespace caf srsbndcrttrack.tof = track.ToF(); } - void FillSBNDFrameShiftInfo(const raw::FrameShiftInfo &frame, + void FillSBNDFrameShiftInfo(const sbnd::timing::FrameShiftInfo &frame, caf::SRSBNDFrameShiftInfo &srsbndframe, bool allowEmpty) { - srsbndframe.timingType = frame.timingType; - srsbndframe.frameTdcCrtt1 = frame.frameTdcCrtt1; - srsbndframe.frameTdcBes = frame.frameTdcBes; - srsbndframe.frameTdcRwm = frame.frameTdcRwm; - srsbndframe.frameHltCrtt1 = frame.frameHltCrtt1; - srsbndframe.frameHltBeamGate = frame.frameHltBeamGate; - srsbndframe.frameApplyAtCaf = frame.frameApplyAtCaf; + srsbndframe.timingType = frame.TimingType(); + srsbndframe.frameTdcCrtt1 = frame.FrameTdcCrtt1(); + srsbndframe.frameTdcBes = frame.FrameTdcBes(); + srsbndframe.frameTdcRwm = frame.FrameTdcRwm(); + srsbndframe.frameHltCrtt1 = frame.FrameHltCrtt1(); + srsbndframe.frameHltBeamGate = frame.FrameHltBeamGate(); + srsbndframe.frameApplyAtCaf = frame.FrameApplyAtCaf(); } - void FillSBNDTimingInfo(const raw::TimingInfo &timing, + void FillSBNDTimingInfo(const sbnd::timing::TimingInfo &timing, caf::SRSBNDTimingInfo &srsbndtiming, bool allowEmpty) { - srsbndtiming.rawDAQHeaderTimestamp = timing.rawDAQHeaderTimestamp; - srsbndtiming.tdcCrtt1 = timing.tdcCrtt1; - srsbndtiming.tdcBes = timing.tdcBes; - srsbndtiming.tdcRwm = timing.tdcRwm; - srsbndtiming.tdcEtrig = timing.tdcEtrig; - srsbndtiming.hltCrtt1 = timing.hltCrtt1; - srsbndtiming.hltEtrig = timing.hltEtrig; - srsbndtiming.hltBeamGate = timing.hltBeamGate; + srsbndtiming.rawDAQHeaderTimestamp = timing.RawDAQHeaderTimestamp(); + srsbndtiming.tdcCrtt1 = timing.TdcCrtt1(); + srsbndtiming.tdcBes = timing.TdcBes(); + srsbndtiming.tdcRwm = timing.TdcRwm(); + srsbndtiming.tdcEtrig = timing.TdcEtrig(); + srsbndtiming.hltCrtt1 = timing.HltCrtt1(); + srsbndtiming.hltEtrig = timing.HltEtrig(); + srsbndtiming.hltBeamGate = timing.HltBeamGate(); } void FillCRTPMTMatch(const sbn::crt::CRTPMTMatching &match, diff --git a/sbncode/CAFMaker/FillReco.h b/sbncode/CAFMaker/FillReco.h index a301faba5..a79d0185d 100644 --- a/sbncode/CAFMaker/FillReco.h +++ b/sbncode/CAFMaker/FillReco.h @@ -42,9 +42,11 @@ #include "sbnobj/SBND/CRT/CRTTrack.hh" #include "sbnobj/Common/CRT/CRTPMTMatching.hh" #include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh" +#include "sbnobj/SBND/Timing/TimingInfo.hh" +#include "sbnobj/SBND/Timing/FrameShiftInfo.hh" + #include "nusimdata/SimulationBase/MCParticle.h" #include "nusimdata/SimulationBase/MCTruth.h" -#include "sbndcode/Timing/SBNDRawTimingObj.h" #include "sbnanaobj/StandardRecord/SRSlice.h" #include "sbnanaobj/StandardRecord/StandardRecord.h" @@ -280,11 +282,11 @@ namespace caf caf::SRPFP& srpfp, bool allowEmpty = false); - void FillSBNDFrameShiftInfo(const raw::FrameShiftInfo &frame, + void FillSBNDFrameShiftInfo(const sbnd::timing::FrameShiftInfo &frame, caf::SRSBNDFrameShiftInfo &srsbndframe, bool allowEmpty = false); - void FillSBNDTimingInfo(const raw::TimingInfo &timing, + void FillSBNDTimingInfo(const sbnd::timing::TimingInfo &timing, caf::SRSBNDTimingInfo &srsbndtiming, bool allowEmpty = false); From c95e4da5040d8e7eb82088f638cdec5d29bd1793 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 2 Sep 2025 14:30:14 -0500 Subject: [PATCH 06/13] address comments --- sbncode/CAFMaker/CAFMaker_module.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 870c813be..3ae6d18db 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -318,8 +318,8 @@ class CAFMaker : public art::EDProducer { void FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time); void FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_time, double CRTT1_reference_time); - void SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame); - void SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame); + void SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) const; + void SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) const; /// Equivalent of FindManyP except a return that is !isValid() prints a /// messsage and aborts if StrictMode is true. @@ -504,7 +504,7 @@ void CAFMaker::BlindEnergyParameters(StandardRecord* brec) { } } -void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame){ +void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) const { //CRT Space Point for (SRCRTSpacePoint &sp: rec.crt_spacepoints){ @@ -523,7 +523,7 @@ void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame){ //} } -void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame){ +void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) const { double SBNDFrame_us = SBNDFrame / 1000.0; //convert ns to us @@ -2416,7 +2416,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { rec.opflashes = srflashes; rec.nopflashes = srflashes.size(); rec.sbnd_frames = srsbndframeshiftinfo; - rec.sbnd_timings = srsbndtiminginfo; + rec.sbnd_timings = srsbndtiminginfo; if (fParams.FillTrueParticles()) { rec.true_particles = true_particles; @@ -2425,7 +2425,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { rec.crtpmt_matches = srcrtpmtmatches; rec.ncrtpmt_matches = srcrtpmtmatches.size(); - // ICARUS: Fix the Reference time + // Move the reference time of reconstructed objects from trigger time to beam spill/beam gate opening time. // // We want MC and Data to have the same reference time. // In MC/LArSoft the "reference time" is canonically defined @@ -2442,6 +2442,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { // filled with the default values, which are set to the numerical limits of double. // In this case, we should set the PMT_reference_time to 0. + // ICARUS: Fix the Reference time const bool hasValidTriggerTime = srtrigger.global_trigger_det_time > (std::numeric_limits::min() + std::numeric_limits::epsilon()) && @@ -2458,8 +2459,11 @@ void CAFMaker::produce(art::Event& evt) noexcept { // TODO: TPC? - // SBND: Fix the Reference time in data depending on the stream (See FrameShift module on sbndcode repo) - if (isRealData & (fDet == kSBND)) + // SBND: Fix the Reference time in data depending on the stream i + // For more information, see: + // https://sbn-docdb.fnal.gov/cgi-bin/sso/RetrieveFile?docid=43090 + + if (isRealData && (fDet == kSBND) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)) { mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; @@ -2754,7 +2758,6 @@ void CAFMaker::endJob() { if(fParams.CreateBlindedCAF() && fFlatFilep) AddMetadataToFile(fFlatFilep, metamap); } - } // end namespace caf DEFINE_ART_MODULE(caf::CAFMaker) //////////////////////////////////////////////////////////////////////// From e545454555a0f1aee81555fcbbf3f74771bc3e90 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 2 Sep 2025 15:56:27 -0500 Subject: [PATCH 07/13] initialise empty label --- sbncode/CAFMaker/CAFMaker_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 3ae6d18db..57b45b948 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2459,7 +2459,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { // TODO: TPC? - // SBND: Fix the Reference time in data depending on the stream i + // SBND: Fix the Reference time in data depending on the stream // For more information, see: // https://sbn-docdb.fnal.gov/cgi-bin/sso/RetrieveFile?docid=43090 From 2f079d4905aac0cd56f593cf50bad328d9430b1d Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 2 Sep 2025 16:04:41 -0500 Subject: [PATCH 08/13] remove label --- sbncode/CAFMaker/CAFMakerParams.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index 2ee91d866..28d2d6d66 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -341,13 +341,13 @@ namespace caf Atom SBNDFrameShiftInfoLabel { Name("SBNDFrameShiftInfoLabel"), Comment("Label of sbnd frame shift."), - "frameshift" // sbnd + "" // sbnd }; Atom SBNDTimingInfoLabel { Name("SBNDTimingInfoLabel"), Comment("Label of sbnd timing shift."), - "frameshift" // sbnd + "" // sbnd }; Atom CRTPMTLabel { From 691681d1399aaa89d9248039707c1af139b905fc Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 2 Sep 2025 16:24:05 -0500 Subject: [PATCH 09/13] catching NaN cases and 0 --- sbncode/CAFMaker/CAFMaker_module.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 57b45b948..ff5d9b869 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -506,6 +506,7 @@ void CAFMaker::BlindEnergyParameters(StandardRecord* brec) { void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) const { + std::cout << "hellooooo PMT " << std::endl; //CRT Space Point for (SRCRTSpacePoint &sp: rec.crt_spacepoints){ sp.time += SBNDFrame; //ns @@ -524,7 +525,7 @@ void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) cons } void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) const { - + std::cout << "hellooooo PMT " << std::endl; double SBNDFrame_us = SBNDFrame / 1000.0; //convert ns to us //Op Flash @@ -2463,16 +2464,18 @@ void CAFMaker::produce(art::Event& evt) noexcept { // For more information, see: // https://sbn-docdb.fnal.gov/cgi-bin/sso/RetrieveFile?docid=43090 - if (isRealData && (fDet == kSBND) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)) + if (isRealData && (fDet == kSBND)) { - mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" - << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; - - //shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match - SBNDShiftCRTReference(rec, rec.sbnd_frames.frameApplyAtCaf); + if ((rec.sbnd_frames.frameApplyAtCaf != kSignalingNaN) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)){ + mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" + << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; + + //shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match + SBNDShiftCRTReference(rec, rec.sbnd_frames.frameApplyAtCaf); - //shift reference frame for PMT objects: opflash, opt0 - SBNDShiftPMTReference(rec, rec.sbnd_frames.frameApplyAtCaf); + //shift reference frame for PMT objects: opflash, opt0 + SBNDShiftPMTReference(rec, rec.sbnd_frames.frameApplyAtCaf); + } } // Get metadata information for header From e489c77b637bdf3490e4ec1ea0f702b41751c0a6 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 2 Sep 2025 16:25:58 -0500 Subject: [PATCH 10/13] remove test comments --- sbncode/CAFMaker/CAFMaker_module.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index ff5d9b869..772d3a949 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -506,7 +506,6 @@ void CAFMaker::BlindEnergyParameters(StandardRecord* brec) { void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) const { - std::cout << "hellooooo PMT " << std::endl; //CRT Space Point for (SRCRTSpacePoint &sp: rec.crt_spacepoints){ sp.time += SBNDFrame; //ns @@ -525,7 +524,7 @@ void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) cons } void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) const { - std::cout << "hellooooo PMT " << std::endl; + double SBNDFrame_us = SBNDFrame / 1000.0; //convert ns to us //Op Flash From ee536944bad5588c75226752f7527b543a230d97 Mon Sep 17 00:00:00 2001 From: VCLanNguyen <74775793+VCLanNguyen@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:07:46 -0700 Subject: [PATCH 11/13] Update sbncode/CAFMaker/CAFMaker_module.cc with the correct Nan Check Co-authored-by: Gianluca Petrillo --- sbncode/CAFMaker/CAFMaker_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 772d3a949..8d6fcc7eb 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2465,7 +2465,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { if (isRealData && (fDet == kSBND)) { - if ((rec.sbnd_frames.frameApplyAtCaf != kSignalingNaN) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)){ + if (!std::isnan(rec.sbnd_frames.frameApplyAtCaf) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)){ mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; From 0cddf8860257ccb25c80e50f7046ada413358a53 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Wed, 3 Sep 2025 20:12:23 -0500 Subject: [PATCH 12/13] Fill SRTrigger --- sbncode/CAFMaker/CAFMaker_module.cc | 4 ++++ sbncode/CAFMaker/FillTrigger.cxx | 9 +++++++++ sbncode/CAFMaker/FillTrigger.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 8d6fcc7eb..e1f257f57 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -2465,6 +2465,10 @@ void CAFMaker::produce(art::Event& evt) noexcept { if (isRealData && (fDet == kSBND)) { + // Fill trigger info + FillTriggerSBND(srsbndtiminginfo, srtrigger); + + // Shift timing reference frame if (!std::isnan(rec.sbnd_frames.frameApplyAtCaf) && (rec.sbnd_frames.frameApplyAtCaf != 0.0)){ mf::LogInfo("CAFMaker") << "Setting Reference Timing for timing object in SBND \n" << " Shift Apply At Caf Level = " << rec.sbnd_frames.frameApplyAtCaf << " ns\n"; diff --git a/sbncode/CAFMaker/FillTrigger.cxx b/sbncode/CAFMaker/FillTrigger.cxx index 009deccef..8bf82c02c 100644 --- a/sbncode/CAFMaker/FillTrigger.cxx +++ b/sbncode/CAFMaker/FillTrigger.cxx @@ -35,4 +35,13 @@ namespace caf // TODO: fill others? } + void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo){ + + triggerInfo.global_trigger_time = timingInfo.hltEtrig; + triggerInfo.beam_gate_time_abs = timingInfo.hltBeamGate; + + double diff_ts = triggerInfo.global_trigger_det_time - triggerInfo.beam_gate_det_time; + triggerInfo.trigger_within_gate = diff_ts; + } + } diff --git a/sbncode/CAFMaker/FillTrigger.h b/sbncode/CAFMaker/FillTrigger.h index b83c2e9f0..ea1aab7eb 100644 --- a/sbncode/CAFMaker/FillTrigger.h +++ b/sbncode/CAFMaker/FillTrigger.h @@ -4,6 +4,7 @@ #include "sbnobj/Common/Trigger/ExtraTriggerInfo.h" #include "sbnobj/Common/Trigger/BeamBits.h" #include "sbnanaobj/StandardRecord/SRTrigger.h" +#include "sbnanaobj/StandardRecord/SRSBNDTimingInfo.h" #include "lardataobj/RawData/TriggerData.h" #include @@ -18,6 +19,7 @@ namespace caf void FillTriggerMC(double absolute_time, caf::SRTrigger& triggerInfo); + void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo); } #endif From e2c16b64d7dc0de841b7a822a49df3859fd52c7d Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Thu, 4 Sep 2025 12:18:04 -0500 Subject: [PATCH 13/13] fix trk-mathced CRT --- sbncode/CAFMaker/CAFMaker_module.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index e1f257f57..7fd5222fb 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -517,10 +517,13 @@ void CAFMaker::SBNDShiftCRTReference(StandardRecord &rec, double SBNDFrame) cons } //TODO: CRT Space Point and Track Match - //for (SRPFP &pfp: rec.reco.pfp) { - // pfp.trk.crtspacepoint.spacepoint.time += SBNDFrame; - // pfp.trk.crtsbndtrack.track.time += SBNDFrame; - //} + for (SRSlice &slc: rec.slc){ + for (SRPFP &pfp: slc.reco.pfp){ + if(!std::isnan(pfp.trk.crtspacepoint.score)) pfp.trk.crtspacepoint.spacepoint.time += SBNDFrame; + + if(!std::isnan(pfp.trk.crtsbndtrack.score)) pfp.trk.crtsbndtrack.track.time += SBNDFrame; + } + } } void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) const {