Skip to content

Commit 621fdbb

Browse files
committed
Merge tag 'v10_20_05' into feature/frame_shift_refactor_v10_14_02
v10_20_05
2 parents 3f47621 + 29ff655 commit 621fdbb

24 files changed

Lines changed: 385 additions & 54 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
1717

1818
find_package(cetmodules 3.20.00 REQUIRED)
19-
project(sbncode VERSION 10.14.02 LANGUAGES CXX)
19+
project(sbncode VERSION 10.20.05 LANGUAGES CXX)
2020

2121
message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================")
2222

sbncode/BeamSpillInfoRetriever/POTTools.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace sbn::pot{
2020
if (ctb_frag.Trigger(word_i)->IsHLT() && ctb_frag.Trigger(word_i)->IsTrigger(HLT))
2121
{
2222
foundHLT = true;
23-
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS * 20;
24-
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp * 20;
25-
double currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp/20).to_ullong()/50e6;
23+
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS;
24+
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp;
25+
std::uint64_t currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong() * 20;
2626
if(currTS_candidate < PTBInfo.currPTBTimeStamp){
27-
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp / 20).to_ullong()/50e6;
27+
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong() * 20;
2828
PTBInfo.currPTBTimeStamp = currTS_candidate;
2929
PTBInfo.GateCounter = ctb_frag.Trigger(word_i)->gate_counter;
3030
}
@@ -43,6 +43,35 @@ namespace sbn::pot{
4343
}
4444
}
4545

