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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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