Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 08:29:24

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 = 10 * m;
0051   DefineMaterials();
0052   SetMaterial("Molybdenum98");
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   // define a Material from isotopes
0075   //
0076   MaterialWithSingleIsotope("Molybdenum98", "Mo98", 10.28 * g / cm3, 42, 98);
0077 
0078   // NE213
0079   G4Element* H = new G4Element("Hydrogen", "H", 1., 1.01 * g / mole);
0080   G4Element* C = new G4Element("Carbon", "C", 6., 12.00 * g / mole);
0081   G4Material* ne213 = new G4Material("NE213", 0.874 * g / cm3, 2);
0082   ne213->AddElement(H, 9.2 * perCent);
0083   ne213->AddElement(C, 90.8 * perCent);
0084 
0085   G4Material* hydrogen = new G4Material("hydrogen", 1.0 * g / cm3, 1);
0086   hydrogen->AddElement(H, 1);
0087 
0088   G4Material* carbon = new G4Material("carbon", 1.0 * g / cm3, 1);
0089   carbon->AddElement(C, 1);
0090 
0091   G4Material* plastic = new G4Material("plastic", 1.0 * g / cm3, 2);
0092   plastic->AddElement(H, 1);
0093   plastic->AddElement(C, 1);
0094 
0095   // or use G4-NIST materials data base
0096   //
0097   G4NistManager* man = G4NistManager::Instance();
0098   man->FindOrBuildMaterial("G4_B");
0099 
0100   G4Element* O = man->FindOrBuildElement("O");
0101   G4Element* Hf = man->FindOrBuildElement("Hf");
0102 
0103   G4Material* HfO2 = new G4Material("HfO2", 9.68 * g / cm3, 2);
0104   HfO2->AddElement(Hf, 1);
0105   HfO2->AddElement(O, 2);
0106 
0107   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0108 }
0109 
0110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0111 
0112 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol,
0113                                                             G4double density, G4int Z, G4int A)
0114 {
0115   // define a material from an isotope
0116   //
0117   G4int ncomponents;
0118   G4double abundance, massfraction;
0119 
0120   G4Isotope* isotope = new G4Isotope(symbol, Z, A);
0121 
0122   G4Element* element = new G4Element(name, symbol, ncomponents = 1);
0123   element->AddIsotope(isotope, abundance = 100. * perCent);
0124 
0125   G4Material* material = new G4Material(name, density, ncomponents = 1);
0126   material->AddElement(element, massfraction = 100. * perCent);
0127 
0128   return material;
0129 }
0130 
0131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0132 
0133 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0134 {
0135   // Cleanup old geometry
0136   G4GeometryManager::GetInstance()->OpenGeometry();
0137   G4PhysicalVolumeStore::GetInstance()->Clean();
0138   G4LogicalVolumeStore::GetInstance()->Clean();
0139   G4SolidStore::GetInstance()->Clean();
0140 
0141   G4Box* sBox = new G4Box("Container",  // its name
0142                           fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);  // its dimensions
0143 
0144   fLBox = new G4LogicalVolume(sBox,  // its shape
0145                               fMaterial,  // its material
0146                               fMaterial->GetName());  // its name
0147 
0148   fPBox = new G4PVPlacement(0,  // no rotation
0149                             G4ThreeVector(),  // at (0,0,0)
0150                             fLBox,  // its logical volume
0151                             fMaterial->GetName(),  // its name
0152                             0,  // its mother  volume
0153                             false,  // no boolean operation
0154                             0);  // copy number
0155 
0156   PrintParameters();
0157 
0158   // always return the root volume
0159   //
0160   return fPBox;
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void DetectorConstruction::PrintParameters()
0166 {
0167   G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0168          << "\n \n"
0169          << fMaterial << G4endl;
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 
0174 void DetectorConstruction::SetMaterial(G4String materialChoice)
0175 {
0176   // search the material by its name
0177   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0178 
0179   if (pttoMaterial) {
0180     if (fMaterial != pttoMaterial) {
0181       fMaterial = pttoMaterial;
0182       if (fLBox) {
0183         fLBox->SetMaterial(pttoMaterial);
0184       }
0185       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0186     }
0187   }
0188   else {
0189     G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " << materialChoice
0190            << " not found" << G4endl;
0191   }
0192 }
0193 
0194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0195 
0196 void DetectorConstruction::SetSize(G4double value)
0197 {
0198   fBoxSize = value;
0199   G4RunManager::GetRunManager()->ReinitializeGeometry();
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......