Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDrawDetector3D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <limits>
4 
5 #include "TROOT.h"
6 #include "TApplication.h"
7 #include "TCanvas.h"
8 #include "TView.h"
9 #include "TGeometry.h"
10 #include "TGeoManager.h"
11 #include "TGeoMatrix.h"
12 #include "TGeoMaterial.h"
13 #include "TGeoMedium.h"
14 #include "TGeoVolume.h"
15 
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 #include "JDetector/JDetector.hh"
20 
21 
22 /**
23  * \file
24  * Auxiliary program to draw the detector in 3D.
25  * \author mdejong
26  */
27 int main(int argc, char**argv)
28 {
29  using namespace std;
30 
31  string detectorFile;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Auxiliary program to draw the detector in 3D.");
37 
38  zap['a'] = make_field(detectorFile);
39  zap['d'] = make_field(debug) = 1;
40 
41  zap(argc, argv);
42  }
43  catch(const exception &error) {
44  FATAL(error.what() << endl);
45  }
46 
47 
48  using namespace JPP;
49 
51 
52  try {
53  load(detectorFile, detector);
54  }
55  catch(const JException& error) {
56  FATAL(error);
57  }
58 
59  if (!detector.empty()) {
60 
61  JPosition3D pos(0.0, 0.0, 0.0);
62 
63  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
64  pos += *i;
65  }
66 
67  pos /= detector.size();
68 
69  NOTICE("Detector center: " << pos.getX() << ' ' << pos.getY() << ' ' << pos.getZ() << endl);
70 
71  double zmin = numeric_limits<double>::max();
72  double zmax = numeric_limits<double>::lowest();
73 
74  double radius = 0.0;
75 
76  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
77 
78  const double x = i->getX() - pos.getX();
79  const double y = i->getY() - pos.getY();
80  const double z = i->getZ() - pos.getZ();
81 
82  const double R = sqrt(x*x + y*y);
83 
84  if (z < zmin) zmin = z;
85  if (z > zmax) zmax = z;
86 
87  if (R > radius) radius = R;
88  }
89 
90  NOTICE("can: " << zmin << ' ' << zmax << ' ' << radius << endl);
91  }
92 
93 
94  double xmax = 0.0;
95  double ymax = 0.0;
96  double zmax = 0.0;
97 
98  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
99  if (i->getX() > xmax) xmax = i->getX();
100  if (i->getY() > ymax) ymax = i->getY();
101  if (i->getZ() > zmax) zmax = i->getZ();
102  }
103 
104  xmax *= 2.5;
105  ymax *= 2.5;
106  zmax *= 2.5;
107 
108 
109  TApplication* tapple = new TApplication("user", NULL, NULL);
110  TCanvas* canvas = new TCanvas("a", detectorFile.c_str(), 1200, 1200);
111 
112  canvas->SetFillColor(0);
113 
114  TGeoManager* geom = new TGeoManager ("geometry", "");
115  TGeoMaterial* material = new TGeoMaterial("vacuum", 0, 0, 0);
116  TGeoMedium* medium = new TGeoMedium ("vacuum", 1, material);
117  TGeoVolume* top = geom->MakeBox ("Top", medium, xmax, ymax, zmax);
118  TGeoVolume* shape = geom->MakeSphere("Module", medium, 0.4, 0.5);
119 
120  shape->SetLineColor(kBlue);
121 
122  int N = 0;
123 
124  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
125  top->AddNode(shape, N++, new TGeoTranslation(i->getX(), i->getY(), i->getZ()));
126  }
127 
128  geom->SetTopVolume(top);
129  geom->CloseGeometry();
130  //geom->SetVisLevel(4);
131 
132  top->Draw();
133 
134  canvas->GetView()->ShowAxis();
135  canvas->Update();
136  tapple->Run();
137 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
Detector data structure.
Definition: JDetector.hh:89
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Data structure for detector geometry and calibration.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
double getX() const
Get x position.
Definition: JVector3D.hh:94
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
do set_variable DETECTOR_TXT $WORKDIR detector
double getZ() const
Get z position.
Definition: JVector3D.hh:115