Back to home page

EIC code displayed by LXR

 
 

    


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