11 #include <tst/Verify.h>
12 #include <utl/AugerUnits.h>
13 #include <utl/TimeDistribution.h>
14 #include <utl/Trace.h>
15 #include <sdet/StationTriggerAlgorithm.h>
16 #include <cppunit/extensions/HelperMacros.h>
26 #define ASSERT_EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
34 "PLD=" << bitset<16>(info.
GetPLDBits()) <<
", "
38 "stop=" << info.
GetStop() <<
", "
47 CPPUNIT_TEST(TestOneT1ThresholdOnTimeDistributionI);
48 CPPUNIT_TEST(TestOneT2ThresholdOnTimeDistributionI);
49 CPPUNIT_TEST(TestManyT1ThresholdOnTimeDistributionI);
56 CPPUNIT_TEST_SUITE_END();
59 const double fUBSampling = 25*
ns;
60 const double fT1Threshold = 1.7;
61 const double fTOTThreshold = 0.2;
62 const double fTOTdThreshold = 0.2;
63 const double fT2Threshold = 3.4;
64 const double fTOTdDecayInBins = 67 / fUBSampling;
65 const int fLatchBin = 246;
66 const int fTraceLength = 3*1024/4;
76 " +----------------- ePLDRandom" "\n"
78 " | +------------- ePLDTOTC (MoPS)" "\n"
79 " | |+------------ ePLDTOTB (TOTd)" "\n"
80 " | ||+----------- ePLDTOTA (TOT)" "\n"
81 " | |||+---------- ePLDThreshold" "\n"
83 " | |||| +------ ePLDLatchRandom" "\n"
84 " | |||| |+----- ePLDLatchTOTC (MoPS)" "\n"
85 " | |||| ||+---- ePLDLatchTOTB (TOTd)" "\n"
86 " | |||| |||+--- ePLDLatchTOTA (TOT)" "\n"
87 " | |||| ||||+-- ePLDLatchThreshold" "\n"
89 " (PLD=f...ba98...43210," "\n"
100 const double vem = 60;
104 const int bin = -123;
105 trace1[bin] = trace2[bin] = trace3[bin] = 2*vem;
107 const int start = bin - fLatchBin + 1;
108 vector<StationTriggerInfo> info;
109 info.emplace_back(StationTriggerData::ePLDLatchThreshold,
false, start, bin, start + fTraceLength);
111 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"one t1th");
121 const int bin = -123;
122 trace1[bin] = trace2[bin] = trace3[bin] = 3.5*vem;
124 const int start = bin - fLatchBin + 1;
125 vector<StationTriggerInfo> info;
126 info.emplace_back(StationTriggerData::ePLDLatchThreshold,
true, start, bin, start + fTraceLength);
128 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"one t2th");
139 const int bin[] = { -1000+300, 0+300, 1000+300 };
140 constexpr
int nBits = Length(bin);
141 for (
int i = 0; i < nBits; ++i) {
142 trace1[bin[i]] = trace2[bin[i]] = trace3[bin[i]] = 2*vem;
143 trace1[bin[i]+1] = trace2[bin[i]+1] = trace3[bin[i]+1] = 1*vem;
146 vector<StationTriggerInfo> info;
147 for (
int i = 0; i < nBits; ++i) {
148 const int start = bin[i] - fLatchBin + 1;
149 info.emplace_back(StationTriggerData::ePLDLatchThreshold,
false, start, bin[i], start + fTraceLength);
152 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"many t1th");
164 const int thBin = -666;
165 trace1[thBin] = trace2[thBin] = trace3[thBin] = 2*vem;
168 const int totBin = thBin + 200;
169 const int nCoinc = 15;
170 const int stride = 5;
171 for (
int i = 0; i < nCoinc; ++i) {
172 const int bin = totBin + stride*i;
175 case 0: trace1[bin] = trace2[bin] = 0.3*vem;
break;
176 case 1: trace1[bin] = trace3[bin] = 0.3*vem;
break;
177 case 2: trace2[bin] = trace3[bin] = 0.3*vem;
break;
178 case 3: trace1[bin] = trace2[bin] = trace3[bin] = 0.3*vem ;
break;
182 const int start = thBin - fLatchBin + 1;
183 vector<StationTriggerInfo> info;
185 StationTriggerData::ePLDLatchThreshold | StationTriggerData::ePLDTOTA,
false,
186 start, thBin, start + fTraceLength
189 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"one t1th and one tot");
201 const int totBin = 666;
202 const int nCoinc = 20;
203 const int stride = 5;
204 for (
int i = 0; i < nCoinc; ++i) {
205 const int bin = totBin + stride*i;
208 case 0: trace1[bin] = trace2[bin] = 0.3*vem;
break;
209 case 1: trace1[bin] = trace3[bin] = 0.3*vem;
break;
210 case 2: trace2[bin] = trace3[bin] = 0.3*vem;
break;
211 case 3: trace1[bin] = trace2[bin] = trace3[bin] = 0.4*vem ;
break;
216 const int latch = totBin + (13-1)*stride;
217 const int start = latch - fLatchBin + 1;
218 vector<StationTriggerInfo> info;
220 StationTriggerData::ePLDLatchTOTA | StationTriggerData::ePLDTOTA,
false,
221 start, latch, start + fTraceLength
224 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"one tot");
235 const int first = -1000;
236 const int last = 2000;
237 const int stride = 5;
239 for (
int i = first; i < last; i += stride) {
241 switch (
abs(i % 4)) {
242 case 0: trace1[i] = trace2[i] = 0.3*vem;
break;
243 case 1: trace1[i] = trace3[i] = 0.3*vem;
break;
244 case 2: trace2[i] = trace3[i] = 0.3*vem;
break;
245 case 3: trace1[i] = trace2[i] = trace3[i] = 0.4*vem ;
break;
249 const int length = last - first;
250 const int traceLength = fTraceLength - (fLatchBin-1);
251 const int nT1 = length/traceLength + bool((length % traceLength)/(12*3 + 1));
253 vector<StationTriggerInfo> info;
254 for (
int i = 0; i < nT1; ++i) {
255 const int latch = first + traceLength*i + (13-1)*stride;
256 const int start = latch - fLatchBin + 1;
258 StationTriggerData::ePLDLatchTOTA | StationTriggerData::ePLDTOTA,
false,
259 start, latch, start + fTraceLength
263 Check(vem, 0, first, last, trace1, trace2, trace3, info,
"many tot");
275 const int totBin = 666;
276 const int nCoinc = 20;
277 const int stride = 2;
278 for (
int i = 0; i < nCoinc; ++i) {
279 const int bin = totBin + stride*i;
281 case 0: trace1[bin] = 0.22*vem;
break;
282 case 1: trace2[bin] = 0.22*vem;
break;
283 case 2: trace3[bin] = 0.22*vem;
break;
284 case 3: trace1[bin] = trace2[bin] = 0.22*vem;
break;
285 case 4: trace1[bin] = trace3[bin] = 0.22*vem;
break;
286 case 5: trace2[bin] = trace3[bin] = 0.22*vem;
break;
287 case 6: trace1[bin] = trace2[bin] = trace3[bin] = 0.25*vem ;
break;
292 const int latch = totBin + (18-1)*stride;
295 const int start = latch - fLatchBin + 1;
296 vector<StationTriggerInfo> info;
298 StationTriggerData::ePLDLatchTOTB | StationTriggerData::ePLDTOTB,
false,
299 start, latch, start + fTraceLength
301 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"two totd");
304 double previous_1 = 0;
305 double previous_2 = 0;
306 double previous_3 = 0;
307 const double rate = exp(-1/fTOTdDecayInBins);
308 for (
int bin = totBin; bin < totBin + nCoinc*stride + 10; ++bin) {
309 trace1[bin] += previous_1 * rate;
310 trace2[bin] += previous_2 * rate;
311 trace3[bin] += previous_3 * rate;
312 previous_1 = trace1[bin];
313 previous_2 = trace2[bin];
314 previous_3 = trace3[bin];
319 StationTriggerData::ePLDLatchTOTB | StationTriggerData::ePLDTOTB | StationTriggerData::ePLDTOTA,
false,
320 start, latch, start + fTraceLength
322 Check(vem, 0, -1000, 2000, trace1, trace2, trace3, info,
"???");
334 const int totBin = 666;
335 const int nCoinc = 20;
336 const int stride = 2;
337 for (
int i = 0; i < nCoinc; ++i) {
338 const int bin = totBin + stride*i;
340 case 0: trace1[bin] = 0.22*vem;
break;
341 case 1: trace2[bin] = 0.22*vem;
break;
342 case 2: trace3[bin] = 0.22*vem;
break;
343 case 3: trace1[bin] = trace2[bin] = 0.22*vem;
break;
344 case 4: trace1[bin] = trace3[bin] = 0.22*vem;
break;
345 case 5: trace2[bin] = trace3[bin] = 0.22*vem;
break;
346 case 6: trace1[bin] = trace2[bin] = trace3[bin] = 0.25*vem ;
break;
351 double previous_1 = 0;
352 double previous_2 = 0;
353 double previous_3 = 0;
354 const double rate = exp(-1/fTOTdDecayInBins);
355 for (
int bin = totBin; bin < totBin + nCoinc*stride + 10; ++bin) {
356 trace1[bin] += previous_1 * rate;
357 trace2[bin] += previous_2 * rate;
358 trace3[bin] += previous_3 * rate;
359 previous_1 = trace1[bin];
360 previous_2 = trace2[bin];
361 previous_3 = trace3[bin];
365 const double baseline = 50;
366 for (
int bin = -1000; bin <= 2000; ++bin) {
367 trace1[bin] += baseline;
368 trace2[bin] += baseline;
369 trace3[bin] += baseline;
373 const int latch = totBin + (18-1)*stride;
376 const int start = latch - fLatchBin + 1;
378 vector<StationTriggerInfo> info;
380 StationTriggerData::ePLDLatchTOTB | StationTriggerData::ePLDTOTB | StationTriggerData::ePLDTOTA,
false,
381 start, latch, start + fTraceLength
383 Check(vem, baseline, -1000, 2000, trace1, trace2, trace3, info,
"one tot (with nonzero baseline)");
413 template<
class Trace>
415 Check(
const double vem,
const double baseline,
416 const int first,
const int last,
418 const vector<StationTriggerInfo>& shouldGet,
419 const string& comment =
"")
422 if (!comment.empty())
423 cerr << comment <<
'\n';
425 using namespace sdet::Trigger;
427 ThresholdUp t1th(
int(round(baseline + fT1Threshold*vem)), 3, 3);
428 ThresholdUp t2th(
int(round(baseline + fT2Threshold*vem)), 3, 3);
438 const vector<const Trace*> traces = { &t1, &t2, &t3 };
439 const vector<StationTriggerInfo> infos = sTrig.
Run(first, last, traces);
440 Match(infos, shouldGet);
441 const auto stot = SimpleToT(fTOTThreshold*vem, baseline, 12, 120, 2, first, last, traces);
442 cerr <<
" SimpleToT " << stot.first <<
' ' << stot.second <<
"\n\n";
447 Match(
const vector<StationTriggerInfo>& infos1,
const vector<StationTriggerInfo>& infos2)
449 if (infos1.size() != infos2.size()) {
451 for (
unsigned int i = 0; i < infos1.size(); ++i)
452 cerr <<
"trigger info " << i <<
": " << infos1[i] <<
'\n';
455 for (
unsigned int i = 0; i < infos1.size(); ++i) {
458 cerr <<
"match " << i+1 <<
'/' << infos1.size() <<
":\n " << info1 <<
" =?=\n " << info2;
461 ASSERT_EQUAL(info1.IsT1Threshold(), info2.IsT1Threshold());
462 ASSERT_EQUAL(info1.IsTimeOverThreshold(), info2.IsTimeOverThreshold());
473 template<
class Trace>
477 const int occupancy,
const int window,
const int multiplicity,
478 const int first,
const int last,
479 const vector<const Trace*>& traces)
481 const int maxi =
max(last - window, first);
482 for (
int i = first; i <= maxi; ++i) {
483 const int maxj = min(i + window, last);
485 for (
int j = i; j <= maxj; ++j) {
487 for (
const auto t : traces) {
488 const double s = (*t)[j] - baseline;
492 if (m >= multiplicity) {
494 if (trig > occupancy)
495 return make_pair(
true, j);
499 return make_pair(
false, 0);
void TestOneT1ThresholdOnTimeDistributionI()
bool IsT2Threshold() const
Histogram class for time distributions with suppressed empty bins.
void Check(const double vem, const double baseline, const int first, const int last, const Trace &t1, const Trace &t2, const Trace &t3, const vector< StationTriggerInfo > &shouldGet, const string &comment="") const
static pair< bool, int > SimpleToT(const double totTh, const double baseline, const int occupancy, const int window, const int multiplicity, const int first, const int last, const vector< const Trace * > &traces)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
int GetStart() const
First bin of trace.
ostream & operator<<(ostream &os, const Separator< T > &s)
double abs(const SVector< n, T > &v)
void Check(const Iterator &i, const Iterator &e, const int id)
a t3: algo, second, usecond and a vector of <t3stat>
void TestManyT1ThresholdOnTimeDistributionI()
void TestOneTOTdOnTimeDistributionIWithBaseline()
void TestOneTOTOnTimeDistributionI()
Local station hardware (PLD) and software (T2) trigger algorithm.
int GetStop() const
Last+1 bin of trace.
void TestOneTOTdOnTimeDistributionI()
void TestOneT2ThresholdOnTimeDistributionI()
#define ASSERT_EQUAL(x, y)
void TestT1ThresholdAndTOTOnTimeDistributionI()
TestStationTriggerAlgorithm()
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
std::vector< StationTriggerInfo > Run(const int start, const int stop, const std::vector< const Trace< T > * > &traces)
static void Match(const vector< StationTriggerInfo > &infos1, const vector< StationTriggerInfo > &infos2)
void TestManyTOTOnTimeDistributionI()