Skip to content

Commit 6ebc744

Browse files
committed
Merge branch 'feature/hbjamin_PTBTriggerInfoToCAFs_v10_06_00_02'
2 parents 774bcb0 + 9442f94 commit 6ebc744

File tree

8 files changed

+103
-14
lines changed

8 files changed

+103
-14
lines changed

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/CAFMaker_module.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
118118
#include "sbnobj/Common/POTAccounting/EXTCountInfo.h"
119119
#include "sbnobj/Common/POTAccounting/NuMISpillInfo.h"
120+
#include "sbncode/BeamSpillInfoRetriever/POTTools.h"
121+
#include "artdaq-core/Data/ContainerFragment.hh"
120122
#include "sbnobj/Common/Trigger/ExtraTriggerInfo.h"
121123
#include "sbnobj/Common/Reco/CRUMBSResult.h"
122124
#include "sbnobj/Common/Reco/OpT0FinderResult.h"
@@ -1393,6 +1395,7 @@ bool CAFMaker::GetPsetParameter(const fhicl::ParameterSet& pset,
13931395

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

13971400
bool const firstInFile = (fIndexInFile++ == 0);
13981401

@@ -1756,6 +1759,24 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17561759
FillTriggerEmulation(monpulses_handle, monpulse_sizes_handle, pairs_handle, trigemu_handle, srtrigger);
17571760
}
17581761

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+
17591780
// If not real data, fill in enough of the SRTrigger to make (e.g.) the CRT
17601781
// time referencing work. TODO: add more stuff to a "MC"-Trigger?
17611782
// No longer needed with incorporation of trigger emulation in the MC.

sbncode/CAFMaker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
5252
${GENIE_LIB_LIST}
5353
nugen::EventGeneratorBase_GENIE
5454
sbndaq_artdaq_core::sbndaq-artdaq-core_Obj_SBND
55+
sbn_POTTools
5556
)
5657

5758
cet_build_plugin ( CAFMaker art::module

sbncode/CAFMaker/FillTrigger.cxx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include<iostream>
2+
#include <bitset>
23
#include "sbncode/CAFMaker/FillTrigger.h"
34

45
namespace caf
@@ -73,4 +74,27 @@ namespace caf
7374
caf_softInfo.flash_peakpe = softInfo.peakPE;
7475
caf_softInfo.flash_peaktime = softInfo.peaktime + softInfo.trig_ts*1e-3;
7576
}
77+
78+
void FillPTBTriggersSBND(const std::vector<sbn::pot::PTBInfo_t>& ptb_triggers, caf::SRTrigger& triggerInfo) {
79+
triggerInfo.ptb_hlt_timestamp.clear();
80+
triggerInfo.ptb_hlt_bit.clear();
81+
triggerInfo.ptb_llt_timestamp.clear();
82+
triggerInfo.ptb_llt_bit.clear();
83+
84+
// Decode trigger words: each set bit becomes a separate entry with the same timestamp
85+
for(const auto& trig : ptb_triggers) {
86+
// Choose destination vectors based on trigger type
87+
auto& ptb_timestamp = trig.isHLT ? triggerInfo.ptb_hlt_timestamp : triggerInfo.ptb_llt_timestamp;
88+
auto& ptb_bit = trig.isHLT ? triggerInfo.ptb_hlt_bit : triggerInfo.ptb_llt_bit;
89+
90+
std::bitset<64> const triggerWord { trig.triggerWord };
91+
// currPTBTimeStamp is already in nanoseconds (uint64_t), use directly
92+
// Loop variable is uint8_t since we know bit values are 0-63 (fits in uint8_t)
93+
for(std::uint8_t bit = 0; bit < triggerWord.size(); ++bit) {
94+
if(!triggerWord[bit]) continue;
95+
ptb_timestamp.push_back(trig.currPTBTimeStamp);
96+
ptb_bit.push_back(bit);
97+
}
98+
}
99+
}
76100
}

sbncode/CAFMaker/FillTrigger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lardataobj/RawData/TriggerData.h"
1010
#include "art/Framework/Principal/Handle.h"
1111
#include "sbndaq-artdaq-core/Obj/SBND/pmtSoftwareTrigger.hh"
12+
#include "sbncode/BeamSpillInfoRetriever/POTTools.h"
1213

1314
namespace caf
1415
{
@@ -30,6 +31,8 @@ namespace caf
3031
art::Handle<bool> const& passedTrig,
3132
caf::SRTrigger& triggerInfo);
3233
void FillSoftwareTriggerSBND(const sbnd::trigger::pmtSoftwareTrigger& softInfo, caf::SRSoftwareTrigger& caf_softInfo);
34+
35+
void FillPTBTriggersSBND(const std::vector<sbn::pot::PTBInfo_t>& ptb_triggers, caf::SRTrigger& triggerInfo);
3336
}
3437

3538
#endif

0 commit comments

Comments
 (0)