Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEditDetector.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4 #include <vector>
5 
6 #include "TRandom3.h"
7 
8 #include "JDetector/JDetector.hh"
17 #include "JGeometry3D/JVector3D.hh"
18 #include "JMath/JConstants.hh"
19 #include "JMath/JMath.hh"
20 #include "JTools/JRange.hh"
21 #include "JLang/JException.hh"
22 #include "JLang/JToken.hh"
23 #include "JSupport/JMeta.hh"
24 
25 #include "Jeep/JeepToolkit.hh"
26 #include "Jeep/JPrint.hh"
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 namespace {
32 
33  using namespace JPP;
34 
35  /**
36  * Wild card for string identifier, module identifier or PMT address.
37  */
38  static const int WILDCARD = -1;
39 
40  static const char EOL = ';'; //!< end-of-line
41 
42  static const std::string reset_t = "reset"; //!< Reset time offset, position and PMT status bit
43  static const std::string set_t = "set"; //!< Set time offset, position or PMT status bit
44  static const std::string add_t = "add"; //!< Add time offset or position
45  static const std::string sub_t = "sub"; //!< Subtract time offset or position
46  static const std::string rot_t = "rot"; //!< Rotate around z-axis by value [rad]
47  static const std::string mul_t = "mul"; //!< Multiply z-position by (1 + value)
48  static const std::string via_t = "via"; //!< Apply time offset by (floor * value)
49  static const std::string assign_t = "assign"; //!< Assign identifier
50 
51  static const std::string rand_t = "rand"; //!< Random value(s)
52  static const std::string randset_t = rand_t + set_t; //!< Set time offset or position
53  static const std::string randadd_t = rand_t + add_t; //!< Add time offset or position
54  static const std::string randsub_t = rand_t + sub_t; //!< Subtract time offset or position
55  static const std::string randrot_t = rand_t + rot_t; //!< Rotate around z-axis by value [rad]
56  static const std::string randmul_t = rand_t + mul_t; //!< Multiply z-position by (1 + value)
57  static const std::string randvia_t = rand_t + via_t; //!< Apply time offset by (floor * value)
58 
59  static const std::string RESET_t = "RESET"; //!< Reset time offset and quaternion of module
60  static const std::string SET_t = "SET"; //!< Set time offset or quaternion of module
61  static const std::string ADD_t = "ADD"; //!< Add time offset or quaternion of module
62  static const std::string SUB_t = "SUB"; //!< Subtract time offset or quaternion of module
63 
64 
65  /**
66  * Auxiliary class to apply detector modifications.
67  *
68  * Note that the internal identifier may apply to a module as well as a string.
69  */
70  class JModifier {
71  public:
72  /**
73  * Default constructor.
74  */
75  JModifier()
76  {}
77 
78 
79  /**
80  * Check validity.
81  *
82  * \return true if valid modifier; else false
83  */
84  bool is_valid() const
85  {
86  return (action != "" && !data.empty());
87  }
88 
89 
90  /**
91  * Apply modification to given module.
92  *
93  * \param module module
94  * \return true if valid action; else false
95  */
96  bool apply(JModule& module) const
97  {
98  switch (data.size()) {
99 
100  case 0:
101  return apply(module, action); // reset calibration
102 
103  case 1:
104  return apply(module, action, data[0]); // time/position/orientation calibration
105 
106  case 2:
107  return apply(module, action, JVector3D(data[0], data[1], 0.0)); // 2D position calibration
108 
109  case 3:
110  return apply(module, action, JVector3D(data[0], data[1], data[2])); // 3D position calibration
111 
112  case 4:
113  return apply(module, action, JQuaternion3D(data[0], data[1], data[2], data[3])); // 3D quaternion calibration
114 
115  default:
116  return false;
117  }
118  }
119 
120 
121  /**
122  * Read modifier from input.
123  *
124  * \param in input stream
125  * \param modifier modifier
126  * \return input stream
127  */
128  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
129  {
130  using namespace std;
131 
132  if (in >> modifier.id >> modifier.action) {
133 
134  modifier.data.clear();
135 
136  for (double x; in >> x; ) {
137  modifier.data.push_back(x);
138  }
139 
140  in.clear(ios_base::eofbit);
141  }
142 
143  return in;
144  }
145 
146 
147  /**
148  * Write modifier to output.
149  *
150  * \param out output stream
151  * \param modifier modifier
152  * \return output stream
153  */
154  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
155  {
156  out << modifier.id;
157  out << ' ';
158  out << modifier.action;
159 
160  for (std::vector<double>::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) {
161  out << ' ' << *i;
162  }
163 
164  return out;
165  }
166 
167 
168  int id;
169  std::string action;
170  std::vector<double> data;
171 
172  private:
173 
174  /**
175  * Apply reset to given module.
176  *
177  * \param module module
178  * \param action action
179  * \return true if valid action; else false
180  */
181  static bool apply(JModule& module, const std::string& action)
182  {
183  if (action == reset_t) {
184 
186 
187  for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
189  pmt->setStatus(JStatus());
190  }
191 
192  return true;
193 
194  } else if (action == RESET_t) {
195 
196  module.setCalibration(JCalibration());
197  module.setQuaternion(JQuaternion3D());
198 
199  return true;
200 
201  } else if (action == SET_t) {
202 
203  if (module.getFloor() != 0)
204  module.setT0(getAverage(make_array(module.begin(), module.end(), &JPMT::getT0)) - PIEZO_DELAYTIME_US * 1.0e+3);
205  else
206  module.setT0(0.0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
207 
208  return true;
209 
210  } else {
211 
212  return false;
213  }
214  }
215 
216 
217  /**
218  * Apply time/position/orientation calibration to given module.
219  *
220  * \param module module
221  * \param action action
222  * \param value value
223  * \return true if valid action; else false
224  */
225  static bool apply(JModule& module, const std::string& action, const double value)
226  {
227  if (action == set_t) { // actions with fixed values
228 
229  module.set(value);
230 
231  } else if (action == add_t) {
232 
233  module.add(value);
234 
235  } else if (action == sub_t) {
236 
237  module.sub(value);
238 
239  } else if (action == rot_t) {
240 
241  const JVector3D center = module.getPosition();
242 
243  module.sub(center);
244 
245  module.rotate(JRotation3Z(value));
246 
247  module.add(center);
248 
249  } else if (action == mul_t) {
250 
251  if (module.getFloor() != 0) {
252 
253  const JVector3D center(module.getPosition().getX(),
254  module.getPosition().getY(),
255  module.getPosition().getZ() * (1.0 + value));
256 
257  module.set(center);
258  }
259 
260  } else if (action == via_t) {
261 
262  module.add(value * module.getFloor());
263 
264  } else if (action == SET_t) {
265 
266  module.setT0(value);
267 
268  } else if (action == ADD_t) {
269 
270  module.addT0(value);
271 
272  } else if (action == SUB_t) {
273 
274  module.subT0(value);
275 
276  } else if (action == randadd_t) { // actions with random values
277 
278  module.add(gRandom->Gaus(0.0, value));
279 
280  } else if (action == randsub_t) {
281 
282  module.sub(gRandom->Gaus(0.0, value));
283 
284  } else if (action == randrot_t){
285 
286  const JVector3D center = module.getPosition();
287 
288  module.sub(center);
289 
290  module.rotate(JRotation3Z(gRandom->Gaus(0.0, value)));
291 
292  module.add(center);
293 
294  } else if (action == randmul_t) {
295 
296  if (module.getFloor() != 0) {
297 
298  const JVector3D center(module.getPosition().getX(),
299  module.getPosition().getY(),
300  module.getPosition().getZ() * gRandom->Gaus(1.0, value));
301 
302  module.set(center);
303  }
304 
305  } else if (action == randvia_t) {
306 
307  module.add(gRandom->Gaus(0.0, value) * module.getFloor());
308 
309  } else if (action == assign_t) {
310 
311  module.setID((int) value);
312 
313  } else {
314 
315  return false;
316  }
317 
318  return true;
319  }
320 
321 
322  /**
323  * Apply position calibration to given module.
324  *
325  * \param module module
326  * \param action action
327  * \param pos pos
328  * \return true if valid action; else false
329  */
330  static bool apply(JModule& module, const std::string& action, const JVector3D& pos)
331  {
332  const JVector3D randpos(gRandom->Gaus(0.0, pos.getX()),
333  gRandom->Gaus(0.0, pos.getY()),
334  gRandom->Gaus(0.0, pos.getZ()));
335 
336  if (action == set_t) // actions with fixed values
337  module.set(pos);
338  else if (action == add_t)
339  module.add(pos);
340  else if (action == sub_t)
341  module.sub(pos);
342  else if (action == randset_t) // actions with random values
343  module.set(randpos);
344  else if (action == randadd_t)
345  module.add(randpos);
346  else if (action == randsub_t)
347  module.sub(randpos);
348  else
349  return false;
350 
351  return true;
352  }
353 
354 
355  /**
356  * Apply quaternion calibration to given module.
357  *
358  * \param module module
359  * \param action action
360  * \param Q quaternion
361  * \return true if valid action; else false
362  */
363  static bool apply(JModule& module, const std::string& action, const JQuaternion3D& Q)
364  {
365  if (action == SET_t)
366  module.setQuaternion(Q);
367  else if (action == ADD_t)
368  module.setQuaternion(Q * module.getQuaternion());
369  else if (action == SUB_t)
370  module.setQuaternion(Q.getConjugate() * module.getQuaternion());
371  else
372  return false;
373 
374  return true;
375  }
376  };
377 
378 
379  /**
380  * Get modifier for given string.
381  *
382  * \param id string identifier
383  * \param modifier modifier
384  * \return modifier
385  */
386  inline const JModifier& getModifier(const int id, const JModifier& modifier)
387  {
388  using namespace std;
389 
391 
392  const string::size_type pos = modifier.action.find(rand_t);
393 
394  if (pos != string::npos) {
395 
396  JModifier& result = buffer[id][modifier.action][modifier.data.size()];
397 
398  if (!result.is_valid()) {
399 
400  result.id = id;
401  result.action = modifier.action.substr(pos + rand_t.length());
402 
403  for (size_t i = 0; i != modifier.data.size(); ++i) {
404  result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
405  }
406  }
407 
408  return result;
409 
410  } else {
411 
412  return modifier;
413  }
414  }
415 
416 
417  /**
418  * Auxiliary class to apply PMT status modifications.
419  */
420  template<class JAddress_t>
421  class JPMTModifier :
422  public JAddress_t
423  {
424  public:
425  /**
426  * Default constructor.
427  */
428  JPMTModifier()
429  {}
430 
431 
432  /**
433  * Apply modification to given PMT.
434  *
435  * \param pmt PMT
436  * \return true if valid action; else false
437  */
438  bool apply(JPMT& pmt) const
439  {
440  try {
441 
442  if (action == set_t) {
443 
444  pmt.set(getPMTStatusBit(value));
445 
446  } else if (action == reset_t) {
447 
448  pmt.reset(getPMTStatusBit(value));
449 
450  } else {
451 
452  return false;
453  }
454 
455  return true;
456  }
457  catch(const std::exception&) {}
458 
459  return false;
460  }
461 
462 
463  /**
464  * Read PMT modifier from input.
465  *
466  * \param in input stream
467  * \param modifier modifier
468  * \return input stream
469  */
470  friend inline std::istream& operator>>(std::istream& in, JPMTModifier& modifier)
471  {
472  return in >> static_cast<JAddress_t&>(modifier) >> modifier.action >> modifier.value;
473  }
474 
475 
476  /**
477  * Write modifier to output.
478  *
479  * \param out output stream
480  * \param modifier modifier
481  * \return output stream
482  */
483  friend inline std::ostream& operator<<(std::ostream& out, const JPMTModifier& modifier)
484  {
485  out << static_cast<const JAddress_t&>(modifier);
486  out << ' ';
487  out << modifier.action;
488  out << ' ';
489  out << modifier.value;
490 
491  return out;
492  }
493 
494 
495  std::string action;
496  std::string value;
497  };
498 
499 
500  /**
501  * Range of identifiers.
502  */
503  struct JRange_t :
504  public JRange<int> {
505  /**
506  * Separator between two identifier values.
507  */
508  static const char SEPARATOR = '-';
509 
510  /**
511  * Default constructor.
512  */
513  JRange_t() :
514  JRange(-1, -1)
515  {}
516 
517 
518  /**
519  * Read range from input.
520  *
521  * \param in input stream
522  * \param range range
523  * \return input stream
524  */
525  friend inline std::istream& operator>>(std::istream& in, JRange_t& range)
526  {
527  if (in >> range.first) {
528 
529  range.second = range.first;
530 
531  if (in.peek() == (int) JRange_t::SEPARATOR) {
532 
533  in.get();
534 
535  in >> range.second;
536 
537  } else {
538 
539  in.clear();
540  }
541  }
542 
543  return in;
544  }
545 
546 
547  /**
548  * Write range to output.
549  *
550  * \param out output stream
551  * \param range range
552  * \return output stream
553  */
554  friend inline std::ostream& operator<<(std::ostream& out, const JRange_t& range)
555  {
556  return out << range.first << JRange_t::SEPARATOR << range.second;
557  }
558  };
559 }
560 
561 
562 /**
563  * \file
564  *
565  * Auxiliary program to modify detector calibration.
566  *
567  * Syntax:
568  * <pre>
569  * -M "<module identifier> (set|add|sub|randset|randadd|randsub) x0 [x1 [x2]]"
570  * -S "<string number> (set|add|sub|randset|randadd|randsub) x0 [x1 [x2]]"
571  * -M "<module identifier> (rot|randrot) phi"
572  * -S "<string number> (rot|randrot) phi"
573  * -M "<module identifier> (mul|randmul) factor"
574  * -S "<string number> (mul|randmul) factor"
575  * -M "<module identifier> (via|randvia) factor"
576  * -S "<string number> (via|randvia) factor"
577  * -M "<module identifier> (reset)"
578  * -S "<string number> (reset)"
579  * -M "<module identifier> (assign) identifier"
580  * -M "<module identifier> (SET|ADD|SUB|) x0 [x1 x2 x3]"
581  * -S "<string number> (SET|ADD|SUB|) x0 [x1 x2 x3]"
582  * -M "<module identifier> (SET)"
583  * -S "<string number> (SET)"
584  * -P "<PMT identifier> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
585  * -p "<PMT physical address> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
586  * -k "<string number>[-<string number>"
587  * -r "<string number>[-<string number>"
588  * -m "<module identifier>"
589  * -D "<string number> <floor>"
590  * -\@ "<key>=<value>[;<key>=<value>"
591  * </pre>
592  * Options <tt>-M</tt> and <tt>-S</tt> refer to a module and a string, respectively.\n
593  * The values provided for a string modification coherently apply to the modules of the specified string number.
594  *
595  * The options <tt>randxxx</tt> correspond to a randomisation of the specified option.
596  *
597  * If the module identifier or string number is -1,
598  * the action is applied to all modules or strings in the detector, respectively.
599  *
600  * For options <tt>[rand]set</tt>, <tt>[rand]add</tt> and <tt>[rand]sub</tt>,
601  * the number of values apply to position or time calibration in the following way:
602  * -# time calibration <tt>(t = x0)</tt>
603  * -# position calibration <tt>(x = x0, y = x1, z = 0)</tt>
604  * -# position calibration <tt>(x = x0, y = x1, z = x2)</tt>
605  *
606  * For options <tt>[rand]rot</tt>,
607  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis.\n
608  * The rotation angle is defined in radians.
609  *
610  * For options <tt>[rand]mul</tt>,
611  * the multiplication <tt>factor</tt> (a.k.a.\ "stretching") applies to
612  * the z-coordinates of the optical modules and not to the base module (read anchor).\n
613  * The factor is defined as a fraction; the actual multiplication factor is <tt>(1 + factor)</tt>.
614  *
615  * For options <tt>[rand]via</tt>,
616  * the <tt>factor</tt> is multiplied with the floor number and then added to the time calibration.
617  *
618  * For options <tt>SET ADD SUB</tt>,
619  * the number of values apply to time or quaternion calibration of the module in the following way:
620  * -# time calibration <tt>(t = x0)</tt>
621  * -# invalid
622  * -# invalid
623  * -# quaternion calibration <tt>(qa = x0, qb = x1, qc = x2, qd = x3)</tt>
624  *
625  * If no values are given at the option <tt>SET</tt>,
626  * the time calibration of the module is set to the average time calibration of the PMTs in that module,
627  * corrected for the delay time of the pieze sensor (JDETECTOR::PIEZO_DELAYTIME_US).\n
628  * For the base module, the time calibration is set to 0,
629  * corrected for the delay time of the hydrophone (JDETECTOR::HYDROPHONE_DELAYTIME_US).\n
630  * The unit of time calibration is <tt>ns</tt>.
631  *
632  * Note that for string modifiers with option <tt>randxxx</tt>,
633  * the action is coherently applied to the modules in the specified string.\n
634  * Only one type of action (defined by <tt>xxx</tt> and the number of values) is then allowed per string.
635  *
636  * Option <tt>-\@</tt> refers to the header information.\n
637  * The list of possible keys can be obtained using JPrintDetector.cc with option <tt>-O header</tt>.
638  *
639  * Multiple options <tt>-M</tt>, <tt>-S</tt> or <tt>-\@</tt> will be processed in order of appearance.
640  *
641  * Options <tt>-k</tt> and <tt>-r</tt> can be used to keep and remove (a range of) string numbers, respectively.
642  *
643  * The options <tt>-m</tt> and <tt>-D</tt> can be used to maintain a specific module (and remove all others) and
644  * to delete a floor from a string, respectively.
645  *
646  * Note finally that if the output file name is the same as the input file name,
647  * the original file will be overwritten.
648  *
649  * \author mdejong
650  */
651 int main(int argc, char **argv)
652 {
653  using namespace std;
654  using namespace JPP;
655 
656  typedef JToken<';'> JToken_t;
657 
658  string inputFile;
659  string outputFile;
660  vector<JModifier> mod;
661  vector<JModifier> str;
662  vector<JToken_t> hdr;
665  vector<JRange_t> keep;
666  vector<JRange_t> rm;
667  vector<int> id;
668  multimap<int, int> del;
669  int debug;
670 
671  try {
672 
673  JParser<> zap("Auxiliary program to modify detector.");
674 
675  zap['a'] = make_field(inputFile);
676  zap['M'] = make_field(mod) = JPARSER::initialised();
677  zap['S'] = make_field(str) = JPARSER::initialised();
678  zap['@'] = make_field(hdr) = JPARSER::initialised();
679  zap['P'] = make_field(pmt) = JPARSER::initialised();
680  zap['p'] = make_field(alt) = JPARSER::initialised();
681  zap['o'] = make_field(outputFile);
682  zap['k'] = make_field(keep) = JPARSER::initialised();
683  zap['r'] = make_field(rm) = JPARSER::initialised();
684  zap['m'] = make_field(id) = JPARSER::initialised();
685  zap['D'] = make_field(del) = JPARSER::initialised();
686  zap['d'] = make_field(debug) = 2;
687 
688  zap(argc, argv);
689  }
690  catch(const exception &error) {
691  FATAL(error.what() << endl);
692  }
693 
695 
696  try {
697  load(inputFile, detector);
698  }
699  catch(const JException& error) {
700  FATAL(error);
701  }
702 
703 
704  gRandom->SetSeed(0);
705 
706 
707  if ((keep.empty() ? 0 : 1 +
708  rm .empty() ? 0 : 1 +
709  id .empty() ? 0 : 1) > 1) {
710  FATAL("Use either option -k, -r or -m." << endl);
711  }
712 
713 
714  detector.comment.add(JMeta(argc,argv));
715 
716  if (detector.setToLatestVersion()) {
717  NOTICE("Set detector version to " << detector.getVersion() << endl);
718  }
719 
720  if (!hdr.empty()) {
721 
722  JProperties helper = detector.getProperties();
723 
724  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
725 
726  istringstream is(*i);
727 
728  is >> helper;
729  }
730  }
731 
732 
733  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
734 
735  bool __rm__ = !keep.empty() && rm.empty();
736 
737  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
738  if (module->getString() >= i->first && module->getString() <= i->second) {
739  __rm__ = false;
740  }
741  }
742 
743  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
744  if (module->getString() >= i->first && module->getString() <= i->second) {
745  __rm__ = true;
746  }
747  }
748 
749  if (!id.empty()) {
750  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
751  }
752 
753  const auto range = del.equal_range(module->getString());
754 
755  for (auto i = range.first; i != range.second; ++i) {
756  if (i->second == module->getFloor()) {
757  __rm__ = true;
758  }
759  }
760 
761  if (__rm__)
762  module = detector.erase(module);
763  else
764  ++module;
765  }
766 
767 
768  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
769 
770  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
771 
772  if (module->getID() == i->id || i->id == WILDCARD ){
773 
774  DEBUG("Modifier" << ' '
775  << "(" << FILL(4,'0') << module->getString() << "," << FILL(2,'0') << module->getFloor() << FILL() << ")" << ' '
776  << setw(10) << module->getID() << ' '
777  << "action" << ' ' << i->action << JEEPZ() << i->data << endl);
778 
779  if (!i->apply(*module)) {
780  ERROR("No valid action: " << *i << endl);
781  }
782  }
783  }
784  }
785 
786 
787  for (vector<JModifier>::const_iterator i = str.begin(); i != str.end(); ++i) {
788 
789  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
790 
791  if (module->getString() == i->id || i->id == WILDCARD) {
792 
793  const JModifier& modifier = getModifier(module->getString(), *i);
794 
795  DEBUG("Modifier" << ' '
796  << "(" << FILL(4,'0') << module->getString() << "," << FILL(2,'0') << module->getFloor() << FILL() << ")" << ' '
797  << setw(10) << module->getID() << ' '
798  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl);
799 
800  if (!modifier.apply(*module)) {
801  ERROR("No valid action: " << *i << endl);
802  }
803  }
804  }
805  }
806 
807 
808  for (vector< JPMTModifier<JPMTIdentifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
809 
810  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
811 
812  if (module->getID() == i->getModuleID() || i->getModuleID() == WILDCARD) {
813 
814  DEBUG("PMT modifier" << ' '
815  << "(" << setw(10) << module->getID() << "," << setw(2) << i->getPMTAddress() << ")" << ' '
816  << "action" << ' ' << i->action << ' '
817  << "value" << ' ' << i->value << endl);
818 
819  if (i->getPMTAddress() == WILDCARD) {
820 
821  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
822  if (!i->apply(module->getPMT(pmt))) {
823  ERROR("No valid action: " << *i << endl);
824  }
825  }
826 
827  } else if (i->getPMTAddress() < 0 ||
828  i->getPMTAddress() >= getNumberOfPMTs(*module) ||
829  !i->apply(module->getPMT(i->getPMTAddress()))) {
830  ERROR("No valid action: " << *i << endl);
831  }
832  }
833  }
834  }
835 
836  if (!alt.empty()) {
837 
838  if (!hasDetectorAddressMap(detector.getID())) {
839  FATAL("Invalid detector identifier " << detector.getID() << endl);
840  }
841 
842  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
843 
844  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
845 
846  const JModuleAddressMap memo = demo.get(module->getID());
847 
848  for (vector< JPMTModifier<JPMTPhysicalAddress> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
849 
850  const int tdc = memo.getAddressTranslator(*i).tdc;
851 
852  DEBUG("PMT modifier" << ' '
853  << "(" << setw(10) << module->getID() << "," << setw(2) << tdc << ")" << ' '
854  << "action" << ' ' << i->action << ' '
855  << "value" << ' ' << i->value << endl);
856 
857  if (!i->apply(module->getPMT(tdc))) {
858  ERROR("No valid action: " << *i << endl);
859  }
860  }
861  }
862  }
863 
864 
865  try {
867  }
868  catch(const JException& error) {
869  FATAL(error);
870  }
871 }
void set(const int bit)
Set PMT status.
Definition: JStatus.hh:124
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
Definition: JStatus.hh:281
Exceptions.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:57
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
JQuaternion3D getConjugate() const
Get conjugate of this quaternion.
Detector data structure.
Definition: JDetector.hh:80
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Utility class to parse parameter values.
Definition: JProperties.hh:496
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
void subT0(const double t0)
Subtract time offset.
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:42
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Data structure for time calibration.
void reset(const int bit)
Reset PMT status.
Definition: JStatus.hh:135
string outputFile
is
Definition: JDAQCHSM.chsm:167
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
const JQuaternion3D & getQuaternion() const
Get quaternion.
Rotation around Z-axis.
Definition: JRotation3D.hh:85
JModule & sub(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:474
Lookup table for PMT addresses in optical module.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
static const double PIEZO_DELAYTIME_US
Piezo delay time [us].
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
void setQuaternion(const JQuaternion3D &quaternion)
Set quaternion.
Mathematical constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:37
Auxiliary methods for handling file names, type names and environment.
return result
Definition: JPolint.hh:727
int getID() const
Get identifier.
Definition: JObjectID.hh:50
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
JPosition3D getPosition(const Vec &pos)
Get position.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
static const JModule & getInstance()
Get reference to unique instance of this class object.
Definition: JModule.hh:103
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:211
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:351
Range of values.
Definition: JRange.hh:38
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
int getString() const
Get string number.
Definition: JLocation.hh:134
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1593
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void setT0(const double t0)
Set time offset.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Wrapper class around string.
Definition: JToken.hh:23
void setCalibration(const JCalibration &cal)
Set calibration.
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:72
double getX() const
Get x position.
Definition: JVector3D.hh:94
Base class for data structures with artithmetic capabilities.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
void addT0(const double t0)
Add time offset.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:444
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:456
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
double getT0() const
Get time offset.
int main(int argc, char *argv[])
Definition: Main.cpp:15