Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:53:19

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 "G4GeometryManager.hh"
0034 #include "G4LogicalVolume.hh"
0035 #include "G4LogicalVolumeStore.hh"
0036 #include "G4Material.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4PhysicalConstants.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Tubs.hh"
0045 #include "G4UnitsTable.hh"
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 DetectorConstruction::DetectorConstruction()
0050 {
0051   fTargetLength = 1 * cm;
0052   fTargetRadius = 0.5 * cm;
0053   fDetectorLength = 5 * cm;
0054   fDetectorThickness = 2 * cm;
0055 
0056   fWorldLength = std::max(fTargetLength, fDetectorLength);
0057   fWorldRadius = fTargetRadius + fDetectorThickness;
0058 
0059   DefineMaterials();
0060 
0061   fDetectorMessenger = new DetectorMessenger(this);
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 DetectorConstruction::~DetectorConstruction()
0067 {
0068   delete fDetectorMessenger;
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 G4VPhysicalVolume* DetectorConstruction::Construct()
0074 {
0075   return ConstructVolumes();
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 void DetectorConstruction::DefineMaterials()
0081 {
0082   // build materials
0083   //
0084   fDetectorMater = new G4Material("Germanium", 32, 72.61 * g / mole, 5.323 * g / cm3);
0085 
0086   G4Element* N = new G4Element("Nitrogen", "N", 7, 14.01 * g / mole);
0087   G4Element* O = new G4Element("Oxygen", "O", 8, 16.00 * g / mole);
0088   //
0089   G4int ncomponents;
0090   G4double fractionmass;
0091   G4Material* Air20 = new G4Material("Air", 1.205 * mg / cm3, ncomponents = 2, kStateGas,
0092                                      293. * kelvin, 1. * atmosphere);
0093   Air20->AddElement(N, fractionmass = 0.7);
0094   Air20->AddElement(O, fractionmass = 0.3);
0095   //
0096   fWorldMater = Air20;
0097 
0098   // or use G4 materials data base
0099   //
0100   G4NistManager* man = G4NistManager::Instance();
0101   fTargetMater = man->FindOrBuildMaterial("G4_CESIUM_IODIDE");
0102 
0103   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0109 {
0110   // Cleanup old geometry
0111   G4GeometryManager::GetInstance()->OpenGeometry();
0112   G4PhysicalVolumeStore::GetInstance()->Clean();
0113   G4LogicalVolumeStore::GetInstance()->Clean();
0114   G4SolidStore::GetInstance()->Clean();
0115 
0116   // World
0117   //
0118   // (re) compute World dimensions if necessary
0119   fWorldLength = std::max(fTargetLength, fDetectorLength);
0120   fWorldRadius = fTargetRadius + fDetectorThickness;
0121 
0122   G4Tubs* sWorld = new G4Tubs("World",  // name
0123                               0., fWorldRadius, 0.5 * fWorldLength, 0., twopi);  // dimensions
0124 
0125   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,  // shape
0126                                                 fWorldMater,  // material
0127                                                 "World");  // name
0128 
0129   fPhysiWorld = new G4PVPlacement(0,  // no rotation
0130                                   G4ThreeVector(),  // at (0,0,0)
0131                                   lWorld,  // logical volume
0132                                   "World",  // name
0133                                   0,  // mother volume
0134                                   false,  // no boolean operation
0135                                   0);  // copy number
0136 
0137   // Target
0138   //
0139   G4Tubs* sTarget = new G4Tubs("Target",  // name
0140                                0., fTargetRadius, 0.5 * fTargetLength, 0., twopi);  // dimensions
0141 
0142   fLogicTarget = new G4LogicalVolume(sTarget,  // shape
0143                                      fTargetMater,  // material
0144                                      "Target");  // name
0145 
0146   new G4PVPlacement(0,  // no rotation
0147                     G4ThreeVector(),  // at (0,0,0)
0148                     fLogicTarget,  // logical volume
0149                     "Target",  // name
0150                     lWorld,  // mother  volume
0151                     false,  // no boolean operation
0152                     0);  // copy number
0153 
0154   // Detector
0155   //
0156   G4Tubs* sDetector =
0157     new G4Tubs("Detector", fTargetRadius, fWorldRadius, 0.5 * fDetectorLength, 0., twopi);
0158 
0159   fLogicDetector = new G4LogicalVolume(sDetector,  // shape
0160                                        fDetectorMater,  // material
0161                                        "Detector");  // name
0162 
0163   new G4PVPlacement(0,  // no rotation
0164                     G4ThreeVector(),  // at (0,0,0)
0165                     fLogicDetector,  // logical volume
0166                     "Detector",  // name
0167                     lWorld,  // mother  volume
0168                     false,  // no boolean operation
0169                     0);  // copy number
0170 
0171   PrintParameters();
0172 
0173   // always return the root volume
0174   //
0175   return fPhysiWorld;
0176 }
0177 
0178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0179 
0180 void DetectorConstruction::PrintParameters()
0181 {
0182   G4cout << "\n Target : Length = " << G4BestUnit(fTargetLength, "Length")
0183          << " Radius = " << G4BestUnit(fTargetRadius, "Length")
0184          << " Material = " << fTargetMater->GetName();
0185   G4cout << "\n Detector : Length = " << G4BestUnit(fDetectorLength, "Length")
0186          << " Tickness = " << G4BestUnit(fDetectorThickness, "Length")
0187          << " Material = " << fDetectorMater->GetName() << G4endl;
0188   G4cout << "\n" << fTargetMater << "\n" << fDetectorMater << G4endl;
0189 }
0190 
0191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0192 
0193 void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
0194 {
0195   // search the material by its name
0196   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0197 
0198   if (pttoMaterial) {
0199     fTargetMater = pttoMaterial;
0200     if (fLogicTarget) {
0201       fLogicTarget->SetMaterial(fTargetMater);
0202     }
0203     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0204   }
0205   else {
0206     G4cout << "\n--> warning from DetectorConstruction::SetTargetMaterial : " << materialChoice
0207            << " not found" << G4endl;
0208   }
0209 }
0210 
0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0212 
0213 void DetectorConstruction::SetDetectorMaterial(G4String materialChoice)
0214 {
0215   // search the material by its name
0216   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0217 
0218   if (pttoMaterial) {
0219     fDetectorMater = pttoMaterial;
0220     if (fLogicDetector) {
0221       fLogicDetector->SetMaterial(fDetectorMater);
0222     }
0223     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0224   }
0225   else {
0226     G4cout << "\n--> warning from DetectorConstruction::SetDetectorMaterial : " << materialChoice
0227            << " not found" << G4endl;
0228   }
0229 }
0230 
0231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0232 
0233 void DetectorConstruction::SetTargetRadius(G4double value)
0234 {
0235   fTargetRadius = value;
0236   G4RunManager::GetRunManager()->ReinitializeGeometry();
0237 }
0238 
0239 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0240 
0241 void DetectorConstruction::SetTargetLength(G4double value)
0242 {
0243   fTargetLength = value;
0244   G4RunManager::GetRunManager()->ReinitializeGeometry();
0245 }
0246 
0247 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0248 
0249 void DetectorConstruction::SetDetectorThickness(G4double value)
0250 {
0251   fDetectorThickness = value;
0252   G4RunManager::GetRunManager()->ReinitializeGeometry();
0253 }
0254 
0255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0256 
0257 void DetectorConstruction::SetDetectorLength(G4double value)
0258 {
0259   fDetectorLength = value;
0260   G4RunManager::GetRunManager()->ReinitializeGeometry();
0261 }
0262 
0263 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0264 
0265 G4double DetectorConstruction::GetTargetLength()
0266 {
0267   return fTargetLength;
0268 }
0269 
0270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0271 
0272 G4double DetectorConstruction::GetTargetRadius()
0273 {
0274   return fTargetRadius;
0275 }
0276 
0277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0278 
0279 G4Material* DetectorConstruction::GetTargetMaterial()
0280 {
0281   return fTargetMater;
0282 }
0283 
0284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0285 
0286 G4LogicalVolume* DetectorConstruction::GetLogicTarget()
0287 {
0288   return fLogicTarget;
0289 }
0290 
0291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0292 
0293 G4double DetectorConstruction::GetDetectorLength()
0294 {
0295   return fDetectorLength;
0296 }
0297 
0298 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0299 
0300 G4double DetectorConstruction::GetDetectorThickness()
0301 {
0302   return fDetectorThickness;
0303 }
0304 
0305 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0306 
0307 G4Material* DetectorConstruction::GetDetectorMaterial()
0308 {
0309   return fDetectorMater;
0310 }
0311 
0312 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0313 
0314 G4LogicalVolume* DetectorConstruction::GetLogicDetector()
0315 {
0316   return fLogicDetector;
0317 }
0318 
0319 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......