Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcoustics/JEvD.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <map>
6 #include <memory>
7 
9 
10 #include "TROOT.h"
11 #include "TApplication.h"
12 #include "TCanvas.h"
13 #include "TStyle.h"
14 #include "TH2D.h"
15 #include "TText.h"
16 #include "TMarker.h"
17 
18 #include "JDetector/JDetector.hh"
21 
23 #include "JAcoustics/JGeometry.hh"
25 #include "JAcoustics/JEvent.hh"
26 #include "JAcoustics/JEvt.hh"
28 #include "JAcoustics/JSupport.hh"
29 
30 #include "JROOT/JStyle.hh"
31 #include "JROOT/JCanvas.hh"
32 
34 #include "JSupport/JTreeScanner.hh"
35 
36 #include "JSystem/JKeypress.hh"
37 
38 #include "Jeep/JPrint.hh"
39 #include "Jeep/JParser.hh"
40 #include "Jeep/JMessage.hh"
41 
42 namespace {
43 
44  /**
45  * Wild card character for file name substition.
46  */
47  const char WILDCARD = '%';
48 }
49 
50 
51 /**
52  * \file
53  *
54  * Program to display hit probabilities.
55  *
56  * \author mdejong
57  */
58 int main(int argc, char **argv)
59 {
60  using namespace std;
61  using namespace JPP;
62 
64  JLimit_t& numberOfEvents = inputFile.getLimit();
65  string detectorFile;
66  string outputFile;
67  JSoundVelocity V = getSoundVelocity; // default sound velocity
68  JCanvas canvas;
69  size_t prescale;
70  double ratio;
71  bool batch;
72  size_t Nmin;
73  int debug;
74 
75 
76  try {
77 
78  JParser<> zap("Program to display strings.");
79 
80  zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(1200, 600);
81  zap['f'] = make_field(inputFile, "input file (output of JKatoomba[.sh])");
82  zap['n'] = make_field(numberOfEvents) = JLimit::max();
83  zap['a'] = make_field(detectorFile);
84  zap['o'] = make_field(outputFile, "graphics output file name") = MAKE_STRING("A_" << WILDCARD << ".gif");
85  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
86  zap['M'] = make_field(getMechanics, "mechanics data") = JPARSER::initialised();
87  zap['P'] = make_field(prescale, "prescale") = 1;
88  zap['R'] = make_field(ratio, "aspect ratio") = 0.1;
89  zap['B'] = make_field(batch, "batch processing");
90  zap['N'] = make_field(Nmin, "minimum number of transmissions") = 0;
91  zap['d'] = make_field(debug) = 1;
92 
93  zap(argc, argv);
94  }
95  catch(const exception& error) {
96  FATAL(error.what() << endl);
97  }
98 
99  if (batch && outputFile == "") {
100  FATAL("Missing output file name " << outputFile << " in batch mode." << endl);
101  }
102 
103  if (!batch && outputFile == "") {
104  outputFile = MAKE_STRING(WILDCARD << ".gif");
105  }
106 
107  if (outputFile.find(WILDCARD) == string::npos) {
108  FATAL("Output file name " << outputFile << " has no wild card '" << WILDCARD << "'" << endl);
109  }
110 
112 
113  try {
114  load(detectorFile, detector);
115  }
116  catch(const JException& error) {
117  FATAL(error);
118  }
119 
120  const JLocationRouter router (detector);
121  const JGeometry geometry(detector);
122 
123  V.set(detector.getUTMZ());
124 
125  map<int, JStatus> status;
126 
127  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
128  status[module->getID()] = module->getStatus();
129  }
130 
131  // ROOT
132 
133  gROOT->SetBatch(batch);
134 
135  TApplication* tp = new TApplication("user", NULL, NULL);
136  TCanvas* cv = new TCanvas("display", "", canvas.x, canvas.y);
137 
138  unique_ptr<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh()));
139 
140  gROOT->SetStyle("gplot");
141  gROOT->ForceStyle();
142 
143  const size_t NY = (size_t) (sqrt(geometry.size()) * 0.75 + 0.25);
144  const size_t NX = (size_t) (geometry.size() + NY - 1) / NY;
145 
146  const size_t NUMBER_OF_PADS = NX * NY;
147 
148  cv->SetFillStyle(4000);
149  cv->SetFillColor(kWhite);
150 
151  TPad* p1 = new TPad("p1", NULL, 0.0, 0.00, 1.0, 0.95);
152  TPad* p2 = new TPad("p2", NULL, 0.0, 0.95, 1.0, 1.00);
153 
154  p1->Divide(NX, NY, 0.01, 0.001);
155 
156  p1->Draw();
157  p2->Draw();
158 
159  double zmin = 0.0;
160  double zmax = 0.0;
161 
162  for (JGeometry::const_iterator i = geometry.begin(); i != geometry.end(); ++i) {
163 
164  if (i->second.getZ() < zmin) {
165  zmin = i->second.getZ();
166  }
167 
168  if (i->second.rbegin()->getHeight() > zmax) {
169  zmax = i->second.rbegin()->getHeight();
170  }
171  }
172 
173  zmin -= 2.0;
174  zmax += 10.0;
175 
176  double xmin = -ratio * (zmax - zmin);
177  double xmax = +ratio * (zmax - zmin);
178 
179  TH2D H2[NUMBER_OF_PADS];
180  TText T2[NUMBER_OF_PADS];
181 
182  for (size_t i = 0; i != geometry.size(); ++i) {
183 
184  H2[i] = TH2D(MAKE_CSTRING(FILL(4,'0') << geometry.at(i).first << FILL()), NULL, 100, xmin, xmax, 100, zmin, zmax);
185 
186  DEBUG("Pad " << setw(3) << i + 1 << ' ' << H2[i].GetName() << endl);
187 
188  H2[i].GetXaxis()->SetTitle("x/y [m]");
189  H2[i].GetYaxis()->SetTitle("z [m]");
190 
191  H2[i].GetXaxis()->CenterTitle(true);
192  H2[i].GetYaxis()->CenterTitle(true);
193 
194  H2[i].SetStats(kFALSE);
195 
196  T2[i] = TText(0.0, zmax + 0.05 * (zmax - zmin), MAKE_CSTRING(FILL(4,'0') << geometry.at(i).first << FILL()));
197 
198  T2[i].SetTextAlign(21);
199  T2[i].SetTextFont(42);
200  T2[i].SetTextSize(0.05);
201 
202  p1->cd(i+1);
203 
204  H2[i].Draw("AXIS");
205  T2[i].Draw();
206  }
207 
209 
210  JTreeScanner_t in(inputFile);
211 
212  JTreeScanner_t::iterator p = in.begin();
213 
214  while (inputFile.hasNext()) {
215 
216  cout << "\revent: " << setw(8) << inputFile.getCounter() << flush;
217 
218  const JEvt* evt = inputFile.next();
219  const JModel model = getModel(*evt);
220 
221  if (batch && inputFile.getCounter()%prescale != 0) {
222  continue;
223  }
224 
225  if (Nmin != 0) {
226 
227  for ( ; p != in.end() && p-> begin()->getToA() < evt->UNIXTimeStart - 0.5; ++p) {}
228 
229  JTreeScanner_t::iterator q = p;
230 
231  for ( ; q != in.end() && q->rbegin()->getToA() <= evt->UNIXTimeStop + 0.5; ++q) {}
232 
233  if (p != q) {
234 
235  map<int, size_t> buffer;
236 
237  for (JTreeScanner_t::iterator evt = p; evt != q; ++evt) {
238  for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
239  buffer[i->getID()] += 1;
240  }
241  }
242 
243  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
244 
245  module->setStatus(status[module->getID()]);
246 
247  if (buffer[module->getID()] < Nmin) {
248  module->set(module->getFloor() == 0 ? HYDROPHONE_DISABLE : PIEZO_DISABLE);
249  }
250  }
251  }
252  }
253 
254  // graphics
255 
256  string utc = JDateAndTime((time_t) evt->UNIXTimeStart);
257 
258  TText title(0.5, 0.5, utc.c_str());
259 
260  title.SetTextAlign(22);
261  title.SetTextFont(42);
262  title.SetTextSize(0.3);
263 
264  p2->cd();
265 
266  title.Draw();
267 
268  vector<TMarker> X[NUMBER_OF_PADS];
269  vector<TMarker> Y[NUMBER_OF_PADS];
270 
271  for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
272 
273  if (geometry.has(i->id)) {
274 
275  const int index = geometry.getIndex(i->id);
276 
277  const JGEOMETRY::JString& string = geometry [i->id];
278  const JMODEL ::JString& parameters = model.string[i->id];
279 
280  X[index].push_back(TMarker(0.0, string.getZ(), kFullCircle));
281  Y[index].push_back(TMarker(0.0, string.getZ(), kFullCircle));
282 
283  for (size_t floor = 1; floor < string.size(); ++floor) {
284 
285  const JLocation location(i->id, floor);
286  const JPosition3D position = string.getPosition(parameters, floor);
287 
288  if (router.hasLocation(location) && !router.getModule(location).has(PIEZO_DISABLE)) {
289  X[index].push_back(TMarker(position.getX() - string.getX(), position.getZ(), kFullCircle));
290  Y[index].push_back(TMarker(position.getY() - string.getY(), position.getZ(), kFullCircle));
291  }
292  }
293  }
294  }
295 
296  // draw
297 
298  for (size_t i = 0; i != NUMBER_OF_PADS; ++i) {
299 
300  p1->cd(i+1);
301 
302  for (auto& m1 : X[i]) { static_cast<TAttMarker&>(m1) = TAttMarker(kBlack, kFullCircle, 0.7/sqrt(NY)); m1.Draw(); }
303  for (auto& m1 : Y[i]) { static_cast<TAttMarker&>(m1) = TAttMarker(kRed, kFullCircle, 0.7/sqrt(NY)); m1.Draw(); }
304  }
305 
306  cv->Update();
307 
308  // action
309 
310  if (batch) {
311 
312  cv->SaveAs(replace(outputFile, WILDCARD, MAKE_STRING(FIXED(12,0,'0') << evt->UNIXTimeStart << FILL())).c_str());
313 
314  } else {
315 
316  static int count = 0;
317 
318  if (count++ == 0) {
319  cout << endl << "Type '?' for possible options." << endl;
320  }
321 
322  for (bool user = true; user; ) {
323 
324  cout << "\n> " << flush;
325 
326  switch (JKeypress(true).get()) {
327 
328  case '?':
329  cout << endl;
330  cout << "possible options: " << endl;
331  cout << 'q' << " -> " << "exit application" << endl;
332  cout << 'u' << " -> " << "update canvas" << endl;
333  cout << 's' << " -> " << "save graphics to file" << endl;
334  cout << 'r' << " -> " << "rewind input file" << endl;
335  cout << 'R' << " -> " << "switch to ROOT mode (quit ROOT to continue)" << endl;
336  cout << 'p' << " -> " << "print event information" << endl;
337  cout << ' ' << " -> " << "next event (as well as any other key)" << endl;
338  break;
339 
340  case 'q':
341  cout << endl;
342  return 0;
343 
344  case 'u':
345  cv->Update();
346  break;
347 
348  case 's':
349  cv->SaveAs(replace(outputFile, WILDCARD, MAKE_STRING(FIXED(12,0,'0') << evt->UNIXTimeStart << FILL())).c_str());
350  break;
351 
352  case 'R':
353  tp->Run(kTRUE);
354  break;
355 
356  case 'p':
357  cout << endl << *evt << endl;
358  break;
359 
360  case 'r':
361  inputFile.rewind();
362 
363  default:
364  user = false;
365  break;
366  }
367  }
368  }
369  }
370  cout << endl;
371 }
JModel getModel(const JEvt &evt)
Get model.
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
int main(int argc, char *argv[])
Definition: Main.cc:15
TPaveText * p1
TString replace(const TString &target, const TRegexp &regexp, const T &replacement)
Replace regular expression in input by given replacement.
Definition: JPrintResult.cc:63
Sound velocity.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:242
then wget no check certificate user
ROOT TTree parameter settings.
Detector data structure.
Definition: JDetector.hh:89
bool hasLocation(const JLocation &location) const
Has module.
Acoustic geometries.
const JModule & getModule(const JLocation &location) const
Get module parameters.
*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.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
int getIndex(const T &value) const
Get index of given value.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
string outputFile
Template definition for direct access of elements in ROOT TChain.
Data structure for detector geometry and calibration.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
Direct access to location in detector data structure.
static const char WILDCARD
Definition: JDAQTags.hh:50
Model for fit to acoustics data.
Acoustic event fit toolkit.
double UNIXTimeStop
stop time
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const JSoundVelocity getSoundVelocity(1541.0,-17.0e-3,-2000.0)
Function object for velocity of sound.
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Acoustic event fit.
Router for direct addressing of location data in detector data structure.
Keyboard settings for unbuffered input.
Logical location of module.
Definition: JLocation.hh:37
Acoustics toolkit.
bool has(const int bit) const
Test PMT status.
Definition: JStatus.hh:120
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Enable unbuffered terminal input.
Definition: JKeypress.hh:32
double getY() const
Get y position.
Definition: JVector3D.hh:104
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
Implementation for depth dependend velocity of sound.
#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
JACOUSTICS::JModel::string_type string
p2
Definition: module-Z:fit.sh:74
const double xmin
Definition: JQuadrature.cc:23
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double UNIXTimeStart
start time
General purpose class for object reading from a list of file names.
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:48
Auxiliary class for date and time.
Definition: JDateAndTime.hh:78
Utility class to parse command line options.
static const int PIEZO_DISABLE
Enable (disable) use of piezo if this status bit is 0 (1);.
double getX() const
Get x position.
Definition: JVector3D.hh:94
no fit printf nominal n $STRING awk v X
static const int HYDROPHONE_DISABLE
Enable (disable) use of hydrophone if this status bit is 0 (1);.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
container_type::const_iterator const_iterator
Definition: JHashMap.hh:86
do set_variable DETECTOR_TXT $WORKDIR detector
Acoustic event fit.
bool has(const T &value) const
Test whether given value is present.
double getZ() const
Get z position.
Definition: JVector3D.hh:115
Wrapper class around ROOT TStyle.
Definition: JStyle.hh:20
int debug
debug level
Data structure for size of TCanvas.
Definition: JCanvas.hh:26
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62