Jpp  18.3.0
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 #include <memory>
5 
6 #include "TROOT.h"
7 #include "TApplication.h"
8 #include "TCanvas.h"
9 #include "TView.h"
10 #include "TGeometry.h"
11 #include "TGeoManager.h"
12 #include "TGeoMatrix.h"
13 #include "TGeoMaterial.h"
14 #include "TGeoMedium.h"
15 #include "TGeoVolume.h"
16 
17 #include "JDetector/JDetector.hh"
19 
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  * Auxiliary program to draw the detector in 3D.
29  * \author mdejong
30  */
31 int main(int argc, char**argv)
32 {
33  using namespace std;
34  using namespace JPP;
35 
36  string detectorFile;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Auxiliary program to draw the detector in 3D.");
42 
43  zap['a'] = make_field(detectorFile);
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52 
53  JDetector detector;
54 
55  try {
56  load(detectorFile, detector);
57  }
58  catch(const JException& error) {
59  FATAL(error);
60  }
61 
62  if (detector.empty()) {
63  FATAL("Empty detector " << detectorFile << endl);
64  }
65 
66  JCylinder3D cylinder(detector.begin(), detector.end());
67 
68  NOTICE("Detector volume: " << cylinder << endl);
69 
70  TApplication* tp = new TApplication("user", NULL, NULL);
71  TCanvas* cv = new TCanvas("a", detectorFile.c_str(), 1200, 1200);
72 
73  cv->SetFillColor(0);
74 
75  TGeoManager* geom = new TGeoManager ("geometry", "");
76  TGeoMaterial* material = new TGeoMaterial("vacuum", 0, 0, 0);
77  TGeoMedium* medium = new TGeoMedium ("vacuum", 1, material);
78  TGeoVolume* top = geom->MakeBox ("Top", medium, cylinder.getRadius(), cylinder.getRadius(), cylinder.getZmax() - cylinder.getZmin());
79  TGeoVolume* shape = geom->MakeSphere("Module", medium, 0.4, 0.5);
80 
81  shape->SetLineColor(kBlue);
82 
83  int N = 0;
84 
85  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
86  top->AddNode(shape, N++, new TGeoTranslation(i->getX() - cylinder.getX(), i->getY() - cylinder.getY(), i->getZ() - cylinder.getZmin()));
87  }
88 
89  geom->SetTopVolume(top);
90  geom->CloseGeometry();
91  //geom->SetVisLevel(4);
92 
93  top->Draw();
94 
95  cv->GetView()->ShowAxis();
96  cv->Update();
97 
98  tp->Run();
99 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for detector geometry and calibration.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
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.
Utility class to parse command line options.
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level