Skip to content

Commit a6256ad

Browse files
authored
Merge pull request #562 from SBNSoftware/lnguyen/frame_shift_pr_dev
Frame Shift Module to Correct Timing in Data - PR For Develop
2 parents 0ad5ec1 + a42eafd commit a6256ad

7 files changed

Lines changed: 150 additions & 2 deletions

File tree

sbncode/CAFMaker/CAFMakerParams.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,18 @@ namespace caf
338338
"crttracks" // sbnd
339339
};
340340

341+
Atom<string> SBNDFrameShiftInfoLabel {
342+
Name("SBNDFrameShiftInfoLabel"),
343+
Comment("Label of sbnd frame shift."),
344+
"" // sbnd
345+
};
346+
347+
Atom<string> SBNDTimingInfoLabel {
348+
Name("SBNDTimingInfoLabel"),
349+
Comment("Label of sbnd timing shift."),
350+
"" // sbnd
351+
};
352+
341353
Atom<string> CRTPMTLabel {
342354
Name("CRTPMTLabel"),
343355
Comment("Label for the CRTPMT Matched variables from the crtpmt data product"),

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
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+
502545
void 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
26952781
DEFINE_ART_MODULE(caf::CAFMaker)
26962782
////////////////////////////////////////////////////////////////////////

sbncode/CAFMaker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
3737
sbnobj::Common_Analysis
3838
sbnobj::Common_PMT_Data
3939
sbnobj::SBND_CRT
40+
sbnobj::SBND_Timing
4041
lardataalg::DetectorInfo
4142
art::Framework_Services_System_TriggerNamesService_service
4243
sbncode_Metadata_MetadataSBN_service

sbncode/CAFMaker/FillReco.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ namespace caf
141141
srsbndcrttrack.tof = track.ToF();
142142
}
143143

144+
void FillSBNDFrameShiftInfo(const sbnd::timing::FrameShiftInfo &frame,
145+
caf::SRSBNDFrameShiftInfo &srsbndframe,
146+
bool allowEmpty)
147+
{
148+
srsbndframe.timingType = frame.TimingType();
149+
srsbndframe.frameTdcCrtt1 = frame.FrameTdcCrtt1();
150+
srsbndframe.frameTdcBes = frame.FrameTdcBes();
151+
srsbndframe.frameTdcRwm = frame.FrameTdcRwm();
152+
srsbndframe.frameHltCrtt1 = frame.FrameHltCrtt1();
153+
srsbndframe.frameHltBeamGate = frame.FrameHltBeamGate();
154+
srsbndframe.frameApplyAtCaf = frame.FrameApplyAtCaf();
155+
}
156+
157+
void FillSBNDTimingInfo(const sbnd::timing::TimingInfo &timing,
158+
caf::SRSBNDTimingInfo &srsbndtiming,
159+
bool allowEmpty)
160+
{
161+
srsbndtiming.rawDAQHeaderTimestamp = timing.RawDAQHeaderTimestamp();
162+
srsbndtiming.tdcCrtt1 = timing.TdcCrtt1();
163+
srsbndtiming.tdcBes = timing.TdcBes();
164+
srsbndtiming.tdcRwm = timing.TdcRwm();
165+
srsbndtiming.tdcEtrig = timing.TdcEtrig();
166+
srsbndtiming.hltCrtt1 = timing.HltCrtt1();
167+
srsbndtiming.hltEtrig = timing.HltEtrig();
168+
srsbndtiming.hltBeamGate = timing.HltBeamGate();
169+
}
170+
144171
void FillCRTPMTMatch(const sbn::crt::CRTPMTMatching &match,
145172
caf::SRCRTPMTMatch &srmatch,
146173
bool allowEmpty){

sbncode/CAFMaker/FillReco.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
#include "sbnobj/Common/CRT/CRTPMTMatching.hh"
4444
#include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh"
4545
#include "sbnobj/Common/PMT/Data/PMTBeamSignal.hh"
46+
#include "sbnobj/SBND/Timing/TimingInfo.hh"
47+
#include "sbnobj/SBND/Timing/FrameShiftInfo.hh"
48+
4649
#include "nusimdata/SimulationBase/MCParticle.h"
4750
#include "nusimdata/SimulationBase/MCTruth.h"
4851

@@ -281,6 +284,14 @@ namespace caf
281284
caf::SRPFP& srpfp,
282285
bool allowEmpty = false);
283286

287+
void FillSBNDFrameShiftInfo(const sbnd::timing::FrameShiftInfo &frame,
288+
caf::SRSBNDFrameShiftInfo &srsbndframe,
289+
bool allowEmpty = false);
290+
291+
void FillSBNDTimingInfo(const sbnd::timing::TimingInfo &timing,
292+
caf::SRSBNDTimingInfo &srsbndtiming,
293+
bool allowEmpty = false);
294+
284295
template<class T, class U>
285296
void CopyPropertyIfSet( const std::map<std::string, T>& props, const std::string& search, U& value );
286297
}

sbncode/CAFMaker/FillTrigger.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ namespace caf
3535
// TODO: fill others?
3636
}
3737

38+
void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo){
39+
40+
triggerInfo.global_trigger_time = timingInfo.hltEtrig;
41+
triggerInfo.beam_gate_time_abs = timingInfo.hltBeamGate;
42+
43+
double diff_ts = triggerInfo.global_trigger_det_time - triggerInfo.beam_gate_det_time;
44+
triggerInfo.trigger_within_gate = diff_ts;
45+
}
46+
3847
}

sbncode/CAFMaker/FillTrigger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "sbnobj/Common/Trigger/ExtraTriggerInfo.h"
55
#include "sbnobj/Common/Trigger/BeamBits.h"
66
#include "sbnanaobj/StandardRecord/SRTrigger.h"
7+
#include "sbnanaobj/StandardRecord/SRSBNDTimingInfo.h"
78
#include "lardataobj/RawData/TriggerData.h"
89

910
#include <vector>
@@ -18,6 +19,7 @@ namespace caf
1819

1920
void FillTriggerMC(double absolute_time, caf::SRTrigger& triggerInfo);
2021

22+
void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo);
2123
}
2224

2325
#endif

0 commit comments

Comments
 (0)