Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 08:29:30

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   fTesthadrDir = new G4UIdirectory("/testhadr/");
0045   fTesthadrDir->SetGuidance("commands specific to this example");
0046 
0047   G4bool broadcast = false;
0048   fDetDir = new G4UIdirectory("/testhadr/det/", broadcast);
0049   fDetDir->SetGuidance("detector construction commands");
0050 
0051   fMaterCmd1 = new G4UIcmdWithAString("/testhadr/det/setAbsorMat", this);
0052   fMaterCmd1->SetGuidance("Select absorber material");
0053   fMaterCmd1->SetParameterName("choice", false);
0054   fMaterCmd1->AvailableForStates(G4State_PreInit, G4State_Idle);
0055 
0056   fMaterCmd2 = new G4UIcmdWithAString("/testhadr/det/setContMat", this);
0057   fMaterCmd2->SetGuidance("Select container material");
0058   fMaterCmd2->SetParameterName("choice", false);
0059   fMaterCmd2->AvailableForStates(G4State_PreInit, G4State_Idle);
0060 
0061   fSizeCmd1 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setAbsorRadius", this);
0062   fSizeCmd1->SetGuidance("Set absorber radius");
0063   fSizeCmd1->SetParameterName("Radius", false);
0064   fSizeCmd1->SetRange("Radius>0.");
0065   fSizeCmd1->SetUnitCategory("Length");
0066   fSizeCmd1->AvailableForStates(G4State_PreInit, G4State_Idle);
0067 
0068   fSizeCmd2 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setAbsorLength", this);
0069   fSizeCmd2->SetGuidance("Set absorber length");
0070   fSizeCmd2->SetParameterName("Length", false);
0071   fSizeCmd2->SetRange("Length>0.");
0072   fSizeCmd2->SetUnitCategory("Length");
0073   fSizeCmd2->AvailableForStates(G4State_PreInit, G4State_Idle);
0074 
0075   fSizeCmd3 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setContThick", this);
0076   fSizeCmd3->SetGuidance("Set container thickness");
0077   fSizeCmd3->SetParameterName("Thick", false);
0078   fSizeCmd3->SetRange("Thick>0.");
0079   fSizeCmd3->SetUnitCategory("Length");
0080   fSizeCmd3->AvailableForStates(G4State_PreInit, G4State_Idle);
0081 
0082   fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0083   fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0084   fIsotopeCmd->SetGuidance("  symbol of isotope, Z, A, density of material");
0085   //
0086   G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0087   symbPrm->SetGuidance("isotope symbol");
0088   fIsotopeCmd->SetParameter(symbPrm);
0089   //
0090   G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0091   ZPrm->SetGuidance("Z");
0092   ZPrm->SetParameterRange("Z>0");
0093   fIsotopeCmd->SetParameter(ZPrm);
0094   //
0095   G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0096   APrm->SetGuidance("A");
0097   APrm->SetParameterRange("A>0");
0098   fIsotopeCmd->SetParameter(APrm);
0099   //
0100   G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0101   densityPrm->SetGuidance("density of material");
0102   densityPrm->SetParameterRange("density>0.");
0103   fIsotopeCmd->SetParameter(densityPrm);
0104   //
0105   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0106   unitPrm->SetGuidance("unit of density");
0107   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0108   unitPrm->SetParameterCandidates(unitList);
0109   fIsotopeCmd->SetParameter(unitPrm);
0110   //
0111   fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0115 
0116 DetectorMessenger::~DetectorMessenger()
0117 {
0118   delete fMaterCmd1;
0119   delete fMaterCmd2;
0120   delete fSizeCmd1;
0121   delete fSizeCmd2;
0122   delete fSizeCmd3;
0123   delete fIsotopeCmd;
0124   delete fDetDir;
0125   delete fTesthadrDir;
0126 }
0127 
0128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0129 
0130 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0131 {
0132   if (command == fMaterCmd1) {
0133     fDetector->SetAbsorMaterial(newValue);
0134   }
0135   if (command == fMaterCmd2) {
0136     fDetector->SetContainMaterial(newValue);
0137   }
0138 
0139   if (command == fSizeCmd1) {
0140     fDetector->SetAbsorRadius(fSizeCmd1->GetNewDoubleValue(newValue));
0141   }
0142 
0143   if (command == fSizeCmd2) {
0144     fDetector->SetAbsorLength(fSizeCmd2->GetNewDoubleValue(newValue));
0145   }
0146 
0147   if (command == fSizeCmd3) {
0148     fDetector->SetContainThickness(fSizeCmd3->GetNewDoubleValue(newValue));
0149   }
0150 
0151   if (command == fIsotopeCmd) {
0152     G4int Z;
0153     G4int A;
0154     G4double dens;
0155     G4String name, unt;
0156     std::istringstream is(newValue);
0157     is >> name >> Z >> A >> dens >> unt;
0158     dens *= G4UIcommand::ValueOf(unt);
0159     fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0160     fDetector->SetAbsorMaterial(name);
0161   }
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......