Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 // $Id: DetectorMessenger.cc 77288 2013-11-22 10:52:58Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorMessenger.hh"
35 
36 #include <sstream>
37 
38 #include "DetectorConstruction.hh"
39 #include "G4UIdirectory.hh"
40 #include "G4UIcommand.hh"
41 #include "G4UIparameter.hh"
42 #include "G4UIcmdWithAnInteger.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 :G4UImessenger(),fDetector(Det),
50  fTestemDir(0),
51  fDetDir(0),
52  fNbAbsorCmd(0),
53  fAbsorCmd(0),
54  fSizeYZCmd(0),
55  fIsotopeCmd(0)
56 {
57  fTestemDir = new G4UIdirectory("/testhadr/");
58  fTestemDir->SetGuidance(" detector control.");
59 
60  fDetDir = new G4UIdirectory("/testhadr/det/");
61  fDetDir->SetGuidance("detector construction commands");
62 
63  fNbAbsorCmd = new G4UIcmdWithAnInteger("/testhadr/det/setNbOfAbsor",this);
64  fNbAbsorCmd->SetGuidance("Set number of Absorbers.");
65  fNbAbsorCmd->SetParameterName("NbAbsor",false);
66  fNbAbsorCmd->SetRange("NbAbsor>0");
68  fNbAbsorCmd->SetToBeBroadcasted(false);
69 
70  fAbsorCmd = new G4UIcommand("/testhadr/det/setAbsor",this);
71  fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
72  fAbsorCmd->SetGuidance(" absor number : from 1 to NbOfAbsor");
73  fAbsorCmd->SetGuidance(" material name");
74  fAbsorCmd->SetGuidance(" thickness (with unit) : t>0.");
75  //
76  G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb",'i',false);
77  AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
78  AbsNbPrm->SetParameterRange("AbsorNb>0");
79  fAbsorCmd->SetParameter(AbsNbPrm);
80  //
81  G4UIparameter* MatPrm = new G4UIparameter("material",'s',false);
82  MatPrm->SetGuidance("material name");
83  fAbsorCmd->SetParameter(MatPrm);
84  //
85  G4UIparameter* ThickPrm = new G4UIparameter("thickness",'d',false);
86  ThickPrm->SetGuidance("thickness of absorber");
87  ThickPrm->SetParameterRange("thickness>0.");
88  fAbsorCmd->SetParameter(ThickPrm);
89  //
90  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
91  unitPrm->SetGuidance("unit of thickness");
93  unitPrm->SetParameterCandidates(unitList);
94  fAbsorCmd->SetParameter(unitPrm);
95  //
97  fAbsorCmd->SetToBeBroadcasted(false);
98 
99  fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ",this);
100  fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber");
101  fSizeYZCmd->SetParameterName("SizeYZ",false);
102  fSizeYZCmd->SetRange("SizeYZ>0.");
103  fSizeYZCmd->SetUnitCategory("Length");
105  fSizeYZCmd->SetToBeBroadcasted(false);
106 
107  fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this);
108  fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
109  fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
110  //
111  G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false);
112  symbPrm->SetGuidance("isotope symbol");
113  fIsotopeCmd->SetParameter(symbPrm);
114  //
115  G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false);
116  ZPrm->SetGuidance("Z");
117  ZPrm->SetParameterRange("Z>0");
118  fIsotopeCmd->SetParameter(ZPrm);
119  //
120  G4UIparameter* APrm = new G4UIparameter("A",'i',false);
121  APrm->SetGuidance("A");
122  APrm->SetParameterRange("A>0");
123  fIsotopeCmd->SetParameter(APrm);
124  //
125  G4UIparameter* densityPrm = new G4UIparameter("density",'d',false);
126  densityPrm->SetGuidance("density of material");
127  densityPrm->SetParameterRange("density>0.");
128  fIsotopeCmd->SetParameter(densityPrm);
129  //
130  G4UIparameter* unitPrm1 = new G4UIparameter("unit",'s',false);
131  unitPrm1->SetGuidance("unit of density");
133  unitPrm1->SetParameterCandidates(unitList1);
134  fIsotopeCmd->SetParameter(unitPrm1);
135  //
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
140 
142 {
143  delete fNbAbsorCmd;
144  delete fAbsorCmd;
145  delete fSizeYZCmd;
146  delete fIsotopeCmd;
147  delete fDetDir;
148  delete fTestemDir;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
154 {
155  if( command == fNbAbsorCmd )
156  { fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));}
157 
158  if (command == fAbsorCmd)
159  {
160  G4int num; G4double tick;
161  G4String unt, mat;
162  std::istringstream is(newValue);
163  is >> num >> mat >> tick >> unt;
164  G4String material=mat;
165  tick *= G4UIcommand::ValueOf(unt);
166  fDetector->SetAbsorMaterial (num,material);
167  fDetector->SetAbsorThickness(num,tick);
168  }
169 
170  if( command == fSizeYZCmd )
171  { fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));}
172 
173  if (command == fIsotopeCmd)
174  {
175  G4int Z; G4int A; G4double dens;
176  G4String name, unt;
177  std::istringstream is(newValue);
178  is >> name >> Z >> A >> dens >> unt;
179  dens *= G4UIcommand::ValueOf(unt);
180  fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A);
181  }
182 }
183 
184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
const XML_Char * name
Definition: expat.h:151
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
string material
Definition: eplot.py:19
double A(double temperature)
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:321
void SetAbsorMaterial(G4int, const G4String &)
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:240
G4Material * MaterialWithSingleIsotope(G4String, G4String, G4double, G4int, G4int)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:309
DetectorMessenger(DetectorConstruction *)
Detector construction class to define materials and geometry.
void SetAbsorThickness(G4int, G4double)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:316
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)