ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorConstruction.cc
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 //
28 //
29 //
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33 #include "DetectorConstruction.hh"
34 #include "DetectorMessenger.hh"
35 
36 #include "G4NistManager.hh"
37 #include "G4Material.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4PVReplica.hh"
42 #include "G4UniformMagField.hh"
43 
44 #include "G4GeometryManager.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4LogicalVolumeStore.hh"
47 #include "G4SolidStore.hh"
48 
49 #include "G4UImanager.hh"
50 #include "G4UnitsTable.hh"
51 #include "G4PhysicalConstants.hh"
52 #include "G4SystemOfUnits.hh"
54 #include "G4AutoDelete.hh"
55 #include "G4RunManager.hh"
56 #include <iomanip>
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 :G4VUserDetectorConstruction(),fDefaultMaterial(0),fPhysiWorld(0),
62  fDetectorMessenger(0)
63 {
64  // default parameter values of the absorbers
65  fNbOfAbsor = 1;
66  fAbsorThickness[0] = 0*mm; //dummy, for initialization
67  fAbsorThickness[1] = 1*mm;
68  fAbsorSizeYZ = 1.*mm;
69  for (G4int iAbs=0; iAbs<kMaxAbsor; iAbs++) {
70  fNbOfDivisions[iAbs] = 1;
71  }
73 
74  // materials
76  SetAbsorMaterial(1,"G4_Si");
77 
78  // create commands for interactive definition of the calorimeter
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86  delete fDetectorMessenger;
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  return ConstructVolumes();
94 }
95 
96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
97 
99 {
101 
102  man->FindOrBuildMaterial("G4_Al");
103  man->FindOrBuildMaterial("G4_Si");
104  man->FindOrBuildMaterial("G4_Fe");
105  man->FindOrBuildMaterial("G4_Cu");
106  man->FindOrBuildMaterial("G4_Ge");
107  man->FindOrBuildMaterial("G4_Mo");
108  man->FindOrBuildMaterial("G4_Ta");
109  man->FindOrBuildMaterial("G4_W");
110  man->FindOrBuildMaterial("G4_Au");
111  man->FindOrBuildMaterial("G4_Pb");
112  man->FindOrBuildMaterial("G4_PbWO4");
113  man->FindOrBuildMaterial("G4_SODIUM_IODIDE");
114 
115  man->FindOrBuildMaterial("G4_AIR");
116  man->FindOrBuildMaterial("G4_WATER");
117 
118  G4Element* H = man->FindOrBuildElement("H");
119  G4Element* O = man->FindOrBuildElement("O");
120 
121  G4Material* H2O =
122  new G4Material("Water", 1.000*g/cm3, 2);
123  H2O->AddElement(H, 2);
124  H2O->AddElement(O, 1);
126 
127  G4double density = universe_mean_density; //from PhysicalConstants.h
128  G4double pressure = 3.e-18*pascal;
129  G4double temperature = 2.73*kelvin;
130  G4Material* Galactic =
131  new G4Material("Galactic", 1., 1.008*g/mole, density,
132  kStateGas,temperature,pressure);
133 
134  fDefaultMaterial = Galactic;
135 
136  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
140 
142 {
143  // Compute total thickness of absorbers
144  fAbsorSizeX = 0.;
145  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
146  fAbsorSizeX += fAbsorThickness[iAbs];
147  }
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 {
154  // complete the Calor parameters definition
156 
157  // Cleanup old geometry
162 
163  //
164  // World
165  //
166  G4Box* solidWorld =
167  new G4Box("World", //name
168  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //size
169 
170  G4LogicalVolume* logicWorld =
171  new G4LogicalVolume(solidWorld, //solid
172  fDefaultMaterial, //material
173  "World"); //name
174 
175  fPhysiWorld =
176  new G4PVPlacement(0, //no rotation
177  G4ThreeVector(), //at (0,0,0)
178  logicWorld, //logical volume
179  "World", //name
180  0, //mother volume
181  false, //no boolean operation
182  0); //copy number
183 
184  //
185  // Absorbers
186  //
187  fXfront[0] = -0.5*fAbsorSizeX;
188  //
189  for (G4int k=1; k<=fNbOfAbsor; k++) {
191  G4String matname = material->GetName();
192 
193  G4Box* solidAbsor =
194  new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
195 
196  G4LogicalVolume* logicAbsor =
197  new G4LogicalVolume(solidAbsor, // solid
198  material, // material
199  matname); // name
200 
201  fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1];
202  G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k];
203  G4ThreeVector position = G4ThreeVector(xcenter,0.,0.);
204 
205  new G4PVPlacement(0, //no rotation
206  position, //position
207  logicAbsor, //logical volume
208  matname, //name
209  logicWorld, //mother
210  false, //no boulean operat
211  k); //copy number
212 
213  // divisions, if any
214  //
215  G4double LayerThickness = fAbsorThickness[k]/fNbOfDivisions[k];
216  G4Box* solidLayer =
217  new G4Box(matname,LayerThickness/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
218 
219  G4LogicalVolume* logicLayer =
220  new G4LogicalVolume(solidLayer, //solid
221  material, //material
222  matname); //name
223 
224  new G4PVReplica(matname, //name
225  logicLayer, //logical volume
226  logicAbsor, //mother
227  kXAxis, //axis of replication
228  fNbOfDivisions[k], //number of replica
229  LayerThickness); //witdth of replica
230  }
231 
232  PrintParameters();
233 
234  //always return the physical World
235  //
236  return fPhysiWorld;
237 }
238 
239 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
240 
242 {
243  G4cout << "\n-------------------------------------------------------------"
244  << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:";
245  for (G4int i=1; i<=fNbOfAbsor; i++)
246  {
247  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
248  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length")
249  << " divided in " << fNbOfDivisions[i] << " slices";
250  }
251  G4cout << "\n-------------------------------------------------------------\n"
252  << G4endl;
253 }
254 
255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
256 
258 {
259  // set the number of Absorbers
260  //
261  if (ival < 1 || ival > (kMaxAbsor-1))
262  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
263  << ival << " must be at least 1 and and most " << kMaxAbsor-1
264  << ". Command refused" << G4endl;
265  return;
266  }
267  fNbOfAbsor = ival;
269 }
270 
271 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272 
274 {
275  // search the material by its name
276  //
277  if (iabs > fNbOfAbsor || iabs <= 0)
278  { G4cout << "\n --->warning from SetfAbsorMaterial: absor number "
279  << iabs << " out of range. Command refused" << G4endl;
280  return;
281  }
282 
283  G4Material* pttoMaterial =
285  if (pttoMaterial) {
286  fAbsorMaterial[iabs] = pttoMaterial;
288  }
289 }
290 
291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
292 
294 {
295  // change Absorber thickness
296  //
297  if (iabs > fNbOfAbsor || iabs <= 0)
298  { G4cout << "\n --->warning from SetfAbsorThickness: absor number "
299  << iabs << " out of range. Command refused" << G4endl;
300  return;
301  }
302  if (val <= DBL_MIN)
303  { G4cout << "\n --->warning from SetfAbsorThickness: thickness "
304  << val << " out of range. Command refused" << G4endl;
305  return;
306  }
307  fAbsorThickness[iabs] = val;
309 }
310 
311 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
312 
314 {
315  // change the transverse size
316  //
317  if (val <= DBL_MIN)
318  { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness "
319  << val << " out of range. Command refused" << G4endl;
320  return;
321  }
322  fAbsorSizeYZ = val;
324 }
325 
326 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
327 
329 {
330  // set the number of divisions
331  //
332  if (iabs > fNbOfAbsor || iabs < 1)
333  { G4cout << "\n --->warning from SetNbOfDivisions: absor number "
334  << iabs << " out of range. Command refused" << G4endl;
335  return;
336  }
337 
338  if (ival < 1)
339  { G4cout << "\n --->warning from SetNbOfDivisions: "
340  << ival << " must be at least 1. Command refused" << G4endl;
341  return;
342  }
343  fNbOfDivisions[iabs] = ival;
345 }
346 
347 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
348 
350 {
351  if ( fFieldMessenger.Get() == 0 ) {
352  // Create global magnetic field messenger.
353  // Uniform magnetic field is then created automatically if
354  // the field value is not zero.
355  G4ThreeVector fieldValue = G4ThreeVector();
357  new G4GlobalMagFieldMessenger(fieldValue);
358  //msg->SetVerboseLevel(1);
360  fFieldMessenger.Put( msg );
361  }
362 }
363 
364 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
365