Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:59

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 DetectorConstruction0.cc
0027 /// \brief Implementation of the Common::DetectorConstruction0 class
0028 
0029 #include "DetectorConstruction0.hh"
0030 
0031 #include "G4Box.hh"
0032 #include "G4GenericMessenger.hh"
0033 #include "G4LogicalVolume.hh"
0034 #include "G4Material.hh"
0035 #include "G4NistManager.hh"
0036 #include "G4PVPlacement.hh"
0037 
0038 namespace Common
0039 {
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 DetectorConstruction0::DetectorConstruction0(const G4String& materialName, G4double hx, G4double hy,
0044                                              G4double hz)
0045   : fMaterialName(materialName), fDimensions(hx, hy, hz)
0046 {
0047   DefineCommands();
0048 }
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 DetectorConstruction0::~DetectorConstruction0()
0053 {
0054   delete fMessenger;
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 G4VPhysicalVolume* DetectorConstruction0::Construct()
0060 {
0061   // Define materials via NIST manager
0062   //
0063   auto nistManager = G4NistManager::Instance();
0064 
0065   auto material = nistManager->FindOrBuildMaterial(fMaterialName);
0066 
0067   // World
0068   //
0069   auto sWorld = new G4Box("World",  // name
0070                           fDimensions.x(),  // dimensions (half-lentghs)
0071                           fDimensions.y(), fDimensions.z());
0072 
0073   fWorldVolume = new G4LogicalVolume(sWorld,  // shape
0074                                      material,  // material
0075                                      "World");  // name
0076 
0077   auto pWorld = new G4PVPlacement(0,  // no rotation
0078                                   G4ThreeVector(),  // at (0,0,0)
0079                                   fWorldVolume,  // logical volume
0080                                   "World",  // name
0081                                   0,  // mother  volume
0082                                   false,  // no boolean operation
0083                                   0);  // copy number
0084 
0085   // always return the root volume
0086   //
0087   return pWorld;
0088 }
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0091 
0092 void DetectorConstruction0::SetMaterial(const G4String& materialName)
0093 {
0094   auto nistManager = G4NistManager::Instance();
0095 
0096   auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
0097   if (!newMaterial) {
0098     G4cerr << "Material " << materialName << " not found." << G4endl;
0099     G4cerr << "The box material was not changed." << G4endl;
0100     return;
0101   }
0102 
0103   if (fWorldVolume) fWorldVolume->SetMaterial(newMaterial);
0104   G4cout << "Material of box changed to " << materialName << G4endl;
0105 }
0106 
0107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0108 
0109 void DetectorConstruction0::SetDimensions(G4ThreeVector dimensions)
0110 {
0111   /// Set world dimension (in half lengths).
0112   /// This setting has effect only if called in PreInit> phase
0113 
0114   fDimensions = dimensions;
0115 }
0116 
0117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0118 
0119 void DetectorConstruction0::DefineCommands()
0120 {
0121   // Define /B5/detector command directory using generic messenger class
0122   fMessenger = new G4GenericMessenger(this, "/detector/", "Detector control");
0123 
0124   // setMaterial command
0125   auto& setMaterialCmd = fMessenger->DeclareMethod(
0126     "setMaterial", &DetectorConstruction0::SetMaterial, "Set world material name.");
0127   setMaterialCmd.SetParameterName("materialName", false);
0128   setMaterialCmd.SetDefaultValue("G4_AIR");
0129   setMaterialCmd.SetStates(G4State_PreInit);
0130 
0131   // setDimensions command
0132   auto& setDimensionsCmd =
0133     fMessenger->DeclareMethodWithUnit("setDimensions", "mm", &DetectorConstruction0::SetDimensions,
0134                                       "Set world dimensions (in half lentgh).");
0135   setDimensionsCmd.SetParameterName("dimensions", false);
0136   setDimensionsCmd.SetStates(G4State_PreInit);
0137 }
0138 
0139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0140 
0141 }  // namespace Common