Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JBallarat.hh
Go to the documentation of this file.
1 #ifndef __JCOMPASS__JBALLARAT__
2 #define __JCOMPASS__JBALLARAT__
3 
4 #include "JDetector/JDetector.hh"
7 
8 #include "JCompass/JEvt.hh"
10 
11 #include "JLang/JObjectIterator.hh"
12 #include "JLang/JException.hh"
13 #include "JLang/JComparator.hh"
14 
16 #include "JGeometry3D/JEigen3D.hh"
17 
18 #include "JTools/JElement.hh"
19 #include "JTools/JCollection.hh"
20 #include "JTools/JPolfit.hh"
21 #include "JTools/JHashMap.hh"
22 
23 
24 namespace JCOMPASS {}
25 namespace JPP { using namespace JCOMPASS; }
26 
27 namespace JCOMPASS {
28 
32 
33 
34  /**
35  * Dynamic orientation calibration.
36  *
37  * Note that the quaternion data of the internal detector are used to track the consecutive rotations.
38  */
39  struct JBallarat {
40 
41  enum {
42  NUMBER_OF_POINTS = 20, //!< number of points for interpolation
43  NUMBER_OF_DEGREES = 1 //!< number of degrees for interpolation
44  };
45 
50  typedef typename function_type::collection_type::container_type container_type;
51 
53 
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param detector detector
62  * \param Tmax_s applicability period [s]
63  */
65  const double Tmax_s) :
66  detector(detector),
67  Tmax_s(Tmax_s),
68  t0_s(std::numeric_limits<double>::lowest())
69  {
70  using namespace JPP;
71 
72  if (hasDetectorAddressMap(this->detector.getID())) {
73 
74  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
75 
76  for (JDetector::iterator module = this->detector.begin(); module != this->detector.end(); ++module) {
77  module->setQuaternion(getRotation(getModule(demo.get(module->getID())), *module));
78  }
79 
80  } else {
81 
82  THROW(JValueOutOfRange, "No detector address map for detector identier " << detector.getID());
83  }
84  }
85 
86 
87  /**
88  * Load calibration data.
89  *
90  * \param input detector calibration data
91  */
93  {
94  using namespace JPP;
95 
96  t0_s = std::numeric_limits<double>::lowest();
97 
98  while (input.hasNext()) {
99 
100  const JOrientation* orientation = input.next();
101 
102  static_cast<container_type&>(calibration[orientation->id]).push_back(element_type(orientation->t, getQuaternion(*orientation)));
103  }
104 
105  for (data_type::iterator i = calibration.begin(); i != calibration.end(); ++i) {
106  i->second.sort();
107  i->second.compile();
108  }
109  }
110 
111 
112  /**
113  * Check validity of calibration.
114  *
115  * \return true if valid; else false
116  */
117  bool is_valid() const
118  {
119  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
120  if (!calibration.has(module->getID())) {
121  return false;
122  }
123  }
124 
125  return true;
126  }
127 
128 
129  /**
130  * Get minimal abscissa.
131  *
132  * \return minimal abscissa
133  */
134  double getXmin() const
135  {
136  double xmin = std::numeric_limits<double>::max();
137 
138  for (const_iterator i = this->begin(); i != this->end(); ++i) {
139  if (!i->second.empty() && i->second.getXmin() < xmin) {
140  xmin = i->second.getXmin();
141  }
142  }
143 
144  return xmin;
145  }
146 
147 
148  /**
149  * Get maximal abscissa.
150  *
151  * \return maximal abscissa
152  */
153  double getXmax() const
154  {
155  double xmax = std::numeric_limits<double>::lowest();
156 
157  for (const_iterator i = this->begin(); i != this->end(); ++i) {
158  if (!i->second.empty() && i->second.getXmax() > xmax) {
159  xmax = i->second.getXmax();
160  }
161  }
162 
163  return xmax;
164  }
165 
166 
167  const_iterator begin() const { return calibration.begin(); } //!< begin of calibration data
168  const_iterator end() const { return calibration.end(); } //!< end of calibration data
169  const_reverse_iterator rbegin() const { return calibration.rbegin(); } //!< begin of reverse of calibration data
170  const_reverse_iterator rend() const { return calibration.rend(); } //!< begin of reverse of calibration data
171 
172 
173  /**
174  * Get detector calibrated at given time.
175  *
176  * \param t1_s time [s]
177  * \return detector
178  */
179  const JDetector& operator()(const double t1_s)
180  {
181  using namespace std;
182  using namespace JPP;
183 
184  if (!calibration.empty()) {
185 
186  if (fabs(t1_s - t0_s) > Tmax_s) {
187 
188  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
189 
190  if (calibration.has(module->getID())) {
191 
192  const function_type& f1 = calibration.get(module->getID());
193 
194  if (!f1.empty()) {
195 
196  if (t1_s >= f1.getXmin() && t1_s <= f1.getXmax()) {
197 
198  JQuaternion3D Q0 = module->getQuaternion();
199  JQuaternion3D Q1 = f1(t1_s);
200 
201  module->rotate(Q1 * Q0.conjugate());
202  module->setQuaternion(Q1);
203  }
204  }
205  }
206  }
207 
208  t0_s = t1_s;
209  }
210  }
211 
212  return detector;
213  }
214 
215 
216  protected:
219  double Tmax_s;
220 
221  private:
222  double t0_s;
223  };
224 }
225 
226 #endif
const_iterator end() const
end of calibration data
Definition: JBallarat.hh:168
Exceptions.
JTOOLS::JElement2D< double, JGEOMETRY3D::JQuaternion3D > element_type
Definition: JBallarat.hh:46
int id
module identifier
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...
void load(JObjectIterator< JCOMPASS::JOrientation > &input)
Load calibration data.
Definition: JBallarat.hh:92
container_type::const_reverse_iterator const_reverse_iterator
Definition: JHashMap.hh:86
data_type::const_iterator const_iterator
Definition: JBallarat.hh:54
JQuaternion3D getQuaternion(const JQuaternion &Q)
Get quaternion.
General purpose class for hash map of unique elements.
Detector data structure.
Definition: JDetector.hh:80
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
const JDetector & operator()(const double t1_s)
Get detector calibrated at given time.
Definition: JBallarat.hh:179
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
const_reverse_iterator rend() const
begin of reverse of calibration data
Definition: JBallarat.hh:170
Lookup table for PMT addresses in detector.
JDetector detector
Definition: JBallarat.hh:218
data_type::const_reverse_iterator const_reverse_iterator
Definition: JBallarat.hh:55
Interface of object iteration for a single data type.
function_type::collection_type::container_type container_type
Definition: JBallarat.hh:50
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
const JQuaternion3D & getQuaternion() const
Get quaternion.
data_type calibration
Definition: JBallarat.hh:217
virtual mapped_type & get(typename JClass< key_type >::argument_type key) override
Get mapped value.
Definition: JHashMap.hh:118
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
virtual const pointer_type & next()=0
Get next element.
Detector file.
Definition: JHead.hh:196
int getID() const
Get identifier.
Definition: JObjectID.hh:50
virtual bool hasNext()=0
Check availability of next element.
JBallarat(const JDetector &detector, const double Tmax_s)
Constructor.
Definition: JBallarat.hh:64
number of points for interpolation
Definition: JBallarat.hh:42
General purpose class for a collection of sorted elements.
Compass event fit.
double getXmin() const
Get minimal abscissa.
Definition: JBallarat.hh:134
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
bool is_valid() const
Check validity of calibration.
Definition: JBallarat.hh:117
Data structure for unit quaternion in three dimensions.
Dynamic orientation calibration.
Definition: JBallarat.hh:39
Template class for polynomial interpolation in 1D.
Definition: JPolfit.hh:144
JTOOLS::JPolfitFunction1D< NUMBER_OF_POINTS, NUMBER_OF_DEGREES, element_type, JTOOLS::JCollection > function_type
Definition: JBallarat.hh:49
2D Element.
Definition: JElement.hh:46
Orientation of module.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Compass event data types.
container_type::const_iterator const_iterator
Definition: JHashMap.hh:85
JTOOLS::JHashMap< int, function_type > data_type
Definition: JBallarat.hh:52
const_reverse_iterator rbegin() const
begin of reverse of calibration data
Definition: JBallarat.hh:169
const_iterator begin() const
begin of calibration data
Definition: JBallarat.hh:167
bool has(const T &value) const
Test whether given value is present.
number of degrees for interpolation
Definition: JBallarat.hh:43
double getXmax() const
Get maximal abscissa.
Definition: JBallarat.hh:153
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
JQuaternion3D & conjugate()
Conjugate quaternion.
container_type::iterator iterator
Definition: JHashMap.hh:87