Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:13

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file medical/electronScattering/src/DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 //
0029 //
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "DetectorConstruction.hh"
0034 
0035 #include "DetectorMessenger.hh"
0036 
0037 #include "G4GeometryManager.hh"
0038 #include "G4LogicalVolume.hh"
0039 #include "G4LogicalVolumeStore.hh"
0040 #include "G4Material.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PhysicalConstants.hh"
0043 #include "G4PhysicalVolumeStore.hh"
0044 #include "G4SolidStore.hh"
0045 #include "G4SystemOfUnits.hh"
0046 #include "G4Tubs.hh"
0047 #include "G4UnitsTable.hh"
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 DetectorConstruction::DetectorConstruction()
0052   : fMaterial_World(0),
0053     fMaterial_Frame(0),
0054     fMaterial_ExitWindow(0),
0055     fMaterial_ScatterFoil(0),
0056     fMaterial_MonitorChbr(0),
0057     fMaterial_Bag(0),
0058     fMaterial_Gas(0),
0059     fMaterial_Ring(0),
0060     fPvol_World(0),
0061     fPvol_Frame(0),
0062     fDetectorMessenger(0)
0063 {
0064   // materials
0065   DefineMaterials();
0066 
0067   // geometry
0068   GeometryParameters();
0069 
0070   // create commands for interactive definition of the calorimeter
0071   fDetectorMessenger = new DetectorMessenger(this);
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 DetectorConstruction::~DetectorConstruction()
0077 {
0078   delete fDetectorMessenger;
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 G4VPhysicalVolume* DetectorConstruction::Construct()
0084 {
0085   return ConstructVolumes();
0086 }
0087 
0088 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0089 
0090 void DetectorConstruction::DefineMaterials()
0091 {
0092   G4double a, z, density;
0093   G4int ncomponents, natoms;
0094   G4double fractionmass;
0095   G4double temperature, pressure;
0096 
0097   // define Elements
0098   //
0099   G4Element* H = new G4Element("Hydrogen", "H", z = 1, a = 1.0079 * g / mole);
0100   G4Element* He = new G4Element("Helium", "He", z = 2, a = 4.0026 * g / mole);
0101   G4Element* Be = new G4Element("Beryllium", "Be", z = 4, a = 9.1218 * g / mole);
0102   G4Element* C = new G4Element("Carbon", "C", z = 6, a = 12.0107 * g / mole);
0103   G4Element* N = new G4Element("Nitrogen", "N", z = 7, a = 14.0067 * g / mole);
0104   G4Element* O = new G4Element("Oxygen", "O", z = 8, a = 15.9994 * g / mole);
0105   G4Element* Al = new G4Element("Aluminium", "Al", z = 13, a = 26.9815 * g / mole);
0106   G4Element* Ar = new G4Element("Argon", "Ar", z = 18, a = 39.9480 * g / mole);
0107   G4Element* Ti = new G4Element("Titanium", "Ti", z = 22, a = 47.8670 * g / mole);
0108   G4Element* Va = new G4Element("Vanadium", "Va", z = 23, a = 50.9415 * g / mole);
0109   G4Element* Cu = new G4Element("Copper", "Cu", z = 29, a = 63.5460 * g / mole);
0110   G4Element* Ta = new G4Element("Tantalum", "Ta", z = 73, a = 180.9479 * g / mole);
0111   G4Element* Au = new G4Element("Gold", "Au", z = 79, a = 196.9666 * g / mole);
0112 
0113   // Air
0114   //
0115   G4Material* Air = new G4Material("Air", density = 1.205 * mg / cm3, ncomponents = 4, kStateGas,
0116                                    293. * kelvin, 1. * atmosphere);
0117   Air->AddElement(C, fractionmass = 0.000124);
0118   Air->AddElement(N, fractionmass = 0.755267);
0119   Air->AddElement(O, fractionmass = 0.231782);
0120   Air->AddElement(Ar, fractionmass = 0.012827);
0121 
0122   // Titanium
0123   //
0124   G4Material* Titanium = new G4Material("Titanium", density = 4.42 * g / cm3, ncomponents = 3);
0125   Titanium->AddElement(Ti, fractionmass = 0.90);
0126   Titanium->AddElement(Al, fractionmass = 0.06);
0127   Titanium->AddElement(Va, fractionmass = 0.04);
0128 
0129   // Mylar
0130   //
0131   G4Material* Mylar = new G4Material("Mylar", density = 1.40 * g / cm3, ncomponents = 3);
0132   Mylar->AddElement(H, natoms = 4);
0133   Mylar->AddElement(C, natoms = 5);
0134   Mylar->AddElement(O, natoms = 2);
0135 
0136   // Helium
0137   //
0138   G4Material* Helium = new G4Material("Helium", density = 0.166 * mg / cm3, ncomponents = 1,
0139                                       kStateGas, 293. * kelvin, 1. * atmosphere);
0140   Helium->AddElement(He, fractionmass = 1.0);
0141 
0142   // Aluminium
0143   //
0144   G4Material* Aluminium = new G4Material("Aluminium", density = 2.7 * g / cm3, ncomponents = 1);
0145   Aluminium->AddElement(Al, fractionmass = 1.0);
0146 
0147   // Beryllium
0148   //
0149   G4Material* Beryllium = new G4Material("Beryllium", density = 1.85 * g / cm3, ncomponents = 1);
0150   Beryllium->AddElement(Be, fractionmass = 1.0);
0151 
0152   // Graphite
0153   //
0154   G4Material* Graphite = new G4Material("Graphite", density = 2.18 * g / cm3, ncomponents = 1);
0155   Graphite->AddElement(C, fractionmass = 1.0);
0156 
0157   // Copper
0158   //
0159   G4Material* Copper = new G4Material("Copper", density = 8.92 * g / cm3, ncomponents = 1);
0160   Copper->AddElement(Cu, fractionmass = 1.0);
0161 
0162   // Tantalum
0163   //
0164   G4Material* Tantalum = new G4Material("Tantalum", density = 16.65 * g / cm3, ncomponents = 1);
0165   Tantalum->AddElement(Ta, fractionmass = 1.0);
0166 
0167   // Gold
0168   //
0169   G4Material* Gold = new G4Material("Gold", density = 19.30 * g / cm3, ncomponents = 1);
0170   Gold->AddElement(Au, fractionmass = 1.0);
0171 
0172   // example of vacuum
0173   //
0174   density = universe_mean_density;  // from PhysicalConstants.h
0175   pressure = 3.e-18 * pascal;
0176   temperature = 2.73 * kelvin;
0177   G4Material* Vacuum = new G4Material("Galactic", z = 1, a = 1.01 * g / mole, density, kStateGas,
0178                                       temperature, pressure);
0179 
0180   // print
0181   //
0182   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0183 
0184   // assign materials
0185   //
0186   fMaterial_World = Vacuum;
0187   fMaterial_Frame = Air;
0188   fMaterial_ExitWindow = Titanium;
0189   fMaterial_ScatterFoil = fMaterial_Frame;
0190   fMaterial_MonitorChbr = Mylar;
0191   fMaterial_Bag = Mylar;
0192   fMaterial_Gas = Helium;
0193   fMaterial_Ring = Aluminium;
0194 }
0195 
0196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0197 
0198 void DetectorConstruction::GeometryParameters()
0199 {
0200   fZfront_ExitWindow = 0.0 * um;
0201   fThickness_ExitWindow = 41.2 * um;
0202 
0203   fZfront_ScatterFoil = 2.65 * cm;
0204   fThickness_ScatterFoil = 0.0 * um;
0205 
0206   fZfront_MonitorChbr = 50. * mm;
0207   fThickness_MonitorChbr = 112.7 * um;
0208 
0209   fZfront_Bag = 64.975 * mm;
0210   fThickness_Bag = 110.0050 * cm;
0211 
0212   fThickness_Gas = 110. * cm;
0213 
0214   fThickness_Ring = 14. * mm;
0215   fInnerRadius_Ring = 20. * cm;
0216 
0217   fZfront_Frame = 2.0 * um;
0218   fThickness_Frame = 118.2 * cm;
0219 
0220   fThickness_World = fZfront_Frame + fThickness_Frame;
0221   fRadius_World = 23.3 * cm;
0222 }
0223 
0224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0225 
0226 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0227 {
0228   // Cleanup old geometry
0229   //
0230   G4GeometryManager::GetInstance()->OpenGeometry();
0231   G4PhysicalVolumeStore::GetInstance()->Clean();
0232   G4LogicalVolumeStore::GetInstance()->Clean();
0233   G4SolidStore::GetInstance()->Clean();
0234 
0235   // World
0236   //
0237   G4Tubs* svol_World = new G4Tubs("World",  // name
0238                                   0 * cm, fRadius_World,  // r1, r2
0239                                   0.5 * fThickness_World,  // half-length
0240                                   0., twopi);  // theta1, theta2
0241 
0242   G4LogicalVolume* lvol_World = new G4LogicalVolume(svol_World,  // its solid
0243                                                     fMaterial_World,  // its material
0244                                                     "World");  // its name
0245 
0246   fPvol_World = new G4PVPlacement(0,  // no rotation
0247                                   G4ThreeVector(),  // no translation
0248                                   lvol_World,  // its logical volume
0249                                   "World",  // its name
0250                                   0,  // its mother  volume
0251                                   false,  // no boolean operation
0252                                   0);  // copy number
0253 
0254   // Frame
0255   //
0256   G4Tubs* svol_Frame = new G4Tubs("Frame",  // name
0257                                   0 * cm, fRadius_World,  // r1, r2
0258                                   0.5 * fThickness_Frame,  // half-length
0259                                   0., twopi);  // theta1, theta2
0260 
0261   G4LogicalVolume* lvol_Frame = new G4LogicalVolume(svol_Frame,  // its solid
0262                                                     fMaterial_Frame,  // its material
0263                                                     "Frame");  // its name
0264 
0265   G4double zpos = fZfront_Frame;
0266 
0267   fPvol_Frame = new G4PVPlacement(0,  // no rotation
0268                                   G4ThreeVector(0, 0, zpos),  // translation
0269                                   lvol_Frame,  // its logical volume
0270                                   "Frame",  // its name
0271                                   lvol_World,  // its mother  volume
0272                                   false,  // no boolean operation
0273                                   0);  // copy number
0274 
0275   // ExitWindow
0276   //
0277   G4Tubs* svol_ExitWindow = new G4Tubs("ExitWindow",  // name
0278                                        0 * cm, fRadius_World,  // r1, r2
0279                                        0.5 * fThickness_ExitWindow,  // half-length
0280                                        0., twopi);  // theta1, theta2
0281 
0282   G4LogicalVolume* lvol_ExitWindow = new G4LogicalVolume(svol_ExitWindow,  // solid
0283                                                          fMaterial_ExitWindow,  // material
0284                                                          "ExitWindow");  // name
0285 
0286   zpos = fZfront_ExitWindow + 0.5 * fThickness_ExitWindow - 0.5 * fThickness_Frame;
0287 
0288   new G4PVPlacement(0,  // no rotation
0289                     G4ThreeVector(0, 0, zpos),  // translation
0290                     lvol_ExitWindow,  // logical volume
0291                     "ExitWindow",  // name
0292                     lvol_Frame,  // mother volume
0293                     false,  // no boolean operation
0294                     0);  // copy number
0295 
0296   // Monitor Chamber
0297   //
0298   G4Tubs* svol_MonitorChbr = new G4Tubs("MonitorChbr",  // name
0299                                         0 * cm, fRadius_World,  // r1, r2
0300                                         0.5 * fThickness_MonitorChbr,  // half-length
0301                                         0., twopi);  // theta1, theta2
0302 
0303   G4LogicalVolume* lvol_MonitorChbr = new G4LogicalVolume(svol_MonitorChbr,  // solid
0304                                                           fMaterial_MonitorChbr,  // material
0305                                                           "MonitorChbr");  // name
0306 
0307   zpos = fZfront_MonitorChbr + 0.5 * fThickness_MonitorChbr - 0.5 * fThickness_Frame;
0308 
0309   new G4PVPlacement(0,  // no rotation
0310                     G4ThreeVector(0, 0, zpos),  // translation
0311                     lvol_MonitorChbr,  // logical volume
0312                     "MonitorChbr",  // name
0313                     lvol_Frame,  // mother volume
0314                     false,  // no boolean operation
0315                     0);  // copy number
0316 
0317   // Bag
0318   //
0319   G4Tubs* svol_Bag = new G4Tubs("Bag",  // name
0320                                 0 * cm, fRadius_World,  // r1, r2
0321                                 0.5 * fThickness_Bag,  // half-length
0322                                 0., twopi);  // theta1, theta2
0323 
0324   G4LogicalVolume* lvol_Bag = new G4LogicalVolume(svol_Bag,  // solid
0325                                                   fMaterial_Bag,  // material
0326                                                   "Bag");  // name
0327 
0328   zpos = fZfront_Bag + 0.5 * fThickness_Bag - 0.5 * fThickness_Frame;
0329 
0330   new G4PVPlacement(0,  // no rotation
0331                     G4ThreeVector(0, 0, zpos),  // translation
0332                     lvol_Bag,  // logical volume
0333                     "Bag",  // name
0334                     lvol_Frame,  // mother volume
0335                     false,  // no boolean operation
0336                     0);  // copy number
0337 
0338   // Gas
0339   //
0340   G4Tubs* svol_Gas = new G4Tubs("Gas",  // name
0341                                 0 * cm, fRadius_World,  // r1, r2
0342                                 0.5 * fThickness_Gas,  // half-length
0343                                 0., twopi);  // theta1, theta2
0344 
0345   G4LogicalVolume* lvol_Gas = new G4LogicalVolume(svol_Gas,  // solid
0346                                                   fMaterial_Gas,  // material
0347                                                   "Gas");  // name
0348 
0349   new G4PVPlacement(0,  // no rotation
0350                     G4ThreeVector(),  // no translation
0351                     lvol_Gas,  // logical volume
0352                     "Gas",  // name
0353                     lvol_Bag,  // mother volume
0354                     false,  // no boolean operation
0355                     0);  // copy number
0356 
0357   // Rings
0358   //
0359   G4Tubs* svol_Ring = new G4Tubs("Ring",  // name
0360                                  fInnerRadius_Ring, fRadius_World,  // r1, r2
0361                                  0.5 * fThickness_Ring,  // half-length
0362                                  0., twopi);  // theta1, theta2
0363 
0364   G4LogicalVolume* lvol_Ring = new G4LogicalVolume(svol_Ring,  // solid
0365                                                    fMaterial_Ring,  // material
0366                                                    "Ring");  // name
0367 
0368   zpos = 0.5 * (fThickness_Gas - fThickness_Ring);
0369 
0370   new G4PVPlacement(0,  // no rotation
0371                     G4ThreeVector(0, 0, zpos),  // translation
0372                     lvol_Ring,  // logical volume
0373                     "Ring",  // name
0374                     lvol_Gas,  // mother volume
0375                     false,  // no boolean operation
0376                     1);  // copy number
0377 
0378   new G4PVPlacement(0,  // no rotation
0379                     G4ThreeVector(0, 0, -zpos),  // translation
0380                     lvol_Ring,  // logical volume
0381                     "Ring",  // name
0382                     lvol_Gas,  // mother volume
0383                     false,  // no boolean operation
0384                     2);  // copy number
0385 
0386   // ScatterFoil (only if it is not Air)
0387   //
0388   if ((fMaterial_ScatterFoil != fMaterial_Frame) && (fThickness_ScatterFoil > 0.)) {
0389     G4Tubs* svol_ScatterFoil = new G4Tubs("ScatterFoil",  // name
0390                                           0 * cm, fRadius_World,  // r1, r2
0391                                           0.5 * fThickness_ScatterFoil,  // half-length
0392                                           0., twopi);  // theta1, theta2
0393 
0394     G4LogicalVolume* lvol_ScatterFoil = new G4LogicalVolume(svol_ScatterFoil,  // solid
0395                                                             fMaterial_ScatterFoil,  // material
0396                                                             "ScatterFoil");  // name
0397 
0398     zpos = fZfront_ScatterFoil + 0.5 * fThickness_ScatterFoil - 0.5 * fThickness_Frame;
0399 
0400     new G4PVPlacement(0,  // no rotation
0401                       G4ThreeVector(0, 0, zpos),  // translation
0402                       lvol_ScatterFoil,  // logical volume
0403                       "ScatterFoil",  // name
0404                       lvol_Frame,  // mother volume
0405                       false,  // no boolean operation
0406                       0);  // copy number
0407   }
0408 
0409   PrintGeometry();
0410 
0411   // always return the physical World
0412   //
0413   return fPvol_World;
0414 }
0415 
0416 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0417 
0418 void DetectorConstruction::PrintGeometry()
0419 {
0420   // choose printing format
0421   std::ios::fmtflags mode = G4cout.flags();
0422   G4cout.setf(std::ios::fixed, std::ios::floatfield);
0423   G4int prec = G4cout.precision(6);
0424 
0425   G4cout << "\n \t \t"
0426          << "Material \t"
0427          << "Z_front \t"
0428          << "Thickness \n";
0429 
0430   G4cout << "\n  ExitWindow \t" << fMaterial_ExitWindow->GetName() << "\t"
0431          << G4BestUnit(fZfront_ExitWindow, "Length") << "\t"
0432          << G4BestUnit(fThickness_ExitWindow, "Length");
0433 
0434   if (fMaterial_ScatterFoil != fMaterial_Frame) {
0435     G4cout << "\n  ScatterFoil \t" << fMaterial_ScatterFoil->GetName() << "\t"
0436            << "\t" << G4BestUnit(fZfront_ScatterFoil, "Length") << "\t"
0437            << G4BestUnit(fThickness_ScatterFoil, "Length");
0438   }
0439 
0440   G4cout << "\n  MonitorChbr \t" << fMaterial_MonitorChbr->GetName() << "\t"
0441          << "\t" << G4BestUnit(fZfront_MonitorChbr, "Length") << "\t"
0442          << G4BestUnit(fThickness_MonitorChbr, "Length");
0443 
0444   G4double thickBagWindow = 0.5 * (fThickness_Bag - fThickness_Gas);
0445   G4double zfrontGas = fZfront_Bag + thickBagWindow;
0446   G4double zfrontBagWindow2 = zfrontGas + fThickness_Gas;
0447 
0448   G4cout << "\n  BagWindow1 \t" << fMaterial_Bag->GetName() << "\t"
0449          << "\t" << G4BestUnit(fZfront_Bag, "Length") << "\t"
0450          << G4BestUnit(thickBagWindow, "Length");
0451 
0452   G4cout << "\n  Gas       \t" << fMaterial_Gas->GetName() << "\t"
0453          << "\t" << G4BestUnit(zfrontGas, "Length") << "\t" << G4BestUnit(fThickness_Gas, "Length");
0454 
0455   G4cout << "\n  BagWindow2 \t" << fMaterial_Bag->GetName() << "\t"
0456          << "\t" << G4BestUnit(zfrontBagWindow2, "Length") << "\t"
0457          << G4BestUnit(thickBagWindow, "Length");
0458 
0459   G4cout << "\n  ScoringPlane \t" << fMaterial_Frame->GetName() << "\t"
0460          << "\t" << G4BestUnit(fThickness_Frame, "Length") << "\n"
0461          << G4endl;
0462 
0463   // restaure default formats
0464   G4cout.setf(mode, std::ios::floatfield);
0465   G4cout.precision(prec);
0466 }
0467 
0468 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0469 
0470 void DetectorConstruction::SetMaterialScatter(G4String material)
0471 {
0472   // search the material by its name
0473   G4Material* pMaterial = G4Material::GetMaterial(material);
0474 
0475   if (pMaterial) fMaterial_ScatterFoil = pMaterial;
0476 }
0477 
0478 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0479 
0480 void DetectorConstruction::SetThicknessScatter(G4double val)
0481 {
0482   fThickness_ScatterFoil = val;
0483 }
0484 
0485 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0486 
0487 #include "G4RunManager.hh"
0488 
0489 void DetectorConstruction::UpdateGeometry()
0490 {
0491   G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
0492 }
0493 
0494 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......