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