Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm11/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 electromagnetic/TestEm11/src/DetectorMessenger.cc
27 /// \brief Implementation of the DetectorMessenger class
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  fNdivCmd(0),
55  fSizeYZCmd(0)
56 {
57  fTestemDir = new G4UIdirectory("/testem/");
58  fTestemDir->SetGuidance(" detector control.");
59 
60  fDetDir = new G4UIdirectory("/testem/det/");
61  fDetDir->SetGuidance("detector construction commands");
62 
63  fNbAbsorCmd = new G4UIcmdWithAnInteger("/testem/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("/testem/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  fNdivCmd = new G4UIcommand("/testem/det/nDivAbsor",this);
100  fNdivCmd->SetGuidance("Divide the absor nb : number of divisions");
101  fNdivCmd->SetGuidance(" absor number : from 1 to NbOfAbsor");
102  fNdivCmd->SetGuidance(" number of divisions >= 0");
103  //
104  G4UIparameter* AbsNbPar = new G4UIparameter("AbsorNb",'i',false);
105  AbsNbPar->SetGuidance("absor number : from 1 to NbOfAbsor");
106  AbsNbPar->SetParameterRange("AbsorNb>0");
107  fNdivCmd->SetParameter(AbsNbPar);
108  //
109  G4UIparameter* NdivPrm = new G4UIparameter("NdivNb",'i',false);
110  NdivPrm->SetGuidance("nb of divisions > 0");
111  NdivPrm->SetParameterRange("NdivNb>0");
112  fNdivCmd->SetParameter(NdivPrm);
113  //
115  fNdivCmd->SetToBeBroadcasted(false);
116 
117  fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this);
118  fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber");
119  fSizeYZCmd->SetParameterName("SizeYZ",false);
120  fSizeYZCmd->SetRange("SizeYZ>0.");
121  fSizeYZCmd->SetUnitCategory("Length");
123  fSizeYZCmd->SetToBeBroadcasted(false);
124 
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
130 {
131  delete fNbAbsorCmd;
132  delete fAbsorCmd;
133  delete fNdivCmd;
134  delete fSizeYZCmd;
135  delete fDetDir;
136  delete fTestemDir;
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
140 
142 {
143  if( command == fNbAbsorCmd )
144  { fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));}
145 
146  if (command == fAbsorCmd)
147  {
148  G4int num; G4double tick;
149  G4String unt, mat;
150  std::istringstream is(newValue);
151  is >> num >> mat >> tick >> unt;
152  G4String material=mat;
153  tick *= G4UIcommand::ValueOf(unt);
154  fDetector->SetAbsorMaterial (num,material);
155  fDetector->SetAbsorThickness(num,tick);
156  }
157 
158  if (command == fNdivCmd)
159  {
160  G4int num, ndiv;
161  std::istringstream is(newValue);
162  is >> num >> ndiv;
163  fDetector->SetNbOfDivisions (num,ndiv);
164  }
165 
166  if( command == fSizeYZCmd )
167  { fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));}
168 
169 }
170 
171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
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
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
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)