Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JRandomTimeslice.hh
Go to the documentation of this file.
1#ifndef __JTIMESLICE__JRANDOMTIMESLICE__
2#define __JTIMESLICE__JRANDOMTIMESLICE__
3
4#include <vector>
5#include <set>
6
7#include <TRandom3.h>
8
17
18
19/**
20 * \author mdejong
21 */
22
23namespace KM3NETDAQ {
24
26
27
28 /**
29 * Timeslice with random data.
30 */
32 public JTimesliceL0
33 {
34 /**
35 * Default constructor.
36 */
39
40
41 /**
42 * Constructor.
43 *
44 * \param chronometer chronometer
45 * \param simbad detector simulator
46 */
49 {
50 using namespace JPP;
51
53
54 if (simbad.hasK40Simulator() &&
55 simbad.hasPMTSimulator() &&
56 simbad.hasCLBSimulator()) {
57
58 const double Tmin = getTimeSinceRTS(chronometer.getFrameIndex()); // [ns]
59
60 const JTimeRange period(Tmin, Tmin + getFrameTime()); // [ns]
61
62 JModuleData buffer;
63
64 for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) {
65
66 if (!module->empty() && simbad.getCLBSimulator().hasCLB(module->getID())) {
67
68 buffer.reset(module->size());
69
70 simbad.generateHits(*module, period, buffer);
71
72 this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID())));
73
74 simbad(*module, buffer, *(this->rbegin()));
75 }
76 }
77 }
78 }
79
80
81 /**
82 * Recycle time slice by randomly shuffling time intervals of data.
83 *
84 * Hits within one time interval are swapped with hits within another -randomly selected- time interval.\n
85 * Time intervals in which a high-rate veto occurred are excluded.
86 *
87 * Note that the time interval should be:
88 * - (much) larger than time differences of hits in L1 coincidence; and
89 * - (much) smaller than time covered by data (as per KM3NETDAQ::getFrameTime()).
90 *
91 * \param T_ns time interval
92 */
93 void recycle(const double T_ns)
94 {
95 using namespace std;
96 using namespace JPP;
97
99 typedef JDAQHit::JTDC_t JTDC_t;
100
101 size_t N = (size_t) (getFrameTime() / T_ns + 0.5); // number of time intervals
102
103 if (N < 100) { N = 100; } // allow to keep indices at time of high-rate veto
104 if (N > 50000) { N = 50000; } // maximum expected number of hits due to high-rate veto
105
106 const JTDC_t Ts = (JTDC_t) (getFrameTime() / N); // TDC interval
107
108 random_indices_t index (N); // indices of time intervals for swapping
109 vector<buffer_type> buffer(N); // data per time interval
110
111 for (iterator frame = this->begin(); frame != this->end(); ++frame) {
112
113 if (!frame->empty()) {
114
115 for (size_t i = 0; i != N; ++i) {
116 buffer[i].clear();
117 }
118
119 // store data per time interval
120
121 vector<JTDC_t> T_max(NUMBER_OF_PMTS,
122 numeric_limits<JTDC_t>::max()); // maximal time per PMT, e.g. due to high-rate veto
123
124 for (JDAQSuperFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
125
126 T_max[hit->getPMT()] = hit->getT();
127
128 const int i = hit->getT() / Ts;
129
130 buffer[i].push_back(*hit);
131 }
132
133 set<size_t> keep; // indices corresponding to times of high-rate veto
134
135 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
136 if (frame->testHighRateVeto(pmt)) {
137 keep.insert(T_max[pmt] / Ts);
138 }
139 }
140
141 index.random_shuffle(keep); // randomly shuffle values between kept indices
142
143 // Wall street shuflle
144
145 JDAQSuperFrame::iterator hit = frame->begin();
146
147 for (size_t in = 0; in != N; ++in) {
148
149 const size_t out = index [in];
150 buffer_type& zbuf = buffer[out];
151
152 const JTDC_t T_in = in * Ts;
153 const JTDC_t T_out = out * Ts;
154
155 for (buffer_type::iterator i = zbuf.begin(); i != zbuf.end(); ++i, ++hit) {
156 *hit = JDAQHit(i->getPMT(), (i->getT() - T_out) + T_in, i->getToT());
157 }
158 }
159 }
160 }
161 }
162
163
164 /**
165 * Auxiliary data structure for randomisation of indices.
166 */
168 public std::vector<size_t>
169 {
170 /**
171 * Constructor.
172 *
173 * \param N number of indices
174 */
175 random_indices_t(const size_t N) :
176 std::vector<size_t>(N)
177 {}
178
179 /**
180 * Randomly shuffle values between fixed indices.
181 *
182 * \param keep fixed indices
183 */
185 {
186 for (size_t i = 0; i != this->size(); ++i) {
187 (*this)[i] = i;
188 }
189
190 size_t i1 = 0;
191
192 for (const size_t i2 : keep) {
193
195
196 i1 = i2 + 1;
197 }
198
199 random_shuffle(i1, this->size());
200 }
201
202 private:
203 /**
204 * Randomly shuffle values between given indices.
205 *
206 * \param i1 first index (included)
207 * \param i2 last index (excluded)
208 */
209 inline void random_shuffle(const int i1, const int i2)
210 {
211 for (int i = i2 - 1; i > i1; --i) {
212
213 const int l = i1 + gRandom->Integer(i - i1);
214
215 std::swap((*this)[i], (*this)[l]);
216 }
217 }
218 };
219 };
220}
221
222#endif
223
KM3NeT DAQ constants, bit handling, etc.
Auxiliaries for creation of time slice data.
Data structure for PMT data corresponding to a detector module.
void reset(size_t size)
Reset buffers.
Template definition of a multi-dimensional oscillation probability interpolation table.
void insert(const JMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input)
Insert multidimensional input.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Hit data structure.
Definition JDAQHit.hh:35
Data frame of one optical module.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:70
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition JDAQClock.hh:263
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26
Auxiliary class for TDC constraints.
Definition JTDC_t.hh:39
Auxiliary data structure for randomisation of indices.
void random_shuffle(const int i1, const int i2)
Randomly shuffle values between given indices.
void random_shuffle(const std::set< size_t > &keep)
Randomly shuffle values between fixed indices.
Timeslice with random data.
JRandomTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad)
Constructor.
JRandomTimeslice()
Default constructor.
void recycle(const double T_ns)
Recycle time slice by randomly shuffling time intervals of data.
Base class class for generation of time slice data.