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 | // |
---|
26 | // $Id: DetectorConstruction.cc,v 1.2 2010/06/04 19:03:36 vnivanch Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
28 | // |
---|
29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
31 | |
---|
32 | #include "DetectorConstruction.hh" |
---|
33 | #include "DetectorMessenger.hh" |
---|
34 | |
---|
35 | #include "G4Material.hh" |
---|
36 | #include "G4Box.hh" |
---|
37 | #include "G4LogicalVolume.hh" |
---|
38 | #include "G4PVPlacement.hh" |
---|
39 | #include "G4UniformMagField.hh" |
---|
40 | |
---|
41 | #include "G4GeometryManager.hh" |
---|
42 | #include "G4UserLimits.hh" |
---|
43 | #include "G4PhysicalVolumeStore.hh" |
---|
44 | #include "G4LogicalVolumeStore.hh" |
---|
45 | #include "G4SolidStore.hh" |
---|
46 | |
---|
47 | #include "G4UnitsTable.hh" |
---|
48 | #include "G4NistManager.hh" |
---|
49 | |
---|
50 | #include "G4MonopoleFieldSetup.hh" |
---|
51 | #include "G4FieldManager.hh" |
---|
52 | #include "G4TransportationManager.hh" |
---|
53 | |
---|
54 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
55 | |
---|
56 | DetectorConstruction::DetectorConstruction() |
---|
57 | { |
---|
58 | // default parameter values |
---|
59 | absorSizeX = absorSizeYZ = 10 * cm; |
---|
60 | worldSizeX = worldSizeYZ = 1.2 * absorSizeX; |
---|
61 | maxStepSize = 5 * mm; |
---|
62 | |
---|
63 | worldMaterial = absorMaterial = 0; |
---|
64 | magField = 0; |
---|
65 | lAbsor = 0; |
---|
66 | fMFieldSetup = 0; |
---|
67 | |
---|
68 | DefineMaterials(); |
---|
69 | SetMaterial("G4_Al"); |
---|
70 | |
---|
71 | // create commands for interactive definition of the detector |
---|
72 | detectorMessenger = new DetectorMessenger(this); |
---|
73 | } |
---|
74 | |
---|
75 | DetectorConstruction::~DetectorConstruction() |
---|
76 | { |
---|
77 | delete detectorMessenger; |
---|
78 | } |
---|
79 | |
---|
80 | G4VPhysicalVolume* DetectorConstruction::Construct() |
---|
81 | { |
---|
82 | return ConstructVolumes(); |
---|
83 | } |
---|
84 | |
---|
85 | void DetectorConstruction::DefineMaterials() |
---|
86 | { |
---|
87 | /*********************** define Elements *********************/ |
---|
88 | G4double z, a; |
---|
89 | |
---|
90 | G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole); |
---|
91 | G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole); |
---|
92 | |
---|
93 | /*********************** define Materials **********************/ |
---|
94 | G4double density, temperature, pressure; |
---|
95 | G4int ncomponents; |
---|
96 | G4double fractionmass; |
---|
97 | |
---|
98 | G4Material* Air = new G4Material("Air" , density = 1.290 * mg/cm3, ncomponents=2); |
---|
99 | Air->AddElement(N, fractionmass = 0.7); |
---|
100 | Air->AddElement(O, fractionmass = 0.3); |
---|
101 | |
---|
102 | density = universe_mean_density; //from PhysicalConstants.h |
---|
103 | pressure = 3.e-18 * pascal; |
---|
104 | temperature = 2.73 * kelvin; |
---|
105 | |
---|
106 | G4Material* vacuum = new G4Material("Galactic", z = 1, a = 1.008 * g/mole, density, |
---|
107 | kStateGas, temperature, pressure); |
---|
108 | |
---|
109 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
110 | |
---|
111 | //default materials |
---|
112 | worldMaterial = vacuum; |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
117 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() |
---|
118 | { |
---|
119 | G4GeometryManager::GetInstance()->OpenGeometry(); |
---|
120 | G4PhysicalVolumeStore::GetInstance()->Clean(); |
---|
121 | G4LogicalVolumeStore::GetInstance()->Clean(); |
---|
122 | G4SolidStore::GetInstance()->Clean(); |
---|
123 | |
---|
124 | /**************************** World *****************************/ |
---|
125 | G4Box * sWorld = new G4Box("world", //name |
---|
126 | worldSizeX / 2, worldSizeYZ / 2, worldSizeYZ / 2); //dimensions |
---|
127 | |
---|
128 | G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld, //shape |
---|
129 | worldMaterial, //material |
---|
130 | "world"); //name |
---|
131 | |
---|
132 | G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation |
---|
133 | G4ThreeVector(), //at (0,0,0) |
---|
134 | lWorld, //logical volume |
---|
135 | "world", //name |
---|
136 | 0, //mother volume |
---|
137 | false, //no boolean operation |
---|
138 | 0); //copy number |
---|
139 | |
---|
140 | |
---|
141 | /************************** Absorber ***************************/ |
---|
142 | G4Box * sAbsor = new G4Box("Absorber", //name |
---|
143 | absorSizeX / 2, absorSizeYZ / 2, absorSizeYZ / 2); //dimensions |
---|
144 | |
---|
145 | lAbsor = new G4LogicalVolume(sAbsor, //shape |
---|
146 | absorMaterial, //material |
---|
147 | "Absorber"); //name |
---|
148 | |
---|
149 | |
---|
150 | new G4PVPlacement(0, //no rotation |
---|
151 | G4ThreeVector(), //at (0,0,0) |
---|
152 | lAbsor, //logical volume |
---|
153 | "Absorber", //name |
---|
154 | lWorld, //mother volume |
---|
155 | false, //no boolean operation |
---|
156 | 0); //copy number |
---|
157 | lAbsor->SetUserLimits(new G4UserLimits(maxStepSize)); |
---|
158 | |
---|
159 | PrintParameters(); |
---|
160 | |
---|
161 | /************ always return the World volume *****************/ |
---|
162 | return pWorld; |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
168 | void DetectorConstruction::PrintParameters() |
---|
169 | { |
---|
170 | G4cout << "\n---------------------------------------------------------\n"; |
---|
171 | G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX, "Length") |
---|
172 | << " of " << absorMaterial->GetName() << G4endl; |
---|
173 | G4cout << "\n---------------------------------------------------------\n"; |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
179 | void DetectorConstruction::SetSizeX(G4double value) |
---|
180 | { |
---|
181 | absorSizeX = value; worldSizeX = 1.2 * absorSizeX; |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
186 | void DetectorConstruction::SetSizeYZ(G4double value) |
---|
187 | { |
---|
188 | absorSizeYZ = value; |
---|
189 | worldSizeYZ = 1.2 * absorSizeYZ; |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
194 | void DetectorConstruction::SetMaterial(G4String materialChoice) |
---|
195 | { |
---|
196 | // search the material by its name |
---|
197 | G4Material * pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
198 | if (pttoMaterial) absorMaterial = pttoMaterial; |
---|
199 | else G4cout << "Material does not exist in DB" << G4endl; |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
204 | |
---|
205 | void DetectorConstruction::SetMagField(G4double fieldValue) |
---|
206 | { |
---|
207 | //apply a global uniform magnetic field along Z axis |
---|
208 | G4FieldManager * fieldMgr = |
---|
209 | G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
210 | |
---|
211 | if (magField) { delete magField; } //delete the existing magn field |
---|
212 | |
---|
213 | //fMFieldSetup = G4MonopoleFieldSetup::GetMonopoleFieldSetup(); // create the field |
---|
214 | |
---|
215 | |
---|
216 | if (fieldValue != 0.) // create a new one if non nul |
---|
217 | { |
---|
218 | magField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); |
---|
219 | fieldMgr->SetDetectorField(magField); |
---|
220 | fieldMgr->CreateChordFinder(magField); |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | magField = 0; |
---|
225 | fieldMgr->SetDetectorField(magField); |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
230 | |
---|
231 | void DetectorConstruction::SetMaxStepSize(G4double step_) |
---|
232 | { |
---|
233 | maxStepSize = step_; |
---|
234 | if(lAbsor) lAbsor->SetUserLimits(new G4UserLimits(maxStepSize)); |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
239 | #include "G4RunManager.hh" |
---|
240 | |
---|
241 | void DetectorConstruction::UpdateGeometry() |
---|
242 | { |
---|
243 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); |
---|
244 | } |
---|
245 | |
---|
246 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|