Jpp  18.5.0
the software that should make you happy
 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 
7 
8 #include "JTools/JPolint.hh"
9 #include "JTools/JElement.hh"
11 #include "JTools/JCollection.hh"
12 #include "JTools/JGrid.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JDETECTOR {}
20 namespace JPP { using namespace JDETECTOR; }
21 
22 namespace JDETECTOR {
23 
24  /**
25  * Auxiliary class for a non-linear transfer function of TDC inside FPGA.
26  */
27  template<class JAbscissa_t, class JOrdinate_t>
29  public JTOOLS::JPolintFunction1D<0,
30  JTOOLS::JElement2D<JAbscissa_t, JOrdinate_t>,
31  JTOOLS::JGridCollection,
32  JOrdinate_t>
33  {
34  public:
35 
36  typedef JTOOLS::JPolintFunction1D<0,
39  JOrdinate_t> JFunction1D_t;
40 
41 
42  /**
43  * Default constructor.
44  */
46  {}
47 
48 
49  /**
50  * Set the non-linearity function.
51  *
52  * \param nx number of elements
53  * \param Xmin lower limit
54  * \param Xmax upper limit
55  * \param __begin begin of weights
56  * \param __end end of weights
57  */
58  template<class T>
59  void set(const int nx,
60  const JAbscissa_t Xmin,
61  const JAbscissa_t Xmax,
62  T __begin,
63  T __end)
64  {
65  // make CDF
66 
67  const int N = std::distance(__begin, __end);
68 
70 
71  for (T i = __begin; i != __end; ++i) {
72  X.push_back(*i);
73  }
74 
75  for (int i = 0, j = 1; j != N; ++i, ++j) {
76  X[j] += X[i];
77  }
78 
79  for (int i = 0; i != N; ++i) {
80  X[i] /= X[N-1];
81  }
82 
83 
85 
86  for (typename JFunction1D_t::iterator i = this->begin(); i != this->end(); ++i) {
87 
88  int j = 0;
89 
90  while (j != N && Xmin + X[j] * (Xmax - Xmin) < i->getX()) {
91  ++j;
92  }
93 
94  i->getY() = (JOrdinate_t) (Xmin + j * (Xmax - Xmin) / N);
95  }
96 
97  JFunction1D_t::compile();
98  }
99 
100 
101  /**
102  * Get the function value including non-linearity.
103  *
104  * \param x abscissa value
105  * \return function value
106  */
107  JOrdinate_t operator()(const JAbscissa_t x) const
108  {
109  const long long int n = (long long int) (x / (this->getXmax() - this->getXmin()));
110  const JAbscissa_t x1 = x - n * (this->getXmax() - this->getXmin());
111 
112  return (JOrdinate_t) (x - x1) + JFunction1D_t::operator()(x1);
113  }
114  };
115 
116 
117  /**
118  * Default CLB simulation.
119  *
120  * This class provides for the implementation of the conversion of a time-over-threshold pulse to a hit.\n
121  * A hit consists of:
122  * - PMT readout channel;
123  * - time stamp of the leading edge of the time-over-threshold pulse;
124  * - length of the time-over-threshold pulse;
125  *
126  * The time stamping and pulse length determination is done by a TDC
127  * which is integrated inside the FPGA.
128  * The observed non-linearity of the TDC is implemented in this class.
129  *
130  * Although the hits from the same PMT are striclty time sorted,
131  * hits from different PMTs could be reordered due to the occupancy of the buffers inside the FPGA.
132  * This reordering is also implemented in the this class.
133  */
136  {
137  public:
138  /**
139  * Implementation of non-linearity of TDC.
140  */
141  class JTDC :
143  {
144  public:
145  /**
146  * Default constructor.
147  * The non-linearity parameters are due to D. Calvo.
148  */
150  {
151  const double Tmin_ns = 0.0;
152  const double Tmax_ns = 4.0;
153 
154  const double W[] = { 0.2413,
155  0.2492,
156  0.2554,
157  0.2541 };
158 
159  getTDC.set(4000, Tmin_ns, Tmax_ns, W, W + sizeof(W)/sizeof(W[0]));
160  }
161 
162 
163  /**
164  * Make DAQ hit.
165  *
166  * \param pmt PMT channel
167  * \param t_ns time of hit [ns]
168  * \param tot_ns time over threshold [ns]
169  * \return DAQ hit
170  */
171  virtual JDAQHit makeHit(const JPMT_t pmt,
172  const double t_ns,
173  const JTOT_t tot_ns) const override
174  {
175  return JDAQHit(pmt, getTDC(t_ns), tot_ns);
176  }
177 
178 
179  JTransferFunction1D<double, JTDC_t> getTDC; //!< TDC non-linearity function
180  };
181 
182 
183  /**
184  * Auxiliary class to mimic hit ordering effects due to state machine inside CLB.
185  */
188  {
189  public:
190  /**
191  * Constructor.
192  *
193  * \param Tmax maximal time difference for swap [ns]
194  */
196  {
197  this->Tmax = Tmax;
198  }
199 
200 
201  /**
202  * Test whether two consecutive hits may be swapped.
203  *
204  * \param first first DAQ hit
205  * \param second second DAQ hit
206  * \return true if PMTs differ and time difference less than preset value; else false
207  */
208  virtual bool maybeSwapped(const JDAQHit& first, const JDAQHit& second) const override
209  {
210  return (first.getPMT() != second.getPMT() && second.getT() - first.getT() < Tmax);
211  }
212 
213 
215  };
216 
217 
218  /**
219  * Constructor.
220  *
221  * \param Tmax maximal time difference for swap [ns]
222  */
225  new JStateMachine(Tmax))
226  {}
227  };
228 }
229 
230 #endif
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.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JTOOLS::JPolintFunction1D< 0, JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >, JTOOLS::JGridCollection, JOrdinate_t > JFunction1D_t
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
Auxiliary class to mimic hit ordering effects due to state machine inside CLB.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JOrdinate_t operator()(const JAbscissa_t x) const
Get the function value including non-linearity.
const int n
Definition: JPolint.hh:786
JTransferFunction1D< double, JTDC_t > getTDC
TDC non-linearity function.
Hit data structure.
Definition: JDAQHit.hh:34
General purpose class for collection of equidistant elements.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
General purpose class for a collection of sorted elements.
JTransferFunction1D()
Default constructor.
virtual bool maybeSwapped(const JDAQHit &first, const JDAQHit &second) const override
Test whether two consecutive hits may be swapped.
virtual JDAQHit makeHit(const JPMT_t pmt, const double t_ns, const JTOT_t tot_ns) const override
Make DAQ hit.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
Auxiliary class for a non-linear transfer function of TDC inside FPGA.
JCLBDefaultSimulator(const JDAQHit::JTDC_t Tmax=0)
Constructor.
2D Element.
Definition: JElement.hh:46
no fit printf nominal n $STRING awk v X
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.
int j
Definition: JPolint.hh:792
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:209
Template class for polynomial interpolation in 1D.
Definition: JPolint.hh:1092