Jpp
JDrawModule3D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <sstream>
4 #include <iomanip>
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 #include "TGeoTube.h"
17 #include "TGeoCone.h"
18 #include "TPaveText.h"
19 
20 #include "JTools/JConstants.hh"
21 #include "JDetector/JDetector.hh"
25 
26 #include "Jeep/JPrint.hh"
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 /**
32  * Global variables to handle mouse events.
33  */
34 TCanvas* c1 = NULL;
35 TPaveText* p1 = NULL;
36 
37 
38 /**
39  */
40 class JGeoVolume :
41  public TGeoVolume
42 {
43 public:
44  /**
45  * Constructor.
46  *
47  * \param name name
48  * \param shape shape
49  * \param med medium
50  */
51  JGeoVolume(const char* name,
52  const TGeoShape* shape,
53  const TGeoMedium* med = 0) :
54  TGeoVolume(name, shape, med)
55  {}
56 
57 
58  /**
59  * Mouse events.
60  *
61  * \param event event
62  * \param px x-position of mouse
63  * \param py y-position of mouse
64  */
65  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
66  {
67  if (event == kMouseEnter) {
68 
69  for (std::vector<std::string>::const_iterator i = buffer.begin(); i != buffer.end(); ++i)
70  p1->AddText(i->c_str());
71 
72  p1->Draw();
73  c1->Update();
74 
75  } else if (event == kMouseLeave) {
76 
77  p1->Clear();
78  p1->Draw();
79  c1->Update();
80 
81  } else {
82 
83  TGeoVolume::ExecuteEvent(event, px, py);
84  }
85  }
86 
87 
88  /**
89  * Add text to buffer.
90  *
91  * \param text text
92  */
93  void AddText(const std::string& text)
94  {
95  buffer.push_back(text);
96  }
97 
98 protected:
100 };
101 
102 
103 
104 /**
105  * \file
106  * Auxiliary program to draw a given module in 3D.
107  * \author mdejong
108  */
109 int main(int argc, char**argv)
110 {
111  using namespace std;
112 
113  string detectorFile;
114  int moduleID;
115  int debug;
116 
117  try {
118 
119  JParser<> zap("Auxiliary program to draw a given module in 3D.");
120 
121  zap['a'] = make_field(detectorFile);
122  zap['M'] = make_field(moduleID) = -1;
123  zap['d'] = make_field(debug) = 1;
124 
125  zap(argc, argv);
126  }
127  catch(const exception &error) {
128  FATAL(error.what() << endl);
129  }
130 
131 
132  using namespace JPP;
133 
134 
135  JDetector detector;
136 
137  try {
138  load(detectorFile, detector);
139  }
140  catch(const JException& error) {
141  FATAL(error);
142  }
143 
144  if (detector.empty()) {
145  FATAL("Empty detector.");
146  }
147 
148 
149  JModule module;
150 
151  if (moduleID == -1) {
152 
153  module = detector.front();
154 
155  } else {
156 
157  JModuleRouter router(detector);
158 
159  if (!router.hasModule(moduleID)) {
160  FATAL("Missing module " << moduleID << endl);
161  } else {
162  module = router.getModule(moduleID);
163  }
164  }
165 
166  module -= module.getPosition(); // ~center module
167 
168 
169  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
170  const JModuleAddressMap& memo = demo.get(module.getID());
171 
172 
173  TApplication* app = new TApplication("user", NULL, NULL);
174 
175  c1 = new TCanvas("module", detectorFile.c_str(), 600, 600);
176  p1 = new TPaveText(0.7, 0.9, 1.0, 1.0, "NB");
177 
178  c1->SetFillColor(0);
179 
180  p1->SetFillColor(0);
181  p1->SetBorderSize(0);
182  p1->SetTextSize(0.03);
183 
184  TGeoManager* gGeoManager = new TGeoManager("geometry", "");
185 
186  TGeoMaterial* mat = new TGeoMaterial("vacuum", 0, 0, 0);
187  TGeoMedium* med = new TGeoMedium ("vacuum", 1, mat);
188  TGeoVolume* top = gGeoManager->MakeBox("top", med, 30.0, 30.0, 30.0);
189 
190  // PMT
191  //
192  // ->dz<-
193  //
194  // _/|
195  // R1 |_ | R2
196  // \|
197  //
198  // ->dz<-
199 
200  const double dz = 3.0; // [cm]
201  const double R1 = 2.0; // [cm]
202  const double R2 = 4.0; // [cm]
203 
204 
205  const Int_t color[] = { kRed, kOrange, kYellow, kGreen, kBlue, kMagenta };
206 
207  for (unsigned int tdc = 0; tdc != module.size(); ++tdc) {
208 
209  const JPMTAddressTranslator& address = memo.getAddressTranslator(tdc);
210  const int index = address.ring - 'A';
211 
212  ostringstream os[2];
213 
214  os[0] << "PMT " << setw(1) << address.ring << setw(1) << address.position;
215  os[1] << "TDC " << setw(2) << tdc;
216 
217  TGeoVolumeAssembly* pPMT = new TGeoVolumeAssembly("PMT");
218 
219  JGeoVolume* pTube = new JGeoVolume("dynode", new TGeoTube("", 0.0, R1, 0.5 * dz), med);
220  JGeoVolume* pCone = new JGeoVolume("cathode", new TGeoCone("", 0.5 * dz, 0.0, R1, 0.0, R2), med);
221 
222  for (int i = 0; i != sizeof(os)/sizeof(os[0]); ++i) {
223  pTube->AddText(os[i].str());
224  pCone->AddText(os[i].str());
225  }
226 
227  pTube->SetLineColor(color[index]);
228  pCone->SetLineColor(color[index]);
229 
230  pPMT->AddNode(pTube, 0, new TGeoTranslation(0.0, 0.0, -dz));
231  pPMT->AddNode(pCone, 1, new TGeoTranslation(0.0, 0.0, 0.0));
232 
233  const JPMT& pmt = module.getPMT(tdc);
234 
235  const Double_t x = pmt.getX() * 100; // [cm]
236  const Double_t y = pmt.getY() * 100; // [cm]
237  const Double_t z = pmt.getZ() * 100; // [cm]
238 
239  const Double_t theta = pmt.getTheta() * 180.0 / PI; // [deg]
240  const Double_t phi = pmt.getPhi() * 180.0 / PI; // [deg]
241 
242  DEBUG("PMT" << " "
243  << setw(1) << address.ring
244  << setw(1) << address.position << " "
245  << " TDC "
246  << setw(2) << tdc << " "
247  << FIXED(3,0) << x << " [cm] "
248  << FIXED(3,0) << y << " [cm] "
249  << FIXED(3,0) << z << " [cm] "
250  << FIXED(4,0) << theta << " [deg] "
251  << FIXED(4,0) << phi << " [deg] "
252  << endl);
253 
254  TGeoRotation* rot = new TGeoRotation();
255 
256  rot->RotateY(theta);
257  rot->RotateZ(phi);
258 
259  top->AddNode(pPMT, tdc, new TGeoCombiTrans(x,y,z,rot));
260  }
261 
262  gGeoManager->SetTopVolume(top);
263  gGeoManager->CloseGeometry();
264 
265  top->Draw();
266 
267  c1->GetView()->ShowAxis();
268  c1->Update();
269 
270  app->Run();
271 }
JGeoVolume::buffer
std::vector< std::string > buffer
Definition: JDrawModule3D.cc:99
text
char text[TEXT_SIZE]
Definition: elog.cc:72
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JMessage.hh
JPrint.hh
JGeoVolume::JGeoVolume
JGeoVolume(const char *name, const TGeoShape *shape, const TGeoMedium *med=0)
Constructor.
Definition: JDrawModule3D.cc:51
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
c1
TCanvas * c1
Global variables to handle mouse events.
Definition: JDrawModule3D.cc:34
std::vector
Definition: JSTDTypes.hh:12
event
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Definition: JVoltageOptimizer_utils.hh:26
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JConstants.hh
JDetectorAddressMapToolkit.hh
JGeoVolume::AddText
void AddText(const std::string &text)
Add text to buffer.
Definition: JDrawModule3D.cc:93
JModuleRouter.hh
R1
#define R1(x)
JParser.hh
JGeoVolume::ExecuteEvent
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Mouse events.
Definition: JDrawModule3D.cc:65
JDetectorToolkit.hh
JGeoVolume
Definition: JDrawModule3D.cc:40
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
p1
TPaveText * p1
Definition: JDrawModule3D.cc:35
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JDETECTOR::JDetectorAddressMap::get
const JModuleAddressMap & get(const int id) const
Get module address map.
Definition: JDetectorAddressMap.hh:69
JDETECTOR::getDetectorAddressMap
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Definition: JDetectorAddressMapToolkit.hh:363
main
int main(int argc, char **argv)
Definition: JDrawModule3D.cc:109