Back to home page

EIC code displayed by LXR

 
 

    


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

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 // This example is provided by the Geant4-DNA collaboration
0030 // Any report or published results obtained using the Geant4-DNA software
0031 // shall cite the following Geant4-DNA collaboration publications:
0032 // Med. Phys. 45 (2018) e722-e739
0033 // Phys. Med. 31 (2015) 861-874
0034 // Med. Phys. 37 (2010) 4692-4708
0035 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0036 //
0037 // The Geant4-DNA web site is available at http://geant4-dna.org
0038 //
0039 
0040 #include "DetectorConstruction.hh"
0041 
0042 #include "DetectorMessenger.hh"
0043 
0044 #include "G4NistManager.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4PhysicalConstants.hh"
0047 #include "G4RunManager.hh"
0048 #include "G4Sphere.hh"
0049 #include "G4UnitsTable.hh"
0050 #include "G4UserLimits.hh"
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction()
0055 {
0056   // Default tracking cut
0057 
0058   fTrackingCut = 7.4 * CLHEP::eV;
0059 
0060   // Default parameter values
0061 
0062   fWorldRadius = 10 * CLHEP::m;
0063   fCytoThickness = 20 * CLHEP::nm;
0064   fNuclRadius = 10 * CLHEP::nm;
0065 
0066   DefineMaterials();
0067 
0068   // Create commands for interactive definition of the detector
0069 
0070   fDetectorMessenger = new DetectorMessenger(this);
0071 }
0072 
0073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0074 
0075 DetectorConstruction::~DetectorConstruction()
0076 {
0077   delete fDetectorMessenger;
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void DetectorConstruction::DefineMaterials()
0083 {
0084   G4NistManager* man = G4NistManager::Instance();
0085 
0086   fWorldMaterial = man->FindOrBuildMaterial("G4_WATER");
0087   fCytoMaterial = fNuclMaterial = man->FindOrBuildMaterial("G4_WATER");
0088 }
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0091 
0092 G4VPhysicalVolume* DetectorConstruction::Construct()
0093 {
0094   if (fWorld) return fWorld;
0095 
0096   // Spherical world
0097 
0098   G4Sphere* sWorld = new G4Sphere("World", 0., 1000 * fNuclRadius, 0., twopi, 0., pi);
0099 
0100   fLogicalWorld = new G4LogicalVolume(sWorld, fWorldMaterial, "World");
0101 
0102   fWorld = new G4PVPlacement(0, G4ThreeVector(), fLogicalWorld, "World", 0, false, 0);
0103 
0104   // Spherical nucleus
0105 
0106   G4Sphere* sNucl = new G4Sphere("Nucl", 0., fNuclRadius, 0., twopi, 0., pi);
0107 
0108   fLogicalNucl = new G4LogicalVolume(sNucl, fNuclMaterial, "Nucl");
0109 
0110   fNucl = new G4PVPlacement(0, G4ThreeVector(), "Nucl", fLogicalNucl, fWorld, false, 0);
0111 
0112   // Spherical shell for cytoplasm
0113 
0114   G4Sphere* sCyto =
0115     new G4Sphere("Cyto", fNuclRadius, fNuclRadius + fCytoThickness, 0., twopi, 0., pi);
0116 
0117   fLogicalCyto = new G4LogicalVolume(sCyto, fCytoMaterial, "Cyto");
0118 
0119   fCyto = new G4PVPlacement(0, G4ThreeVector(), "Cyto", fLogicalCyto, fWorld, false, 0);
0120   //
0121 
0122   PrintParameters();
0123 
0124   // Tracking cut
0125 
0126   fLogicalNucl->SetUserLimits(new G4UserLimits(DBL_MAX, DBL_MAX, DBL_MAX, fTrackingCut));
0127   fLogicalCyto->SetUserLimits(new G4UserLimits(DBL_MAX, DBL_MAX, DBL_MAX, fTrackingCut));
0128   fLogicalWorld->SetUserLimits(new G4UserLimits(DBL_MAX, DBL_MAX, DBL_MAX, fTrackingCut));
0129 
0130   //
0131   return fWorld;
0132 }
0133 
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0135 
0136 void DetectorConstruction::PrintParameters() const
0137 {
0138   G4cout << "\n---------------------------------------------------------\n";
0139   G4cout << "---> The tracking cut is set to " << G4BestUnit(fTrackingCut, "Energy") << G4endl;
0140   G4cout << "---> The World is a sphere of " << G4BestUnit(1000 * fNuclRadius, "Length")
0141          << "radius of " << fWorldMaterial->GetName() << G4endl;
0142   G4cout << "---> The Nucleus is a sphere of " << G4BestUnit(fNuclRadius, "Length") << "radius of "
0143          << fWorldMaterial->GetName() << " of mass " << G4BestUnit(GetNuclMass(), "Mass") << G4endl;
0144   G4cout << "---> The Cytoplasm is a spherical shell of thickness "
0145          << G4BestUnit(fCytoThickness, "Length") << "of " << fWorldMaterial->GetName()
0146          << " of mass " << G4BestUnit(GetCytoMass(), "Mass") << G4endl;
0147   G4cout << "\n---------------------------------------------------------\n";
0148 }
0149 
0150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0151 
0152 void DetectorConstruction::SetTrackingCut(G4double value)
0153 {
0154   fTrackingCut = value;
0155 }
0156 
0157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0158 
0159 void DetectorConstruction::SetNuclRadius(G4double value)
0160 {
0161   fNuclRadius = value;
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0165 
0166 void DetectorConstruction::SetCytoThickness(G4double value)
0167 {
0168   fCytoThickness = value;
0169 }
0170 
0171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0172 
0173 void DetectorConstruction::SetWorldMaterial(const G4String& materialChoice)
0174 {
0175   // Search the material by its name
0176   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0177 
0178   if (pttoMaterial && pttoMaterial != fWorldMaterial) {
0179     fWorldMaterial = pttoMaterial;
0180     if (fLogicalWorld) fLogicalWorld->SetMaterial(pttoMaterial);
0181     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0182   }
0183 }
0184 
0185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0186 
0187 void DetectorConstruction::SetCytoMaterial(const G4String& materialChoice)
0188 {
0189   // Search the material by its name
0190   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0191 
0192   if (pttoMaterial && pttoMaterial != fCytoMaterial) {
0193     fCytoMaterial = pttoMaterial;
0194     if (fLogicalCyto) fLogicalCyto->SetMaterial(pttoMaterial);
0195     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0196   }
0197 }
0198 
0199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0200 
0201 void DetectorConstruction::SetNuclMaterial(const G4String& materialChoice)
0202 {
0203   // Search the material by its name
0204   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0205 
0206   if (pttoMaterial && pttoMaterial != fNuclMaterial) {
0207     fNuclMaterial = pttoMaterial;
0208     if (fLogicalNucl) fLogicalNucl->SetMaterial(pttoMaterial);
0209     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0210   }
0211 }