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 
71 
72  // materials
74  SetAbsorMaterial(1,"G4_Si");
75 
76  // create commands for interactive definition of the calorimeter
78 }
79 
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 
83 {
84  delete fDetectorMessenger;
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
91  return ConstructVolumes();
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
97 {
99 
100  man->FindOrBuildMaterial("G4_AIR");
101 
102  G4Element* H = man->FindOrBuildElement("H");
103  G4Element* O = man->FindOrBuildElement("O");
104 
105  G4Material* H2O =
106  new G4Material("Water", 1.000*g/cm3, 2);
107  H2O->AddElement(H, 2);
108  H2O->AddElement(O, 1);
110 
111  G4Element* Hf = man->FindOrBuildElement("Hf");
112 
113  G4Material* HfO2 = new G4Material("HfO2", 9.68*g/cm3, 2);
114  HfO2->AddElement(Hf, 1);
115  HfO2->AddElement(O , 2);
116 
117  // example of vacuum
118  G4double density = universe_mean_density; //from PhysicalConstants.h
119  G4double pressure = 3.e-18*pascal;
120  G4double temperature = 2.73*kelvin;
121  G4Material* Galactic =
122  new G4Material("Galactic", 1., 1.008*g/mole, density,
123  kStateGas,temperature,pressure);
124 
125  fDefaultMaterial = Galactic;
126 
127  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
133  G4String symbol, G4double density, G4int Z, G4int A)
134 {
135  // define a material from an isotope
136  //
137  G4int ncomponents;
138  G4double abundance, massfraction;
139 
140  G4Isotope* isotope = new G4Isotope(symbol, Z, A);
141 
142  G4Element* element = new G4Element(name, symbol, ncomponents=1);
143  element->AddIsotope(isotope, abundance= 100.*perCent);
144 
145  G4Material* material = new G4Material(name, density, ncomponents=1);
146  material->AddElement(element, massfraction=100.*perCent);
147 
148  return material;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
154 {
155  // Compute total thickness of absorbers
156  fAbsorSizeX = 0.;
157  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
158  fAbsorSizeX += fAbsorThickness[iAbs];
159  }
160  fWorldSizeX = 1.2*fAbsorSizeX;
162 }
163 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
165 
167 {
168  // complete the Calor parameters definition
170 
171  // Cleanup old geometry
176 
177  //
178  // World
179  //
180  G4Box* solidWorld =
181  new G4Box("World", //name
182  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //size
183 
184  G4LogicalVolume* logicWorld =
185  new G4LogicalVolume(solidWorld, //solid
186  fDefaultMaterial, //material
187  "World"); //name
188 
189  fPhysiWorld =
190  new G4PVPlacement(0, //no rotation
191  G4ThreeVector(), //at (0,0,0)
192  logicWorld, //logical volume
193  "World", //name
194  0, //mother volume
195  false, //no boolean operation
196  0); //copy number
197 
198  //
199  // Absorbers
200  //
201  fXfront[0] = -0.5*fAbsorSizeX;
202  //
203  for (G4int k=1; k<=fNbOfAbsor; k++) {
204  G4Material* material = fAbsorMaterial[k];
205  G4String matname = material->GetName();
206 
207  G4Box* solidAbsor =
208  new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
209 
210  G4LogicalVolume* logicAbsor =
211  new G4LogicalVolume(solidAbsor, // solid
212  material, // material
213  matname); // name
214 
215  fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1];
216  G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k];
217  G4ThreeVector position = G4ThreeVector(xcenter,0.,0.);
218 
219  new G4PVPlacement(0, //no rotation
220  position, //position
221  logicAbsor, //logical volume
222  matname, //name
223  logicWorld, //mother
224  false, //no boulean operat
225  k); //copy number
226  }
227 
228  PrintParameters();
229 
230  //always return the physical World
231  //
232  return fPhysiWorld;
233 }
234 
235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
236 
238 {
239  G4cout << "\n-------------------------------------------------------------"
240  << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:";
241  for (G4int i=1; i<=fNbOfAbsor; i++)
242  {
243  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
244  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length");
245  }
246  G4cout << "\n-------------------------------------------------------------\n"
247  << G4endl;
248 }
249 
250 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
251 
253 {
254  // set the number of Absorbers
255  //
256  if (ival < 1 || ival > (kMaxAbsor-1))
257  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
258  << ival << " must be at least 1 and and most " << kMaxAbsor-1
259  << ". Command refused" << G4endl;
260  return;
261  }
262  fNbOfAbsor = ival;
264 }
265 
266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
267 
268 void DetectorConstruction::SetAbsorMaterial(G4int iabs,const G4String& material)
269 {
270  // search the material by its name
271  //
272  if (iabs > fNbOfAbsor || iabs <= 0)
273  { G4cout << "\n --->warning from SetfAbsorMaterial: absor number "
274  << iabs << " out of range. Command refused" << G4endl;
275  return;
276  }
277 
278  G4Material* pttoMaterial =
280  if (pttoMaterial) {
281  fAbsorMaterial[iabs] = pttoMaterial;
283  }
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290  // change Absorber thickness
291  //
292  if (iabs > fNbOfAbsor || iabs <= 0)
293  { G4cout << "\n --->warning from SetfAbsorThickness: absor number "
294  << iabs << " out of range. Command refused" << G4endl;
295  return;
296  }
297  if (val <= DBL_MIN)
298  { G4cout << "\n --->warning from SetfAbsorThickness: thickness "
299  << val << " out of range. Command refused" << G4endl;
300  return;
301  }
302  fAbsorThickness[iabs] = val;
304 }
305 
306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
307 
309 {
310  // change the transverse size
311  //
312  if (val <= DBL_MIN)
313  { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness "
314  << val << " out of range. Command refused" << G4endl;
315  return;
316  }
317  fAbsorSizeYZ = val;
319 }
320 
321 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
322 
324 {
325  if ( fFieldMessenger.Get() == 0 ) {
326  // Create global magnetic field messenger.
327  // Uniform magnetic field is then created automatically if
328  // the field value is not zero.
329  G4ThreeVector fieldValue = G4ThreeVector();
331  new G4GlobalMagFieldMessenger(fieldValue);
332  //msg->SetVerboseLevel(1);
334  fFieldMessenger.Put( msg );
335  }
336 }
337 
338 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
339