Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-25 08:03:05

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 //
0027 /// \file radiobiology/src/DetectorConstruction.cc
0028 /// \brief Implementation of the RadioBio::DetectorConstruction class
0029 
0030 #include "DetectorConstruction.hh"
0031 
0032 #include "G4Box.hh"
0033 #include "G4GeometryManager.hh"
0034 #include "G4LogicalVolume.hh"
0035 #include "G4LogicalVolumeStore.hh"
0036 #include "G4Material.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4PhysicalVolumeStore.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4SolidStore.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044 #include "G4VisAttributes.hh"
0045 
0046 #include "DetectorMessenger.hh"
0047 #include "VoxelizedSensitiveDetector.hh"
0048 
0049 #include <sstream>
0050 
0051 namespace RadioBio
0052 {
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 DetectorConstruction::DetectorConstruction()
0057 {
0058   // Set the default box material
0059   SetMaterial("G4_WATER");
0060 
0061   // Create the messenger
0062   fDetectorMessenger = new DetectorMessenger(this);
0063 
0064   // Voxelize the detecctor with default size
0065   VoxelizedSensitiveDetector::CreateInstance(this, 0.1 * m, 1 * m, 1 * m);
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 DetectorConstruction::~DetectorConstruction()
0071 {
0072   delete fDetectorMessenger;
0073 }
0074 
0075 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0076 
0077 G4VPhysicalVolume* DetectorConstruction::Construct()
0078 {
0079   return ConstructVolumes();
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0083 
0084 void DetectorConstruction::ConstructSDandField()
0085 {
0086   VoxelizedSensitiveDetector::GetInstance()->ConstructSD();
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0090 
0091 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0092 {
0093   // Cleanup old geometry
0094   G4GeometryManager::GetInstance()->OpenGeometry();
0095   G4PhysicalVolumeStore::GetInstance()->Clean();
0096   G4LogicalVolumeStore::GetInstance()->Clean();
0097   G4SolidStore::GetInstance()->Clean();
0098 
0099   // Materials
0100   G4bool isotopes = false;
0101   G4Material* airNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR", isotopes);
0102 
0103   // Simulation world
0104   const G4double worldX = 400.0 * cm;
0105   const G4double worldY = 400.0 * cm;
0106   const G4double worldZ = 400.0 * cm;
0107 
0108   G4Box* sWorld = new G4Box("TreatmentRoom", worldX, worldY, worldZ);
0109 
0110   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, airNist, "logicWorld", 0, 0, 0);
0111 
0112   pWorld = new G4PVPlacement(0, G4ThreeVector(), "physicsWorld", lWorld, 0, false, 0);
0113 
0114   // Create a visual attribute for the world
0115   G4VisAttributes* worldVisAttributes = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));  // Blue color
0116   worldVisAttributes->SetVisibility(true);  // Ensure visibility
0117   worldVisAttributes->SetForceWireframe(true);  // Optional: make it wireframe for clarity
0118   lWorld->SetVisAttributes(worldVisAttributes);
0119 
0120   G4Box* sBox = new G4Box("Container", fBoxSizeX / 2, fBoxSizeY / 2, fBoxSizeZ / 2);
0121 
0122   fLBox = new G4LogicalVolume(sBox, fMaterial, fMaterial->GetName());
0123 
0124   fPBox = new G4PVPlacement(0, G4ThreeVector(), fLBox, fMaterial->GetName(), lWorld, false, 0);
0125 
0126   // Initialize pointer to world for voxelization
0127   VoxelizedSensitiveDetector::GetInstance()->InitializeWorldPtr(fPBox);
0128 
0129   // Create Voxelized Geometry
0130   VoxelizedSensitiveDetector::GetInstance()->Construct();
0131 
0132   // Always return the root volume
0133   return pWorld;
0134 }
0135 
0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0137 
0138 void DetectorConstruction::PrintParameters()
0139 {
0140   G4cout << "\n The Box dimensions are: " << G4endl
0141          << "x: " << G4BestUnit(fBoxSizeX, "Length") << G4endl
0142          << "y: " << G4BestUnit(fBoxSizeY, "Length") << G4endl
0143          << "z: " << G4BestUnit(fBoxSizeZ, "Length") << G4endl;
0144 
0145   G4cout << "And its volume therefore is: "
0146          << fPBox->GetLogicalVolume()->GetSolid()->GetCubicVolume() / m3 << " m3" << G4endl;
0147 }
0148 
0149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0150 
0151 void DetectorConstruction::SetMaterial(G4String materialChoice)
0152 {
0153   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0154 
0155   if (pttoMaterial) {
0156     if (fMaterial != pttoMaterial) {
0157       fMaterial = pttoMaterial;
0158       if (fLBox) {
0159         fLBox->SetMaterial(pttoMaterial);
0160       }
0161       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0162     }
0163   } else {
0164     std::stringstream sstr;
0165     sstr << "material " << +materialChoice << " does not exist, keeping material "
0166          << fMaterial->GetName();
0167 
0168     G4Exception("DetectorConstruction::SetMaterial", "NoWorldMat", JustWarning, sstr.str().c_str());
0169   }
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 
0174 void DetectorConstruction::SetSize(G4double value)
0175 {
0176   SetSizeX(value);
0177   SetSizeY(value);
0178   SetSizeZ(value);
0179 }
0180 
0181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0182 
0183 void DetectorConstruction::SetSize(G4ThreeVector size)
0184 {
0185   SetSizeX(size.getX());
0186   SetSizeY(size.getY());
0187   SetSizeZ(size.getZ());
0188 }
0189 
0190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0191 
0192 void DetectorConstruction::SetSizeX(G4double sizeX)
0193 {
0194   fBoxSizeX = sizeX;
0195 }
0196 
0197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0198 
0199 void DetectorConstruction::SetSizeY(G4double sizeY)
0200 {
0201   fBoxSizeY = sizeY;
0202 }
0203 
0204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0205 
0206 void DetectorConstruction::SetSizeZ(G4double sizeZ)
0207 {
0208   fBoxSizeZ = sizeZ;
0209 }
0210 
0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0212 
0213 }  // namespace RadioBio