Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCLBDefaultSimulator.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JCLBDEFAULTSIMULATOR__
2 #define __JDETECTOR__JCLBDEFAULTSIMULATOR__
3 
4 #include <cmath>
5 
6 #include "JDAQ/JDAQHit.hh"
8 
9 #include "JTools/JPolint.hh"
10 #include "JTools/JElement.hh"
12 #include "JTools/JCollection.hh"
13 #include "JTools/JGrid.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JDETECTOR {}
21 namespace JPP { using namespace JDETECTOR; }
22 
23 namespace JDETECTOR {
24 
25  using KM3NETDAQ::JDAQHit;
26 
27 
28  /**
29  * Auxiliary class for a non-linear transfer function of TDC inside FPGA.
30  */
31  template<class JAbscissa_t, class JOrdinate_t>
33  public JTOOLS::JPolintFunction1D<0,
34  JTOOLS::JElement2D<JAbscissa_t, JOrdinate_t>,
35  JTOOLS::JGridCollection,
36  JOrdinate_t>
37  {
38  public:
39 
40  typedef JTOOLS::JPolintFunction1D<0,
43  JOrdinate_t> JFunction1D_t;
44 
45 
46  /**
47  * Default constructor.
48  */
50  {}
51 
52 
53  /**
54  * Set the non-linearity function.
55  *
56  * \param nx number of elements
57  * \param Xmin lower limit
58  * \param Xmax upper limit
59  * \param __begin begin of weights
60  * \param __end end of weights
61  */
62  template<class T>
63  void set(const int nx,
64  const JAbscissa_t Xmin,
65  const JAbscissa_t Xmax,
66  T __begin,
67  T __end)
68  {
69  // make CDF
70 
71  const int N = std::distance(__begin, __end);
72 
74 
75  for (T i = __begin; i != __end; ++i) {
76  X.push_back(*i);
77  }
78 
79  for (int i = 0, j = 1; j != N; ++i, ++j) {
80  X[j] += X[i];
81  }
82 
83  for (int i = 0; i != N; ++i) {
84  X[i] /= X[N-1];
85  }
86 
87 
89 
90  for (typename JFunction1D_t::iterator i = this->begin(); i != this->end(); ++i) {
91 
92  int j = 0;
93 
94  while (j != N && Xmin + X[j] * (Xmax - Xmin) < i->getX()) {
95  ++j;
96  }
97 
98  i->getY() = (JOrdinate_t) (Xmin + j * (Xmax - Xmin) / N);
99  }
100 
101  JFunction1D_t::compile();
102  }
103 
104 
105  /**
106  * Get the function value including non-linearity.
107  *
108  * \param x abscissa value
109  * \return function value
110  */
111  JOrdinate_t operator()(const JAbscissa_t x) const
112  {
113  const long long int n = (long long int) (x / (this->getXmax() - this->getXmin()));
114  const JAbscissa_t x1 = x - n * (this->getXmax() - this->getXmin());
115 
116  return (JOrdinate_t) (x - x1) + JFunction1D_t::operator()(x1);
117  }
118  };
119 
120 
121  /**
122  * Default CLB simulation.
123  *
124  * This class provides for the implementation of the conversion of a time-over-threshold pulse
125  * to a so-called hit.\n
126  * A hit consists of:
127  * - PMT readout channel;
128  * - time stamp of the leading edge of the time-over-threshold pulse;
129  * - length of the time-over-threshold pulse;
130  *
131  * The time stamping and pulse length determination is done by a TDC
132  * which is integrated inside the FPGA.
133  * The observed non-linearity of the TDC is also implemented in this class.
134  *
135  * Although the hits from the same PMT are striclty time sorted, hits from different
136  * PMTs will be reordered due to the occupancy of the buffers inside the FPGA.
137  * This reordering is implemented in the nested class JStateMachine.
138  */
141  {
142  public:
143  /**
144  * Implementation of non-linearity of TDC.
145  */
146  class JTDC :
148  {
149  public:
150  /**
151  * Default constructor.
152  * The non-linearity parameters are due to D. Calvo.
153  */
155  {
156  const double Tmin_ns = 0.0;
157  const double Tmax_ns = 4.0;
158 
159  const double W[] = { 0.2413,
160  0.2492,
161  0.2554,
162  0.2541 };
163 
164  getTDC.set(4000, Tmin_ns, Tmax_ns, W, W + sizeof(W)/sizeof(W[0]));
165  }
166 
167 
168  /**
169  * Make DAQ hit.
170  *
171  * \param pmt PMT channel
172  * \param t_ns time of hit [ns]
173  * \param tot_ns time over threshold [ns]
174  * \return DAQ hit
175  */
176  virtual JDAQHit makeHit(const JPMT_t pmt,
177  const double t_ns,
178  const JTOT_t tot_ns) const
179  {
180  return JDAQHit(pmt, getTDC(t_ns), tot_ns);
181  }
182 
183 
184  JTransferFunction1D<double, JTDC_t> getTDC; //!< TDC non-linearity function
185  };
186 
187 
188  /**
189  * Auxiliary class to mimic hit ordering effects due to state machine inside CLB.
190  */
193  {
194  public:
195  /**
196  * Constructor.
197  *
198  * \param Tmax maximal time difference for swap [ns]
199  */
201  {
202  this->Tmax = Tmax;
203  }
204 
205 
206  /**
207  * Test whether two consecutive hits may be swapped.
208  *
209  * \param first first DAQ hit
210  * \param second second DAQ hit
211  * \return true if PMTs differ and time difference less than preset value; else false
212  */
213  virtual bool maybeSwapped(const JDAQHit& first, const JDAQHit& second) const
214  {
215  return (first.getPMT() != second.getPMT() && second.getT() - first.getT() < Tmax);
216  }
217 
218 
220  };
221 
222 
223  /**
224  * Constructor.
225  *
226  * \param Tmax maximal time difference for swap [ns]
227  */
230  new JStateMachine(Tmax))
231  {}
232  };
233 }
234 
235 #endif
2D Element.
Definition: JElement.hh:44
The elements in a collection are sorted according to their abscissa values and a given distance opera...
Interface to mimic hit ordering effects due to state machine inside CLB.
JTOOLS::JPolintFunction1D< 0, JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >, JTOOLS::JGridCollection, JOrdinate_t > JFunction1D_t
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:85
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:74
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:41
Auxiliary class to mimic hit ordering effects due to state machine inside CLB.
JOrdinate_t operator()(const JAbscissa_t x) const
Get the function value including non-linearity.
JTransferFunction1D< double, JTDC_t > getTDC
TDC non-linearity function.
Hit data structure.
Definition: JDAQHit.hh:36
General purpose class for collection of equidistant elements.
General purpose class for a collection of sorted elements.
JTransferFunction1D()
Default constructor.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
virtual JDAQHit makeHit(const JPMT_t pmt, const double t_ns, const JTOT_t tot_ns) const
Make DAQ hit.
virtual bool maybeSwapped(const JDAQHit &first, const JDAQHit &second) const
Test whether two consecutive hits may be swapped.
Auxiliary class for a non-linear transfer function of TDC inside FPGA.
JCLBDefaultSimulator(const JDAQHit::JTDC_t Tmax=0)
Constructor.
void set(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax, T __begin, T __end)
Set the non-linearity function.
Implementation of non-linearity of TDC.
JStateMachine(const JDAQHit::JTDC_t Tmax)
Constructor.
JGrid< JAbscissa_t > make_grid(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax)
Helper method for JGrid.
Definition: JGrid.hh:177
Template class for polynomial interpolation in 1D.
Definition: JPolint.hh:857