Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRandomTimeslice.hh
Go to the documentation of this file.
1 #ifndef __JTIMESLICE__JRANDOMTIMESLICE__
2 #define __JTIMESLICE__JRANDOMTIMESLICE__
3 
4 #include <vector>
5 
6 #include <TRandom3.h>
7 
10 #include "JDetector/JPMTAddress.hh"
11 #include "JDetector/JTimeRange.hh"
15 
16 
17 /**
18  * \author mdejong
19  */
20 
21 namespace KM3NETDAQ {
22 
24 
25 
26  /**
27  * Timeslice with random data.
28  */
30  public JTimesliceL0
31  {
32  /**
33  * Default constructor.
34  */
36  {}
37 
38 
39  /**
40  * Constructor.
41  *
42  * \param chronometer chronometer
43  * \param simbad detector simulator
44  */
45  JRandomTimeslice(const JDAQChronometer& chronometer,
46  const JDetectorSimulator& simbad)
47  {
48  using namespace JPP;
49 
50  setDAQChronometer(chronometer);
51 
52  if (simbad.hasK40Simulator() &&
53  simbad.hasPMTSimulator() &&
54  simbad.hasCLBSimulator()) {
55 
56  const double Tmin = getTimeSinceRTS(chronometer.getFrameIndex()); // [ns]
57 
58  const JTimeRange period(Tmin, Tmin + getFrameTime()); // [ns]
59 
60  JModuleData buffer;
61 
62  for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) {
63 
64  buffer.reset(module->size());
65 
66  simbad.generateHits(*module, period, buffer);
67 
68  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID())));
69 
70  simbad(*module, buffer, *(this->rbegin()));
71  }
72  }
73  }
74 
75 
76  /**
77  * Recycle time slice by randomly shuffling time intervals of data.
78  *
79  * Hits within one time interval are swapped with hits within another -randomly selected- time interval.
80  *
81  * Note that the time interval should be:
82  * - (much) larger than time differences of hits in L1 coincidence; and
83  * - (much) smaller than time covered by data (as per KM3NETDAQ::getFrameTime()).
84  *
85  * \param T_ns time interval
86  */
87  void recycle(const double T_ns)
88  {
89  using namespace std;
90  using namespace JPP;
91 
92  typedef JDAQHit::JTDC_t JTDC_t;
93 
94 
95  size_t N; // number of time intervals
96 
97  if (T_ns < 1.0)
98  N = (size_t) getFrameTime();
99  else if (T_ns < getFrameTime())
100  N = (size_t) (getFrameTime() / T_ns + 0.5);
101  else
102  N = 1;
103 
104  const JTDC_t T_step = (JTDC_t) (getFrameTime() / N); // TDC interval
105 
106 
107  typedef vector<JDAQHit> buffer_type;
108 
109  vector<size_t> index (N); // indices of time intervals for swapping
110  vector<buffer_type> buffer(N); // data per time interval
111 
112  for (iterator frame = this->begin(); frame != this->end(); ++frame) {
113 
114  if (!frame->empty()) {
115 
116 
117  for (size_t i = 0; i != N; ++i) {
118  index [i] = i;
119  buffer[i].clear();
120  }
121 
122 
123  vector<size_t> N_max(NUMBER_OF_PMTS, N); // number of time intervals per PMT
124  vector<JTDC_t> T_max(NUMBER_OF_PMTS, 0); // maximal time per PMT, e.g. due to high-rate veto
125 
126  for (JDAQSuperFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
127  T_max[hit->getPMT()] = hit->getT();
128  }
129 
130  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
131 
132  const size_t N_i = (T_max[i] + T_step) / T_step;
133 
134  if (N_i < N_max[i]) {
135  N_max[i] = N_i;
136  }
137  }
138 
139  sort(N_max.begin(), N_max.end()); // swaps by allowed time range
140 
141  for (size_t i = 0, L = 0; i != N_max.size(); ++i) {
142 
143  size_t M = N_max[i];
144 
145  if (L != M) {
146  for (size_t i = M - L - 1; i != 0; --i) {
147  std::swap(index[L + i], index[L + gRandom->Integer(i+1)]);
148  }
149  }
150 
151  L = M;
152  }
153 
154  const size_t M = N_max[NUMBER_OF_PMTS - 1];
155 
156 
157  // Wall street shuflle
158 
159  JDAQSuperFrame::const_iterator hit = frame->begin();
160 
161  for (size_t in = 0; in != M; ++in) {
162 
163  const size_t out = index[in];
164  buffer_type& zbuf = buffer[out];
165 
166  const JTDC_t T_in = in * T_step;
167  const JTDC_t T_out = out * T_step;
168 
169  for ( ; hit != frame->end() && hit->getT() < T_in + T_step; ++hit) {
170  zbuf.push_back(JDAQHit(hit->getPMT(), (hit->getT() - T_in) + T_out, hit->getToT()));
171  }
172  }
173 
174 
175  // copy back data
176 
177  for (size_t i = 0, number_of_hits = 0; i != M; ++i) {
178 
179  memcpy(frame->data() + number_of_hits, buffer[i].data(), buffer[i].size() * sizeof(JDAQHit));
180 
181  number_of_hits += buffer[i].size();
182  }
183  }
184  }
185  }
186  };
187 }
188 
189 #endif
190 
void reset(size_t size)
Reset buffers.
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
Data structure for PMT data corresponding to a detector module.
JRandomTimeslice()
Default constructor.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
int getFrameIndex() const
Get frame index.
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const
Generate hits.
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
bool hasPMTSimulator() const
Check availability of PMT simulator.
Hit data structure.
Definition: JDAQHit.hh:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
bool hasK40Simulator() const
Check availability of K40 simulator.
bool hasCLBSimulator() const
Check availability of CLB simulator.
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition: JDAQClock.hh:263
JRandomTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad)
Constructor.
Base class class for generation of time slice data.
Definition: JTimesliceL0.hh:18
Auxiliaries for creation of time slice data.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
Timeslice with random data.
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
Data frame of one optical module.
void recycle(const double T_ns)
Recycle time slice by randomly shuffling time intervals of data.