Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 08:28:53

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 #include "DetectorConstruction.hh"
0030 
0031 #include "DetectorMessenger.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4UnitsTable.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 DetectorConstruction::DetectorConstruction()
0049 {
0050   fBoxSize = 1 * m;
0051   DefineMaterials();
0052   SetMaterial("Water_ts");
0053   fDetectorMessenger = new DetectorMessenger(this);
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 DetectorConstruction::~DetectorConstruction()
0059 {
0060   delete fDetectorMessenger;
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 G4VPhysicalVolume* DetectorConstruction::Construct()
0066 {
0067   return ConstructVolumes();
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void DetectorConstruction::DefineMaterials()
0073 {
0074   // specific element name for thermal neutronHP
0075   // (see G4ParticleHPThermalScatteringNames.cc)
0076 
0077   G4int ncomponents, natoms;
0078 
0079   // pressurized water
0080   G4Element* H = new G4Element("TS_H_of_Water", "H", 1., 1.0079 * g / mole);
0081   G4Element* O = new G4Element("Oxygen", "O", 8., 16.00 * g / mole);
0082   G4Material* H2O = new G4Material("Water_ts", 1.000 * g / cm3, ncomponents = 2, kStateLiquid,
0083                                    593 * kelvin, 150 * bar);
0084   H2O->AddElement(H, natoms = 2);
0085   H2O->AddElement(O, natoms = 1);
0086   H2O->GetIonisation()->SetMeanExcitationEnergy(78.0 * eV);
0087 
0088   // heavy water
0089   G4Isotope* H2 = new G4Isotope("H2", 1, 2);
0090   G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1);
0091   D->AddIsotope(H2, 100 * perCent);
0092   G4Material* D2O = new G4Material("HeavyWater", 1.11 * g / cm3, ncomponents = 2, kStateLiquid,
0093                                    293.15 * kelvin, 1 * atmosphere);
0094   D2O->AddElement(D, natoms = 2);
0095   D2O->AddElement(O, natoms = 1);
0096 
0097   // graphite
0098   G4Isotope* C12 = new G4Isotope("C12", 6, 12);
0099   G4Element* C = new G4Element("TS_C_of_Graphite", "C", ncomponents = 1);
0100   C->AddIsotope(C12, 100. * perCent);
0101   G4Material* graphite = new G4Material("graphite", 2.27 * g / cm3, ncomponents = 1, kStateSolid,
0102                                         293 * kelvin, 1 * atmosphere);
0103   graphite->AddElement(C, natoms = 1);
0104 
0105   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0109 
0110 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol,
0111                                                             G4double density, G4int Z, G4int A)
0112 {
0113   // define a material from an isotope
0114   //
0115   G4int ncomponents;
0116   G4double abundance, massfraction;
0117 
0118   G4Isotope* isotope = new G4Isotope(symbol, Z, A);
0119 
0120   G4Element* element = new G4Element(name, symbol, ncomponents = 1);
0121   element->AddIsotope(isotope, abundance = 100. * perCent);
0122 
0123   G4Material* material = new G4Material(name, density, ncomponents = 1);
0124   material->AddElement(element, massfraction = 100. * perCent);
0125 
0126   return material;
0127 }
0128 
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0130 
0131 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0132 {
0133   // Cleanup old geometry
0134   G4GeometryManager::GetInstance()->OpenGeometry();
0135   G4PhysicalVolumeStore::GetInstance()->Clean();
0136   G4LogicalVolumeStore::GetInstance()->Clean();
0137   G4SolidStore::GetInstance()->Clean();
0138 
0139   G4Box* sBox = new G4Box("Container",  // its name
0140                           fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);  // its dimensions
0141 
0142   fLBox = new G4LogicalVolume(sBox,  // its shape
0143                               fMaterial,  // its material
0144                               fMaterial->GetName());  // its name
0145 
0146   fPBox = new G4PVPlacement(0,  // no rotation
0147                             G4ThreeVector(),  // at (0,0,0)
0148                             fLBox,  // its logical volume
0149                             fMaterial->GetName(),  // its name
0150                             0,  // its mother  volume
0151                             false,  // no boolean operation
0152                             0);  // copy number
0153 
0154   PrintParameters();
0155 
0156   // always return the root volume
0157   //
0158   return fPBox;
0159 }
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0162 
0163 void DetectorConstruction::PrintParameters()
0164 {
0165   G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0166          << "\n \n"
0167          << fMaterial << G4endl;
0168 }
0169 
0170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0171 
0172 void DetectorConstruction::SetMaterial(G4String materialChoice)
0173 {
0174   // search the material by its name
0175   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0176 
0177   if (pttoMaterial) {
0178     if (fMaterial != pttoMaterial) {
0179       fMaterial = pttoMaterial;
0180       if (fLBox) {
0181         fLBox->SetMaterial(pttoMaterial);
0182       }
0183       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0184     }
0185   }
0186   else {
0187     G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " << materialChoice
0188            << " not found" << G4endl;
0189   }
0190 }
0191 
0192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0193 
0194 void DetectorConstruction::SetSize(G4double value)
0195 {
0196   fBoxSize = value;
0197   G4RunManager::GetRunManager()->ReinitializeGeometry();
0198 }
0199 
0200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......