Skip to content

Commit 4d96ccf

Browse files
Merge branch 'develop' into feature/hjscott1
2 parents 310e5e2 + f0f9d96 commit 4d96ccf

31 files changed

Lines changed: 2071 additions & 109 deletions

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
1717

18-
set(${PROJECT_NAME}_CMAKE_PROJECT_VERSION_STRING 09.93.01)
18+
set(${PROJECT_NAME}_CMAKE_PROJECT_VERSION_STRING 09.93.01.01)
1919
find_package(cetmodules REQUIRED)
2020
project(sbndcode LANGUAGES CXX)
2121

2222
# for CI:
23-
# project(sbndcode VERSION 09.93.01)
23+
# project(sbndcode VERSION 09.93.01.01)
2424

2525
message(STATUS "\n")
2626
message(STATUS "================================= ${PROJECT_NAME} =================================")

sbndcode/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ add_subdirectory(OpT0Finder)
2121
add_subdirectory(ShowerAna)
2222
add_subdirectory(Commissioning)
2323
add_subdirectory(Trigger)
24+
add_subdirectory(Timing)
25+
add_subdirectory(PTBAna)
2426

2527
# subdirectory for gallery stuff
2628
add_subdirectory(gallery)

sbndcode/Decoders/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ add_subdirectory(PTB)
33
add_subdirectory(SPECTDC)
44
add_subdirectory(PMT)
55
add_subdirectory(CRT)
6+
add_subdirectory(XARAPUCA)
67

7-
install_fhicl()
8+
install_fhicl()
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
art_make(
2-
MODULE_LIBRARIES
1+
cet_build_plugin( SBNDPMTDecoder art::module
2+
SOURCE SBNDPMTDecoder_module.cc
3+
LIBRARIES
34
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_SBND
45
sbnobj::SBND_Timing
5-
6+
lardata::Utilities
7+
canvas::canvas
68
lardataobj::RecoBase
7-
9+
lardataobj::RawData
10+
lardataobj::headers
811
art_root_io::TFileService_service
912
art_root_io::tfile_support
1013
artdaq_core::artdaq-core_Data
11-
1214
ROOT::Core
1315
ROOT::Tree
14-
1516
)
1617

1718
install_fhicl()
19+
install_headers()
20+
install_source()

sbndcode/Decoders/PMT/SBNDPMTDecoder_module.cc

Lines changed: 324 additions & 68 deletions
Large diffs are not rendered by default.

sbndcode/Decoders/PMT/pmtdecoder.fcl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,46 @@ pmtdecoder:
1313

1414
# configure CAEN inputs
1515
caen_fragment_name: [ "CAENV1730", "ContainerCAENV1730" ]
16-
ignore_fragid: [8] # boards to ignore for testing purposes, fragid==8 is the timing board, this is 0-indexed!
16+
ignore_fragid: [] # boards to ignore for testing purposes, fragid==8 is the timing board, this is 0-indexed!
1717
nominal_length: 5000 # expected waveform length
18+
raw_ts_correction: 367000 # ns, correction to the rawheader timestamp
1819

1920
# configure SPEC TDC inputs
2021
spectdc_product_name: "tdcdecoder" # used if the tdc decoder has been run
21-
spectdc_ftrig_ch: 3 # this should be the channel number of the spec tdc that stores the flash trigger
22-
spectdc_etrig_ch: 4 # this should be the channel number of the spec tdc that stores the event trigger
22+
spectdc_ftrig_ch: 3 # channel number of the spec tdc that stores the flash trigger
23+
spectdc_etrig_ch: 4 # channel number of the spec tdc that stores the event trigger
2324

24-
# configure PTB inputs
25+
# configure PTB inputs; the HLT with the smallest trigger word will be used (within some range to the rawheader timestamp)
2526
ptb_product_name: "ptbdecoder"
26-
ptb_etrig_trigword: 0x0000000000000000
27+
ptb_etrig_trigword_min: 1 # minimum trigger word (in decimal)
28+
ptb_etrig_trigword_max: 100000 # maximum trigger word (in decimal)
2729
ptb_etrig_wordtype: 2
30+
ptb_trig_raw_diff_max: 3000000 # the maximum allowed time difference in ns
2831

2932
# configure output options
33+
# use time difference between reference + CAEN used to determine rollover and/or weirdness
34+
allowed_time_diff: 3000 # us!! not nanoseconds
3035
# configure the output data product instance names
3136
pmtInstanceName: "PMTChannels"
3237
ftrigInstanceName: "FTrigChannels"
38+
timingInstanceName: "TimingChannels"
3339
output_ftrig_wvfm: true # whether or not to output the ftrig as an opdetwaveform (artroot data product)
40+
output_timing_wvfm: true # whether or not to output the timing caen wvfms as an opdetwaveform (artroot data product)
41+
ignore_timing_ch: [4,5,6,7,8,9,10,11,12,13,14] # only ch0=BES, ch1=RWM, ch2=ETRIG, ch3=MSUM, ch15=FTRIG
3442

3543
# more detailed configurables
3644
n_maxflashes: 30 # maximum number of flashes anticipated, this is used for memory allocation
37-
n_caenboards: 8 # number of caen boards; this is used for memory allocation
45+
n_caenboards: 9 # number of caen boards; this is used for memory allocation
46+
# 1-8 = PMT caens, 9th = timing caen
3847
threshold_ftrig: 16350 # the threshold for the flash trigger channel
3948

4049
fragid_offset: 40960 # the offset to subtract to get single digit fragids; if use_set_map is true, should set this to 0
4150
hist_evt: 1 # the # of the event used to generate the histograms, 1st event by default
4251

43-
# for when the fragIDs are mapped to the old configuration...
44-
set_fragid_map: [3,7,5,9,11,13,15,17,19] # digitizers 0-8 are mapped to these fragids
52+
# for when the fragIDs are mapped to the old configuration or you need to hardcode fragids...
53+
## to use this, must set `fragid_offset` to 0!!!
4554
use_set_map: false
55+
set_fragid_map: [3,7,5,9,11,13,15,17,19] # use if `use_set_map` is true: digitizers 0-8 are mapped to these fragids
4656

4757
# ordered in sets of 15 by increasing fragID
4858
# the PMT_to_Digitizers.txt file in the same directory is the reference for this
@@ -54,7 +64,8 @@ pmtdecoder:
5464
173,172,227,226,197,196,171,170,225,224,169,168,223,222,167, # digitizer 4
5565
195,194,221,220,165,164,219,218,193,192,163,162,217,216,166, # digitizer 5
5666
251,250,305,304,275,274,249,248,303,302,247,246,301,300,245, # digitizer 6
57-
273,272,299,298,243,242,297,296,271,270,241,240,295,294,244] # digitizer 7
67+
273,272,299,298,243,242,297,296,271,270,241,240,295,294,244, # digitizer 7
68+
900,901,902,903,904,905,906,907,908,909,910,911,912,913,914] # digitizer 8 (TIMING CAEN)
5869
}
5970

