Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JDrawDetector2D.cc File Reference

Auxiliary program to draw the footprint of detector(s). More...

#include <string>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <memory>
#include "TROOT.h"
#include "TH2D.h"
#include "TApplication.h"
#include "TGraph.h"
#include "TEllipse.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TMarker.h"
#include "TText.h"
#include "TStyle.h"
#include "TLegend.h"
#include "TError.h"
#include "JROOT/JCanvas.hh"
#include "JROOT/JStyle.hh"
#include "JROOT/JMarkerAttributes.hh"
#include "JROOT/JLegend.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JTripod.hh"
#include "JDetector/JTransmitter.hh"
#include "JGeometry2D/JPosition2D.hh"
#include "JGeometry2D/JCircle2D.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JContainer.hh"
#include "Jeep/JProperties.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

Auxiliary program to draw the footprint of detector(s).

Author
mdejong

Definition in file JDrawDetector2D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 179 of file JDrawDetector2D.cc.

180{
181 using namespace std;
182 using namespace JPP;
183
186
187 vector<string> detectorFile;
188 vector<string> tripodsFile;
189 vector<string> transmittersFile;
190 string outputFile;
191 JCanvas canvas;
192 JCircle2D focus;
193 string legend;
194 double markerSize;
195 double textSize;
196 bool drawCircle;
197 bool all;
198 bool batch;
199 int debug;
200
201 try {
202
203 JProperties properties;
204
205 properties["focus"] = focus;
206
207 JParser<> zap("Auxiliary program to draw the footprint of detector(s).");
208
209 zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
210 zap['@'] = make_field(properties, "properties") = JPARSER::initialised();
211 zap['a'] = make_field(detectorFile, "detector file") = JPARSER::initialised();
212 zap['T'] = make_field(tripodsFile, "tripod file") = JPARSER::initialised();
213 zap['Y'] = make_field(transmittersFile, "transmitter file") = JPARSER::initialised();
214 zap['o'] = make_field(outputFile, "graphics output") = "";
215 zap['L'] = make_field(legend, "position legend e.g. TR") = "", "TL", "TR", "BR", "BL";
216 zap['S'] = make_field(markerSize, "marker size") = 1.0;
217 zap['s'] = make_field(textSize, "text size") = 0.02;
218 zap['C'] = make_field(drawCircle, "draw smallest enclosing cicrle");
219 zap['A'] = make_field(all, "draw all modules");
220 zap['B'] = make_field(batch, "batch processing");
221 zap['d'] = make_field(debug) = 1;
222
223 zap(argc, argv);
224 }
225 catch(const exception &error) {
226 FATAL(error.what() << endl);
227 }
228
229
230 if (detectorFile.empty() && tripodsFile.empty()) {
231 FATAL("No detector elements." << endl);
232 }
233
234
235 gROOT->SetBatch(batch);
236
237 gErrorIgnoreLevel = kWarning;
238
239 TApplication* tp = new TApplication("user", NULL, NULL);
240 TCanvas* cv = new TCanvas("detector", "", canvas.x, canvas.y);
241
242 if (!batch) {
243 ((TRootCanvas *) cv->GetCanvasImp())->Connect("CloseWindow()", "TApplication", tp, "Terminate()");
244 }
245
246 unique_ptr<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh()));
247
248 gROOT->SetStyle("gplot");
249 gROOT->ForceStyle();
250
251 cv->SetFillStyle(4000);
252 cv->SetFillColor(kWhite);
253 cv->Divide(1, 1);
254 cv->cd(1);
255
256 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
257
258 vector<TAttText> text_attributes = {
259 TAttText(kHAlignLeft + kVAlignBottom, 0.25*PI, kBlack, 62, textSize),
260 TAttText(kHAlignRight + kVAlignBottom, 0.75*PI, kBlack, 62, textSize),
261 TAttText(kHAlignRight + kVAlignTop, 1.25*PI, kBlack, 62, textSize),
262 TAttText(kHAlignLeft + kVAlignTop, 1.75*PI, kBlack, 62, textSize)
263 };
264
265 map<string, JGraph_t> data; // graphics data
266 JUTMPosition position; // UTM position
267 double offset = 0.0; // text offset
268
269 for (size_t i = 0; i != detectorFile.size(); ++i) {
270
272
273 try {
274 load(detectorFile[i], detector);
275 }
276 catch(const JException& error) {
277 FATAL(error);
278 }
279
280 position = detector.getUTMPosition();
281
282 const TAttMarker& marker = *JMarkerAttributes::getInstance().next();
283 const TAttText& text = text_attributes[(0+i)%text_attributes.size()];
284 vector<JPoint_t>& buffer = data[getFilename(detectorFile[i])];
285
286 if (offset == 0.0) {
287 offset = 3.0 * textSize * JCircle2D(detector.begin(), detector.end()).getRadius();
288 }
289
290 set<int> counter;
291
292 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
293
294 if (module->getFloor() == 0) {
295
296 buffer.push_back(JPoint_t(MAKE_STRING(module->getString()),
297 JPosition2D(module->getX(), module->getY()),
298 marker,
299 text,
300 offset));
301
302 counter.insert(module->getString());
303 }
304 }
305
306 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
307
308 const bool status = (counter.count(module->getString()) == 0);
309
310 if (status || all) {
311
312 buffer.push_back(JPoint_t((status ? MAKE_STRING(module->getString()) : ""),
313 JPosition2D(module->getX(), module->getY()),
314 marker,
315 text,
316 offset));
317
318 counter.insert(module->getString());
319 }
320 }
321 }
322
323 for (size_t i = 0; i != tripodsFile.size(); ++i) {
324
325 tripods_container tripods;
326
327 tripods.load(tripodsFile[i].c_str());
328
329 const TAttMarker& marker = *JMarkerAttributes::getInstance().next();
330 const TAttText& text = text_attributes[(0+i)%text_attributes.size()];
331 vector<JPoint_t>& buffer = data[getFilename(tripodsFile[i])];
332
333 if (offset == 0.0) {
334 offset = 3.0 * textSize * JCircle2D(tripods.begin(), tripods.end()).getRadius();
335 }
336
337 for (tripods_container::iterator i = tripods.begin(); i != tripods.end(); ++i) {
338
339 buffer.push_back(JPoint_t(MAKE_STRING(i->getID()),
340 JPosition2D(i->getUTMEast() - position.getUTMEast(), i->getUTMNorth() - position.getUTMNorth()),
341 marker,
342 text,
343 offset));
344 }
345 }
346
347 if (!transmittersFile.empty()) {
348
349 if (transmittersFile.size() == detectorFile.size()) {
350
351 for (size_t i = 0; i != transmittersFile.size(); ++i) {
352
353 transmitters_container transmitters;
354
355 transmitters.load(transmittersFile[i].c_str());
356
358
359 load(detectorFile[i], detector);
360
361 const TAttMarker& marker = *JMarkerAttributes::getInstance().next();
362 const TAttText& text = text_attributes[(2+i)%text_attributes.size()];
363 vector<JPoint_t>& buffer = data[getFilename(transmittersFile[i])];
364
365 if (offset == 0.0) {
366 offset = 3.0 * textSize * JCircle2D(transmitters.begin(), transmitters.end()).getRadius();
367 }
368
369 for (transmitters_container::iterator i = transmitters.begin(); i != transmitters.end(); ++i) {
370
371 const JPosition3D pos = detector.getModule(i->getLocation()).getPosition();
372
373 buffer.push_back(JPoint_t(MAKE_STRING(i->getID()),
374 JPosition2D(pos.getX() + i->getX(), pos.getY() + i->getY()),
375 marker,
376 text,
377 offset));
378 }
379 }
380
381 } else {
382
383 FATAL("Tranmitter files and detector files should match one-to-one." << endl);
384 }
385 }
386
387 vector<JPosition2D> buffer;
388
389 for (map<string, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
390 copy(i->second.begin(), i->second.end(), back_inserter(buffer));
391 }
392
393 JCircle2D circle(buffer.begin(), buffer.end()); // enclosing circle
394
395 if (focus.getRadius() > 0.0) {
396 circle = focus;
397 }
398
399 NOTICE("focus = " << FIXED(12,3) << circle.getX() << ' ' << FIXED(12,3) << circle.getY() << ' ' << FIXED(9,3) << circle.getRadius() << endl);
400
401 // center
402
403 for (map<string, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
404 i->second.sub(circle.getX(), circle.getY());
405 }
406
407 circle.sub(circle.getPosition());
408
409
410 // draw
411
412 cv->cd(1);
413
414 const Double_t xmin = circle.getX() - 1.15 * circle.getRadius();
415 const Double_t xmax = circle.getX() + 1.15 * circle.getRadius();
416 const Double_t ymin = circle.getY() - 1.15 * circle.getRadius();
417 const Double_t ymax = circle.getY() + 1.15 * circle.getRadius();
418
419 TH2D h2("h2", "", 200, xmin, xmax, 200, ymin, ymax);
420
421 h2.GetXaxis()->SetTitle("x [m]");
422 h2.GetYaxis()->SetTitle("y [m]");
423
424 h2.GetXaxis()->CenterTitle(true);
425 h2.GetYaxis()->CenterTitle(true);
426
427 h2.SetStats(kFALSE);
428 h2.Draw("AXIS");
429
430
431 TEllipse ellipse(circle.getX(), circle.getY(), circle.getRadius());
432
433 if (drawCircle) {
434 ellipse.Draw();
435 }
436
437 for (map<string, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
438 i->second.Draw();
439 }
440
441 if (legend != "") {
442
443 Ssiz_t height = data.size();
444 Ssiz_t width = 1;
445
446 for (map<string, JGraph_t>::const_iterator i = data.begin(); i != data.end(); ++i) {
447 width = max(width, (Ssiz_t) i->first.size());
448 }
449
450 TLegend* lg = getLegend(width, height, legend);
451
452 lg->SetTextSize(textSize);
453
454 for (map<string, JGraph_t>::const_iterator i = data.begin(); i != data.end(); ++i) {
455 if (!i->second.empty()) {
456 lg->AddEntry(&i->second[0].marker, i->first.c_str(), "P");
457 }
458 }
459
460 lg->Draw();
461 }
462
463 cv->Update();
464
465 if (outputFile != "") {
466 cv->SaveAs(outputFile.c_str());
467 }
468
469 if (!batch) {
470 tp->Run();
471 }
472}
string outputFile
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Detector data structure.
Definition JDetector.hh:96
Utility class to parse parameter values.
Data structure for circle in two dimensions.
Definition JCircle2D.hh:35
double getRadius() const
Get radius.
Definition JCircle2D.hh:144
Data structure for position in two dimensions.
Data structure for position in three dimensions.
double getY() const
Get y position.
Definition JVector3D.hh:104
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
Data structure for UTM position.
double getUTMNorth() const
Get UTM north.
double getUTMEast() const
Get UTM east.
char text[TEXT_SIZE]
Definition elog.cc:72
const double xmax
const double xmin
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option, const Double_t factor=1.0)
Get legend.
Definition JLegend.hh:29
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:42
void load(const char *file_name)
Load from input file.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68