Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSDetectorConstruction.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 //
28 //
29 //
30 // $Id: TSDetectorConstruction.cc 93110 2015-11-05 08:37:42Z jmadsen $
31 //
32 //
50 //
51 //
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55 
56 
57 
59 
60 #include "G4RunManager.hh"
61 #include "G4Box.hh"
62 #include "G4LogicalVolume.hh"
63 #include "G4VPhysicalVolume.hh"
64 #include "G4Material.hh"
65 #include "G4NistManager.hh"
66 #include "G4PVPlacement.hh"
67 #include "G4VisAttributes.hh"
68 #include "G4Colour.hh"
69 #include "G4UnitsTable.hh"
70 #include "G4UserLimits.hh"
71 
72 #include "G4SDManager.hh"
74 #include "G4PSEnergyDeposit.hh"
75 #include "G4PSNofStep.hh"
76 
77 using namespace CLHEP;
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
81 TSDetectorConstruction* TSDetectorConstruction::fgInstance = 0;
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  return fgInstance;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 : fWorldPhys(0),
94  fWorldMaterialName("G4_Galactic"),
95  fTargetMaterialName("G4_B"),
96  fCasingMaterialName("G4_WATER"),
97  fWorldDim(G4ThreeVector(0.5*m, 0.5*m, 0.5*m)),
98  fTargetDim(G4ThreeVector(0.5*m, 0.5*m, 0.5*m)),
99  fTargetSections(G4ThreeVector(5, 5, 5)),
100  fMfdName("Target_MFD")
101 {
102  fgInstance = this;
103 }
104 
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
106 
108 {
109  fgInstance = 0;
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
115 {
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 
123 {
124  MaterialCollection_t materials;
126 
127  materials["World"] = nist->FindOrBuildMaterial(fWorldMaterialName);
128  materials["Target"] = nist->FindOrBuildMaterial(fTargetMaterialName);
129  materials["Casing"] = nist->FindOrBuildMaterial(fCasingMaterialName);
130 
131  return materials;
132 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
138 {
139  G4UserLimits* steplimit = new G4UserLimits(0.1*(fTargetDim.z()
140  /fTargetSections.z()));
141  G4bool check_overlap = true;
142 
143  G4Box* world_solid = new G4Box("World",
144  0.5*fWorldDim.x(),
145  0.5*fWorldDim.y(),
146  0.5*fWorldDim.z());
147  G4LogicalVolume* world_log = new G4LogicalVolume(world_solid,
148  materials.find("World")
149  ->second,
150  "World");
151  fWorldPhys = new G4PVPlacement(0,
152  G4ThreeVector(0.),
153  "World",
154  world_log,
155  0, false, 0, check_overlap);
156 
157  G4int nz = fTargetSections.z();
158  G4int ny = fTargetSections.y();
159  G4int nx = fTargetSections.x();
160 
161  // spacing between sections
162  G4double sx = fTargetDim.x()/fTargetSections.x();
163  G4double sy = fTargetDim.y()/fTargetSections.y();
164  G4double sz = fTargetDim.z()/fTargetSections.z();
165 
166  //G4cout << "World has dimensions : "
167  //<< G4BestUnit(fWorldDim, "Length") << G4endl;
168 
169  //------------------------------------------------------------------------//
170  // Set Visual Attributes
171  //------------------------------------------------------------------------//
172  G4VisAttributes* red = new G4VisAttributes(G4Color(1., 0., 0., 1.0));
173  G4VisAttributes* green = new G4VisAttributes(G4Color(0., 1., 0., 0.25));
174  G4VisAttributes* blue = new G4VisAttributes(G4Color(0., 0., 1., 0.1));
175  G4VisAttributes* white = new G4VisAttributes(G4Color(1., 1., 1., 1.));
176 
177  white->SetVisibility(true);
178  red->SetVisibility(true);
179  green->SetVisibility(true);
180  blue->SetVisibility(true);
181 
182  white->SetForceWireframe(true);
183  red->SetForceSolid(true);
184  green->SetForceSolid(true);
185  blue->SetForceSolid(true);
186 
187  world_log->SetVisAttributes(white);
188 
189  for(G4int k = 0; k < nz; ++k)
190  for(G4int j = 0; j < ny; ++j)
191  for(G4int i = 0; i < nx; ++i)
192  {
193  // displacement of section
194  G4double dx
195  = 0.5*sx + static_cast<G4double>(i)*sx - 0.5*fWorldDim.x();
196  G4double dy
197  = 0.5*sy + static_cast<G4double>(j)*sy - 0.5*fWorldDim.y();
198  G4double dz
199  = 0.5*sz + static_cast<G4double>(k)*sz - 0.5*fWorldDim.z();
200  G4ThreeVector td = G4ThreeVector(dx, dy, -dz);
201  // make unique name
202  std::stringstream ss_name;
203  ss_name << "Target_" << i << "_" << j << "_" << k;
204 
205  G4Box* target_solid = new G4Box(ss_name.str(),
206  0.5*sx,
207  0.5*sy,
208  0.5*sz);
209 
210 
211  G4Material* target_material = 0;
212  G4bool is_casing = true;
213 
214  if(j == 0 || j+1 == ny || i == 0 || i+1 == nx ||
215  (nz > 1 && (k == 0 || k+1 == nz)))
216  target_material = materials.find("Casing")->second;
217  else {
218  target_material = materials.find("Target")->second;
219  is_casing = false;
220  }
221 
222  G4LogicalVolume* target_log =
223  new G4LogicalVolume(target_solid,
224  target_material,
225  ss_name.str());
226 
227  target_log->SetUserLimits(steplimit);
228 
229  new G4PVPlacement(0,
230  td,
231  ss_name.str(),
232  target_log,
233  fWorldPhys,
234  true,
235  k*nx*ny + j*nx + i,
236  check_overlap);
237 
238  fScoringVolumes.insert(target_log);
239 
240  if(is_casing)
241  target_log->SetVisAttributes(blue);
242  else
243  {
244  // making a checkerboard for kicks...
245  G4bool even_z = (k%2 == 0) ? true : false;
246  G4bool even_y = (j%2 == 0) ? true : false;
247  G4bool even_x = (i%2 == 0) ? true : false;
248 
249  G4VisAttributes* theColor = nullptr;
250 
251  if((even_z))
252  {
253  if((even_y && even_x) || (!even_y && !even_x))
254  theColor = red;
255  else
256  theColor = green;
257  } else // ! even_z
258  {
259  if((!even_y && even_x) || (even_y && !even_x))
260  theColor = red;
261  else
262  theColor = green;
263  }
264 
265  target_log->SetVisAttributes(theColor);
266  }
267 
268  }
269 
270 
271 
272  return fWorldPhys;
273 }
274 
275 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
276 
278 {
279  //------------------------------------------------//
280  // MultiFunctionalDetector //
281  //------------------------------------------------//
282  // Define MultiFunctionalDetector with name.
285  G4VPrimitiveScorer* edep = new G4PSEnergyDeposit("EnergyDeposit");
286  MFDet->RegisterPrimitive(edep);
287  G4VPrimitiveScorer* nstep = new G4PSNofStep("NumberOfSteps");
288  MFDet->RegisterPrimitive(nstep);
289 
290  // add scoring volumes
291  for(auto ite : fScoringVolumes)
292  {
293  SetSensitiveDetector(ite, MFDet);
294  }
295 }
296 
297 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
298 
299 
static constexpr double m
G4bool RegisterPrimitive(G4VPrimitiveScorer *)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
Definition: test07.cc:36
CLHEP::Hep3Vector G4ThreeVector
double x() const
virtual MaterialCollection_t ConstructMaterials()
Definition: G4Box.hh:64
void SetUserLimits(G4UserLimits *pULimits)
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
static TSDetectorConstruction * Instance()
double z() const
void SetForceSolid(G4bool=true)
virtual G4VPhysicalVolume * ConstructWorld(const MaterialCollection_t &)
void SetVisibility(G4bool=true)
bool G4bool
Definition: G4Types.hh:79
G4Colour G4Color
Definition: G4Color.hh:42
std::map< G4String, G4Material * > MaterialCollection_t
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:71
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
double y() const
Definition of the TSDetectorConstruction class.
G4VPhysicalVolume * Construct()
double G4double
Definition: G4Types.hh:76
void SetForceWireframe(G4bool=true)
void SetVisAttributes(const G4VisAttributes *pVA)