Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JKatoomba_t.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JKATOOMBA_T__
2#define __JACOUSTICS__JKATOOMBA_T__
3
4#include <vector>
5#include <memory>
6#include <mutex>
7
8#include "TMatrixTSym.h"
9#include "TDecompSVD.h"
10
11#include "JFit/JEstimator.hh"
12#include "JFit/JRegressor.hh"
13#include "JFit/JSimplex.hh"
14#include "JFit/JMEstimator.hh"
15#include "JMath/JVectorND.hh"
16#include "JMath/JMatrixNS.hh"
17#include "JLang/JType.hh"
18#include "JLang/JException.hh"
19#include "JMath/JMatrixNS.hh"
20#include "Jeep/JMessage.hh"
21
24#include "JAcoustics/JEKey.hh"
26#include "JAcoustics/JModel.hh"
27#include "JAcoustics/JHit.hh"
29
30
31/**
32 * \file
33 *
34 * Fit functions of acoustic model.
35 * \author mdejong
36 */
37namespace JACOUSTICS {}
38namespace JPP { using namespace JACOUSTICS; }
39
40namespace JACOUSTICS {
41
42 using JLANG::JType;
45 using JMATH::JMath;
46 using JFIT::JEstimator;
48 using JFIT::JSimplex;
50
51
52 /**
53 * Get total weight of data points.
54 *
55 * \param __begin begin of data
56 * \param __end end of data
57 * \return total weight
58 */
59 template<class T>
60 inline double getWeight(T __begin, T __end)
61 {
62 double W = 0;
63
64 for (T i = __begin; i != __end; ++i) {
65 W += i->getWeight();
66 }
67
68 return W;
69 }
70
71
72 /**
73 * Template definition of fit function of acoustic model.
74 */
75 template<template<class T> class JMinimiser_t = JType>
76 struct JKatoomba;
77
78
79 /**
80 * Auxiliary base class for fit function of acoustic model.
81 */
82 template<>
83 struct JKatoomba<JType> {
84
85 typedef std::shared_ptr<JMEstimator> estimator_type;
86
87
88 /**
89 * Auxiliary data structure to sort transmissions.
90 */
91 static const struct compare {
92 /**
93 * Sort transmissions in following order.
94 * - ascending identifier;
95 * - descending quality;
96 * - ascending time-of-arrival;
97 *
98 * \param first first transmission
99 * \param second second transmission
100 * \return true if first transmission before second; else false
101 */
102 inline bool operator()(const JTransmission& first, const JTransmission& second) const
103 {
104 if (first.getID() == second.getID()) {
105
106 if (first.getQ() == second.getQ())
107 return first.getToA() < second.getToA();
108 else
109 return first.getQ() > second.getQ();
110
111 } else {
112
113 return first.getID() < second.getID();
114 }
115 }
116 } compare;
117
118
119 /**
120 * Constructor.
121 * The option corresponds to the use of fit parameters in the model of the detector geometry.\n
122 * A negative implies that all strings in the detector use common fit parameters.
123 *
124 * \param geometry detector geometry
125 * \param velocity sound velocity
126 * \param option option
127 */
128 JKatoomba(const JGeometry& geometry,
129 const JSoundVelocity& velocity,
130 const int option) :
131 geometry(geometry),
132 velocity(velocity),
133 option (option)
134 {
136
137 if (option < 0) {
138 this->option = -option;
139 }
140 };
141
142
143 /**
144 * Get estimated time-of-arrival for given hit.
145 *
146 * \param model model
147 * \param hit hit
148 * \return time-of-arrival
149 */
150 double getToA(const JModel& model, const JHit& hit) const
151 {
152 const JGEOMETRY::JString& string = geometry[hit.getString()];
153 const JMODEL ::JString& parameters = model.string[hit.getString()];
154 const JPosition3D position = string.getPosition(parameters, hit.getFloor());
155
156 const double D = hit.getDistance(position);
157 const double Vi = velocity.getInverseVelocity(D, hit.getZ(), position.getZ());
158
159 return model.emission[hit.getEKey()].t1 + D * Vi;
160 }
161
162
163 /**
164 * Get estimated time-of-emission for given hit.
165 *
166 * \param model model
167 * \param hit hit
168 * \return time-of-arrival
169 */
170 double getToE(const JModel& model, const JHit& hit) const
171 {
172 const JGEOMETRY::JString& string = geometry[hit.getString()];
173 const JMODEL ::JString& parameters = model.string[hit.getString()];
174 const JPosition3D position = string.getPosition(parameters, hit.getFloor());
175
176 const double D = hit.getDistance(position);
177 const double Vi = velocity.getInverseVelocity(D, hit.getZ(), position.getZ());
178
179 return hit.getValue() - D * Vi;
180 }
181
182
183 const JGeometry& geometry; //!< detector geometry
184 JSoundVelocity velocity; //!< sound velocity
185 int option; //!< fit option
186 estimator_type estimator; //!< M-Estimator function
187
188 protected:
189 /**
190 * H-equation as per hit.
191 */
192 struct H_t :
193 public JMODEL::JEmission,
194 public JMODEL::JString,
195 public JMath<H_t>
196 {
197 /**
198 * Default constructor.
199 */
200 H_t() :
201 JMODEL::JEmission(),
202 JMODEL::JString ()
203 {}
204
205
206 /**
207 * Constructor.
208 *
209 * \param emission emission
210 * \param string string
211 */
212 H_t(const JMODEL::JEmission& emission,
213 const JMODEL::JString& string) :
214 JMODEL::JEmission(emission),
215 JMODEL::JString (string)
216 {}
217
218
219 /**
220 * Scale H-equation.
221 *
222 * \param factor multiplication factor
223 * \return this H-equation
224 */
225 H_t& mul(const double factor)
226 {
227 static_cast<JMODEL::JEmission&>(*this).mul(factor);
228 static_cast<JMODEL::JString&> (*this).mul(factor);
229
230 return *this;
231 }
232 };
233
234
235 /**
236 * Indices of H-equation in global model.
237 */
238 struct I_t
239 {
240 /**
241 * Default constructor.
242 */
243 I_t() :
244 t1 (0),
245 tx (0),
246 ty (0),
247 tx2(0),
248 ty2(0),
249 vs (0)
250 {}
251
252
253 int t1;
254 int tx;
255 int ty;
256 int tx2;
257 int ty2;
258 int vs;
259 };
260 };
261
262
263 /**
264 * Template specialisation of fit function of acoustic model based on JAbstractMinimiser minimiser.\n
265 * This class can be used to evaluate the chi2.
266 */
267 template<>
269 public JAbstractMinimiser<JModel>,
270 public JKatoomba<>
271 {
272 typedef double result_type;
273
274
275 /**
276 * Constructor
277 * The option corresponds to the use of fit parameters in the model of the detector geometry.\n
278 * A negative implies that all strings in the detector use common fit parameters.
279 *
280 * \param geometry detector geometry
281 * \param velocity sound velocity
282 * \param option option
283 */
284 JKatoomba(const JGeometry& geometry,
285 const JSoundVelocity& velocity,
286 const int option) :
287 JKatoomba<>(geometry, velocity, option)
288 {};
289
290
291 /**
292 * Fit function.\n
293 * This method is used to determine the chi2 of given hit with respect to actual model.
294 *
295 * \param model model
296 * \param hit hit
297 * \return chi2
298 */
299 result_type operator()(const JModel& model, const JHit& hit) const
300 {
301 const double toa_s = this->getToA(model, hit);
302 const double u = (toa_s - hit.getValue()) / hit.getSigma();
303
304 return estimator->getRho(u) * hit.getWeight();
305 }
306
307
308 /**
309 * Fit.
310 *
311 * \param __begin begin of hits
312 * \param __end end of hits
313 * \return chi2
314 */
315 template<class T>
316 result_type operator()(T __begin, T __end)
317 {
318 this->value.setOption(this->option);
319
320 return JAbstractMinimiser<JModel>::operator()(*this, __begin, __end);
321 }
322
323
324 /**
325 * Fit.
326 *
327 * \param model model
328 * \param __begin begin of hits
329 * \param __end end of hits
330 * \return chi2
331 */
332 template<class T>
333 result_type operator()(const JModel& model, T __begin, T __end)
334 {
335 this->value = model;
336
337 return (*this)(__begin, __end);
338 }
339 };
340
341
342 /**
343 * Algorithm for matrix inversion.
344 */
346 SVD_t = 1, //!< SVD
347 LDU_t = 2 //!< LDU
348 };
349
350
351 /**
352 * Auxiliary data structure for compatibility of symmetric matrix.
353 * Inversion is based on SVD algorithm.
354 */
355 struct TMatrixDS :
356 public TMatrixD
357 {
358 static constexpr double TOLERANCE = 1.0e-8; //!< Tolerance for SVD
359
360 /**
361 * Resize matrix.
362 */
363 void resize(const size_t size)
364 {
365 ResizeTo(size, size);
366 }
367
368 /**
369 * Set matrix to the null matrix.
370 */
371 void reset()
372 {
373 Zero();
374 }
375
376 /**
377 * Invert matrix according SVD decomposition.
378 */
379 void invert()
380 {
381#ifdef THREAD_SAFE
382 using namespace std;
383
384 unique_lock<mutex> lock(mtx);
385#endif
386 TDecompSVD svd(*this, TOLERANCE);
387
388 Bool_t status;
389
390 static_cast<TMatrixD&>(*this) = svd.Invert(status);
391 }
392
393 /**
394 * Get solution of equation <tt>A x = b</tt>.
395 *
396 * \param u column vector; b on input, x on output(I/O)
397 */
398 template<class JVectorND_t>
399 void solve(JVectorND_t& u)
400 {
401#ifdef THREAD_SAFE
402 using namespace std;
403
404 unique_lock<mutex> lock(mtx);
405#endif
406 TDecompSVD svd(*this, TOLERANCE);
407
408 TVectorD b(u.size());
409
410 for (size_t i = 0; i != u.size(); ++i) {
411 b[i] = u[i];
412 }
413
414 svd.Solve(b);
415
416 for (size_t i = 0; i != u.size(); ++i) {
417 u[i] = b[i];
418 }
419 }
420
421 static std::mutex mtx; //!< TDecompSVD
422 };
423
424
425 /**
426 * Using declaration for compatibility of symmetric matrix.
427 * Inversion is based on LDU algorithm.
428 */
429 using JMATH::JMatrixNS;
430
431
432 /**
433 * Template specialisation of fit function of acoustic model based on linear approximation.
434 */
435 template<>
437 public JKatoomba<>
438 {
439 /**
440 * Constructor
441 * The option corresponds to the use of fit parameters in the model of the detector geometry.\n
442 * A negative implies that all strings in the detector use common fit parameters.
443 *
444 * \param geometry detector geometry
445 * \param velocity sound velocity
446 * \param option option
447 */
448 JKatoomba(const JGeometry& geometry,
449 const JSoundVelocity& velocity,
450 const int option) :
451 JKatoomba<>(geometry, velocity, option)
452 {};
453
454
455 /**
456 * Get start values of string parameters.\n
457 * Note that this method may throw an exception.
458 *
459 * \param __begin begin of hits
460 * \param __end end of hits
461 * \return model
462 */
463 template<class T>
464 JModel& operator()(T __begin, T __end) const
465 {
466 switch (MATRIX_INVERSION) {
467
468 case SVD_t:
469 return this->evaluate(__begin, __end, svd);
470
471 case LDU_t:
472 return this->evaluate(__begin, __end, ldu);
473
474 default:
475 THROW(JValueOutOfRange, "Invalid matrix type " << MATRIX_INVERSION);
476 }
477 }
478
479
480 static JMatrix_t MATRIX_INVERSION; // matrix inversion
481
482 private:
483 mutable JMatrixNS ldu;
484 mutable TMatrixDS svd;
485
487
488 /**
489 * Get start values of string parameters.\n
490 * Note that this method may throw an exception.
491 *
492 * \param __begin begin of hits
493 * \param __end end of hits
494 * \param V matrix
495 * \return model
496 */
497 template<class T, class JMatrixNS_t>
498 JModel& evaluate(T __begin, T __end, JMatrixNS_t& V) const
499 {
500 using namespace std;
501 using namespace JPP;
502 using namespace JGEOMETRY;
503
504 value = JModel(__begin, __end); // set up global model according data
505
506 if (this->option == JMODEL::FIT_EMITTERS_ONLY_t)
507 value.setOption(JMODEL::FIT_EMITTERS_ONLY_t);
508 else
510
511 H_t H; // H-equation as per hit
512 I_t i; // indices of H-equation in global model
513
514 const size_t N = value.getN();
515
516 V.resize(N);
517 Y.resize(N);
518
519 V.reset();
520 Y.reset();
521
522 for (T hit = __begin; hit != __end; ++hit) {
523
524 const JString& string = geometry[hit->getString()];
525 const JPosition3D position = string.getPosition(hit->getFloor());
526 const double Vi = velocity.getInverseVelocity(hit->getDistance(position), hit->getZ(), position.getZ());
527
528 const double h1 = string.getHeight(hit->getFloor());
529 const JPosition3D p1 = string.getPosition() - hit->getPosition();
530 const double ds = sqrt(p1.getLengthSquared() + h1*h1 + 2.0*p1.getZ()*h1);
531 const double y = hit->getValue() - Vi*ds;
532 const double W = sqrt(hit->getWeight());
533
534 H.t1 = W * 1.0;
535 H.tx = W * Vi * p1.getX() * h1 / ds;
536 H.ty = W * Vi * p1.getY() * h1 / ds;
537
538 i.t1 = value.getIndex(hit->getEKey(), &H_t::t1);
539 i.tx = value.getIndex(hit->getString(), &H_t::tx);
540 i.ty = value.getIndex(hit->getString(), &H_t::ty);
541
542 V(i.t1, i.t1) += H.t1 * H.t1;
543
544 Y[i.t1] += W * H.t1 * y;
545
546 if (hit->getFloor() != 0) {
547
548 if (this->option != JMODEL::FIT_EMITTERS_ONLY_t) {
549
550 V(i.t1, i.tx) += H.t1 * H.tx; V(i.t1, i.ty) += H.t1 * H.ty;
551 V(i.tx, i.t1) += H.tx * H.t1; V(i.ty, i.t1) += H.ty * H.t1;
552
553 V(i.tx, i.tx) += H.tx * H.tx; V(i.tx, i.ty) += H.tx * H.ty;
554 V(i.ty, i.tx) += H.ty * H.tx; V(i.ty, i.ty) += H.ty * H.ty;
555
556 Y[i.tx] += W * H.tx * y;
557 Y[i.ty] += W * H.ty * y;
558 }
559 }
560 }
561
562 // solve A x = b
563
564 V.solve(Y);
565
566 for (size_t row = 0; row != N; ++row) {
567 value[row] += Y[row];
568 }
569
570 return value;
571 }
572
573
574 mutable JModel value;
575 };
576
577
578 /**
579 * Template specialisation of fit function of acoustic model based on JSimplex minimiser.
580 */
581 template<>
583 public JSimplex<JModel>,
584 public JKatoomba<>
585 {
586 /**
587 * Constructor
588 * The option corresponds to the use of fit parameters in the model of the detector geometry.\n
589 * A negative implies that all strings in the detector use common fit parameters.
590 *
591 * \param geometry detector geometry
592 * \param velocity sound velocity
593 * \param option option
594 */
595 JKatoomba(const JGeometry& geometry,
596 const JSoundVelocity& velocity,
597 const int option) :
598 JKatoomba<>(geometry, velocity, option)
599 {};
600
601
602 /**
603 * Fit function.\n
604 * This method is used to determine the chi2 of given hit with respect to actual model.
605 *
606 * \param model model
607 * \param hit hit
608 * \return chi2
609 */
610 double operator()(const JModel& model, const JHit& hit) const
611 {
612 const double toa_s = this->getToA(model, hit);
613 const double u = (toa_s - hit.getValue()) / hit.getSigma();
614
615 return estimator->getRho(u);
616 }
617
618
619 /**
620 * Fit.
621 *
622 * \param __begin begin of hits
623 * \param __end end of hits
624 * \return chi2
625 */
626 template<class T>
627 double operator()(T __begin, T __end)
628 {
629 this->step.clear();
630
631 for (JModel::string_type::const_iterator i = this->value.string.begin(); i != this->value.string.end(); ++i) {
632
634
635 switch (this->option) {
636
638 model.string[i->first] = JMODEL::JString(0.0, 0.0, 0.0, 0.0, 1.0e-6); this->step.push_back(model);
639
641 model.string[i->first] = JMODEL::JString(0.0, 0.0, 1.0e-6, 0.0, 0.0); this->step.push_back(model);
642 model.string[i->first] = JMODEL::JString(0.0, 0.0, 0.0, 1.0e-6, 0.0); this->step.push_back(model);
643
645 model.string[i->first] = JMODEL::JString(1.0e-3, 0.0, 0.0, 0.0, 0.0); this->step.push_back(model);
646 model.string[i->first] = JMODEL::JString(0.0, 1.0e-3, 0.0, 0.0, 0.0); this->step.push_back(model);
647 break;
648
649 default:
650 break;
651 }
652 }
653
654 for (JModel::emission_type::const_iterator i = this->value.emission.begin(); i != this->value.emission.end(); ++i) {
655
657
658 model.emission[i->first] = JMODEL::JEmission(5.0e-5); this->step.push_back(model);
659 }
660
661 return JSimplex<JModel>::operator()(*this, __begin, __end);
662 }
663 };
664
665
666 /**
667 * Place holder for custom implementation.
668 */
669 template<class T>
670 class JGandalf {};
671
672
673 /**
674 * Template specialisation of fit function of acoustic model based on JGandalf minimiser.
675 */
676 template<>
678 public JKatoomba<>
679 {
680 typedef double result_type;
681
682 /**
683 * Type definition internal data structure.
684 */
686
687
688 /**
689 * Constructor
690 * The option corresponds to the use of fit parameters in the model of the detector geometry.\n
691 * A negative implies that all strings in the detector use common fit parameters.
692 *
693 * \param geometry detector geometry
694 * \param velocity sound velocity
695 * \param option option
696 */
697 JKatoomba(const JGeometry& geometry,
698 const JSoundVelocity& velocity,
699 const int option) :
700 JKatoomba<>(geometry, velocity, option)
701 {};
702
703
704 /**
705 * Fit.
706 *
707 * \param __begin begin of hits
708 * \param __end end of hits
709 * \return chi2 and gradient
710 */
711 template<class T>
712 result_type operator()(T __begin, T __end)
713 {
714 using namespace std;
715 using namespace JPP;
716
717 value.setOption(this->option);
718
719 const int N = value.getN();
720
721 V.resize(N);
722 Y.resize(N);
723 h.resize(N);
724
725 data_type data;
726
727 for (T hit = __begin; hit != __end; ++hit) {
728 data[hit->getLocation()][hit->getEmitter()].push_back(*hit);
729 }
730
731 lambda = LAMBDA_MIN;
732
733 result_type precessor = numeric_limits<double>::max();
734
735 for (numberOfIterations = 0; numberOfIterations != MAXIMUM_ITERATIONS; ++numberOfIterations) {
736
737 DEBUG("step: " << numberOfIterations << endl);
738
739 evaluate(data);
740
741 DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
742 DEBUG("chi2: " << FIXED(12,5) << successor << endl);
743
744 if (successor < precessor) {
745
746 if (numberOfIterations != 0) {
747
748 if (fabs(precessor - successor) < EPSILON*fabs(precessor)) {
749 return successor;
750 }
751
752 if (lambda > LAMBDA_MIN) {
753 lambda /= LAMBDA_DOWN;
754 }
755 }
756
757 precessor = successor;
758 previous = value;
759
760 } else {
761
762 value = previous;
763 lambda *= LAMBDA_UP;
764
765 if (lambda > LAMBDA_MAX) {
766 return precessor; // no improvement found
767 }
768
769 evaluate(data);
770 }
771
772 // force definite positiveness
773
774 for (int i = 0; i != N; ++i) {
775
776 if (V(i,i) < PIVOT) {
777 V(i,i) = PIVOT;
778 }
779
780 h[i] = 1.0 / sqrt(V(i,i));
781 }
782
783 // normalisation
784
785 for (int i = 0; i != N; ++i) {
786 for (int j = 0; j != i; ++j) {
787 V(j,i) *= h[i] * h[j];
788 V(i,j) = V(j,i);
789 }
790 }
791
792 for (int i = 0; i != N; ++i) {
793 V(i,i) = 1.0 + lambda;
794 }
795
796
797 // solve A x = b
798
799 for (int col = 0; col != N; ++col) {
800 Y[col] *= h[col];
801 }
802
803 try {
804 V.solve(Y);
805 }
806 catch (const exception& error) {
807
808 ERROR("JGandalf: " << error.what() << endl << V << endl);
809
810 break;
811 }
812
813 // update value
814
815 for (int row = 0; row != N; ++row) {
816
817 DEBUG("u[" << noshowpos << setw(3) << row << "] = " << showpos << FIXED(20,5) << value[row]);
818
819 value[row] -= h[row] * Y[row];
820
821 DEBUG(" -> " << FIXED(20,10) << value[row] << noshowpos << endl);
822 }
823 }
824
825 return precessor;
826 }
827
828 static int debug; //!< debug level
829 static int MAXIMUM_ITERATIONS; //!< maximal number of iterations
830 static double EPSILON; //!< maximal distance to minimum
831 static double LAMBDA_MIN; //!< minimal value control parameter
832 static double LAMBDA_MAX; //!< maximal value control parameter
833 static double LAMBDA_UP; //!< multiplication factor control parameter
834 static double LAMBDA_DOWN; //!< multiplication factor control parameter
835 static double PIVOT; //!< minimal value diagonal element of matrix
836
837 double lambda;
841
842 private:
843 /**
844 * Evaluation of fit.
845 *
846 * \param data data
847 */
848 inline void evaluate(const data_type& data)
849 {
850 using namespace std;
851 using namespace JPP;
852
853 successor = 0.0;
854
855 V.reset();
856 Y.reset();
857
858 for (data_type::const_iterator p = data.begin(); p != data.end(); ++p) {
859
860 const JGEOMETRY::JString& string = geometry [p->first.getString()];
861 const JMODEL ::JString& parameters = value.string[p->first.getString()];
862 const JPosition3D position = string.getPosition(parameters, p->first.getFloor());
863
864 for (data_type::mapped_type::const_iterator emitter = p->second.begin(); emitter != p->second.end(); ++emitter) {
865
866 const double D = emitter->first.getDistance(position);
867 const double Vi = velocity.getInverseVelocity(D, emitter->first.getZ(), position.getZ());
868
869 const H_t H0(1.0, string.getGradient(parameters, emitter->first.getPosition(), p->first.getFloor()) * Vi);
870
871 for (data_type::mapped_type::mapped_type::const_iterator hit = emitter->second.begin(); hit != emitter->second.end(); ++hit) {
872
873 const double toa_s = value.emission[hit->getEKey()].t1 + D * Vi;
874
875 const double u = (toa_s - hit->getValue()) / hit->getSigma();
876 const double W = sqrt(hit->getWeight());
877
878 successor += (W*W) * estimator->getRho(u);
879
880 const H_t H = H0 * (W * estimator->getPsi(u) / hit->getSigma());
881
882 I_t i;
883
884 i.t1 = value.getIndex(hit->getEKey(), &H_t::t1);
885 i.tx = value.getIndex(hit->getString(), &H_t::tx);
886 i.ty = value.getIndex(hit->getString(), &H_t::ty);
887 i.tx2 = value.getIndex(hit->getString(), &H_t::tx2);
888 i.ty2 = value.getIndex(hit->getString(), &H_t::ty2);
889 i.vs = value.getIndex(hit->getString(), &H_t::vs);
890
891 V(i.t1, i.t1) += H.t1 * H.t1;
892
893 Y[i.t1] += W * H.t1;
894
895 if (hit->getFloor() != 0) {
896
897 switch (this->option) {
898
900 V(i.t1, i.vs) += H.t1 * H.vs; V(i.tx, i.vs) += H.tx * H.vs; V(i.ty, i.vs) += H.ty * H.vs; V(i.tx2, i.vs) += H.tx2 * H.vs; V(i.ty2, i.vs) += H.ty2 * H.vs;
901
902 V(i.vs, i.t1) = V(i.t1, i.vs);
903 V(i.vs, i.tx) = V(i.tx, i.vs);
904 V(i.vs, i.ty) = V(i.ty, i.vs);
905 V(i.vs, i.tx2) = V(i.tx2, i.vs);
906 V(i.vs, i.ty2) = V(i.ty2, i.vs);
907
908 V(i.vs, i.vs) += H.vs * H.vs;
909
910 Y[i.vs] += W * H.vs;
911
913 V(i.t1, i.tx2) += H.t1 * H.tx2; V(i.tx, i.tx2) += H.tx * H.tx2; V(i.ty, i.tx2) += H.ty * H.tx2;
914
915 V(i.tx2, i.t1) = V(i.t1, i.tx2);
916 V(i.tx2, i.tx) = V(i.tx, i.tx2);
917 V(i.tx2, i.ty) = V(i.ty, i.tx2);
918
919 V(i.t1, i.ty2) += H.t1 * H.ty2; V(i.tx, i.ty2) += H.tx * H.ty2; V(i.ty, i.ty2) += H.ty * H.ty2;
920
921 V(i.ty2, i.t1) = V(i.t1, i.ty2);
922 V(i.ty2, i.tx) = V(i.tx, i.ty2);
923 V(i.ty2, i.ty) = V(i.ty, i.ty2);
924
925 V(i.tx2, i.tx2) += H.tx2 * H.tx2; V(i.tx2, i.ty2) += H.tx2 * H.ty2;
926 V(i.ty2, i.tx2) = V(i.tx2, i.ty2); V(i.ty2, i.ty2) += H.ty2 * H.ty2;
927
928 Y[i.tx2] += W * H.tx2;
929 Y[i.ty2] += W * H.ty2;
930
932 V(i.t1, i.tx) += H.t1 * H.tx; V(i.t1, i.ty) += H.t1 * H.ty;
933 V(i.tx, i.t1) = V(i.t1, i.tx); V(i.ty, i.t1) = V(i.t1, i.ty);
934
935 V(i.tx, i.tx) += H.tx * H.tx; V(i.tx, i.ty) += H.tx * H.ty;
936 V(i.ty, i.tx) = V(i.tx, i.ty); V(i.ty, i.ty) += H.ty * H.ty;
937
938 Y[i.tx] += W * H.tx;
939 Y[i.ty] += W * H.ty;
940 break;
941
942 default:
943 break;
944 }
945 }
946 }
947 }
948 }
949 }
950
951
952 JMATH::JVectorND Y; // gradient
955 std::vector<double> h; // normalisation vector
956 };
957}
958
959#endif
Acoustic hit.
Model for fit to acoutsics data.
TPaveText * p1
Emitter hash key.
Linear fit methods.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Acoustic fit parameters.
Acoustic geometries.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
General purpose data regression method.
Sound velocity.
Acoustic transmission.
Place holder for custom implementation.
int getFloor() const
Get floor number.
Definition JLocation.hh:146
int getString() const
Get string number.
Definition JLocation.hh:135
Abstract minimiser.
Definition JRegressor.hh:27
result_type operator()(const JFunction_t &fit, T __begin, T __end)
Get chi2.
Definition JRegressor.hh:48
Template definition of linear fit.
Definition JEstimator.hh:25
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Definition JSimplex.hh:44
double operator()(const JFunction_t &fit, T __begin, T __end)
Multi-dimensional fit.
Definition JSimplex.hh:71
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition JVector3D.hh:270
double getZ() const
Get z position.
Definition JVector3D.hh:115
Exception for division by zero.
Wrapper class around STL string class.
Definition JString.hh:29
Exception for accessing a value in a collection that is outside of its range.
@ FIT_EMITTERS_AND_STRINGS_1st_ORDER_t
fit times of emission of emitters and tilt angles of strings
@ FIT_EMITTERS_AND_STRINGS_2nd_ORDER_t
fit times of emission of emitters and tilt angles of strings with second order correction
@ FIT_EMITTERS_ONLY_t
fit only times of emission of emitters
@ FIT_EMITTERS_AND_STRINGS_2nd_ORDER_AND_STRETCHING_t
fit times of emission of emitters and tilt angles of strings with second order correction and stretch...
Auxiliary classes and methods for acoustic position calibration.
double getWeight(T __begin, T __end)
Get total weight of data points.
JMatrix_t
Algorithm for matrix inversion.
void model(JModel_t &value)
Auxiliary function to constrain model during fit.
Definition JGandalf.hh:57
static const double H
Planck constant [eV s].
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int j
Definition JPolint.hh:801
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Acoustics hit.
double getSigma() const
Get resolution of time-of-arrival.
double getValue() const
Get expectation value of time-of-arrival.
double getWeight() const
Get weight.
JEKey getEKey() const
Get emitter hash key of this hit.
result_type operator()(T __begin, T __end)
Fit.
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor The option corresponds to the use of fit parameters in the model of the detector geometry...
result_type operator()(const JModel &model, T __begin, T __end)
Fit.
result_type operator()(const JModel &model, const JHit &hit) const
Fit function.
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor The option corresponds to the use of fit parameters in the model of the detector geometry...
JModel & evaluate(T __begin, T __end, JMatrixNS_t &V) const
Get start values of string parameters.
JModel & operator()(T __begin, T __end) const
Get start values of string parameters.
static double LAMBDA_DOWN
multiplication factor control parameter
std::map< JLocation, std::map< JEmitter, std::vector< JHit > > > data_type
Type definition internal data structure.
static double PIVOT
minimal value diagonal element of matrix
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor The option corresponds to the use of fit parameters in the model of the detector geometry...
result_type operator()(T __begin, T __end)
Fit.
static double LAMBDA_UP
multiplication factor control parameter
static int MAXIMUM_ITERATIONS
maximal number of iterations
static double LAMBDA_MAX
maximal value control parameter
static double EPSILON
maximal distance to minimum
void evaluate(const data_type &data)
Evaluation of fit.
static double LAMBDA_MIN
minimal value control parameter
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor The option corresponds to the use of fit parameters in the model of the detector geometry...
double operator()(const JModel &model, const JHit &hit) const
Fit function.
double operator()(T __begin, T __end)
Fit.
H_t & mul(const double factor)
Scale H-equation.
H_t(const JMODEL::JEmission &emission, const JMODEL::JString &string)
Constructor.
Indices of H-equation in global model.
Auxiliary data structure to sort transmissions.
bool operator()(const JTransmission &first, const JTransmission &second) const
Sort transmissions in following order.
const JGeometry & geometry
detector geometry
double getToA(const JModel &model, const JHit &hit) const
Get estimated time-of-arrival for given hit.
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor.
std::shared_ptr< JMEstimator > estimator_type
estimator_type estimator
M-Estimator function.
double getToE(const JModel &model, const JHit &hit) const
Get estimated time-of-emission for given hit.
JSoundVelocity velocity
sound velocity
Template definition of fit function of acoustic model.
JEmission & mul(const double factor)
Scale emission.
JString & mul(const double factor)
Scale string.
static bool singularity
Option for common fit parameters.
Model for fit to acoustics data.
JACOUSTICS::JModel::emission_type emission
size_t getIndex(int id, double JString::*p) const
Get index of fit parameter for given string.
JACOUSTICS::JModel::string_type string
Implementation for depth dependend velocity of sound.
Acoustic transmission.
double getToA() const
Get calibrated time of arrival.
double getQ() const
Get quality.
int getID() const
Get identifier.
Auxiliary data structure for compatibility of symmetric matrix.
void resize(const size_t size)
Resize matrix.
static std::mutex mtx
TDecompSVD.
void reset()
Set matrix to the null matrix.
static constexpr double TOLERANCE
Tolerance for SVD.
void invert()
Invert matrix according SVD decomposition.
void solve(JVectorND_t &u)
Get solution of equation A x = b.
Interface for maximum likelihood estimator (M-estimator).
Auxiliary class for a type holder.
Definition JType.hh:19
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347
JMatrixND & reset()
Set matrix to the null matrix.
Definition JMatrixND.hh:459
N x N symmetric matrix.
Definition JMatrixNS.hh:30
Nx1 matrix.
Definition JVectorND.hh:23
void reset()
Reset.
Definition JVectorND.hh:45
container_type::const_iterator const_iterator
Definition JHashMap.hh:86