Skip to content

Commit 6413c97

Browse files
committed
Merge branch 'lnguyen/frame_shift_pr_spring' of github.com:SBNSoftware/sbncode into rc-nuint
2 parents 0d40e2a + 8ca69d2 commit 6413c97

File tree

7 files changed

+150
-2
lines changed

7 files changed

+150
-2
lines changed

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
@@ -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
26842770
DEFINE_ART_MODULE(caf::CAFMaker)
26852771
////////////////////////////////////////////////////////////////////////

sbncode/CAFMaker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
3636
sbnobj::Common_Reco
3737
sbnobj::Common_Analysis
3838
sbnobj::SBND_CRT
39+
sbnobj::SBND_Timing
3940
lardataalg::DetectorInfo
4041
art::Framework_Services_System_TriggerNamesService_service
4142
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
@@ -42,6 +42,9 @@
4242
#include "sbnobj/SBND/CRT/CRTTrack.hh"
4343
#include "sbnobj/Common/CRT/CRTPMTMatching.hh"
4444
#include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh"
45+
#include "sbnobj/SBND/Timing/TimingInfo.hh"
46+
#include "sbnobj/SBND/Timing/FrameShiftInfo.hh"
47+
4548
#include "nusimdata/SimulationBase/MCParticle.h"
4649
#include "nusimdata/SimulationBase/MCTruth.h"
4750

@@ -279,6 +282,14 @@ namespace caf
279282
caf::SRPFP& srpfp,
280283
bool allowEmpty = false);
281284

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

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)