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
@@ -2367,14 +2428,17 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23672428 rec.nsbnd_crt_tracks = srsbndcrttracks.size ();
23682429 rec.opflashes = srflashes;
23692430 rec.nopflashes = srflashes.size ();
2431+ rec.sbnd_frames = srsbndframeshiftinfo;
2432+ rec.sbnd_timings = srsbndtiminginfo;
2433+
23702434 if (fParams .FillTrueParticles ()) {
23712435 rec.true_particles = true_particles;
23722436 }
23732437 rec.ntrue_particles = true_particles.size ();
23742438 rec.crtpmt_matches = srcrtpmtmatches;
23752439 rec.ncrtpmt_matches = srcrtpmtmatches.size ();
23762440
2377- // Fix the Reference time
2441+ // Move the reference time of reconstructed objects from trigger time to beam spill/beam gate opening time.
23782442 //
23792443 // We want MC and Data to have the same reference time.
23802444 // In MC/LArSoft the "reference time" is canonically defined
@@ -2391,6 +2455,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23912455 // filled with the default values, which are set to the numerical limits of double.
23922456 // In this case, we should set the PMT_reference_time to 0.
23932457
2458+ // ICARUS: Fix the Reference time
23942459 const bool hasValidTriggerTime =
23952460 srtrigger.global_trigger_det_time >
23962461 (std::numeric_limits<double >::min () + std::numeric_limits<double >::epsilon ()) &&
@@ -2406,6 +2471,28 @@ void CAFMaker::produce(art::Event& evt) noexcept {
24062471 FixPMTReferenceTimes (rec, PMT_reference_time);
24072472
24082473 // TODO: TPC?
2474+
2475+ // SBND: Fix the Reference time in data depending on the stream
2476+ // For more information, see:
2477+ // https://sbn-docdb.fnal.gov/cgi-bin/sso/RetrieveFile?docid=43090
2478+
2479+ if (isRealData && (fDet == kSBND ))
2480+ {
2481+ // Fill trigger info
2482+ FillTriggerSBND (srsbndtiminginfo, srtrigger);
2483+
2484+ // Shift timing reference frame
2485+ if (!std::isnan (rec.sbnd_frames .frameApplyAtCaf ) && (rec.sbnd_frames .frameApplyAtCaf != 0.0 )){
2486+ mf::LogInfo (" CAFMaker" ) << " Setting Reference Timing for timing object in SBND \n "
2487+ << " Shift Apply At Caf Level = " << rec.sbnd_frames .frameApplyAtCaf << " ns\n " ;
2488+
2489+ // shift reference frame for CRT objects: crt trk, crt sp, crt sp match, crt trk match
2490+ SBNDShiftCRTReference (rec, rec.sbnd_frames .frameApplyAtCaf );
2491+
2492+ // shift reference frame for PMT objects: opflash, opt0
2493+ SBNDShiftPMTReference (rec, rec.sbnd_frames .frameApplyAtCaf );
2494+ }
2495+ }
24092496
24102497 // Get metadata information for header
24112498 unsigned int run = evt.run ();
@@ -2690,7 +2777,6 @@ void CAFMaker::endJob() {
26902777 if (fParams .CreateBlindedCAF () && fFlatFilep ) AddMetadataToFile (fFlatFilep , metamap);
26912778}
26922779
2693-
26942780} // end namespace caf
26952781DEFINE_ART_MODULE (caf::CAFMaker)
26962782// //////////////////////////////////////////////////////////////////////
0 commit comments