Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JNarrabri.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JNARRABRI__
2 #define __JACOUSTICS__JNARRABRI__
3 
4 #include <limits>
5 
6 #include "JDetector/JDetector.hh"
7 
9 
10 #include "Jeep/JContainer.hh"
11 
12 #include "JTools/JHashMap.hh"
13 #include "JTools/JSpline.hh"
14 #include "JTools/JPolfit.hh"
15 #include "JTools/JElement.hh"
16 #include "JTools/JCollection.hh"
17 
18 #include "JAcoustics/JModel.hh"
19 #include "JAcoustics/JGeometry.hh"
20 #include "JAcoustics/JEvt.hh"
21 
22 
23 /**
24  * \file
25  *
26  * Dynamic position calibration.
27  * \author mdejong
28  */
29 namespace JACOUSTICS {}
30 namespace JPP { using namespace JACOUSTICS; }
31 
32 namespace JACOUSTICS {
33 
36  using JEEP::JContainer;
37 
38 
39  /**
40  * Dynamic position calibration.
41  */
42  struct JNarrabri {
43 
44  enum {
45  NUMBER_OF_POINTS = 7, //!< number of points for interpolation
46  NUMBER_OF_DEGREES = 2 //!< number of degrees for interpolation
47  };
48 
53 
55 
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param detector detector
64  * \param Tmax_s applicability period [s]
65  */
67  const double Tmax_s) :
68  detector(detector),
69  geometry(detector),
70  Tmax_s(Tmax_s),
71  t0_s(std::numeric_limits<double>::lowest())
72  {}
73 
74 
75  /**
76  * Load calibration data.
77  *
78  * \param input detector calibration data
79  */
81  {
82  t0_s = std::numeric_limits<double>::lowest();
83 
84  while (input.hasNext()) {
85 
86  const JEvt* evt = input.next();
87  const double t1_s = 0.5 * (evt->UNIXTimeStart + evt->UNIXTimeStop);
88 
89  for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
90  calibration[i->id][t1_s] = JMODEL::JString(i->tx, i->ty);
91  }
92  }
93 
94  for (data_type::iterator i = calibration.begin(); i != calibration.end(); ++i) {
95  i->second.compile();
96  }
97  }
98 
99 
100  /**
101  * Check validity of calibration.
102  *
103  * \return true if valid; else false
104  */
105  bool is_valid() const
106  {
107  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
108  if (!calibration.has(module->getString())) {
109  return false;
110  }
111  }
112 
113  return true;
114  }
115 
116 
117  /**
118  * Get minimal abscissa.
119  *
120  * \return minimal abscissa
121  */
122  double getXmin() const
123  {
124  double xmin = std::numeric_limits<double>::max();
125 
126  for (const_iterator i = this->begin(); i != this->end(); ++i) {
127  if (!i->second.empty() && i->second.getXmin() < xmin) {
128  xmin = i->second.getXmin();
129  }
130  }
131 
132  return xmin;
133  }
134 
135 
136  /**
137  * Get maximal abscissa.
138  *
139  * \return maximal abscissa
140  */
141  double getXmax() const
142  {
143  double xmax = std::numeric_limits<double>::lowest();
144 
145  for (const_iterator i = this->begin(); i != this->end(); ++i) {
146  if (!i->second.empty() && i->second.getXmax() > xmax) {
147  xmax = i->second.getXmax();
148  }
149  }
150 
151  return xmax;
152  }
153 
154 
155  const_iterator begin() const { return calibration.begin(); } //!< begin of calibration data
156  const_iterator end() const { return calibration.end(); } //!< end of calibration data
157  const_reverse_iterator rbegin() const { return calibration.rbegin(); } //!< begin of reverse of calibration data
158  const_reverse_iterator rend() const { return calibration.rend(); } //!< begin of reverse of calibration data
159 
160 
161  /**
162  * Get detector calibrated at given time.
163  *
164  * \param t1_s time [s]
165  * \return detector
166  */
167  const JDetector& operator()(const double t1_s)
168  {
169  using namespace std;
170  using namespace JPP;
171 
172  if (!calibration.empty()) {
173 
174  if (fabs(t1_s - t0_s) > Tmax_s) {
175 
177 
178  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
179 
180  if (!buffer.has(module->getString())) {
181  if (calibration.has(module->getString())) {
182  buffer[module->getString()] = calibration[module->getString()](t1_s);
183  }
184  }
185 
186  if (buffer.has(module->getString())) {
187  module->set(geometry[module->getString()].getPosition(buffer[module->getString()], module->getFloor()) - getPiezoPosition());
188  }
189  }
190 
191  t0_s = t1_s;
192  }
193  }
194 
195  return detector;
196  }
197 
198 
199  protected:
203  double Tmax_s;
204 
205  private:
206  double t0_s;
207  };
208 }
209 
210 #endif
const double xmax
Definition: JQuadrature.cc:24
General purpose class for collection of elements, see: &lt;a href=&quot;JTools.PDF&quot;;&gt;Collection of elements...
Definition: JCollection.hh:73
The elements in a collection are sorted according to their abscissa values and a given distance opera...
const_reverse_iterator rend() const
begin of reverse of calibration data
Definition: JNarrabri.hh:158
container_type::const_reverse_iterator const_reverse_iterator
Definition: JHashMap.hh:87
General purpose class for hash map of unique elements.
Detector data structure.
Definition: JDetector.hh:89
Acoustic geometries.
const JDetector & operator()(const double t1_s)
Get detector calibrated at given time.
Definition: JNarrabri.hh:167
Interface of object iteration for a single data type.
double getXmin() const
Get minimal abscissa.
Definition: JNarrabri.hh:122
Data structure for detector geometry and calibration.
JTOOLS::JHashMap< int, function_type > data_type
Definition: JNarrabri.hh:54
double UNIXTimeStop
stop time
virtual const pointer_type & next()=0
Get next element.
Detector file.
Definition: JHead.hh:226
Acoustic event fit.
const_iterator end() const
end of calibration data
Definition: JNarrabri.hh:156
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
double getXmax() const
Get maximal abscissa.
Definition: JNarrabri.hh:141
virtual bool hasNext()=0
Check availability of next element.
number of degrees for interpolation
Definition: JNarrabri.hh:46
General purpose class for a collection of sorted elements.
JTOOLS::JElement2D< double, JMODEL::JString > element_type
Definition: JNarrabri.hh:49
const_iterator begin() const
begin of calibration data
Definition: JNarrabri.hh:155
data_type::const_iterator const_iterator
Definition: JNarrabri.hh:56
void set(const JHashMap &source, const mapped_type &value)
Set values corresponding to keys in given source.
Definition: JHashMap.hh:130
JNarrabri(const JDetector &detector, const double Tmax_s)
Constructor.
Definition: JNarrabri.hh:66
const double xmin
Definition: JQuadrature.cc:23
JTOOLS::JPolfitFunction1D< NUMBER_OF_POINTS, NUMBER_OF_DEGREES, element_type, JTOOLS::JCollection > function_type
Definition: JNarrabri.hh:52
double UNIXTimeStart
start time
JPosition3D getPiezoPosition()
Get relative position of piezo in optical module.
bool is_valid() const
Check validity of calibration.
Definition: JNarrabri.hh:105
Template class for polynomial interpolation in 1D.
Definition: JPolfit.hh:149
Dynamic position calibration.
Definition: JNarrabri.hh:42
number of points for interpolation
Definition: JNarrabri.hh:45
2D Element.
Definition: JElement.hh:46
container_type::const_iterator const_iterator
Definition: JHashMap.hh:86
Model for fit to acoutsics data.
Acoustic event fit.
bool has(const T &value) const
Test whether given value is present.
const_reverse_iterator rbegin() const
begin of reverse of calibration data
Definition: JNarrabri.hh:157
data_type::const_reverse_iterator const_reverse_iterator
Definition: JNarrabri.hh:57
void load(JObjectIterator< JEvt > &input)
Load calibration data.
Definition: JNarrabri.hh:80
Container I/O.
container_type::iterator iterator
Definition: JHashMap.hh:88