Jpp
JCLBDefaultSimulatorInterface.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JCLBDEFAULTSIMULATORINTERFACE__
2 #define __JDETECTOR__JCLBDEFAULTSIMULATORINTERFACE__
3 
4 #include <vector>
5 #include <algorithm>
6 
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JDETECTOR {}
17 namespace JPP { using namespace JDETECTOR; }
18 
19 namespace JDETECTOR {
20 
21  using KM3NETDAQ::JDAQHit;
23  using KM3NETDAQ::getRTS;
24 
25 
26  /**
27  * Default CLB simulation.
28  *
29  * This class provides for a default implementation of the JCLBSimulator interface
30  * which is based on a simulation of the TDC and the state machine inside the CLB.
31  * In this, the number of hits may actually change due to the dynamic range of
32  * the TDC (loss of hits) and the dynamic range of the time-over-threshold (gain
33  * of hits).
34  * The nested class JStateMachine constitutes a user interface for the simulation
35  * of the state machine through method JStateMachine::maybeSwapped().
36  * With the default implementation, the overall time ordering if hits is maintained.
37  * For a realistic simulation of the CLB, a pointer to an implementation of this
38  * interface should be provided.
39  */
41  public JCLBSimulator
42  {
43  protected:
44 
48 
49 
50  public:
51  /**
52  * Interface for TDC.
53  */
54  class JTDC {
55  public:
56  /**
57  * Virtual destructor.
58  */
59  virtual ~JTDC()
60  {}
61 
62 
63  /**
64  * Make DAQ hit.
65  *
66  * \param pmt PMT channel
67  * \param t_ns time of hit [ns]
68  * \param tot_ns time over threshold [ns]
69  * \return DAQ hit
70  */
71  virtual JDAQHit makeHit(const JPMT_t pmt,
72  const double t_ns,
73  const JTOT_t tot_ns) const
74  {
75  return JDAQHit(pmt, (JTDC_t) t_ns, tot_ns);
76  }
77  };
78 
79 
80  /**
81  * Interface to mimic hit ordering effects due to state machine inside CLB.
82  */
83  class JStateMachine {
84  public:
85  /**
86  * Virtual destructor.
87  */
88  virtual ~JStateMachine()
89  {}
90 
91 
92  /**
93  * Test whether two consecutive hits may be swapped.
94  *
95  * \param first first DAQ hit
96  * \param second second DAQ hit
97  * \return true if first and second hit may be swapped; else false
98  */
99  virtual bool maybeSwapped(const JDAQHit& first, const JDAQHit& second) const
100  {
101  return false;
102  }
103  };
104 
105 
106  /**
107  * Constructor.
108  * N.B: This class owns the object pointed to using JSinglePointer<>.
109  *
110  * \param __TDC pointer TDC simulator
111  * \param __state_machine pointer state machine
112  */
114  JCLBSimulator(),
115  TDC (__TDC),
116  state_machine(__state_machine)
117  {}
118 
119 
120  /**
121  * Process data.
122  *
123  * \param input PMT data
124  * \param output CLB data
125  */
126  virtual void processData(const JCLBInput& input,
127  JDAQFrame& output) const
128  {
129  using namespace std;
130 
131 
132  const JTDC_t TMIN = 0; // [ns]
133  const JTDC_t TMAX = (JTDC_t) getRTS(); // [ns]
134 
135  buffer.clear();
136 
137 
138  for (JPMT_t pmt = 0; pmt != (JPMT_t) input.size(); ++pmt) {
139 
140 
141  const JPMTData<JPMTPulse>& in = input[pmt];
142 
143 
144  // TDC
145 
146  JPMTData<JPMTPulse>::const_iterator hit = in.begin();
147 
148  for ( ; hit != in.end() && hit->t_ns < TMIN; ++hit) {}
149 
150  for ( ; hit != in.end() && hit->t_ns < TMAX; ++hit) {
151 
152  double t1 = hit->t_ns;
153  double tot = hit->tot_ns;
154 
155  // generate multiple hits if time-over-threshold exceeds dynamic range
156 
157  while (tot > JDAQHit::getMaximalToT()) {
158 
159  buffer.push_back(TDC->makeHit(pmt, t1, JDAQHit::getMaximalToT()));
160 
161  t1 += JDAQHit::getMaximalToT();
162  tot -= JDAQHit::getMaximalToT();
163  }
164 
165  if (tot > getMinimalToT()) {
166  buffer.push_back(TDC->makeHit(pmt, t1, (JTOT_t) (tot + 0.5)));
167  }
168  }
169  }
170 
171 
172  if (buffer.size() > 1) {
173 
174  // process data through state machine
175 
176  sort(buffer.begin(), buffer.end());
177 
178  for (std::vector<JDAQHit>::iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
179 
180  if (state_machine->maybeSwapped(*p,*q)) {
181  iter_swap(p,q);
182  }
183  }
184  }
185 
186 
187  output.add(buffer.size(), buffer.data());
188  }
189 
190 
191  /**
192  * Get maximal pulse length of time-over-threshold measurement.
193  *
194  * \return TDC value [ns]
195  */
197  {
198  return 0xFE;
199  }
200 
201 
202  /**
203  * Get minimal pulse length of time-over-threshold measurement.
204  *
205  * \return TDC value [ns]
206  */
207  static double getMinimalToT()
208  {
209  return 0.5;
210  }
211 
212  private:
216  };
217 }
218 
219 #endif
JDETECTOR::JCLBDefaultSimulatorInterface::JTDC::makeHit
virtual JDAQHit makeHit(const JPMT_t pmt, const double t_ns, const JTOT_t tot_ns) const
Make DAQ hit.
Definition: JCLBDefaultSimulatorInterface.hh:71
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
JLANG::JSinglePointer
The template JSinglePointer class can be used to hold a pointer to an object.
Definition: JSinglePointer.hh:24
KM3NETDAQ::JDAQFrame
Data frame.
Definition: JDAQFrame.hh:64
JCLBSimulator.hh
JDETECTOR::JCLBDefaultSimulatorInterface::getMinimalToT
static double getMinimalToT()
Get minimal pulse length of time-over-threshold measurement.
Definition: JCLBDefaultSimulatorInterface.hh:207
KM3NETDAQ::getRTS
double getRTS()
Get TDC dynamic range.
Definition: JDAQClock.hh:173
JDETECTOR::JCLBDefaultSimulatorInterface::JTDC::~JTDC
virtual ~JTDC()
Virtual destructor.
Definition: JCLBDefaultSimulatorInterface.hh:59
KM3NETDAQ::JDAQFrame::add
JDAQFrame & add(const JDAQFrame &frame)
Add data.
Definition: JDAQFrame.hh:190
JSinglePointer.hh
std::vector< JPMTOutput >
JDETECTOR::JCLBDefaultSimulatorInterface::JTDC_t
JDAQHit::JTDC_t JTDC_t
Definition: JCLBDefaultSimulatorInterface.hh:46
JDETECTOR::JCLBDefaultSimulatorInterface::processData
virtual void processData(const JCLBInput &input, JDAQFrame &output) const
Process data.
Definition: JCLBDefaultSimulatorInterface.hh:126
JDAQClock.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JPMTData::const_iterator
std::vector< JElement_t >::const_iterator const_iterator
Definition: JPMTSimulator.hh:171
JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine::~JStateMachine
virtual ~JStateMachine()
Virtual destructor.
Definition: JCLBDefaultSimulatorInterface.hh:88
JDETECTOR::JCLBDefaultSimulatorInterface::JTOT_t
JDAQHit::JTOT_t JTOT_t
Definition: JCLBDefaultSimulatorInterface.hh:47
KM3NETDAQ::JDAQHit::JPMT_t
unsigned char JPMT_t
PMT channel in FPGA.
Definition: JDAQHit.hh:38
JDETECTOR::JCLBDefaultSimulatorInterface::getMaximalToT
static JTOT_t getMaximalToT()
Get maximal pulse length of time-over-threshold measurement.
Definition: JCLBDefaultSimulatorInterface.hh:196
JDETECTOR::JCLBDefaultSimulatorInterface::buffer
std::vector< JDAQHit > buffer
Definition: JCLBDefaultSimulatorInterface.hh:215
JDETECTOR::JCLBSimulator
Interface for CLB simulation.
Definition: JCLBSimulator.hh:56
KM3NETDAQ::JDAQHit::getMaximalToT
static JTOT_t getMaximalToT()
Get maximal time-over-threshold.
Definition: JDAQHit.hh:108
JDETECTOR::JCLBDefaultSimulatorInterface::JCLBDefaultSimulatorInterface
JCLBDefaultSimulatorInterface(JTDC *__TDC, JStateMachine *__state_machine)
Constructor.
Definition: JCLBDefaultSimulatorInterface.hh:113
JDETECTOR::JCLBDefaultSimulatorInterface::TDC
JLANG::JSinglePointer< JTDC > TDC
Definition: JCLBDefaultSimulatorInterface.hh:213
JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine::maybeSwapped
virtual bool maybeSwapped(const JDAQHit &first, const JDAQHit &second) const
Test whether two consecutive hits may be swapped.
Definition: JCLBDefaultSimulatorInterface.hh:99
KM3NETDAQ::JDAQHit::JTDC_t
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
JDETECTOR::JPMTData
Template data structure for PMT I/O.
Definition: JPMTSimulator.hh:165
JDETECTOR::JCLBDefaultSimulatorInterface::state_machine
JLANG::JSinglePointer< JStateMachine > state_machine
Definition: JCLBDefaultSimulatorInterface.hh:214
std
Definition: jaanetDictionary.h:36
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:34
JDETECTOR::JCLBDefaultSimulatorInterface
Default CLB simulation.
Definition: JCLBDefaultSimulatorInterface.hh:40
KM3NETDAQ::JDAQHit::JTOT_t
unsigned char JTOT_t
time over threshold [ns]
Definition: JDAQHit.hh:40
JDETECTOR::JCLBDefaultSimulatorInterface::JTDC
Interface for TDC.
Definition: JCLBDefaultSimulatorInterface.hh:54
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12