Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:52:47

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 "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4PolarizationManager.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SolidStore.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4UnitsTable.hh"
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 DetectorConstruction::DetectorConstruction()
0050   : G4VUserDetectorConstruction(), fWorld(0), fBox(0), fTargetMaterial(0), fWorldMaterial(0)
0051 {
0052   fBoxSizeXY = 50 * mm;
0053   fBoxSizeZ = 5 * mm;
0054   fWorldSize = 1. * m;
0055   ConstructMaterials();
0056   fMessenger = new DetectorMessenger(this);
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 DetectorConstruction::~DetectorConstruction()
0062 {
0063   delete fMessenger;
0064 }
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void DetectorConstruction::ConstructMaterials()
0068 {
0069   auto nistManager = G4NistManager::Instance();
0070 
0071   fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Fe");
0072   if (fTargetMaterial == nullptr) {
0073     G4cerr << "### ERROR - Material: <"
0074            << "G4_Fe"
0075            << "> not found" << G4endl;
0076   }
0077 
0078   fWorldMaterial = nistManager->FindOrBuildMaterial("G4_Galactic");
0079   if (fWorldMaterial == nullptr) {
0080     G4cerr << "### ERROR -  Material: <"
0081            << "G4_Galactic"
0082            << "> not found" << G4endl;
0083   }
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 G4LogicalVolume* lBox;
0089 
0090 G4VPhysicalVolume* DetectorConstruction::Construct()
0091 {
0092   // G4PolarizationManager::GetInstance()->Clean();
0093 
0094   // World
0095   //
0096   G4Box* sWorld = new G4Box("World",  // name
0097                             fWorldSize / 2, fWorldSize / 2, fWorldSize / 2);  // dimensions
0098 
0099   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,  // shape
0100                                                 fWorldMaterial,  // material
0101                                                 "World");  // name
0102 
0103   fWorld = new G4PVPlacement(0,  // no rotation
0104                              G4ThreeVector(),  // at (0,0,0)
0105                              lWorld,  // logical volume
0106                              "World",  // name
0107                              0,  // mother volume
0108                              false,  // no boolean operation
0109                              0);  // copy number
0110 
0111   // Box
0112   //
0113   G4Box* sBox = new G4Box("Container",  // its name
0114                           fBoxSizeXY / 2., fBoxSizeXY / 2., fBoxSizeZ / 2.);  // its dimensions
0115 
0116   // G4LogicalVolume*
0117   lBox = new G4LogicalVolume(sBox,  // its shape
0118                              fTargetMaterial,  // its material
0119                              "theBox");  // its name
0120 
0121   fBox = new G4PVPlacement(0,  // no rotation
0122                            G4ThreeVector(),  // at (0,0,0)
0123                            lBox,  // its logical volume
0124                            fTargetMaterial->GetName(),  // its name
0125                            lWorld,  // its mother  volume
0126                            false,  // no boolean operation
0127                            0);  // copy number
0128 
0129   PrintParameters();
0130 
0131   // always return the root volume
0132   //
0133   return fWorld;
0134 }
0135 
0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0137 
0138 void DetectorConstruction::ConstructSDandField()
0139 {
0140   // register logical Volume in PolarizationManager with zero polarization
0141   G4PolarizationManager* polMgr = G4PolarizationManager::GetInstance();
0142   polMgr->SetVolumePolarization(lBox, G4ThreeVector(0., 0., 0.));
0143 }
0144 
0145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0146 
0147 void DetectorConstruction::PrintParameters()
0148 {
0149   G4cout << "\n The Box is " << G4BestUnit(fBoxSizeXY, "Length") << " x "
0150          << G4BestUnit(fBoxSizeXY, "Length") << " x " << G4BestUnit(fBoxSizeZ, "Length") << " of "
0151          << fTargetMaterial->GetName() << G4endl;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0155 
0156 void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
0157 {
0158   // search the material by its name
0159   G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0160   if (mat != fTargetMaterial) {
0161     if (mat) {
0162       fTargetMaterial = mat;
0163       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0164       UpdateGeometry();
0165     }
0166     else {
0167       G4cout << "### Warning!  Target material: <" << materialChoice << "> not found" << G4endl;
0168     }
0169   }
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 
0174 void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
0175 {
0176   // search the material by its name
0177   G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0178   if (mat != fWorldMaterial) {
0179     if (mat) {
0180       fWorldMaterial = mat;
0181       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0182       UpdateGeometry();
0183     }
0184     else {
0185       G4cout << "### Warning! World material: <" << materialChoice << "> not found" << G4endl;
0186     }
0187   }
0188 }
0189 
0190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0191 
0192 void DetectorConstruction::SetSizeXY(G4double value)
0193 {
0194   fBoxSizeXY = value;
0195   if (fWorldSize < fBoxSizeXY) fWorldSize = 1.2 * fBoxSizeXY;
0196   UpdateGeometry();
0197 }
0198 
0199 void DetectorConstruction::SetSizeZ(G4double value)
0200 {
0201   fBoxSizeZ = value;
0202   if (fWorldSize < fBoxSizeZ) fWorldSize = 1.2 * fBoxSizeZ;
0203   UpdateGeometry();
0204 }
0205 
0206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0207 
0208 #include "G4RunManager.hh"
0209 
0210 void DetectorConstruction::UpdateGeometry()
0211 {
0212   // if (fWorld)
0213   //   G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
0214   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0215 }
0216 
0217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......