Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:54

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. 45 (2018) e722-e739
0030 // Phys. Med. 31 (2015) 861-874
0031 // Med. Phys. 37 (2010) 4692-4708
0032 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0033 //
0034 // The Geant4-DNA web site is available at http://geant4-dna.org
0035 //
0036 /// \file DetectorConstruction.cc
0037 /// \brief Implementation of the DetectorConstruction class
0038 
0039 #include "DetectorConstruction.hh"
0040 
0041 #include "DetectorMessenger.hh"
0042 #include "PhysicsList.hh"
0043 
0044 #include "G4LogicalVolumeStore.hh"
0045 #include "G4NistManager.hh"
0046 #include "G4RunManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4UserLimits.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 DetectorConstruction::DetectorConstruction(PhysicsList* ptr)
0053   : G4VUserDetectorConstruction(),
0054     fpWaterMaterial(nullptr),
0055     fLogicWorld(nullptr),
0056     fPhysiWorld(nullptr)
0057 {
0058   // Create commands for interactive definition of the detector
0059   fDetectorMessenger = new DetectorMessenger(this, ptr);
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0063 
0064 DetectorConstruction::~DetectorConstruction()
0065 {
0066   delete fDetectorMessenger;
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0070 
0071 void DetectorConstruction::DefineMaterials()
0072 {
0073   // Water is defined from NIST material database
0074   G4NistManager* man = G4NistManager::Instance();
0075 
0076   G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
0077 
0078   /*
0079    If one wishes to test other density value for water material,
0080    one should use instead:
0081    G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED",
0082    "G4_WATER",1.100*g/cm3);
0083 
0084    Note: any string for "G4_WATER_MODIFIED" parameter is accepted
0085    and "G4_WATER" parameter should not be changed
0086    Both materials are created and can be selected from dna.mac
0087    */
0088   fpWaterMaterial = H2O;
0089 
0090   // G4cout << "-> Density of water material (g/cm3)="
0091   //  << fpWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl;
0092 
0093   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0094 }
0095 
0096 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0097 
0098 G4VPhysicalVolume* DetectorConstruction::Construct()
0099 {
0100   if (fPhysiWorld) {
0101     return fPhysiWorld;
0102   }
0103   DefineMaterials();
0104 
0105   // World volume
0106   G4double worldSizeX = 100 * micrometer;
0107   G4double worldSizeY = worldSizeX;
0108   G4double worldSizeZ = worldSizeX;
0109 
0110   G4Box* solidWorld = new G4Box("World",  // its name
0111                                 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2);  // its size
0112 
0113   fLogicWorld = new G4LogicalVolume(solidWorld,  // its solid
0114                                     fpWaterMaterial,  // its material
0115                                     "World");  // its name
0116 
0117   fPhysiWorld = new G4PVPlacement(0,  // no rotation
0118                                   G4ThreeVector(),  // at (0,0,0)
0119                                   "World",  // its name
0120                                   fLogicWorld,  // its logical volume
0121                                   0,  // its mother volume
0122                                   false,  // no boolean operation
0123                                   0);  // copy number
0124 
0125   // Visualization attributes - white
0126   G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0127   worldVisAtt->SetVisibility(true);
0128   fLogicWorld->SetVisAttributes(worldVisAtt);
0129 
0130   G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
0131   worldVisAtt1->SetVisibility(true);
0132 
0133   // Shows how to introduce a 20 eV tracking cut
0134   // logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV));
0135 
0136   return fPhysiWorld;
0137 }
0138 
0139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0140 
0141 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0142 {
0143   // Search the material by its name
0144   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0145 
0146   if (pttoMaterial) {
0147     fpWaterMaterial = pttoMaterial;
0148     if (fLogicWorld) {
0149       fLogicWorld->SetMaterial(fpWaterMaterial);
0150     }
0151     G4RunManager::GetRunManager()->GeometryHasBeenModified();
0152   }
0153 }