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