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