Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/hadronic/Hadr03/src/DetectorMessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /// \file hadronic/Hadr03/src/DetectorMessenger.cc
27 /// \brief Implementation of the DetectorMessenger class
28 //
29 // $Id: DetectorMessenger.cc 77251 2013-11-22 10:06:41Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorMessenger.hh"
35 
36 #include "DetectorConstruction.hh"
37 #include "G4UIdirectory.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIparameter.hh"
40 #include "G4UIcmdWithAString.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47 :G4UImessenger(),
48  fDetector(Det), fTestemDir(0), fDetDir(0), fMaterCmd(0), fSizeCmd(0),
49  fMagFieldCmd(0), fIsotopeCmd(0)
50 {
51  fTestemDir = new G4UIdirectory("/testhadr/");
52  fTestemDir->SetGuidance("commands specific to this example");
53 
54  fDetDir = new G4UIdirectory("/testhadr/det/");
55  fDetDir->SetGuidance("detector construction commands");
56 
57  fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat",this);
58  fMaterCmd->SetGuidance("Select material of the box.");
59  fMaterCmd->SetParameterName("choice",false);
61  fMaterCmd->SetToBeBroadcasted(false);
62 
63  fSizeCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSize",this);
64  fSizeCmd->SetGuidance("Set size of the box");
65  fSizeCmd->SetParameterName("Size",false);
66  fSizeCmd->SetRange("Size>0.");
67  fSizeCmd->SetUnitCategory("Length");
69  fSizeCmd->SetToBeBroadcasted(false);
70 
71  fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setField",this);
72  fMagFieldCmd->SetGuidance("Define magnetic field.");
73  fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
74  fMagFieldCmd->SetParameterName("Bz",false);
75  fMagFieldCmd->SetUnitCategory("Magnetic flux density");
77  fMagFieldCmd->SetToBeBroadcasted(false);
78 
79  fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this);
80  fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
81  fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
82  //
83  G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false);
84  symbPrm->SetGuidance("isotope symbol");
85  fIsotopeCmd->SetParameter(symbPrm);
86  //
87  G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false);
88  ZPrm->SetGuidance("Z");
89  ZPrm->SetParameterRange("Z>0");
90  fIsotopeCmd->SetParameter(ZPrm);
91  //
92  G4UIparameter* APrm = new G4UIparameter("A",'i',false);
93  APrm->SetGuidance("A");
94  APrm->SetParameterRange("A>0");
95  fIsotopeCmd->SetParameter(APrm);
96  //
97  G4UIparameter* densityPrm = new G4UIparameter("density",'d',false);
98  densityPrm->SetGuidance("density of material");
99  densityPrm->SetParameterRange("density>0.");
100  fIsotopeCmd->SetParameter(densityPrm);
101  //
102  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
103  unitPrm->SetGuidance("unit of density");
105  unitPrm->SetParameterCandidates(unitList);
106  fIsotopeCmd->SetParameter(unitPrm);
107  //
109  fIsotopeCmd->SetToBeBroadcasted(false);
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
115 {
116  delete fMaterCmd;
117  delete fSizeCmd;
118  delete fMagFieldCmd;
119  delete fIsotopeCmd;
120  delete fDetDir;
121  delete fTestemDir;
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
127 {
128  if( command == fMaterCmd )
129  { fDetector->SetMaterial(newValue);}
130 
131  if( command == fSizeCmd )
132  { fDetector->SetSize(fSizeCmd->GetNewDoubleValue(newValue));}
133 
134  if( command == fMagFieldCmd )
135  { fDetector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));}
136 
137  if (command == fIsotopeCmd)
138  {
139  G4int Z; G4int A; G4double dens;
140  G4String name, unt;
141  std::istringstream is(newValue);
142  is >> name >> Z >> A >> dens >> unt;
143  dens *= G4UIcommand::ValueOf(unt);
144  fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A);
145  fDetector->SetMaterial(name);
146  }
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
const XML_Char * name
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:306
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4Material * MaterialWithSingleIsotope(G4String, G4String, G4double, G4int, G4int)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:301
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)