Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JDrawModule3D.cc File Reference

Auxiliary program to draw a given module in 3D. More...

#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#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 "TGeoTube.h"
#include "TGeoCone.h"
#include "TPaveText.h"
#include "JMath/JConstants.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Classes

class  JGeoVolume
 

Functions

int main (int argc, char **argv)
 

Variables

TCanvas * c1 = NULL
 Global variables to handle mouse events.
 
TPaveText * p1 = NULL
 

Detailed Description

Auxiliary program to draw a given module in 3D.

Author
mdejong

Definition in file JDrawModule3D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 108 of file JDrawModule3D.cc.

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
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 << setw(8) << pmt.getID() << " "
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}
TCanvas * c1
Global variables to handle mouse events.
TPaveText * p1
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Lookup table for PMT addresses in detector.
const JModuleAddressMap & get(const int id) const
Get module address map.
Detector data structure.
Definition JDetector.hh:96
Lookup table for PMT addresses in optical module.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
Definition JModule.hh:75
int position
position within ring [1,6]
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
double getTheta() const
Get theta angle.
Definition JVersor3D.hh:128
double getPhi() const
Get phi angle.
Definition JVersor3D.hh:144
void AddText(const std::string &text)
Add text to buffer.
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
#define R1(x)
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Data structure to translate PMT physical to readout address.

Variable Documentation

◆ c1

TCanvas* c1 = NULL

Global variables to handle mouse events.

Definition at line 34 of file JDrawModule3D.cc.

◆ p1

TPaveText* p1 = NULL

Definition at line 35 of file JDrawModule3D.cc.