Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:08

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 #include "DetectorConstruction.hh"
0030 
0031 #include "DetectorMessenger.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4Colour.hh"
0035 #include "G4GeometryManager.hh"
0036 #include "G4LogicalVolume.hh"
0037 #include "G4LogicalVolumeStore.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4PhysicalVolumeStore.hh"
0042 #include "G4Region.hh"
0043 #include "G4RegionStore.hh"
0044 #include "G4RunManager.hh"
0045 #include "G4SolidStore.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4Tubs.hh"
0048 #include "G4VisAttributes.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 DetectorConstruction::DetectorConstruction()
0053   : G4VUserDetectorConstruction(), fDiameter(6 * nm), fLength(10 * nm)
0054 {
0055   fDetectorMessenger = new DetectorMessenger(this);
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 DetectorConstruction::~DetectorConstruction()
0061 {
0062   delete fDetectorMessenger;
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 G4VPhysicalVolume* DetectorConstruction::Construct()
0067 {
0068   return ConstructVolumes();
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0074 {
0075   // Cleanup old geometry
0076   //
0077   G4GeometryManager::GetInstance()->OpenGeometry();
0078   G4PhysicalVolumeStore::GetInstance()->Clean();
0079   G4LogicalVolumeStore::GetInstance()->Clean();
0080   G4SolidStore::GetInstance()->Clean();
0081 
0082   //
0083   G4Material* water = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
0084 
0085   // Geometry parameters
0086   G4double worldSize = 150 * nanometer;
0087 
0088   G4VSolid* world = new G4Box("world",  // its name
0089                               worldSize / 2, worldSize / 2, worldSize / 2);  // its size
0090 
0091   G4LogicalVolume* worldLog = new G4LogicalVolume(world,  // its solid
0092                                                   water,  // its material
0093                                                   "world");  // its name
0094 
0095   G4VisAttributes* vis = new G4VisAttributes(G4Colour(G4Colour::Blue()));
0096   worldLog->SetVisAttributes(vis);
0097 
0098   G4VPhysicalVolume* worldPhys = new G4PVPlacement(0,  // no rotation
0099                                                    G4ThreeVector(),  // at (0,0,0)
0100                                                    worldLog,  // its logical volume
0101                                                    "world",  // its name
0102                                                    0,  // its mother  volume
0103                                                    false,  // no boolean operation
0104                                                    0,  // copy number
0105                                                    true);  // checking overlaps forced to YES
0106 
0107   G4VSolid* target = new G4Tubs("target", 0, fDiameter / 2, fLength / 2, 0, 360 * deg);  // its size
0108 
0109   G4LogicalVolume* targetLog = new G4LogicalVolume(target, water, "target");
0110 
0111   new G4PVPlacement(0,  // no rotation
0112                     G4ThreeVector(),  // at (0,0,0)
0113                     targetLog,  // its logical volume
0114                     "target",  // its name
0115                     worldLog,  // its mother volume
0116                     false,  // no boolean operation
0117                     0,  // copy number
0118                     true);  // checking overlaps force to YES
0119 
0120   // A region is needed as splitting is performed in regions
0121   G4Region* aRegion = G4RegionStore::GetInstance()->FindOrCreateRegion("Target");
0122   targetLog->SetRegion(aRegion);
0123   aRegion->AddRootLogicalVolume(targetLog);
0124 
0125   G4VisAttributes* visTarget = new G4VisAttributes(G4Colour(G4Colour::Blue()));
0126   visTarget->SetForceSolid(true);
0127   visTarget->SetVisibility(true);
0128   targetLog->SetVisAttributes(visTarget);
0129 
0130   return worldPhys;
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0134 
0135 void DetectorConstruction::SetDiameter(G4double diameter)
0136 {
0137   fDiameter = diameter;
0138   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0142 
0143 void DetectorConstruction::SetLength(G4double length)
0144 {
0145   fLength = length;
0146   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0147 }
0148 
0149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0150 
0151 #include "G4RunManager.hh"
0152 
0153 void DetectorConstruction::UpdateGeometry()
0154 {
0155   G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
0156 }
0157 
0158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......