diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index 572bb5545..085be78e2 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."), + "frameshift" // sbnd + }; + + Atom SBNDTimingInfoLabel { + Name("SBNDTimingInfoLabel"), + Comment("Label of sbnd timing shift."), + "frameshift" // 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 f51183b46..263f14797 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 + } + + //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){ + + 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) { @@ -1602,6 +1640,8 @@ void CAFMaker::produce(art::Event& evt) noexcept { std::vector srcrttracks; std::vector srcrtspacepoints; std::vector srsbndcrttracks; + caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo; + caf::SRSBNDTimingInfo srsbndtiminginfo; if(fDet == kICARUS) { @@ -1650,6 +1690,22 @@ 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()) { + raw::FrameShiftInfo const& sbndframeshiftinfo(*sbndframeshiftinfo_handle); + FillSBNDFrameShiftInfo(sbndframeshiftinfo, srsbndframeshiftinfo); + } + + art::Handle sbndtiminginfo_handle; + GetByLabelStrict(evt, fParams.SBNDTimingInfoLabel(), sbndtiminginfo_handle); + // fill into event + if (sbndtiminginfo_handle.isValid()) { + raw::TimingInfo const& sbndtiminginfo(*sbndtiminginfo_handle); + FillSBNDTimingInfo(sbndtiminginfo, srsbndtiminginfo); + } } // Get all of the CRTPMT Matches @@ -2367,6 +2423,9 @@ 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.sbnd_timings = srsbndtiminginfo; + if (fParams.FillTrueParticles()) { rec.true_particles = true_particles; } @@ -2374,7 +2433,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 @@ -2406,6 +2465,19 @@ void CAFMaker::produce(art::Event& evt) noexcept { FixPMTReferenceTimes(rec, PMT_reference_time); // TODO: TPC? + + // 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 \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 unsigned int run = evt.run(); diff --git a/sbncode/CAFMaker/FillReco.cxx b/sbncode/CAFMaker/FillReco.cxx index cb3dc5f6c..b798537d4 100644 --- a/sbncode/CAFMaker/FillReco.cxx +++ b/sbncode/CAFMaker/FillReco.cxx @@ -141,6 +141,33 @@ namespace caf srsbndcrttrack.tof = track.ToF(); } + void FillSBNDFrameShiftInfo(const raw::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; + } + + void FillSBNDTimingInfo(const raw::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; + } + 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 4b24b4a98..e80467660 100644 --- a/sbncode/CAFMaker/FillReco.h +++ b/sbncode/CAFMaker/FillReco.h @@ -45,6 +45,7 @@ #include "sbnobj/Common/PMT/Data/PMTBeamSignal.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" @@ -281,6 +282,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 ); }