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  */
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 status PMT status
194  * \param input PMT signals
195  * \param output PMT hits
196  */
197  virtual void processHits(const JPMTIdentifier& ID,
198  const JCalibration& calibration,
199  const JStatus& status,
200  const JPMTData<JPMTSignal>& input,
201  JPMTData<JPMTPulse>& output) const
202  {
203  getPMTSimulator().processHits(ID, calibration, status, input, output);
204  }
205 
206 
207  /**
208  * Process data.
209  *
210  * \param id module identifier
211  * \param input PMT data
212  * \param output CLB data
213  */
214  virtual void processData(const JModuleIdentifier& id, const JCLBInput& input, JDAQSuperFrame& output) const
215  {
216  getCLBSimulator().processData(id, input, output);
217  }
218 
219 
220  /**
221  * Process module data in one step.
222  *
223  * \param module module
224  * \param input PMT signals
225  * \param output CLB data
226  */
227  virtual void operator()(const JModule& module,
228  JModuleData& input,
229  JDAQSuperFrame& output) const
230  {
231  // PMT simulation
232 
233  buffer.reset(input.size());
234 
235  for (unsigned int i = 0; i != input.size(); ++i) {
236 
237  input[i].sort();
238 
239  const JPMT& pmt = module.getPMT(i);
240 
241  processHits(JPMTIdentifier(module.getID(), i),
242  pmt.getCalibration(),
243  pmt.getStatus(),
244  input [i],
245  buffer[i]);
246  }
247 
248  // CLB simulation
249 
250  processData(module, buffer, output);
251  }
252 
253 
254  protected:
258 
259  private:
260  mutable JCLBInput buffer;
261  };
262 }
263 
264 #endif
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JLANG::JSinglePointer< JCLBSimulator > clbSimulator
Exceptions.
const JStatus & getStatus() const
Get status.
Definition: JStatus.hh:80
Interface for PMT simulation.
virtual void processHits(const JPMTIdentifier &id, const JCalibration &calibration, const JStatus &status, const JPMTData< JPMTSignal > &input, JPMTData< JPMTPulse > &output) const =0
Process hits.
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:50
Data structure for PMT data corresponding to a detector module.
virtual void processHits(const JPMTIdentifier &ID, const JCalibration &calibration, const JStatus &status, const JPMTData< JPMTSignal > &input, JPMTData< JPMTPulse > &output) const
Process hits.
const JCalibration & getCalibration() const
Get calibration.
Detector data structure.
Definition: JDetector.hh:80
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:40
Data structure for PMT calibration.
virtual void operator()(const JModule &module, JModuleData &input, JDAQSuperFrame &output) const
Process module data in one step.
const JPMTSimulator & getPMTSimulator() const
Get PMT simulator.
Data structure for detector geometry and calibration.
JRange< double > JTimeRange
Type definition for time range.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
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.
virtual void processData(const JModuleIdentifier &id, const JCLBInput &input, JDAQSuperFrame &output) const
Process data.
bool hasPMTSimulator() const
Check availability of PMT simulator.
Detector file.
Definition: JHead.hh:130
void reset(JCLBSimulator *clbSimulator)
Reset CLB simulator.
JDetectorSimulator(const JDetector &detector)
Constructor.
int getID() const
Get identifier.
Definition: JObjectID.hh:55
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
JDetectorSimulator & operator=(const JDetectorSimulator &)
Make assignment operator inaccesible.
const JCLBSimulator & getCLBSimulator() const
Get CLB simulator.
Direct access to PMT in detector data structure.
bool hasK40Simulator() const
Check availability of K40 simulator.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:174
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.
Auxiliary class for object identification.
Definition: JObjectID.hh:27
Template data structure for PMT I/O.
JLANG::JSinglePointer< JPMTSimulator > pmtSimulator
void reset(size_t size)
Reset CLB buffers.
Wrapper for CLB input.
Interface for CLB simulation.
Data frame of one optical module.
virtual void processData(const JModuleIdentifier &id, const JCLBInput &input, JDAQSuperFrame &output) const =0
Process data.
const JK40Simulator & getK40Simulator() const
Get K40 simulator.
JDetectorSimulator(const JDetectorSimulator &)
Make copy constructor inaccesible.