6071
END_PROLOG

sbndcode/Decoders/PTB/SBNDPTBDecoder_module.cc

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ SBNDPTBDecoder::SBNDPTBDecoder(fhicl::ParameterSet const & p)
7878

7979
void SBNDPTBDecoder::produce(art::Event & evt)
8080
{
81-
82-
8381
// look first for container fragments and then non-container fragments
84-
8582
std::vector<raw::ptb::sbndptb> sbndptbs;
8683

8784
art::InputTag itag1(fInputLabel, fInputContainerInstance);
@@ -117,6 +114,61 @@ void SBNDPTBDecoder::produce(art::Event & evt)
117114
evt.put(std::make_unique<std::vector<raw::ptb::sbndptb>>(std::move(sbndptbs)),fOutputInstance);
118115
}
119116

117+
118+
void print_fragment_words(const artdaq::Fragment& frag, size_t wordNum, size_t bitsPerWord ) {
119+
120+
const __uint8_t* data_ptr = reinterpret_cast<const __uint8_t*>(frag.dataBegin());
121+
size_t wordCount = frag.dataSizeBytes() / (bitsPerWord / 8);
122+
for (size_t w = 0; w < wordCount; w++) {
123+
// Check if the current word index matches the specified word index
124+
if (w == wordNum) {
125+
// Print the bits for the specified n-bit word
126+
for (int i = (bitsPerWord-1); i >= 0; --i) {
127+
// Calculate the byte index and bit index
128+
size_t byteIndex = w * (bitsPerWord / 8) + (i / 8);
129+
int bitIndex = (i % 8); // Get the correct bit position in the byte
130+
// Print the bit
131+
std::cout << static_cast<int>((data_ptr[byteIndex] >> bitIndex) & 1);
132+
if (i % 8 == 0) {
133+
std::cout << " ";
134+
}
135+
}
136+
std::cout << std::endl; // New line after printing the word
137+
}
138+
}
139+
}
140+
141+
142+
//Copied from Lines 1382-1406 from sbndaq-artdaq/sbndaq-artdaq/ArtModules/SBND/EventAna_module.cc
143+
144+
/*******************************************
145+
* Note: Below for the Timestamp conversion,
146+
* The PTB TS is in UTC seconds since the Unix epoch in 50MHz clock ticks.
147+
* This means to recover seconds since the Unix epoch use: sec_since_epoch = TS / 50e6
148+
* and of course nanosec_since_epoch = (TS / 50e6) * 1e9 = TS * 20
149+
*
150+
* Note: The `CTBFragment` constructor grabs the chunk of memory the artDAQ fragment occupies.
151+
* Since we know a priori the number of PTB words (from the TCP header) and the size (128b for all words)
152+
* we can loop over the memory addresses, casting each 128b into the correct word type given by each word's `type`.
153+
*
154+
* There are 5 word types with the following bit arrangement:
155+
* Feeback = | 3b Word Type | 61b Payload | 64b Timestamp | (here Payload is split into code, source, payload1, payload2)
156+
* LLT, HLT = | 3b Word Type | 61b Payload | 64b Timestamp |
157+
* Channel Status = | 3b Word Type | 64b Payload | 61b Timestamp | (Larger Payload to fit all input channels)
158+
*
159+
* Word Type:
160+
* - 0x0 = Feedback/Error Word -> Errors from the firmware, should abort the run
161+
* - 0x1 = Low Level Trigger (LLT) -> Holds a record of any asserted LLTs
162+
* - 0x2 = High Level Trigger (HLT) -> Holds a record of any asserted HLTs
163+
* - 0x3 = Channel status -> Holds a record of any asserted inputs
164+
* - 0x7 = Timestamp Word -> No payload just a timestamp, these are periodic
165+
*
166+
* Note: Payload AND'd with mask the size of the expected number of bits just
167+
* to make sure we don't get any unexpected garbage bits since we aren't using
168+
* the full bits of the variable type e.g. uint64_t, unint16_t..
169+
**************************************/
170+
171+
120172
void SBNDPTBDecoder::_process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sout)
121173
{
122174
sbndaq::CTBFragment ctbfrag(frag); // somehow the name CTBFragment stuck
@@ -145,8 +197,19 @@ void SBNDPTBDecoder::_process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sou
145197
tstruct.timestamp = ctbfrag.Trigger(iword)->timestamp;
146198
if (ctbfrag.Trigger(iword)->IsHLT())
147199
{
200+
201+
if (*(frag.metadata<int>()) == 2){ //If data is taken with 192b PTB words
202+
tstruct.prev_timestamp = ctbfrag.PTBWord(iword)->prevTS;
203+
tstruct.gate_counter = ctbfrag.Trigger(iword)->gate_counter;
204+
}
205+
else if (*(frag.metadata<int>()) != 2){ //If data is taken with 128b PTB words
206+
tstruct.prev_timestamp = 0;
207+
tstruct.gate_counter = 0;
208+
}
209+
148210
ix = sout.HLTrigs.size();
149211
sout.HLTrigs.push_back(tstruct);
212+
150213
if (fDebugLevel > 0)
151214
{
152215
std::cout << "SBNDPTBDecoder_module: found HLT: " << wt << " " << ix << std::endl;

sbndcode/Decoders/PTB/classes_def.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
-->
66

77
<lcgdict>
8-
<class name="raw::ptb::Trigger" ClassVersion="10">
8+
<class name="raw::ptb::Trigger" ClassVersion="11">
9+
<version ClassVersion="11" checksum="1173933314"/>
910
<version ClassVersion="10" checksum="983962440"/>
1011
</class>
11-
<class name="raw::ptb::ChStatus" ClassVersion="10">
12+
<class name="raw::ptb::ChStatus" ClassVersion="11">
13+
<version ClassVersion="11" checksum="1302570871"/>
1214
<version ClassVersion="10" checksum="2716777827"/>
1315
</class>
14-
<class name="raw::ptb::Feedback" ClassVersion="10">
16+
<class name="raw::ptb::Feedback" ClassVersion="11">
17+
<version ClassVersion="11" checksum="2612286493"/>
1518
<version ClassVersion="10" checksum="404427229"/>
1619
</class>
17-
<class name="raw::ptb::Misc" ClassVersion="10">
20+
<class name="raw::ptb::Misc" ClassVersion="11">
21+
<version ClassVersion="11" checksum="686355011"/>
1822
<version ClassVersion="10" checksum="1110799137"/>
1923
</class>
2024
<class name="raw::ptb::WordIndex" ClassVersion="10">

sbndcode/Decoders/PTB/sbndptb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ namespace raw {
1818
namespace ptb {
1919

2020
struct Trigger {
21+
ULong64_t prev_timestamp;
2122
ULong64_t timestamp;
2223
ULong64_t trigger_word;
24+
uint32_t gate_counter;
2325
uint32_t word_type;
2426
};
2527

2628
struct ChStatus {
29+
ULong64_t prev_timestamp;
2730
ULong64_t timestamp;
2831
uint32_t beam;
2932
uint32_t crt;
@@ -35,6 +38,7 @@ namespace raw {
3538
};
3639

3740
struct Feedback {
41+
ULong64_t prev_timestamp;
3842
ULong64_t timestamp;
3943
uint32_t code;
4044
uint32_t source;
@@ -43,6 +47,7 @@ namespace raw {
4347
};
4448

4549
struct Misc {
50+
ULong64_t prev_timestamp;
4651
ULong64_t timestamp;
4752
ULong64_t payload;
4853
uint32_t word_type;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
art_make(
2+
MODULE_LIBRARIES
3+
sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_SBND
4+
sbnobj::SBND_Timing
5+
6+
lardataobj::RecoBase
7+
8+
art_root_io::TFileService_service
9+
art_root_io::tfile_support
10+
artdaq_core::artdaq-core_Data
11+
12+
ROOT::Core
13+
ROOT::Tree
14+
15+
)
16+
17+
install_fhicl()

0 commit comments

Comments
 (0)