Geant4  10.00.p02
DetectorConstruction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: DetectorConstruction.cc 68726 2013-04-05 09:35:20Z gcosmo $
27 //
30 
31 #include "DetectorConstruction.hh"
32 #include "DetectorMessenger.hh"
33 
34 #include "G4Material.hh"
35 #include "G4NistManager.hh"
36 #include "G4Tubs.hh"
37 #include "G4Trd.hh"
38 #include "G4LogicalVolume.hh"
39 #include "G4PVPlacement.hh"
40 #include "G4Transform3D.hh"
41 #include "G4RotationMatrix.hh"
42 #include "G4ReflectionFactory.hh"
43 
44 #include "G4GeometryManager.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4LogicalVolumeStore.hh"
47 #include "G4SolidStore.hh"
48 #include "G4PhysicalConstants.hh"
49 #include "G4SystemOfUnits.hh"
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
55  fMessenger(0),
56  fMethod(kWithDirectMatrix),
57  fWorldVolume(0),
58  fTrdVolume(0)
59 
60 {
61  fMessenger = new DetectorMessenger(this);
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  delete fMessenger;
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
74 {
75  // Materials
77  G4Material* material = nist->FindOrBuildMaterial("G4_AIR");
78 
79  // Clean old geometry, if any
80  //
85 
86  // World
87  //
88  G4double rmin = 0.;
89  G4double rmax = 5*cm;
90  G4double hz = 5*cm;
91  G4double phiMin = 0.;
92  G4double deltaPhi = 360*degree;
93 
95  = new G4Tubs("World", //name
96  rmin, rmax, hz, phiMin, deltaPhi); //size
97 
99  = new G4LogicalVolume(solidWorld, //solid
100  material, //material
101  "World"); //name
102 
104  = new G4PVPlacement(0, //no rotation
105  G4ThreeVector(), //at (0,0,0)
106  fWorldVolume, //logical volume
107  "World", //name
108  0, //mother volume
109  false, //no boolean operation
110  0); //copy number
111 
112  // Trd volume
113  //
114  G4double dX1 = 1*cm;
115  G4double dX2 = 1*cm;
116  G4double dY1 = 1*cm;
117  G4double dY2 = 2*cm;
118  G4double dZ = 3*cm;
119 
120  G4Trd* solidTrd
121  = new G4Trd("trd", //name
122  dX1/2, dX2/2, dY1/2, dY2/2, dZ/2); //size
123 
124  fTrdVolume
125  = new G4LogicalVolume(solidTrd, //solid
126  material, //material
127  "trd"); //name
128 
129 
130  // Place Volume1 and Volume2 according to selected methods
131  //
132  switch ( fMethod ) {
136  case kWithEulerAngles: PlaceWithEulerAngles(); break;
137  case kWithReflections: PlaceWithReflections(); break;
138  default: ;;
139  }
140 
141  // Return the root volume
142  //
143  return physiWorld;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
149 {
150  G4double og = 3*cm;
151 
152  // 1st position
153  //
154  G4double phi = 30*deg;
155  // u, v, w are the daughter axes, projected on the mother frame
156  G4ThreeVector u = G4ThreeVector(0, 0, -1);
157  G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
158  G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
159  G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
160  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
161  rotm1.print(G4cout);
162  G4ThreeVector position1 = og*w;
163  G4Transform3D transform1 = G4Transform3D(rotm1,position1);
164 
165  new G4PVPlacement(transform1, //position, rotation
166  fTrdVolume, //logical volume
167  "Trd", //name
168  fWorldVolume, //mother volume
169  false, //no boolean operation
170  1); //copy number
171 
172  // 2nd position
173  //
174  phi = phi + 90*deg;
175  v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
176  w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
177  G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
178  G4ThreeVector position2 = og*w;
179  G4Transform3D transform2 = G4Transform3D(rotm2,position2);
180  new G4PVPlacement(transform2, //position, rotation
181  fTrdVolume, //logical volume
182  "Trd", //name
183  fWorldVolume, //mother volume
184  false, //no boolean operation
185  1); //copy number
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 
191 {
192  G4double og = 3*cm;
193 
194  // 1st position
195  //
196  G4double phi = 30*deg;
197  // u, v, w are the daughter axes, projected on the mother frame
198  G4ThreeVector u = G4ThreeVector(0, 0, -1);
199  G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
200  G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
201  G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
202  G4RotationMatrix* rotm1Inv = new G4RotationMatrix(rotm1.inverse());
203  G4cout << "\n --> phi = " << phi/deg << " deg; inverse rotation matrix : ";
204  rotm1Inv->print(G4cout);
205  G4ThreeVector position1 = og*w;
206 
207  new G4PVPlacement(rotm1Inv,
208  position1,
209  fTrdVolume, //logical volume
210  "Trd", //name
211  fWorldVolume, //mother volume
212  false, //no boolean operation
213  1); //copy number
214 
215  // 2nd position
216  //
217  phi = phi + 90*deg;
218  v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
219  w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
220  G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
221  G4RotationMatrix* rotm2Inv = new G4RotationMatrix(rotm2.inverse());
222  G4ThreeVector position2 = og*w;
223 
224  new G4PVPlacement(rotm2Inv, //rotation
225  position2, //position
226  fTrdVolume, //logical volume
227  "Trd", //name
228  fWorldVolume, //mother volume
229  false, //no boolean operation
230  2); //copy number
231 }
232 
233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
234 
236 {
237  G4double og = 3*cm;
238 
239  // 1st position (with first G4PVPlacement constructor)
240  //
241  G4double phi = 30*deg, theta = 90*deg;
243  rotm1.rotateY(theta);
244  rotm1.rotateZ(phi);
245  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
246  rotm1.print(G4cout);
247  G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
248  G4ThreeVector position1 = og*w;
249  G4Transform3D transform1(rotm1,position1);
250 
251  new G4PVPlacement(transform1, //rotation,position
252  fTrdVolume, //logical volume
253  "Trd", //name
254  fWorldVolume, //mother volume
255  false, //no boolean operation
256  1); //copy number
257 
258  // 2nd position (with second G4PVPlacement constructor)
259  //
260  phi = phi + 90*deg;
261  //rotm2Inv could be calculated with rotm2.inverse()
262  //but also by the following :
263  G4RotationMatrix* rotm2Inv = new G4RotationMatrix();
264  rotm2Inv->rotateZ(-phi);
265  rotm2Inv->rotateY(-theta);
266  w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
267  G4ThreeVector position2 = og*w;
268 
269  new G4PVPlacement(rotm2Inv, //rotation
270  position2, //position
271  fTrdVolume, //logical volume
272  "Trd", //name
273  fWorldVolume, //mother volume
274  false, //no boolean operation
275  2); //copy number
276 }
277 
278 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
279 
281 {
282  //definitions : mother frame = {x,y,z} ; daughter frame = {u,v,w}
283  // n = node line = intercept of xy and uv planes
284  // phi_euler = (x,n) : precession
285  // theta_euler = (z,w) : nutation
286  // psi_euler = (n,u) : proper rotation
287 
288  G4double og = 3*cm;
289 
290  // 1st position (with first G4PVPlacement constructor)
291  //
292  G4double phi = 30*deg;
293  G4double phi_euler = phi + pi/2;
294  G4double theta_euler = 90*deg;
295  G4double psi_euler = -90*deg;
296  //attention : clhep Euler constructor build inverse matrix !
297  G4RotationMatrix rotm1Inv = G4RotationMatrix(phi_euler,theta_euler,psi_euler);
298  G4RotationMatrix rotm1 = rotm1Inv.inverse();
299  //remark : could be built as rotm1 = G4RotationMatrix(-psi, -theta, -phi)
300  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
301  rotm1.print(G4cout);
302  G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
303  G4ThreeVector position1 = og*w;
304  G4Transform3D transform1 = G4Transform3D(rotm1,position1);
305 
306  new G4PVPlacement(transform1, //position, rotation
307  fTrdVolume, //logical volume
308  "Trd", //name
309  fWorldVolume, //mother volume
310  false, //no boolean operation
311  1); //copy number
312 
313  // 2nd position (with second G4PVPlacement constructor)
314  //
315  phi = phi + 90*deg;
316 
317  phi_euler = phi + pi/2;
318  G4RotationMatrix* rotm2Inv
319  = new G4RotationMatrix(phi_euler,theta_euler,psi_euler);
320  w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
321  G4ThreeVector position2 = og*w;
322 
323  new G4PVPlacement(rotm2Inv, //rotation
324  position2, //position
325  fTrdVolume, //logical volume
326  "Trd", //name
327  fWorldVolume, //mother volume
328  false, //no boolean operation
329  2); //copy number
330 }
331 
332 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
333 
335 {
339 
340  G4double og = 3*cm;
341 
342  // Place first two positionz in z = - 3cm
343  //
344 
345  // 1st position
346  G4double phi = 30*deg;
347  G4RotationMatrix rotm1;
348  //rotm1.rotateY(90*deg);
349  rotm1.rotateZ(phi);
350  G4ThreeVector uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0);
351  G4ThreeVector position = og*uz;
352  G4Transform3D transform1(rotm1,position);
353  G4Transform3D translateZ = HepGeom::Translate3D(0, 0, -3.*cm);
354 
355  new G4PVPlacement(translateZ * transform1, //rotation,position
356  fTrdVolume, //logical volume
357  "Trd", //name
358  fWorldVolume, //mother volume
359  false, //no boolean operation
360  1); //copy number
361 
362  // 2nd position
363  phi = phi + pi/2 ;
364  G4RotationMatrix rotm2;
365  //rotm2.rotateY(90*deg);
366  rotm2.rotateZ(phi);
367  uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0.);
368  position = og*uz;
369  G4Transform3D transform2 = G4Transform3D(rotm2, position);
370 
371  new G4PVPlacement(translateZ * transform2, //rotation, position
372  fTrdVolume, //logical volume
373  "Trd", //name
374  fWorldVolume, //mother volume
375  false, //no boolean operation
376  2); //copy number
377 
378 
379  // Place next two positionz in z = + 3cm with reflection
380  //
381 
382  // 3rd position
383  translateZ = HepGeom::Translate3D(0, 0, +3.*cm);
384  G4Transform3D reflect3D = HepGeom::ReflectZ3D();
385 
387  ->Place(translateZ * transform1 * reflect3D, //rotation,position
388  "Trd", //name
389  fTrdVolume, //logical volume
390  fWorldVolume, //mother volume
391  false, //no boolean operation
392  3); //copy number
393 
394  // 4rd position
396  ->Place( translateZ * transform2 * reflect3D,//rotation,position
397  "Trd", //name
398  fTrdVolume, //logical volume
399  fWorldVolume, //mother volume
400  false, //no boolean operation
401  4); //copy number
402 }
403 
404 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
405 
406 #include "G4RunManager.hh"
407 
409  fMethod = method;
411 }
412 
413 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const double cm
Definition: G4SIunits.hh:106
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4VPhysicalVolume * Construct()
const G4double pi
Definition: G4Tubs.hh:85
DetectorMessenger * fMessenger
static void Clean()
Definition: G4SolidStore.cc:79
Definition: G4Trd.hh:72
static G4NistManager * Instance()
static G4ReflectionFactory * Instance()
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4VPhysicalVolume * physiWorld
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
G4PhysicalVolumesPair Place(const G4Transform3D &transform3D, const G4String &name, G4LogicalVolume *LV, G4LogicalVolume *motherLV, G4bool isMany, G4int copyNo, G4bool surfCheck=false)
static const double deg
Definition: G4SIunits.hh:133
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4LogicalVolume * fTrdVolume
HepGeom::Transform3D G4Transform3D
static G4GeometryManager * GetInstance()
G4LogicalVolume * fWorldVolume
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
int position
Definition: filter.cc:7
static const double degree
Definition: G4SIunits.hh:125
void SetMethod(EMethod method)
void OpenGeometry(G4VPhysicalVolume *vol=0)
double G4double
Definition: G4Types.hh:76
Messenger class that defines commands for DetectorConstruction.