Files
geant4/examples/extended/medical/dna/range/src/DetectorConstruction.cc
T
2024-06-28 13:08:51 +02:00

169 lines
6.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// This example is provided by the Geant4-DNA collaboration
// Any report or published results obtained using the Geant4-DNA software
// shall cite the following Geant4-DNA collaboration publications:
// Med. Phys. 45 (2018) e722-e739
// Phys. Med. 31 (2015) 861-874
// Med. Phys. 37 (2010) 4692-4708
// Int. J. Model. Simul. Sci. Comput. 1 (2010) 157178
//
// The Geant4-DNA web site is available at http://geant4-dna.org
//
/// \file medical/dna/range/src/DetectorConstruction.cc
/// \brief Implementation of the DetectorConstruction class
#include "DetectorConstruction.hh"
#include "DetectorMessenger.hh"
#include "G4GeometryManager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4NistManager.hh"
#include "G4PVPlacement.hh"
#include "G4PhysicalConstants.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4RunManager.hh"
#include "G4SolidStore.hh"
#include "G4Sphere.hh"
#include "G4SystemOfUnits.hh"
#include "G4UnitsTable.hh"
#include "G4UserLimits.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
: G4VUserDetectorConstruction(), fAbsorMaterial(0), fAbsor(0), fDetectorMessenger(0)
{
// Default tracking cut
fTrackingCut = 7.4 * eV;
// Default parameter values
fAbsorRadius = 1 * m;
DefineMaterials();
SetMaterial("G4_WATER");
// Create commands for interactive definition of the detector
fDetectorMessenger = new DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
delete fDetectorMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::Construct()
{
return ConstructVolumes();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::DefineMaterials()
{
G4NistManager* man = G4NistManager::Instance();
man->FindOrBuildMaterial("G4_WATER");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
{
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// Spherical absorber
G4Sphere* sAbsor = new G4Sphere("Absorber", // name
0., fAbsorRadius, 0., twopi, 0., pi); // size
fLogicalAbsor = new G4LogicalVolume(sAbsor, // solid
fAbsorMaterial, // material
"Absorber"); // name
fAbsor = new G4PVPlacement(0, // no rotation
G4ThreeVector(), // at (0,0,0)
fLogicalAbsor, // logical volume
"Absorber", // name
0, // mother volume
false, // no boolean operation
0); // copy number
PrintParameters();
fLogicalAbsor->SetUserLimits(new G4UserLimits(DBL_MAX, DBL_MAX, DBL_MAX, fTrackingCut));
// Always return the root volume
return fAbsor;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::PrintParameters() const
{
G4cout << "\n---------------------------------------------------------\n";
G4cout << "---> The tracking cut to all particles is set to "
<< G4BestUnit(fTrackingCut, "Energy") << G4endl;
G4cout << "---> The Absorber is a sphere of " << G4BestUnit(fAbsorRadius, "Length")
<< " radius of " << fAbsorMaterial->GetName() << " made of"
<< "\n \n"
<< fAbsorMaterial << G4endl;
G4cout << "\n---------------------------------------------------------\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetTrackingCut(G4double value)
{
fTrackingCut = value;
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetRadius(G4double value)
{
fAbsorRadius = value;
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetMaterial(G4String materialChoice)
{
G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
// Search the material by its name
G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
if (pttoMaterial) fAbsorMaterial = pttoMaterial;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}