Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JAcousticsMonitor.cc File Reference

Example program to monitor acoustic events. More...

#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "JTools/JHashCollection.hh"
#include "JTools/JHashMap.hh"
#include "JTools/JRange.hh"
#include "JTools/JQuantile.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JSupport.hh"
#include "Jeep/JContainer.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to monitor acoustic events.

Author
mdejong

Definition in file JAcousticsMonitor.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file JAcousticsMonitor.cc.

43 {
44  using namespace std;
45  using namespace JPP;
46 
47  JMultipleFileScanner<> inputFile;
48  JLimit_t& numberOfEvents = inputFile.getLimit();
49  string outputFile;
50  string detectorFile;
51  int debug;
52 
53  try {
54 
55  JParser<> zap("Example program to monitor acoustic events.");
56 
57  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
58  zap['n'] = make_field(numberOfEvents) = JLimit::max();
59  zap['o'] = make_field(outputFile) = "monitor.root";
60  zap['a'] = make_field(detectorFile);
61  zap['d'] = make_field(debug) = 2;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
71 
72  try {
73  load(detectorFile, detector);
74  }
75  catch(const JException& error) {
76  FATAL(error);
77  }
78 
79  JHashMap<int, JLocation> receivers;
80 
81  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
82  receivers[i->getID()] = i->getLocation();
83  }
84 
85 
86  const JHashCollection<int> string(make_array(detector.begin(), detector.end(), &JModule::getString));
87  const JRange <int> floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
88 
89 
90  JManager<int, TH1D> HA(new TH1D("H[%].size", NULL, detector.size() + 1, -0.5, detector.size() + 0.5));
91  JManager<int, TH1D> HB(new TH1D("H[%].overlays", NULL, 101, -0.5, 100.5));
92  JManager<int, TH1D> HC(new TH1D("H[%].time", NULL, 800, 0.0, 4.0));
93  JManager<int, TH1D> HD(new TH1D("H[%].rms", NULL, 100, 0.0, 0.05));
94  JManager<int, TH1D> HQ(new TH1D("H[%].quality", NULL, 200, 0.0, 8.0));
95  JManager<int, TH1D> H1(new TH1D("H[%].multiplicity", NULL, 101, -0.5, 100.5));
96  JManager<int, TH2D> H2(new TH2D("H[%].event", NULL,
97  string.size(), -0.5, string.size() - 0.5,
98  floor.getUpperLimit() + 1, - 0.5, floor.getUpperLimit() + 0.5));
99  JManager<int, TH2D> H3((TH2D*) H2->Clone("H[%].doubles"));
100 
101  JManager<int, TGraph> GA(new TGraph(), "G[%].size");
102  JManager<int, TGraph> GD(new TGraph(), "G[%].rms");
103  JManager<int, TGraph> GQ(new TGraph(), "G[%].quality");
104 
105  for (Int_t i = 1; i <= H2->GetXaxis()->GetNbins(); ++i) {
106  H2->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
107  H3->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
108  }
109 
110  for (Int_t i = 1; i <= H2->GetYaxis()->GetNbins(); ++i) {
111  H2->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
112  H3->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
113  }
114 
116 
117  JTreeScanner_t in(inputFile);
118 
120 
121  for (JTreeScanner_t::iterator event = in.begin(); event != in.end(); ++event) {
122 
123  HA[event->getID()]->Fill((double) event->size());
124  HB[event->getID()]->Fill((double) event->getOverlays());
125 
126  if (toe.has(event->getID())) {
127  HC[event->getID()]->Fill(log10(event->begin()->getToE() - toe[event->getID()]));
128  }
129 
130  const double t1 = event->begin()->getToE();
131 
132  JQuantile QD("", true), QQ;
133 
134  for (JEvent::const_iterator i = event->begin(); i != event->end(); ++i) {
135  QD.put(i->getToE() - t1);
136  QQ.put(log10(i->getQ()));
137  }
138 
139  HD[event->getID()]->Fill(QD.getSTDev());
140 
141  AddPoint(GA[event->getID()], t1, event->size());
142  AddPoint(GD[event->getID()], t1, QD.getQuantile(0.5));
143  AddPoint(GQ[event->getID()], t1, QQ.getMean());
144 
145  toe[event->getID()] = event->begin()->getToE();
146 
147  TH1D* h1 = H1[event->getID()];
148  TH1D* hq = HQ[event->getID()];
149  TH2D* h2 = H2[event->getID()];
150  TH2D* h3 = H3[event->getID()];
151 
152  map<int, set<double> > buffer;
153 
154  for (JEvent::const_iterator i = event->begin(); i != event->end(); ++i) {
155  buffer[i->getID()].insert(i->getQ());
156  }
157 
158  for (map<int, set<double> >::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
159 
160  h1->Fill((double) i->second.size());
161 
162  hq->Fill(log10(*(i->second.rbegin())));
163 
164  if (receivers.has(i->first)) {
165 
166  const JLocation& location = receivers[i->first];
167 
168  h2->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
169 
170  if (i->second.size() > 1u) {
171  h3->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
172  }
173  }
174  }
175  }
176  STATUS(endl);
177 
178 
179  TFile out(outputFile.c_str(), "recreate");
180 
181  out << HA << HB << HC << HD << HQ << H1 << H2 << H3;
182  out << GA << GD << GQ;
183 
184  out.Write();
185  out.Close();
186 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
void AddPoint(TGraph *g1, const Double_t x, const Double_t y)
Add point to TGraph.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:43
do rm f tmp H1
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
string outputFile
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
double getMean() const
Get mean value.
Definition: JQuantile.hh:224
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
Detector file.
Definition: JHead.hh:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:37
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:129
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
Base class for JTreeScanner.
Definition: JTreeScanner.hh:52
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:739
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38