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 | // |
---|
27 | // $Id: PhotInDetectorConstruction.cc,v 1.5 2006/06/29 16:25:09 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // *************************************************************************** |
---|
31 | |
---|
32 | //#define debug |
---|
33 | |
---|
34 | #include "PhotInDetectorConstruction.hh" |
---|
35 | |
---|
36 | // all BODY variables must be initialized in this constructor |
---|
37 | PhotInDetectorConstruction::PhotInDetectorConstruction(G4double x,G4double y,G4double z): |
---|
38 | numberOfLayers(PhotInNOfLayers),numberOfSlabs(PhotInNOfSlabs), |
---|
39 | samplingFraction(PhotInSampFract),xHD(x),yHD(y),zHD(z),serial(false), |
---|
40 | worldMaterial(0),absorberMaterial(0),gapMaterial(0),layerSolid(0),slabSolid(0) |
---|
41 | { |
---|
42 | #ifdef debug |
---|
43 | G4cout<<"PhotInDetectorConstruction::Constructor is called"<<G4endl; |
---|
44 | #endif |
---|
45 | layerParam = new PhotInLayerParameterisation; // should it be deleted in Distructor?MK |
---|
46 | layerParam->SetNumberOfLayers(numberOfLayers); // 9 by default (can be changed) |
---|
47 | layerParam->SetHalfTotalThickness(zHD); // transfer totalThickness of theSection |
---|
48 | G4double hlth=zHD/numberOfLayers; // Calculate thickness of one layer |
---|
49 | gapParam = new PhotInGapParameterisation; // should it be deleted in Distructor?MK |
---|
50 | gapParam->SetNumberOfSlabs(numberOfSlabs); // 9 by default (can be changed) |
---|
51 | gapParam->SetHalfTotalWidth(yHD); // Transfer |
---|
52 | gapParam->SetHalfTotalLayerThickness(hlth); // Transfer |
---|
53 | gapParam->SetSamplingFraction(samplingFraction); // Transfer |
---|
54 | PhotInCalorimeterSD::SetNumberOfLayers(numberOfLayers);// Construction of sensitiveLayers |
---|
55 | PhotInCalorimeterSD::SetNumberOfSlabs(numberOfSlabs); // Construction of sensitiveSlabs |
---|
56 | DefineMaterials(); // Material factory |
---|
57 | |
---|
58 | for(G4int i=0; i<PhotInNumSections ;i++) |
---|
59 | { |
---|
60 | calorLogical[i]=0; |
---|
61 | layerLogical[i]=0; |
---|
62 | slabLogical[i]=0; |
---|
63 | calorPhysical[i]=0; |
---|
64 | layerPhysical[i]=0; |
---|
65 | slabPhysical[i]=0; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | PhotInDetectorConstruction::~PhotInDetectorConstruction() |
---|
70 | { |
---|
71 | //delete gapParam; // Try to open later to be sure that it is not delited by G4 |
---|
72 | //delete layerParam; // Try to open later to be sure that it is not delited by G4 |
---|
73 | } |
---|
74 | |
---|
75 | void PhotInDetectorConstruction::DefineMaterials() // Material factory (@@ can be in Const) |
---|
76 | { |
---|
77 | G4String name, symbol; // a = mean_atomic_mass, z = mean_number_of_protons |
---|
78 | G4double a, z, density; //iz=number of protons in an isotope; |
---|
79 | G4int iz, in; //in=number of nucleons in an isotope; |
---|
80 | |
---|
81 | G4int ncomponents, natoms; |
---|
82 | G4double abundance, fractionmass; |
---|
83 | G4double temperature, pressure; |
---|
84 | // |
---|
85 | // define Elements |
---|
86 | // |
---|
87 | G4Element* H = new G4Element(name="Hydrogen",symbol="H" , z= 1., a=1.01*g/mole); |
---|
88 | G4Element* C = new G4Element(name="Carbon" ,symbol="C" , z= 6., a=12.01*g/mole); |
---|
89 | G4Element* N = new G4Element(name="Nitrogen",symbol="N" , z= 7., a=14.01*g/mole); |
---|
90 | G4Element* O = new G4Element(name="Oxygen" ,symbol="O" , z= 8., a=16.00*g/mole); |
---|
91 | // |
---|
92 | // define an Element from isotopes, by relative abundance |
---|
93 | // |
---|
94 | G4Isotope* U5 = new G4Isotope(name="U235", iz=92, in=235, a=235.01*g/mole); // @@ Corr. |
---|
95 | G4Isotope* U8 = new G4Isotope(name="U238", iz=92, in=238, a=238.03*g/mole); // @@ Corr. |
---|
96 | |
---|
97 | G4Element* U = new G4Element(name="enriched Uranium", symbol="U", ncomponents=2); |
---|
98 | U->AddIsotope(U5, abundance= 90.*perCent); |
---|
99 | U->AddIsotope(U8, abundance= 10.*perCent); |
---|
100 | // |
---|
101 | // define simple materials |
---|
102 | // |
---|
103 | G4Material* Al = new G4Material(name="Aluminium",z=13.,a=26.98*g/mole,density=2.7*g/cm3); |
---|
104 | |
---|
105 | //density = 1.390*g/cm3; |
---|
106 | //a = 39.95*g/mole; |
---|
107 | //G4Material* lAr = new G4Material(name="liquidArgon", z=18., a, density); |
---|
108 | |
---|
109 | //density = 11.35*g/cm3; |
---|
110 | //a = 207.19*g/mole; |
---|
111 | //G4Material* Pb = new G4Material(name="Lead" , z=82., a, density); |
---|
112 | // |
---|
113 | // define complex materials. case 1: chemical molecule |
---|
114 | // |
---|
115 | density = 1.000*g/cm3; |
---|
116 | G4Material* H2O = new G4Material(name="Water", density, ncomponents=2); |
---|
117 | H2O->AddElement(H, natoms=2); |
---|
118 | H2O->AddElement(O, natoms=1); |
---|
119 | |
---|
120 | density = 1.032*g/cm3; |
---|
121 | G4Material* Sci = new G4Material(name="Scintillator", density, ncomponents=2); |
---|
122 | Sci->AddElement(C, natoms=9); |
---|
123 | Sci->AddElement(H, natoms=10); |
---|
124 | // |
---|
125 | // define complex material. case 2: mixture by fractional mass |
---|
126 | // |
---|
127 | density = 1.290*mg/cm3; |
---|
128 | G4Material* Air = new G4Material(name="Air" , density, ncomponents=2); |
---|
129 | Air->AddElement(N, fractionmass=0.7); |
---|
130 | Air->AddElement(O, fractionmass=0.3); |
---|
131 | // |
---|
132 | // examples of vacuum |
---|
133 | // |
---|
134 | density = universe_mean_density; |
---|
135 | pressure = 3.e-18*pascal; |
---|
136 | temperature = 2.73*kelvin; |
---|
137 | a=1.01*g/mole; // Kosmic |
---|
138 | z=1.; // Hydrogrn |
---|
139 | G4Material* Vacuum=new G4Material(name="Vac",z,a,density,kStateGas,temperature,pressure); |
---|
140 | |
---|
141 | #ifdef debug |
---|
142 | G4cout<<"PhotInDetectorConstruction::DefineMaterials:"<<*(G4Material::GetMaterialTable()) |
---|
143 | <<G4endl; |
---|
144 | #endif |
---|
145 | |
---|
146 | //default materials of the calorimeter |
---|
147 | worldMaterial = Vacuum; |
---|
148 | absorberMaterial = Al; |
---|
149 | gapMaterial = Sci; |
---|
150 | layerParam->SetAbsorberMaterial(absorberMaterial); |
---|
151 | gapParam->SetGapMaterial(gapMaterial); |
---|
152 | } |
---|
153 | |
---|
154 | G4VPhysicalVolume* PhotInDetectorConstruction::Construct() |
---|
155 | { |
---|
156 | // Definition of Logical and Physical volumes |
---|
157 | G4LogicalVolume* worldLogical; // One logical volume for the World |
---|
158 | G4VPhysicalVolume* worldPhysical; // One Physical volume for the World |
---|
159 | |
---|
160 | G4double shiftY=yHD+yHD; // shift perpendicular to slabs |
---|
161 | G4double shiftZ=zHD+zHD; // shift perpendicular to layers |
---|
162 | G4double wxHD=xHD+0.5*m; // along slabs |
---|
163 | G4double wyHD=shiftY+yHD+0.5*m; // perpendicular to slabs |
---|
164 | G4double wzHD=shiftZ+zHD+0.5*m; // perpendicular to layers |
---|
165 | // |
---|
166 | // World volume: Solid=BOX, make Logical, make Physical |
---|
167 | // ==================================================== |
---|
168 | G4VSolid* worldSolid = new G4Box("World",wxHD,wyHD,wzHD); |
---|
169 | worldLogical = new G4LogicalVolume(worldSolid,worldMaterial,"World"); |
---|
170 | worldPhysical = new G4PVPlacement(0,G4ThreeVector(),worldLogical,"World",0,false,0); |
---|
171 | // |
---|
172 | // Calorimeter Section: Solid=BOX, make 3 Logical and 3 serial/parallel Physical |
---|
173 | // ============================================================================= |
---|
174 | G4VSolid* calorSolid = new G4Box("CalorSect",xHD,yHD,zHD); |
---|
175 | G4int i; // If i is used many times it is btter to define it as external var. for LOOPs |
---|
176 | for(i=0; i<PhotInNumSections; i++) |
---|
177 | { |
---|
178 | calorLogical[i] = new G4LogicalVolume(calorSolid,absorberMaterial,PhotInCalName[i]); |
---|
179 | if(serial) // if true = one section after another (serial) |
---|
180 | calorPhysical[i] = new G4PVPlacement(0, G4ThreeVector(0.,0.,(i-1)*shiftZ), |
---|
181 | calorLogical[i],PhotInCalName[i],worldLogical,false,i); |
---|
182 | else // *DEFAULT* false = side by side (parallel) |
---|
183 | calorPhysical[i] = new G4PVPlacement(0, G4ThreeVector(0.,G4double(i-1)*shiftY,0.), |
---|
184 | calorLogical[i],PhotInCalName[i],worldLogical,false,i); |
---|
185 | } |
---|
186 | // |
---|
187 | // Layers & Slabs: Solid=BOX. First Active (samplFract thick div in slabs), then Absorber |
---|
188 | // |
---|
189 | G4double layerZ=zHD/numberOfLayers; // Half thickness of one layer |
---|
190 | G4double slabY=yHD/numberOfSlabs; // Half width of one active slab |
---|
191 | layerSolid = new G4Box("Layer",xHD,yHD,layerZ); |
---|
192 | slabSolid = new G4Box("Gap",xHD,slabY,layerZ*samplingFraction); |
---|
193 | for(i=0; i<PhotInNumSections; i++) // Construct layers for all sections |
---|
194 | { |
---|
195 | layerLogical[i] = new G4LogicalVolume(layerSolid,absorberMaterial,"Layer"); |
---|
196 | layerPhysical[i] = new G4PVParameterised("Layer", layerLogical[i], calorLogical[i], |
---|
197 | kZAxis, numberOfLayers, layerParam); |
---|
198 | slabLogical[i] = new G4LogicalVolume(slabSolid,gapMaterial,"Slab"); |
---|
199 | slabPhysical[i] = new G4PVParameterised("Slab", slabLogical[i], layerLogical[i], |
---|
200 | kYAxis, numberOfSlabs, gapParam); |
---|
201 | } |
---|
202 | // |
---|
203 | // Regions |
---|
204 | // |
---|
205 | for(i=0; i<PhotInNumSections; i++) |
---|
206 | { |
---|
207 | G4Region* aRegion = new G4Region(PhotInRegName[i]); |
---|
208 | calorLogical[i]->SetRegion(aRegion); // Mutual |
---|
209 | aRegion->AddRootLogicalVolume(calorLogical[i]); // definition |
---|
210 | } |
---|
211 | // |
---|
212 | // Sensitive Detectors: Absorber and Gap |
---|
213 | // |
---|
214 | G4SDManager* SDman = G4SDManager::GetSDMpointer(); // Manager of sensitive detectors |
---|
215 | for(i=0; i<PhotInNumSections ;i++) |
---|
216 | { |
---|
217 | G4VSensitiveDetector* calorSD = new PhotInCalorimeterSD(PhotInDetName[i]); // Sections |
---|
218 | SDman->AddNewDetector(calorSD); // all section is a sensitive detector |
---|
219 | layerLogical[i]->SetSensitiveDetector(calorSD);// Make layers to be sensitive detectors |
---|
220 | slabLogical[i]->SetSensitiveDetector(calorSD); // Make slabs to be sensitive detectors |
---|
221 | } |
---|
222 | // |
---|
223 | // Visualization attributes |
---|
224 | // |
---|
225 | worldLogical->SetVisAttributes(G4VisAttributes::Invisible); |
---|
226 | G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.,1.,1.)); |
---|
227 | simpleBoxVisAtt->SetVisibility(true); |
---|
228 | for(i=0;i<PhotInNumSections;i++) |
---|
229 | { |
---|
230 | calorLogical[i]->SetVisAttributes(simpleBoxVisAtt); |
---|
231 | layerLogical[i]->SetVisAttributes(simpleBoxVisAtt); |
---|
232 | slabLogical[i]->SetVisAttributes(simpleBoxVisAtt); |
---|
233 | } |
---|
234 | #ifdef debug |
---|
235 | G4cout<<"PhotInDetectorConstruction::Construct:"<<G4endl; |
---|
236 | PrintCalorParameters(); |
---|
237 | #endif |
---|
238 | return worldPhysical; |
---|
239 | } |
---|
240 | |
---|
241 | void PhotInDetectorConstruction::PrintCalorParameters() const |
---|
242 | { |
---|
243 | G4cout << "----PhotInDetectorConstruction::PrintCalorParameters()-----" << G4endl; |
---|
244 | if(serial) G4cout << " Calorimeters are placed in serial." << G4endl; |
---|
245 | else G4cout << " Calorimeters are placed in parallel." << G4endl; |
---|
246 | G4cout << " Absorber is made of " << absorberMaterial->GetName() << G4endl; |
---|
247 | G4cout << " Gap is made of " << gapMaterial->GetName() << G4endl; |
---|
248 | G4cout << "--------------------------------------------------------" << G4endl; |
---|
249 | } |
---|
250 | |
---|
251 | void PhotInDetectorConstruction::SetAbsorberMaterial(G4String materialChoice) |
---|
252 | { |
---|
253 | #ifdef debug |
---|
254 | G4cout<<"PhotInDetectorConstruction::SetAbsorberMaterial: "<<materialChoice<<G4endl; |
---|
255 | #endif |
---|
256 | // search the material by its name |
---|
257 | G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); |
---|
258 | if(pttoMaterial) |
---|
259 | { |
---|
260 | absorberMaterial = pttoMaterial; |
---|
261 | layerParam->SetAbsorberMaterial(pttoMaterial); |
---|
262 | for(G4int i=0; i<PhotInNumSections; i++) |
---|
263 | { |
---|
264 | calorLogical[i]->SetMaterial(absorberMaterial); |
---|
265 | layerLogical[i]->SetMaterial(absorberMaterial); |
---|
266 | } |
---|
267 | } |
---|
268 | else G4cerr<<"PhotInDetectorConst::SetAbsM:"<<materialChoice<<" is not defined."<<G4endl; |
---|
269 | } |
---|
270 | |
---|
271 | void PhotInDetectorConstruction::SetGapMaterial(G4String materialChoice) |
---|
272 | { |
---|
273 | #ifdef debug |
---|
274 | G4cout<<"PhotInDetectorConstruction::SetGapMaterial: "<<materialChoice<<G4endl; |
---|
275 | #endif |
---|
276 | // search the material by its name |
---|
277 | G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); |
---|
278 | if(pttoMaterial) |
---|
279 | { |
---|
280 | gapMaterial = pttoMaterial; |
---|
281 | gapParam->SetGapMaterial(pttoMaterial); |
---|
282 | } |
---|
283 | else G4cerr<<"PhotInDetectorConst::SetGapM:"<<materialChoice<<" is not defined."<<G4endl; |
---|
284 | } |
---|
285 | |
---|
286 | void PhotInDetectorConstruction::SetSerialGeometry(G4bool ser) |
---|
287 | { |
---|
288 | #ifdef debug |
---|
289 | G4cout<<"PhotInDetectorConstruction::SetSerialGeometry: "<<ser<<G4endl; |
---|
290 | #endif |
---|
291 | if(serial==ser) return; // Do nothing if serialization is the same |
---|
292 | serial=ser; |
---|
293 | G4double shiftZ=zHD+zHD; // shift perpendicular to layers |
---|
294 | G4double shiftY=yHD+yHD; // shift perpendicular to slabs |
---|
295 | for(G4int i=0; i<PhotInNumSections; i++) |
---|
296 | { |
---|
297 | if(serial) calorPhysical[i]->SetTranslation(G4ThreeVector(0.,0.,(i-1)*shiftZ)); |
---|
298 | else calorPhysical[i]->SetTranslation(G4ThreeVector(0.,(i-1)*shiftY,0.)); |
---|
299 | } |
---|
300 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
301 | } |
---|
302 | |
---|
303 | void PhotInDetectorConstruction::SetNumberOfLayers(G4int nl) |
---|
304 | { |
---|
305 | #ifdef debug |
---|
306 | G4cout<<"PhotInDetectorConstruction::SetNumberOfLayers: "<<nl<<G4endl; |
---|
307 | #endif |
---|
308 | numberOfLayers = nl; |
---|
309 | layerSolid->SetZHalfLength(zHD/numberOfLayers); |
---|
310 | layerParam->SetNumberOfLayers(nl); |
---|
311 | for(G4int i=0; i<PhotInNumSections; i++) |
---|
312 | { |
---|
313 | if(layerPhysical[i]) |
---|
314 | { |
---|
315 | if(slabPhysical[i]) |
---|
316 | { |
---|
317 | layerLogical[i]->RemoveDaughter(slabPhysical[i]); |
---|
318 | delete slabPhysical[i]; |
---|
319 | } |
---|
320 | calorLogical[i]->RemoveDaughter(layerPhysical[i]); |
---|
321 | delete layerPhysical[i]; |
---|
322 | } |
---|
323 | layerPhysical[i] = new G4PVParameterised("Layer", layerLogical[i], calorLogical[i], |
---|
324 | kZAxis , numberOfLayers , layerParam); |
---|
325 | slabPhysical[i] = new G4PVParameterised("Slab", slabLogical[i], layerLogical[i], |
---|
326 | kYAxis , numberOfSlabs , gapParam); |
---|
327 | } |
---|
328 | PhotInCalorimeterSD::SetNumberOfLayers(nl); |
---|
329 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
330 | } |
---|
331 | |
---|
332 | void PhotInDetectorConstruction::SetNumberOfSlabs(G4int sn) |
---|
333 | { |
---|
334 | #ifdef debug |
---|
335 | G4cout<<"PhotInDetectorConstruction::SetNumberOfSlabs: "<<sn<<G4endl; |
---|
336 | #endif |
---|
337 | numberOfSlabs = sn; |
---|
338 | slabSolid->SetZHalfLength(yHD/sn); |
---|
339 | gapParam->SetNumberOfSlabs(sn); |
---|
340 | for(G4int i=0; i<PhotInNumSections; i++) |
---|
341 | { |
---|
342 | if(slabPhysical[i]) |
---|
343 | { |
---|
344 | layerLogical[i]->RemoveDaughter(slabPhysical[i]); |
---|
345 | delete slabPhysical[i]; |
---|
346 | } |
---|
347 | slabPhysical[i] = new G4PVParameterised("Slab", slabLogical[i], layerLogical[i], |
---|
348 | kYAxis , numberOfSlabs , gapParam); |
---|
349 | } |
---|
350 | PhotInCalorimeterSD::SetNumberOfSlabs(sn); |
---|
351 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
352 | } |
---|
353 | |
---|
354 | void PhotInDetectorConstruction::CreateMaterial(G4String materialChoice) |
---|
355 | { |
---|
356 | #ifdef debug |
---|
357 | G4cout<<"PhotInDetectorConstruction::CreateMaterial: "<<materialChoice<<G4endl; |
---|
358 | #endif |
---|
359 | if(G4Material::GetMaterial(materialChoice) != 0) return; |
---|
360 | |
---|
361 | G4double a, z, density; |
---|
362 | // List of possible new materials (Material Factory) |
---|
363 | if (materialChoice == "Silicon") |
---|
364 | new G4Material("Silicon", z=14., a= 28.09*g/mole, density= 2.33*g/cm3); |
---|
365 | else if (materialChoice =="Iron") |
---|
366 | new G4Material("Iron", z=26., a=55.85*g/mole, density=7.87*g/cm3); |
---|
367 | else if (materialChoice =="ArgonGas") |
---|
368 | new G4Material("ArgonGas",z=18., a= 39.95*g/mole, density=1.782*mg/cm3); |
---|
369 | else if (materialChoice =="He") |
---|
370 | new G4Material("He", z=2., a=4.0*g/mole, density=0.1786e-03*g/cm3); |
---|
371 | else G4cerr<<"**PhotInDetectorConstruction::CreateMaterial: No "<<materialChoice<<G4endl; |
---|
372 | } |
---|