Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDrawDetector3D.cc File Reference

Auxiliary program to draw the detector in 3D. More...

#include <string>
#include <iostream>
#include <limits>
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TView.h"
#include "TGeometry.h"
#include "TGeoManager.h"
#include "TGeoMatrix.h"
#include "TGeoMaterial.h"
#include "TGeoMedium.h"
#include "TGeoVolume.h"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to draw the detector in 3D.

Author
mdejong

Definition in file JDrawDetector3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file JDrawDetector3D.cc.

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 
50  JDetector detector;
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 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level