46+
std::vector<PTBInfo_t> extractAllPTBInfo(std::vector<artdaq::Fragment> const& cont_frags) {
47+
std::vector<PTBInfo_t> PTBInfoVec;
48+
for (auto const& cont : cont_frags)
49+
{
50+
artdaq::ContainerFragment cont_frag(cont);
51+
for (size_t fragi = 0; fragi < cont_frag.block_count(); ++fragi)
52+
{
53+
artdaq::Fragment frag = *cont_frag[fragi];
54+
sbndaq::CTBFragment ctb_frag(frag);
55+
for(size_t word_i = 0; word_i < ctb_frag.NWords(); ++word_i)
56+
{
57+
if(ctb_frag.Trigger(word_i)){
58+
PTBInfo_t PTBInfo;
59+
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS;
60+
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp;
61+
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong() * 20;
62+
PTBInfo.currPTBTimeStamp = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong() * 20;
63+
PTBInfo.GateCounter = ctb_frag.Trigger(word_i)->gate_counter;
64+
PTBInfo.isHLT = ctb_frag.Trigger(word_i)->IsHLT();
65+
PTBInfo.triggerWord = ctb_frag.Trigger(word_i)->trigger_word;
66+
PTBInfoVec.push_back(PTBInfo);
67+
}
68+
}
69+
}
70+
}
71+
72+
return PTBInfoVec;
73+
}
74+
4675
double extractTDCTimeStamp(art::Handle<std::vector<artdaq::Fragment> > cont_frags) {
4776

4877
double TDCTimeStamp = 0;

sbncode/BeamSpillInfoRetriever/POTTools.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313

1414
#include "sbncode/BeamSpillInfoRetriever/MWRData.h"
1515
#include "larcorealg/CoreUtils/counter.h"
16+
#include <vector>
1617

1718
namespace sbn::pot{
1819

1920
typedef struct PTBInfo_t {
20-
double currPTBTimeStamp = 1e20;
21-
double prevPTBTimeStamp = 0;
21+
std::uint64_t currPTBTimeStamp = UINT64_MAX; ///< Timestamp in UTC nanoseconds since Unix epoch (converted from 20ns clock ticks)
22+
std::uint64_t prevPTBTimeStamp = 0;
2223
unsigned int GateCounter = 0;
24+
bool isHLT = false;
25+
uint64_t triggerWord = 0; ///< Timestamp in s since beam extraction signal
2326
} PTBInfo_t;
2427

2528
typedef struct TriggerInfo_t {
2629
int gate_type = 0; ///< Source of the spill: `1`: BNB, `2`: NuMI
27-
double t_current_event = 0;
30+
double t_current_event = 0; ///< Timestamp in UTC seconds since Unix epoch (converted from 20ns clock ticks)
2831
double t_previous_event = 0;
2932
unsigned int number_of_gates_since_previous_event = 0;
3033
std::int64_t WR_to_Spill_conversion = 0;
@@ -36,13 +39,21 @@ namespace sbn::pot{
3639
} MWRdata_t;
3740

3841
/**
39-
* @brief Extracts information from PTB for use in SBND POT accounting.
42+
* @brief Extracts information from PTB for a single HLT for use in SBND POT accounting.
4043
*
4144
* @param cont_frags The PTB fragments to examine.
4245
* @param HLT The high level trigger we are searching for.
4346
*/
4447
PTBInfo_t extractPTBInfo(art::Handle<std::vector<artdaq::Fragment> > cont_frags, int HLT);
4548

49+
/**
50+
* @brief Extracts ALL PTB information for using in SBND CAF files.
51+
*
52+
* @param cont_frags The PTB fragments to examine.
53+
* @return Vector of PTBInfo_t containing all triggers found.
54+
*/
55+
std::vector<PTBInfo_t> extractAllPTBInfo(std::vector<artdaq::Fragment> const& cont_frags);
56+
4657
/**
4758
* @brief Extracts information from TDC for use in SBND POT accounting.
4859
*

sbncode/BeamSpillInfoRetriever/SBNDBNBRetriever/SBNDBNBRetriever_module.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ sbn::pot::TriggerInfo_t sbn::SBNDBNBRetriever::extractTriggerInfo(art::Event con
123123
else{
124124
// If missing TDC, use PTB instead
125125
mf::LogDebug("SBNDBNBRetriever") << " Missing TDC Container Fragments!!! " << std::endl;
126-
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp - fBESOffset;
126+
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp / 1e9 - fBESOffset;
127127
}
128128

129-
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp - fBESOffset;
129+
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp / 1e9 - fBESOffset;
130130
triggerInfo.number_of_gates_since_previous_event = PTBInfo.GateCounter;
131131

132-
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp - triggerInfo.t_current_event - fBESOffset;
132+
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp / 1e9 - triggerInfo.t_current_event - fBESOffset;
133133

134134
// Catch for an issue seen a few times where PTB off by a second.
135135
// Only need to correct prevTS because either currTS is from TDC

sbncode/BeamSpillInfoRetriever/SBNDBNBZEROBIASRetriever/SBNDBNBZEROBIASRetriever_module.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ sbn::pot::TriggerInfo_t sbn::SBNDBNBZEROBIASRetriever::extractTriggerInfo(art::E
126126
else{
127127
// If missing TDC, use PTB instead
128128
mf::LogDebug("SBNDBNBZEROBIASRetriever") << " Missing TDC Container Fragments!!!" << std::endl;
129-
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp - fBESOffset;
129+
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp / 1e9 - fBESOffset;
130130
}
131131

132-
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp - fBESOffset;
132+
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp / 1e9 - fBESOffset;
133133
triggerInfo.number_of_gates_since_previous_event = PTBInfo.GateCounter;
134134

135-
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp - triggerInfo.t_current_event - fBESOffset;
135+
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp / 1e9 - triggerInfo.t_current_event - fBESOffset;
136136

137137
// Catch for an issue seen a few times where PTB off by a second.
138138
// Only need to correct prevTS because either currTS is from TDC

sbncode/CAFMaker/CAFMakerParams.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ namespace caf
483483
"simdrift"
484484
};
485485

486+
Atom<art::InputTag> SimEnergyDepositLabel {
487+
Name("SimEnergyDepositLabel"),
488+
Comment("Label of input sim::SimEnergyDeposit objects."),
489+
art::InputTag("ionandscint", "priorSCE","G4")
490+
};
491+
486492
Atom<bool> FillTrueParticles {
487493
Name("FillTrueParticles"),
488494
Comment("Whether to fill the rec.true_particles branch. The information on true particles"
@@ -634,7 +640,18 @@ namespace caf
634640
Comment("Label of CVN scores."),
635641
"cvn"
636642
};
643+
644+
Atom<string> LightCaloLabel {
645+
Name("LightCaloLabel"),
646+
Comment("Label of light calorimetry producer"),
647+
"lightcalo"
648+
};
637649

650+
Atom<std::string> fBlipTag {
651+
Name("BlipTag"),
652+
Comment("Provide a string to label the blip input"),
653+
"blipreco"
654+
};
638655
};
639656
}
640657

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "sbncode/CAFMaker/FillExposure.h"
2121
#include "sbncode/CAFMaker/FillTrigger.h"
2222
#include "sbncode/CAFMaker/Utils.h"
23+
#include "sbncode/CAFMaker/FillBlip.h"
2324

2425
// C/C++ includes
2526
#include <fenv.h>
@@ -97,6 +98,7 @@
9798
#include "lardataobj/RecoBase/MCSFitResult.h"
9899
#include "lardataobj/RecoBase/Cluster.h"
99100
#include "lardataobj/AnalysisBase/MVAOutput.h"
101+
#include "lardataobj/Simulation/SimEnergyDeposit.h"
100102

101103
#include "nusimdata/SimulationBase/MCFlux.h"
102104
#include "nusimdata/SimulationBase/MCTruth.h"
@@ -115,11 +117,14 @@
115117
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
116118
#include "sbnobj/Common/POTAccounting/EXTCountInfo.h"
117119
#include "sbnobj/Common/POTAccounting/NuMISpillInfo.h"
120+
#include "sbncode/BeamSpillInfoRetriever/POTTools.h"
121+
#include "artdaq-core/Data/ContainerFragment.hh"
118122
#include "sbnobj/Common/Trigger/ExtraTriggerInfo.h"
119123
#include "sbnobj/Common/Reco/CRUMBSResult.h"
120124
#include "sbnobj/Common/Reco/OpT0FinderResult.h"
121125
#include "sbnobj/SBND/CRT/CRTVeto.hh"
122126
#include "sbnobj/Common/Reco/CorrectedOpFlashTiming.h"
127+
#include "sbnobj/Common/Reco/LightCalo.h"
123128
#include "sbnobj/SBND/Timing/TimingInfo.hh"
124129
#include "sbnobj/SBND/Timing/FrameShiftInfo.hh"
125130

@@ -352,6 +357,10 @@ class CAFMaker : public art::EDProducer {
352357
art::FindOneP<T> FindOnePStrict(const U& from, const art::Event& evt,
353358
const art::InputTag& label) const;
354359

360+
template <class T, class U>
361+
art::FindOneP<T> FindOnePStrictSingle(const U& from, const art::Event& evt,
362+
const art::InputTag& label) const;
363+
355364
template <class T, class D, class U>
356365
art::FindOneP<T, D> FindOnePDStrict(const U& from,
357366
const art::Event& evt,
@@ -1299,6 +1308,14 @@ art::FindOneP<T> CAFMaker::FindOnePStrict(const U& from,
12991308
return ret;
13001309
}
13011310

1311+
//......................................................................
1312+
template <class T, class U>
1313+
art::FindOneP<T> CAFMaker::FindOnePStrictSingle(const U& from,
1314+
const art::Event& evt,
1315+
const art::InputTag& tag) const {
1316+
return FindOnePStrict<T>(std::vector{ from }, evt, tag);
1317+
}
1318+
13021319
//......................................................................
13031320
template <class T, class D, class U>
13041321
art::FindOneP<T, D> CAFMaker::FindOnePDStrict(const U& from,
@@ -1378,6 +1395,7 @@ bool CAFMaker::GetPsetParameter(const fhicl::ParameterSet& pset,
13781395

13791396
//......................................................................
13801397
void CAFMaker::produce(art::Event& evt) noexcept {
1398+
mf::LogInfo("CAFMaker") << "CAFMaker::produce called for event: " << evt.id();
13811399

13821400
bool const firstInFile = (fIndexInFile++ == 0);
13831401

@@ -1637,6 +1655,36 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16371655
} // end for fm
16381656
} // end for i (mctruths)
16391657

1658+
// get sim energy deposits if they're there
1659+
::art::Handle<std::vector<sim::SimEnergyDeposit>> sed_handle;
1660+
GetByLabelStrict(evt, fParams.SimEnergyDepositLabel().encode(), sed_handle);
1661+
1662+
if (!isRealData && sed_handle.isValid()){
1663+
art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
1664+
1665+
srtruthbranch.dep.reserve(mctruths.size());
1666+
for (size_t n=0; n<mctruths.size();n++){
1667+
SRTrueDeposit init;
1668+
init.electrons = 0;
1669+
init.photons = 0;
1670+
init.energy = 0;
1671+
srtruthbranch.dep.push_back(init);
1672+
}
1673+
1674+
for (sim::SimEnergyDeposit const& sed: *sed_handle){
1675+
const auto trackID = sed.TrackID();
1676+
1677+
art::Ptr<simb::MCTruth> mctruth = pi_serv->TrackIdToMCTruth_P(trackID);
1678+
auto it = std::find(mctruths.begin(), mctruths.end(), mctruth);
1679+
if (it == mctruths.end()) continue;
1680+
1681+
auto idx = std::distance(mctruths.begin(), it);
1682+
srtruthbranch.dep.at(idx).energy += sed.Energy()*1e-3; // GeV
1683+
srtruthbranch.dep.at(idx).photons += sed.NumPhotons();
1684+
srtruthbranch.dep.at(idx).electrons += sed.NumElectrons();
1685+
}
1686+
}
1687+
16401688
// get the number of events generated in the gen stage
16411689
unsigned n_gen_evt = 0;
16421690
for (const art::ProcessConfiguration &process: evt.processHistory()) {
@@ -1711,6 +1759,24 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17111759
FillTriggerEmulation(monpulses_handle, monpulse_sizes_handle, pairs_handle, trigemu_handle, srtrigger);
17121760
}
17131761

1762+
1763+
// Fill PTB (Penn Trigger Board) information for SBND real data
1764+
if (isRealData && fDet == kSBND) {
1765+
art::InputTag PTB_itag("daq", "ContainerPTB");
1766+
art::Handle<artdaq::Fragments> ptb_frags_handle;
1767+
evt.getByLabel(PTB_itag, ptb_frags_handle);
1768+
if (ptb_frags_handle.isValid()) {
1769+
mf::LogDebug("CAFMaker") << "Found ContainerPTB, extracting PTB triggers...";
1770+
std::vector<sbn::pot::PTBInfo_t> ptb_triggers = sbn::pot::extractAllPTBInfo(*ptb_frags_handle);
1771+
mf::LogDebug("CAFMaker") << "Extracted " << ptb_triggers.size() << " PTB triggers";
1772+
FillPTBTriggersSBND(ptb_triggers, srtrigger);
1773+
mf::LogDebug("CAFMaker") << "PTB HLT triggers: " << srtrigger.ptb_hlt_timestamp.size()
1774+
<< ", LLT triggers: " << srtrigger.ptb_llt_timestamp.size();
1775+
} else {
1776+
mf::LogDebug("CAFMaker") << "ContainerPTB not found for event " << evt.id();
1777+
}
1778+
}
1779+
17141780
// If not real data, fill in enough of the SRTrigger to make (e.g.) the CRT
17151781
// time referencing work. TODO: add more stuff to a "MC"-Trigger?
17161782
// No longer needed with incorporation of trigger emulation in the MC.
@@ -1791,12 +1857,15 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17911857
{
17921858
art::Handle<std::vector<sbnd::crt::CRTSpacePoint>> crtspacepoints_handle;
17931859
GetByLabelStrict(evt, fParams.CRTSpacePointLabel(), crtspacepoints_handle);
1860+
art::FindOneP<sbnd::crt::CRTCluster> foCRTCluster =
1861+
FindOnePStrict<sbnd::crt::CRTCluster>(crtspacepoints_handle, evt, fParams.CRTSpacePointLabel());
17941862

17951863
if (crtspacepoints_handle.isValid()) {
17961864
const std::vector<sbnd::crt::CRTSpacePoint> &crtspacepoints = *crtspacepoints_handle;
17971865
for (unsigned i = 0; i < crtspacepoints.size(); i++) {
17981866
srcrtspacepoints.emplace_back();
1799-
FillCRTSpacePoint(crtspacepoints[i], srcrtspacepoints.back());
1867+
const art::Ptr<sbnd::crt::CRTCluster> crtcluster = foCRTCluster.at(i);
1868+
FillCRTSpacePoint(crtspacepoints[i], *crtcluster, srcrtspacepoints.back());
18001869
}
18011870
}
18021871

@@ -1928,6 +1997,13 @@ void CAFMaker::produce(art::Event& evt) noexcept {
19281997
}
19291998
}
19301999

2000+
//Fill blips. art::handle for blips and then call fill blips for each one. Make a vector to hold all of them. I handle for loop in Fill blip
2001+
art::Handle<std::vector<blip::Blip>> blipHandle;
2002+
std::vector<caf::SRBlip> srblips;
2003+
if(evt.getByLabel( fParams.fBlipTag(), blipHandle)) //fill SR blips
2004+
{
2005+
FillBlip( *blipHandle, srblips);
2006+
}
19312007
// collect the TPC slices
19322008
std::vector<art::Ptr<recob::Slice>> slices;
19332009
std::vector<std::string> slice_tag_suffixes;
@@ -2049,6 +2125,10 @@ void CAFMaker::produce(art::Event& evt) noexcept {
20492125
if (fmCorrectedOpFlash.isValid())
20502126
slcCorrectedOpFlash = fmCorrectedOpFlash.at(0);
20512127

2128+
art::FindOneP<sbn::LightCalo> foLightCalo =
2129+
FindOnePStrict<sbn::LightCalo>(sliceList,evt,
2130+
fParams.LightCaloLabel() + slice_tag_suff);
2131+
const sbn::LightCalo *slcLightCalo = foLightCalo.isValid()? foLightCalo.at(0).get() : nullptr;
20522132

20532133
art::FindOneP<lcvn::Result> foCVNResult =
20542134
FindOnePStrict<lcvn::Result>(sliceList, evt,
@@ -2239,6 +2319,9 @@ void CAFMaker::produce(art::Event& evt) noexcept {
22392319
FindOnePDStrict<sbnd::crt::CRTSpacePoint, anab::T0>(slcTracks, evt,
22402320
fParams.CRTSpacePointMatchLabel() + slice_tag_suff);
22412321

2322+
art::Handle<std::vector<sbnd::crt::CRTSpacePoint>> crtspacepoints_handle;
2323+
GetByLabelStrict(evt, fParams.CRTSpacePointLabel(), crtspacepoints_handle);
2324+
22422325
art::FindOneP<sbnd::crt::CRTTrack, anab::T0> foSBNDCRTTrackMatch =
22432326
FindOnePDStrict<sbnd::crt::CRTTrack, anab::T0>(slcTracks, evt,
22442327
fParams.SBNDCRTTrackMatchLabel() + slice_tag_suff);
@@ -2308,6 +2391,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23082391
FillSliceCRUMBS(slcCRUMBS, recslc);
23092392
FillSliceOpT0Finder(slcOpT0, recslc);
23102393
FillSliceBarycenter(slcHits, slcSpacePoints, recslc);
2394+
FillSliceLightCalo(slcLightCalo, recslc);
23112395
FillTPCPMTBarycenterMatch(barycenterMatch, recslc);
23122396
FillCorrectedOpFlashTiming(slcCorrectedOpFlash, recslc);
23132397
FillCVNScores(cvnResult, recslc);
@@ -2515,8 +2599,12 @@ void CAFMaker::produce(art::Event& evt) noexcept {
25152599
{
25162600
const art::Ptr<sbnd::crt::CRTSpacePoint> crtspacepoint = foCRTSpacePointMatch.at(iPart);
25172601

2602+
art::FindOneP<sbnd::crt::CRTCluster> foCRTCluster =
2603+
FindOnePStrictSingle<sbnd::crt::CRTCluster>(crtspacepoint, evt, fParams.CRTSpacePointLabel());
2604+
const art::Ptr<sbnd::crt::CRTCluster>& crtcluster = foCRTCluster.at(0);
2605+
25182606
if(crtspacepoint.isNonnull())
2519-
FillTrackCRTSpacePoint(foCRTSpacePointMatch.data(iPart).ref(), crtspacepoint, trk);
2607+
FillTrackCRTSpacePoint(foCRTSpacePointMatch.data(iPart).ref(), *crtspacepoint, *crtcluster, trk);
25202608
}
25212609
if(foSBNDCRTTrackMatch.isValid() && fDet == kSBND)
25222610
{
@@ -2605,6 +2693,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
26052693
rec.sbnd_crt_veto = srsbndcrtveto;
26062694
rec.opflashes = srflashes;
26072695
rec.nopflashes = srflashes.size();
2696+
rec.blips = srblips;
26082697
rec.sbnd_frames = srsbndframeshiftinfo;
26092698
rec.sbnd_timings = srsbndtiminginfo;
26102699
rec.soft_trig = srsbndsofttrig;

0 commit comments

Comments
 (0)