Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:28:48

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 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 "G4Box.hh"
0038 #include "G4GeometryManager.hh"
0039 #include "G4LogicalVolume.hh"
0040 #include "G4LogicalVolumeStore.hh"
0041 #include "G4Material.hh"
0042 #include "G4NistManager.hh"
0043 #include "G4PVPlacement.hh"
0044 #include "G4PhysicalConstants.hh"
0045 #include "G4PhysicalVolumeStore.hh"
0046 #include "G4RunManager.hh"
0047 #include "G4SolidStore.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4UnitsTable.hh"
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 DetectorConstruction::DetectorConstruction()
0054 {
0055   // default geometrical parameters
0056   fAbsorThickness = 1 * cm;
0057   fAbsorSizeYZ = 1 * cm;
0058   fWorldSizeX = 1.2 * fAbsorThickness;
0059   fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
0060 
0061   // materials
0062   DefineMaterials();
0063   SetAbsorMaterial("G4_Co");
0064 
0065   // create commands for interactive definition of the geometry
0066   fDetectorMessenger = new DetectorMessenger(this);
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 DetectorConstruction::~DetectorConstruction()
0072 {
0073   delete fDetectorMessenger;
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 
0078 G4VPhysicalVolume* DetectorConstruction::Construct()
0079 {
0080   return ConstructVolumes();
0081 }
0082 
0083 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0084 
0085 void DetectorConstruction::DefineMaterials()
0086 {
0087   // specific element name for thermal neutronHP
0088   // (see G4ParticleHPThermalScatteringNames.cc)
0089 
0090   G4int ncomponents, natoms;
0091 
0092   // pressurized water
0093   G4Element* H = new G4Element("TS_H_of_Water", "H", 1., 1.0079 * g / mole);
0094   G4Element* O = new G4Element("Oxygen", "O", 8., 16.00 * g / mole);
0095   G4Material* H2O = new G4Material("Water_ts", 1.000 * g / cm3, ncomponents = 2, kStateLiquid,
0096                                    593 * kelvin, 150 * bar);
0097   H2O->AddElement(H, natoms = 2);
0098   H2O->AddElement(O, natoms = 1);
0099   H2O->GetIonisation()->SetMeanExcitationEnergy(78.0 * eV);
0100 
0101   // heavy water
0102   G4Isotope* H2 = new G4Isotope("H2", 1, 2);
0103   G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1);
0104   D->AddIsotope(H2, 100 * perCent);
0105   G4Material* D2O = new G4Material("HeavyWater", 1.11 * g / cm3, ncomponents = 2, kStateLiquid,
0106                                    293.15 * kelvin, 1 * atmosphere);
0107   D2O->AddElement(D, natoms = 2);
0108   D2O->AddElement(O, natoms = 1);
0109 
0110   // graphite
0111   G4Isotope* C12 = new G4Isotope("C12", 6, 12);
0112   G4Element* C = new G4Element("TS_C_of_Graphite", "C", ncomponents = 1);
0113   C->AddIsotope(C12, 100. * perCent);
0114   G4Material* graphite = new G4Material("graphite", 2.27 * g / cm3, ncomponents = 1, kStateSolid,
0115                                         293 * kelvin, 1 * atmosphere);
0116   graphite->AddElement(C, natoms = 1);
0117 
0118   // example of vacuum
0119   fWorldMaterial = new G4Material("Galactic", 1, 1.01 * g / mole, universe_mean_density, kStateGas,
0120                                   2.73 * kelvin, 3.e-18 * pascal);
0121 
0122   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0126 
0127 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol,
0128                                                             G4double density, G4int Z, G4int A)
0129 {
0130   // define a material from an isotope
0131   //
0132   G4int ncomponents;
0133   G4double abundance, massfraction;
0134 
0135   G4Isotope* isotope = new G4Isotope(symbol, Z, A);
0136 
0137   G4Element* element = new G4Element(name, symbol, ncomponents = 1);
0138   element->AddIsotope(isotope, abundance = 100. * perCent);
0139 
0140   G4Material* material = new G4Material(name, density, ncomponents = 1);
0141   material->AddElement(element, massfraction = 100. * perCent);
0142 
0143   return material;
0144 }
0145 
0146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0147 
0148 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0149 {
0150   // Cleanup old geometry
0151   G4GeometryManager::GetInstance()->OpenGeometry();
0152   G4PhysicalVolumeStore::GetInstance()->Clean();
0153   G4LogicalVolumeStore::GetInstance()->Clean();
0154   G4SolidStore::GetInstance()->Clean();
0155 
0156   // World
0157   //
0158   fWorldSizeX = 1.2 * fAbsorThickness;
0159   fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
0160 
0161   G4Box* sWorld = new G4Box("World",  // name
0162                             fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);  // dimensions
0163 
0164   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,  // shape
0165                                                 fWorldMaterial,  // material
0166                                                 "World");  // name
0167 
0168   fWorldVolume = new G4PVPlacement(0,  // no rotation
0169                                    G4ThreeVector(),  // at (0,0,0)
0170                                    lWorld,  // logical volume
0171                                    "World",  // name
0172                                    0,  // mother volume
0173                                    false,  // no boolean operation
0174                                    0);  // copy number
0175 
0176   // Absorber
0177   //
0178   G4Box* sAbsor = new G4Box("Absorber",  // name
0179                             fAbsorThickness / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2);  // dimensions
0180 
0181   fLAbsor = new G4LogicalVolume(sAbsor,  // shape
0182                                 fAbsorMaterial,  // material
0183                                 fAbsorMaterial->GetName());  // name
0184 
0185   new G4PVPlacement(0,  // no rotation
0186                     G4ThreeVector(),  // at (0,0,0)
0187                     fLAbsor,  // logical volume
0188                     fAbsorMaterial->GetName(),  // name
0189                     lWorld,  // mother  volume
0190                     false,  // no boolean operation
0191                     0);  // copy number
0192 
0193   PrintParameters();
0194 
0195   // always return the root volume
0196   //
0197   return fWorldVolume;
0198 }
0199 
0200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0201 
0202 void DetectorConstruction::PrintParameters()
0203 {
0204   G4cout << "\n The Absorber is " << G4BestUnit(fAbsorThickness, "Length") << " of "
0205          << fAbsorMaterial->GetName() << "\n \n"
0206          << fAbsorMaterial << G4endl;
0207 }
0208 
0209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0210 
0211 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice)
0212 {
0213   // search the material by its name
0214   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0215 
0216   if (pttoMaterial) {
0217     fAbsorMaterial = pttoMaterial;
0218     if (fLAbsor) {
0219       fLAbsor->SetMaterial(fAbsorMaterial);
0220     }
0221     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0222   }
0223   else {
0224     G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " << materialChoice
0225            << " not found" << G4endl;
0226   }
0227 }
0228 
0229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0230 
0231 void DetectorConstruction::SetAbsorThickness(G4double value)
0232 {
0233   fAbsorThickness = value;
0234   G4RunManager::GetRunManager()->ReinitializeGeometry();
0235 }
0236 
0237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0238 
0239 void DetectorConstruction::SetAbsorSizeYZ(G4double value)
0240 {
0241   fAbsorSizeYZ = value;
0242   G4RunManager::GetRunManager()->ReinitializeGeometry();
0243 }
0244 
0245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......