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