Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 08:28:56

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 DetectorMessenger.cc
0027 /// \brief Implementation of the DetectorMessenger class
0028 
0029 #include "DetectorMessenger.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 
0033 #include "G4UIcmdWithADoubleAndUnit.hh"
0034 #include "G4UIcmdWithAString.hh"
0035 #include "G4UIcmdWithoutParameter.hh"
0036 #include "G4UIcommand.hh"
0037 #include "G4UIdirectory.hh"
0038 #include "G4UIparameter.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 DetectorMessenger::DetectorMessenger(DetectorConstruction* Det) : fDetector(Det)
0043 {
0044   fTesthadDir = new G4UIdirectory("/testhadr/");
0045   fTesthadDir->SetGuidance("commands specific to this example");
0046 
0047   fDetDir = new G4UIdirectory("/testhadr/det/");
0048   fDetDir->SetGuidance("detector construction commands");
0049 
0050   fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat", this);
0051   fMaterCmd->SetGuidance("Select material of the box.");
0052   fMaterCmd->SetParameterName("choice", false);
0053   fMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0054   fMaterCmd->SetToBeBroadcasted(false);
0055 
0056   fSizeCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSize", this);
0057   fSizeCmd->SetGuidance("Set size of the box");
0058   fSizeCmd->SetParameterName("Size", false);
0059   fSizeCmd->SetRange("Size>0.");
0060   fSizeCmd->SetUnitCategory("Length");
0061   fSizeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0062   fSizeCmd->SetToBeBroadcasted(false);
0063 
0064   fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0065   fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0066   fIsotopeCmd->SetGuidance("  symbol of isotope, Z, A, density of material");
0067   //
0068   G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0069   symbPrm->SetGuidance("isotope symbol");
0070   fIsotopeCmd->SetParameter(symbPrm);
0071   //
0072   G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0073   ZPrm->SetGuidance("Z");
0074   ZPrm->SetParameterRange("Z>0");
0075   fIsotopeCmd->SetParameter(ZPrm);
0076   //
0077   G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0078   APrm->SetGuidance("A");
0079   APrm->SetParameterRange("A>0");
0080   fIsotopeCmd->SetParameter(APrm);
0081   //
0082   G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0083   densityPrm->SetGuidance("density of material");
0084   densityPrm->SetParameterRange("density>0.");
0085   fIsotopeCmd->SetParameter(densityPrm);
0086   //
0087   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0088   unitPrm->SetGuidance("unit of density");
0089   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0090   unitPrm->SetParameterCandidates(unitList);
0091   fIsotopeCmd->SetParameter(unitPrm);
0092   //
0093   fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0094   fIsotopeCmd->SetToBeBroadcasted(false);
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 DetectorMessenger::~DetectorMessenger()
0100 {
0101   delete fMaterCmd;
0102   delete fSizeCmd;
0103   delete fIsotopeCmd;
0104   delete fDetDir;
0105   delete fTesthadDir;
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0109 
0110 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0111 {
0112   if (command == fMaterCmd) {
0113     fDetector->SetMaterial(newValue);
0114   }
0115 
0116   if (command == fSizeCmd) {
0117     fDetector->SetSize(fSizeCmd->GetNewDoubleValue(newValue));
0118   }
0119 
0120   if (command == fIsotopeCmd) {
0121     G4int Z;
0122     G4int A;
0123     G4double dens;
0124     G4String name, unt;
0125     std::istringstream is(newValue);
0126     is >> name >> Z >> A >> dens >> unt;
0127     dens *= G4UIcommand::ValueOf(unt);
0128     fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0129     fDetector->SetMaterial(name);
0130   }
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......