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

Example program to monitor acoustic events rate per emitter and receiver and run. 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 "JLang/JPredicate.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 rate per emitter and receiver and run.

Output: histogram of the acoustic event rate per emitter and run.

Author
mdejong, cgatius

Definition in file JAcousticsMonitor_short.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file JAcousticsMonitor_short.cc.

46 {
47  using namespace std;
48  using namespace JPP;
49 
50  JMultipleFileScanner<> inputFile;
51  JLimit_t& numberOfEvents = inputFile.getLimit();
52  string outputFile;
53  string detectorFile;
54  int debug;
55  double lifetime_s;
56 
57  try {
58 
59  JParser<> zap("Example program to monitor acoustic events.");
60 
61  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
62  zap['n'] = make_field(numberOfEvents) = JLimit::max();
63  zap['o'] = make_field(outputFile) = "monitor.root";
64  zap['a'] = make_field(detectorFile);
65  zap['d'] = make_field(debug) = 2;
66  zap['l'] = make_field(lifetime_s, "run lifetime in seconds");
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
74 
75  try {
76  load(detectorFile, detector);
77  }
78  catch(const JException& error) {
79  FATAL(error);
80  }
81 
82  JHashMap<int, JLocation> receivers;
83 
84  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
85 
86  receivers[i->getID()] = i->getLocation();
87  }
88 
89  const JHashCollection<int> string(make_array(detector.begin(), detector.end(), &JModule::getString));
90  const JRange <int> floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
91 
92  JManager<int, TH2D> H2(new TH2D("H[%].event", NULL,
93  string.size(), -0.5, string.size() - 0.5,
94  floor.getUpperLimit() + 1, - 0.5, floor.getUpperLimit() + 0.5));
95 
96  for (Int_t i = 1; i <= H2->GetXaxis()->GetNbins(); ++i) {
97  H2->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
98  }
99 
100  for (Int_t i = 1; i <= H2->GetYaxis()->GetNbins(); ++i) {
101  H2->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i-1));
102  }
103 
105 
106  JTreeScanner_t in(inputFile);
107 
108  for (JTreeScanner_t::iterator event = in.begin(); event != in.end(); ++event) {
109 
110  JQuantile QD("", true), QQ;
111 
112  TH2D* h2 = H2[event->getID()];
113 
114  map<int, set<double> > buffer;
115 
116  for (JEvent::const_iterator i = event->begin(); i != event->end(); ++i) {
117  buffer[i->getID()].insert(i->getQ());
118  }
119 
120  for (map<int, set<double> >::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
121 
122  if (receivers.has(i->first)) {
123 
124  const JLocation& location = receivers[i->first];
125 
126  h2->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), 1.0/lifetime_s);
127  }
128  }
129  }
130  STATUS(endl);
131 
132  TFile out(outputFile.c_str(), "recreate");
133 
134  out << H2;
135 
136  out.Write();
137  out.Close();
138 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:43
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
string outputFile
Template definition for direct access of elements in ROOT TChain.
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:224
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:54
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
int debug
debug level
Definition: JSirene.cc:66
#define FATAL(A)
Definition: JMessage.hh:67
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.
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 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