Project
Loading...
Searching...
No Matches
testInteractionSampler.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test InteractionSampler class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <algorithm>
16#include <boost/test/unit_test.hpp>
19
20namespace o2
21{
22BOOST_AUTO_TEST_CASE(InteractionSampler)
23{
24 using Sampler = o2::steer::InteractionSampler;
25
26 const int ntest = 100;
27 std::vector<o2::InteractionTimeRecord> records; // destination for records
28 records.reserve(ntest);
29
30 printf("Testing sampler with default settings\n");
31 // default sampler with BC filling like in TPC TDR, 50kHz
32 Sampler defSampler;
33 defSampler.init();
34 defSampler.generateCollisionTimes(records);
35 double t = -1.;
36 for (const auto& rec : records) {
37 BOOST_CHECK(rec.getTimeNS() >= t); // make sure time is non-decreasing
38 t = rec.getTimeNS();
39 }
40
41 printf("\nTesting sampler with custom bunch filling and low mu\n");
42 // configure sampler with custom bunch filling and mu per BC
43 Sampler sampler1;
44 // train of 100 bunches spaced by 25 ns (1slot) and staring at BC=0
45 sampler1.getBunchFilling().setBCTrain(100, 1, 0);
46 // train of 100 bunches spaced by 50 ns (2slots) and staring at BC=200
47 sampler1.getBunchFilling().setBCTrain(200, 2, 200);
48 // add isolated BC at slot 1600
49 sampler1.getBunchFilling().setBC(1600);
50 // add 5 trains of 20 bunches with 100ns(4slots) spacing, separated by 10 slots and
51 // starting at bunch 700
52 sampler1.getBunchFilling().setBCTrains(5, 10, 20, 4, 700);
53 // set total interaction rate in Hz
54 sampler1.setInteractionRate(40e3);
55 sampler1.init();
56 sampler1.generateCollisionTimes(records);
57 t = -1.;
58 for (const auto& rec : records) {
59 BOOST_CHECK(rec.getTimeNS() >= t); // make sure time is non-decreasing
60 t = rec.getTimeNS();
61 }
62
63 // make sure the IR corresponds to declared one
64 records.reserve((int)sampler1.getInteractionRate());
65 sampler1.generateCollisionTimes(records);
66 double dt = (records.back().getTimeNS() - records.front().getTimeNS()) * 1.e-9;
67 printf("\nGenerated %d collisions with time span %.3fs at IR=%e\n",
68 (int)records.size(), dt, sampler1.getInteractionRate());
69 BOOST_CHECK(std::abs(dt - 1.) < 0.1);
70
71 // reconfigure w/o modifying BC filling but setting per bunch
72 // mu (large -> lot of in-bunch pile-up)
73 printf("\nResetting/testing sampler with same bunch filling but high mu\n");
74 sampler1.setMuPerBC(0.5);
75 sampler1.init(); // this will reset all counters from previous calls
76 // instead of filling the vector records, we can sample one by one
77 t = -1.;
78 for (int i = 0; i < ntest; i++) {
79 auto rec = sampler1.generateCollisionTime();
80 rec.print();
81 // make sure time is non-decreasing and the BC is interacting
82 BOOST_CHECK(rec.getTimeNS() >= t && sampler1.getBunchFilling().testBC(rec.bc));
83 t = rec.getTimeNS();
84 }
85 sampler1.print();
86 sampler1.getBunchFilling().print();
87}
88} // namespace o2
int32_t i
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
GPUReconstruction * rec
BOOST_CHECK(tree)