Back to home page

EIC code displayed by LXR

 
 

    


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

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