Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcousticsMonitor.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TH2D.h"
10 
12 #include "JTools/JHashMap.hh"
13 #include "JTools/JRange.hh"
14 #include "JTools/JQuantile.hh"
15 
16 #include "JDetector/JDetector.hh"
18 
20 #include "JSupport/JTreeScanner.hh"
21 
22 #include "JROOT/JRootToolkit.hh"
23 #include "JROOT/JManager.hh"
24 
25 #include "JAcoustics/JEvent.hh"
26 #include "JAcoustics/JSupport.hh"
28 
29 #include "Jeep/JContainer.hh"
30 #include "Jeep/JPrint.hh"
31 #include "Jeep/JParser.hh"
32 #include "Jeep/JMessage.hh"
33 
34 
35 /**
36  * \file
37  *
38  * Example program to monitor acoustic events.
39  * \author mdejong
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45 
46  JMultipleFileScanner<> inputFile;
47  JLimit_t& numberOfEvents = inputFile.getLimit();
48  string outputFile;
49  string detectorFile;
51  double Q;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Example program to monitor acoustic events.");
57 
58  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
59  zap['n'] = make_field(numberOfEvents) = JLimit::max();
60  zap['o'] = make_field(outputFile) = "monitor.root";
61  zap['a'] = make_field(detectorFile);
62  zap['@'] = make_field(parameters, "trigger parameters") = JPARSER::initialised();
63  zap['Q'] = make_field(Q) = 0.9;
64  zap['d'] = make_field(debug) = 2;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
73 
74  try {
75  load(detectorFile, detector);
76  }
77  catch(const JException& error) {
78  FATAL(error);
79  }
80 
81  JHashMap<int, JLocation> receivers;
82 
83  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
84  receivers[i->getID()] = i->getLocation();
85  }
86 
87 
88  const JHashCollection<int> string(make_array(detector.begin(), detector.end(), &JModule::getString));
89  const JRange <int> floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
90 
91 
92  JManager<int, TH1D> HA(new TH1D("H[%].size", NULL, detector.size() + 1, -0.5, detector.size() + 0.5));
93  JManager<int, TH1D> HB(new TH1D("H[%].overlays", NULL, 101, -0.5, 100.5));
94  JManager<int, TH1D> HC(new TH1D("H[%].time", NULL, 800, 0.0, 4.0));
95  JManager<int, TH1D> HD(new TH1D("H[%].rms", NULL, 500, 0.0, 1.0e-1));
96  JManager<int, TH1D> HE(new TH1D("H[%].quantile", NULL, 500, 0.0, 1.0e-1));
97  JManager<int, TH1D> HQ(new TH1D("H[%].quality", NULL, 200, 0.0, 8.0));
98  JManager<int, TH1D> H1(new TH1D("H[%].multiplicity", NULL, 101, -0.5, 100.5));
99  JManager<int, TH2D> H2(new TH2D("H[%].event", NULL,
100  string.size(), -0.5, string.size() - 0.5,
101  floor.getUpperLimit() + 1, - 0.5, floor.getUpperLimit() + 0.5));
102  JManager<int, TH2D> H3((TH2D*) H2->Clone("H[%].doubles"));
103 
104  for (Int_t i = 1; i <= H2->GetXaxis()->GetNbins(); ++i) {
105  H2->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
106  H3->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
107  }
108 
109  for (Int_t i = 1; i <= H2->GetYaxis()->GetNbins(); ++i) {
110  H2->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
111  H3->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
112  }
113 
114 
116 
117  counter_type counter = 0;
118 
119  for (JMultipleFileScanner<>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
120 
121  JTreeScanner_t in(*i);
122 
124 
125  for (JTreeScanner_t::iterator event = in.begin(); event != in.end() && counter != inputFile.getLimit(); ++event, ++counter) {
126 
127  if (counter%1000 == 0) {
128  STATUS("event " << setw(8) << counter << '\r'); DEBUG(endl);
129  }
130 
131  const JEvent evt = *event;
132 
133  JQuantile Q1("", true);
134 
135  for (JEvent::const_iterator i = evt.begin(); i != evt.end(); ++i) {
136  Q1.put(i->getToE());
137  }
138 
139  HA[evt.getID()]->Fill((double) evt.size());
140  HB[evt.getID()]->Fill((double) evt.getOverlays());
141 
142  if (toe.has(evt.getID())) {
143  HC[evt.getID()]->Fill(log10(evt.begin()->getToE() - toe[evt.getID()]));
144  }
145 
146  HD[evt.getID()]->Fill(Q1.getSTDev());
147  HE[evt.getID()]->Fill(Q1.getQuantile(Q, JQuantile::symmetric_t));
148 
149  toe[evt.getID()] = evt.begin()->getToE();
150 
151  TH1D* hq = HQ[evt.getID()];
152  TH1D* h1 = H1[evt.getID()];
153  TH2D* h2 = H2[evt.getID()];
154  TH2D* h3 = H3[evt.getID()];
155 
156  map<int, set<double> > buffer;
157 
158  for (JEvent::const_iterator i = evt.begin(); i != evt.end(); ++i) {
159  buffer[i->getID()].insert(i->getQ());
160  }
161 
162  for (map<int, set<double> >::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
163 
164  hq->Fill(log10(*(i->second.rbegin())));
165  h1->Fill((double) i->second.size());
166 
167  if (receivers.has(i->first)) {
168 
169  const JLocation& location = receivers[i->first];
170 
171  h2->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
172 
173  if (i->second.size() > 1u) {
174  h3->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
175  }
176  }
177  }
178  }
179  }
180  STATUS(endl);
181 
182 
183  TFile out(outputFile.c_str(), "recreate");
184 
185  out << HA << HB << HC << HD << HE << HQ << H1 << H2 << H3;
186 
187  out.Write();
188  out.Close();
189 }
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
int getOverlays() const
Get overlays.
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
double getSTDev() const
Get standard deviation.
Definition: JQuantile.hh:266
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:43
General purpose class for hash map of unique elements.
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
Detector data structure.
Definition: JDetector.hh:89
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Acoustic event.
General purpose class for a hash collection of unique elements.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Long64_t counter_type
Type definition for counter.
Dynamic ROOT object management.
string outputFile
Template definition for direct access of elements in ROOT TChain.
Data structure for detector geometry and calibration.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
set_variable E_E log10(E_{fit}/E_{#mu})"
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
double getQuantile(const double Q, const Quantile_t option=forward_t) const
Get quantile.
Definition: JQuantile.hh:319
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:133
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
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...
Base class for JTreeScanner.
Definition: JTreeScanner.hh:54
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Acoustic trigger parameters.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Acoustic event.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
int getID() const
Get identifier.
double u[N+1]
Definition: JPolint.hh:776
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
bool has(const T &value) const
Test whether given value is present.
Container I/O.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62