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