Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetectorSimulator.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JDETECTORSIMULATOR__
2 #define __JDETECTOR__JDETECTORSIMULATOR__
3 
5 #include "JDetector/JDetector.hh"
10 #include "JLang/JException.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JDETECTOR {}
18 namespace JPP { using namespace JDETECTOR; }
19 
20 namespace JDETECTOR {
21 
23 
24 
25  /**
26  * Detector simulation.
27  *
28  * This class implements the JK40Simulator, JPMTSimulator and JCLBSimulator interfaces.
29  * The implementations of these interfaces should be provided via pointers to corresponding objects.
30  *
31  * N.B: This class owns the objects pointed to using class JLANG::JSinglePointer.
32  */
34  public JPMTRouter,
35  public JK40Simulator,
36  public JPMTSimulator,
37  public JCLBSimulator
38  {
39  private:
40  /**
41  * Make copy constructor inaccesible.
42  */
44 
45 
46  /**
47  * Make assignment operator inaccesible
48  */
50 
51 
52  public:
53  /**
54  * Constructor.
55  *
56  * \param detector detector
57  */
58  JDetectorSimulator(const JDetector& detector) :
59  JPMTRouter(detector)
60  {}
61 
62 
63  /**
64  * Check availability of K40 simulator.
65  *
66  * \return true if simulator available; else false
67  */
68  bool hasK40Simulator() const
69  {
70  return k40Simulator.get() != NULL;
71  }
72 
73 
74 
75  /**
76  * Check availability of PMT simulator.
77  *
78  * \return true if simulator available; else false
79  */
80  bool hasPMTSimulator() const
81  {
82  return pmtSimulator.get() != NULL;
83  }
84 
85 
86  /**
87  * Check availability of CLB simulator.
88  *
89  * \return true if simulator available; else false
90  */
91  bool hasCLBSimulator() const
92  {
93  return clbSimulator.get() != NULL;
94  }
95 
96 
97  /**
98  * Get K40 simulator.
99  *
100  * \return K40 simulator
101  */
103  {
104  if (hasK40Simulator())
105  return *k40Simulator;
106  else
107  THROW(JPointerException, "JDetectorSimulator: K40 simulator not avaliable.");
108  }
109 
110 
111  /**
112  * Get PMT simulator.
113  *
114  * \return PMT simulator
115  */
117  {
118  if (hasPMTSimulator())
119  return *pmtSimulator;
120  else
121  THROW(JPointerException, "JDetectorSimulator: PMT simulator not avaliable.");
122  }
123 
124 
125  /**
126  * Get CLB simulator.
127  *
128  * \return CLB simulator
129  */
131  {
132  if (hasCLBSimulator())
133  return *clbSimulator;
134  else
135  THROW(JPointerException, "JDetectorSimulator: CLB simulator not avaliable.");
136  }
137 
138 
139  /**
140  * Reset K40 simulator.
141  *
142  * \param k40Simulator K40 simulator
143  */
145  {
146  this->k40Simulator.reset(k40Simulator);
147  }
148 
149 
150 
151  /**
152  * Reset PMT simulator.
153  *
154  * \param pmtSimulator PMT simulator
155  */
157  {
158  this->pmtSimulator.reset(pmtSimulator);
159  }
160 
161 
162  /**
163  * Reset CLB simulator.
164  *
165  * \param clbSimulator CLB simulator
166  */
168  {
169  this->clbSimulator.reset(clbSimulator);
170  }
171 
172 
173  /**
174  * Generate hits.
175  *
176  * \param module module
177  * \param period time window [ns]
178  * \param output background data
179  */
180  virtual void generateHits(const JModule& module,
181  const JTimeRange& period,
182  JModuleData& output) const
183  {
184  getK40Simulator().generateHits(module, period, output);
185  }
186 
187 
188  /**
189  * Process hits.
190  *
191  * \param ID PMT identifier
192  * \param calibration PMT calibration
193  * \param input PMT signals
194  * \param output PMT hits
195  */
196  virtual void processHits(const JPMTIdentifier& ID,
197  const JCalibration& calibration,
198  const JPMTData<JPMTSignal>& input,
199  JPMTData<JPMTPulse>& output) const
200  {
201  getPMTSimulator().processHits(ID, calibration, input, output);
202  }
203 
204 
205  /**
206  * Process data.
207  *
208  * \param input PMT data
209  * \param output CLB data
210  */
211  virtual void processData(const JCLBInput& input,
212  JDAQFrame& output) const
213  {
214  getCLBSimulator().processData(input, output);
215  }
216 
217 
218  /**
219  * Process module data in one step.
220  *
221  * \param module module
222  * \param input PMT signals
223  * \param output CLB data
224  */
225  virtual void operator()(const JModule& module,
226  JModuleData& input,
227  JDAQFrame& output) const
228  {
229  // PMT simulation
230 
231  JDETECTOR::reset(buffer, input.size());
232 
233  for (unsigned int pmt = 0; pmt != input.size(); ++pmt) {
234 
235  input[pmt].sort();
236 
237  processHits(JPMTIdentifier(module.getID(), pmt), module.getPMT(pmt), input[pmt], buffer[pmt]);
238  }
239 
240  // CLB simulation
241 
242  processData(buffer, output);
243  }
244 
245 
246  protected:
250 
251  private:
252  mutable JCLBInput buffer;
253  };
254 }
255 
256 #endif
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
virtual void processHits(const JPMTIdentifier &id, const JCalibration &calibration, const JPMTData< JPMTSignal > &input, JPMTData< JPMTPulse > &output) const =0
Process hits.
JLANG::JSinglePointer< JCLBSimulator > clbSimulator
Exceptions.
Interface for PMT simulation.
Exception for accessing an invalid pointer.
Definition: JException.hh:108
Interface for simulation of K40 background.
Data structure for a composite optical module.
Definition: JModule.hh:47
Data structure for PMT data corresponding to a detector module.
Detector data structure.
Definition: JDetector.hh:77
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
Data structure for PMT calibration.
const JPMTSimulator & getPMTSimulator() const
Get PMT simulator.
Data structure for detector geometry and calibration.
JRange< double > JTimeRange
Type definition for time range.
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const
Generate hits.
JLANG::JSinglePointer< JK40Simulator > k40Simulator
The template JSinglePointer class can be used to hold a pointer to an object.
void reset(JPMTSimulator *pmtSimulator)
Reset PMT simulator.
bool hasPMTSimulator() const
Check availability of PMT simulator.
void reset(JCLBSimulator *clbSimulator)
Reset CLB simulator.
virtual void processData(const JCLBInput &input, JDAQFrame &output) const
Process data.
JDetectorSimulator(const JDetector &detector)
Constructor.
int getID() const
Get identifier.
Definition: JObjectID.hh:54
Data frame.
Definition: JDAQFrame.hh:70
JDetectorSimulator & operator=(const JDetectorSimulator &)
Make assignment operator inaccesible.
const JCLBSimulator & getCLBSimulator() const
Get CLB simulator.
Direct access to PMT in detector data structure.
virtual void operator()(const JModule &module, JModuleData &input, JDAQFrame &output) const
Process module data in one step.
bool hasK40Simulator() const
Check availability of K40 simulator.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:141
bool hasCLBSimulator() const
Check availability of CLB simulator.
void reset(JK40Simulator *k40Simulator)
Reset K40 simulator.
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const =0
Generate hits.
Template data structure for PMT I/O.
virtual void processHits(const JPMTIdentifier &ID, const JCalibration &calibration, const JPMTData< JPMTSignal > &input, JPMTData< JPMTPulse > &output) const
Process hits.
JLANG::JSinglePointer< JPMTSimulator > pmtSimulator
Interface for CLB simulation.
virtual void processData(const JCLBInput &input, JDAQFrame &output) const =0
Process data.
const JK40Simulator & getK40Simulator() const
Get K40 simulator.
JDetectorSimulator(const JDetectorSimulator &)
Make copy constructor inaccesible.