Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:04

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 /////////////////////////////////////////////////////////////////////////
0030 //
0031 // DetectorConstruction
0032 //
0033 // Created: 20.06.2008 V.Ivanchenko
0034 //
0035 // Modified:
0036 //
0037 ////////////////////////////////////////////////////////////////////////
0038 //
0039 
0040 #include "DetectorConstruction.hh"
0041 
0042 #include "DetectorMessenger.hh"
0043 
0044 #include "G4Colour.hh"
0045 #include "G4GeometryManager.hh"
0046 #include "G4LogicalVolume.hh"
0047 #include "G4LogicalVolumeStore.hh"
0048 #include "G4NistManager.hh"
0049 #include "G4PVPlacement.hh"
0050 #include "G4PhysicalConstants.hh"
0051 #include "G4PhysicalVolumeStore.hh"
0052 #include "G4RunManager.hh"
0053 #include "G4SolidStore.hh"
0054 #include "G4SystemOfUnits.hh"
0055 #include "G4Tubs.hh"
0056 #include "G4UnitsTable.hh"
0057 #include "G4VisAttributes.hh"
0058 #include "G4ios.hh"
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 DetectorConstruction::DetectorConstruction()
0063   : G4VUserDetectorConstruction(),
0064     fTargetMaterial(nullptr),
0065     fWorldMaterial(nullptr),
0066     fSolidW(nullptr),
0067     fSolidA(nullptr),
0068     fLogicTarget(nullptr),
0069     fLogicWorld(nullptr),
0070     fPhysWorld(nullptr),
0071     fPhysList(nullptr)
0072 {
0073   fDetectorMessenger = new DetectorMessenger(this);
0074 
0075   fRadius = 5. * cm;
0076   fLength = 10. * cm;
0077 
0078   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
0079   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0080 
0081   ComputeGeomParameters();
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 DetectorConstruction::~DetectorConstruction()
0087 {
0088   delete fDetectorMessenger;
0089 }
0090 
0091 void DetectorConstruction::ComputeGeomParameters()
0092 {
0093   // Sizes
0094   fWorldR = fRadius + CLHEP::cm;
0095   fWorldZ = fLength + CLHEP::cm;
0096   if (fPhysWorld) {
0097     fSolidW->SetOuterRadius(fWorldR);
0098     fSolidW->SetZHalfLength(fWorldZ * 0.5);
0099     fSolidA->SetOuterRadius(fRadius);
0100     fSolidA->SetZHalfLength(fLength * 0.5);
0101   }
0102 }
0103 
0104 G4VPhysicalVolume* DetectorConstruction::Construct()
0105 {
0106   if (fPhysWorld) {
0107     return fPhysWorld;
0108   }
0109   ComputeGeomParameters();
0110 
0111   //
0112   // World
0113   //
0114   fSolidW = new G4Tubs("World", 0., fWorldR, 0.5 * fWorldZ, 0., twopi);
0115   fLogicWorld = new G4LogicalVolume(fSolidW, fWorldMaterial, "World");
0116   fPhysWorld =
0117     new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", nullptr, false, 0);
0118 
0119   //
0120   // Target volume
0121   //
0122   fSolidA = new G4Tubs("Target", 0., fRadius, 0.5 * fLength, 0., twopi);
0123   fLogicTarget = new G4LogicalVolume(fSolidA, fTargetMaterial, "Target");
0124   new G4PVPlacement(nullptr, G4ThreeVector(), fLogicTarget, "Target", fLogicWorld, false, 0);
0125 
0126   G4cout << "### Target consist of " << fTargetMaterial->GetName()
0127          << " disks with R(mm)= " << fRadius / mm << "  fLength(mm)= " << fLength / mm << "  ###"
0128          << G4endl;
0129 
0130   // colors
0131   fLogicWorld->SetVisAttributes(G4VisAttributes::GetInvisible());
0132 
0133   G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
0134   fLogicTarget->SetVisAttributes(regCcolor);
0135 
0136   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0137 
0138   return fPhysWorld;
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0142 
0143 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0144 {
0145   // search the material by its name
0146   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0147 
0148   if (material && material != fTargetMaterial) {
0149     fTargetMaterial = material;
0150     if (fLogicTarget) {
0151       fLogicTarget->SetMaterial(fTargetMaterial);
0152     }
0153     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0154   }
0155 }
0156 
0157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0158 
0159 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0160 {
0161   // search the material by its name
0162   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0163 
0164   if (material && material != fWorldMaterial) {
0165     fWorldMaterial = material;
0166     if (fLogicWorld) {
0167       fLogicWorld->SetMaterial(fWorldMaterial);
0168     }
0169     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0170   }
0171 }
0172 
0173 void DetectorConstruction::SetTargetRadius(G4double val)
0174 {
0175   if (val > 0.0 && val != fRadius) {
0176     fRadius = val;
0177     ComputeGeomParameters();
0178   }
0179 }
0180 
0181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0182 
0183 void DetectorConstruction::SetTargetLength(G4double val)
0184 {
0185   if (val > 0.0 && val != fLength) {
0186     fLength = val;
0187     ComputeGeomParameters();
0188   }
0189 }
0190 
0191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......