Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.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 // $Id: DetectorConstruction.cc 101905 2016-12-07 11:34:39Z gunter $
30 //
32 //
33 // DetectorConstruction
34 //
35 // Created: 31.01.2003 V.Ivanchenko
36 //
37 // Modified:
38 // 04.06.2006 Adoptation of Hadr01 (V.Ivanchenko)
39 //
41 //
42 
43 #include "DetectorConstruction.hh"
44 #include "DetectorMessenger.hh"
45 
46 #include "G4Tubs.hh"
47 #include "G4LogicalVolume.hh"
48 #include "G4PVPlacement.hh"
49 
50 #include "G4RunManager.hh"
51 
52 #include "G4GeometryManager.hh"
53 #include "G4PhysicalVolumeStore.hh"
54 #include "G4LogicalVolumeStore.hh"
55 #include "G4SolidStore.hh"
56 
57 #include "G4VisAttributes.hh"
58 #include "G4Colour.hh"
59 
60 #include "G4UnitsTable.hh"
61 #include "G4ios.hh"
62 
63 #include "TargetSD.hh"
64 #include "CheckVolumeSD.hh"
65 #include "G4SDManager.hh"
66 #include "HistoManager.hh"
67 #include "G4NistManager.hh"
68 
69 #include "G4PhysicalConstants.hh"
70 #include "G4SystemOfUnits.hh"
71 
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
77  fTargetMaterial(0),
78  fWorldMaterial(0),
79  fLogicTarget(0),
80  fLogicCheck(0),
81  fLogicWorld(0),
82  fDetectorMessenger(0)
83 {
84  fDetectorMessenger = new DetectorMessenger(this);
85 
86  fRadius = 10.*cm;
87 
88  fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
89  fWorldMaterial =
91 
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
97 {
98  delete fDetectorMessenger;
99 }
100 
102 {
103  // Cleanup old geometry
104 
109 
110  // Sizes
111  G4double checkR = fRadius + mm;
112  G4double worldR = fRadius + cm;
113  G4double targetZ = HistoManager::GetPointer()->Length()*0.5;
114  G4double checkZ = targetZ + mm;
115  G4double worldZ = targetZ + cm;
116 
118  G4double sliceZ = targetZ/G4double(nSlices);
119 
120  //
121  // World
122  //
123  G4Tubs* solidW = new G4Tubs("World",0.,worldR,worldZ,0.,twopi);
124  fLogicWorld = new G4LogicalVolume( solidW,fWorldMaterial,"World");
126  fLogicWorld,"World",0,false,0);
127  //
128  // Check volume
129  //
130  G4Tubs* solidC = new G4Tubs("Check",0.,checkR,checkZ,0.,twopi);
131  fLogicCheck = new G4LogicalVolume( solidC,fWorldMaterial,"Check");
132  new G4PVPlacement(0,G4ThreeVector(),fLogicCheck,"Check",
133  fLogicWorld,false,0);
134 
135  //
136  // Target volume
137  //
138  G4Tubs* solidA = new G4Tubs("Target",0.,fRadius,sliceZ,0.,twopi);
139  fLogicTarget = new G4LogicalVolume( solidA,fTargetMaterial,"Target");
140 
141  G4double z = sliceZ - targetZ;
142 
143  for(G4int i=0; i<nSlices; i++) {
144  // physC =
145  new G4PVPlacement(0,G4ThreeVector(0.0,0.0,z),fLogicTarget,"Target",
146  fLogicCheck,false,i);
147  z += 2.0*sliceZ;
148  }
149  G4cout << "### Target consist of " << nSlices
150  << " of " << fTargetMaterial->GetName()
151  << " disks with R(mm)= " << fRadius/mm
152  << " Width(mm)= " << 2.0*sliceZ/mm
153  << " Total Length(mm)= " << 2.0*targetZ/mm
154  << " ###" << G4endl;
155 
156  // colors
158  fLogicWorld->SetVisAttributes(&zero);
159 
160  G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
161  fLogicCheck->SetVisAttributes(&regWcolor);
162 
163  G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
164  fLogicTarget->SetVisAttributes(&regCcolor);
165 
166  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
167 
168  return world;
169 }
170 
172 {
173  static G4ThreadLocal G4bool initialized = false;
174  if ( ! initialized ) {
175  // Prepare sensitive detectors
176  CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD");
177  (G4SDManager::GetSDMpointer())->AddNewDetector( fCheckSD );
178  fLogicCheck->SetSensitiveDetector(fCheckSD);
179 
180  TargetSD* fTargetSD = new TargetSD("targetSD");
181  (G4SDManager::GetSDMpointer())->AddNewDetector( fTargetSD );
182  fLogicTarget->SetSensitiveDetector(fTargetSD);
183  initialized=true;
184  }
185 }
186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
187 
189 {
190  // search the material by its name
192 
193  if (material && material != fTargetMaterial) {
194  fTargetMaterial = material;
195  if(fLogicTarget) { fLogicTarget->SetMaterial(fTargetMaterial); }
197  }
198 }
199 
200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
201 
203 {
204  // search the material by its name
206 
207  if (material && material != fWorldMaterial) {
208  fWorldMaterial = material;
209  if(fLogicWorld) { fLogicWorld->SetMaterial(fWorldMaterial); }
211  }
212 }
213 
214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
215 
217 {
218  if(val > 0.0) {
219  fRadius = val;
221  }
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double mm
Definition: G4SIunits.hh:115
G4int NumberOfSlices() const
CLHEP::Hep3Vector G4ThreeVector
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
Definition: G4Tubs.hh:85
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
void SetWorldMaterial(const G4String &)
static void Clean()
Definition: G4SolidStore.cc:79
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
static constexpr double twopi
Definition: G4SIunits.hh:76
static G4PhysicalVolumeStore * GetInstance()
string material
Definition: eplot.py:19
virtual void ConstructSDandField()
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
bool G4bool
Definition: G4Types.hh:79
static constexpr double cm
Definition: G4SIunits.hh:119
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4double Length() const
static G4GeometryManager * GetInstance()
void SetTargetMaterial(const G4String &)
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
void SetTargetRadius(G4double val)
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
static HistoManager * GetPointer()
Definition: HistoManager.cc:64
double G4double
Definition: G4Types.hh:76
void SetMaterial(G4Material *pMaterial)
static const G4VisAttributes & GetInvisible()
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)