Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JDynamics.hh
Go to the documentation of this file.
1#ifndef __JDYNAMICS__JDYNAMICS__
2#define __JDYNAMICS__JDYNAMICS__
3
4#include <ostream>
5#include <set>
6
7#include "JLang/JTypeList.hh"
8
12
13#include "JUTC/JUTCTimeRange.hh"
14
15#include "JCompass/JEvt.hh"
17#include "JCompass/JSupport.hh"
18
19#include "JAcoustics/JModel.hh"
22#include "JAcoustics/JEvt.hh"
25
27#include "JLang/JException.hh"
28
31
32#include "JTools/JElement.hh"
33#include "JTools/JCollection.hh"
34#include "JTools/JPolfit.hh"
35#include "JTools/JHashMap.hh"
36#include "JTools/JRange.hh"
37
39
42
43
44/**
45 * \file
46 *
47 * Dynamic detector calibration.
48 * \author mdejong
49 */
50
51namespace JDYNAMICS {}
52namespace JPP { using namespace JDYNAMICS; }
53
54/**
55 * Main namespace for dynamic position and orientation calibration.
56 */
57namespace JDYNAMICS {
58
59 using JLANG::JTYPELIST;
62 using JLANG::JNoValue;
66
67
68 /**
69 * Type definition for calibration data.
70 */
74
75
76 /**
77 * Dynamic detector calibration.
78 */
79 struct JDynamics :
80 public JDetector
81 {
82 /**
83 * Auxiliary data structure to track applicability period of calibration data.
84 */
85 struct JUTCTracker :
86 public JUTCTimeRange
87 {
88 /**
89 * Constructor.
90 *
91 * \param Tmax_s applicability period [s]
92 */
93 JUTCTracker(const double Tmax_s) :
94 JUTCTimeRange(-Tmax_s, +Tmax_s)
95 {}
96
97
98 /**
99 * Reset.
100 */
101 void reset()
102 {
103 set(0.0);
104 }
105
106
107 /**
108 * Set.
109 *
110 * \param t0_s UTC time [s]
111 */
112 void set(const double t0_s)
113 {
114 const double Tmax_s = 0.5 * (getUpperLimit() - getLowerLimit());
115
116 setRange(t0_s - Tmax_s, t0_s + Tmax_s);
117 }
118 };
119
120
121 /**
122 * Dynamic orientation calibration.
123 */
125 public JUTCTracker
126 {
127 enum {
128 NUMBER_OF_POINTS = 20, //!< number of points for interpolation
129 NUMBER_OF_DEGREES = 1 //!< number of degrees for interpolation
130 };
131
136 typedef typename function_type::collection_type::container_type container_type;
137
140
143
144
145 /**
146 * Constructor.
147 *
148 * \param detector detector
149 * \param Tmax_s applicability period of calibration [s]
150 */
152 const double Tmax_s) :
153 JUTCTracker(Tmax_s)
154 {
155 using namespace JPP;
156
158 THROW(JValueOutOfRange, "Detector version " << detector.getVersion() << " < " << JDetectorVersion::V4);
159 }
160
161 if (hasDetectorBuilder(detector.getID())) {
162
163 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
164
165 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
166 if (module->getFloor() != 0) {
167 buffer[module->getID()] = getRotation(demo.getModule(module->getID()), *module);
168 }
169 }
170
171 } else {
172
173 THROW(JValueOutOfRange, "No detector address map for detector identier " << detector.getID());
174 }
175 }
176
177
178 /**
179 * Load calibration data.
180 *
181 * \param input calibration data
182 */
184 {
185 this->reset();
186
187 while (input.hasNext()) {
188
189 const JCOMPASS::JOrientation* orientation = input.next();
190
191 if (buffer.has(orientation->id)) {
193 }
194 }
195
196 for (data_type::iterator i = calibration.begin(); i != calibration.end(); ++i) {
197 i->second.sort();
198 i->second.compile();
199 }
200 }
201
202
203 bool empty() const { return calibration.empty(); } //!< empty
204 size_t size() const { return calibration.size(); } //!< size
205 const_iterator begin() const { return calibration.begin(); } //!< begin of calibration data
206 const_iterator end() const { return calibration.end(); } //!< end of calibration data
207 const_reverse_iterator rbegin() const { return calibration.rbegin(); } //!< begin of reverse of calibration data
208 const_reverse_iterator rend() const { return calibration.rend(); } //!< begin of reverse of calibration data
209
210
211 /**
212 * Get coverage.
213 *
214 * \param detector detector
215 * \param t1_s UTC time [s]
216 * \return coverage [0,1]
217 */
218 double getCoverage(const JDetector& detector, const double t1_s) const
219 {
220 int n0 = 0;
221 int n1 = 0;
222
223 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
224
225 if (module->getFloor() != 0 && !module->has(COMPASS_DISABLE)) {
226
227 ++n0;
228
229 if (calibration.has(module->getID()) && !calibration.get(module->getID()).empty()) {
230 if (calibration[module->getID()].getXmin() <= t1_s &&
231 calibration[module->getID()].getXmax() >= t1_s) {
232 ++n1;
233 }
234 }
235 }
236 }
237
238 if (n0 != 0)
239 return (double) n1 / (double) n0;
240 else
241 return 0.0;
242 }
243
244
245 /**
246 * Calibrate given detector at given UTC time.
247 *
248 * \param detector detector (I/O)
249 * \param t1_s UTC time [s]
250 * \return true if updated; else false
251 */
252 bool update(JDetector& detector, const double t1_s)
253 {
254 using namespace std;
255 using namespace JPP;
256
257 if (!calibration.empty()) {
258
259 if (!in_range(t1_s)) {
260
261 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
262
263 if (module->getFloor() != 0 && !module->has(COMPASS_DISABLE) && calibration.has(module->getID()) && buffer.has(module->getID())) {
264
265 const function_type& f1 = calibration.get(module->getID());
266
267 if (!f1.empty()) {
268
269 if (t1_s >= f1.getXmin() && t1_s <= f1.getXmax()) {
270
271 JQuaternion3D Q0 = buffer[module->getID()];
272 JQuaternion3D Q1 = module->getQuaternion() * f1(t1_s);
273
274 const JPosition3D center = module->getPosition();
275
276 module->sub(center);
277
278 module->rotate(Q1 * Q0.conjugate());
279
280 module->add(center);
281
282 buffer[module->getID()] = Q1;
283 }
284 }
285 }
286 }
287
288 set(t1_s);
289
290 return true;
291 }
292 }
293
294 return false;
295 }
296
297 protected:
300 };
301
302
303 /**
304 * Dynamic position calibration.
305 */
306 struct JPosition :
307 public JUTCTracker
308 {
309 enum {
310 NUMBER_OF_POINTS = 7, //!< number of points for interpolation
311 NUMBER_OF_DEGREES = 2 //!< number of degrees for interpolation
312 };
313
315
317 typedef JTOOLS::JPolfitFunction1D<NUMBER_OF_POINTS,
318 NUMBER_OF_DEGREES,
320
322
325
326
327 /**
328 * Constructor.
329 *
330 * \param detector detector
331 * \param Tmax_s applicability period of calibration [s]
332 */
334 const double Tmax_s) :
335 JUTCTracker(Tmax_s),
337 {
338 using namespace JPP;
339
341 THROW(JValueOutOfRange, "Detector version " << detector.getVersion() << " < " << JDetectorVersion::V4);
342 }
343 }
344
345
346 /**
347 * Load calibration data.
348 *
349 * \param input calibration data
350 */
352 {
353 this->reset();
354
355 while (input.hasNext()) {
356
357 const JACOUSTICS::JEvt* evt = input.next();
358 const double t1_s = 0.5 * (evt->UNIXTimeStart + evt->UNIXTimeStop);
359
360 for (JACOUSTICS::JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
361 calibration[i->id][t1_s] = getString(*i);
362 }
363 }
364
365 for (data_type::iterator i = calibration.begin(); i != calibration.end(); ++i) {
366 i->second.compile();
367 }
368 }
369
370
371 /**
372 * Load mechanical model data.
373 *
374 * \param input mechanical model data
375 */
377 {
378 if (input.hasNext())
379 geometry.setMechanics(*input.next());
380 else
381 THROW(JNoValue, "Position calibration requires mechanical model data in input file; run putMechanics[.sh] or rerun JKatoomba.");
382 }
383
384
385 bool empty() const { return calibration.empty(); } //!< empty
386 size_t size() const { return calibration.size(); } //!< size
387 const_iterator begin() const { return calibration.begin(); } //!< begin of calibration data
388 const_iterator end() const { return calibration.end(); } //!< end of calibration data
389 const_reverse_iterator rbegin() const { return calibration.rbegin(); } //!< begin of reverse of calibration data
390 const_reverse_iterator rend() const { return calibration.rend(); } //!< begin of reverse of calibration data
391
392
393 /**
394 * Get coverage.
395 *
396 * \param detector detector
397 * \param t1_s UTC time [s]
398 * \return coverage [0,1]
399 */
400 double getCoverage(const JDetector& detector, const double t1_s) const
401 {
402 int n0 = 0;
403 int n1 = 0;
404
405 std::set<int> string;
406
407 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
408 if (module->getFloor() != 0) {
409 string.insert(module->getString());
410 }
411 }
412
413 for (std::set<int>::const_iterator i = string.begin(); i != string.end(); ++i) {
414
415 ++n0;
416
417 if (calibration.has(*i) && !calibration.get(*i).empty()) {
418 if (calibration[*i].getXmin() <= t1_s &&
419 calibration[*i].getXmax() >= t1_s) {
420 ++n1;
421 }
422 }
423 }
424
425 if (n0 != 0)
426 return (double) n1 / (double) n0;
427 else
428 return 0.0;
429 }
430
431
432 /**
433 * Get detector geometry.
434 *
435 * \return detector geometry
436 */
437 const JGeometry& getGeometry() const
438 {
439 return geometry;
440 }
441
442
443 /**
444 * Calibrate given detector at given UTC time.
445 *
446 * \param detector detector (I/O)
447 * \param t1_s UTC time [s]
448 * \return true if updated; else false
449 */
450 bool update(JDetector& detector, const double t1_s)
451 {
452 using namespace std;
453 using namespace JPP;
454
455 if (!calibration.empty()) {
456
457 if (!in_range(t1_s)) {
458
460
461 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
462
463 if (module->getFloor() != 0) {
464
465 if (!buffer.has(module->getString())) {
466
467 if (calibration.has(module->getString())) {
468
469 const function_type& f1 = calibration.get(module->getString());
470
471 if (!f1.empty()) {
472 if (t1_s >= f1.getXmin() && t1_s <= f1.getXmax()) {
473 buffer[module->getString()] = f1(t1_s);
474 }
475 }
476 }
477 }
478
479 if (buffer.has(module->getString())) {
480 module->set(geometry[module->getString()].getPosition(buffer[module->getString()], module->getFloor()) - getPiezoPosition());
481 }
482 }
483 }
484
485 set(t1_s);
486
487 return true;
488 }
489 }
490
491 return false;
492 }
493
494 protected:
497 };
498
499
500 /**
501 */
503
504
505 /**
506 * Constructor.
507 *
508 * \param detector detector
509 * \param Tmax_s applicability period of calibration [s]
510 */
512 const double Tmax_s) :
514 orientation(detector, Tmax_s),
515 position (detector, Tmax_s)
516 {
517 this->setUTCTimeRange(JUTCTimeRange::DEFAULT_RANGE());
518 }
519
520
521 /**
522 * Get actual detector.
523 *
524 * \return detector
525 */
526 const JDetector& getDetector() const
527 {
528 return static_cast<const JDetector&>(*this);
529 }
530
531
532 /**
533 * Load calibration data.
534 *
535 * \param input calibration data
536 */
537 template<class JObjectIterator_t>
538 void load(JObjectIterator_t& input)
539 {
540 this->setUTCTimeRange(JUTCTimeRange::DEFAULT_RANGE());
541
542 try { orientation.load(dynamic_cast<JObjectIterator<JCOMPASS::JOrientation>&>(input)); } catch(const std::exception&) {}
543 try { position .load(dynamic_cast<JObjectIterator<JACOUSTICS::JEvt>&> (input)); } catch(const std::exception&) {}
544
545 if (!position.empty()) {
546 position.load(dynamic_cast<JObjectIterator<JACOUSTICS::JDetectorMechanics_t>&>(input));
547 }
548 }
549
550
551 /**
552 * Get detector calibrated at given time.
553 *
554 * \param t1_s UTC time [s]
555 * \return true if updated; else false
556 */
557 bool update(const double t1_s)
558 {
559 bool is_updated = false;
560
561 if (!in_range(t1_s)) {
562
563 JUTCTimeRange range;
564
565 if (orientation.update(static_cast<JDetector&>(*this), t1_s)) { range.join(orientation.getUTCTimeRange()); is_updated = true; }
566 if (position .update(static_cast<JDetector&>(*this), t1_s)) { range.join(position .getUTCTimeRange()); is_updated = true; }
567
568 if (is_updated) {
569 setUTCTimeRange(range);
570 }
571 }
572
573 return is_updated;
574 }
575
576
577 /**
578 * Get detector calibrated at given time.
579 *
580 * \param chronometer chronometer
581 * \return true if updated; else false
582 */
583 bool update(const JDAQChronometer& chronometer)
584 {
585 return update(chronometer.getTimesliceStart().getUTCseconds());
586 }
587
588
589 /**
590 * Get coverage at given time.
591 *
592 * \param t1_s UTC time [s]
593 * \return coverage
594 */
595 coverage_type getCoverage(const double t1_s) const
596 {
597 return { orientation.getCoverage(*this, t1_s), position.getCoverage(*this, t1_s) };
598 }
599
600
601 /**
602 * Get coverage at given time.
603 *
604 * \param chronometer chronometer
605 * \return coverage
606 */
607 coverage_type getCoverage(const JDAQChronometer& chronometer) const
608 {
609 return getCoverage(chronometer.getTimesliceStart().getUTCseconds());
610 }
611
612
613 /**
614 * Get actual coverage.
615 *
616 * \return coverage
617 */
619 {
620 return getCoverage(0.5 * (getLowerLimit() + getUpperLimit()));
621 }
622
623
624 JOrientation orientation; //!< orientation calibration
625 JPosition position; //!< position calibration
626 };
627}
628
629#endif
Acoustic event fit toolkit.
Acoustic event fit.
Model for fit to acoutsics data.
ROOT TTree parameter settings.
General purpose class for a collection of sorted elements.
Compass event fit.
Compass event data types.
ROOT TTree parameter settings.
Coverage of dynamical detector calibration.
Detector support kit.
Data structure for detector geometry and calibration.
The elements in a collection are sorted according to their abscissa values and a given distance opera...
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Acoustic geometries.
General purpose class for hash map of unique elements.
Mechanical modelling of string.
Auxiliary class to define a range between two values.
Detector data structure.
Definition JDetector.hh:96
Data structure for position in three dimensions.
Data structure for unit quaternion in three dimensions.
Exception for missing value.
Interface of object iteration for a single data type.
virtual bool hasNext()=0
Check availability of next element.
virtual const pointer_type & next()=0
Get next element.
Exception for accessing a value in a collection that is outside of its range.
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements....
Definition JSet.hh:22
bool has(const T &value) const
Test whether given value is present.
Template class for polynomial interpolation in 1D.
Definition JPolfit.hh:174
void setRange(const range_type &range)
Set range.
Definition JRange.hh:146
static JRange< T, JComparator_t > DEFAULT_RANGE()
Default range.
Definition JRange.hh:555
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
range_type & join(const range_type &range)
Join ranges.
Definition JRange.hh:415
bool in_range(argument_type x) const
Test whether value is inside range.
Definition JRange.hh:323
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
UTC time range [s].
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
uint32_t getUTCseconds() const
Get major time.
static const int COMPASS_DISABLE
Enable (disable) use of compass if this status bit is 0 (1);.
Auxiliary classes and methods for acoustic position calibration.
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
JQuaternion3D getQuaternion(const JQuaternion &Q)
Get quaternion.
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
bool hasDetectorBuilder(const int id)
Check if detector builder is available.
Main namespace for dynamic position and orientation calibration.
Definition JCoverage.hh:11
JTYPELIST< JCOMPASS::JOrientation, JACOUSTICS::JEvt, JACOUSTICS::JDetectorMechanics_t >::typelist calibration_types
Type definition for calibration data.
Definition JDynamics.hh:73
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JDAQUTCTimeRange getUTCTimeRange()
Get UTC time range.
if((p==this->begin() &&this->getDistance(x,(p++) ->getX()) > distance_type::precision)||(p==this->end() &&this->getDistance((--p) ->getX(), x) > distance_type::precision))
Template base class for polynomial interpolations with polynomial result.
Definition JPolint.hh:775
void reset(T &value)
Reset value.
Calibration.
Definition JHead.hh:330
Detector file.
Definition JHead.hh:227
Auxiliary data structure for mechanical model parameters of strings in a given detector.
Acoustic event fit.
double UNIXTimeStop
stop time
double UNIXTimeStart
start time
Orientation of module.
@ V4
Version with quaternion and time offset per module.
Dynamic orientation calibration.
Definition JDynamics.hh:126
JTOOLS::JHashMap< int, JGEOMETRY3D::JQuaternion3D > buffer_type
Definition JDynamics.hh:138
bool update(JDetector &detector, const double t1_s)
Calibrate given detector at given UTC time.
Definition JDynamics.hh:252
const_reverse_iterator rend() const
begin of reverse of calibration data
Definition JDynamics.hh:208
data_type::const_reverse_iterator const_reverse_iterator
Definition JDynamics.hh:142
@ NUMBER_OF_DEGREES
number of degrees for interpolation
Definition JDynamics.hh:129
@ NUMBER_OF_POINTS
number of points for interpolation
Definition JDynamics.hh:128
JTOOLS::JPolfitFunction1D< NUMBER_OF_POINTS, NUMBER_OF_DEGREES, element_type, JTOOLS::JCollection > function_type
Definition JDynamics.hh:135
const_reverse_iterator rbegin() const
begin of reverse of calibration data
Definition JDynamics.hh:207
JTOOLS::JElement2D< double, JGEOMETRY3D::JQuaternion3D > element_type
Definition JDynamics.hh:132
void load(JObjectIterator< JCOMPASS::JOrientation > &input)
Load calibration data.
Definition JDynamics.hh:183
const_iterator begin() const
begin of calibration data
Definition JDynamics.hh:205
data_type::const_iterator const_iterator
Definition JDynamics.hh:141
function_type::collection_type::container_type container_type
Definition JDynamics.hh:136
JTOOLS::JHashMap< int, function_type > data_type
Definition JDynamics.hh:139
double getCoverage(const JDetector &detector, const double t1_s) const
Get coverage.
Definition JDynamics.hh:218
JOrientation(const JDetector &detector, const double Tmax_s)
Constructor.
Definition JDynamics.hh:151
const_iterator end() const
end of calibration data
Definition JDynamics.hh:206
Dynamic position calibration.
Definition JDynamics.hh:308
void load(JObjectIterator< JACOUSTICS::JDetectorMechanics_t > &input)
Load mechanical model data.
Definition JDynamics.hh:376
data_type::const_reverse_iterator const_reverse_iterator
Definition JDynamics.hh:324
JTOOLS::JHashMap< int, function_type > data_type
Definition JDynamics.hh:321
JTOOLS::JElement2D< double, JACOUSTICS::JMODEL::JString > element_type
Definition JDynamics.hh:316
const_reverse_iterator rend() const
begin of reverse of calibration data
Definition JDynamics.hh:390
JPosition(const JDetector &detector, const double Tmax_s)
Constructor.
Definition JDynamics.hh:333
JACOUSTICS::JGeometry JGeometry
Definition JDynamics.hh:314
const_iterator end() const
end of calibration data
Definition JDynamics.hh:388
JTOOLS::JPolfitFunction1D< NUMBER_OF_POINTS, NUMBER_OF_DEGREES, element_type, JTOOLS::JCollection > function_type
Definition JDynamics.hh:319
void load(JObjectIterator< JACOUSTICS::JEvt > &input)
Load calibration data.
Definition JDynamics.hh:351
double getCoverage(const JDetector &detector, const double t1_s) const
Get coverage.
Definition JDynamics.hh:400
bool update(JDetector &detector, const double t1_s)
Calibrate given detector at given UTC time.
Definition JDynamics.hh:450
const JGeometry & getGeometry() const
Get detector geometry.
Definition JDynamics.hh:437
const_reverse_iterator rbegin() const
begin of reverse of calibration data
Definition JDynamics.hh:389
const_iterator begin() const
begin of calibration data
Definition JDynamics.hh:387
data_type::const_iterator const_iterator
Definition JDynamics.hh:323
Auxiliary data structure to track applicability period of calibration data.
Definition JDynamics.hh:87
JUTCTracker(const double Tmax_s)
Constructor.
Definition JDynamics.hh:93
void set(const double t0_s)
Set.
Definition JDynamics.hh:112
Dynamic detector calibration.
Definition JDynamics.hh:81
JPosition position
position calibration
Definition JDynamics.hh:625
JDYNAMICS::coverage_type coverage_type
Definition JDynamics.hh:502
JDynamics(const JDetector &detector, const double Tmax_s)
Constructor.
Definition JDynamics.hh:511
JOrientation orientation
orientation calibration
Definition JDynamics.hh:624
bool update(const double t1_s)
Get detector calibrated at given time.
Definition JDynamics.hh:557
coverage_type getCoverage(const JDAQChronometer &chronometer) const
Get coverage at given time.
Definition JDynamics.hh:607
coverage_type getCoverage(const double t1_s) const
Get coverage at given time.
Definition JDynamics.hh:595
coverage_type getCoverage() const
Get actual coverage.
Definition JDynamics.hh:618
bool update(const JDAQChronometer &chronometer)
Get detector calibrated at given time.
Definition JDynamics.hh:583
const JDetector & getDetector() const
Get actual detector.
Definition JDynamics.hh:526
void load(JObjectIterator_t &input)
Load calibration data.
Definition JDynamics.hh:538
Data structure for coverage of detector by dynamical calibrations.
Definition JCoverage.hh:19
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
2D Element.
Definition JPolint.hh:1131
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75
container_type::const_iterator const_iterator
Definition JHashMap.hh:86
container_type::iterator iterator
Definition JHashMap.hh:88
container_type::const_reverse_iterator const_reverse_iterator
Definition JHashMap.hh:87