150 string parametersFile;
152 string output_summary;
153 string output_status;
156 int number_of_failures = 0;
161 JParser<> zap(
"Auxiliary program to apply test criteria to 2D histograms monitoring acoustic rate per emitter.");
163 zap[
'i'] =
make_field(inputFile,
"output root file from JAcousticsMonitorRateSummary");
164 zap[
'@'] =
make_field(parametersFile,
"ASCII formatted input file with test criteria (acoustics_monitor)");
165 zap[
'F'] =
make_field(facet,
"Color facet") = get_keys(color_facets);
167 zap[
's'] =
make_field(output_summary,
"output summary file");
168 zap[
'o'] =
make_field(output_status,
"output information file working/not working");
173 catch(
const exception &error) {
174 FATAL(error.what() << endl);
177 ofstream out_summary(output_summary.c_str());
178 out_summary.imbue(locale(out_summary.getloc(), color_facets[facet]->clone()));
179 out_summary <<
"ACOUSTIC MONITORING \nRun: " << run << endl;
180 out_summary <<
"\n(Note: red highlights are the reason for the warning)" << endl;
183 out_status.open(output_status.c_str());
184 out_status <<
"INFORMATION ABOUT RECEIVER STATUS \nRun: " << run << endl;
192 ifstream in(parametersFile.c_str());
197 JParameters_t parameters;
199 for (
string buffer; getline(in, buffer); ) {
201 if (!buffer.empty() && buffer[0] != JParameters_t::SKIPLINE) {
203 istringstream is(buffer);
205 if (is >> key >> parameters) { zmap[key] = parameters; }
212 FATAL(
"Error opening file: " << parametersFile << endl);
228 for (JDetector::const_iterator i =
detector.begin(); i !=
detector.end(); ++i) {
230 receivers[i->getID()] = i->getLocation();
234 const JRange <int> floor1 (make_array(
detector.begin(),
detector.end(), &JModule::getFloor));
236 JManager<int, TH2D> H3(
new TH2D(
"H[%].rate-test", NULL,
237 string1.size(), - 0.5, string1.size() - 0.5,
240 for (Int_t i = 1; i <= H3->GetXaxis()->GetNbins(); ++i) {
241 H3->GetXaxis()->SetBinLabel(i,
MAKE_CSTRING(string1.at(i-1)));
244 for (Int_t i = 1; i <= H3->GetYaxis()->GetNbins(); ++i) {
250 TFile* f = TFile::Open(inputFile.c_str());
258 if(objectIDs.empty()) {
259 ++number_of_failures;
261 out_summary << RED <<
"No acoustic data." << endl;
262 out_summary << RESET;
267 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
269 if (i->first[0] ==
'0') {
continue; }
271 out_summary <<
"\nEmitter: " << i->first << endl;
272 out_status <<
"\nEmitter: " << i->first << endl;
273 const TRegexp regexp(i->first);
275 TH2D* h3 = H3[stoi(i->first)];
279 for (Int_t ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
280 for (Int_t iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
281 string du = to_string(h3->GetXaxis()->GetBinLabel(ix));
282 string floor = to_string(h3->GetYaxis()->GetBinLabel(iy));
283 h3->Fill(ix-1, iy-1, 1.0);
284 out_status <<
"\nDU\tFloor\tOutOfRange\tSupposedToWork\tRate" << endl;
285 out_status << du <<
"\t" << floor <<
"\t" << 1 <<
"\t" << i->second.working << 0 << endl;
291 for (vector<JRootObjectID>::const_iterator objectID = objectIDs.cbegin() ; objectID != objectIDs.cend() ; ++objectID) {
293 const TString& objectName = objectID->getFullObjectName();
296 if (objectName.Index(regexp) != -1) {
299 if (!i->second.working) {
300 out_summary << (i->second.working != 0 ? RED : GREEN);
301 out_summary <<
"Emitter started working." << endl;
302 out_summary << RESET;
303 out_summary <<
"(Acoustic rates not tested)" << endl;
307 if (i->second.working) {
311 int number_of_bins = 0;
312 int number_of_outliers = 0;
314 double min_rate = i->second.expected_rate * i->second.range.getLowerLimit();
315 double max_rate = i->second.expected_rate * i->second.range.getUpperLimit();
316 int outliers = i->second.number_of_outliers;
318 if (h2 == NULL &&
dynamic_cast<TH2*
>(p) != NULL) { h2 =
dynamic_cast<TH2*
>(p); };
321 out_status <<
"min rate fraction: " << i->second.range.getLowerLimit() << endl;
322 out_status <<
"max rate fraction: " << i->second.range.getUpperLimit() << endl;
323 out_status <<
"max allowed outliers: " << outliers << endl;
324 out_status <<
"\nDU\tFloor\tOutOfRange\tSupposedToWork\tRate" << endl;
326 for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
327 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
329 const Double_t z = h2->GetBinContent(ix, iy);
330 string du = to_string(h2->GetXaxis()->GetBinLabel(ix));
331 string floor = to_string(h2->GetYaxis()->GetBinLabel(iy));
333 du.insert(du.begin(), 4 - du.length(),
'0');
334 floor.insert(floor.begin(), 3 - floor.length(),
'0');
335 const string id = du +
'.' + floor;
339 if (zmap.find(
id)!=zmap.end()) { working = zmap.find(
id)->second.working; }
344 if (z < min_rate || z > max_rate) {
346 h3->Fill(ix-1, iy-1, 1.0);
349 ++number_of_outliers;
353 if (floor ==
"000" && z == 0) {
354 out_summary <<
"DU " << du <<
", floor " << floor <<
" : Acoustic rate out of range -> " << z <<
" Hz." << RED <<
" Hydrophone stopped working." << endl;
355 out_summary << RESET;
356 ++number_of_failures;
358 out_summary <<
"DU " << du <<
", floor " << floor <<
" : Acoustic rate out of range -> " << z <<
" Hz." << endl;
361 }
else if (!working) {
362 out_summary <<
"DU " << du <<
", floor " << floor <<
" : Working again -> " << z <<
" Hz." << endl;
365 out_status << du <<
"\t" << floor <<
"\t" << status <<
"\t" << working <<
"\t" << z << endl;
369 }
else {
FATAL(
"Object at " << objectName <<
" is not TH2." << endl); }
371 out_summary << (number_of_outliers > outliers ? RED : GREEN) <<
"Number of outliers = " << number_of_outliers <<
"/" << number_of_bins << endl;
372 out_summary << RESET;
374 if (number_of_outliers > outliers) {
376 ++number_of_failures;
377 out_summary << (number_of_outliers > outliers ? RED : GREEN) <<
"Test failed." << endl;
378 out_summary << RESET;
381 out_summary << (outliers >= number_of_outliers ? GREEN : RED) <<
"Test passed." << endl;
382 out_summary << RESET;
389 }
else if (objectID + 1 == objectIDs.cend()) {
392 for (Int_t ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
393 for (Int_t iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
394 string du = to_string(h3->GetXaxis()->GetBinLabel(ix));
395 string floor = to_string(h3->GetYaxis()->GetBinLabel(iy));
396 h3->Fill(ix-1, iy-1, 1.0);
397 out_status <<
"\nDU\tFloor\tOutOfRange\tSupposedToWork\tRate" << endl;
398 out_status << du <<
"\t" << floor <<
"\t" << 1 <<
"\t" << i->second.working << 0 << endl;
403 if (i->second.working) {
404 ++number_of_failures;
405 out_summary << (i->second.working != 0 ? RED : GREEN) <<
"Emitter stopped working." << endl;
406 out_summary << RESET;
408 out_summary <<
"Emitter is expected to not work." << endl;