Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G02DetectorConstruction.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 //g
28 //
29 //
30 // $Id$
31 //
32 // Class G02DetectorConstruction implementation
33 //
34 // ----------------------------------------------------------------------------
35 
37 
38 // Geant4 includes
39 //
40 #include "globals.hh"
41 #include "G4GeometryManager.hh"
42 #include "G4VisAttributes.hh"
43 
44 // Materials
45 //
46 #include "G4Material.hh"
47 
48 // Geometry includes
49 //
50 #include "G4LogicalVolume.hh"
51 #include "G4VPhysicalVolume.hh"
52 #include "G4PVParameterised.hh"
53 #include "G4PVPlacement.hh"
54 #include "G4Box.hh"
55 #include "G4Tubs.hh"
56 
57 // Reflected solids
58 //
59 #include "G4ReflectedSolid.hh"
60 #include "G4DisplacedSolid.hh"
61 #include "G4ReflectionFactory.hh"
62 #include "G4RotationMatrix.hh"
63 #include "G4AffineTransform.hh"
64 #include "G4Transform3D.hh"
65 
66 // Assembly volumes
67 //
68 #include "G4AssemblyVolume.hh"
69 
70 // Volume parameterisations
71 //
73 
74 // Messenger
75 //
76 #include "G02DetectorMessenger.hh"
77 
78 // GDML parser include
79 //
80 #include "G4GDMLParser.hh"
81 
82 #include "G4PhysicalConstants.hh"
83 #include "G4SystemOfUnits.hh"
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 //
87 // Constructor
88 //
90  : fAir(0), fAluminum(0), fPb(0), fXenon(0)
91 {
92  fExpHall_x=5.*m;
93 
94  fReadFile ="test.gdml";
95  fWriteFile="wtest.gdml";
96  fStepFile ="mbb";
97  fWritingChoice=1;
98 
99  fDetectorMessenger = new G02DetectorMessenger( this );
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 //
104 // Destructor
105 //
107 {
108  if(fDetectorMessenger) delete fDetectorMessenger;
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 //
113 // Constructs geometries and materials
114 //
116 {
117  // Writing or Reading of Geometry using G4GDML
118 
119  G4VPhysicalVolume* fWorldPhysVol;
120 
121  if(fWritingChoice==0)
122  {
123  // **** LOOK HERE*** FOR READING GDML FILES
124  //
125 
126  // ACTIVATING OVERLAP CHECK when read volumes are placed.
127  // Can take long time in case of complex geometries
128  //
129  // fParser.SetOverlapCheck(true);
130 
131  fParser.Read(fReadFile);
132 
133  // READING GDML FILES OPTION: 2nd Boolean argument "Validate".
134  // Flag to "false" disables check with the Schema when reading GDML file.
135  // See the GDML Documentation for more information.
136  //
137  // fParser.Read(fReadFile,false);
138 
139  // Prints the material information
140  //
142 
143  // Giving World Physical Volume from GDML Parser
144  //
145  fWorldPhysVol = fParser.GetWorldVolume();
146  }
147  else if(fWritingChoice==1)
148  {
149  // **** LOOK HERE*** FOR WRITING GDML FILES
150  // Detector Construction and WRITING to GDML
151  //
152  ListOfMaterials();
153  fWorldPhysVol = ConstructDetector();
154 
155  // OPTION: TO ADD MODULE AT DEPTH LEVEL ...
156  //
157  // Can be a integer or a pointer to the top Physical Volume:
158  //
159  // G4int depth=1;
160  // parser.AddModule(depth);
161 
162  // OPTION: SETTING ADDITION OF POINTER TO NAME TO FALSE
163  //
164  // By default, written names in GDML consist of the given name with
165  // appended the pointer reference to it, in order to make it unique.
166  // Naming policy can be changed by using the following method, or
167  // calling Write with additional Boolean argument to "false".
168  // NOTE: you have to be sure not to have duplication of names in your
169  // Geometry Setup.
170  //
171  // parser.SetAddPointerToName(false);
172  //
173  // or
174  //
175  // fParser.Write(fWriteFile, fWorldPhysVol, false);
176 
177  // Writing Geometry to GDML File
178  //
179  fParser.Write(fWriteFile, fWorldPhysVol);
180 
181  // OPTION: SPECIFYING THE SCHEMA LOCATION
182  //
183  // When writing GDML file the default the Schema Location from the
184  // GDML web site will be used:
185  // "http://cern.ch/service-spi/app/releases/GDML/GDML_2_10_0/src/GDMLSchema/gdml.xsd"
186  //
187  // NOTE: GDML Schema is distributed in Geant4 in the directory:
188  // $G4INSTALL/source/persistency/gdml/schema
189  //
190  // You can change the Schema path by adding a parameter to the Write
191  // command, as follows:
192  //
193  // fParser.Write(fWriteFile, fWorldPhysVol, "your-path-to-schema/gdml.xsd");
194  }
195  else // Demonstration how to Read STEP files using GDML
196  {
197  // Some printout...
198  //
199  ListOfMaterials();
200 
201  // Arbitrary values that should enclose any reasonable geometry
202  //
203  const G4double expHall_y = fExpHall_x/50.;
204  const G4double expHall_z = fExpHall_x/50.;
205 
206  // Create the hall
207  //
208  G4Box * experimentalHallBox
209  = new G4Box("ExpHallBox",fExpHall_x/50.,expHall_y,expHall_z);
210  G4LogicalVolume * experimentalHallLV
211  = new G4LogicalVolume(experimentalHallBox, fAir,"ExpHallLV");
212  fWorldPhysVol
213  = new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0),
214  experimentalHallLV, "ExpHallPhys", 0, false, 0);
215 
216  // G02DetectorConstruction via reading STEP File
217  //
218  G4LogicalVolume* LogicalVolST
219  = fParser.ParseST(fStepFile,fAir,fAluminum);
220 
221  // Placement inside of the hall
222  //
223  new G4PVPlacement(0, G4ThreeVector(10.0,0.0,0.0), LogicalVolST,
224  "StepPhys", experimentalHallLV, false, 0);
225  }
226 
227  // Set Visualization attributes to world
228  //
229  G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
230  fWorldPhysVol->GetLogicalVolume()->SetVisAttributes(BoxVisAtt);
231 
232  return fWorldPhysVol;
233 }
234 
235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
236 //
237 // Utility to build and list necessary materials
238 //
240 {
241  G4double a; // atomic mass
242  G4double z; // atomic number
243  G4double density,temperature,pressure;
244  G4double fractionmass;
246  G4int ncomponents;
247 
248  // Elements needed for the materials
249 
250  a = 14.01*g/mole;
251  G4Element* elN = new G4Element(name="Nitrogen", symbol="N", z=7., a);
252 
253  a = 16.00*g/mole;
254  G4Element* elO = new G4Element(name="Oxygen", symbol="O", z=8., a);
255 
256  a = 26.98*g/mole;
257  G4Element* elAl = new G4Element(name="Aluminum", symbol="Al", z=13., a);
258 
259  // Print the Element information
260  //
262 
263  // Air
264  //
265  density = 1.29*mg/cm3;
266  fAir = new G4Material(name="Air", density, ncomponents=2);
267  fAir->AddElement(elN, fractionmass=0.7);
268  fAir->AddElement(elO, fractionmass=0.3);
269 
270  // Aluminum
271  //
272  density = 2.70*g/cm3;
273  fAluminum = new G4Material(name="Aluminum", density, ncomponents=1);
274  fAluminum->AddElement(elAl, fractionmass=1.0);
275 
276  // Lead
277  //
278  fPb = new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
279 
280  // Xenon gas
281  //
282  fXenon = new G4Material("XenonGas", z=54., a=131.29*g/mole,
283  density= 5.458*mg/cm3, kStateGas,
284  temperature= 293.15*kelvin, pressure= 1*atmosphere);
285 
286  // Prints the material information
287  //
289 }
290 
291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
292 //
293 // Detector Construction
294 //
295 // Detector consist from DetectorBox, Conrol Room and 4 SubDetectors
296 // SubDetectors1 and 2 show how to use Reflection Factory and Assembly
297 // SubDetectors 3 and 4 show how to use Parameterisation
298 //
300 {
301  // Arbitary values that should enclose any reasonable geometry
302  //
303  const G4double expHall_y = fExpHall_x;
304  const G4double expHall_z = fExpHall_x;
305 
306  // Create the hall
307  //
308  G4Box * experimentalHallBox =
309  new G4Box("ExpHallBox", fExpHall_x, expHall_y, expHall_z);
310  G4LogicalVolume * experimentalHallLV =
311  new G4LogicalVolume(experimentalHallBox, fAir, "ExpHallLV");
312  G4PVPlacement * experimentalHallPhys =
313  new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0), experimentalHallLV,
314  "ExpHallPhys", 0, false, 0);
315 
316  // G02DetectorConstruction
317 
318  const G4double det_x = fExpHall_x*0.8;
319  const G4double det_y = fExpHall_x*0.7;
320  const G4double det_z = det_y;
321 
322  // Create the detector box
323  //
324  G4Box * detectorBox =
325  new G4Box("detectorBox", det_x, det_y, det_z);
326  G4LogicalVolume * detectorLV =
327  new G4LogicalVolume(detectorBox, fAir, "detLV");
328  // G4PVPlacement * detectorPhys =
329  new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0), detectorLV,
330  "detPhys", experimentalHallLV, false, 0);
331 
332  // Create the Control room box
333  //
334  const G4double room_x = fExpHall_x/20.;
335  const G4double room_y = room_x;
336  const G4double room_z = room_x;
337 
338  G4Box * roomBox =
339  new G4Box("roomBox", room_x, room_y, room_z);
340  G4LogicalVolume * roomLV =
341  new G4LogicalVolume(roomBox, fAir, "roomLV");
342  // G4PVPlacement * roomPhys =
343  new G4PVPlacement(0, G4ThreeVector(fExpHall_x-room_x-10.,0.0,0.0), roomLV,
344  "roomPhys", experimentalHallLV, false, 0);
345 
346  // SubDetector1
347  //
348  const G4double bigL=fExpHall_x/5.+50.;
349  G4LogicalVolume* subDetectorLV1 = ConstructSubDetector1();
350  // G4PVPlacement * detPhys1 =
351  new G4PVPlacement(0, G4ThreeVector(bigL,0.0,0.0), subDetectorLV1,
352  "PhysSubDetector1", detectorLV, false, 0);
353 
354  //
355  // LOOK HERE FOR REFLECTIONS
356  //
357 
358  // SubDetector2
359  //
360  G4Translate3D translation(-bigL, 0., 0.);
361  G4RotationMatrix* rotD3 = new G4RotationMatrix();
362  G4Transform3D rotation = G4Rotate3D(*rotD3);
363  G4ReflectX3D reflection;
364  G4Transform3D transform = translation*rotation*reflection;
365 
366  // Place the reflected part using G4ReflectionFactory
367  //
368  G4ReflectionFactory::Instance()->Place(transform, "reflSubDetector",
369  subDetectorLV1, detectorLV, false, 0);
370 
371  // SubDetector3
372  //
373  G4LogicalVolume* subDetectorLV3 = ConstructSubDetector2();
374  // G4PVPlacement * detPhys3 =
375  new G4PVPlacement(0, G4ThreeVector(0.0,bigL,0.0), subDetectorLV3,
376  "PhysSubDetectorFirst3", detectorLV, false, 0);
377 
378  // SubDetector4, placement of parameterised chambers
379  //
380  G4LogicalVolume* subDetectorLV4 = ConstructSubDetector2();
382  // G4PVPlacement * detChamb =
383  new G4PVPlacement(0, G4ThreeVector(0,0.0,0.0), subChamberLV,
384  "AssemblyPhys", subDetectorLV4, false, 0);
385  // G4PVPlacement * detPhys4 =
386  new G4PVPlacement(0, G4ThreeVector(0.0,-bigL,0.0), subDetectorLV4,
387  "PhysSubDetectorSecond3", detectorLV, false, 0);
388 
389  return experimentalHallPhys;
390 }
391 
392 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
393 //
394 // SubDetector1
395 //
397 {
398  const G4double sub_x = fExpHall_x/5.;
399  const G4double sub_y = sub_x;
400 
401  // Create the hall
402  //
403  G4Tubs * subTub =
404  new G4Tubs("subTub", 0., sub_x, sub_y, -90.*deg, 180*deg);
405  G4LogicalVolume * subTubLV =
406  new G4LogicalVolume(subTub, fPb, "tubLV");
407  G4LogicalVolume *AssemblyLV = ConstructAssembly();
408  // G4PVPlacement * detAss =
409  new G4PVPlacement(0, G4ThreeVector(sub_x/3,0.0,0.0), AssemblyLV,
410  "AssemblyPhys", subTubLV, false, 0);
411  return subTubLV;
412 }
413 
414 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
415 //
416 // SubDetector2
417 //
419 {
420  const G4double sub_x = fExpHall_x/10.;
421  const G4double sub_y = sub_x*2.;
422  const G4double sub_z = sub_x;
423 
424  // Create the hall
425  //
426  G4Box * detHallBox =
427  new G4Box("detHallBox", sub_x, sub_y, sub_z);
428  G4LogicalVolume * detHallLV =
429  new G4LogicalVolume(detHallBox, fAluminum, "detHallLV");
430 
431  return detHallLV;
432 }
433 
434 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
435 //
436 // Assembly
437 //
439 {
440  const G4double big_x = fExpHall_x/17;
441  const G4double big_y = big_x;
442  const G4double big_z = big_x;
443 
444  // Create the Box
445  //
446  G4Box * OuterBox =
447  new G4Box("OuterBox", big_x, big_y, big_z);
448  G4LogicalVolume * OuterBoxLV =
449  new G4LogicalVolume(OuterBox, fAir, "OuterBoxLV");
450  // G4PVPlacement * OuterBoxPhys =
451  new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0), OuterBoxLV,
452  "OuterBoxPhys", 0, false, 0);
453 
454  // The aluminum object's logical volume
455  //
456  const G4double bigL=big_x/2.5;
457  const G4double medL=big_x/8;
458  const G4double smalL=big_x/12;
459 
460  G4Box * BigBox =
461  new G4Box("BBox", bigL, bigL, bigL);
462  G4LogicalVolume * BigBoxLV =
463  new G4LogicalVolume(BigBox, fAluminum, "AlBigBoxLV");
464  G4Box * MedBox =
465  new G4Box("MBox", medL, medL, medL);
466  G4LogicalVolume * MedBoxLV1 =
467  new G4LogicalVolume(MedBox, fAluminum, "AlMedBoxLV1");
468  G4Box * SmallBox =
469  new G4Box("SBox", smalL, smalL, smalL);
470  G4LogicalVolume * SmallBoxLV =
471  new G4LogicalVolume(SmallBox, fAluminum, "AlSmaBoxLV");
472 
473  const G4double bigPlace=bigL+10.;
474  const G4double medPlace=medL+10.;
475  // G4PVPlacement * BigBoxPhys =
476  new G4PVPlacement(0, G4ThreeVector(bigPlace,0.0,0.0), BigBoxLV,
477  "AlPhysBig", OuterBoxLV, false, 0);
478 
479  // Construction of Tub
480  //
481  G4Tubs * BigTube =
482  new G4Tubs("BTube",0,smalL,smalL,-pi/2.,pi);
483 
484  // Construction of Reflection of Tub
485  //
486  G4ReflectX3D Xreflection;
487  G4Translate3D translation(-bigPlace, 0., 0.);
488  G4Transform3D transform =Xreflection;
489 
490  G4ReflectedSolid * ReflBig =
491  new G4ReflectedSolid("Refll_Big", BigTube, transform);
492  G4LogicalVolume * ReflBigLV =
493  new G4LogicalVolume(ReflBig, fXenon, "ReflBigAl");
494  new G4PVPlacement(0, G4ThreeVector(0.,0.0,0.0), ReflBigLV,
495  "AlPhysBigTube", SmallBoxLV, false, 0);
496  //
497  // LOOK HERE FOR ASSEMBLY
498  //
499 
500  // create Assembly of Boxes and Tubs
501  //
502  G4AssemblyVolume* assembly = new G4AssemblyVolume();
503  G4RotationMatrix* rot = new G4RotationMatrix();
504  G4ThreeVector posBig(-bigPlace, 0, 0);
505  G4ThreeVector posBig0(bigPlace/4, 0, 0);
506  G4ThreeVector posMed(-medPlace, 0, 0);
507  G4ThreeVector posMed0(medPlace, 0, 0);
508  G4ThreeVector position(0., 0., 0.);
509 
510  // Add to Assembly the MediumBox1
511  //
512  assembly->AddPlacedVolume(MedBoxLV1, posMed0, rot);
513 
514  // Add to Assembly the Small Box
515  //
516  assembly->AddPlacedVolume(SmallBoxLV, posMed, rot);
517 
518  // Place the Assembly
519  //
520  assembly->MakeImprint(BigBoxLV, posBig0, rot, 0);
521 
522  //
523  // LOOK HERE FOR ASSEMBLY with REFLECTION
524  //
525 
526  G4Translate3D translation1(-bigPlace, 0., 0.);
527  G4RotationMatrix* rotD3 = new G4RotationMatrix();
528  G4Transform3D rotation = G4Rotate3D(*rotD3);
529  G4ReflectX3D reflection;
530  G4Transform3D transform1 = translation1*rotation*reflection;
531 
532  assembly->MakeImprint(OuterBoxLV, transform1, 0, 0);
533 
534  return OuterBoxLV;
535 }
536 
537 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
538 //
539 // Parameterised Chamber
540 //
542 {
543  const G4double chamber_x = fExpHall_x/12.;
544  const G4double chamber_y = chamber_x;
545  const G4double chamber_z = chamber_x;
546 
547  // Create the hall
548  //
549  G4Box * paramChamberBox =
550  new G4Box("ChamberBox", chamber_x, chamber_y, chamber_z);
551  G4LogicalVolume * paramChamberLV =
552  new G4LogicalVolume(paramChamberBox, fAir, "ChamberLV");
553 
554  // Parametrisation Chamber (taken from N02 novice example)
555  //
556  G4int NbOfChambers = 5;
557  G4double ChamberWidth = 2*cm;
558  G4double ChamberSpacing = 8*cm;
559  G4double fTrackerLength = (NbOfChambers+1)*ChamberSpacing; // Full length
560  G4double trackerSize = 0.5*fTrackerLength;
561 
562  // An example of parameterised volume
563  // dummy values for G4Box -- modified by parameterised volume
564  //
565  G4Box *solidChamber =
566  new G4Box("chamber", 10*cm, 10*cm, 1*cm);
567  G4LogicalVolume* logicChamber =
568  new G4LogicalVolume(solidChamber, fAluminum, "Chamber", 0, 0, 0);
569 
570  G4double firstPosition = -trackerSize + 0.5*ChamberWidth;
571  G4double firstLength = fTrackerLength/10;
572  G4double lastLength = fTrackerLength;
573 
574  G4VPVParameterisation* chamberParam =
575  new G02ChamberParameterisation( NbOfChambers, // NoChambers
576  firstPosition, // Z of center of first
577  ChamberSpacing, // Z spacing of centers
578  ChamberWidth, // Width Chamber
579  firstLength, // lengthInitial
580  lastLength); // lengthFinal
581  // G4VPhysicalVolume* physiChamber =
582  new G4PVParameterised( "Chamber", // their name
583  logicChamber, // their logical volume
584  paramChamberLV, // mother logical volume
585  kZAxis, // Are placed along this axis
586  NbOfChambers, // Number of chambers
587  chamberParam); // The parametrisation
588  return paramChamberLV;
589 }
590 
591 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
592 //
593 // SetReadFile
594 //
596 {
597  fReadFile=File;
598  fWritingChoice=0;
599 }
600 
601 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
602 //
603 // SetWriteFile
604 //
606 {
607  fWriteFile=File;
608  fWritingChoice=1;
609 }
610 
611 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
612 //
613 // SetStepFile
614 //
616 {
617  fStepFile=File;
618  fWritingChoice=3;
619 }