Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
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 {
58  fMessenger = new DetectorMessenger(this);
59 }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  delete fMessenger;
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
71 {
72  // Materials
74  G4bool fromIsotopes = false;
75  G4Material* material = nist->FindOrBuildMaterial("G4_AIR", fromIsotopes);
76 
77  // Clean old geometry, if any
78  //
83 
84  // World
85  //
86  G4double rmin = 0.;
87  G4double rmax = 5*cm;
88  G4double hz = 5*cm;
89  G4double phiMin = 0.;
90  G4double deltaPhi = 360*degree;
91 
92  G4Tubs* solidWorld
93  = new G4Tubs("World", //name
94  rmin, rmax, hz, phiMin, deltaPhi); //size
95 
96  fWorldVolume
97  = new G4LogicalVolume(solidWorld, //solid
98  material, //material
99  "World"); //name
100 
101  G4VPhysicalVolume* physiWorld
102  = new G4PVPlacement(0, //no rotation
103  G4ThreeVector(), //at (0,0,0)
104  fWorldVolume, //logical volume
105  "World", //name
106  0, //mother volume
107  false, //no boolean operation
108  0); //copy number
109 
110  // Trd volume
111  //
112  G4double dX1 = 1*cm;
113  G4double dX2 = 1*cm;
114  G4double dY1 = 1*cm;
115  G4double dY2 = 2*cm;
116  G4double dZ = 3*cm;
117 
118  G4Trd* solidTrd
119  = new G4Trd("trd", //name
120  dX1/2, dX2/2, dY1/2, dY2/2, dZ/2); //size
121 
122  fTrdVolume
123  = new G4LogicalVolume(solidTrd, //solid
124  material, //material
125  "trd"); //name
126 
127 
128  // Place Volume1 and Volume2 according to selected methods
129  //
130  switch ( fMethod ) {
131  case kWithDirectMatrix: PlaceWithDirectMatrix(); break;
132  case kWithInverseMatrix: PlaceWithInverseMatrix(); break;
133  case kWithAxialRotations: PlaceWithAxialRotations(); break;
134  case kWithEulerAngles: PlaceWithEulerAngles(); break;
135  case kWithReflections: PlaceWithReflections(); break;
136  default: ;;
137  }
138 
139  // Return the root volume
140  //
141  return physiWorld;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
146 void DetectorConstruction::PlaceWithDirectMatrix()
147 {
148  G4double og = 3*cm;
149 
150  // 1st position
151  //
152  G4double phi = 30*deg;
153  // u, v, w are the daughter axes, projected on the mother frame
154  G4ThreeVector u = G4ThreeVector(0, 0, -1);
155  G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
156  G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
157  G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
158  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
159  rotm1.print(G4cout);
160  G4ThreeVector position1 = og*w;
161  G4Transform3D transform1 = G4Transform3D(rotm1,position1);
162 
163  new G4PVPlacement(transform1, //position, rotation
164  fTrdVolume, //logical volume
165  "Trd", //name
166  fWorldVolume, //mother volume
167  false, //no boolean operation
168  1); //copy number
169 
170  // 2nd position
171  //
172  phi = phi + 90*deg;
173  v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
174  w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
175  G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
176  G4ThreeVector position2 = og*w;
177  G4Transform3D transform2 = G4Transform3D(rotm2,position2);
178  new G4PVPlacement(transform2, //position, rotation
179  fTrdVolume, //logical volume
180  "Trd", //name
181  fWorldVolume, //mother volume
182  false, //no boolean operation
183  1); //copy number
184 }
185 
186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
187 
188 void DetectorConstruction::PlaceWithInverseMatrix()
189 {
190  G4double og = 3*cm;
191 
192  // 1st position
193  //
194  G4double phi = 30*deg;
195  // u, v, w are the daughter axes, projected on the mother frame
196  G4ThreeVector u = G4ThreeVector(0, 0, -1);
197  G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
198  G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
199  G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
200  G4RotationMatrix* rotm1Inv = new G4RotationMatrix(rotm1.inverse());
201  G4cout << "\n --> phi = " << phi/deg << " deg; inverse rotation matrix : ";
202  rotm1Inv->print(G4cout);
203  G4ThreeVector position1 = og*w;
204 
205  new G4PVPlacement(rotm1Inv,
206  position1,
207  fTrdVolume, //logical volume
208  "Trd", //name
209  fWorldVolume, //mother volume
210  false, //no boolean operation
211  1); //copy number
212 
213  // 2nd position
214  //
215  phi = phi + 90*deg;
216  v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
217  w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
218  G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
219  G4RotationMatrix* rotm2Inv = new G4RotationMatrix(rotm2.inverse());
220  G4ThreeVector position2 = og*w;
221 
222  new G4PVPlacement(rotm2Inv, //rotation
223  position2, //position
224  fTrdVolume, //logical volume
225  "Trd", //name
226  fWorldVolume, //mother volume
227  false, //no boolean operation
228  2); //copy number
229 }
230 
231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
232 
233 void DetectorConstruction::PlaceWithAxialRotations()
234 {
235  G4double og = 3*cm;
236 
237  // 1st position (with first G4PVPlacement constructor)
238  //
239  G4double phi = 30*deg, theta = 90*deg;
241  rotm1.rotateY(theta);
242  rotm1.rotateZ(phi);
243  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
244  rotm1.print(G4cout);
245  G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
246  G4ThreeVector position1 = og*w;
247  G4Transform3D transform1(rotm1,position1);
248 
249  new G4PVPlacement(transform1, //rotation,position
250  fTrdVolume, //logical volume
251  "Trd", //name
252  fWorldVolume, //mother volume
253  false, //no boolean operation
254  1); //copy number
255 
256  // 2nd position (with second G4PVPlacement constructor)
257  //
258  phi = phi + 90*deg;
259  //rotm2Inv could be calculated with rotm2.inverse()
260  //but also by the following :
261  G4RotationMatrix* rotm2Inv = new G4RotationMatrix();
262  rotm2Inv->rotateZ(-phi);
263  rotm2Inv->rotateY(-theta);
264  w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
265  G4ThreeVector position2 = og*w;
266 
267  new G4PVPlacement(rotm2Inv, //rotation
268  position2, //position
269  fTrdVolume, //logical volume
270  "Trd", //name
271  fWorldVolume, //mother volume
272  false, //no boolean operation
273  2); //copy number
274 }
275 
276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
277 
278 void DetectorConstruction::PlaceWithEulerAngles()
279 {
280  //definitions : mother frame = {x,y,z} ; daughter frame = {u,v,w}
281  // n = node line = intercept of xy and uv planes
282  // phi_euler = (x,n) : precession
283  // theta_euler = (z,w) : nutation
284  // psi_euler = (n,u) : proper rotation
285 
286  G4double og = 3*cm;
287 
288  // 1st position (with first G4PVPlacement constructor)
289  //
290  G4double phi = 30*deg;
291  G4double phi_euler = phi + pi/2;
292  G4double theta_euler = 90*deg;
293  G4double psi_euler = -90*deg;
294  //attention : clhep Euler constructor build inverse matrix !
295  G4RotationMatrix rotm1Inv = G4RotationMatrix(phi_euler,theta_euler,psi_euler);
296  G4RotationMatrix rotm1 = rotm1Inv.inverse();
297  //remark : could be built as rotm1 = G4RotationMatrix(-psi, -theta, -phi)
298  G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
299  rotm1.print(G4cout);
300  G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
301  G4ThreeVector position1 = og*w;
302  G4Transform3D transform1 = G4Transform3D(rotm1,position1);
303 
304  new G4PVPlacement(transform1, //position, rotation
305  fTrdVolume, //logical volume
306  "Trd", //name
307  fWorldVolume, //mother volume
308  false, //no boolean operation
309  1); //copy number
310 
311  // 2nd position (with second G4PVPlacement constructor)
312  //
313  phi = phi + 90*deg;
314 
315  phi_euler = phi + pi/2;
316  G4RotationMatrix* rotm2Inv
317  = new G4RotationMatrix(phi_euler,theta_euler,psi_euler);
318  w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
319  G4ThreeVector position2 = og*w;
320 
321  new G4PVPlacement(rotm2Inv, //rotation
322  position2, //position
323  fTrdVolume, //logical volume
324  "Trd", //name
325  fWorldVolume, //mother volume
326  false, //no boolean operation
327  2); //copy number
328 }
329 
330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
331 
332 void DetectorConstruction::PlaceWithReflections()
333 {
337 
338  G4double og = 3*cm;
339 
340  // Place first two positionz in z = - 3cm
341  //
342 
343  // 1st position
344  G4double phi = 30*deg;
345  G4RotationMatrix rotm1;
346  //rotm1.rotateY(90*deg);
347  rotm1.rotateZ(phi);
348  G4ThreeVector uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0);
349  G4ThreeVector position = og*uz;
350  G4Transform3D transform1(rotm1,position);
351  G4Transform3D translateZ = HepGeom::Translate3D(0, 0, -3.*cm);
352 
353  new G4PVPlacement(translateZ * transform1, //rotation,position
354  fTrdVolume, //logical volume
355  "Trd", //name
356  fWorldVolume, //mother volume
357  false, //no boolean operation
358  1); //copy number
359 
360  // 2nd position
361  phi = phi + pi/2 ;
362  G4RotationMatrix rotm2;
363  //rotm2.rotateY(90*deg);
364  rotm2.rotateZ(phi);
365  uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0.);
366  position = og*uz;
367  G4Transform3D transform2 = G4Transform3D(rotm2, position);
368 
369  new G4PVPlacement(translateZ * transform2, //rotation, position
370  fTrdVolume, //logical volume
371  "Trd", //name
372  fWorldVolume, //mother volume
373  false, //no boolean operation
374  2); //copy number
375 
376 
377  // Place next two positionz in z = + 3cm with reflection
378  //
379 
380  // 3rd position
381  translateZ = HepGeom::Translate3D(0, 0, +3.*cm);
382  G4Transform3D reflect3D = HepGeom::ReflectZ3D();
383 
385  ->Place(translateZ * transform1 * reflect3D, //rotation,position
386  "Trd", //name
387  fTrdVolume, //logical volume
388  fWorldVolume, //mother volume
389  false, //no boolean operation
390  3); //copy number
391 
392  // 4rd position
394  ->Place( translateZ * transform2 * reflect3D,//rotation,position
395  "Trd", //name
396  fTrdVolume, //logical volume
397  fWorldVolume, //mother volume
398  false, //no boolean operation
399  4); //copy number
400 }
401 
402 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
403 
404 #include "G4RunManager.hh"
405 
407  fMethod = method;
409 }
410 
411 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......