Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:27:56

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 // The `molcounters` example(s) are provided as part of Geant4-DNA
0027 // and any report or published result obtained using it shall cite
0028 // the respective Geant4-DNA collaboration publications.
0029 //
0030 // Reports or results obtained using the spatially-aware `MoleculeCounter`
0031 // provided in this example, shall further cite:
0032 //
0033 // Velten & Tomé, Radiation Physics and Chemistry, 2023 (10.1016/j.radphyschem.2023.111194)
0034 //
0035 //
0036 // Author: Christian Velten (2025)
0037 //
0038 
0039 #include "DetectorConstruction.hh"
0040 
0041 #include "G4Box.hh"
0042 #include "G4Ellipsoid.hh"
0043 #include "G4LogicalVolume.hh"
0044 #include "G4NistManager.hh"
0045 #include "G4Orb.hh"
0046 #include "G4PVPlacement.hh"
0047 #include "G4PhysicalConstants.hh"
0048 #include "G4PhysicalVolumeStore.hh"
0049 #include "G4SystemOfUnits.hh"
0050 #include "G4VPhysicalVolume.hh"
0051 #include "Randomize.hh"
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 G4VPhysicalVolume* DetectorConstruction::Construct()
0054 {
0055   // Water is defined from NIST material database
0056   auto man = G4NistManager::Instance();
0057   auto water = man->FindOrBuildMaterial("G4_WATER");
0058 
0059   //
0060   // World
0061   //
0062   const G4double worldXYZ = 1 * m;
0063 
0064   auto solidWorld = new G4Box("World", 0.5 * worldXYZ, 0.5 * worldXYZ, 0.5 * worldXYZ);
0065   auto lvWorld = new G4LogicalVolume(solidWorld, water, "World");
0066   auto pvWorld =
0067     new G4PVPlacement(nullptr, G4ThreeVector(), lvWorld, "World", nullptr, false, 0, true);
0068 
0069   //
0070   // Cell
0071   ConstructCell(pvWorld);
0072 
0073   // return the world
0074   return pvWorld;
0075 }
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 void DetectorConstruction::ConstructCell(G4VPhysicalVolume* pvWorld)
0078 {
0079   const G4double cellRadius = 7 * um;
0080   const G4double nucleusRadius = 4 * um;
0081 
0082   const G4int nMitochondria = 100;
0083   const G4double mitoA = 0.55 * micrometer;
0084   const G4double mitoB = 0.25 * micrometer;
0085   const G4double mitoC = 0.90 * micrometer;
0086 
0087   auto solidCell = new G4Orb("Cell", cellRadius);
0088   auto lvCell = new G4LogicalVolume(
0089     solidCell, G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER"), "Cell");
0090   auto pvCell =
0091     new G4PVPlacement(nullptr, G4ThreeVector(), "Cell", lvCell, pvWorld, false, 0, true);
0092 
0093   auto solidNucleus = new G4Orb("Nucleus", nucleusRadius);
0094   auto lvNucleus = new G4LogicalVolume(
0095     solidNucleus, G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER"), "Nucleus");
0096 
0097   new G4PVPlacement(nullptr, G4ThreeVector(), "Nucleus", lvNucleus, pvCell, false, 0, true);
0098 
0099   auto solidMito = new G4Ellipsoid("Mitochondria", mitoA, mitoB, mitoC);
0100   auto lvMito = new G4LogicalVolume(
0101     solidMito, G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER"), "Mitochondria");
0102 
0103   for (auto i = 0; i < nMitochondria; ++i) {
0104     G4bool overlap = true;
0105     do {
0106       auto u = twopi * G4UniformRand();
0107       auto v = std::acos(2 * G4UniformRand() - 1);
0108       auto dr = G4UniformRand() * cellRadius;
0109       auto x = dr * std::cos(u) * std::sin(v);
0110       auto y = dr * std::sin(u) * std::sin(v);
0111       auto z = dr * std::cos(v);
0112       auto pos = G4ThreeVector(x, y, z);
0113 
0114       auto phi = G4UniformRand() * 2 * pi;
0115       auto psi = G4UniformRand() * 2 * pi;
0116       auto rot = new G4RotationMatrix();
0117       rot->rotateX(psi);
0118       rot->rotateY(phi);
0119 
0120       auto pvMito = new G4PVPlacement(rot, pos, "Mitochondria", lvMito, pvCell, false, i, false);
0121 
0122       overlap = pvMito->CheckOverlaps(1000, 0, false);
0123       if (overlap) {
0124         G4PhysicalVolumeStore::DeRegister(pvMito);
0125       }
0126     } while (overlap);
0127   }
0128 }
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......