53{
56
60 string detectorFile;
61 long long int Tmax_s = 600;
63 double sigma_deg = 1.0;
64 double stdev = numeric_limits<double>::max();
65 int numberOfOutliers = 0;
66 string ahrsFile;
67 bool overwriteDetector;
69
70 try {
71
73
79
80 JParser<> zap(
"Program to calibrate in situ AHRS.");
81
82 zap[
'f'] =
make_field(inputFile,
"output of JConvertDB -q ahrs");
86 zap[
'c'] =
make_field(ahrsFile,
"output of JAHRSCalibration");
90
91 zap(argc, argv);
92 }
93 catch(const exception &error) {
94 FATAL(error.what() << endl);
95 }
96
97
99
100 try {
102 }
105 }
106
108
111
112
114
115
118
119
121
123
125
127
128
130
131 JManager_t H0(new TH1D("%.twist", NULL, 100, 0.0, 5.0));
132 JManager_t H1(new TH1D("%.swing", NULL, 250, 0.0, 2.5));
133 JManager_t HN(new TH1D("%.count", NULL, 100, -0.5, 99.5));
134
135 TH2D h2("h2", NULL,
136 string.size(), -0.5, string.size() - 0.5,
138
139 for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
140 h2.GetXaxis()->SetBinLabel(i,
MAKE_CSTRING(
string.at(i-1)));
141 }
142 for (Int_t i = 1; i <= h2.GetYaxis()->GetNbins(); ++i) {
144 }
145
146 TH2D* h1 = (TH2D*) h2.Clone("h1");
147
148
150
152
154
155 for (JMultipleFileScanner_t::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
156
157 STATUS(
"processing file " << *file_name << endl);
158
160
162
163 const JAHRS* parameters = in.next();
164
165 if (
is_valid(*parameters) && router.hasModule(parameters->
DOMID)) {
166 data[router.getModule(parameters->
DOMID).getString()].push_back(*parameters);
167 }
168 }
169
171
173
174 for (vector<JAHRS>::const_iterator p = i->second.begin(); p != i->second.end(); ) {
175
176 long long int t1 = p->UNIXTIME;
177 long long int t2 = t1;
178
180
181 for ( ; p != i->second.end() && p->UNIXTIME < t1 + Tmax_s * 1000; t2 = (p++)->UNIXTIME) {
182
184
185 const JModule& module = router.getModule(p->DOMID);
186
188
190
191 const JQuaternion3D Q =
module.getQuaternion() * compass.getQuaternion();
192
193 buffer.push_back(
JHit(p->DOMID, module.
getZ(), Q, sigma_deg));
194 }
195 }
196 }
197
199
200 for (vector<JHit>::const_iterator hit = buffer.begin(); hit != buffer.end(); ++hit) {
201
202 const JLocation& location = router.getModule(hit->getID());
203
205 }
206
208
210
211 for (int ns = 0; ns != numberOfOutliers; ++ns) {
212
215
217
220
222
223 if (x > xmax) {
225 out = hit;
226 }
227 }
228
229 if (xmax > stdev * sigma_deg) {
230
231 const JLocation& location = router.getModule(out->getID());
232
234
236
239
242
243 cout << "remove " << location << ' '
247 }
248
249 swap(*out, *--__end);
250
252
253 } else {
254
255 break;
256 }
257 }
258
260
261 simplex.
step.resize(4);
262
267
268 const double chi2 = simplex(
getChi2, buffer.begin(), __end);
269 const int ndf =
distance(buffer.begin(), __end) * 4 - simplex.
step.size();
270
272
273
275
276
277 for (vector<JHit>::const_iterator hit = buffer.begin(); hit != buffer.end(); ++hit) {
278
281
284
286
287 H0[hit->getID()]->Fill(
getAngle(q1.twist, q2.twist));
288 H1[hit->getID()]->Fill(
getAngle(q1.swing, q2.swing));
289 }
290
292
293 for (vector<JHit>::const_iterator hit = buffer.begin(); hit != __end; ++hit) {
294 count[hit->getID()] += 1;
295 }
296
298 HN[i->first]->Fill(i->second);
299 }
300 }
301 }
302 }
303 }
304
305
306 h2.Divide(h1);
307
309
310 for (JManager_t* p : { &H0, &H1, &HN }) {
311 for (JManager_t::iterator i = p->begin(); i != p->end(); ++i) {
313 }
314 }
315
317
318
319 if (overwriteDetector) {
320
321 NOTICE(
"Store calibration data on file " << detectorFile << endl);
322
323 if (
detector.setToLatestVersion()) {
324 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
325 }
326
328
330
332
334
335 module.setQuaternion(Q.normalise());
336 }
337
339 }
340}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_CSTRING(A)
Make C-string.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Data structure for compass in three dimensions.
Logical location of module.
int getFloor() const
Get floor number.
int getString() const
Get string number.
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
bool has(const int bit) const
Test PMT status.
Utility class to parse parameter values.
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
std::vector< JModel_t > step
Data structure for unit quaternion in three dimensions.
const JQuaternion3D & getQuaternion() const
Get quaternion.
JQuaternion3D getConjugate() const
Get conjugate of this quaternion.
static const JQuaternion3D & getIdentity()
Get identity quaternion.
double getZ() const
Get z position.
Utility class to parse command line options.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
static const int COMPASS_DISABLE
Enable (disable) use of compass if this status bit is 0 (1);.
JEvt getEvt(const JHead &header, const JModel &model)
Get event.
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
double getChi2(const double P)
Get chi2 corresponding to given probability.
double getAngle(const JQuaternion3D &first, const JQuaternion3D &second)
Get space angle between quanternions.
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.
int getIndex()
Get index for user I/O manipulation.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
bool is_valid(const json &js)
Check validity of JSon data.
Auxiliary data structure for floating point format specification.
Model for fit to acoustics data.
Auxiliary data structure for chi2 evaluation.
static const int NUMBER_OF_PARAMETERS
number of parameters of fit per quaternion
Auxiliary class to map module identifier to AHRS calibration.
Auxiliary data structure to check validity of AHRS data.
long long int UNIXTIME
[ms]
Router for mapping of string identifier to index.
static int debug
debug level (default is off).
Auxiliary data structure for decomposition of quaternion in twist and swing quaternions.
This class represents a rotation around the x-axis.
This class represents a rotation around the y-axis.
This class represents a rotation around the z-axis.
Auxiliary class to determine average of set of values.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
static counter_type max()
Get maximum counter value.
Auxiliary base class for list of file names.