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