Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcousticsDisable.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <fstream>
6 #include <sstream>
7 #include <set>
8 #include <array>
9 #include <limits>
10 
11 #include "TROOT.h"
12 #include "TFile.h"
13 #include "TH1D.h"
14 #include "TKey.h"
15 #include "TString.h"
16 #include "TRegexp.h"
17 
19 
20 #include "JSupport/JMeta.hh"
21 #include "JSystem/JGlob.hh"
22 #include "JSystem/JStat.hh"
23 
24 #include "Jeep/JContainer.hh"
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 /**
29  * \author mdejong
30  * Auxiliary program to set disable status of transmission based on time-of-arrival histograms.
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36 
37  typedef JContainer< set<JTransmission_t> > disable_container;
38  typedef array<double, 2> array_type;
39 
40  vector<string> inputFile;
41  string outputFile;
42  int Nmin;
43  double Tmax_us;
44  array_type Q = { 0.1, 0.9 };
45  string disableFile;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Auxiliary program to set disable status of transmission based on time-of-arrival histograms.");
51 
52  zap['f'] = make_field(inputFile, "input file (output from JCanberra).");
53  zap['o'] = make_field(outputFile) = "disable.root";
54  zap['N'] = make_field(Nmin, "minimum number of entries") = 1;
55  zap['T'] = make_field(Tmax_us, "maximal time [us]");
56  zap['Q'] = make_field(Q, "quantiles");
57  zap['!'] = make_field(disableFile, "disable transmission file") = "";
58  zap['d'] = make_field(debug, "debug.") = 1;
59 
60  zap(argc, argv);
61  }
62  catch(const exception &error) {
63  FATAL(error.what() << endl);
64  }
65 
66 
67  inputFile = getFilenames(inputFile);
68 
69  disable_container disable;
70 
71  if (disableFile != "" && getFileStatus(disableFile.c_str())) {
72  disable.load(disableFile.c_str());
73  }
74 
75  disable.comment.add(JMeta(argc, argv));
76 
77  TFile out(outputFile.c_str(), "recreate");
78 
79  TH1D ha("ha", NULL, 1000, 0.0, 1.0e4);
80  TH1D hb("hb", NULL, 1000, 0.0, 1.0e3);
81 
82  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
83 
84  NOTICE("Processing " << *i << endl) ;
85 
86  TFile in(i->c_str(), "read");
87 
88  TIter iter(in.GetListOfKeys());
89 
90  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
91 
92  if (TString(key->GetName()).EndsWith(".toa")) {
93 
94  TH1* h1 = dynamic_cast<TH1*>(key->ReadObj());
95 
96  if (h1 != NULL) {
97 
98  TString buffer(h1->GetName());
99 
100  const char* regexp = "[^0-9][0-9]* [0-9]*[^0-9]";
101 
102  buffer = buffer(TRegexp(regexp));
103  buffer = buffer(1, buffer.Length() - 2);
104 
105  if (buffer.Length() > 0 && buffer.IsDigit()) {
106 
107  JTransmission_t id;
108 
109  istringstream(buffer.Data()) >> id;
110 
111  const int N = h1->GetEntries();
112 
113  if (N > 0 && N < Nmin) {
114 
115  NOTICE("disable: " << setw(2) << id.tx << ' ' << setw(8) << id.rx << ' ' << setw(6) << N << " < " << setw(6) << Nmin << endl);
116 
117  disable.insert(id);
118  }
119 
120  ha.Fill(N);
121 
122  if (N > 0) {
123 
124  vector<double> R(Q.size());
125 
126  h1->GetQuantiles(Q.size(), R.data(), Q.data());
127 
128  const double T_us = (*R.rbegin() - *R.begin()) * 1.0e6;
129 
130  hb.Fill(T_us);
131 
132  DEBUG("transmission: " << setw(2) << id.tx << ' ' << setw(8) << id.rx << ' ' << setw(6) << N << ' ' << FIXED(6,1) << T_us << " [us]" << endl);
133 
134  if (T_us > Tmax_us) {
135 
136  NOTICE("disable: " << setw(2) << id.tx << ' ' << setw(8) << id.rx << ' ' << FIXED(6,1) << T_us << " > " << FIXED(6,1) << Tmax_us << " [us]" << endl);
137 
138  disable.insert(id);
139  }
140  }
141 
142  } else {
143 
144  ERROR("Histogram name " << h1->GetName() << " not compatible with regular expression " << regexp << "." << endl);
145  }
146  }
147  }
148  }
149 
150  in.Close();
151  }
152 
153  if (disableFile != "") {
154  disable.store(disableFile.c_str());
155  }
156 
157  out.Write();
158  out.Close();
159 }
Utility class to parse command line options.
Definition: JParser.hh:1711
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
static JGlob getFilenames
Function object to get list of files for given pattern.
Definition: JGlob.hh:123
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
Acoustic transmission identifier.
Container I/O.
int debug
debug level
File list.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
File status.