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 "G4Sphere.hh"
38 #include "G4LogicalVolume.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4PVReplica.hh"
42 
43 #include "G4GeometryManager.hh"
44 #include "G4PhysicalVolumeStore.hh"
45 #include "G4LogicalVolumeStore.hh"
46 #include "G4SolidStore.hh"
47 #include "G4RunManager.hh"
48 
49 #include "G4UnitsTable.hh"
50 #include "G4PhysicalConstants.hh"
51 #include "G4SystemOfUnits.hh"
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
57  fAbsorMaterial(nullptr),
58  fAbsor(nullptr)
59 {
60  // default parameter values
61  fAbsorRadius = 3*cm;
62  fNbOfLayers = 1;
63 
65  SetMaterial("G4_WATER");
66 
67  // create commands for interactive definition of the detector
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
74 { delete fDetectorMessenger;}
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
79 {
81 
82  man->FindOrBuildMaterial("G4_Al");
83  man->FindOrBuildMaterial("G4_Si");
84  man->FindOrBuildMaterial("G4_Fe");
85  man->FindOrBuildMaterial("G4_Ge");
86  man->FindOrBuildMaterial("G4_Gd");
87  man->FindOrBuildMaterial("G4_W");
88  man->FindOrBuildMaterial("G4_Pb");
89 
90  man->FindOrBuildMaterial("G4_AIR");
91  man->FindOrBuildMaterial("G4_WATER");
92  man->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
93 
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100 {
101  // Absorber
102  //
103  G4Sphere*
104  sAbsor = new G4Sphere("Absorber", //name
105  0., fAbsorRadius, 0., twopi, 0., pi); //size
106 
107  fSpheres.push_back(sAbsor);
108 
110  lAbsor = new G4LogicalVolume(sAbsor, //solid
111  fAbsorMaterial, //material
112  "Absorber"); //name
113  fLVolumes.push_back(lAbsor);
114 
115  fAbsor = new G4PVPlacement(0, //no rotation
116  G4ThreeVector(), //at (0,0,0)
117  lAbsor, //logical volume
118  "Absorber", //name
119  0, //mother volume
120  false, //no boolean operation
121  0); //copy number
122 
123  // Layers
124  //
126 
127  for (G4int i=1; i<=fNbOfLayers; i++) {
128  G4Sphere*
129  sLayer = new G4Sphere("Layer", (i-1)*fLayerThickness, i*fLayerThickness,
130  0., twopi, 0., pi);
131 
132  fSpheres.push_back(sLayer);
133 
135  lLayer = new G4LogicalVolume(sLayer, //shape
136  fAbsorMaterial, //material
137  "Layer"); //name
138  fLVolumes.push_back(lLayer);
139 
140  new G4PVPlacement(0, //no rotation
141  G4ThreeVector(), //at (0,0,0)
142  lLayer, //logical volume
143  "Layer", //name
144  lAbsor, //mother volume
145  false, //no boolean operation
146  i); //copy number
147 
148  }
149 
150  PrintParameters();
151 
152  //
153  //always return the root volume
154  //
155  return fAbsor;
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
159 
161 {
162  G4cout << "\n---------------------------------------------------------\n";
163  G4cout << "---> The Absorber is a sphere of "
164  << G4BestUnit(fAbsorRadius,"Length") << " radius of "
165  << fAbsorMaterial->GetName() << " divided in " << fNbOfLayers
166  << " slices of " << G4BestUnit(fLayerThickness,"Length")
167  << "\n \n" << fAbsorMaterial << G4endl;
168  G4cout << "\n---------------------------------------------------------\n";
169 }
170 
171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
172 
174 {
175  // geometry was already constructed - scale radii of all spheres
176  if(fAbsor) {
177  G4double scale = value/fAbsorRadius;
178  for (auto solid : fSpheres) {
179  if(scale > 1.0) {
180  solid->SetOuterRadius(solid->GetOuterRadius()*scale);
181  solid->SetInnerRadius(solid->GetInnerRadius()*scale);
182  } else {
183  solid->SetInnerRadius(solid->GetInnerRadius()*scale);
184  solid->SetOuterRadius(solid->GetOuterRadius()*scale);
185  }
186  }
187  }
189 }
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192 
193 void DetectorConstruction::SetMaterial(G4String materialChoice)
194 {
195  // search the material by its name
196  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
197 
198  if (pttoMaterial && pttoMaterial != fAbsorMaterial) {
199  fAbsorMaterial = pttoMaterial;
201 
202  // geometry was already constructed - only change material
203  if(fAbsor) {
204  for (auto lv : fLVolumes) { lv->SetMaterial(fAbsorMaterial); }
205  }
206  }
207 }
208 
209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
210 
212 {
213  fNbOfLayers = value;
214 }
215 
216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......