Jpp
Functions
JDrawDetector2D.cc File Reference
#include <string>
#include <iostream>
#include <limits>
#include <vector>
#include "TROOT.h"
#include "TH2D.h"
#include "TApplication.h"
#include "TGraph.h"
#include "TEllipse.h"
#include "TCanvas.h"
#include "TMarker.h"
#include "TStyle.h"
#include "TLegend.h"
#include "JGizmo/JMarkerAttributes.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JGeometry2D/JPosition2D.hh"
#include "JGeometry2D/JCircle2D.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 31 of file JDrawDetector2D.cc.

32 {
33  using namespace std;
34 
35  vector<string> detectorFile;
36  bool legend;
37  double markerSize;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Auxiliary program to draw the footprint of detector(s).");
43 
44  zap['a'] = make_field(detectorFile);
45  zap['L'] = make_field(legend);
46  zap['S'] = make_field(markerSize) = 0.5;
47  zap['d'] = make_field(debug) = 1;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  using namespace JPP;
57 
58 
60 
61 
62  int npos = 0;
63 
64  vector<TGraph*> buffer;
65 
66  JCircle2D circle;
67 
68  for (vector<string>::const_iterator file_name = detectorFile.begin(); file_name != detectorFile.end(); ++file_name) {
69 
71 
72  try {
73  load(*file_name, detector);
74  }
75  catch(const JException& error) {
76  FATAL(error);
77  }
78 
79  if (detector.empty()) {
80  ERROR("Empty detector." << endl);
81  }
82 
83  circle = JCircle2D(detector.begin(), detector.end());
84 
85  TGraph* graph = new TGraph(detector.size());
86 
87  graph->SetTitle(file_name->c_str());
88 
89  int n = 0;
90 
91  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i, ++n) {
92 
93  npos += 1;
94 
95  graph->GetX()[n] = i->getX();
96  graph->GetY()[n] = i->getY();
97  }
98 
99  dynamic_cast<TAttMarker&>(*graph) = *JGIZMO::JMarkerAttributes::getInstance().next();
100 
101  buffer.push_back(graph);
102  }
103 
104 
105  if (npos == 0) {
106  FATAL("No detector elements." << endl);
107  }
108 
109 
110  DEBUG("Detector (x,y,R): " << circle.getX() << ' ' << circle.getY() << ' ' << circle.getRadius() << endl);
111 
112  for (vector<TGraph*>::iterator graph = buffer.begin(); graph != buffer.end(); ++graph) {
113  for (int i = 0; i != (*graph)->GetN(); ++i) {
114  (*graph)->GetX()[i] -= circle.getX();
115  (*graph)->GetY()[i] -= circle.getY();
116  }
117  }
118 
119  circle.sub(circle.getPosition());
120 
121  Double_t R = circle.getRadius();
122 
123  if (R <= 1.0) {
124  R = 1.0;
125  }
126 
127  Double_t xmin = circle.getX() - R;
128  Double_t xmax = circle.getX() + R;
129  Double_t ymin = circle.getY() - R;
130  Double_t ymax = circle.getY() + R;
131 
132 
133  TApplication* tp = new TApplication("user", NULL, NULL);
134 
135 
136  TCanvas cv("detector", "", 400, 400);
137 
138  cv.SetFillStyle(4000);
139  cv.SetFillColor(0);
140 
141  cv.Divide(1, 1);
142  cv.cd(1);
143 
144  const Double_t dx = (xmax - xmin);
145  const Double_t dy = (ymax - ymin);
146 
147  xmin -= 0.1 * dx;
148  xmax += 0.1 * dx;
149  ymin -= 0.1 * dy;
150  ymax += 0.1 * dy;
151 
152 
153  TH2D h2("h2", "", 1, xmin, xmax, 1, ymin, ymax);
154 
155  h2.GetXaxis()->SetTitle("x [m]");
156  h2.GetYaxis()->SetTitle("y [m]");
157 
158  h2.GetXaxis()->CenterTitle(true);
159  h2.GetYaxis()->CenterTitle(true);
160 
161  h2.SetStats(kFALSE);
162  h2.Draw();
163 
164 
165  TEllipse ellipse(circle.getX(), circle.getY(), circle.getRadius());
166 
167  ellipse.Draw();
168 
169  for (vector<TGraph*>::iterator graph = buffer.begin(); graph != buffer.end(); ++graph) {
170  (*graph)->Draw("P");
171  }
172 
173 
174  if (legend) {
175 
176  const Double_t x2 = gPad->GetX2() - gStyle->GetPadRightMargin();
177  const Double_t y2 = gPad->GetY2() - gStyle->GetPadTopMargin();
178 
179  size_t length = 10;
180  Double_t font_size = 0.03; // gStyle->GetStatFontSize();
181 
182  for (vector<TGraph*>::iterator graph = buffer.begin(); graph != buffer.end(); ++graph) {
183  length = max(length, strlen((*graph)->GetTitle()));
184  }
185 
186  TLegend* legend = new TLegend(x2 - length * font_size * 0.65 - 0.02,
187  y2 - buffer.size() * font_size,
188  x2 - 0.01,
189  y2 - 0.01);
190 
191  //legend->SetFillStyle(4000);
192  legend->SetFillColor(0);
193  legend->SetBorderSize(0);
194  legend->SetTextSize(font_size);
195 
196  for (vector<TGraph*>::iterator graph = buffer.begin(); graph != buffer.end(); ++graph) {
197  legend->AddEntry(*graph, (*graph)->GetTitle(), "P");
198  }
199 
200  legend->Draw();
201  }
202 
203  cv.Update();
204 
205  tp->Run();
206 }
JGEOMETRY2D::JPosition2D::getPosition
const JPosition2D & getPosition() const
Get position.
Definition: JPosition2D.hh:97
JGEOMETRY2D::JCircle2D
Data structure for circle in two dimensions.
Definition: JCircle2D.hh:29
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGEOMETRY2D::JCircle2D::getRadius
double getRadius() const
Get radius.
Definition: JCircle2D.hh:121
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
JGIZMO::JMarkerAttributes::setMarkerSize
void setMarkerSize(const Double_t size)
Set marker size.
Definition: JMarkerAttributes.hh:81
JGIZMO::JMarkerAttributes::next
virtual const pointer_type & next()
Get next element.
Definition: JMarkerAttributes.hh:114
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JGEOMETRY2D::JVector2D::sub
JVector2D & sub(const JVector2D &vector)
Subtract vector.
Definition: JVector2D.hh:114
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JGEOMETRY2D::JVector2D::getX
double getX() const
Get x position.
Definition: JVector2D.hh:62
JGEOMETRY2D::JVector2D::getY
double getY() const
Get y position.
Definition: JVector2D.hh:73
JGIZMO::JMarkerAttributes::getInstance
static JMarkerAttributes & getInstance()
Get reference to unique instance of this class object.
Definition: JMarkerAttributes.hh:68
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JLANG::JException
General exception.
Definition: JException.hh:23