Geant4_10
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 67268 2013-02-13 11:38:40Z 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"
41 #include "G4UIcmdWithAnInteger.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
48 :G4UImessenger(),fDetector(Det),
49  fTestemDir(0),
50  fDetDir(0),
51  fMaterCmd(0),
52  fSizeXCmd(0),
53  fSizeYZCmd(0),
54  fMagFieldCmd(0),
55  fTalNbCmd(0),
56  fTalDefCmd(0),
57  fTalPosiCmd(0),
58  fUpdateCmd(0)
59 {
60  fTestemDir = new G4UIdirectory("/testem/");
61  fTestemDir->SetGuidance(" detector control.");
62 
63  fDetDir = new G4UIdirectory("/testem/det/");
64  fDetDir->SetGuidance("detector construction commands");
65 
66  fMaterCmd = new G4UIcmdWithAString("/testem/det/setMat",this);
67  fMaterCmd->SetGuidance("Select material of the box.");
68  fMaterCmd->SetParameterName("choice",false);
70 
71  fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeX",this);
72  fSizeXCmd->SetGuidance("Set sizeX of the absorber");
73  fSizeXCmd->SetParameterName("SizeX",false);
74  fSizeXCmd->SetRange("SizeX>0.");
75  fSizeXCmd->SetUnitCategory("Length");
77 
78  fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this);
79  fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber");
80  fSizeYZCmd->SetParameterName("SizeYZ",false);
81  fSizeYZCmd->SetRange("SizeYZ>0.");
82  fSizeYZCmd->SetUnitCategory("Length");
84 
85  fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField",this);
86  fMagFieldCmd->SetGuidance("Define magnetic field.");
87  fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
88  fMagFieldCmd->SetParameterName("Bz",false);
89  fMagFieldCmd->SetUnitCategory("Magnetic flux density");
91 
92  fTalNbCmd = new G4UIcmdWithAnInteger("/testem/det/tallyNumber",this);
93  fTalNbCmd->SetGuidance("Set number of fTallies.");
94  fTalNbCmd->SetParameterName("tallyNb",false);
95  fTalNbCmd->SetRange("tallyNb>=0");
97 
98  fTalDefCmd = new G4UIcommand("/testem/det/tallyDefinition",this);
99  fTalDefCmd->SetGuidance("Set tally nb, material, box dimensions.");
100  fTalDefCmd->SetGuidance(" tally number : from 1 to tallyNumber");
101  fTalDefCmd->SetGuidance(" material name");
102  fTalDefCmd->SetGuidance(" dimensions (3-vector with unit)");
103  //
104  G4UIparameter* fTalNbPrm = new G4UIparameter("tallyNb",'i',false);
105  fTalNbPrm->SetGuidance("tally number : from 1 to tallyNumber");
106  fTalNbPrm->SetParameterRange("tallyNb>0");
107  fTalDefCmd->SetParameter(fTalNbPrm);
108  //
109  G4UIparameter* MatPrm = new G4UIparameter("material",'s',false);
110  MatPrm->SetGuidance("material name");
111  fTalDefCmd->SetParameter(MatPrm);
112  //
113  G4UIparameter* SizeXPrm = new G4UIparameter("sizeX",'d',false);
114  SizeXPrm->SetGuidance("sizeX");
115  SizeXPrm->SetParameterRange("sizeX>0.");
116  fTalDefCmd->SetParameter(SizeXPrm);
117  //
118  G4UIparameter* SizeYPrm = new G4UIparameter("sizeY",'d',false);
119  SizeYPrm->SetGuidance("sizeY");
120  SizeYPrm->SetParameterRange("sizeY>0.");
121  fTalDefCmd->SetParameter(SizeYPrm);
122  //
123  G4UIparameter* SizeZPrm = new G4UIparameter("sizeZ",'d',false);
124  SizeZPrm->SetGuidance("sizeZ");
125  SizeZPrm->SetParameterRange("sizeZ>0.");
126  fTalDefCmd->SetParameter(SizeZPrm);
127  //
128  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
129  unitPrm->SetGuidance("unit of dimensions");
131  unitPrm->SetParameterCandidates(unitList);
132  fTalDefCmd->SetParameter(unitPrm);
133  //
135 
136  fTalPosiCmd = new G4UIcommand("/testem/det/tallyPosition",this);
137  fTalPosiCmd->SetGuidance("Set tally nb, position");
138  fTalPosiCmd->SetGuidance(" tally number : from 1 to tallyNumber");
139  fTalPosiCmd->SetGuidance(" position (3-vector with unit)");
140  //
141  G4UIparameter* fTalNumPrm = new G4UIparameter("tallyNum",'i',false);
142  fTalNumPrm->SetGuidance("tally number : from 1 to tallyNumber");
143  fTalNumPrm->SetParameterRange("tallyNum>0");
144  fTalPosiCmd->SetParameter(fTalNumPrm);
145  //
146  G4UIparameter* PosiXPrm = new G4UIparameter("posiX",'d',false);
147  PosiXPrm->SetGuidance("position X");
148  fTalPosiCmd->SetParameter(PosiXPrm);
149  //
150  G4UIparameter* PosiYPrm = new G4UIparameter("posiY",'d',false);
151  PosiYPrm->SetGuidance("position Y");
152  fTalPosiCmd->SetParameter(PosiYPrm);
153  //
154  G4UIparameter* PosiZPrm = new G4UIparameter("posiZ",'d',false);
155  PosiZPrm->SetGuidance("position Z");
156  fTalPosiCmd->SetParameter(PosiZPrm);
157  //
158  G4UIparameter* unitPr = new G4UIparameter("unit",'s',false);
159  unitPr->SetGuidance("unit of position");
160  unitPr->SetParameterCandidates(unitList);
161  fTalPosiCmd->SetParameter(unitPr);
162  //
164 
165  fUpdateCmd = new G4UIcmdWithoutParameter("/testem/det/update",this);
166  fUpdateCmd->SetGuidance("Update calorimeter geometry.");
167  fUpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" ");
168  fUpdateCmd->SetGuidance("if you changed geometrical value(s).");
169  fUpdateCmd->AvailableForStates(G4State_Idle);
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
173 
175 {
176  delete fMaterCmd;
177  delete fSizeXCmd;
178  delete fSizeYZCmd;
179  delete fMagFieldCmd;
180  delete fTalNbCmd;
181  delete fTalDefCmd;
182  delete fTalPosiCmd;
183  delete fUpdateCmd;
184  delete fDetDir;
185  delete fTestemDir;
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 
191 {
192  if( command == fMaterCmd )
193  { fDetector->SetMaterial(newValue);}
194 
195  if( command == fSizeXCmd )
196  { fDetector->SetSizeX(fSizeXCmd->GetNewDoubleValue(newValue));}
197 
198  if( command == fSizeYZCmd )
199  { fDetector->SetSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));}
200 
201  if( command == fMagFieldCmd )
202  { fDetector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));}
203 
204  if( command == fTalNbCmd )
205  { fDetector->SetTallyNumber(fTalNbCmd->GetNewIntValue(newValue));}
206 
207  if (command == fTalDefCmd)
208  {
209  G4int num; G4double v1, v2, v3;
210  G4String unt, mat;
211  std::istringstream is(newValue);
212  is >> num >> mat >> v1 >> v2 >> v3 >> unt;
214  v1 *= G4UIcommand::ValueOf(unt);
215  v2 *= G4UIcommand::ValueOf(unt);
216  v3 *= G4UIcommand::ValueOf(unt);
217  fDetector->SetTallyMaterial (num,material);
218  fDetector->SetTallySize(num,G4ThreeVector(v1,v2,v3));
219  }
220 
221  if (command == fTalPosiCmd)
222  {
223  G4int num; G4double v1, v2, v3;
224  G4String unt;
225  std::istringstream is(newValue);
226  is >> num >> v1 >> v2 >> v3 >> unt;
227  v1 *= G4UIcommand::ValueOf(unt);
228  v2 *= G4UIcommand::ValueOf(unt);
229  v3 *= G4UIcommand::ValueOf(unt);
230  fDetector->SetTallyPosition(num,G4ThreeVector(v1,v2,v3));
231  }
232 
233  if( command == fUpdateCmd )
234  { fDetector->UpdateGeometry();}
235 }
236 
237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetTallyMaterial(G4int, G4String)
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
CLHEP::Hep3Vector G4ThreeVector
static G4int GetNewIntValue(const char *paramString)
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
Float_t mat
Definition: plot.C:40
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
void SetTallySize(G4int, G4ThreeVector)
DetectorMessenger(DetectorConstruction *)
void SetTallyPosition(G4int, G4ThreeVector)
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)