1 #ifndef __JACOUSTICS__JKATOOMBA_T__ 
    2 #define __JACOUSTICS__JKATOOMBA_T__ 
    8 #include "TMatrixTSym.h" 
    9 #include "TDecompSVD.h" 
   38 namespace JACOUSTICS {}
 
   39 namespace JPP { 
using namespace JACOUSTICS; }
 
   41 namespace JACOUSTICS {
 
   65     for (
T i = __begin; 
i != __end; ++
i) {
 
  145   template<
template<
class T> 
class JMinimiser_t = 
JType>
 
  161     static const struct compare {
 
  179             return first.
getQ()   > second.
getQ();
 
  219       const double Vi    = velocity.getInverseVelocity(D, hit.
getZ(), position.
getZ());
 
  239       const double Vi    = velocity.getInverseVelocity(D, hit.
getZ(), position.
getZ());
 
  276         JMODEL::JEmission(emission),
 
  287       H_t& 
mul(
const double factor)
 
  361       const double toa_s = this->getToA(model, hit);
 
  364       return estimator->getRho(u) * hit.
getWeight();
 
  378       this->value.setOption(this->option);
 
  397       return (*
this)(__begin, __end);
 
  425       ResizeTo(size, size);
 
  444       unique_lock<mutex> lock(
mtx);
 
  450       static_cast<TMatrixD&
>(*this) = svd.Invert(status);
 
  458     template<
class JVectorND_t>
 
  464       unique_lock<mutex> lock(
mtx);
 
  468       TVectorD b(u.size());
 
  470       for (
size_t i = 0; 
i != u.size(); ++
i) {
 
  476       for (
size_t i = 0; 
i != u.size(); ++
i) {
 
  524       switch (MATRIX_INVERSION) {
 
  527         return this->evaluate(__begin, __end, svd);
 
  530         return this->evaluate(__begin, __end, ldu);
 
  555     template<
class T, 
class JMatrixNS_t>
 
  560       using namespace JGEOMETRY;
 
  562       value = 
JModel(__begin, __end);                 
 
  572       const size_t N = value.getN();
 
  580       for (
T hit = __begin; hit != __end; ++hit) {
 
  582         const JString&    
string   = geometry[hit->getString()];
 
  584         const double      Vi       = velocity.getInverseVelocity(hit->getDistance(position), hit->getZ(), position.
getZ());
 
  586         const double      h1 = 
string.getHeight(hit->getFloor());
 
  587         const JPosition3D p1 = 
string.getPosition()  -  hit->getPosition();
 
  589         const double      y  = hit->getValue()  -  Vi*ds;
 
  590         const double      W  = sqrt(hit->getWeight());
 
  593         H.tx  =  W * Vi * p1.
getX() * h1 / ds;
 
  594         H.ty  =  W * Vi * p1.
getY() * h1 / ds;
 
  596         i.t1  =  value.getIndex(hit->getEKey(),   &H_t::t1);
 
  597         i.tx  =  value.getIndex(hit->getString(), &H_t::tx);
 
  598         i.ty  =  value.getIndex(hit->getString(), &H_t::ty);
 
  600         V(
i.t1, 
i.t1) += 
H.t1 * 
H.t1;
 
  602         Y[
i.t1] += W * 
H.t1 * 
y;
 
  604         if (hit->getFloor() != 0) {
 
  608             V(
i.t1, 
i.tx) += 
H.t1 * 
H.tx;  
V(
i.t1, 
i.ty) += 
H.t1 * 
H.ty;
 
  609             V(
i.tx, 
i.t1) += 
H.tx * 
H.t1;  
V(
i.ty, 
i.t1) += 
H.ty * 
H.t1;
 
  611             V(
i.tx, 
i.tx) += 
H.tx * 
H.tx;  
V(
i.tx, 
i.ty) += 
H.tx * 
H.ty;
 
  612             V(
i.ty, 
i.tx) += 
H.ty * 
H.tx;  
V(
i.ty, 
i.ty) += 
H.ty * 
H.ty;
 
  614             Y[
i.tx] += W * 
H.tx * 
y;
 
  615             Y[
i.ty] += W * 
H.ty * 
y;
 
  624       for (
size_t row = 0; row != 
N; ++row) {
 
  625         value[row] += 
Y[row];
 
  668       const double toa_s = this->getToA(model, hit);
 
  671       return estimator->getRho(u);
 
  691         switch (this->option) {
 
  771       value.setOption(this->option);
 
  773       const int N = value.getN();
 
  781       for (
T hit = __begin; hit != __end; ++hit) {
 
  782         data[hit->getLocation()][hit->getEmitter()].push_back(*hit);
 
  787       result_type precessor = numeric_limits<double>::max();
 
  789       for (numberOfIterations = 0; numberOfIterations != MAXIMUM_ITERATIONS; ++numberOfIterations) {
 
  791         DEBUG(
"step:     " << numberOfIterations << endl);
 
  795         DEBUG(
"lambda:   " << 
FIXED(12,5) << lambda    << endl);
 
  796         DEBUG(
"chi2:     " << 
FIXED(12,5) << successor << endl);
 
  798         if (successor < precessor) {
 
  800           if (numberOfIterations != 0) {
 
  802             if (fabs(precessor - successor) < EPSILON*fabs(precessor)) {
 
  806             if (lambda > LAMBDA_MIN) {
 
  807               lambda /= LAMBDA_DOWN;
 
  811           precessor = successor;
 
  819           if (lambda > LAMBDA_MAX) {
 
  828         for (
int i = 0; 
i != 
N; ++
i) {
 
  830           if (
V(
i,
i) < PIVOT) {
 
  834           h[
i] = 1.0 / sqrt(
V(
i,
i));
 
  839         for (
int i = 0; 
i != 
N; ++
i) {
 
  840           for (
int j = 0; 
j != 
i; ++
j) {
 
  841             V(
j,
i) *= h[
i] * h[
j];
 
  846         for (
int i = 0; 
i != 
N; ++
i) {
 
  847           V(
i,
i) = 1.0 + lambda;
 
  853         for (
int col = 0; col != 
N; ++col) {
 
  860         catch (
const exception& error) {
 
  862           ERROR(
"JGandalf: " << error.what() << endl << 
V << endl);
 
  869         for (
int row = 0; row != 
N; ++row) {
 
  871           DEBUG(
"u[" << noshowpos << setw(3) << row << 
"] = " << showpos << 
FIXED(20,5) << value[row]);
 
  873           value[row] -= h[row] * 
Y[row];
 
  875           DEBUG(
" -> " << 
FIXED(20,10) << value[row] << noshowpos << endl);
 
  912       for (data_type::const_iterator p = data.begin(); p != data.end(); ++p) {
 
  918         for (data_type::mapped_type::const_iterator emitter = p->second.begin(); emitter != p->second.end(); ++emitter) {
 
  920           const double D  = emitter->first.getDistance(position);
 
  921           const double Vi = velocity.getInverseVelocity(D, emitter->first.getZ(), position.
getZ());
 
  923           const H_t    H0(1.0, 
string.getGradient(parameters, emitter->first.getPosition(), p->first.getFloor()) * Vi);
 
  925           for (data_type::mapped_type::mapped_type::const_iterator hit = emitter->second.begin(); hit != emitter->second.end(); ++hit) {
 
  927             const double toa_s = value.emission[hit->getEKey()].t1  +  D * Vi;
 
  929             const double u  = (toa_s - hit->getValue()) / hit->getSigma();
 
  930             const double W  = sqrt(hit->getWeight());
 
  932             successor += (W*W) * estimator->getRho(u);
 
  934             const H_t    
H  = H0 * (W * estimator->getPsi(u) / hit->getSigma());
 
  938             i.t1  =  value.getIndex(hit->getEKey(),   &H_t::t1);
 
  939             i.tx  =  value.getIndex(hit->getString(), &H_t::tx);
 
  940             i.ty  =  value.getIndex(hit->getString(), &H_t::ty);
 
  941             i.tx2 =  value.getIndex(hit->getString(), &H_t::tx2);
 
  942             i.ty2 =  value.getIndex(hit->getString(), &H_t::ty2);
 
  943             i.vs  =  value.getIndex(hit->getString(), &
H_t::vs);
 
  945             V(i.t1, i.t1) += H.t1 * H.t1;
 
  949             if (hit->getFloor() != 0) {
 
  951               switch (this->option) {
 
  954                 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;
 
  956                 V(i.vs,  i.t1)   = 
V(i.t1,  i.vs);
 
  957                 V(i.vs,  i.tx)   = 
V(i.tx,  i.vs);
 
  958                 V(i.vs,  i.ty)   = 
V(i.ty,  i.vs);
 
  959                 V(i.vs,  i.tx2)  = 
V(i.tx2, i.vs);
 
  960                 V(i.vs,  i.ty2)  = 
V(i.ty2, i.vs);
 
  962                 V(i.vs,  i.vs)  += H.vs  * H.vs;
 
  967                 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;
 
  969                 V(i.tx2, i.t1)   = 
V(i.t1,  i.tx2);
 
  970                 V(i.tx2, i.tx)   = 
V(i.tx,  i.tx2);
 
  971                 V(i.tx2, i.ty)   = 
V(i.ty,  i.tx2);
 
  973                 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;
 
  975                 V(i.ty2, i.t1)   = 
V(i.t1,  i.ty2);
 
  976                 V(i.ty2, i.tx)   = 
V(i.tx,  i.ty2);
 
  977                 V(i.ty2, i.ty)   = 
V(i.ty,  i.ty2);
 
  979                 V(i.tx2, i.tx2) += H.tx2 * H.tx2;    
V(i.tx2, i.ty2) += H.tx2 * H.ty2;
 
  980                 V(i.ty2, i.tx2)  = 
V(i.tx2, i.ty2);  
V(i.ty2, i.ty2) += H.ty2 * H.ty2;
 
  982                 Y[i.tx2] += W * H.tx2;
 
  983                 Y[i.ty2] += W * H.ty2;
 
  986                 V(i.t1,  i.tx)  += H.t1  * H.tx;   
V(i.t1,  i.ty)  += H.t1  * H.ty;
 
  987                 V(i.tx,  i.t1)   = 
V(i.t1, i.tx);  
V(i.ty,  i.t1)   = 
V(i.t1, i.ty);
 
  989                 V(i.tx,  i.tx)  += H.tx  * H.tx;   
V(i.tx,  i.ty)  += H.tx  * H.ty;
 
  990                 V(i.ty,  i.tx)   = 
V(i.tx, i.ty);  
V(i.ty,  i.ty)  += H.ty  * H.ty;
 
I_t()
Default constructor. 
 
General purpose data regression method. 
 
JString & mul(const double factor)
Scale string. 
 
void solve(JVectorND_t &u)
Get solution of equation A x = b. 
 
Wrapper class around STL string class. 
 
void resize(const size_t size)
Resize matrix. 
 
Auxiliary base class for aritmetic operations of derived class types. 
 
JModel & evaluate(T __begin, T __end, JMatrixNS_t &V) const 
Get start values of string parameters. 
 
double getQ() const 
Get quality. 
 
double getWeight(T __begin, T __end)
Get total weight of data points. 
 
int getFloor() const 
Get floor number. 
 
Template definition of linear fit. 
 
static double LAMBDA_UP
multiplication factor control parameter 
 
Interface for maximum likelihood estimator (M-estimator). 
 
double getWeight() const 
Get weight. 
 
const JGeometry & geometry
detector geometry 
 
bool operator()(const JTransmission &first, const JTransmission &second) const 
Sort transmissions in following order. 
 
static std::mutex mtx
TDecompSVD. 
 
fit times of emission of emitters and tilt angles of strings with second order correction ...
 
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message. 
 
static const double H
Planck constant [eV s]. 
 
result_type operator()(const JFunction_t &fit, T __begin, T __end)
Get chi2. 
 
*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
 
static constexpr double TOLERANCE
Tolerance for SVD. 
 
H_t & mul(const double factor)
Scale H-equation. 
 
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. 
 
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. 
 
H_t()
Default constructor. 
 
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
 
double getDistance(const JVector3D &pos) const 
Get distance to point. 
 
JQuantile()
Default constructor. 
 
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
 
Place holder for custom implementation. 
 
Model for fit to acoustics data. 
 
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor. 
 
JMatrix_t
Algorithm for matrix inversion. 
 
static double EPSILON
maximal distance to minimum 
 
double operator()(const JModel &model, const JHit &hit) const 
Fit function. 
 
result_type operator()(T __begin, T __end)
Fit. 
 
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor. 
 
fit times of emission of emitters and tilt angles of strings 
 
static double LAMBDA_MIN
minimal value control parameter 
 
long double getMean(const double value) const 
Get mean value. 
 
static int debug
debug level 
 
do set_variable OUTPUT_DIRECTORY $WORKDIR T
 
double operator()(T __begin, T __end)
Fit. 
 
result_type operator()(T __begin, T __end)
Fit. 
 
JACOUSTICS::JModel::emission_type emission
 
fit only times of emission of emitters 
 
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor. 
 
double getY() const 
Get y position. 
 
std::map< JLocation, std::map< JEmitter, std::vector< JHit > > > data_type
Type definition internal data structure. 
 
const JPosition3D & getPosition() const 
Get position. 
 
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 
 
static JMatrix_t MATRIX_INVERSION
Matrix inversion. 
 
void invert()
Invert matrix according SVD decomposition. 
 
JEmission & mul(const double factor)
Scale emission. 
 
double operator()(const JFunction_t &fit, T __begin, T __end)
Multi-dimensional fit. 
 
Auxiliary data structure for compatibility of symmetric matrix. 
 
double getToE(const JModel &model, const JHit &hit) const 
Get estimated time-of-emission for given hit. 
 
JACOUSTICS::JModel::string_type string
 
JSoundVelocity velocity
sound velocity 
 
JModel & operator()(T __begin, T __end) const 
Get start values of string parameters. 
 
std::shared_ptr< JMEstimator > estimator_type
 
H_t(const JMODEL::JEmission &emission, const JMODEL::JString &string)
Constructor. 
 
int getString() const 
Get string number. 
 
Auxiliary data structure for average. 
 
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
 
static double LAMBDA_DOWN
multiplication factor control parameter 
 
Exception for division by zero. 
 
result_type operator()(const JModel &model, const JHit &hit) const 
Fit function. 
 
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. 
 
double getToA() const 
Get calibrated time of arrival. 
 
void put(const double x)
Put value. 
 
double getToA(const JModel &model, const JHit &hit) const 
Get estimated time-of-arrival for given hit. 
 
static double PIVOT
minimal value diagonal element of matrix 
 
int getID() const 
Get identifier. 
 
double getX() const 
Get x position. 
 
fit times of emission of emitters and tilt angles of strings with second order correction and stretch...
 
Data structure for position in three dimensions. 
 
Exception for accessing a value in a collection that is outside of its range. 
 
long double getMean() const 
Get mean value. 
 
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor. 
 
Model for fit to acoutsics data. 
 
estimator_type estimator
M-Estimator function. 
 
void evaluate(const data_type &data)
Evaluation of fit. 
 
void reset()
Set matrix to the null matrix. 
 
do echo Generating $dir eval D
 
double getZ() const 
Get z position. 
 
JKatoomba(const JGeometry &geometry, const JSoundVelocity &velocity, const int option)
Constructor. 
 
Maximum likelihood estimator (M-estimators). 
 
Template definition of fit function of acoustic model. 
 
#define DEBUG(A)
Message macros. 
 
double getSigma() const 
Get resolution of time-of-arrival.