Geant4  10.03.p02
 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 70755 2013-06-05 12:17:48Z ihrivnac $
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), fTesthadrDir(0), fDetDir(0), fMaterCmd1(0), fMaterCmd2(0),
49  fSizeCmd1(0), fSizeCmd2(0), fSizeCmd3(0),
50  fIsotopeCmd(0)
51 {
52  fTesthadrDir = new G4UIdirectory("/testhadr/");
53  fTesthadrDir->SetGuidance("commands specific to this example");
54 
55  G4bool broadcast = false;
56  fDetDir = new G4UIdirectory("/testhadr/det/",broadcast);
57  fDetDir->SetGuidance("detector construction commands");
58 
59  fMaterCmd1 = new G4UIcmdWithAString("/testhadr/det/setAbsorMat",this);
60  fMaterCmd1->SetGuidance("Select absorber material");
61  fMaterCmd1->SetParameterName("choice",false);
63 
64  fMaterCmd2 = new G4UIcmdWithAString("/testhadr/det/setContMat",this);
65  fMaterCmd2->SetGuidance("Select container material");
66  fMaterCmd2->SetParameterName("choice",false);
68 
69  fSizeCmd1 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setAbsorRadius",this);
70  fSizeCmd1->SetGuidance("Set absorber radius");
71  fSizeCmd1->SetParameterName("Radius",false);
72  fSizeCmd1->SetRange("Radius>0.");
73  fSizeCmd1->SetUnitCategory("Length");
75 
76  fSizeCmd2 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setAbsorLength",this);
77  fSizeCmd2->SetGuidance("Set absorber length");
78  fSizeCmd2->SetParameterName("Length",false);
79  fSizeCmd2->SetRange("Length>0.");
80  fSizeCmd2->SetUnitCategory("Length");
82 
83  fSizeCmd3 = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setContThick",this);
84  fSizeCmd3->SetGuidance("Set container thickness");
85  fSizeCmd3->SetParameterName("Thick",false);
86  fSizeCmd3->SetRange("Thick>0.");
87  fSizeCmd3->SetUnitCategory("Length");
89 
90  fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this);
91  fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
92  fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
93  //
94  G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false);
95  symbPrm->SetGuidance("isotope symbol");
96  fIsotopeCmd->SetParameter(symbPrm);
97  //
98  G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false);
99  ZPrm->SetGuidance("Z");
100  ZPrm->SetParameterRange("Z>0");
101  fIsotopeCmd->SetParameter(ZPrm);
102  //
103  G4UIparameter* APrm = new G4UIparameter("A",'i',false);
104  APrm->SetGuidance("A");
105  APrm->SetParameterRange("A>0");
106  fIsotopeCmd->SetParameter(APrm);
107  //
108  G4UIparameter* densityPrm = new G4UIparameter("density",'d',false);
109  densityPrm->SetGuidance("density of material");
110  densityPrm->SetParameterRange("density>0.");
111  fIsotopeCmd->SetParameter(densityPrm);
112  //
113  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
114  unitPrm->SetGuidance("unit of density");
116  unitPrm->SetParameterCandidates(unitList);
117  fIsotopeCmd->SetParameter(unitPrm);
118  //
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
125 {
126  delete fMaterCmd1;
127  delete fMaterCmd2;
128  delete fSizeCmd1;
129  delete fSizeCmd2;
130  delete fSizeCmd3;
131  delete fIsotopeCmd;
132  delete fDetDir;
133  delete fTesthadrDir;
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
139 {
140  if( command == fMaterCmd1 )
141  { fDetector->SetAbsorMaterial(newValue);}
142  if( command == fMaterCmd2 )
143  { fDetector->SetContainMaterial(newValue);}
144 
145  if( command == fSizeCmd1 )
146  { fDetector->SetAbsorRadius(fSizeCmd1->GetNewDoubleValue(newValue));}
147 
148  if( command == fSizeCmd2 )
149  { fDetector->SetAbsorLength(fSizeCmd2->GetNewDoubleValue(newValue));}
150 
151  if( command == fSizeCmd3 )
152  { fDetector->SetContainThickness(fSizeCmd3->GetNewDoubleValue(newValue));}
153 
154  if (command == fIsotopeCmd)
155  {
156  G4int Z; G4int A; G4double dens;
157  G4String name, unt;
158  std::istringstream is(newValue);
159  is >> name >> Z >> A >> dens >> unt;
160  dens *= G4UIcommand::ValueOf(unt);
161  fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A);
162  fDetector->SetAbsorMaterial(name);
163  }
164 }
165 
166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
const XML_Char * name
Definition: expat.h:151
void SetNewValue(G4UIcommand *, G4String)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
double A(double temperature)
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:321
bool G4bool
Definition: G4Types.hh:79
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
void SetContainMaterial(G4String)
DetectorMessenger(DetectorConstruction *)
Detector construction class to define materials and geometry.
void SetContainThickness(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)