GEMC  1.8
Geant4 Monte-Carlo Framework
detector_editor.cc
Go to the documentation of this file.
1 // %%%%%%%%%%
2 // Qt headers
3 // %%%%%%%%%%
4 #include <QtGui>
5 
6 // %%%%%%%%%%
7 // G4 headers
8 // %%%%%%%%%%
9 #include "G4UnitsTable.hh"
10 
11 // %%%%%%%%%%%%%
12 // gemc headers
13 // %%%%%%%%%%%%%
14 #include "detector_editor.h"
15 #include "images/g4Box_xpm.h"
16 #include "images/g4Cons_xpm.h"
17 #include "images/g4Polycone_xmp.h"
18 #include "images/g4Sphere_xpm.h"
19 #include "images/g4Trd_xpm.h"
20 #include "images/g4Trap_xpm.h"
21 #include "images/g4Tubs_xpm.h"
22 #include "images/g4Torus_xpm.h"
24 #include "images/copy_xpm.h"
25 #include "images/operation_xpm.h"
26 #include "string_utilities.h"
27 
28 
29 // %%%%%%%%%%%
30 // C++ headers
31 // %%%%%%%%%%%
32 #include <iostream>
33 #include <sstream>
34 using namespace std;
35 
37 {
38  Detector = detect;
39  tabWidget = new QTabWidget;
40  tabWidget->addTab(new PlacementTab(Detector), tr("Placement"));
41  tabWidget->addTab(new DimensionsTab(Detector), tr("Dimensions"));
42  tabWidget->addTab(new SensitivityTab(Detector), tr("Material, Sensitivity"));
43 
44  buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
45  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
46  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
47 
48  QVBoxLayout *mainLayout = new QVBoxLayout;
49  mainLayout->addWidget(tabWidget);
50  mainLayout->addWidget(buttonBox);
51  setLayout(mainLayout);
52 
53  setWindowTitle(tr("Detector Editor"));
54 }
55 
57 {
58  Detector = detect;
59  QLabel *dNameLabel = new QLabel(tr("Volume Name:"));
60  QLineEdit *dNameEdit = new QLineEdit(Detector->name.c_str());
61  QLabel *solidType = new QLabel(detect->type.c_str());
62  solidType->setFrameStyle(QFrame::Panel | QFrame::Sunken);
63 
64  stringstream Dim;
65  string d1, d2, dtot;
66  Dim.clear();
67  QLabel *placeXLabel = new QLabel("X Position");
68  Dim << G4BestUnit(Detector->pos.getX(), "Length");
69  Dim >> d1 >> d2;
70  dtot = d1 + "*" + d2 ;
71  placeXEdit = new QLineEdit(dtot.c_str());
72 
73  Dim.clear();
74  QLabel *placeYLabel = new QLabel("Y Position");
75  Dim << G4BestUnit(Detector->pos.getY(), "Length");
76  Dim >> d1 >> d2;
77  dtot = d1 + "*" + d2 ;
78  placeYEdit = new QLineEdit(dtot.c_str());
79 
80  Dim.clear();
81  QLabel *placeZLabel = new QLabel("Z Position");
82  Dim << G4BestUnit(Detector->pos.getZ(), "Length");
83  Dim >> d1 >> d2;
84  dtot = d1 + "*" + d2 ;
85  placeZEdit = new QLineEdit(dtot.c_str());
86 
87  Dim.clear();
88  QLabel *rotXLabel = new QLabel("Euler Phi Rotation");
89  Dim << G4BestUnit(Detector->rot.getPhi(), "Angle");
90  Dim >> d1 >> d2;
91  dtot = d1 + "*" + d2 ;
92  rotXEdit = new QLineEdit(dtot.c_str());
93 
94  Dim.clear();
95  QLabel *rotYLabel = new QLabel("Euler theta Rotation");
96  Dim << G4BestUnit(Detector->rot.getTheta(), "Angle");
97  Dim >> d1 >> d2;
98  dtot = d1 + "*" + d2 ;
99  rotYEdit = new QLineEdit(dtot.c_str());
100 
101  Dim.clear();
102  QLabel *rotZLabel = new QLabel("Euler psi Rotation");
103  Dim << G4BestUnit(Detector->rot.getPsi(), "Angle");
104  Dim >> d1 >> d2;
105  dtot = d1 + "*" + d2 ;
106  rotZEdit = new QLineEdit(dtot.c_str());
107 
108 
109  QVBoxLayout *mainLayout = new QVBoxLayout;
110  mainLayout->addWidget(dNameLabel);
111  mainLayout->addWidget(dNameEdit);
112  mainLayout->addWidget(placeXLabel);
113  mainLayout->addWidget(placeXEdit);
114  mainLayout->addWidget(placeYLabel);
115  mainLayout->addWidget(placeYEdit);
116  mainLayout->addWidget(placeZLabel);
117  mainLayout->addWidget(placeZEdit);
118  mainLayout->addSpacing(50);
119  mainLayout->addWidget(rotXLabel);
120  mainLayout->addWidget(rotXEdit);
121  mainLayout->addWidget(rotYLabel);
122  mainLayout->addWidget(rotYEdit);
123  mainLayout->addWidget(rotZLabel);
124  mainLayout->addWidget(rotZEdit);
125 
126  setLayout(mainLayout);
127  connect ( dNameEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_dname(QString) ) );
128  connect ( placeXEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
129  connect ( placeYEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
130  connect ( placeZEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
131 
132 }
133 
134 
136 {
137  string what;
138  Detector = detect;
139 
140  what = "Volume Name: " + Detector->name;
141  QLabel *dNameLabel = new QLabel(what.c_str());
142 
143  what = "Description: " + Detector->description;
144  QLabel *dDescLabel = new QLabel(what.c_str());
145 
146  what = "Material: " + Detector->material;
147  QLabel *dMateLabel = new QLabel(what.c_str());
148 
149  what = "Magnetic Field: " + Detector->magfield;
150  QLabel *dMagfLabel = new QLabel(what.c_str());
151 
152  what = "Sensitivity, bank: " + Detector->sensitivity;
153  QLabel *dSensLabel = new QLabel(what.c_str());
154 
155 
156 
157  QLabel *dHitLabel, *dIdenLabel;
158  dHitLabel = NULL;
159  dIdenLabel = NULL;
160 
161  if(Detector->identity.size())
162  {
163  what = "Hit Type: " + Detector->hitType;
164  dHitLabel = new QLabel(what.c_str());
165 
166  what = "Identifier: " ;
167  for(unsigned int i=0; i<Detector->identity.size(); i++)
168  what = what + Detector->identity[i].name + " " + stringify(Detector->identity[i].id) + " ";
169  dIdenLabel = new QLabel(what.c_str());
170  }
171 
172  QVBoxLayout *mainLayout = new QVBoxLayout;
173  mainLayout->addWidget(dNameLabel);
174  mainLayout->addWidget(dDescLabel);
175  mainLayout->addWidget(dMateLabel);
176  mainLayout->addWidget(dMagfLabel);
177  mainLayout->addWidget(dSensLabel);
178  if(Detector->identity.size())
179  {
180  mainLayout->addWidget(dHitLabel);
181  mainLayout->addWidget(dIdenLabel);
182  }
183 
184  setLayout(mainLayout);
185 
186 }
187 
188 
189 
190 
191 void PlacementTab::change_dname(QString dname)
192 {
193  Detector->name = gemc_tostring(dname);
194 }
195 
196 
198 {
199  Detector = detect;
200  QLabel *solidType = new QLabel(detect->type.c_str());
201  solidType->setFrameStyle(QFrame::Panel | QFrame::Sunken);
202  vector< vector<string> > dimTypes = dimensionstype(Detector->type);
203  for(unsigned int i=0; i<dimTypes.size(); i++)
204  {
205  stringstream Dim;
206  string d1, d2, dtot;
207  Dim << G4BestUnit(Detector->dimensions[i], dimTypes[i][1]);
208  Dim >> d1 >> d2;
209  dtot = d1 + "*" + d2 ;
210  dimTypesLabel.push_back(new QLabel(dimTypes[i][0].c_str()));
211  dimTypesEdit.push_back(new QLineEdit(dtot.c_str()));
212  }
213  QPixmap solidpic;
214  if(Detector->type == "Box") solidpic = QPixmap(g4Box_xpm);
215  if(Detector->type == "Cons") solidpic = QPixmap(g4Cons_xpm);
216  if(Detector->type == "G4Trap") solidpic = QPixmap(g4Trap_xpm);
217  if(Detector->type == "ITrd") solidpic = QPixmap(g4Trap_xpm);
218  if(Detector->type == "Polycone") solidpic = QPixmap(g4Polycone_xpm);
219  if(Detector->type == "Tube") solidpic = QPixmap(g4Tubs_xpm);
220  if(Detector->type == "Sphere") solidpic = QPixmap(g4Sphere_xpm);
221  if(Detector->type == "Trd") solidpic = QPixmap(g4Trd_xpm);
222  if(Detector->type == "Ellipsoid") solidpic = QPixmap(g4EllipticalTube_xpm);
223  if(Detector->type == "Torus") solidpic = QPixmap(g4Torus_xpm);
224  if(Detector->type.find("CopyOf") != string::npos) solidpic = QPixmap(copy_xpm);
225  if(Detector->type.find("Operation:") != string::npos) solidpic = QPixmap(operation_xpm);
226 
227  QLabel *solidPicL = new QLabel();
228  solidPicL->setPixmap(solidpic);
229 
230  QWidget *VPlacements = new QWidget(this);
231 
232  QVBoxLayout *mainLayout = new QVBoxLayout;
233  mainLayout->addWidget(solidType);
234  for(unsigned int i=0; i<dimTypes.size(); i++)
235  {
236  mainLayout-> addWidget( dimTypesLabel[i]);
237  mainLayout-> addWidget( dimTypesEdit[i]);
238  }
239  VPlacements ->setLayout(mainLayout);
240  VPlacements->show();
241 
242 
243  QHBoxLayout *viewLayout = new QHBoxLayout(this);
244  viewLayout->addWidget(VPlacements);
245  viewLayout->addWidget(solidPicL);
246 
247  for(unsigned int i=0; i<dimTypes.size(); i++)
248  {
249  mainLayout-> addWidget( dimTypesLabel[i]);
250  mainLayout-> addWidget( dimTypesEdit[i]);
251  connect ( dimTypesEdit[i] , SIGNAL( textChanged (QString) ), this, SLOT( change_dimension() ) );
252  }
253 
254 }
255 
256 void DimensionsTab::change_dimension()
257 {
258  vector<double> newdimensions;
259  vector< vector<string> > dimTypes = dimensionstype(Detector->type);
260  for(unsigned int i=0; i<dimTypes.size(); i++)
261  newdimensions.push_back(get_number(gemc_tostring(dimTypesEdit[i]->text())));
262  Detector->dimensions = newdimensions;
263 
264 }
265 
266 
267 void PlacementTab::change_placement()
268 {
269 
270  double x = get_number(gemc_tostring(placeXEdit->text()));
271  double y = get_number(gemc_tostring(placeYEdit->text()));
272  double z = get_number(gemc_tostring(placeZEdit->text()));
273 
274  G4ThreeVector newpos(x, y, z);
275 
276  // for(int i=0; i<dimTypes.size(); i++)
277  // newdimensions.push_back(get_number(gemc_tostring(dimTypesEdit[i]->text())));
278  Detector->pos = newpos;
279 
280 }
281 
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 
292 
QLabel * rotXLabel
label for x rotation
vector< QLineEdit * > dimTypesEdit
vector of line editor for dimension. Size depends on solid type
PlacementTab(detector *, QWidget *parent=0)
Constructor.
QLineEdit * rotYEdit
line editor for y rotation
QLineEdit * placeYEdit
line editor for y position
detector * Detector
pointer to detector
QLabel * rotZLabel
label for z rotation
string sensitivity
Defines the Sensitive Detector. possible choices: "no" "hits collection name".
Definition: detector.h:75
QLabel * placeYLabel
label for y position
QLabel * placeZLabel
label for z position
vector< QLabel * > dimTypesLabel
vector of label for dimension. Size depends on solid type
STL namespace.
G4ThreeVector pos
Position relative to the mother volume, as G4ThreeVector.
Definition: detector.h:57
string gemc_tostring(QString input)
DimensionsTab(detector *, QWidget *parent=0)
Constructor.
QLineEdit * placeXEdit
line editor for x position
vector< vector< string > > dimensionstype(string solidtype)
Returns dimensions nomenclature for different solid type.
Definition: detector.cc:803
string stringify(double x)
string name
Name of the volume. Since this is the key of the STL map, it has to be unique.
Definition: detector.h:53
QLabel * placeXLabel
label for x position
SensitivityTab(detector *, QWidget *parent=0)
Constructor.
QLabel * rotYLabel
label for y rotation
string material
Volume Material name.
Definition: detector.h:65
detector * Detector
Pointer to detector object.
string hitType
Hit Process routine name. A Hit Process MPHBaseClass derived class must exists with this name...
Definition: detector.h:76
vector< identifier > identity
Vector of identifiers. Example: superlayer manual 1 type manual 2 segment manual 3 strip manual 4...
Definition: detector.h:77
detector * Detector
Pointer to detector object.
string magfield
Magnetic Field. The string "no" means that the field is inherited from the mother volume...
Definition: detector.h:66
QLineEdit * rotZEdit
line editor for z rotation
detector * Detector
pointer to detector
G4RotationMatrix rot
Rotation Matrix, defined by rotations along x,y,z axis relative to the mother volume.
Definition: detector.h:58
string type
solid type. This follows the GEANT4 definitions
Definition: detector.h:62
vector< double > dimensions
vector of dimensions. Size, units depends on solid type
Definition: detector.h:63
QLineEdit * rotXEdit
line editor for x rotation
double get_number(string)
Returns dimension from string, i.e. 100*cm.
DetectorEditor(detector *, QWidget *parent=0)
Constructor.
QLineEdit * placeZEdit
line editor for z position
string description
Volume Description for documentation.
Definition: detector.h:55