From 566daded0fefef4ee471456a72ca591ab2ea9539 Mon Sep 17 00:00:00 2001 From: kjplows Date: Thu, 10 Apr 2025 08:23:07 -0500 Subject: [PATCH 01/12] Update explicit references to 'EventWeightParameterSet::kMultisim' --- sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx b/sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx index 640a84769..14d9c68f8 100644 --- a/sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx +++ b/sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx @@ -261,7 +261,7 @@ namespace sbn { //Let's make a weights based on the calculator you have requested - if(fParameterSet.fRWType == EventWeightParameterSet::kMultisim){ + if(fParameterSet.fRWType == EventWeightParameterSet::kMultiSim){ for (size_t i=0;isecond[i]; @@ -293,7 +293,7 @@ namespace sbn { return weights;//done, all 1 }// Hadronic parent check - if(fParameterSet.fRWType == EventWeightParameterSet::kMultisim){ + if(fParameterSet.fRWType == EventWeightParameterSet::kMultiSim){ for (unsigned int i = 0; int(weights.size()) < NUni; i++) {//if all weights are 1, no need to calculate weights; std::pair test_weight; @@ -338,7 +338,7 @@ namespace sbn { }; }//Iterate through the number of universes - }//Yes, Multisim + }//Yes, MultiSim } if(count_weights){ From a0442281b318a78250046bd034f005630e26f7ab Mon Sep 17 00:00:00 2001 From: Anna Heggestuen Date: Mon, 2 Jun 2025 19:00:57 -0500 Subject: [PATCH 02/12] read PMTBeamSignal into the CAFMaker to be passed to FillICARUSOpFlash --- sbncode/CAFMaker/CAFMakerParams.h | 6 ++++++ sbncode/CAFMaker/CAFMaker_module.cc | 15 +++++++++++++-- sbncode/CAFMaker/CMakeLists.txt | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index 253f0d4c2..572bb5545 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -374,6 +374,12 @@ namespace caf "OpFlash" }; + Atom PMTBeamSignalLabel { + Name("PMTBeamSignalLabel"), + Comment("Label for special PMT beam timing signals used to build the beam bunch structure"), + "beamTiming:RWM" + }; + Atom CRTSimT0Offset { Name("CRTSimT0Offset"), Comment("start of beam gate/simulation time in the simulated CRT clock"), diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 48da84e8f..31212aec0 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1669,6 +1669,10 @@ void CAFMaker::produce(art::Event& evt) noexcept { std::vector srflashes; if(fDet == kICARUS) { + //Get all of the special PMT Beam Signals (to use as an opFlash reference time below) + art::Handle> PMTBeamSignal_handle; + GetByLabelStrict(evt, fParams.PMTBeamSignalLabel(), PMTBeamSignal_handle); + for (const std::string& pandora_tag_suffix : pandora_tag_suffixes) { art::Handle> flashes_handle; GetByLabelStrict(evt, fParams.OpFlashLabel() + pandora_tag_suffix, flashes_handle); @@ -1676,7 +1680,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { if (flashes_handle.isValid()) { const std::vector &opflashes = *flashes_handle; int cryostat = ( pandora_tag_suffix.find("W") != std::string::npos ) ? 1 : 0; - + // get associated OpHits for each OpFlash art::FindMany findManyHits(flashes_handle, evt, fParams.OpFlashLabel() + pandora_tag_suffix); @@ -1686,7 +1690,14 @@ void CAFMaker::produce(art::Event& evt) noexcept { std::vector const& ophits = findManyHits.at(iflash); srflashes.emplace_back(); - FillICARUSOpFlash(flash, ophits, cryostat, srflashes.back()); + if(PMTBeamSignal_handle.isValid() && isRealData){ + const std::vector &pmtbeamsignals = *PMTBeamSignal_handle; + FillICARUSOpFlash(flash, ophits, cryostat, pmtbeamsignals, srflashes.back()); + } + else{ + const std::vector pmtbeamsignals; + FillICARUSOpFlash(flash, ophits, cryostat, pmtbeamsignals, srflashes.back()); + } iflash++; } } diff --git a/sbncode/CAFMaker/CMakeLists.txt b/sbncode/CAFMaker/CMakeLists.txt index 76c3903d4..4cae127e2 100644 --- a/sbncode/CAFMaker/CMakeLists.txt +++ b/sbncode/CAFMaker/CMakeLists.txt @@ -35,6 +35,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker sbnobj::Common_CRT sbnobj::Common_Reco sbnobj::Common_Analysis + sbnobj::Common_PMT_Data sbnobj::SBND_CRT lardataalg::DetectorInfo art::Framework_Services_System_TriggerNamesService_service From 505cdc88702a885e9f64c756ad5a521b6a26521f Mon Sep 17 00:00:00 2001 From: Anna Heggestuen Date: Mon, 2 Jun 2025 19:06:33 -0500 Subject: [PATCH 03/12] within FillICARUSOpFlash, reconstruct the flash time w.r.t. RWM time using information stored in PMTBeamSignal --- sbncode/CAFMaker/FillReco.cxx | 6 ++++++ sbncode/CAFMaker/FillReco.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index d81cb5890..75c46cea5 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -183,6 +183,7 @@ namespace caf void FillICARUSOpFlash(const recob::OpFlash &flash, std::vector const& hits, int cryo, + std::vector RWMTimes, caf::SROpFlash &srflash, bool allowEmpty) { @@ -192,11 +193,16 @@ namespace caf srflash.timewidth = flash.TimeWidth(); double firstTime = std::numeric_limits::max(); + std::map startmap, risemap; for(const auto& hit: hits){ double const hitTime = hit->HasStartTime()? hit->StartTime(): hit->PeakTime(); if (firstTime > hitTime) firstTime = hitTime; + if (!RWMTimes.empty()) + sbn::timing::SelectFirstOpHitByTime(hit,startmap,risemap); } + srflash.rwmtime = getFlashBunchTime(risemap, RWMTimes); + std::cout << "Flash at Time " << flash.Time() << " has " << startmap.size() << " opHit channels, flashTime_rwm = " << srflash.rwmtime << " \n"; srflash.firsttime = firstTime; srflash.cryo = cryo; // 0 in SBND, 0/1 for E/W in ICARUS diff --git a/sbncode/CAFMaker/FillReco.h b/sbncode/CAFMaker/FillReco.h index 6e8ecf292..4b24b4a98 100644 --- a/sbncode/CAFMaker/FillReco.h +++ b/sbncode/CAFMaker/FillReco.h @@ -42,6 +42,7 @@ #include "sbnobj/SBND/CRT/CRTTrack.hh" #include "sbnobj/Common/CRT/CRTPMTMatching.hh" #include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh" +#include "sbnobj/Common/PMT/Data/PMTBeamSignal.hh" #include "nusimdata/SimulationBase/MCParticle.h" #include "nusimdata/SimulationBase/MCTruth.h" @@ -256,6 +257,7 @@ namespace caf void FillICARUSOpFlash(const recob::OpFlash &flash, std::vector const& hits, int cryo, + std::vector RWMTimes, caf::SROpFlash &srflash, bool allowEmpty = false); From 9aa0be95ae6243b768c7099dc5a622faeedd431a Mon Sep 17 00:00:00 2001 From: Anna Heggestuen Date: Mon, 2 Jun 2025 19:07:29 -0500 Subject: [PATCH 04/12] remove cout statement --- sbncode/CAFMaker/FillReco.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index 75c46cea5..0d69d594b 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -202,7 +202,6 @@ namespace caf sbn::timing::SelectFirstOpHitByTime(hit,startmap,risemap); } srflash.rwmtime = getFlashBunchTime(risemap, RWMTimes); - std::cout << "Flash at Time " << flash.Time() << " has " << startmap.size() << " opHit channels, flashTime_rwm = " << srflash.rwmtime << " \n"; srflash.firsttime = firstTime; srflash.cryo = cryo; // 0 in SBND, 0/1 for E/W in ICARUS From a492b433631af51e140042bae88e8aa7667f2cc6 Mon Sep 17 00:00:00 2001 From: Anna Heggestuen Date: Thu, 5 Jun 2025 14:17:32 -0500 Subject: [PATCH 05/12] remove startmap from SelectFirstOpHitByTime as it is not needed --- sbncode/CAFMaker/FillReco.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index 0d69d594b..cb3dc5f6c 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -193,13 +193,13 @@ namespace caf srflash.timewidth = flash.TimeWidth(); double firstTime = std::numeric_limits::max(); - std::map startmap, risemap; + std::map risemap; for(const auto& hit: hits){ double const hitTime = hit->HasStartTime()? hit->StartTime(): hit->PeakTime(); if (firstTime > hitTime) firstTime = hitTime; if (!RWMTimes.empty()) - sbn::timing::SelectFirstOpHitByTime(hit,startmap,risemap); + sbn::timing::SelectFirstOpHitByTime(hit,risemap); } srflash.rwmtime = getFlashBunchTime(risemap, RWMTimes); srflash.firsttime = firstTime; From 0f63559060a95327629ecc23a7844cb256e5513c Mon Sep 17 00:00:00 2001 From: Anna Heggestuen Date: Thu, 5 Jun 2025 14:33:47 -0500 Subject: [PATCH 06/12] use GetByLabelIfExists for PMTBeamSignalLabel --- 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 31212aec0..b2cdb15f8 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1671,7 +1671,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { { //Get all of the special PMT Beam Signals (to use as an opFlash reference time below) art::Handle> PMTBeamSignal_handle; - GetByLabelStrict(evt, fParams.PMTBeamSignalLabel(), PMTBeamSignal_handle); + GetByLabelIfExists(evt, fParams.PMTBeamSignalLabel(), PMTBeamSignal_handle); for (const std::string& pandora_tag_suffix : pandora_tag_suffixes) { art::Handle> flashes_handle; From f37272b9f4c193d1bb80329876d48a88cff2b3f8 Mon Sep 17 00:00:00 2001 From: kjplows Date: Wed, 30 Jul 2025 15:36:57 -0500 Subject: [PATCH 07/12] Update dependencies --- CMakeLists.txt | 2 +- ups/product_deps | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 176b4d3c9..6d2f8b3ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) find_package(cetmodules 3.20.00 REQUIRED) -project(sbncode VERSION 10.06.00.03 LANGUAGES CXX) +project(sbncode VERSION 10.06.00.04 LANGUAGES CXX) message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================") diff --git a/ups/product_deps b/ups/product_deps index efa661c7b..4d5dd8cb9 100644 --- a/ups/product_deps +++ b/ups/product_deps @@ -254,7 +254,7 @@ libdir fq_dir lib product version qual flags genie_xsec v3_04_00 - larcv2 v2_2_6 - -larsoft v10_06_00_01 - +larsoft v10_06_00_02 - sbnalg v10_06_00_03 - sbndaq_artdaq_core v1_10_06 - sbndata v01_07 - From f04aa0a1d7b770019964cf6f0e67f5b7c08b6622 Mon Sep 17 00:00:00 2001 From: kjplows Date: Mon, 11 Aug 2025 11:41:07 -0500 Subject: [PATCH 08/12] Updated dependencies --- CMakeLists.txt | 2 +- ups/product_deps | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d2f8b3ef..67af6b4fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) find_package(cetmodules 3.20.00 REQUIRED) -project(sbncode VERSION 10.06.00.04 LANGUAGES CXX) +project(sbncode VERSION 10.09.00 LANGUAGES CXX) message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================") diff --git a/ups/product_deps b/ups/product_deps index 4d5dd8cb9..07b483f3f 100644 --- a/ups/product_deps +++ b/ups/product_deps @@ -252,10 +252,10 @@ libdir fq_dir lib # #################################### product version qual flags -genie_xsec v3_04_00 - +genie_xsec v3_06_00 - larcv2 v2_2_6 - -larsoft v10_06_00_02 - -sbnalg v10_06_00_03 - +larsoft v10_09_00 - +sbnalg v10_09_00 - sbndaq_artdaq_core v1_10_06 - sbndata v01_07 - systematicstools v01_04_04 - From f8687208a3025120eba677efa5f8a79d68324ad4 Mon Sep 17 00:00:00 2001 From: VCLanNguyen Date: Tue, 12 Aug 2025 20:06:49 -0500 Subject: [PATCH 09/12] 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 10/12] 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 11/12] 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 12/12] 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){