Skip to content

Commit 8b5120e

Browse files
author
Benjamin Harris
committed
Add PTB HLT and LLT information to CAF files for real SBND data
1 parent 5ff32f5 commit 8b5120e

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

sbncode/BeamSpillInfoRetriever/POTTools.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ namespace sbn::pot{
4343
}
4444
}
4545

46+
std::vector<PTBInfo_t> extractAllPTBInfo(art::Handle<std::vector<artdaq::Fragment> > 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+
double currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong()/50e6;
62+
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong()/50e6;
63+
PTBInfo.currPTBTimeStamp = currTS_candidate;
64+
PTBInfo.GateCounter = ctb_frag.Trigger(word_i)->gate_counter;
65+
PTBInfo.isHLT = ctb_frag.Trigger(word_i)->IsHLT();
66+
PTBInfo.triggerWord = ctb_frag.Trigger(word_i)->trigger_word;
67+
PTBInfoVec.push_back(PTBInfo);
68+
}
69+
}
70+
}
71+
}
72+
73+
return PTBInfoVec;
74+
}
75+
4676
double extractTDCTimeStamp(art::Handle<std::vector<artdaq::Fragment> > cont_frags) {
4777

4878
double TDCTimeStamp = 0;

sbncode/BeamSpillInfoRetriever/POTTools.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
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 {
2021
double currPTBTimeStamp = 1e20;
2122
double prevPTBTimeStamp = 0;
2223
unsigned int GateCounter = 0;
24+
bool isHLT = false;
25+
uint64_t triggerWord = 0;
2326
} PTBInfo_t;
2427

2528
typedef struct TriggerInfo_t {
@@ -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(art::Handle<std::vector<artdaq::Fragment> > cont_frags);
56+
4657
/**
4758
* @brief Extracts information from TDC for use in SBND POT accounting.
4859
*

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
116116
#include "sbnobj/Common/POTAccounting/EXTCountInfo.h"
117117
#include "sbnobj/Common/POTAccounting/NuMISpillInfo.h"
118+
#include "sbncode/BeamSpillInfoRetriever/POTTools.h"
119+
#include "artdaq-core/Data/ContainerFragment.hh"
118120
#include "sbnobj/Common/Trigger/ExtraTriggerInfo.h"
119121
#include "sbnobj/Common/Reco/CRUMBSResult.h"
120122
#include "sbnobj/Common/Reco/OpT0FinderResult.h"
@@ -1711,6 +1713,23 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17111713
FillTriggerEmulation(monpulses_handle, monpulse_sizes_handle, pairs_handle, trigemu_handle, srtrigger);
17121714
}
17131715

1716+
1717+
// Fill PTB (Penn Trigger Board) information for SBND real data
1718+
if (isRealData && fDet == kSBND) {
1719+
art::InputTag PTB_itag("daq", "ContainerPTB");
1720+
art::Handle<artdaq::Fragments> ptb_frags_handle;
1721+
evt.getByLabel(PTB_itag, ptb_frags_handle);
1722+
if (ptb_frags_handle.isValid()) {
1723+
try {
1724+
std::vector<sbn::pot::PTBInfo_t> ptb_triggers = sbn::pot::extractAllPTBInfo(ptb_frags_handle);
1725+
FillPTBTriggersSBND(ptb_triggers, srtrigger);
1726+
}
1727+
catch (...) {
1728+
std::cout << "CAFMaker: Failed to extract PTB triggers" << std::endl;
1729+
}
1730+
}
1731+
}
1732+
17141733
// If not real data, fill in enough of the SRTrigger to make (e.g.) the CRT
17151734
// time referencing work. TODO: add more stuff to a "MC"-Trigger?
17161735
// 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
@@ -50,6 +50,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
5050
${GENIE_LIB_LIST}
5151
nugen::EventGeneratorBase_GENIE
5252
sbndaq_artdaq_core::sbndaq-artdaq-core_Obj_SBND
53+
sbn_POTTools
5354
)
5455

5556
cet_build_plugin ( CAFMaker art::module

sbncode/CAFMaker/FillTrigger.cxx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,28 @@ namespace caf
7373
caf_softInfo.flash_peakpe = softInfo.peakPE;
7474
caf_softInfo.flash_peaktime = softInfo.peaktime + softInfo.trig_ts*1e-3;
7575
}
76+
77+
void FillPTBTriggersSBND(const std::vector<sbn::pot::PTBInfo_t>& ptb_triggers, caf::SRTrigger& triggerInfo) {
78+
triggerInfo.ptb_hlt_timestamp.clear();
79+
triggerInfo.ptb_hlt_bit.clear();
80+
triggerInfo.ptb_llt_timestamp.clear();
81+
triggerInfo.ptb_llt_bit.clear();
82+
83+
// Decode trigger words: each set bit becomes a separate entry with the same timestamp
84+
for(const auto& trig : ptb_triggers) {
85+
std::uint64_t triggerWord = trig.triggerWord;
86+
for(int bit = 0; bit < 64; ++bit) {
87+
std::uint64_t bitMask = 1ULL << bit;
88+
if(triggerWord & bitMask) {
89+
if(trig.isHLT) {
90+
triggerInfo.ptb_hlt_timestamp.push_back(trig.currPTBTimeStamp);
91+
triggerInfo.ptb_hlt_bit.push_back(bit);
92+
} else {
93+
triggerInfo.ptb_llt_timestamp.push_back(trig.currPTBTimeStamp);
94+
triggerInfo.ptb_llt_bit.push_back(bit);
95+
}
96+
}
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)