44 struct JParameters_t {
46 static const char SKIPLINE =
'#';
54 range(JRange<double>::DEFAULT_RANGE()),
66 friend inline std::istream&
operator>>(std::istream& in, JParameters_t&
object)
69 return in >>
object.working >>
object.expected_rate >>
object.range >>
object.number_of_outliers;
80 friend inline std::ostream&
operator<<(std::ostream& out,
const JParameters_t&
object)
85 return out << setw(6) <<
object.working <<
' '
86 <<
FIXED(2,6) <<
object.expected_rate <<
' '
87 <<
FIXED(2,6) <<
object.range.getLowerLimit() <<
' '
88 <<
FIXED(2,6) <<
object.range.getUpperLimit() <<
' '
89 << setw(4) <<
object.number_of_outliers;
95 int number_of_outliers;
107 TIter iter(dir->GetListOfKeys());
109 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
111 if (key->IsFolder()){
113 dir->cd(key->GetName());
115 TDirectory *subdir = gDirectory;
124 buffer.push_back(objectID);
144 int main(
int argc,
char **argv)
150 string parametersFile;
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[
'f'] =
make_field(inputFile,
"output root file from JAcousticsMonitor_short");
164 zap[
'P'] =
make_field(parametersFile,
"ASCII formatted input file with test criteria (acoustic_monitor_00000XXX.txt)");
167 zap[
'w'] =
make_field(outputFile1,
"output summary file");
168 zap[
't'] =
make_field(outputFile2,
"output root file");
173 catch(
const exception &error) {
174 FATAL(error.what() << endl);
177 ofstream out(outputFile1.c_str());
178 out.imbue(locale(out.getloc(),
color_facets[facet]->clone()));
179 out <<
"ACOUSTIC MONITORING \nRun: " << run << endl;
180 out <<
"\n(Note: red highlights are the reason for the warning)" << endl;
188 ifstream in(parametersFile.c_str());
193 JParameters_t parameters;
195 for (
string buffer;
getline(in, buffer); ) {
197 if (!buffer.empty() && buffer[0] != JParameters_t::SKIPLINE) {
199 istringstream is(buffer);
201 if (is >> key >> parameters) { zmap[key] = parameters; }
208 FATAL(
"Error opening file: " << parametersFile << endl);
224 for (JDetector::const_iterator i =
detector.begin(); i !=
detector.end(); ++i) {
226 receivers[i->getID()] = i->getLocation();
233 string1.size(), - 0.5, string1.size() - 0.5,
236 for (Int_t i = 1; i <= H3->GetXaxis()->GetNbins(); ++i) {
237 H3->GetXaxis()->SetBinLabel(i,
MAKE_CSTRING(string1.at(i-1)));
240 for (Int_t i = 1; i <= H3->GetYaxis()->GetNbins(); ++i) {
246 TFile* f = TFile::Open(inputFile.c_str());
254 if(objectIDs.empty()) {
255 ++number_of_failures;
257 out <<
RED <<
"No acoustic data." << endl;
263 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
265 if (i->first[0] ==
'0') {
continue; }
267 out <<
"\nEmitter: " << i->first << endl;
269 const TRegexp regexp(i->first);
271 TH2D* h3 = H3[stoi(i->first)];
275 for (Int_t ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
276 for (Int_t iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
277 h3->Fill(ix-1, iy-1, 1.0);
285 const TString& objectName = objectID->getFullObjectName();
288 if (objectName.Index(regexp) != -1) {
291 if (!i->second.working) {
292 out << (i->second.working != 0 ?
RED :
GREEN);
293 out <<
"Emitter started working." << endl;
295 out <<
"(Acoustic rates not tested)" << endl;
299 if (i->second.working) {
303 int number_of_bins = 0;
304 int number_of_outliers = 0;
306 double min_rate = i->second.expected_rate * i->second.range.getLowerLimit();
307 double max_rate = i->second.expected_rate * i->second.range.getUpperLimit();
308 int outliers = i->second.number_of_outliers;
310 if (h2 == NULL &&
dynamic_cast<TH2*
>(p) != NULL) { h2 =
dynamic_cast<TH2*
>(p); };
314 for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
315 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
317 const Double_t z = h2->GetBinContent(ix, iy);
318 string du =
to_string(h2->GetXaxis()->GetBinLabel(ix));
319 string floor =
to_string(h2->GetYaxis()->GetBinLabel(iy));
321 du.insert(du.begin(), 4 - du.length(),
'0');
322 floor.insert(floor.begin(), 3 - floor.length(),
'0');
323 const string id = du +
'.' + floor;
326 if (zmap.find(
id)!=zmap.end()) { working = zmap.find(
id)->second.working; }
331 if (z < min_rate || z > max_rate) {
333 h3->Fill(ix-1, iy-1, 1.0);
335 ++number_of_outliers;
338 if (floor ==
"000" && z == 0) {
339 out <<
"DU " << du <<
", floor " << floor <<
" : Acoustic rate out of range -> " << z <<
" Hz." <<
RED <<
" Hydrophone stopped working." << endl;
341 ++number_of_failures;
343 out <<
"DU " << du <<
", floor " << floor <<
" : Acoustic rate out of range -> " << z <<
" Hz." << endl;
346 }
else if (!working) {
347 out <<
"DU " << du <<
", floor " << floor <<
" : Working again -> " << z <<
" Hz." << endl;
352 }
else {
FATAL(
"Object at " << objectName <<
" is not TH2." << endl); }
354 out << (number_of_outliers > outliers ?
RED :
GREEN) <<
"Number of outliers = " << number_of_outliers <<
"/" << number_of_bins << endl;
357 if (number_of_outliers > outliers) {
359 ++number_of_failures;
360 out << (number_of_outliers > outliers ?
RED :
GREEN) <<
"Test failed." << endl;
364 out << (outliers >= number_of_outliers ?
GREEN :
RED) <<
"Test passed." << endl;
372 }
else if (objectID + 1 == objectIDs.cend()) {
375 for (Int_t ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) {
376 for (Int_t iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) {
377 h3->Fill(ix-1, iy-1, 1.0);
382 if (i->second.working) {
383 ++number_of_failures;
384 out << (i->second.working != 0 ?
RED :
GREEN) <<
"Emitter stopped working." << endl;
387 out <<
"Emitter is expected to not work." << endl;
394 TFile out2(outputFile2.c_str(),
"recreate");
402 if (number_of_failures > 0) {
403 number_of_failures = 1;
404 cout << number_of_failures << endl;
int main(int argc, char **argv)
Program to test:
I/O coloring auxiliaries.
Data structure for detector geometry and calibration.
General purpose class for a hash collection of unique elements.
General purpose class for hash map of unique elements.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Dynamic ROOT object management.
General purpose messaging.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
void readDir(TDirectory *dir, std::vector< TString > &v)
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
#define MAKE_STRING(A)
Make string.
Auxiliary class to define a range between two values.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Auxiliary class to handle file name, ROOT directory and object name.
Utility class to parse command line options.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
static const JColorFacetMap_t color_facets
Color facets.
std::string to_string(const T &value)
Convert value to string.
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::map< int, range_type > map_type
Auxiliary data structure for floating point format specification.