118118#include " sbnobj/Common/Trigger/ExtraTriggerInfo.h"
119119#include " sbnobj/Common/Reco/CRUMBSResult.h"
120120#include " sbnobj/Common/Reco/OpT0FinderResult.h"
121+ #include " sbnobj/SBND/Timing/TimingInfo.hh"
122+ #include " sbnobj/SBND/Timing/FrameShiftInfo.hh"
121123
122124// GENIE
123125#include " Framework/EventGen/EventRecord.h"
@@ -316,6 +318,9 @@ class CAFMaker : public art::EDProducer {
316318 void FixPMTReferenceTimes (StandardRecord &rec, double PMT_reference_time);
317319 void FixCRTReferenceTimes (StandardRecord &rec, double CRTT0_reference_time, double CRTT1_reference_time);
318320
321+ void SBNDShiftCRTReference (StandardRecord &rec, double SBNDFrame) const ;
322+ void SBNDShiftPMTReference (StandardRecord &rec, double SBNDFrame) const ;
323+
319324 // / Equivalent of FindManyP except a return that is !isValid() prints a
320325 // / messsage and aborts if StrictMode is true.
321326 template <class T , class U >
@@ -499,6 +504,44 @@ void CAFMaker::BlindEnergyParameters(StandardRecord* brec) {
499504 }
500505}
501506
507+ void CAFMaker::SBNDShiftCRTReference (StandardRecord &rec, double SBNDFrame) const {
508+
509+ // CRT Space Point
510+ for (SRCRTSpacePoint &sp: rec.crt_spacepoints ){
511+ sp.time += SBNDFrame; // ns
512+ }
513+
514+ // CRT Track
515+ for (SRSBNDCRTTrack &trk: rec.sbnd_crt_tracks ){
516+ trk.time += SBNDFrame; // ns
517+ }
518+
519+ // TODO: CRT Space Point and Track Match
520+ for (SRSlice &slc: rec.slc ){
521+ for (SRPFP &pfp: slc.reco .pfp ){
522+ if (!std::isnan (pfp.trk .crtspacepoint .score )) pfp.trk .crtspacepoint .spacepoint .time += SBNDFrame;
523+
524+ if (!std::isnan (pfp.trk .crtsbndtrack .score )) pfp.trk .crtsbndtrack .track .time += SBNDFrame;
525+ }
526+ }
527+ }
528+
529+ void CAFMaker::SBNDShiftPMTReference (StandardRecord &rec, double SBNDFrame) const {
530+
531+ double SBNDFrame_us = SBNDFrame / 1000.0 ; // convert ns to us
532+
533+ // Op Flash
534+ for (SROpFlash &opf: rec.opflashes ) {
535+ opf.time += SBNDFrame_us;
536+ opf.firsttime += SBNDFrame_us;
537+ }
538+
539+ // OpT0 match to slice
540+ for (SRSlice &s: rec.slc ) {
541+ s.opt0 .time += SBNDFrame_us;
542+ }
543+ }
544+
502545void CAFMaker::FixPMTReferenceTimes (StandardRecord &rec, double PMT_reference_time) {
503546 // Fix the flashes
504547 for (SROpFlash &f: rec.opflashes ) {
@@ -1602,6 +1645,8 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16021645 std::vector<caf::SRCRTTrack> srcrttracks;
16031646 std::vector<caf::SRCRTSpacePoint> srcrtspacepoints;
16041647 std::vector<caf::SRSBNDCRTTrack> srsbndcrttracks;
1648+ caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo;
1649+ caf::SRSBNDTimingInfo srsbndtiminginfo;
16051650
16061651 if (fDet == kICARUS )
16071652 {
@@ -1650,6 +1695,22 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16501695 FillSBNDCRTTrack (sbndcrttracks[i], srsbndcrttracks.back ());
16511696 }
16521697 }
1698+
1699+ art::Handle<sbnd::timing::FrameShiftInfo> sbndframeshiftinfo_handle;
1700+ GetByLabelStrict (evt, fParams .SBNDFrameShiftInfoLabel (), sbndframeshiftinfo_handle);
1701+ // fill into event
1702+ if (sbndframeshiftinfo_handle.isValid ()) {
1703+ sbnd::timing::FrameShiftInfo const & sbndframeshiftinfo (*sbndframeshiftinfo_handle);
1704+ FillSBNDFrameShiftInfo (sbndframeshiftinfo, srsbndframeshiftinfo);
1705+ }
1706+
1707+ art::Handle<sbnd::timing::TimingInfo> sbndtiminginfo_handle;
1708+ GetByLabelStrict (evt, fParams .SBNDTimingInfoLabel (), sbndtiminginfo_handle);
1709+ // fill into event
1710+ if (sbndtiminginfo_handle.isValid ()) {
1711+ sbnd::timing::TimingInfo const & sbndtiminginfo (*sbndtiminginfo_handle);
1712+ FillSBNDTimingInfo (sbndtiminginfo, srsbndtiminginfo);
1713+ }
16531714 }
16541715
16551716 // Get all of the CRTPMT Matches
@@ -2356,14 +2417,17 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23562417 rec.nsbnd_crt_tracks = srsbndcrttracks.size ();
23572418 rec.opflashes = srflashes;
23582419 rec.nopflashes = srflashes.size ();
2420+ rec.sbnd_frames = srsbndframeshiftinfo;
2421+ rec.sbnd_timings = srsbndtiminginfo;
2422+
23592423 if (fParams .FillTrueParticles ()) {
23602424 rec.true_particles = true_particles;
23612425 }
23622426 rec.ntrue_particles = true_particles.size ();
23632427 rec.crtpmt_matches = srcrtpmtmatches;
23642428 rec.ncrtpmt_matches = srcrtpmtmatches.size ();
23652429
2366- // Fix the Reference time
2430+ // Move the reference time of reconstructed objects from trigger time to beam spill/beam gate opening time.
23672431 //
23682432 // We want MC and Data to have the same reference time.
23692433 // In MC/LArSoft the "reference time" is canonically defined
@@ -2380,6 +2444,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23802444 // filled with the default values, which are set to the numerical limits of double.
23812445 // In this case, we should set the PMT_reference_time to 0.
23822446
2447+ // ICARUS: Fix the Reference time
23832448 const bool hasValidTriggerTime =
23842449 srtrigger.global_trigger_det_time >
23852450 (std::numeric_limits<double >::min () + std::numeric_limits<double >::epsilon ()) &&
@@ -2395,6 +2460,28 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23952460 FixPMTReferenceTimes (rec, PMT_reference_time);
23962461
23972462 // TODO: TPC?
2463+
2464+ // SBND: Fix the Reference time in data depending on the stream
2465+ // For more information, see:
2466+ // https://sbn-docdb.fnal.gov/cgi-bin/sso/RetrieveFile?docid=43090
2467+
2468+ if (isRealData && (fDet == kSBND ))
2469+ {
2470+ // Fill trigger info
2471+ FillTriggerSBND (srsbndtiminginfo, srtrigger);
2472+
2473+ // Shift timing reference frame
2474+ if (!std::isnan (rec.sbnd_frames .frameApplyAtCaf ) && (rec.sbnd_frames .frameApplyAtCaf != 0.0 )){
2475+ mf::LogInfo (" CAFMaker" ) << " Setting Reference Timing for timing object in SBND \n "
2476+ << " Shift Apply At Caf Level = " << rec.sbnd_frames .frameApplyAtCaf << " ns\n " ;
2477+
2478+ // shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match
2479+ SBNDShiftCRTReference (rec, rec.sbnd_frames .frameApplyAtCaf );
2480+
2481+ // shift reference frame for PMT objects: opflash, opt0
2482+ SBNDShiftPMTReference (rec, rec.sbnd_frames .frameApplyAtCaf );
2483+ }
2484+ }
23982485
23992486 // Get metadata information for header
24002487 unsigned int run = evt.run ();
@@ -2679,7 +2766,6 @@ void CAFMaker::endJob() {
26792766 if (fParams .CreateBlindedCAF () && fFlatFilep ) AddMetadataToFile (fFlatFilep , metamap);
26802767}
26812768
2682-
26832769} // end namespace caf
26842770DEFINE_ART_MODULE (caf::CAFMaker)
26852771// //////////////////////////////////////////////////////////////////////
0 commit comments