Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
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/JModuleRouter.hh"
#include "JDetector/JDetectorAddressMapToolkit.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. More...
 
TPaveText * p1 = NULL
 

Detailed Description

Auxiliary program to draw a given module in 3D.

Author
mdejong

Definition in file JDrawModule3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 109 of file JDrawModule3D.cc.

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 
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
void AddText(const std::string &text)
Add text to buffer.
TPaveText * p1
Data structure for a composite optical module.
Definition: JModule.hh:66
Detector data structure.
Definition: JDetector.hh:81
Router for direct addressing of module data in detector data structure.
#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
Lookup table for PMT addresses in optical module.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:42
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;]
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
#define FATAL(A)
Definition: JMessage.hh:67
TCanvas * c1
Global variables to handle mouse events.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
int position
position within ring [1,6]
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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

Variable Documentation

TCanvas* c1 = NULL

Global variables to handle mouse events.

Definition at line 34 of file JDrawModule3D.cc.

TPaveText* p1 = NULL

Definition at line 35 of file JDrawModule3D.cc.