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