#ifndef __JACOUSTICS__JNARRABRI__ #define __JACOUSTICS__JNARRABRI__ #include #include "JDetector/JDetector.hh" #include "JLang/JObjectIterator.hh" #include "Jeep/JContainer.hh" #include "JTools/JHashMap.hh" #include "JTools/JSpline.hh" #include "JTools/JPolfit.hh" #include "JTools/JElement.hh" #include "JTools/JCollection.hh" #include "JAcoustics/JModel.hh" #include "JAcoustics/JGeometry.hh" #include "JAcoustics/JEvt.hh" /** * \file * * Dynamic position calibration. * \author mdejong */ namespace JACOUSTICS {} namespace JPP { using namespace JACOUSTICS; } namespace JACOUSTICS { using JDETECTOR::JDetector; using JLANG::JObjectIterator; using JEEP::JContainer; /** * Dynamic position calibration. */ struct JNarrabri { enum { NUMBER_OF_POINTS = 7, //!< number of points for interpolation NUMBER_OF_DEGREES = 2 //!< number of degrees for interpolation }; typedef JTOOLS::JElement2D element_type; typedef JTOOLS::JPolfitFunction1D function_type; typedef JTOOLS::JHashMap data_type; typedef data_type::const_iterator const_iterator; typedef data_type::const_reverse_iterator const_reverse_iterator; /** * Constructor. * * \param detector detector * \param Tmax_s applicability period [s] */ JNarrabri(const JDetector& detector, const double Tmax_s) : detector(detector), geometry(detector), Tmax_s(Tmax_s), t0_s(std::numeric_limits::lowest()) {} /** * Load calibration data. * * \param input detector calibration data */ void load(JObjectIterator& input) { t0_s = std::numeric_limits::lowest(); while (input.hasNext()) { const JEvt* evt = input.next(); const double t1_s = 0.5 * (evt->UNIXTimeStart + evt->UNIXTimeStop); for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) { calibration[i->id][t1_s] = JMODEL::JString(i->tx, i->ty); } } for (data_type::iterator i = calibration.begin(); i != calibration.end(); ++i) { i->second.compile(); } } /** * Check validity of calibration. * * \return true if valid; else false */ bool is_valid() const { for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (!calibration.has(module->getString())) { return false; } } return true; } /** * Get minimal abscissa. * * \return minimal abscissa */ double getXmin() const { double xmin = std::numeric_limits::max(); for (const_iterator i = this->begin(); i != this->end(); ++i) { if (!i->second.empty() && i->second.getXmin() < xmin) { xmin = i->second.getXmin(); } } return xmin; } /** * Get maximal abscissa. * * \return maximal abscissa */ double getXmax() const { double xmax = std::numeric_limits::lowest(); for (const_iterator i = this->begin(); i != this->end(); ++i) { if (!i->second.empty() && i->second.getXmax() > xmax) { xmax = i->second.getXmax(); } } return xmax; } const_iterator begin() const { return calibration.begin(); } //!< begin of calibration data const_iterator end() const { return calibration.end(); } //!< end of calibration data const_reverse_iterator rbegin() const { return calibration.rbegin(); } //!< begin of reverse of calibration data const_reverse_iterator rend() const { return calibration.rend(); } //!< begin of reverse of calibration data /** * Get detector calibrated at given time. * * \param t1_s time [s] * \return detector */ const JDetector& operator()(const double t1_s) { using namespace std; using namespace JPP; if (!calibration.empty()) { if (fabs(t1_s - t0_s) > Tmax_s) { JHashMap buffer; for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) { if (!buffer.has(module->getString())) { if (calibration.has(module->getString())) { buffer[module->getString()] = calibration[module->getString()](t1_s); } } if (buffer.has(module->getString())) { module->set(geometry[module->getString()].getPosition(buffer[module->getString()], module->getFloor()) - getPiezoPosition()); } } t0_s = t1_s; } } return detector; } protected: data_type calibration; JDetector detector; JGeometry geometry; double Tmax_s; private: double t0_s; }; } #endif