Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JModule.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JMODULE__
2 #define __JDETECTOR__JMODULE__
3 
4 #include <istream>
5 #include <ostream>
6 #include <vector>
7 
10 #include "JDetector/JPMT.hh"
14 #include "JIO/JSerialisable.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Data structure for a composite optical module.
21  * \author mdejong
22  */
23 namespace JDETECTOR {}
24 namespace JPP { using namespace JDETECTOR; }
25 
26 namespace JDETECTOR {
27 
34  using JIO::JReader;
35  using JIO::JWriter;
36 
37 
38  /**
39  * Data structure for a composite optical module.
40  *
41  * A module consists of a set of JPMT objects.
42  * The index of the PMT object in the module container corresponds to the readout channel (TDC).
43  * The positions of the PMTs are absolute in space (i.e. not relative to the position of the module).
44  * The position of the module is not subject to I/O but derived from the positions of the PMTs
45  * using method compile().
46  */
47  class JModule :
48  public JModuleIdentifier,
49  public JModuleLocation,
50  public JPosition3D,
51  public std::vector<JPMT>
52  {
53  public:
54  /**
55  * Default constructor.
56  */
57  JModule() :
60  JPosition3D(),
61  std::vector<JPMT>()
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param id identifier
69  * \param location location
70  */
71  JModule(const int id,
72  const JModuleLocation& location) :
74  JModuleLocation(location),
75  JPosition3D(),
76  std::vector<JPMT>()
77  {}
78 
79 
80  /**
81  * Get reference to unique instance of this class object.
82  *
83  * This method returns a module with the standard configuration of PMTs.
84  *
85  * \return reference to this class object
86  */
87  static const JModule& getInstance()
88  {
89  static JModule module;
90 
91  if (module.empty()) {
92 
93  module.push_back(JPMT( 1, JAxis3D(JVector3D(+0.000, +0.000, -0.200), JVersor3D(+0.000, +0.000, -1.000))));
94 
95  module.push_back(JPMT( 2, JAxis3D(JVector3D(+0.000, +0.105, -0.170), JVersor3D(+0.000, +0.527, -0.850))));
96  module.push_back(JPMT( 3, JAxis3D(JVector3D(+0.091, +0.053, -0.170), JVersor3D(+0.456, +0.263, -0.850))));
97  module.push_back(JPMT( 4, JAxis3D(JVector3D(+0.091, -0.053, -0.170), JVersor3D(+0.456, -0.263, -0.850))));
98  module.push_back(JPMT( 5, JAxis3D(JVector3D(+0.000, -0.105, -0.170), JVersor3D(+0.000, -0.527, -0.850))));
99  module.push_back(JPMT( 6, JAxis3D(JVector3D(-0.091, -0.053, -0.170), JVersor3D(-0.456, -0.263, -0.850))));
100  module.push_back(JPMT( 7, JAxis3D(JVector3D(-0.091, +0.053, -0.170), JVersor3D(-0.456, +0.263, -0.850))));
101 
102  module.push_back(JPMT( 8, JAxis3D(JVector3D(+0.083, +0.144, -0.111), JVersor3D(+0.416, +0.720, -0.555))));
103  module.push_back(JPMT( 9, JAxis3D(JVector3D(+0.166, +0.000, -0.111), JVersor3D(+0.832, +0.000, -0.555))));
104  module.push_back(JPMT(10, JAxis3D(JVector3D(+0.083, -0.144, -0.111), JVersor3D(+0.416, -0.720, -0.555))));
105  module.push_back(JPMT(11, JAxis3D(JVector3D(-0.083, -0.144, -0.111), JVersor3D(-0.416, -0.720, -0.555))));
106  module.push_back(JPMT(12, JAxis3D(JVector3D(-0.166, +0.000, -0.111), JVersor3D(-0.832, +0.000, -0.555))));
107  module.push_back(JPMT(13, JAxis3D(JVector3D(-0.083, +0.144, -0.111), JVersor3D(-0.416, +0.720, -0.555))));
108 
109  module.push_back(JPMT(14, JAxis3D(JVector3D(+0.000, +0.191, -0.059), JVersor3D(+0.000, +0.955, -0.295))));
110  module.push_back(JPMT(15, JAxis3D(JVector3D(+0.165, +0.096, -0.059), JVersor3D(+0.827, +0.478, -0.295))));
111  module.push_back(JPMT(16, JAxis3D(JVector3D(+0.165, -0.096, -0.059), JVersor3D(+0.827, -0.478, -0.295))));
112  module.push_back(JPMT(17, JAxis3D(JVector3D(+0.000, -0.191, -0.059), JVersor3D(+0.000, -0.955, -0.295))));
113  module.push_back(JPMT(18, JAxis3D(JVector3D(-0.165, -0.096, -0.059), JVersor3D(-0.827, -0.478, -0.295))));
114  module.push_back(JPMT(19, JAxis3D(JVector3D(-0.165, +0.096, -0.059), JVersor3D(-0.827, +0.478, -0.295))));
115 
116  module.push_back(JPMT(20, JAxis3D(JVector3D(+0.096, +0.165, +0.059), JVersor3D(+0.478, +0.827, +0.295))));
117  module.push_back(JPMT(21, JAxis3D(JVector3D(+0.191, +0.000, +0.059), JVersor3D(+0.955, +0.000, +0.295))));
118  module.push_back(JPMT(22, JAxis3D(JVector3D(+0.096, -0.165, +0.059), JVersor3D(+0.478, -0.827, +0.295))));
119  module.push_back(JPMT(23, JAxis3D(JVector3D(-0.096, -0.165, +0.059), JVersor3D(-0.478, -0.827, +0.295))));
120  module.push_back(JPMT(24, JAxis3D(JVector3D(-0.191, +0.000, +0.059), JVersor3D(-0.955, +0.000, +0.295))));
121  module.push_back(JPMT(25, JAxis3D(JVector3D(-0.096, +0.165, +0.059), JVersor3D(-0.478, +0.827, +0.295))));
122 
123  module.push_back(JPMT(26, JAxis3D(JVector3D(+0.000, +0.166, +0.111), JVersor3D(+0.000, +0.832, +0.555))));
124  module.push_back(JPMT(27, JAxis3D(JVector3D(+0.144, +0.083, +0.111), JVersor3D(+0.720, +0.416, +0.555))));
125  module.push_back(JPMT(28, JAxis3D(JVector3D(+0.144, -0.083, +0.111), JVersor3D(+0.720, -0.416, +0.555))));
126  module.push_back(JPMT(29, JAxis3D(JVector3D(+0.000, -0.166, +0.111), JVersor3D(+0.000, -0.832, +0.555))));
127  module.push_back(JPMT(30, JAxis3D(JVector3D(-0.144, -0.083, +0.111), JVersor3D(-0.720, -0.416, +0.555))));
128  module.push_back(JPMT(31, JAxis3D(JVector3D(-0.144, +0.083, +0.111), JVersor3D(-0.720, +0.416, +0.555))));
129  }
130 
131  return module;
132  }
133 
134 
135  /**
136  * Get PMT.
137  *
138  * \param index readout channel (TDC)
139  * \return PMT at given index
140  */
141  const JPMT& getPMT(const int index) const
142  {
143  return at(index);
144  }
145 
146 
147  /**
148  * Get PMT.
149  *
150  * \param index readout channel (TDC)
151  * \return PMT at given index
152  */
153  JPMT& getPMT(const int index)
154  {
155  return at(index);
156  }
157 
158 
159  /**
160  * Compile position of module from the positions of the PMTs.
161  */
162  void compile()
163  {
164  if (!empty()) {
165 
166  JPosition3D pos;
167 
168  for (iterator i = begin(); i != end(); ++i) {
169  pos.add(i->getPosition());
170  }
171 
172  static_cast<JPosition3D&>(*this) = pos.div(size());
173  }
174  }
175 
176 
177  /**
178  * Rotate module.
179  *
180  * \param R rotation matrix
181  */
182  void rotate(const JRotation3D& R)
183  {
184  static_cast<JPosition3D&>(*this).rotate(R);
185 
186  for (iterator i = this->begin(); i != this->end(); ++i) {
187  i->rotate(R);
188  }
189  }
190 
191 
192  /**
193  * Rotate back module.
194  *
195  * \param R rotation matrix
196  */
197  void rotate_back(const JRotation3D& R)
198  {
199  static_cast<JPosition3D&>(*this).rotate_back(R);
200 
201  for (iterator i = this->begin(); i != this->end(); ++i) {
202  i->rotate_back(R);
203  }
204  }
205 
206 
207  /**
208  * Transformation of geometry (see method JGEOMETRY3D::JPosition3D::transform(const JRotation3D&, const JVector3D&)).
209  *
210  * \param R rotation matrix
211  * \param pos position of origin (after rotation)
212  */
213  void transform(const JRotation3D& R,
214  const JVector3D& pos)
215  {
216  static_cast<JPosition3D&>(*this).transform(R, pos);
217 
218  for (iterator i = this->begin(); i != this->end(); ++i) {
219  i->transform(R, pos);
220  }
221  }
222 
223 
224  /**
225  * Transformation of geometry.
226  *
227  * \param T transformation
228  */
230  {
231  static_cast<JPosition3D&>(*this).transform(T.getRotation(), T.getPosition());
232 
233  for (iterator i = this->begin(); i != this->end(); ++i) {
234  i->transform(T);
235  }
236  }
237 
238 
239  /**
240  * Set position.
241  *
242  * \param pos position
243  * \return this module
244  */
245  JModule& set(const JVector3D& pos)
246  {
247  return add(pos - static_cast<JPosition3D&>(*this));
248  }
249 
250 
251  /**
252  * Add position.
253  *
254  * \param pos position
255  * \return this module
256  */
257  JModule& add(const JVector3D& pos)
258  {
259  for (iterator i = begin(); i != end(); ++i) {
260  i->add(pos);
261  }
262 
263  JVector3D::add(pos);
264 
265  return *this;
266  }
267 
268 
269  /**
270  * Subtract position.
271  *
272  * \param pos position
273  * \return this module
274  */
275  JModule& sub(const JVector3D& pos)
276  {
277  for (iterator i = begin(); i != end(); ++i) {
278  i->sub(pos);
279  }
280 
281  JVector3D::sub(pos);
282 
283  return *this;
284  }
285 
286 
287  /**
288  * Set time offset.
289  *
290  * \param t0 time offset [ns]
291  * \return this module
292  */
293  JModule& set(const double t0)
294  {
295  for (iterator i = begin(); i != end(); ++i) {
296  i->setT0(t0);
297  }
298 
299  return *this;
300  }
301 
302 
303  /**
304  * Add time offset.
305  *
306  * \param t0 time offset [ns]
307  * \return this module
308  */
309  JModule& add(const double t0)
310  {
311  for (iterator i = begin(); i != end(); ++i) {
312  i->addT0(t0);
313  }
314 
315  return *this;
316  }
317 
318 
319  /**
320  * Subtract time offset.
321  *
322  * \param t0 time offset [ns]
323  * \return this module
324  */
325  JModule& sub(const double t0)
326  {
327  for (iterator i = begin(); i != end(); ++i) {
328  i->subT0(t0);
329  }
330 
331  return *this;
332  }
333 
334 
335  /**
336  * Add position.
337  *
338  * \param pos position
339  * \return this module
340  */
342  {
343  return this->add(pos);
344  }
345 
346 
347  /**
348  * Subtract position.
349  *
350  * \param pos position
351  * \return this module
352  */
354  {
355  return this->sub(pos);
356  }
357 
358 
359  /**
360  * Read module from input.
361  *
362  * \param in input stream
363  * \param module module
364  * \return input stream
365  */
366  friend inline std::istream& operator>>(std::istream& in, JModule& module)
367  {
368  module.clear();
369 
370  in >> static_cast<JModuleIdentifier&>(module);
371  in >> static_cast<JModuleLocation&> (module);
372 
373  unsigned int n;
374 
375  in >> n;
376 
377  for (JPMT pmt; n != 0 && in >> pmt; --n) {
378  module.push_back(pmt);
379  }
380 
381  module.compile();
382 
383  return in;
384  }
385 
386 
387  /**
388  * Write module to output.
389  *
390  * \param out output stream
391  * \param module module
392  * \return output stream
393  */
394  friend inline std::ostream& operator<<(std::ostream& out, const JModule& module)
395  {
396  using namespace std;
397 
398  out << static_cast<const JModuleIdentifier&>(module);
399  out << ' ';
400  out << static_cast<const JModuleLocation&> (module);
401 
402  out << ' ' << module.size() << endl;
403 
404  for (const_iterator i = module.begin(); i != module.end(); ++i) {
405  out << ' ' << *i << endl;;
406  }
407 
408  return out;
409  }
410 
411 
412  /**
413  * Read module from input.
414  *
415  * \param in reader
416  * \param module module
417  * \return rrreader
418  */
419  friend inline JReader& operator>>(JReader& in, JModule& module)
420  {
421  module.clear();
422 
423  in >> static_cast<JModuleIdentifier&>(module);
424  in >> static_cast<JModuleLocation&> (module);
425 
426  int n;
427 
428  in >> n;
429 
430  for (JPMT pmt; n != 0; --n) {
431 
432  in >> pmt;
433 
434  module.push_back(pmt);
435  }
436 
437  module.compile();
438 
439  return in;
440  }
441 
442 
443  /**
444  * Write module to output.
445  *
446  * \param out writer
447  * \param module module
448  * \return writer
449  */
450  friend inline JWriter& operator<<(JWriter& out, const JModule& module)
451  {
452  out << static_cast<const JModuleIdentifier&>(module);
453  out << static_cast<const JModuleLocation&> (module);
454 
455  int n = module.size();
456 
457  out << n;
458 
459  for (const_iterator i = module.begin(); i != module.end(); ++i) {
460  out << *i;
461  }
462 
463  return out;
464  }
465  };
466 }
467 
468 #endif
friend JReader & operator>>(JReader &in, JModule &module)
Read module from input.
Definition: JModule.hh:419
Interface for binary output.
Data structure for a composite optical module.
Definition: JModule.hh:47
Logical location of module.
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Definition: JPosition3D.hh:199
JModule & operator-=(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:353
JModule & add(const double t0)
Add time offset.
Definition: JModule.hh:309
Rotation matrix.
Definition: JRotation3D.hh:108
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
Definition: JPosition3D.hh:321
friend JWriter & operator<<(JWriter &out, const JModule &module)
Write module to output.
Definition: JModule.hh:450
JModule()
Default constructor.
Definition: JModule.hh:57
Axis object.
Definition: JAxis3D.hh:37
JModule & sub(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:275
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:156
void transform(const JTransformation3D &T)
Transformation of geometry.
Definition: JModule.hh:229
Data structure for vector in three dimensions.
Definition: JVector3D.hh:32
JModule & sub(const double t0)
Subtract time offset.
Definition: JModule.hh:325
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:52
void compile()
Compile position of module from the positions of the PMTs.
Definition: JModule.hh:162
void rotate_back(const JRotation3D &R)
Rotate back module.
Definition: JModule.hh:197
Interface for binary input.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
static const JModule & getInstance()
Get reference to unique instance of this class object.
Definition: JModule.hh:87
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:141
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:182
JModule & operator+=(const JVector3D &pos)
Add position.
Definition: JModule.hh:341
const JRotation3D & getRotation() const
Get rotation.
Definition: JRotation3D.hh:237
friend std::ostream & operator<<(std::ostream &out, const JModule &module)
Write module to output.
Definition: JModule.hh:394
friend std::istream & operator>>(std::istream &in, JModule &module)
Read module from input.
Definition: JModule.hh:366
Data structure for PMT geometry and calibration.
Auxiliary class for object identification.
Definition: JObjectID.hh:27
void transform(const JRotation3D &R, const JVector3D &pos)
Transformation of geometry (see method JGEOMETRY3D::JPosition3D::transform(const JRotation3D&amp;, const JVector3D&amp;)).
Definition: JModule.hh:213
JModule & set(const double t0)
Set time offset.
Definition: JModule.hh:293
JPMT & getPMT(const int index)
Get PMT.
Definition: JModule.hh:153
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JVector3D & div(const double factor)
Scale vector.
Definition: JVector3D.hh:188
JModule(const int id, const JModuleLocation &location)
Constructor.
Definition: JModule.hh:71
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:245
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:140
Logical location of module.
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:257
JVector3D()
Default constructor.
Definition: JVector3D.hh:39