Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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 "TROOT.h"
#include "TH2D.h"
#include "TApplication.h"
#include "TGraph.h"
#include "TEllipse.h"
#include "TCanvas.h"
#include "TMarker.h"
#include "TText.h"
#include "TStyle.h"
#include "TLegend.h"
#include "TError.h"
#include "JLang/JSinglePointer.hh"
#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 "JGeometry2D/JPosition2D.hh"
#include "JGeometry2D/JCircle2D.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JContainer.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

int main ( int  argc,
char **  argv 
)

Definition at line 167 of file JDrawDetector2D.cc.

168 {
169  using namespace std;
170  using namespace JPP;
171 
172  typedef JContainer< vector<JTripod> > tripods_container;
173 
174  vector<string> detectorFile;
175  vector<string> tripodsFile;
176  string outputFile;
177  JCanvas canvas;
178  string legend;
179  double markerSize;
180  double textSize;
181  bool drawCircle;
182  bool batch;
183  int debug;
184 
185  try {
186 
187  JParser<> zap("Auxiliary program to draw the footprint of detector(s).");
188 
189  zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
190  zap['a'] = make_field(detectorFile, "detector file") = JPARSER::initialised();
191  zap['T'] = make_field(tripodsFile, "tripod file") = JPARSER::initialised();
192  zap['o'] = make_field(outputFile, "graphics output") = "";
193  zap['L'] = make_field(legend, "position legend e.g. TR") = "", "TL", "TR", "BR", "BL";
194  zap['S'] = make_field(markerSize, "marker size") = 1.0;
195  zap['s'] = make_field(textSize, "text size") = 0.02;
196  zap['C'] = make_field(drawCircle, "draw smallest enclosing cicrle");
197  zap['B'] = make_field(batch, "batch processing");
198  zap['d'] = make_field(debug) = 1;
199 
200  zap(argc, argv);
201  }
202  catch(const exception &error) {
203  FATAL(error.what() << endl);
204  }
205 
206 
207  if (detectorFile.empty() && tripodsFile.empty()) {
208  FATAL("No detector elements." << endl);
209  }
210 
211 
212  gROOT->SetBatch(batch);
213 
214  gErrorIgnoreLevel = kWarning;
215 
216  TApplication* tp = new TApplication("user", NULL, NULL);
217  TCanvas* cv = new TCanvas("detector", "", canvas.x, canvas.y);
218 
219  JSinglePointer<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh()));
220 
221  gROOT->SetStyle("gplot");
222  gROOT->ForceStyle();
223 
224  cv->SetFillStyle(4000);
225  cv->SetFillColor(kWhite);
226  cv->Divide(1, 1);
227  cv->cd(1);
228 
229  JMarkerAttributes::getInstance().setMarkerSize(markerSize);
230 
231  vector<TAttText> text_attributes = {
232  TAttText(kHAlignLeft + kVAlignBottom, 0.25*PI, kBlack, 62, textSize),
233  TAttText(kHAlignRight + kVAlignBottom, 0.75*PI, kBlack, 62, textSize),
234  TAttText(kHAlignRight + kVAlignTop, 1.25*PI, kBlack, 62, textSize),
235  TAttText(kHAlignLeft + kVAlignTop, 1.75*PI, kBlack, 62, textSize)
236  };
237 
238  map<string, JGraph_t> data; // graphics data
239  JCircle2D circle; // enclosing circle
240  JUTMPosition position; // UTM position
241 
242  for (size_t i = 0; i != detectorFile.size(); ++i) {
243 
245 
246  try {
247  load(detectorFile[i], detector);
248  }
249  catch(const JException& error) {
250  FATAL(error);
251  }
252 
253  JCircle2D c1(detector.begin(), detector.end());
254 
255  if (c1.getRadius() > circle.getRadius()) {
256  circle = c1;
257  }
258 
259  position = detector.getUTMPosition();
260 
261  const TAttMarker& marker = *JMarkerAttributes::getInstance().next();
262  const TAttText& text = text_attributes[i%text_attributes.size()];
263 
264  vector<JPoint_t>& buffer = data[getFilename(detectorFile[i])];
265 
266  set<int> counter;
267 
268  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
269 
270  if (counter.count(module->getString()) == 0) {
271 
272  buffer.push_back(JPoint_t(module->getString(),
273  module->getX(),
274  module->getY(),
275  marker,
276  text,
277  3.0 * textSize * c1.getRadius()));
278 
279  counter.insert(module->getString());
280  }
281  }
282  }
283 
284  for (size_t i = 0; i != tripodsFile.size(); ++i) {
285 
286  tripods_container tripods;
287 
288  ifstream in(tripodsFile[i].c_str());
289 
290  in >> tripods;
291 
292  in.close();
293 
294  if (detectorFile.empty()) {
295  position = getAverage(make_array(tripods.begin(), tripods.end(), &JTripod::getUTMPosition));
296  }
297 
298  JCircle2D c1(make_array(tripods.begin(), tripods.end(), &JTripod::getPosition));
299 
300  c1.sub(position.getPosition());
301 
302  if (c1.getRadius() > circle.getRadius()) {
303  circle = c1;
304  }
305 
306  const TAttMarker& marker = *JMarkerAttributes::getInstance().next();
307  const TAttText& text = text_attributes[i%text_attributes.size()];
308 
309  vector<JPoint_t>& buffer = data[getFilename(tripodsFile[i])];
310 
311  for (tripods_container::iterator i = tripods.begin(); i != tripods.end(); ++i) {
312 
313  buffer.push_back(JPoint_t(i->getID(),
314  i->getUTMEast() - position.getUTMEast(),
315  i->getUTMNorth() - position.getUTMNorth(),
316  marker,
317  text,
318  3.0 * textSize * c1.getRadius()));
319  }
320  }
321 
322 
323  DEBUG("Detector (x,y,R): " << FIXED(12,3) << circle.getX() << ' ' << FIXED(12,3) << circle.getY() << ' ' << FIXED(9,3) << circle.getRadius() << endl);
324 
325  // center
326 
327  for (map<string, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
328  i->second.sub(circle.getX(), circle.getY());
329  }
330 
331  circle.sub(circle.getPosition());
332 
333 
334  // draw
335 
336  cv->cd(1);
337 
338  const Double_t xmin = circle.getX() - 1.15 * circle.getRadius();
339  const Double_t xmax = circle.getX() + 1.15 * circle.getRadius();
340  const Double_t ymin = circle.getY() - 1.15 * circle.getRadius();
341  const Double_t ymax = circle.getY() + 1.15 * circle.getRadius();
342 
343  TH2D h2("h2", "", 1, xmin, xmax, 1, ymin, ymax);
344 
345  h2.GetXaxis()->SetTitle("x [m]");
346  h2.GetYaxis()->SetTitle("y [m]");
347 
348  h2.GetXaxis()->CenterTitle(true);
349  h2.GetYaxis()->CenterTitle(true);
350 
351  h2.SetStats(kFALSE);
352  h2.Draw("AXIS");
353 
354 
355  TEllipse ellipse(circle.getX(), circle.getY(), circle.getRadius());
356 
357  if (drawCircle) {
358  ellipse.Draw();
359  }
360 
361  for (map<string, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
362  i->second.Draw();
363  }
364 
365  if (legend != "") {
366 
367  Ssiz_t height = data.size();
368  Ssiz_t width = 1;
369 
370  for (map<string, JGraph_t>::const_iterator i = data.begin(); i != data.end(); ++i) {
371  width = max(width, (Ssiz_t) i->first.size());
372  }
373 
374  TLegend* lg = getLegend(width, height, legend);
375 
376  lg->SetTextSize(textSize);
377 
378  for (map<string, JGraph_t>::const_iterator i = data.begin(); i != data.end(); ++i) {
379  if (!i->second.empty()) {
380  lg->AddEntry(&i->second[0].marker, i->first.c_str(), "P");
381  }
382  }
383 
384  lg->Draw();
385  }
386 
387  cv->Update();
388 
389  if (outputFile != "") {
390  cv->SaveAs(outputFile.c_str());
391  }
392 
393  if (!batch) {
394  tp->Run();
395  }
396 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
char text[TEXT_SIZE]
Definition: elog.cc:72
const JUTMPosition & getUTMPosition() const
Get UTM position.
Definition: JUTMPosition.hh:84
Data structure for circle in two dimensions.
Definition: JCircle2D.hh:33
Detector data structure.
Definition: JDetector.hh:81
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
Data structure for UTM position.
Definition: JUTMPosition.hh:36
The template JSinglePointer class can be used to hold a pointer to an object.
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
JPosition3D getPosition(const Vec &pos)
Get position.
static const double PI
Mathematical constants.
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
TCanvas * c1
Global variables to handle mouse events.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option="TR")
Get legend.
Definition: JLegend.hh:28
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:88
do set_variable DETECTOR_TXT $WORKDIR detector
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
Wrapper class around ROOT TStyle.
Definition: JStyle.hh:20
Data structure for size of TCanvas.
Definition: JCanvas.hh:26