Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintRMS.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 
8 
9 #include "JAcoustics/JEvent.hh"
10 #include "JAcoustics/JSupport.hh"
11 
12 #include "JTools/JQuantile.hh"
13 
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Auxiliary program to print RMS of acoustic events.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
31  JLimit_t& numberOfEvents = inputFile.getLimit();
32  size_t numberOfOutliers;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Auxiliary program to print RMS of acoustic events.");
38 
39  zap['f'] = make_field(inputFile);
40  zap['n'] = make_field(numberOfEvents) = JLimit_t::max();
41  zap['N'] = make_field(numberOfOutliers) = 0;
42  zap['d'] = make_field(debug) = 1;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50 
51  JQuantile Q;
52 
53  while (inputFile.hasNext()) {
54 
55  const JEvent* evt = inputFile.next();
56 
57  vector<double> buffer;
58 
59  for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
60  buffer.push_back(i->getToE());
61  }
62 
63  if (buffer.size() >= 2 * numberOfOutliers + 5) {
64 
65  sort(buffer.begin(), buffer.end());
66 
67  vector<double>::iterator p = buffer.begin();
68  vector<double>::reverse_iterator q = buffer.rbegin();
69 
70  for (size_t i = 0; i != numberOfOutliers; ++i) {
71  ++p;
72  ++q;
73  }
74 
75  const double x0 = 0.5 * (*p + *q);
76 
77  for (vector<double>::iterator i = p; i != q.base(); ++i) {
78  *i -= x0;
79  }
80 
81  const JQuantile q1("", p, q.base());
82 
83  Q.put(q1.getSTDev());
84  }
85  }
86 
87  cout << Q.getMean();
88 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Quantile calculator.
Definition: JQuantile.hh:88
ROOT TTree parameter settings.
Acoustic event.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:173
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
Acoustic event.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73