Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
examples/JDB/JCompass.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <vector>
4#include <map>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TGraph.h"
9
10#include "JDB/JAHRS.hh"
12#include "JDB/JSupport.hh"
13#include "JDB/JAHRSToolkit.hh"
14
15#include "JGeometry3D/JEigen3D.hh" //JAverage
16
17#include "JROOT/JGraph.hh"
18
23#include "JDetector/JCompass.hh"
24
27
28#include "JLang/JComparator.hh"
30
31#include "Jeep/JPrint.hh"
32#include "Jeep/JParser.hh"
33#include "Jeep/JMessage.hh"
34
35
36/**
37 * \file
38 *
39 * Example program to monitor AHRS data of the first floor and check offsets vs detector file
40 * \author mdejong, vkulikovskiy
41 */
42int main(int argc, char **argv)
43{
44 using namespace std;
45 using namespace JPP;
46
48 JLimit_t& numberOfEvents = inputFile.getLimit();
49 string outputFile;
50 string detectorFile;
51 double Tmax_s;
52 string ahrsFile;
53 int debug;
55
56 try {
57
58 JParser<> zap("Example program to monitor AHRS data.");
59
60 zap['f'] = make_field(inputFile);
61 zap['n'] = make_field(numberOfEvents) = JLimit::max();
62 zap['o'] = make_field(outputFile) = "ahrs.root";
64 zap['T'] = make_field(Tmax_s) = 600.0; // [s]
65 zap['R'] = make_field(frange, "floor range") = JRange<int>(1,1);
66 zap['c'] = make_field(ahrsFile, "output of JAHRSCalibration");
67 zap['d'] = make_field(debug) = 2;
68
69
70 zap(argc, argv);
71 }
72 catch(const exception &error) {
73 FATAL(error.what() << endl);
74 }
75
77
78 try {
80 }
81 catch(const JException& error) {
82 FATAL(error);
83 }
84
85 const JModuleRouter router(detector);
86
89
90 typedef vector<JAHRS> buffer_type; // data type
91 typedef map<JObjectID, buffer_type> map_type; // DOM -> data
92
93 map_type data;
94
95 for (int counter = 0; inputFile.hasNext(); ++counter) {
96
97 STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
98
99 const JAHRS* parameters = inputFile.next();
100
101 if (is_valid(*parameters) && router.hasModule(parameters->DOMID) && calibration.has(parameters->DOMID)) {
102
103 const JLocation location = router.getModule(parameters->DOMID);
104
105 if (frange(location.getFloor())) {
106 data[parameters->DOMID].push_back(*parameters);
107 }
108 }
109 }
110
113 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
114 if (frange(module->getFloor())) {
115 JModule buffer = demo.getModule(module->getID(), module->getLocation());
116 const JQuaternion3D Q = getRotation(buffer, *module);
118 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
119 DOM_heading_map[module->getID()] = phi;
120 cout << "Heading from detector file: " << module->getID() << " " << module->getString() << " " << module->getFloor() << " " << phi/M_PI*180. << " [deg]" << endl;
121 }
122 }
123
124 STATUS(endl);
125
126
131
132 JGraph_t PD_all;
133
134 for (map_type::iterator module = data.begin(); module != data.end(); ++module) {
135
136 if (!module->second.empty()) {
137 const JLocation location = router.getModule(module->first);
138
139 sort(module->second.begin(), module->second.end(), make_comparator(&JAHRS::UNIXTIME));
140
141 for (buffer_type::const_iterator p = module->second.begin(); p != module->second.end(); ) {
142
143 set<int> buffer;
144
145 buffer_type::const_iterator q = p;
147
148 for ( ; q != module->second.end() && q->UNIXTIME - p->UNIXTIME <= Tmax_s * 1.0e3; ++q) {
149 Q.put(JCompass(*q, calibration.get(q->DOMID)).getQuaternion());
150 }
151
152 JDirection3D u(0,0,1);
153 JDirection3D x(1,0,0);
155
156 u.rotate(Q);
157 x.rotate(Q);
158 d.rotate_back(Q);
159
160 const double t1 = p->UNIXTIME * 1.0e-3 + 0.5*Tmax_s;
161
162 ZO[module->first].put(t1, atan2(u.getDY(), u.getDX()));
163 ZA[module->first].put(t1, sqrt(u.getDX()*u.getDX() + u.getDY()* u.getDY()));
164 PD[module->first].put(t1, atan2(d.getDY(), d.getDX()));
165 PD_all.put(location.getString(), atan2(d.getDY(), d.getDX()));
166 XO[module->first].put(t1, atan2(x.getDY(), x.getDX()));
167
168 p = q;
169 }
170 }
171 }
172
173
174 TFile out(outputFile.c_str(), "recreate");
175
176 for (map<JObjectID, JGraph_t>::const_iterator i = ZO.begin(); i != ZO.end(); ++i) {
177 const JLocation location = router.getModule(i->first);
178 out << JGraph(i->second, MAKE_CSTRING("G[" << location.getString() << ","<< location.getFloor() << "].orientation"));
179 }
180
181 for (map<JObjectID, JGraph_t>::const_iterator i = ZA.begin(); i != ZA.end(); ++i) {
182 const JLocation location = router.getModule(i->first);
183 out << JGraph(i->second, MAKE_CSTRING("G[" << location.getString() << ","<< location.getFloor() << "].amplitude"));
184 }
185
186 for (map<JObjectID, JGraph_t>::const_iterator i = PD.begin(); i != PD.end(); ++i) {
187 const JLocation location = router.getModule(i->first);
188 out << JGraph(i->second, MAKE_CSTRING("G[" << location.getString() << ","<< location.getFloor() << "].offset"));
189 }
190
191 for (map<JObjectID, JGraph_t>::const_iterator i = XO.begin(); i != XO.end(); ++i) {
192 const JLocation location = router.getModule(i->first);
193 out << JGraph(i->second, MAKE_CSTRING("G[" << location.getString() << ","<< location.getFloor() << "].xorientation"));
194 }
195 out << JGraph(PD_all, "all_off");
196
197
198 out.Write();
199 out.Close();
200}
string outputFile
ROOT TTree parameter settings.
Detector support kit.
Data structure for detector geometry and calibration.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Data structure for compass in three dimensions.
Definition JCompass.hh:51
JQuaternion3D getQuaternion() const
Get quaternion.
Definition JCompass.hh:201
Detector data structure.
Definition JDetector.hh:96
Logical location of module.
Definition JLocation.hh:40
int getFloor() const
Get floor number.
Definition JLocation.hh:146
int getString() const
Get string number.
Definition JLocation.hh:135
Router for direct addressing of module data in detector data structure.
bool hasModule(const JObjectID &id) const
Has module.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:76
Data structure for direction in three dimensions.
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
Data structure for unit quaternion in three dimensions.
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
General exception.
Definition JException.hh:24
Template definition of a multi-dimensional oscillation probability interpolation table.
int main(int argc, char **argv)
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
JDetectorBuilder & getDetectorBuilder()
Get detector builder.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
static const JVector3D JVector3Z_t(0, 0, 1)
unit z-vector
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:70
bool is_valid(const json &js)
Check validity of JSon data.
std::map< int, range_type > map_type
Calibration.
Definition JHead.hh:330
Detector file.
Definition JHead.hh:227
Auxiliary class to map module identifier to AHRS calibration.
Auxiliary data structure to check validity of AHRS data.
long long int UNIXTIME
[ms]
Definition JAHRS.hh:26
Auxiliary interface for building detector.
Auxiliary data structure for decomposition of quaternion in twist and swing quaternions.
Auxiliary data structure to build TGraph.
Definition JGraph.hh:44
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128