Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:50:29

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 "G4PhysicalConstants.hh"
0041 #include "G4PhysicalVolumeStore.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SolidStore.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4Tubs.hh"
0046 #include "G4UnitsTable.hh"
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0049 
0050 DetectorConstruction::DetectorConstruction()
0051 {
0052   fAbsorRadius = 15 * mm;
0053   fAbsorLength = 60 * mm;
0054   fContainThickness = 2.4 * mm;
0055   DefineMaterials();
0056   SetAbsorMaterial("BeO");
0057   SetContainMaterial("Stainless-Steel");
0058   fDetectorMessenger = new DetectorMessenger(this);
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 DetectorConstruction::~DetectorConstruction()
0064 {
0065   delete fDetectorMessenger;
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 G4VPhysicalVolume* DetectorConstruction::Construct()
0071 {
0072   return ConstructVolumes();
0073 }
0074 
0075 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0076 
0077 void DetectorConstruction::DefineMaterials()
0078 {
0079   G4int ncomponents, natoms;
0080 
0081   G4Element* Be = new G4Element("Beryllium", "Be", 4., 9.01 * g / mole);
0082   G4Element* N = new G4Element("Nitrogen", "N", 7., 14.01 * g / mole);
0083   G4Element* O = new G4Element("Oxygen", "O", 8., 16.00 * g / mole);
0084   G4Element* Cr = new G4Element("Chromium", "Cr", 24., 51.99 * g / mole);
0085   G4Element* Fe = new G4Element("Iron", "Fe", 26., 55.84 * g / mole);
0086   G4Element* Ni = new G4Element("Nickel", "Ni", 28., 58.69 * g / mole);
0087 
0088   G4Material* BeO = new G4Material("BeO", 3.05 * g / cm3, ncomponents = 2);
0089   BeO->AddElement(Be, natoms = 1);
0090   BeO->AddElement(O, natoms = 1);
0091 
0092   G4Material* inox = new G4Material("Stainless-Steel", 8 * g / cm3, ncomponents = 3);
0093   inox->AddElement(Fe, 74 * perCent);
0094   inox->AddElement(Cr, 18 * perCent);
0095   inox->AddElement(Ni, 8 * perCent);
0096 
0097   G4Material* Air = new G4Material("Air", 1.290 * mg / cm3, ncomponents = 2);
0098   Air->AddElement(N, 70. * perCent);
0099   Air->AddElement(O, 30. * perCent);
0100 
0101   fWorldMaterial = Air;
0102 
0103   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol,
0109                                                             G4double density, G4int Z, G4int A)
0110 {
0111   // define a material from an isotope
0112   //
0113   G4int ncomponents;
0114   G4double abundance, massfraction;
0115 
0116   G4Isotope* isotope = new G4Isotope(symbol, Z, A);
0117 
0118   G4Element* element = new G4Element(name, symbol, ncomponents = 1);
0119   element->AddIsotope(isotope, abundance = 100. * perCent);
0120 
0121   G4Material* material = new G4Material(name, density, ncomponents = 1);
0122   material->AddElement(element, massfraction = 100. * perCent);
0123 
0124   return material;
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0130 {
0131   // Cleanup old geometry
0132   G4GeometryManager::GetInstance()->OpenGeometry();
0133   G4PhysicalVolumeStore::GetInstance()->Clean();
0134   G4LogicalVolumeStore::GetInstance()->Clean();
0135   G4SolidStore::GetInstance()->Clean();
0136 
0137   // compute dimensions
0138   G4double ContainRadius = fAbsorRadius + fContainThickness;
0139   G4double ContainLength = fAbsorLength + 2 * fContainThickness;
0140 
0141   G4double WorldSizeXY = 2.4 * ContainRadius;
0142   G4double WorldSizeZ = 1.2 * ContainLength;
0143 
0144   // World
0145   //
0146   G4Box* sWorld = new G4Box("World",  // name
0147                             0.5 * WorldSizeXY, 0.5 * WorldSizeXY, 0.5 * WorldSizeZ);  // dimensions
0148 
0149   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,  // shape
0150                                                 fWorldMaterial,  // material
0151                                                 "World");  // name
0152 
0153   fPWorld = new G4PVPlacement(0,  // no rotation
0154                               G4ThreeVector(),  // at (0,0,0)
0155                               lWorld,  // logical volume
0156                               "World",  // name
0157                               0,  // mother volume
0158                               false,  // no boolean operation
0159                               0);  // copy number
0160 
0161   // Container
0162   //
0163   G4Tubs* sContain = new G4Tubs("Container",  // name
0164                                 0., ContainRadius, 0.5 * ContainLength, 0., twopi);  // dimensions
0165 
0166   fLContain = new G4LogicalVolume(sContain,  // shape
0167                                   fContainMaterial,  // material
0168                                   fContainMaterial->GetName());  // name
0169 
0170   new G4PVPlacement(0,  // no rotation
0171                     G4ThreeVector(),  // at (0,0,0)
0172                     fLContain,  // logical volume
0173                     fContainMaterial->GetName(),  // name
0174                     lWorld,  // mother  volume
0175                     false,  // no boolean operation
0176                     0);  // copy number
0177 
0178   // Absorber
0179   //
0180   G4Tubs* sAbsor = new G4Tubs("Absorber",  // name
0181                               0., fAbsorRadius, 0.5 * fAbsorLength, 0., twopi);  // dimensions
0182 
0183   fLAbsor = new G4LogicalVolume(sAbsor,  // shape
0184                                 fAbsorMaterial,  // material
0185                                 fAbsorMaterial->GetName());  // name
0186 
0187   new G4PVPlacement(0,  // no rotation
0188                     G4ThreeVector(),  // at (0,0,0)
0189                     fLAbsor,  // logical volume
0190                     fAbsorMaterial->GetName(),  // name
0191                     fLContain,  // mother  volume
0192                     false,  // no boolean operation
0193                     0);  // copy number
0194 
0195   PrintParameters();
0196 
0197   // always return the root volume
0198   //
0199   return fPWorld;
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0203 
0204 void DetectorConstruction::PrintParameters()
0205 {
0206   G4cout << "\n The Absorber  is a cylinder of " << fAbsorMaterial->GetName()
0207          << "  radius = " << G4BestUnit(fAbsorRadius, "Length")
0208          << "  length = " << G4BestUnit(fAbsorLength, "Length") << G4endl;
0209   G4cout << " The Container is a cylinder of " << fContainMaterial->GetName()
0210          << "  thickness = " << G4BestUnit(fContainThickness, "Length") << G4endl;
0211 
0212   G4cout << "\n" << fAbsorMaterial << G4endl;
0213   G4cout << "\n" << fContainMaterial << G4endl;
0214 }
0215 
0216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0217 
0218 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice)
0219 {
0220   // search the material by its name
0221   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0222 
0223   if (pttoMaterial) {
0224     fAbsorMaterial = pttoMaterial;
0225     if (fLAbsor) {
0226       fLAbsor->SetMaterial(fAbsorMaterial);
0227     }
0228     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0229   }
0230   else {
0231     G4cout << "\n--> warning from DetectorConstruction::SetAbsorMaterial : " << materialChoice
0232            << " not found" << G4endl;
0233   }
0234 }
0235 
0236 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0237 
0238 void DetectorConstruction::SetContainMaterial(G4String materialChoice)
0239 {
0240   // search the material by its name
0241   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0242 
0243   if (pttoMaterial) {
0244     fContainMaterial = pttoMaterial;
0245     if (fLContain) {
0246       fLContain->SetMaterial(fContainMaterial);
0247     }
0248     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0249   }
0250   else {
0251     G4cout << "\n--> warning from DetectorConstruction::SetContainMaterial : " << materialChoice
0252            << " not found" << G4endl;
0253   }
0254 }
0255 
0256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0257 
0258 void DetectorConstruction::SetAbsorRadius(G4double value)
0259 {
0260   fAbsorRadius = value;
0261   G4RunManager::GetRunManager()->ReinitializeGeometry();
0262 }
0263 
0264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0265 
0266 void DetectorConstruction::SetAbsorLength(G4double value)
0267 {
0268   fAbsorLength = value;
0269   G4RunManager::GetRunManager()->ReinitializeGeometry();
0270 }
0271 
0272 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0273 
0274 void DetectorConstruction::SetContainThickness(G4double value)
0275 {
0276   fContainThickness = value;
0277   G4RunManager::GetRunManager()->ReinitializeGeometry();
0278 }
0279 
0280 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......