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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /// \file field/field03/src/F03DetectorConstruction.cc
 27 /// \brief Implementation of the F03DetectorConstruction class
 28 //
 29 //
 30 //
 31 //
 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 34 
 35 #include "F03DetectorConstruction.hh"
 36 
 37 #include "F03CalorimeterSD.hh"
 38 #include "F03DetectorMessenger.hh"
 39 
 40 #include "G4AutoDelete.hh"
 41 #include "G4GeometryManager.hh"
 42 #include "G4FieldBuilder.hh"
 43 #include "G4LogicalVolume.hh"
 44 #include "G4LogicalVolumeStore.hh"
 45 #include "G4Material.hh"
 46 #include "G4PVPlacement.hh"
 47 #include "G4PhysicalConstants.hh"
 48 #include "G4PhysicalVolumeStore.hh"
 49 #include "G4RunManager.hh"
 50 #include "G4SDManager.hh"
 51 #include "G4SolidStore.hh"
 52 #include "G4SystemOfUnits.hh"
 53 #include "G4Tubs.hh"
 54 #include "G4UniformMagField.hh"
 55 
 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 57 
 58 F03DetectorConstruction::F03DetectorConstruction()
 59 {
 60   fDetectorMessenger = new F03DetectorMessenger(this);
 61 
 62   // create field builder
 63   // this will create commands for field parameters 
 64   G4FieldBuilder* fieldBuilder = G4FieldBuilder::Instance();
 65   // fieldBuilder->SetVerboseLevel(2);
 66 
 67   auto globalFieldParameters = fieldBuilder->GetFieldParameters();
 68   auto localFieldParameters = fieldBuilder->CreateFieldParameters("Radiator");
 69 
 70   // set default min step 0.25 mm
 71   globalFieldParameters->SetMinimumStep(0.25 * mm);
 72   localFieldParameters->SetMinimumStep(0.25 * mm);
 73 
 74   // create materials
 75   DefineMaterials();
 76 }
 77 
 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 79 
 80 F03DetectorConstruction::~F03DetectorConstruction()
 81 {
 82   delete fDetectorMessenger;
 83 }
 84 
 85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 86 
 87 G4VPhysicalVolume* F03DetectorConstruction::Construct()
 88 {
 89   return ConstructCalorimeter();
 90 }
 91 
 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 93 
 94 void F03DetectorConstruction::DefineMaterials()
 95 {
 96   // This function illustrates the possible ways to define materials
 97 
 98   G4String name, symbol;  // a=mass of a mole;
 99   G4double a, z, density;  // z=mean number of protons;
100   G4int nel;
101   G4int ncomponents;
102   G4double fractionmass, pressure, temperature;
103 
104   //
105   // define Elements
106   //
107 
108   a = 1.01 * g / mole;
109   auto elH = new G4Element(name = "Hydrogen", symbol = "H", z = 1., a);
110 
111   a = 12.01 * g / mole;
112   auto elC = new G4Element(name = "Carbon", symbol = "C", z = 6., a);
113 
114   a = 14.01 * g / mole;
115   auto elN = new G4Element(name = "Nitrogen", symbol = "N", z = 7., a);
116 
117   a = 16.00 * g / mole;
118   auto elO = new G4Element(name = "Oxygen", symbol = "O", z = 8., a);
119 
120   a = 39.948 * g / mole;
121   auto elAr = new G4Element(name = "Argon", symbol = "Ar", z = 18., a);
122 
123   //
124   // define simple materials
125   //
126 
127   // Mylar
128 
129   density = 1.39 * g / cm3;
130   auto mylar = new G4Material(name = "Mylar", density, nel = 3);
131   mylar->AddElement(elO, 2);
132   mylar->AddElement(elC, 5);
133   mylar->AddElement(elH, 4);
134 
135   // Polypropelene
136 
137   auto CH2 = new G4Material("Polypropelene", 0.91 * g / cm3, 2);
138   CH2->AddElement(elH, 2);
139   CH2->AddElement(elC, 1);
140 
141   // Krypton as detector gas, STP
142 
143   density = 3.700 * mg / cm3;
144   a = 83.80 * g / mole;
145   auto Kr = new G4Material(name = "Kr", z = 36., a, density);
146 
147   // Dry air (average composition)
148 
149   density = 1.7836 * mg / cm3;  // STP
150   auto argon = new G4Material(name = "Argon", density, ncomponents = 1);
151   argon->AddElement(elAr, 1);
152 
153   density = 1.25053 * mg / cm3;  // STP
154   auto nitrogen = new G4Material(name = "N2", density, ncomponents = 1);
155   nitrogen->AddElement(elN, 2);
156 
157   density = 1.4289 * mg / cm3;  // STP
158   auto oxygen = new G4Material(name = "O2", density, ncomponents = 1);
159   oxygen->AddElement(elO, 2);
160 
161   density = 1.2928 * mg / cm3;  // STP
162   density *= 1.0e-8;  // pumped vacuum
163   temperature = STP_Temperature;
164   pressure = 1.0e-8 * STP_Pressure;
165 
166   auto air =
167     new G4Material(name = "Air", density, ncomponents = 3, kStateGas, temperature, pressure);
168   air->AddMaterial(nitrogen, fractionmass = 0.7557);
169   air->AddMaterial(oxygen, fractionmass = 0.2315);
170   air->AddMaterial(argon, fractionmass = 0.0128);
171 
172   // Xenon as detector gas, STP
173 
174   density = 5.858 * mg / cm3;
175   a = 131.29 * g / mole;
176   auto Xe = new G4Material(name = "Xenon", z = 54., a, density);
177 
178   // Carbon dioxide, STP
179 
180   density = 1.842 * mg / cm3;
181   auto CarbonDioxide = new G4Material(name = "CO2", density, nel = 2);
182   CarbonDioxide->AddElement(elC, 1);
183   CarbonDioxide->AddElement(elO, 2);
184 
185   // 80% Xe + 20% CO2, STP
186 
187   density = 5.0818 * mg / cm3;
188   auto Xe20CO2 = new G4Material(name = "Xe20CO2", density, ncomponents = 2);
189   Xe20CO2->AddMaterial(Xe, fractionmass = 0.922);
190   Xe20CO2->AddMaterial(CarbonDioxide, fractionmass = 0.078);
191 
192   // 80% Kr + 20% CO2, STP
193 
194   density = 3.601 * mg / cm3;
195   auto Kr20CO2 = new G4Material(name = "Kr20CO2", density, ncomponents = 2);
196   Kr20CO2->AddMaterial(Kr, fractionmass = 0.89);
197   Kr20CO2->AddMaterial(CarbonDioxide, fractionmass = 0.11);
198 
199   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
200 
201   // default materials of the calorimeter and TR radiator
202 
203   fRadiatorMat = air;  // CH2 ;   // mylar;
204 
205   fAbsorberMaterial = air;  //  Kr20CO2;   // XeCO2CF4;
206 
207   fWorldMaterial = air;
208 }
209 
210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211 
212 G4VPhysicalVolume* F03DetectorConstruction::ConstructCalorimeter()
213 {
214   // Cleanup old geometry
215 
216   if (fPhysiWorld) {
217     G4GeometryManager::GetInstance()->OpenGeometry();
218     G4PhysicalVolumeStore::GetInstance()->Clean();
219     G4LogicalVolumeStore::GetInstance()->Clean();
220     G4SolidStore::GetInstance()->Clean();
221   }
222 
223   // complete the Calor parameters definition and Print
224 
225   ComputeCalorParameters();
226   PrintCalorParameters();
227 
228   G4bool checkOverlaps = true;
229 
230   fSolidWorld = new G4Tubs("World",  // its name
231                            0., fWorldSizeR, fWorldSizeZ / 2., 0., twopi);  // its size
232 
233   fLogicWorld = new G4LogicalVolume(fSolidWorld,  // its solid
234                                     fWorldMaterial,  // its material
235                                     "World");  // its name
236 
237   fPhysiWorld = new G4PVPlacement(nullptr,  // no rotation
238                                   G4ThreeVector(),  // at (0,0,0)
239                                   "World",  // its name
240                                   fLogicWorld,  // its logical volume
241                                   nullptr,  // its mother  volume
242                                   false,  // no boolean op.
243                                   0,  // copy number
244                                   checkOverlaps);  // checkOverlaps
245 
246   // TR radiator envelope
247   G4double radThick = fFoilNumber * (fRadThickness + fGasGap) + fDetGap;
248   G4double zRad = fZAbsorber - 0.5 * (radThick + fAbsorberThickness);
249 
250   G4cout << "zRad = " << zRad / mm << " mm" << G4endl;
251   G4cout << "radThick = " << radThick / mm << " mm" << G4endl;
252   G4cout << "fFoilNumber = " << fFoilNumber << G4endl;
253   G4cout << "fRadiatorMat = " << fRadiatorMat->GetName() << G4endl;
254   G4cout << "WorldMaterial = " << fWorldMaterial->GetName() << G4endl;
255 
256   fSolidRadiator = new G4Tubs("Radiator", 0.0, fAbsorberRadius, 0.5 * radThick, 0.0, twopi);
257 
258   fLogicRadiator = new G4LogicalVolume(fSolidRadiator, fWorldMaterial, "Radiator");
259 
260   fPhysiRadiator = new G4PVPlacement(nullptr, G4ThreeVector(0, 0, zRad), "Radiator", fLogicRadiator,
261                                      fPhysiWorld, false, 0, checkOverlaps);
262 
263   fSolidRadSlice = new G4Tubs("RadSlice", 0.0, fAbsorberRadius, 0.5 * fRadThickness, 0.0, twopi);
264 
265   fLogicRadSlice = new G4LogicalVolume(fSolidRadSlice, fRadiatorMat, "RadSlice");
266 
267   // Radiator slice
268   G4double radSliceThick = fRadThickness + fGasGap;
269   G4double zStart = 0.5 * (-radThick + radSliceThick) + fDetGap;
270   // start on the board of radiator enevelope + det gap
271 
272   for (G4int j = 0; j < fFoilNumber; j++) {
273     G4double zSlice = zStart + j * radSliceThick;
274     G4cout << zSlice / mm << " mm"
275            << "\t";
276 
277     fPhysiRadSlice = new G4PVPlacement(nullptr, G4ThreeVector(0., 0., zSlice), "RadSlice",
278                                        fLogicRadSlice, fPhysiRadiator, false, j, checkOverlaps);
279   }
280   G4cout << G4endl;
281 
282   // Absorber
283 
284   fSolidAbsorber =
285     new G4Tubs("Absorber", 1.0 * mm, fAbsorberRadius, fAbsorberThickness / 2., 0.0, twopi);
286 
287   fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, fAbsorberMaterial, "Absorber");
288 
289   fPhysiAbsorber = new G4PVPlacement(nullptr, G4ThreeVector(0., 0., fZAbsorber), "Absorber",
290                                      fLogicAbsorber, fPhysiWorld, false, 0, checkOverlaps);
291 
292   return fPhysiWorld;
293 }
294 
295 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
296 
297 void F03DetectorConstruction::PrintCalorParameters()
298 {
299   G4cout << "\n The  WORLD   is made of " << fWorldSizeZ / mm << "mm of "
300          << fWorldMaterial->GetName();
301   G4cout << ", the transverse size (R) of the world is " << fWorldSizeR / mm << " mm. " << G4endl;
302   G4cout << " The ABSORBER is made of " << fAbsorberThickness / mm << "mm of "
303          << fAbsorberMaterial->GetName();
304   G4cout << ", the transverse size (R) is " << fAbsorberRadius / mm << " mm. " << G4endl;
305   G4cout << " Z position of the (middle of the) absorber " << fZAbsorber / mm << "  mm." << G4endl;
306   G4cout << G4endl;
307 }
308 
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
311 void F03DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
312 {
313   // get the pointer to the material table
314   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
315 
316   // search the material by its name
317   G4Material* material;
318   for (size_t j = 0; j < theMaterialTable->size(); j++) {
319     material = (*theMaterialTable)[j];
320     if (material->GetName() == materialChoice) {
321       fAbsorberMaterial = material;
322       fLogicAbsorber->SetMaterial(material);
323       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
324     }
325   }
326 }
327 
328 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
329 
330 void F03DetectorConstruction::SetWorldMaterial(G4String materialChoice)
331 {
332   // get the pointer to the material table
333   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
334 
335   // search the material by its name
336   G4Material* material;
337   for (size_t j = 0; j < theMaterialTable->size(); j++) {
338     material = (*theMaterialTable)[j];
339     if (material->GetName() == materialChoice) {
340       fWorldMaterial = material;
341       fLogicWorld->SetMaterial(material);
342       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
343     }
344   }
345 }
346 
347 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
348 
349 void F03DetectorConstruction::SetAbsorberThickness(G4double val)
350 {
351   // change Absorber thickness and recompute the calorimeter parameters
352   fAbsorberThickness = val;
353   ComputeCalorParameters();
354   G4RunManager::GetRunManager()->GeometryHasBeenModified();
355 }
356 
357 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
358 
359 void F03DetectorConstruction::SetAbsorberRadius(G4double val)
360 {
361   // change the transverse size and recompute the calorimeter parameters
362   fAbsorberRadius = val;
363   ComputeCalorParameters();
364   G4RunManager::GetRunManager()->GeometryHasBeenModified();
365 }
366 
367 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
368 
369 void F03DetectorConstruction::SetWorldSizeZ(G4double val)
370 {
371   fWorldSizeZ = val;
372   ComputeCalorParameters();
373   G4RunManager::GetRunManager()->GeometryHasBeenModified();
374 }
375 
376 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
377 
378 void F03DetectorConstruction::SetWorldSizeR(G4double val)
379 {
380   fWorldSizeR = val;
381   ComputeCalorParameters();
382   G4RunManager::GetRunManager()->GeometryHasBeenModified();
383 }
384 
385 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
386 
387 void F03DetectorConstruction::SetAbsorberZpos(G4double val)
388 {
389   fZAbsorber = val;
390   ComputeCalorParameters();
391   G4RunManager::GetRunManager()->GeometryHasBeenModified();
392 }
393 
394 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
395 
396 void F03DetectorConstruction::SetFieldValue(G4ThreeVector value)
397 {
398   fFieldVector = value;
399 
400   G4UniformMagField* magField = nullptr;
401   if (fFieldVector != G4ThreeVector(0.,0.,0.)) {
402     magField = new G4UniformMagField(fFieldVector);
403   }
404 
405   // Set field to the field builder
406   auto fieldBuilder = G4FieldBuilder::Instance();
407   fieldBuilder->SetGlobalField(magField);
408 }
409 
410 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
411 
412 
413 void F03DetectorConstruction::SetLocalFieldValue(G4ThreeVector value)
414 {
415   fLocalFieldVector = value;
416 
417   G4UniformMagField* magField = nullptr;
418   if (fLocalFieldVector != G4ThreeVector(0.,0.,0.)) {
419     magField = new G4UniformMagField(fLocalFieldVector);
420   }
421 
422   // Set field to the field builder
423   auto fieldBuilder = G4FieldBuilder::Instance();
424   fieldBuilder->SetLocalField(magField, fLogicRadiator);
425 }
426 
427 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
428 
429 void F03DetectorConstruction::ConstructSDandField()
430 {
431   // Sensitive Detectors: Absorber
432 
433   if (!fCalorimeterSD.Get()) {
434     auto calorimeterSD = new F03CalorimeterSD("CalorSD", this);
435     fCalorimeterSD.Put(calorimeterSD);
436   }
437   G4SDManager::GetSDMpointer()->AddNewDetector(fCalorimeterSD.Get());
438   SetSensitiveDetector(fLogicAbsorber, fCalorimeterSD.Get());
439 
440   // Create detector fields
441   SetFieldValue(fFieldVector);
442   SetLocalFieldValue(fLocalFieldVector);
443 
444   // Construct all Geant4 field objects
445   auto fieldBuilder = G4FieldBuilder::Instance();
446   fieldBuilder->ConstructFieldSetup();
447 }
448 
449 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
450