Jpp 20.0.0-195-g190c9e876
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"
37
38#include "Jeep/JPrint.hh"
39#include "Jeep/JParser.hh"
40#include "Jeep/JMessage.hh"
41
42namespace {
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 */
58int 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 JDetectorMechanics mechanics; // mechanical model data
69 JCanvas canvas;
70 size_t prescale;
71 double ratio;
72 bool batch;
73 size_t Nmin;
74 int debug;
75
76
77 try {
78
79 JParser<> zap("Program to display strings.");
80
81 zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(1200, 600);
82 zap['f'] = make_field(inputFile, "input file (output of JKatoomba[.sh])");
83 zap['n'] = make_field(numberOfEvents) = JLimit::max();
84 zap['a'] = make_field(detectorFile);
85 zap['o'] = make_field(outputFile, "graphics output file name") = MAKE_STRING("A_" << WILDCARD << ".gif");
86 zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
87 zap['M'] = make_field(mechanics, "mechanics data") = JPARSER::initialised();
88 zap['P'] = make_field(prescale, "prescale") = 1;
89 zap['R'] = make_field(ratio, "aspect ratio") = 0.1;
90 zap['B'] = make_field(batch, "batch processing");
91 zap['N'] = make_field(Nmin, "minimum number of transmissions") = 0;
92 zap['d'] = make_field(debug) = 1;
93
94 zap(argc, argv);
95 }
96 catch(const exception& error) {
97 FATAL(error.what() << endl);
98 }
99
100 if (batch && outputFile == "") {
101 FATAL("Missing output file name " << outputFile << " in batch mode." << endl);
102 }
103
104 if (!batch && outputFile == "") {
105 outputFile = MAKE_STRING(WILDCARD << ".gif");
106 }
107
108 if (outputFile.find(WILDCARD) == string::npos) {
109 FATAL("Output file name " << outputFile << " has no wild card '" << WILDCARD << "'" << endl);
110 }
111
113
114 try {
115 load(detectorFile, detector);
116 }
117 catch(const JException& error) {
118 FATAL(error);
119 }
120
121 const JLocationRouter router (detector);
122 const JGeometry geometry(detector, mechanics);
123
124 V.set(detector.getUTMZ());
125
126 map<int, JStatus> status;
127
128 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
129 status[module->getID()] = module->getStatus();
130 }
131
132 // ROOT
133
134 gROOT->SetBatch(batch);
135
136 TApplication* tp = new TApplication("user", NULL, NULL);
137 TCanvas* cv = new TCanvas("display", "", canvas.x, canvas.y);
138
139 unique_ptr<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh()));
140
141 gROOT->SetStyle("gplot");
142 gROOT->ForceStyle();
143
144 const size_t NY = (size_t) (sqrt(geometry.size()) * 0.75 + 0.25);
145 const size_t NX = (size_t) (geometry.size() + NY - 1) / NY;
146
147 const size_t NUMBER_OF_PADS = NX * NY;
148
149 cv->SetFillStyle(4000);
150 cv->SetFillColor(kWhite);
151
152 TPad* p1 = new TPad("p1", NULL, 0.0, 0.00, 1.0, 0.95);
153 TPad* p2 = new TPad("p2", NULL, 0.0, 0.95, 1.0, 1.00);
154
155 p1->Divide(NX, NY, 0.01, 0.001);
156
157 p1->Draw();
158 p2->Draw();
159
160 double zmin = 0.0;
161 double zmax = 0.0;
162
163 for (JGeometry::const_iterator i = geometry.begin(); i != geometry.end(); ++i) {
164
165 if (i->second.getZ() < zmin) {
166 zmin = i->second.getZ();
167 }
168
169 if (i->second.rbegin()->getHeight() > zmax) {
170 zmax = i->second.rbegin()->getHeight();
171 }
172 }
173
174 zmin -= 2.0;
175 zmax += 10.0;
176
177 double xmin = -ratio * (zmax - zmin);
178 double xmax = +ratio * (zmax - zmin);
179
180 TH2D H2[NUMBER_OF_PADS];
181 TText T2[NUMBER_OF_PADS];
182
183 for (size_t i = 0; i != geometry.size(); ++i) {
184
185 H2[i] = TH2D(MAKE_CSTRING(FILL(4,'0') << geometry.at(i).first << FILL()), NULL, 100, xmin, xmax, 100, zmin, zmax);
186
187 DEBUG("Pad " << setw(3) << i + 1 << ' ' << H2[i].GetName() << endl);
188
189 H2[i].GetXaxis()->SetTitle("x/y [m]");
190 H2[i].GetYaxis()->SetTitle("z [m]");
191
192 H2[i].GetXaxis()->CenterTitle(true);
193 H2[i].GetYaxis()->CenterTitle(true);
194
195 H2[i].SetStats(kFALSE);
196
197 T2[i] = TText(0.0, zmax + 0.05 * (zmax - zmin), MAKE_CSTRING(FILL(4,'0') << geometry.at(i).first << FILL()));
198
199 T2[i].SetTextAlign(21);
200 T2[i].SetTextFont(42);
201 T2[i].SetTextSize(0.05);
202
203 p1->cd(i+1);
204
205 H2[i].Draw("AXIS");
206 T2[i].Draw();
207 }
208
210
211 JTreeScanner_t in(inputFile);
212
213 JTreeScanner_t::iterator p = in.begin();
214
215 while (inputFile.hasNext()) {
216
217 cout << "\revent: " << setw(8) << inputFile.getCounter() << flush;
218
219 const JEvt* evt = inputFile.next();
220 const JModel model = getModel(*evt);
221
222 if (batch && inputFile.getCounter()%prescale != 0) {
223 continue;
224 }
225
226 if (Nmin != 0) {
227
228 for ( ; p != in.end() && p-> begin()->getToA() < evt->UNIXTimeStart - 0.5; ++p) {}
229
230 JTreeScanner_t::iterator q = p;
231
232 for ( ; q != in.end() && q->rbegin()->getToA() <= evt->UNIXTimeStop + 0.5; ++q) {}
233
234 if (p != q) {
235
236 map<int, size_t> buffer;
237
238 for (JTreeScanner_t::iterator evt = p; evt != q; ++evt) {
239 for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
240 buffer[i->getID()] += 1;
241 }
242 }
243
244 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
245
246 module->setStatus(status[module->getID()]);
247
248 if (buffer[module->getID()] < Nmin) {
249 module->set(module->getFloor() == 0 ? HYDROPHONE_DISABLE : PIEZO_DISABLE);
250 }
251 }
252 }
253 }
254
255 // graphics
256
257 string utc = JDateAndTime((time_t) evt->UNIXTimeStart);
258
259 TText title(0.5, 0.5, utc.c_str());
260
261 title.SetTextAlign(22);
262 title.SetTextFont(42);
263 title.SetTextSize(0.3);
264
265 p2->cd();
266
267 title.Draw();
268
269 vector<TMarker> X[NUMBER_OF_PADS];
270 vector<TMarker> Y[NUMBER_OF_PADS];
271
272 for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
273
274 if (geometry.has(i->id)) {
275
276 const int index = geometry.getIndex(i->id);
277
278 const JGEOMETRY::JString& string = geometry [i->id];
279 const JMODEL ::JString& parameters = model.string[i->id];
280
281 X[index].push_back(TMarker(0.0, string.getZ(), kFullCircle));
282 Y[index].push_back(TMarker(0.0, string.getZ(), kFullCircle));
283
284 for (size_t floor = 1; floor < string.size(); ++floor) {
285
286 const JLocation location(i->id, floor);
287 const JPosition3D position = string.getPosition(parameters, floor);
288
289 if (router.hasLocation(location) && !router.getModule(location).has(PIEZO_DISABLE)) {
290 X[index].push_back(TMarker(position.getX() - string.getX(), position.getZ(), kFullCircle));
291 Y[index].push_back(TMarker(position.getY() - string.getY(), position.getZ(), kFullCircle));
292 }
293 }
294 }
295 }
296
297 // draw
298
299 for (size_t i = 0; i != NUMBER_OF_PADS; ++i) {
300
301 p1->cd(i+1);
302
303 for (auto& m1 : X[i]) { static_cast<TAttMarker&>(m1) = TAttMarker(kBlack, kFullCircle, 0.7/sqrt(NY)); m1.Draw(); }
304 for (auto& m1 : Y[i]) { static_cast<TAttMarker&>(m1) = TAttMarker(kRed, kFullCircle, 0.7/sqrt(NY)); m1.Draw(); }
305 }
306
307 cv->Update();
308
309 // action
310
311 if (batch) {
312
313 cv->SaveAs(replace(outputFile, WILDCARD, MAKE_STRING(FIXED(12,0,'0') << evt->UNIXTimeStart << FILL())).c_str());
314
315 } else {
316
317 static int count = 0;
318
319 if (count++ == 0) {
320 cout << endl << "Type '?' for possible options." << endl;
321 }
322
323 for (bool user = true; user; ) {
324
325 cout << "\n> " << flush;
326
327 switch (JKeypress(true).get()) {
328
329 case '?':
330 cout << endl;
331 cout << "possible options: " << endl;
332 cout << 'q' << " -> " << "exit application" << endl;
333 cout << 'u' << " -> " << "update canvas" << endl;
334 cout << 's' << " -> " << "save graphics to file" << endl;
335 cout << 'r' << " -> " << "rewind input file" << endl;
336 cout << 'R' << " -> " << "switch to ROOT mode (quit ROOT to continue)" << endl;
337 cout << 'p' << " -> " << "print event information" << endl;
338 cout << ' ' << " -> " << "next event (as well as any other key)" << endl;
339 break;
340
341 case 'q':
342 cout << endl;
343 return 0;
344
345 case 'u':
346 cv->Update();
347 break;
348
349 case 's':
350 cv->SaveAs(replace(outputFile, WILDCARD, MAKE_STRING(FIXED(12,0,'0') << evt->UNIXTimeStart << FILL())).c_str());
351 break;
352
353 case 'R':
354 tp->Run(kTRUE);
355 break;
356
357 case 'p':
358 cout << endl << *evt << endl;
359 break;
360
361 case 'r':
362 inputFile.rewind();
363
364 default:
365 user = false;
366 break;
367 }
368 }
369 }
370 }
371 cout << endl;
372}
Acoustics toolkit.
int main(int argc, char **argv)
Acoustic event.
Acoustic event fit toolkit.
Acoustic event fit.
ROOT TTree parameter settings.
string outputFile
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:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
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:24
Utility class to parse command line options.
Definition JParser.hh:1698
Data structure for size of TCanvas.
Definition JCanvas.hh:26
int y
number of pixels in Y
Definition JCanvas.hh:99
int x
number of pixels in X
Definition JCanvas.hh:98
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.
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:38
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:68
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