Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
software/JCompass/JBallarat.cc File Reference

Auxiliary program to process AHRS data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <vector>
#include "JDB/JSupport.hh"
#include "JDB/JAHRS.hh"
#include "JDB/JAHRSCalibration_t.hh"
#include "JDB/JAHRSToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMeta.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JCompass.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JGeometry3D/JEigen3D.hh"
#include "JTools/JHashMap.hh"
#include "JLang/JVectorize.hh"
#include "JLang/JComparator.hh"
#include "JMath/JLegendre.hh"
#include "JCompass/JEvt.hh"
#include "JCompass/JEvtToolkit.hh"
#include "JCompass/JSupport.hh"
#include "JCompass/JNOAA.hh"
#include "JCompass/JPolicy.hh"
#include "JCompass/JCompassSupportkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to process AHRS data.

The AHRS calibration as well as the quaternion calibration are applied to the data.
Possible outliers are removed according the specified maximal angle (option -S <angle_deg>.
For this, interpolations of the data are made based on Legendre polynomials with the number of points and the number of degrees set to NUMBER_OF_POINTS and NUMBER_OF_DEGREES, respectively.

Author
mdejong

Definition in file software/JCompass/JBallarat.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file software/JCompass/JBallarat.cc.

62 {
63  using namespace std;
64  using namespace JPP;
65 
66  JMultipleFileScanner_t inputFile;
67  counter_type numberOfEvents;
69  string detectorFile;
70  string ahrsFile;
71  double angle_deg;
72  int debug;
73 
74  try {
75 
76  JParser<> zap("Auxiliary program to process AHRS data.");
77 
78  zap['f'] = make_field(inputFile, "output of JConvertDB -q ahrs");
79  zap['n'] = make_field(numberOfEvents) = JLimit::max();
80  zap['a'] = make_field(detectorFile);
81  zap['c'] = make_field(ahrsFile, "output of JAHRSCalibration");
82  zap['o'] = make_field(outputFile, "ROOT formatted orientations file");
83  zap['S'] = make_field(angle_deg) = 0.0;
84  zap['d'] = make_field(debug) = 1;
85 
86  zap(argc, argv);
87  }
88  catch(const exception &error) {
89  FATAL(error.what() << endl);
90  }
91 
92 
94 
95  try {
96  load(detectorFile, detector);
97  }
98  catch(const JException& error) {
99  FATAL(error);
100  }
101 
102  const JModuleRouter router(detector);
103  const JNOAAFunction1D_t& getMagneticDeclination = (isARCADetector(detector) ? static_cast<const JNOAAFunction1D_t&>(getARCAMagneticDeclination) :
105  static_cast<const JNOAAFunction1D_t&>(getZEROMagneticDeclination));
106  const double meridian = (isARCADetector(detector) ? ARCA_MERIDIAN_CONVERGENCE_ANGLE_RAD :
108  0.0);
109 
110  NOTICE("Magnetic declination " << getMagneticDeclination << endl);
111  NOTICE("Meridian angle [rad] " << FIXED(5,3) << meridian << endl);
112 
113  const JAHRSCalibration_t calibration(ahrsFile.c_str());
114  const JAHRSValidity is_valid;
115 
116 
117  typedef pair<double, JQuaternion3D> element_type;
118  typedef vector<element_type> buffer_type;
119  typedef JHashMap<int, buffer_type> map_type; // container for temporary storage of data
120 
121  JLegendre<JQuaternion3D, NUMBER_OF_DEGREES> f1; // interpolator for outlier removal
122 
123 
124  outputFile.open();
125 
126  outputFile.put(JMeta(argc, argv));
127 
128  counter_type counter = 0;
129 
130  for (JMultipleFileScanner_t::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
131 
132  STATUS("processing file " << *file_name << "... " << flush);
133 
134  // collect data
135 
136  map_type data;
137 
138  for (JMultipleFileScanner<JAHRS> in(*file_name); in.hasNext() && counter != numberOfEvents; ++counter) {
139 
140  const JAHRS* parameters = in.next();
141  const int id = parameters->DOMID;
142 
143  if (is_valid(*parameters) && calibration.has(id) && router.hasModule(id)) {
144 
145  const JModule& module = router.getModule(id);
146 
147  if (module.getFloor() != 0) {
148 
149  JCompass compass(*parameters, calibration.get(id));
150 
151  compass.correct(getMagneticDeclination(parameters->UNIXTIME * 1.0e-3), meridian);
152 
153  const JQuaternion3D Q = compass.getQuaternion();
154 
155  data[id].push_back(element_type(parameters->UNIXTIME * 1.0e-3, Q));
156  }
157  }
158  }
159 
160  // remove outliers
161 
162  if (angle_deg > 0.0) {
163 
164  for (map_type::iterator module = data.begin(); module != data.end(); ++module) {
165 
166  if (!module->second.empty()) {
167 
168  sort(module->second.begin(), module->second.end(), make_comparator(&element_type::first));
169 
170  buffer_type::iterator out = module->second.begin(); // output
171  buffer_type::const_iterator in = module->second.begin(); // input
172  buffer_type::const_iterator p = module->second.begin(); // begin interpolation data
173  buffer_type::const_iterator q = module->second.begin(); // end interpolation data
174 
175  for (int i = 0; i != NUMBER_OF_POINTS && q != module->second.end(); ++i, ++q) {}
176 
177  for (int i = 0; i != NUMBER_OF_POINTS/2 && in != q; ++i, ++in) {
178 
179  f1.set(p, in, q);
180 
181  if (getAngle(in->second, f1(in->first)) <= angle_deg) {
182  *out = *in;
183  ++out;
184  }
185  }
186 
187  for (++p; q++ != module->second.end(); ++p, ++in) {
188 
189  f1.set(p, in, q);
190 
191  if (getAngle(in->second, f1(in->first)) <= angle_deg) {
192  *out = *in;
193  ++out;
194  }
195  }
196 
197  for ( ; in != module->second.end(); ++in) {
198 
199  f1.set(p, in, q);
200 
201  if (getAngle(in->second, f1(in->first)) <= angle_deg) {
202  *out = *in;
203  ++out;
204  }
205  }
206 
207  module->second.erase(out, module->second.end()); // remove leftovers
208  }
209  }
210  }
211 
212  // apply policy for missing modules and write output
213 
214  const array_type<map_type::key_type>& buffer = make_array(data.begin(), data.end(), &map_type::value_type::first);
215 
216  const JPolicy policy(router, buffer.begin(), buffer.end());
217 
218  for (JPolicy::const_iterator module = policy.begin(); module != policy.end(); ++module) {
219  for (JPolicy::mapped_type::const_iterator in = module->second.begin(); in != module->second.end(); ++in) {
220  for (map_type::mapped_type::const_iterator i = data[*in].begin(); i != data[*in].end(); ++i) {
221  outputFile.put(JOrientation(module->first, i->first, getQuaternion(i->second)));
222  }
223  }
224  }
225 
226  STATUS(endl);
227  }
228 
229  JMultipleFileScanner<JMeta> io(inputFile);
230 
231  io >> outputFile;
232 
233  outputFile.close();
234 }
bool isORCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with that of ORCA.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
double getAngle(const JQuaternion3D &first, const JQuaternion3D &second)
Get space angle between quanternions.
General exception.
Definition: JException.hh:23
static JARCAMagneticDeclination getARCAMagneticDeclination
Function object for magnetic declination at ARCA site.
Definition: JNOAA.hh:730
void correct(const double declination, const double meridian)
Correct compass for magnetic declination and meridian convergence angle.
Definition: JCompass.hh:274
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:57
bool isARCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with tat of ARCA.
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
JQuaternion3D getQuaternion(const JQuaternion &Q)
Get quaternion.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
static JZEROMagneticDeclination getZEROMagneticDeclination
Function object for zero magnetic declination.
Definition: JNOAA.hh:732
Router for direct addressing of module data in detector data structure.
*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
Definition: diff-Tuna.sh:38
Long64_t counter_type
Type definition for counter.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
static const double ARCA_MERIDIAN_CONVERGENCE_ANGLE_RAD
ARCA meridian convergence angle [rad].
static JORCAMagneticDeclination getORCAMagneticDeclination
Function object for magnetic declination at ORCA site.
Definition: JNOAA.hh:731
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const JQuaternion3D & getQuaternion() const
Get quaternion.
Detector file.
Definition: JHead.hh:196
Auxiliary base class for interpolation of magnetic declination data obtained from website of NOAA...
Definition: JNOAA.hh:25
Auxiliary class to define policy for invalid modules.
Definition: JPolicy.hh:31
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:37
Template definition for function evaluation of Legendre polynome.
Definition: JLegendre.hh:213
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for compass in three dimensions.
Definition: JCompass.hh:49
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
Auxiliary base class for list of file names.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Auxiliary class to map module identifier to AHRS calibration.
Orientation of module.
do set_variable DETECTOR_TXT $WORKDIR detector
static const double ORCA_MERIDIAN_CONVERGENCE_ANGLE_RAD
ORCA meridian convergence angle [rad].
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:444
long long int UNIXTIME
[ms]
Definition: JAHRS.hh:26
Auxiliary data structure for return type of make methods.
Definition: JVectorize.hh:25
Auxiliary data structure to check validity of AHRS data.
Definition: JAHRSToolkit.hh:20