Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 07:44:53

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 // The Geant4-DNA web site is available at http://geant4-dna.org
0037 //
0038 //
0039 
0040 #include "DetectorConstruction.hh"
0041 
0042 #include "DetectorMessenger.hh"
0043 #include "PhysicsList.hh"
0044 
0045 #include "G4LogicalVolume.hh"
0046 #include "G4RunManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0050 
0051 DetectorConstruction::DetectorConstruction(PhysicsList* ptr)
0052   : G4VUserDetectorConstruction(),
0053     fpWaterMaterial(nullptr),
0054     fLogicWorld(nullptr),
0055     fPhysiWorld(nullptr)
0056 {
0057   fDetectorMessenger = new DetectorMessenger(this, ptr);
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0061 
0062 DetectorConstruction::~DetectorConstruction()
0063 {
0064   delete fDetectorMessenger;
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0068 
0069 void DetectorConstruction::DefineMaterials()
0070 {
0071   // Water is defined from NIST material database
0072   G4NistManager* man = G4NistManager::Instance();
0073 
0074   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0075 
0076   /*
0077    If one wishes to test other density value for water material,
0078    one should use instead:
0079    G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED",
0080    "G4_WATER",1.100*g/cm3);
0081 
0082    Note: any string for "G4_WATER_MODIFIED" parameter is accepted
0083    and "G4_WATER" parameter should not be changed
0084    Both materials are created and can be selected from dna.mac
0085   */
0086   fpWaterMaterial = H2O;
0087 
0088   // G4cout << "-> Density of water material (g/cm3)="
0089   //  << fpWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl;
0090 
0091   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0092 }
0093 
0094 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0095 
0096 G4VPhysicalVolume* DetectorConstruction::Construct()
0097 {
0098   if (fPhysiWorld) {
0099     return fPhysiWorld;
0100   }
0101   DefineMaterials();
0102 
0103   // World volume
0104 
0105   G4double worldSizeX = 10 * micrometer;
0106   G4double worldSizeY = worldSizeX;
0107   G4double worldSizeZ = worldSizeX;
0108 
0109   G4Box* solidWorld = new G4Box("World",  // its name
0110                                 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2);  // its size
0111 
0112   fLogicWorld = new G4LogicalVolume(solidWorld,  // its solid
0113                                     fpWaterMaterial,  // its material
0114                                     "World");  // its name
0115 
0116   fPhysiWorld = new G4PVPlacement(0,  // no rotation
0117                                   G4ThreeVector(),  // at (0,0,0)
0118                                   "World",  // its name
0119                                   fLogicWorld,  // its logical volume
0120                                   0,  // its mother  volume
0121                                   false,  // no boolean operation
0122                                   0);  // copy number
0123 
0124   // Target volume
0125 
0126   G4Box* solidTarget = new G4Box("volumeTarget",  // its name
0127                                  worldSizeX / 10, worldSizeY / 2, worldSizeZ / 2);  // its size
0128 
0129   fLogicTarget = new G4LogicalVolume(solidTarget,  // its solid
0130                                      fpWaterMaterial,  // its material
0131                                      "volumeTarget");  // its name
0132 
0133   fPhysiTarget = new G4PVPlacement(0,  // no rotation
0134                                    G4ThreeVector(),  // at (0,0,0)
0135                                    "volumeTarget",  // its name
0136                                    fLogicTarget,  // its logical volume
0137                                    fPhysiWorld,  // its mother  volume
0138                                    false,  // no boolean operation
0139                                    0);  // copy number
0140 
0141   // Target region
0142 
0143   G4Region* targetRegion = new G4Region("regionTarget");
0144 
0145   // Cuts needed to allow combination of Physics
0146   // Default EM settings for fast simulation for e+, e-, gammas
0147   // 1 um proton cut avoids creation of very slow recoil ions
0148   G4ProductionCuts* cuts = new G4ProductionCuts();
0149   cuts->SetProductionCut(0.7 * mm, "gamma");
0150   cuts->SetProductionCut(0.7 * mm, "e-");
0151   cuts->SetProductionCut(0.7 * mm, "e+");
0152   cuts->SetProductionCut(1 * micrometer, "proton");
0153   targetRegion->SetProductionCuts(cuts);
0154 
0155   targetRegion->AddRootLogicalVolume(fLogicTarget);
0156 
0157   // Visualization attributes - white
0158   G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0159   worldVisAtt->SetVisibility(true);
0160   fLogicWorld->SetVisAttributes(worldVisAtt);
0161 
0162   G4VisAttributes* targetVisAtt = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
0163   targetVisAtt->SetVisibility(true);
0164   fLogicTarget->SetVisAttributes(targetVisAtt);
0165 
0166   return fPhysiWorld;
0167 }
0168 
0169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0170 
0171 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0172 {
0173   // Search the material by its name
0174   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0175 
0176   if (pttoMaterial) {
0177     fpWaterMaterial = pttoMaterial;
0178     if (fLogicWorld) {
0179       fLogicWorld->SetMaterial(fpWaterMaterial);
0180     }
0181     G4RunManager::GetRunManager()->GeometryHasBeenModified();
0182   }
0183 }