Jpp
JCLBDefaultSimulator.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JCLBDEFAULTSIMULATOR__
2 #define __JDETECTOR__JCLBDEFAULTSIMULATOR__
3 
4 #include <cmath>
5 
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
JTOOLS::JGridCollection
General purpose class for collection of equidistant elements.
Definition: JGridCollection.hh:30
JElement.hh
JDETECTOR::JCLBDefaultSimulatorInterface::JPMT_t
JDAQHit::JPMT_t JPMT_t
Definition: JCLBDefaultSimulatorInterface.hh:45
JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine
Interface to mimic hit ordering effects due to state machine inside CLB.
Definition: JCLBDefaultSimulatorInterface.hh:83
JDETECTOR::JCLBDefaultSimulator::JTDC::JTDC
JTDC()
Default constructor.
Definition: JCLBDefaultSimulator.hh:154
JCollection.hh
KM3NETDAQ::JDAQHit::getPMT
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
JDETECTOR::JCLBDefaultSimulator
Default CLB simulation.
Definition: JCLBDefaultSimulator.hh:139
JGrid.hh
JDETECTOR::JCLBDefaultSimulator::JTDC::makeHit
virtual JDAQHit makeHit(const JPMT_t pmt, const double t_ns, const JTOT_t tot_ns) const
Make DAQ hit.
Definition: JCLBDefaultSimulator.hh:176
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::j
int j
Definition: JPolint.hh:634
JDETECTOR::JTransferFunction1D::JFunction1D_t
JTOOLS::JPolintFunction1D< 0, JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >, JTOOLS::JGridCollection, JOrdinate_t > JFunction1D_t
Definition: JCLBDefaultSimulator.hh:43
JPolint.hh
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JTransferFunction1D
Auxiliary class for a non-linear transfer function of TDC inside FPGA.
Definition: JCLBDefaultSimulator.hh:32
KM3NETDAQ::JDAQHit::getT
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JDETECTOR::JCLBDefaultSimulatorInterface::JTOT_t
JDAQHit::JTOT_t JTOT_t
Definition: JCLBDefaultSimulatorInterface.hh:47
JDETECTOR::JCLBDefaultSimulator::JStateMachine::Tmax
JDAQHit::JTDC_t Tmax
Definition: JCLBDefaultSimulator.hh:219
JDETECTOR::JCLBDefaultSimulator::JTDC::getTDC
JTransferFunction1D< double, JTDC_t > getTDC
TDC non-linearity function.
Definition: JCLBDefaultSimulator.hh:184
JDETECTOR::JCLBDefaultSimulator::JStateMachine::maybeSwapped
virtual bool maybeSwapped(const JDAQHit &first, const JDAQHit &second) const
Test whether two consecutive hits may be swapped.
Definition: JCLBDefaultSimulator.hh:213
JDETECTOR::JTransferFunction1D::JTransferFunction1D
JTransferFunction1D()
Default constructor.
Definition: JCLBDefaultSimulator.hh:49
JDETECTOR::JTransferFunction1D::operator()
JOrdinate_t operator()(const JAbscissa_t x) const
Get the function value including non-linearity.
Definition: JCLBDefaultSimulator.hh:111
JTOOLS::make_grid
JGrid< JAbscissa_t > make_grid(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax)
Helper method for JGrid.
Definition: JGrid.hh:177
KM3NETDAQ::JDAQHit::JTDC_t
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
JCLBDefaultSimulatorInterface.hh
JGridCollection.hh
JDETECTOR::JCLBDefaultSimulator::JTDC
Implementation of non-linearity of TDC.
Definition: JCLBDefaultSimulator.hh:146
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:34
JDAQHit.hh
JTOOLS::JPolintFunction1D
Template class for polynomial interpolation in 1D.
Definition: JPolint.hh:933
JDETECTOR::JCLBDefaultSimulatorInterface
Default CLB simulation.
Definition: JCLBDefaultSimulatorInterface.hh:40
JTOOLS::JElement2D
2D Element.
Definition: JElement.hh:44
JDETECTOR::JCLBDefaultSimulatorInterface::JTDC
Interface for TDC.
Definition: JCLBDefaultSimulatorInterface.hh:54
JDETECTOR::JCLBDefaultSimulator::JStateMachine::JStateMachine
JStateMachine(const JDAQHit::JTDC_t Tmax)
Constructor.
Definition: JCLBDefaultSimulator.hh:200
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12
JTOOLS::configure
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
Definition: JToolsToolkit.hh:285
JDETECTOR::JTransferFunction1D::set
void set(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax, T __begin, T __end)
Set the non-linearity function.
Definition: JCLBDefaultSimulator.hh:63
JTOOLS::JPolintFunction1D< 0, JTOOLS::JElement2D< double, JTDC_t >, JTOOLS::JGridCollection, JTDC_t >::iterator
collection_type::iterator iterator
Definition: JPolint.hh:948
JDETECTOR::JCLBDefaultSimulator::JStateMachine
Auxiliary class to mimic hit ordering effects due to state machine inside CLB.
Definition: JCLBDefaultSimulator.hh:191
JDETECTOR::JCLBDefaultSimulator::JCLBDefaultSimulator
JCLBDefaultSimulator(const JDAQHit::JTDC_t Tmax=0)
Constructor.
Definition: JCLBDefaultSimulator.hh:228