Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:28:02

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 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software
0028 // shall cite the following Geant4-DNA collaboration publications:
0029 // Med. Phys. 51 (2024) 5873-5889
0030 // Med. Phys. 45 (2018) e722-e739
0031 // Phys. Med. 31 (2015) 861-874
0032 // Med. Phys. 37 (2010) 4692-4708
0033 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0034 //
0035 // The Geant4-DNA web site is available at http://geant4-dna.org
0036 //
0037 /// \file DetectorConstruction.cc
0038 /// \brief Implementation of the DetectorConstruction class
0039 
0040 #include "DetectorConstruction.hh"
0041 #include "DetectorMessenger.hh"
0042 
0043 #include "G4RunManager.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4VisAttributes.hh"
0046 #include "G4Tubs.hh"
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0049 
0050 DetectorConstruction::DetectorConstruction(PhysicsList* pl)
0051 {
0052   // Create commands for interactive definition of the detector
0053   fDetectorMessenger = new DetectorMessenger(this, pl);
0054 
0055   // World size
0056   fWorldRadius = 1*um;
0057   fWorldLength = 10*um;
0058 
0059   // Cylinders
0060   fThicknessCylinders = 1*nm;
0061   fMinRadiusCylinders = 0;
0062 
0063   fNumberCylinders = (fWorldRadius-fMinRadiusCylinders) / fThicknessCylinders;
0064 
0065   // Materials
0066   G4NistManager* man = G4NistManager::Instance();
0067   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0068   G4Material* galactic = man->FindOrBuildMaterial("G4_Galactic");
0069 
0070   fWaterMaterial = H2O;
0071   fVacuumMaterial = galactic;
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0075 
0076 DetectorConstruction::~DetectorConstruction()
0077 {
0078   delete fDetectorMessenger;
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0082 
0083 void DetectorConstruction::DefineMaterials()
0084 {
0085   // Water is defined from NIST material database
0086   G4NistManager* man = G4NistManager::Instance();
0087 
0088   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0089   G4Material* galactic = man->FindOrBuildMaterial("G4_Galactic");
0090 
0091   fWaterMaterial = H2O;
0092   fVacuumMaterial = galactic;
0093 
0094   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0098 
0099 G4VPhysicalVolume* DetectorConstruction::Construct()
0100 {
0101   if (fPhysiWorld) return fPhysiWorld;
0102 
0103   // World volume
0104 
0105   G4Tubs* solidWorld =
0106     new G4Tubs("World", 0., fWorldRadius, fWorldLength / 2, 0., 360*deg);
0107 
0108   fLogicWorld = new G4LogicalVolume(solidWorld,  // its solid
0109                                     fVacuumMaterial,  // its material
0110                                     "World");  // its name
0111 
0112   fPhysiWorld = new G4PVPlacement(0,  // no rotation
0113                                   G4ThreeVector(),  // at (0,0,0)
0114                                   "World",  // its name
0115                                   fLogicWorld,  // its logical volume
0116                                   0,  // its mother volume
0117                                   false,  // no boolean operation
0118                                   0);  // copy number
0119 
0120   // Visualization attributes - white
0121   G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0122   worldVisAtt->SetVisibility(true);
0123   fLogicWorld->SetVisAttributes(worldVisAtt);
0124 
0125   // Cylinders
0126 
0127   fNumberCylinders = (fWorldRadius-fMinRadiusCylinders) / fThicknessCylinders;
0128 
0129   // Check values
0130   /*
0131   G4cout << fMinRadiusCylinders/nm << G4endl;
0132   G4cout << fWorldRadius/nm << G4endl;
0133   G4cout << fThicknessCylinders/nm << G4endl;
0134   G4cout << fWorldLength/nm << G4endl;
0135   */
0136 
0137   G4cout << G4endl;
0138   G4cout
0139     << "*******************************************************************"
0140     << G4endl;
0141   G4cout << "*** NUMBER OF HOLLOW CYLINDERS = "<< fNumberCylinders << G4endl;
0142   G4cout
0143     << "*******************************************************************"
0144     << G4endl;
0145   G4cout << G4endl;
0146 
0147   for (G4int i = 0; i < fNumberCylinders; i++) {
0148 
0149     G4double rIn = i*fThicknessCylinders;
0150     G4double rOut = (i+1) * fThicknessCylinders;
0151 
0152     G4Tubs* solidCylinder =
0153       new G4Tubs("Cylinder", rIn, rOut, fWorldLength / 2, 0., 360*deg);
0154 
0155     G4LogicalVolume* logicCylinder =
0156       new G4LogicalVolume(solidCylinder, fWaterMaterial, "Cylinder");
0157 
0158     new G4PVPlacement(nullptr, G4ThreeVector(0, 0, 0), logicCylinder,
0159       "Cylinder", fLogicWorld, false, i, true);
0160 
0161     logicCylinder->SetVisAttributes(worldVisAtt);
0162   }
0163 
0164   // Shows how to introduce a 20 eV tracking cut
0165   // logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV));
0166 
0167   return fPhysiWorld;
0168 }
0169 
0170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0171 
0172 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0173 {
0174   G4Material* pttoMaterial =
0175     G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0176 
0177   if (pttoMaterial) {
0178     fWaterMaterial = pttoMaterial;
0179     if (fLogicWorld) fLogicWorld->SetMaterial(fWaterMaterial);
0180   }
0181 }
0182 
0183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0184 
0185 void DetectorConstruction::SetWorldRadius(const G4double& value)
0186 {
0187   fWorldRadius = value;
0188 }
0189 
0190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0191 
0192 void DetectorConstruction::SetWorldLength(const G4double& value)
0193 {
0194   fWorldLength = value;
0195 }
0196 
0197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0198 
0199 void DetectorConstruction::SetThicknessCylinders(const G4double& value)
0200 {
0201   fThicknessCylinders = value;
0202 }
0203 
0204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0205 
0206 void DetectorConstruction::SetMinRadiusCylinders(const G4double& value)
0207 {
0208   fMinRadiusCylinders = value;
0209 }