Jpp
 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, 11, -0.5, 10.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(new TH2D("H[%].doubles", NULL,
100  string.size(), -0.5, string.size() - 0.5,
101  floor.getUpperLimit() + 1, - 0.5, floor.getUpperLimit() + 0.5));
102 
103  JManager<int, TGraph> GA(new TGraph(), "G[%].size");
104  JManager<int, TGraph> GD(new TGraph(), "G[%].rms");
105  JManager<int, TGraph> GQ(new TGraph(), "G[%].quality");
106 
107  for (Int_t i = 1; i <= H2->GetXaxis()->GetNbins(); ++i) {
108  H2->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
109  }
110 
111  for (Int_t i = 1; i <= H2->GetYaxis()->GetNbins(); ++i) {
112  H2->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
113  }
114  for (Int_t i = 1; i <= H3->GetXaxis()->GetNbins(); ++i) {
115  H3->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
116  }
117 
118  for (Int_t i = 1; i <= H3->GetYaxis()->GetNbins(); ++i) {
119  H3->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
120  }
121 
122 
124 
125  JTreeScanner_t in(inputFile);
126 
128 
129  for (JTreeScanner_t::iterator event = in.begin(); event != in.end(); ++event) {
130 
131  HA[event->getID()]->Fill((double) event->size());
132  HB[event->getID()]->Fill((double) event->getOverlays());
133 
134  if (toe.has(event->getID())) {
135  HC[event->getID()]->Fill(log10(event->begin()->getToE() - toe[event->getID()]));
136  }
137 
138  const double t1 = event->begin()->getToE();
139 
140  JQuantile QD, QQ;
141 
142  for (JEvent::const_iterator i = event->begin(); i != event->end(); ++i) {
143  QD.put(i->getToE() - t1);
144  QQ.put(log10(i->getQ()));
145  }
146 
147  HD[event->getID()]->Fill(QD.getRMS());
148 
149  AddPoint(GA[event->getID()], t1, event->size());
150  AddPoint(GD[event->getID()], t1, QD.getMean());
151  AddPoint(GQ[event->getID()], t1, QQ.getMean());
152 
153  toe[event->getID()] = event->begin()->getToE();
154 
155  TH1D* hq = HQ[event->getID()];
156  TH2D* h2 = H2[event->getID()];
157  TH2D* h3 = H3[event->getID()];
158 
159  map<int, int> buffer;
160 
161  for (JEvent::const_iterator i = event->begin(); i != event->end(); ++i) {
162 
163  hq->Fill(log10(i->getQ()));
164 
165  buffer[i->getID()] += 1;
166 
167  if (receivers.has(i->getID())) {
168 
169  const JLocation& location = receivers[i->getID()];
170 
171  h2->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
172  }
173  }
174 
175  TH1D* h1 = H1[event->getID()];
176 
177  for (map<int, int>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
178  h1->Fill((double) i->second);
179  if (i->second>1) {
180  if (receivers.has(i->first)) {
181  const JLocation& location = receivers[i->first];
182  h3->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0);
183  }
184  }
185  }
186  }
187  STATUS(endl);
188 
189 
190  TFile out(outputFile.c_str(), "recreate");
191 
192  out << HA << HB << HC << HD << HQ << H1 << H2 << H3;
193  out << GA << GD << GQ;
194 
195  out.Write();
196  out.Close();
197 }
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
Quantile calculator.
Definition: JQuantile.hh:88
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
double getRMS() const
Get RMS.
Definition: JQuantile.hh:296
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:282
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:173
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:25
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
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 typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36