Back to home page

EIC code displayed by LXR

 
 

    


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

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