Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-18 07:42:22

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. 51 (2024) 5873-5889
0033 // Med. Phys. 45 (2018) e722-e739
0034 // Phys. Med. 31 (2015) 861-874
0035 // Med. Phys. 37 (2010) 4692-4708
0036 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0037 //
0038 // The Geant4-DNA web site is available at http://geant4-dna.org
0039 //
0040 
0041 #include "DetectorConstruction.hh"
0042 #include "DetectorMessenger.hh"
0043 #include "PhysicsList.hh"
0044 
0045 #include "G4LogicalVolumeStore.hh"
0046 #include "G4NistManager.hh"
0047 #include "G4RunManager.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4UserLimits.hh"
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0052 
0053 DetectorConstruction::DetectorConstruction()
0054   : G4VUserDetectorConstruction()
0055 {
0056   // Create commands for interactive definition of the detector
0057   fpDetectorMessenger = new DetectorMessenger(this);
0058 
0059   // Default values
0060 
0061   // World size
0062   fWorldSize = 100 *um;
0063   // Scorer radius
0064   fScorerRadius = 10 *um;
0065   // Material
0066   G4NistManager* man = G4NistManager::Instance();
0067   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0068   fpWaterMaterial = H2O;
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0072 
0073 DetectorConstruction::~DetectorConstruction()
0074 {
0075   delete fpDetectorMessenger;
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0079 
0080 void DetectorConstruction::DefineMaterials()
0081 {
0082   // Water is defined from NIST material database
0083   G4NistManager* man = G4NistManager::Instance();
0084 
0085   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0086 
0087   /*
0088    If one wishes to test other density value for water material,
0089    one should use instead:
0090    G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED",
0091    "G4_WATER",1.100*g/cm3);
0092 
0093    Note: any string for "G4_WATER_MODIFIED" parameter is accepted
0094    and "G4_WATER" parameter should not be changed
0095    Both materials are created and can be selected from psp.mac
0096    */
0097   fpWaterMaterial = H2O;
0098 
0099   // G4cout << "-> Density of water material (g/cm3)="
0100   //  << fWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl;
0101 
0102   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0103 }
0104 
0105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0106 
0107 G4Material*
0108 DetectorConstruction::MaterialWithDensity(G4String name, G4double density)
0109 {
0110   // Water is defined from NIST material database
0111   G4NistManager* man = G4NistManager::Instance();
0112 
0113   G4Material * material = man->BuildMaterialWithNewDensity(name,
0114    "G4_WATER", density);
0115 
0116    G4cout << "-> Density of water_modified material (g/cm3)="
0117     << material->GetDensity()/(g/cm/cm/cm) << G4endl;
0118 
0119  return material;
0120 }
0121 
0122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0123 
0124 G4VPhysicalVolume* DetectorConstruction::Construct()
0125 {
0126   if (fpPhysiWorld) {
0127     return fpPhysiWorld;
0128   }
0129 
0130   // World volume
0131   G4double worldSizeX = fWorldSize;
0132   G4double worldSizeY = worldSizeX;
0133   G4double worldSizeZ = worldSizeX;
0134 
0135   G4Box* solidWorld = new G4Box("World",  // its name
0136                                 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2);
0137                                 // its size
0138 
0139   fpLogicWorld = new G4LogicalVolume(solidWorld,  // its solid
0140                                      fpWaterMaterial,  // its material
0141                                      "World");  // its name
0142 
0143   fpPhysiWorld = new G4PVPlacement(0,  // no rotation
0144                                    G4ThreeVector(),  // at (0,0,0)
0145                                    "World",  // its name
0146                                    fpLogicWorld,  // its logical volume
0147                                    0,  // its mother volume
0148                                    false,  // no boolean operation
0149                                    0);  // copy number
0150 
0151   // Scorer is a sphere
0152   G4Orb* solidScorer = new G4Orb("Scorer",  // its name
0153                                  fScorerRadius); // its size
0154 
0155   fpLogicScorer = new G4LogicalVolume(solidScorer,  // its solid
0156                                       fpWaterMaterial,  // its material
0157                                       "Scorer");  // its name
0158 
0159   fpPhysiScorer = new G4PVPlacement(0,  // no rotation
0160                                     G4ThreeVector(),  // at (0,0,0)
0161                                     "Scorer",  // its name
0162                                     fpLogicScorer,  // its logical volume
0163                                     fpPhysiWorld,  // its mother volume
0164                                     false,  // no boolean operation
0165                                     0);  // copy number
0166 
0167   // Visualization attributes - white
0168   G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0169   worldVisAtt->SetVisibility(true);
0170   fpLogicWorld->SetVisAttributes(worldVisAtt);
0171 
0172   G4VisAttributes* scorerVisAtt = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
0173   scorerVisAtt->SetVisibility(true);
0174   fpLogicScorer->SetVisAttributes(scorerVisAtt);
0175 
0176   // Shows how to introduce a 20 eV tracking cut
0177   // logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV));
0178 
0179   return fpPhysiWorld;
0180 }
0181 
0182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0183 
0184 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0185 {
0186   // Search the material by its name
0187   G4Material* pttoMaterial =
0188     G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0189 
0190   if (pttoMaterial) {
0191     fpWaterMaterial = pttoMaterial;
0192     if (fpLogicWorld) {
0193       fpLogicWorld->SetMaterial(fpWaterMaterial);
0194     }
0195     G4RunManager::GetRunManager()->GeometryHasBeenModified();
0196   }
0197 }
0198 
0199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0200 
0201 void DetectorConstruction::SetWorldSize(G4double value)
0202 {
0203   fWorldSize = value;
0204   G4RunManager::GetRunManager()->ReinitializeGeometry();
0205 }
0206 
0207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0208 
0209 void DetectorConstruction::SetScorerRadius(G4double value)
0210 {
0211   fScorerRadius = value;
0212   G4RunManager::GetRunManager()->ReinitializeGeometry();
0213 }