Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "JMath/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  * \file
105  * Auxiliary program to draw a given module in 3D.
106  * \author mdejong
107  */
108 int main(int argc, char**argv)
109 {
110  using namespace std;
111 
112  string detectorFile;
113  int moduleID;
114  int debug;
115 
116  try {
117 
118  JParser<> zap("Auxiliary program to draw a given module in 3D.");
119 
120  zap['a'] = make_field(detectorFile);
121  zap['M'] = make_field(moduleID) = -1;
122  zap['d'] = make_field(debug) = 1;
123 
124  zap(argc, argv);
125  }
126  catch(const exception &error) {
127  FATAL(error.what() << endl);
128  }
129 
130 
131  using namespace JPP;
132 
133 
135 
136  try {
137  load(detectorFile, detector);
138  }
139  catch(const JException& error) {
140  FATAL(error);
141  }
142 
143  if (detector.empty()) {
144  FATAL("Empty detector.");
145  }
146 
147 
148  JModule module;
149 
150  if (moduleID == -1) {
151 
152  module = detector.front();
153 
154  } else {
155 
156  JModuleRouter router(detector);
157 
158  if (!router.hasModule(moduleID)) {
159  FATAL("Missing module " << moduleID << endl);
160  } else {
161  module = router.getModule(moduleID);
162  }
163  }
164 
165  module -= module.getPosition(); // ~center module
166 
167 
168  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
169  const JModuleAddressMap& memo = demo.get(module.getID());
170 
171 
172  TApplication* app = new TApplication("user", NULL, NULL);
173 
174  c1 = new TCanvas("module", detectorFile.c_str(), 600, 600);
175  p1 = new TPaveText(0.7, 0.9, 1.0, 1.0, "NB");
176 
177  c1->SetFillColor(0);
178 
179  p1->SetFillColor(0);
180  p1->SetBorderSize(0);
181  p1->SetTextSize(0.03);
182 
183  TGeoManager* gGeoManager = new TGeoManager("geometry", "");
184 
185  TGeoMaterial* mat = new TGeoMaterial("vacuum", 0, 0, 0);
186  TGeoMedium* med = new TGeoMedium ("vacuum", 1, mat);
187  TGeoVolume* top = gGeoManager->MakeBox("top", med, 30.0, 30.0, 30.0);
188 
189  // PMT
190  //
191  // ->dz<-
192  //
193  // _/|
194  // R1 |_ | R2
195  // \|
196  //
197  // ->dz<-
198 
199  const double dz = 3.0; // [cm]
200  const double R1 = 2.0; // [cm]
201  const double R2 = 4.0; // [cm]
202 
203 
204  const Int_t color[] = { kRed, kOrange, kYellow, kGreen, kBlue, kMagenta };
205 
206  for (unsigned int tdc = 0; tdc != module.size(); ++tdc) {
207 
208  const JPMTAddressTranslator& address = memo.getAddressTranslator(tdc);
209  const int index = address.ring - 'A';
210 
211  ostringstream os[2];
212 
213  os[0] << "PMT " << setw(1) << address.ring << setw(1) << address.position;
214  os[1] << "TDC " << setw(2) << tdc;
215 
216  TGeoVolumeAssembly* pPMT = new TGeoVolumeAssembly("PMT");
217 
218  JGeoVolume* pTube = new JGeoVolume("dynode", new TGeoTube("", 0.0, R1, 0.5 * dz), med);
219  JGeoVolume* pCone = new JGeoVolume("cathode", new TGeoCone("", 0.5 * dz, 0.0, R1, 0.0, R2), med);
220 
221  for (int i = 0; i != sizeof(os)/sizeof(os[0]); ++i) {
222  pTube->AddText(os[i].str());
223  pCone->AddText(os[i].str());
224  }
225 
226  pTube->SetLineColor(color[index]);
227  pCone->SetLineColor(color[index]);
228 
229  pPMT->AddNode(pTube, 0, new TGeoTranslation(0.0, 0.0, -dz));
230  pPMT->AddNode(pCone, 1, new TGeoTranslation(0.0, 0.0, 0.0));
231 
232  const JPMT& pmt = module.getPMT(tdc);
233 
234  const Double_t x = pmt.getX() * 100; // [cm]
235  const Double_t y = pmt.getY() * 100; // [cm]
236  const Double_t z = pmt.getZ() * 100; // [cm]
237 
238  const Double_t theta = pmt.getTheta() * 180.0 / PI; // [deg]
239  const Double_t phi = pmt.getPhi() * 180.0 / PI; // [deg]
240 
241  DEBUG("PMT" << " "
242  << setw(1) << address.ring
243  << setw(1) << address.position << " "
244  << " TDC "
245  << setw(2) << tdc << " "
246  << FIXED(3,0) << x << " [cm] "
247  << FIXED(3,0) << y << " [cm] "
248  << FIXED(3,0) << z << " [cm] "
249  << FIXED(4,0) << theta << " [deg] "
250  << FIXED(4,0) << phi << " [deg] "
251  << endl);
252 
253  TGeoRotation* rot = new TGeoRotation();
254 
255  rot->RotateY(theta);
256  rot->RotateZ(phi);
257 
258  top->AddNode(pPMT, tdc, new TGeoCombiTrans(x,y,z,rot));
259  }
260 
261  gGeoManager->SetTopVolume(top);
262  gGeoManager->CloseGeometry();
263 
264  top->Draw();
265 
266  c1->GetView()->ShowAxis();
267  c1->Update();
268 
269  app->Run();
270 }
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
void AddText(const std::string &text)
Add text to buffer.
int main(int argc, char *argv[])
Definition: Main.cc:15
TPaveText * p1
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:68
char text[TEXT_SIZE]
Definition: elog.cc:72
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
#define R1(x)
Lookup table for PMT addresses in detector.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
Data structure for detector geometry and calibration.
std::vector< std::string > buffer
Lookup table for PMT addresses in optical module.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Mathematical constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
then awk string
static const double PI
Mathematical constants.
Data structure to translate PMT physical to readout address.
double getY() const
Get y position.
Definition: JVector3D.hh:104
char ring
ring number [&#39;A&#39;,&#39;F&#39;]
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
TCanvas * c1
Global variables to handle mouse events.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
int position
position within ring [1,6]
JGeoVolume(const char *name, const TGeoShape *shape, const TGeoMedium *med=0)
Constructor.
bool hasModule(const JObjectID &id) const
Has module.
double getX() const
Get x position.
Definition: JVector3D.hh:94
do set_variable DETECTOR_TXT $WORKDIR detector
double getZ() const
Get z position.
Definition: JVector3D.hh:115
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Mouse events.