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