Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:30:16

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 electromagnetic/TestEm12/src/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 "G4NistManager.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PVReplica.hh"
0043 #include "G4PhysicalConstants.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4RunManager.hh"
0046 #include "G4SolidStore.hh"
0047 #include "G4Sphere.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4UnitsTable.hh"
0050 #include "G4VPhysicalVolume.hh"
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 DetectorConstruction::DetectorConstruction()
0055 {
0056   // default parameter values
0057   fAbsorRadius = 3 * cm;
0058   fNbOfLayers = 1;
0059 
0060   DefineMaterials();
0061   SetMaterial("G4_WATER");
0062 
0063   // create commands for interactive definition of the detector
0064   fDetectorMessenger = new DetectorMessenger(this);
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 DetectorConstruction::~DetectorConstruction()
0070 {
0071   delete fDetectorMessenger;
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 void DetectorConstruction::DefineMaterials()
0077 {
0078   G4NistManager* man = G4NistManager::Instance();
0079 
0080   man->FindOrBuildMaterial("G4_Al");
0081   man->FindOrBuildMaterial("G4_Si");
0082   man->FindOrBuildMaterial("G4_Fe");
0083   man->FindOrBuildMaterial("G4_Ge");
0084   man->FindOrBuildMaterial("G4_Gd");
0085   man->FindOrBuildMaterial("G4_W");
0086   man->FindOrBuildMaterial("G4_Pb");
0087 
0088   man->FindOrBuildMaterial("G4_AIR");
0089   man->FindOrBuildMaterial("G4_WATER");
0090   man->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0091 
0092   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 G4VPhysicalVolume* DetectorConstruction::Construct()
0098 {
0099   // Absorber
0100   //
0101   G4Sphere* sAbsor = new G4Sphere("Absorber",  // name
0102                                   0., fAbsorRadius, 0., twopi, 0., pi);  // size
0103 
0104   fSpheres.push_back(sAbsor);
0105 
0106   G4LogicalVolume* lAbsor = new G4LogicalVolume(sAbsor,  // solid
0107                                                 fAbsorMaterial,  // material
0108                                                 "Absorber");  // name
0109   fLVolumes.push_back(lAbsor);
0110 
0111   fAbsor = new G4PVPlacement(0,  // no rotation
0112                              G4ThreeVector(),  // at (0,0,0)
0113                              lAbsor,  // logical volume
0114                              "Absorber",  // name
0115                              0,  // mother  volume
0116                              false,  // no boolean operation
0117                              0);  // copy number
0118 
0119   // Layers
0120   //
0121   fLayerThickness = fAbsorRadius / fNbOfLayers;
0122 
0123   for (G4int i = 1; i <= fNbOfLayers; i++) {
0124     G4Sphere* sLayer =
0125       new G4Sphere("Layer", (i - 1) * fLayerThickness, i * fLayerThickness, 0., twopi, 0., pi);
0126 
0127     fSpheres.push_back(sLayer);
0128 
0129     G4LogicalVolume* lLayer = new G4LogicalVolume(sLayer,  // shape
0130                                                   fAbsorMaterial,  // material
0131                                                   "Layer");  // name
0132     fLVolumes.push_back(lLayer);
0133 
0134     new G4PVPlacement(0,  // no rotation
0135                       G4ThreeVector(),  // at (0,0,0)
0136                       lLayer,  // logical volume
0137                       "Layer",  // name
0138                       lAbsor,  // mother  volume
0139                       false,  // no boolean operation
0140                       i);  // copy number
0141   }
0142 
0143   PrintParameters();
0144 
0145   //
0146   // always return the root volume
0147   //
0148   return fAbsor;
0149 }
0150 
0151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0152 
0153 void DetectorConstruction::PrintParameters()
0154 {
0155   G4cout << "\n---------------------------------------------------------\n";
0156   G4cout << "---> The Absorber is a sphere of " << G4BestUnit(fAbsorRadius, "Length")
0157          << " radius of " << fAbsorMaterial->GetName() << " divided in " << fNbOfLayers
0158          << " slices of " << G4BestUnit(fLayerThickness, "Length") << "\n \n"
0159          << fAbsorMaterial << G4endl;
0160   G4cout << "\n---------------------------------------------------------\n";
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void DetectorConstruction::SetRadius(G4double value)
0166 {
0167   // geometry was already constructed - scale radii of all spheres
0168   if (fAbsor) {
0169     G4double scale = value / fAbsorRadius;
0170     for (auto solid : fSpheres) {
0171       if (scale > 1.0) {
0172         solid->SetOuterRadius(solid->GetOuterRadius() * scale);
0173         solid->SetInnerRadius(solid->GetInnerRadius() * scale);
0174       }
0175       else {
0176         solid->SetInnerRadius(solid->GetInnerRadius() * scale);
0177         solid->SetOuterRadius(solid->GetOuterRadius() * scale);
0178       }
0179     }
0180   }
0181   fAbsorRadius = value;
0182 }
0183 
0184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0185 
0186 void DetectorConstruction::SetMaterial(G4String materialChoice)
0187 {
0188   // search the material by its name
0189   G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
0190 
0191   if (pttoMaterial && pttoMaterial != fAbsorMaterial) {
0192     fAbsorMaterial = pttoMaterial;
0193     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0194 
0195     // geometry was already constructed - only change material
0196     if (fAbsor) {
0197       for (auto lv : fLVolumes) {
0198         lv->SetMaterial(fAbsorMaterial);
0199       }
0200     }
0201   }
0202 }
0203 
0204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0205 
0206 void DetectorConstruction::SetNbOfLayers(G4int value)
0207 {
0208   fNbOfLayers = value;
0209 }
0210 
0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......