1 #ifndef __JACOUSTICS__JKATOOMBA__
2 #define __JACOUSTICS__JKATOOMBA__
6 #include "TMatrixTSym.h"
7 #include "TDecompSVD.h"
31 namespace JACOUSTICS {}
32 namespace JPP {
using namespace JACOUSTICS; }
34 namespace JACOUSTICS {
82 template<
class JPDF_t>
179 template<
template<
class T>
class JMinimiser_t>
217 template<
class JPDF_t>
220 const double toa_s = this->getToA(model, hit);
221 const double u = (toa_s - hit.getValue()) / hit.sigma;
223 return estimator->getRho(u);
252 static constexpr
double TOLERANCE = 1.0e-8;
281 using namespace JGEOMETRY;
283 value =
JModel(__begin, __end);
293 const size_t N = value.getN();
298 for (
T hit = __begin; hit != __end; ++hit) {
302 const double Vi = velocity.getInverseVelocity(hit->getDistance(position), hit->getZ(), position.
getZ());
304 const double h1 =
string.getHeight(hit->getFloor());
305 const JPosition3D p1 =
string.getPosition() - hit->getPosition();
307 const double y = hit->getValue() - Vi*ds;
308 const double W = sqrt(hit->getWeight());
311 H.tx = W * Vi * p1.
getX() * h1 / ds;
312 H.ty = W * Vi * p1.
getY() * h1 / ds;
314 i.t1 = value.getIndex(hit->getEKey(), &H_t::t1);
315 i.tx = value.getIndex(hit->getString(), &H_t::tx);
316 i.ty = value.getIndex(hit->getString(), &H_t::ty);
318 V(i.t1, i.t1) +=
H.t1 *
H.t1;
320 Y[i.t1] += W *
H.t1 * y;
322 if (hit->getFloor() != 0) {
326 V(i.t1, i.tx) +=
H.t1 *
H.tx;
V(i.t1, i.ty) +=
H.t1 *
H.ty;
327 V(i.tx, i.t1) +=
H.tx *
H.t1;
V(i.ty, i.t1) +=
H.ty *
H.t1;
329 V(i.tx, i.tx) +=
H.tx *
H.tx;
V(i.tx, i.ty) +=
H.tx *
H.ty;
330 V(i.ty, i.tx) +=
H.ty *
H.tx;
V(i.ty, i.ty) +=
H.ty *
H.ty;
332 Y[i.tx] += W *
H.tx * y;
333 Y[i.ty] += W *
H.ty * y;
340 TDecompSVD svd(V, TOLERANCE);
344 V = svd.Invert(status);
346 for (
size_t row = 0; row !=
N; ++row) {
347 for (
size_t col = 0; col !=
N; ++col) {
348 value[row] +=
V(row,col) * Y[col];
390 template<
class JPDF_t>
393 const double toa_s = this->getToA(model, hit);
394 const double u = (toa_s - hit.getValue()) / hit.sigma;
396 return estimator->getRho(u);
492 const int N = value.getN();
500 result_type precessor = numeric_limits<double>::max();
502 for (numberOfIterations = 0; numberOfIterations != MAXIMUM_ITERATIONS; ++numberOfIterations) {
504 DEBUG(
"step: " << numberOfIterations << endl);
506 evaluate(__begin, __end);
508 DEBUG(
"lambda: " <<
FIXED(12,5) << lambda << endl);
509 DEBUG(
"chi2: " <<
FIXED(12,5) << successor << endl);
511 if (successor < precessor) {
513 if (numberOfIterations != 0) {
515 if (fabs(precessor - successor) < EPSILON*fabs(precessor)) {
519 if (lambda > LAMBDA_MIN) {
520 lambda /= LAMBDA_DOWN;
524 precessor = successor;
532 if (lambda > LAMBDA_MAX) {
536 evaluate(__begin, __end);
542 for (
int i = 0; i !=
N; ++i) {
544 if (
V(i,i) < PIVOT) {
548 h[i] = 1.0 / sqrt(
V(i,i));
554 for (
int i = 0; i !=
N; ++i) {
555 for (
int j = 0;
j != i; ++
j) {
556 V(
j,i) *= h[i] * h[
j];
561 for (
int i = 0; i !=
N; ++i) {
562 V(i,i) = 1.0 + lambda;
570 ERROR(
"JKatoomb<JGandalf>: " << error.
what() << endl);
575 for (
int i = 0; i !=
N; ++i) {
577 DEBUG(
"u[" << noshowpos << setw(3) << i <<
"] = " << showpos <<
FIXED(20,5) << value[i]);
581 for (
int j = 0;
j !=
N; ++
j) {
582 y +=
V(i,
j) *
Y[
j] * h[i] * h[
j];
587 DEBUG(
' ' <<
FIXED(20,10) << y << noshowpos << endl);
629 for (
T hit = __begin; hit != __end; ++hit) {
635 const double D = hit->getDistance(position);
636 const double Vi = velocity.getInverseVelocity(D, hit->getZ(), position.
getZ());
637 const double toa_s = value.emitter[hit->getEKey()].t1 + D * Vi;
639 const double u = (toa_s - hit->getValue()) / hit->sigma;
640 const double W = sqrt(hit->getWeight());
642 successor += (W*W) * estimator->getRho(u);
644 H_t H(1.0,
string.getGradient(parameters, hit->getPosition(), hit->getFloor()) * Vi);
646 H *= W * estimator->getPsi(u) / hit->sigma;
650 i.
t1 = value.getIndex(hit->getEKey(), &H_t::t1);
651 i.
tx = value.getIndex(hit->getString(), &H_t::tx);
652 i.
ty = value.getIndex(hit->getString(), &H_t::ty);
653 i.
tx2 = value.getIndex(hit->getString(), &H_t::tx2);
654 i.
ty2 = value.getIndex(hit->getString(), &H_t::ty2);
655 i.
vs = value.getIndex(hit->getString(), &H_t::vs);
661 if (hit->getFloor() != 0) {
Auxiliary base class for fit function of acoustic model.
fit times of emission of emitters and tilt angles of strings with second order correction and stretch...
JFit_t
Enumeration for fit algorithms.
JKatoomba(const JDetector &detector, const JSoundVelocity &velocity, const int option)
Constructor.
General purpose data regression method.
void setOption(const int)
Set fit option.
JString & mul(const double factor)
Scale string.
Wrapper class around STL string class.
Auxiliary base class for aritmetic operations of derived class types.
int getFloor() const
Get floor number.
static double LAMBDA_UP
multiplication factor control parameter
Interface for maximum likelihood estimator (M-estimator).
result_type operator()(const JFunction_t &fit, T __begin, T __end)
Get chi2.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Indices of H-equation in global model.
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
JEmitter & mul(const double factor)
Scale emitter.
then for HISTOGRAM in h0 h1
double operator()(const JModel &model, const JHit< JPDF_t > &hit) const
Fit function.
I_t()
Default constructor.
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.
JEKey getEKey() const
Get emitter hash key of this hit.
Template definition of linear fit.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
double getDistance(const JVector3D &pos) const
Get distance to point.
fit times of emission of emitters and tilt angles of strings
JKatoomba(const JDetector &detector, const JSoundVelocity &velocity, const int option)
Constructor.
Model for fit to acoustics data.
H_t(const JMODEL::JEmitter &emitter, const JMODEL::JString &string)
Constructor.
static double EPSILON
maximal distance to minimum
The template JSharedPointer class can be used to share a pointer to an object.
result_type operator()(T __begin, T __end)
Fit.
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
static double LAMBDA_MIN
minimal value control parameter
void evaluate(T __begin, T __end)
Evaluation of fit.
virtual double getInverseVelocity(const double D_m, const double z1, const double z2) const override
Get inverse velocity of sound.
static int debug
debug level
do set_variable OUTPUT_DIRECTORY $WORKDIR T
double operator()(T __begin, T __end)
Fit.
result_type operator()(const JModel &model, const JHit< JPDF_t > &hit) const
Fit function.
double getY() const
Get y position.
const JPosition3D & getPosition() const
Get position.
fit times of emission of emitters and tilt angles of strings with second order correction ...
JKatoomba_t(const JDetector &detector, const JSoundVelocity &velocity, const int option)
Constructor.
double getLengthSquared() const
Get length squared.
General purpose messaging.
Implementation for depth dependend velocity of sound.
static double LAMBDA_MAX
maximal value control parameter
static int MAXIMUM_ITERATIONS
maximal number of iterations
JKatoomba(const JDetector &detector, const JSoundVelocity &velocity, const int option)
Constructor.
double operator()(const JFunction_t &fit, T __begin, T __end)
Multi-dimensional fit.
JOption_t getOption()
Get fit option.
JACOUSTICS::JModel::string_type string
JKatoomba(const JDetector &detector, const JSoundVelocity &velocity, const int option)
Constructor.
JACOUSTICS::JModel::emitter_type emitter
int getString() const
Get string number.
virtual const char * what() const override
Get error message.
const JModel & operator()(T __begin, T __end) const
Get start values of string parameters.
static double LAMBDA_DOWN
multiplication factor control parameter
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++...
result_type operator()(const JModel &model, T __begin, T __end)
Fit.
H_t()
Default constructor.
static double PIVOT
minimal value diagonal element of matrix
double getToA(const JModel &model, const JHit< JPDF_t > &hit) const
Get estimated time-of-arrival for given hit.
double getX() const
Get x position.
H_t & mul(const double factor)
Scale H-equation.
Data structure for position in three dimensions.
const JDetector & detector
detector
Model for fit to acoutsics data.
fit only times of emission of emitters
JSoundVelocity velocity
sound velocity
do echo Generating $dir eval D
double getZ() const
Get z position.
Maximum likelihood estimator (M-estimators).
Template definition of fit function of acoustic model.
#define DEBUG(A)
Message macros.