Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ScoringMessenger.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//
27// ---------------------------------------------------------------------
28
29#include "G4ScoringMessenger.hh"
30#include "G4ScoringManager.hh"
31#include "G4VScoringMesh.hh"
32#include "G4ScoringBox.hh"
33#include "G4ScoringCylinder.hh"
34#include "G4ScoringRealWorld.hh"
35#include "G4ScoringProbe.hh"
36
37#include "G4UIdirectory.hh"
40#include "G4UIcmdWithAString.hh"
41#include "G4UIcmdWithABool.hh"
44#include "G4UIcommand.hh"
45#include "G4UIparameter.hh"
46#include "G4Tokenizer.hh"
47#include "G4UnitsTable.hh"
48#include "G4VScoreColorMap.hh"
49
51 : fSMan(SManager)
52{
53 G4UIparameter* param = nullptr;
54
55 scoreDir = new G4UIdirectory("/score/");
56 scoreDir->SetGuidance("Interactive scoring commands.");
57
58 listCmd = new G4UIcmdWithoutParameter("/score/list", this);
59 listCmd->SetGuidance("List scoring worlds.");
60
61 dumpCmd = new G4UIcmdWithoutParameter("/score/dump", this);
62 dumpCmd->SetGuidance("Dump results of scorers.");
63
64 verboseCmd = new G4UIcmdWithAnInteger("/score/verbose", this);
65 verboseCmd->SetGuidance("Verbosity.");
66 verboseCmd->SetGuidance(" 0) errors or warnings,");
67 verboseCmd->SetGuidance(" 1) information with 0)");
68
69 meshCreateDir = new G4UIdirectory("/score/create/");
70 meshCreateDir->SetGuidance(" Mesh creation commands.");
71 //
72 // Mesh commands
73 meshBoxCreateCmd = new G4UIcmdWithAString("/score/create/boxMesh", this);
74 meshBoxCreateCmd->SetGuidance("Create scoring box mesh.");
75 meshBoxCreateCmd->SetParameterName("MeshName", false);
76 //
77 meshCylinderCreateCmd =
78 new G4UIcmdWithAString("/score/create/cylinderMesh", this);
79 meshCylinderCreateCmd->SetGuidance("Create scoring mesh.");
80 meshCylinderCreateCmd->SetParameterName("MeshName", false);
81
82 meshRWLogVolCreateCmd =
83 new G4UIcommand("/score/create/realWorldLogVol", this);
84 meshRWLogVolCreateCmd->SetGuidance(
85 "Define scorers to a logical volume defined in the real world.");
86 meshRWLogVolCreateCmd->SetGuidance(
87 " - Name of the specified logical volume is used as the mesh name.");
88 meshRWLogVolCreateCmd->SetGuidance(
89 " - /score/mesh commands do not affect for this mesh.");
90 meshRWLogVolCreateCmd->SetGuidance(
91 " - If copyNumberLevel is set, the copy number of that-level higher");
92 meshRWLogVolCreateCmd->SetGuidance(
93 " in the geometrical hierarchy is used as the index.");
94 param = new G4UIparameter("logVol", 's', false);
95 meshRWLogVolCreateCmd->SetParameter(param);
96 param = new G4UIparameter("copyNumberLevel", 'i', true);
97 param->SetParameterRange("copyNumberLevel>=0");
98 param->SetDefaultValue(0);
99 meshRWLogVolCreateCmd->SetParameter(param);
100 //
101 probeCreateCmd = new G4UIcommand("/score/create/probe", this);
102 probeCreateCmd->SetGuidance("Define scoring probe.");
103 probeCreateCmd->SetGuidance(
104 " halfSize defines the half-width of the probing cube.");
105 param = new G4UIparameter("pname", 's', false);
106 probeCreateCmd->SetParameter(param);
107 param = new G4UIparameter("halfSize", 'd', false);
108 probeCreateCmd->SetParameter(param);
109 param = new G4UIparameter("unit", 's', true);
110 param->SetDefaultUnit("mm");
111 probeCreateCmd->SetParameter(param);
112 param = new G4UIparameter("checkOverlap", 'b', true);
113 param->SetDefaultValue(0);
114 probeCreateCmd->SetParameter(param);
115 //
116 meshOpnCmd = new G4UIcmdWithAString("/score/open", this);
117 meshOpnCmd->SetGuidance("Open scoring mesh.");
118 meshOpnCmd->SetParameterName("MeshName", false);
119 //
120 meshClsCmd = new G4UIcmdWithoutParameter("/score/close", this);
121 meshClsCmd->SetGuidance("Close scoring mesh.");
122
123 meshDir = new G4UIdirectory("/score/mesh/");
124 meshDir->SetGuidance(" Mesh processing commands.");
125 //
126 mBoxSizeCmd = new G4UIcmdWith3VectorAndUnit("/score/mesh/boxSize", this);
127 mBoxSizeCmd->SetGuidance("Define size of the scoring mesh.");
128 mBoxSizeCmd->SetGuidance("Dx Dy Dz unit");
129 mBoxSizeCmd->SetParameterName("Di", "Dj", "Dk", false, false);
130 mBoxSizeCmd->SetRange("Di>0. && Dj>0. && Dk>0.");
131 mBoxSizeCmd->SetDefaultUnit("mm");
132 //
133 mCylinderSizeCmd = new G4UIcommand("/score/mesh/cylinderSize", this);
134 mCylinderSizeCmd->SetGuidance("Define size of the scoring mesh.");
135 mCylinderSizeCmd->SetGuidance("R Dz unit");
136 param = new G4UIparameter("R", 'd', false);
137 param->SetParameterRange("R>0");
138 mCylinderSizeCmd->SetParameter(param);
139 param = new G4UIparameter("Dz", 'd', false);
140 param->SetParameterRange("Dz>0");
141 mCylinderSizeCmd->SetParameter(param);
142 param = new G4UIparameter("unit", 's', true);
143 param->SetDefaultUnit("mm");
144 mCylinderSizeCmd->SetParameter(param);
145 //
146 mCylinderRMinCmd =
147 new G4UIcmdWithADoubleAndUnit("/score/mesh/cylinderRMin", this);
148 mCylinderRMinCmd->SetGuidance("Define the inner radius of the tube mesh.");
149 mCylinderRMinCmd->SetGuidance("This command is not needed for cylinder mesh");
150 mCylinderRMinCmd->SetParameterName("RMin", false, false);
151 mCylinderRMinCmd->SetRange("RMin>=0.");
152 mCylinderRMinCmd->SetDefaultUnit("mm");
153 //
154 mCylinderAngleCmd = new G4UIcommand("/score/mesh/cylinderAngles", this);
155 mCylinderAngleCmd->SetGuidance(
156 "Define starting angle and span for tube segment mesh.");
157 mCylinderAngleCmd->SetGuidance(
158 "This command is not needed for cylinder mesh");
159 param = new G4UIparameter("startPhi", 'd', false);
160 mCylinderAngleCmd->SetParameter(param);
161 param = new G4UIparameter("deltaPhi", 'd', false);
162 param->SetParameterRange("deltaPhi>0.");
163 mCylinderAngleCmd->SetParameter(param);
164 param = new G4UIparameter("unit", 's', true);
165 param->SetDefaultUnit("deg");
166 mCylinderAngleCmd->SetParameter(param);
167 //
168 // Division command
169 mBinCmd = new G4UIcommand("/score/mesh/nBin", this);
170 mBinCmd->SetGuidance("Define segments of the scoring mesh.");
171 mBinCmd->SetGuidance("[usage] /score/mesh/nBin");
172 mBinCmd->SetGuidance(" In case of boxMesh, parameters are given in");
173 mBinCmd->SetGuidance(" Ni :(int) Number of bins i (in x-axis) ");
174 mBinCmd->SetGuidance(" Nj :(int) Number of bins j (in y-axis) ");
175 mBinCmd->SetGuidance(" Nk :(int) Number of bins k (in z-axis) ");
176 mBinCmd->SetGuidance(" In case of cylinderMesh, parameters are given in");
177 mBinCmd->SetGuidance(" Nr :(int) Number of bins in radial axis ");
178 mBinCmd->SetGuidance(" Nz :(int) Number of bins in z axis ");
179 mBinCmd->SetGuidance(" Nphi:(int) Number of bins in phi axis ");
180
181 param = new G4UIparameter("Ni", 'i', false);
182 param->SetDefaultValue("1");
183 param->SetParameterRange("Ni>0");
184 mBinCmd->SetParameter(param);
185 param = new G4UIparameter("Nj", 'i', false);
186 param->SetDefaultValue("1");
187 param->SetParameterRange("Nj>0");
188 mBinCmd->SetParameter(param);
189 param = new G4UIparameter("Nk", 'i', false);
190 param->SetDefaultValue("1");
191 mBinCmd->SetParameter(param);
192 param->SetParameterRange("Nk>0");
193
194 // Placement command
195 mTransDir = new G4UIdirectory("/score/mesh/translate/");
196 mTransDir->SetGuidance("Mesh translation commands.");
197 //
198 mTResetCmd = new G4UIcmdWithoutParameter("/score/mesh/translate/reset", this);
199 mTResetCmd->SetGuidance("Reset translated position of the scoring mesh.");
200 //
201 mTXyzCmd = new G4UIcmdWith3VectorAndUnit("/score/mesh/translate/xyz", this);
202 mTXyzCmd->SetGuidance("Translate the scoring mesh.");
203 mTXyzCmd->SetParameterName("X", "Y", "Z", false, false);
204 mTXyzCmd->SetDefaultUnit("mm");
205 //
206 mRotDir = new G4UIdirectory("/score/mesh/rotate/");
207 mRotDir->SetGuidance("Mesh rotation commands.");
208
209 mRotXCmd = new G4UIcmdWithADoubleAndUnit("/score/mesh/rotate/rotateX", this);
210 mRotXCmd->SetGuidance("Rotate the scoring mesh in X axis.");
211 mRotXCmd->SetParameterName("Rx", false);
212 mRotXCmd->SetDefaultUnit("deg");
213 //
214 mRotYCmd = new G4UIcmdWithADoubleAndUnit("/score/mesh/rotate/rotateY", this);
215 mRotYCmd->SetGuidance("Rotate the scoring mesh in Y axis.");
216 mRotYCmd->SetParameterName("Ry", false);
217 mRotYCmd->SetDefaultUnit("deg");
218 //
219 mRotZCmd = new G4UIcmdWithADoubleAndUnit("/score/mesh/rotate/rotateZ", this);
220 mRotZCmd->SetGuidance("Rotate the scoring mesh in Z axis.");
221 mRotZCmd->SetParameterName("Rz", false);
222 mRotZCmd->SetDefaultUnit("deg");
223 //
224 probeDir = new G4UIdirectory("/score/probe/");
225 probeDir->SetGuidance("Probe commands");
226
227 probeMatCmd = new G4UIcmdWithAString("/score/probe/material", this);
228 probeMatCmd->SetGuidance("Specify a material to the probe cube.");
229 probeMatCmd->SetGuidance("Material name has to be taken from G4NistManager.");
230 probeMatCmd->SetGuidance("Once this command is used, the specified material "
231 "overlays the material in the mass geometry");
232 probeMatCmd->SetGuidance("with \"Layered Mass Geometry\" mechanism so that "
233 "physics quantities such as energy deposition");
234 probeMatCmd->SetGuidance("or dose will be calculated with this material.");
235 probeMatCmd->SetGuidance("To switch-off this overlaying, use \"none\".");
236 probeMatCmd->SetParameterName("matName", true);
237 probeMatCmd->SetDefaultValue("none");
238 probeMatCmd->SetToBeBroadcasted(false);
239
240 probeLocateCmd = new G4UIcmdWith3VectorAndUnit("/score/probe/locate", this);
241 probeLocateCmd->SetGuidance(
242 "Locate a probe in the global coordinate system.");
243 probeLocateCmd->SetParameterName("x", "y", "z", false);
244 probeLocateCmd->SetDefaultUnit("mm");
245 probeLocateCmd->SetToBeBroadcasted(false);
246
247 // Draw Scoring result
248 drawCmd = new G4UIcommand("/score/drawProjection", this);
249 drawCmd->SetGuidance("Draw projection(s) of scored quantities.");
250 drawCmd->SetGuidance(
251 "Parameter <proj> specified which projection(s) to be drawn.");
252 drawCmd->SetGuidance(
253 " 100 : xy-plane, 010 : yz-plane, 001 : zx-plane -- default 111");
254 drawCmd->SetGuidance(
255 " 100 : N/A, 010 : z_phi-plane, 001 : r_phi-plane -- default 111");
256 param = new G4UIparameter("meshName", 's', false);
257 drawCmd->SetParameter(param);
258 param = new G4UIparameter("psName", 's', false);
259 drawCmd->SetParameter(param);
260 param = new G4UIparameter("colorMapName", 's', true);
261 param->SetDefaultValue("defaultLinearColorMap");
262 drawCmd->SetParameter(param);
263 param = new G4UIparameter("proj", 'i', true);
264 param->SetDefaultValue(111);
265 drawCmd->SetParameter(param);
266 drawCmd->SetToBeBroadcasted(false);
267
268 // Draw column
269 drawColumnCmd = new G4UIcommand("/score/drawColumn", this);
270 drawColumnCmd->SetGuidance("Draw a cell column.");
271 drawColumnCmd->SetGuidance(" plane = 0 : x-y, 1: y-z, 2: z-x for box mesh");
272 drawColumnCmd->SetGuidance(
273 " 0 : z-phi, 1: r-phi, 2: r-z for cylinder mesh");
274 param = new G4UIparameter("meshName", 's', false);
275 drawColumnCmd->SetParameter(param);
276 param = new G4UIparameter("psName", 's', false);
277 drawColumnCmd->SetParameter(param);
278 param = new G4UIparameter("plane", 'i', false);
279 param->SetParameterRange("plane>=0 && plane<=2");
280 drawColumnCmd->SetParameter(param);
281 param = new G4UIparameter("column", 'i', false);
282 drawColumnCmd->SetParameter(param);
283 param = new G4UIparameter("colorMapName", 's', true);
284 param->SetDefaultValue("defaultLinearColorMap");
285 drawColumnCmd->SetParameter(param);
286 drawColumnCmd->SetToBeBroadcasted(false);
287
288 colorMapDir = new G4UIdirectory("/score/colorMap/");
289 colorMapDir->SetGuidance("Color map commands.");
290
291 listColorMapCmd =
292 new G4UIcmdWithoutParameter("/score/colorMap/listScoreColorMaps", this);
293 listColorMapCmd->SetGuidance("List registered score color maps.");
294 listColorMapCmd->SetToBeBroadcasted(false);
295
296 floatMinMaxCmd = new G4UIcmdWithAString("/score/colorMap/floatMinMax", this);
297 floatMinMaxCmd->SetGuidance(
298 "Min/Max of the color map is calculated according to the actual scores.");
299 floatMinMaxCmd->SetParameterName("colorMapName", true, false);
300 floatMinMaxCmd->SetDefaultValue("defaultLinearColorMap");
301 floatMinMaxCmd->SetToBeBroadcasted(false);
302
303 colorMapMinMaxCmd = new G4UIcommand("/score/colorMap/setMinMax", this);
304 colorMapMinMaxCmd->SetGuidance("Define min/max value of the color map.");
305 param = new G4UIparameter("colorMapMame", 's', true);
306 param->SetDefaultValue("defaultLinearColorMap");
307 colorMapMinMaxCmd->SetParameter(param);
308 param = new G4UIparameter("minValue", 'd', false);
309 colorMapMinMaxCmd->SetParameter(param);
310 param = new G4UIparameter("maxValue", 'd', false);
311 colorMapMinMaxCmd->SetParameter(param);
312 colorMapMinMaxCmd->SetToBeBroadcasted(false);
313
314 // Dump a scored quantity
315 dumpQtyToFileCmd = new G4UIcommand("/score/dumpQuantityToFile", this);
316 dumpQtyToFileCmd->SetGuidance("Dump one scored quantity to file.");
317 param = new G4UIparameter("meshName", 's', false);
318 dumpQtyToFileCmd->SetParameter(param);
319 param = new G4UIparameter("psName", 's', false);
320 dumpQtyToFileCmd->SetParameter(param);
321 param = new G4UIparameter("fileName", 's', false);
322 dumpQtyToFileCmd->SetParameter(param);
323 param = new G4UIparameter("option", 's', true);
324 dumpQtyToFileCmd->SetParameter(param);
325 dumpQtyToFileCmd->SetToBeBroadcasted(false);
326
327 dumpQtyWithFactorCmd = new G4UIcommand("/score/dumpQuantityWithFactor", this);
328 dumpQtyWithFactorCmd->SetGuidance("Dump one scored quantity to file.");
329 dumpQtyWithFactorCmd->SetGuidance(
330 "Each value is multiplied by the specified factor.");
331 param = new G4UIparameter("meshName", 's', false);
332 dumpQtyWithFactorCmd->SetParameter(param);
333 param = new G4UIparameter("psName", 's', false);
334 dumpQtyWithFactorCmd->SetParameter(param);
335 param = new G4UIparameter("fileName", 's', false);
336 dumpQtyWithFactorCmd->SetParameter(param);
337 param = new G4UIparameter("factor", 'd', false);
338 param->SetParameterRange("factor>0.");
339 dumpQtyWithFactorCmd->SetParameter(param);
340 param = new G4UIparameter("option", 's', true);
341 dumpQtyWithFactorCmd->SetParameter(param);
342 dumpQtyWithFactorCmd->SetToBeBroadcasted(false);
343
344 // Dump all scored quantities
345 dumpAllQtsToFileCmd = new G4UIcommand("/score/dumpAllQuantitiesToFile", this);
346 dumpAllQtsToFileCmd->SetGuidance("Dump all quantities of the mesh to file.");
347 param = new G4UIparameter("meshName", 's', false);
348 dumpAllQtsToFileCmd->SetParameter(param);
349 param = new G4UIparameter("fileName", 's', false);
350 dumpAllQtsToFileCmd->SetParameter(param);
351 param = new G4UIparameter("option", 's', true);
352 dumpAllQtsToFileCmd->SetParameter(param);
353 dumpAllQtsToFileCmd->SetToBeBroadcasted(false);
354
355 dumpAllQtsWithFactorCmd =
356 new G4UIcommand("/score/dumpAllQuantitiesWithFactor", this);
357 dumpAllQtsWithFactorCmd->SetGuidance(
358 "Dump all quantities of the mesh to file.");
359 dumpAllQtsWithFactorCmd->SetGuidance(
360 "Each value is multiplied by the specified factor.");
361 param = new G4UIparameter("meshName", 's', false);
362 dumpAllQtsWithFactorCmd->SetParameter(param);
363 param = new G4UIparameter("fileName", 's', false);
364 dumpAllQtsWithFactorCmd->SetParameter(param);
365 param = new G4UIparameter("factor", 'd', false);
366 param->SetParameterRange("factor>0.");
367 dumpAllQtsWithFactorCmd->SetParameter(param);
368 param = new G4UIparameter("option", 's', true);
369 dumpAllQtsWithFactorCmd->SetParameter(param);
370 dumpAllQtsWithFactorCmd->SetToBeBroadcasted(false);
371
372 fill1DCmd = new G4UIcommand("/score/fill1D", this);
373 fill1DCmd->SetGuidance("Let a primitive scorer fill 1-D histogram");
374 fill1DCmd->SetGuidance("Before using this command, primitive scorer must be "
375 "defined and assigned.");
376 fill1DCmd->SetGuidance("Also before using this command, a histogram has to "
377 "be defined by /analysis/h1/create command.");
378 fill1DCmd->SetGuidance(
379 "This command is available only for real-world volume or probe.");
380 fill1DCmd->SetGuidance("Please note that this command has to be applied to "
381 "each copy number of the scoring volume.");
382 fill1DCmd->SetGuidance("If same histogram ID is used more than once, more "
383 "than one scorers fill that histogram.");
384 param = new G4UIparameter("histID", 'i', false);
385 fill1DCmd->SetParameter(param);
386 param = new G4UIparameter("meshName", 's', false);
387 fill1DCmd->SetParameter(param);
388 param = new G4UIparameter("scorerName", 's', false);
389 fill1DCmd->SetParameter(param);
390 param = new G4UIparameter("copyNo", 'i', true);
391 param->SetDefaultValue(0);
392 fill1DCmd->SetParameter(param);
393}
394
396{
397 delete listCmd;
398 delete verboseCmd;
399 //
400 delete meshBoxCreateCmd;
401 delete meshCylinderCreateCmd;
402 delete meshRWLogVolCreateCmd;
403 delete probeCreateCmd;
404 delete meshCreateDir;
405 //
406 delete meshOpnCmd;
407 //
408 delete meshClsCmd;
409 delete meshDir;
410 //
411 delete mBoxSizeCmd;
412 delete mCylinderSizeCmd;
413 delete mCylinderRMinCmd;
414 delete mCylinderAngleCmd;
415 //
416 delete mBinCmd;
417 //
418 delete mTResetCmd;
419 delete mTXyzCmd;
420 delete mTransDir;
421 delete mRotXCmd;
422 delete mRotYCmd;
423 delete mRotZCmd;
424 delete mRotDir;
425 //
426 delete probeLocateCmd;
427 delete probeMatCmd;
428 delete probeDir;
429 //
430 delete dumpCmd;
431 delete drawCmd;
432 delete drawColumnCmd;
433 delete listColorMapCmd;
434 delete floatMinMaxCmd;
435 delete colorMapMinMaxCmd;
436 delete colorMapDir;
437 delete dumpQtyToFileCmd;
438 delete dumpQtyWithFactorCmd;
439 delete dumpAllQtsToFileCmd;
440 delete dumpAllQtsWithFactorCmd;
441 delete fill1DCmd;
442 //
443 delete scoreDir;
444}
445
447{
448 using MeshShape = G4VScoringMesh::MeshShape;
449
450 if(command == listCmd)
451 {
452 fSMan->List();
453 }
454 else if(command == dumpCmd)
455 {
456 fSMan->Dump();
457 }
458 else if(command == drawCmd)
459 {
460 G4Tokenizer next(newVal);
461 G4String meshName = next();
462 G4String psName = next();
463 G4String colorMapName = next();
464 G4int axflg = StoI(next());
465 fSMan->DrawMesh(meshName, psName, colorMapName, axflg);
466 }
467 else if(command == drawColumnCmd)
468 {
469 G4Tokenizer next(newVal);
470 G4String meshName = next();
471 G4String psName = next();
472 G4int iPlane = StoI(next());
473 G4int iColumn = StoI(next());
474 G4String colorMapName = next();
475 fSMan->DrawMesh(meshName, psName, iPlane, iColumn, colorMapName);
476 }
477 else if(command == dumpQtyToFileCmd)
478 {
479 G4Tokenizer next(newVal);
480 G4String meshName = next();
481 G4String psName = next();
482 G4String fileName = next();
483 G4String option = next("\n");
484 auto mesh = fSMan->FindMesh(meshName);
485 if(mesh == nullptr)
486 {
488 ed << "Mesh name <" << meshName << "> is not found. Command ignored.";
489 command->CommandFailed(ed);
490 return;
491 }
492 fSMan->DumpQuantityToFile(meshName, psName, fileName, option);
493 }
494 else if(command == dumpQtyWithFactorCmd)
495 {
496 G4Tokenizer next(newVal);
497 G4String meshName = next();
498 G4String psName = next();
499 G4String fileName = next();
500 G4double fac = StoD(next());
501 G4String option = next("\n");
502 auto mesh = fSMan->FindMesh(meshName);
503 if(mesh == nullptr)
504 {
506 ed << "Mesh name <" << meshName << "> is not found. Command ignored.";
507 command->CommandFailed(ed);
508 return;
509 }
510 fSMan->SetFactor(fac);
511 fSMan->DumpQuantityToFile(meshName, psName, fileName, option);
512 fSMan->SetFactor(1.0);
513 }
514 else if(command == dumpAllQtsToFileCmd)
515 {
516 G4Tokenizer next(newVal);
517 G4String meshName = next();
518 G4String fileName = next();
519 G4String option = next("\n");
520 auto mesh = fSMan->FindMesh(meshName);
521 if(mesh == nullptr)
522 {
524 ed << "Mesh name <" << meshName << "> is not found. Command ignored.";
525 command->CommandFailed(ed);
526 return;
527 }
528 fSMan->DumpAllQuantitiesToFile(meshName, fileName, option);
529 }
530 else if(command == dumpAllQtsWithFactorCmd)
531 {
532 G4Tokenizer next(newVal);
533 G4String meshName = next();
534 G4String fileName = next();
535 G4double fac = StoD(next());
536 G4String option = next("\n");
537 auto mesh = fSMan->FindMesh(meshName);
538 if(mesh == nullptr)
539 {
541 ed << "Mesh name <" << meshName << "> is not found. Command ignored.";
542 command->CommandFailed(ed);
543 return;
544 }
545 fSMan->SetFactor(fac);
546 fSMan->DumpAllQuantitiesToFile(meshName, fileName, option);
547 fSMan->SetFactor(1.0);
548 }
549 else if(command == fill1DCmd)
550 {
551 Fill1D(command, newVal);
552 }
553 else if(command == verboseCmd)
554 {
555 fSMan->SetVerboseLevel(verboseCmd->GetNewIntValue(newVal));
556 }
557 else if(command == meshBoxCreateCmd)
558 {
559 G4VScoringMesh* currentmesh = fSMan->GetCurrentMesh();
560 if(currentmesh != nullptr)
561 {
563 ed << "ERROR[" << meshBoxCreateCmd->GetCommandPath() << "] : Mesh <"
564 << currentmesh->GetWorldName()
565 << "> is still open. Close it first. Command ignored.";
566 command->CommandFailed(ed);
567 }
568 else
569 {
570 G4VScoringMesh* mesh = fSMan->FindMesh(newVal);
571 if(mesh == nullptr)
572 {
573 mesh = new G4ScoringBox(newVal);
574 fSMan->RegisterScoringMesh(mesh);
575 }
576 else
577 {
579 ed << "ERROR[" << meshBoxCreateCmd->GetCommandPath()
580 << "] : Scoring mesh <" << newVal
581 << "> already exists. Command ignored.";
582 command->CommandFailed(ed);
583 }
584 }
585 }
586 else if(command == meshCylinderCreateCmd)
587 {
588 G4VScoringMesh* currentmesh = fSMan->GetCurrentMesh();
589 if(currentmesh != nullptr)
590 {
592 ed << "ERROR[" << meshCylinderCreateCmd->GetCommandPath() << "] : Mesh <"
593 << currentmesh->GetWorldName()
594 << "> is still open. Close it first. Command ignored.";
595 command->CommandFailed(ed);
596 }
597 else
598 {
599 G4VScoringMesh* mesh = fSMan->FindMesh(newVal);
600 if(mesh == nullptr)
601 {
602 mesh = new G4ScoringCylinder(newVal);
603 fSMan->RegisterScoringMesh(mesh);
604 }
605 else
606 {
608 ed << "ERROR[" << meshCylinderCreateCmd->GetCommandPath()
609 << "] : Scoring mesh <" << newVal
610 << "> already exists. Command ignored.";
611 command->CommandFailed(ed);
612 }
613 }
614 }
615 else if(command == meshRWLogVolCreateCmd)
616 {
617 auto mesh = fSMan->GetCurrentMesh();
618 if(mesh != nullptr)
619 {
621 ed << "ERROR[" << meshRWLogVolCreateCmd->GetCommandPath() << "] : Mesh <"
622 << mesh->GetWorldName()
623 << "> is still open. Close it first. Command ignored.";
624 command->CommandFailed(ed);
625 }
626 else
627 {
628 G4Tokenizer next(newVal);
629 G4String meshName = next();
630 G4int idx = StoI(next());
631 mesh = fSMan->FindMesh(meshName);
632 if(mesh == nullptr)
633 {
634 mesh = new G4ScoringRealWorld(meshName);
635 mesh->SetCopyNumberLevel(idx);
636 fSMan->RegisterScoringMesh(mesh);
637 }
638 else
639 {
641 ed << "ERROR[" << meshRWLogVolCreateCmd->GetCommandPath()
642 << "] : Scoring mesh <" << meshName
643 << "> already exists. Command ignored.";
644 command->CommandFailed(ed);
645 }
646 }
647 }
648 else if(command == probeCreateCmd)
649 {
650 auto mesh = fSMan->GetCurrentMesh();
651 if(mesh != nullptr)
652 {
654 ed << "ERROR[" << meshRWLogVolCreateCmd->GetCommandPath() << "] : Mesh <"
655 << mesh->GetWorldName()
656 << "> is still open. Close it first. Command ignored.";
657 command->CommandFailed(ed);
658 }
659 else
660 {
661 G4Tokenizer next(newVal);
662 G4String qname = next();
663 G4double halfSize = StoD(next());
664 halfSize *= G4UIcommand::ValueOf(next());
665 G4bool checkOverlap = StoB(next());
666 mesh = fSMan->FindMesh(qname);
667 if(mesh == nullptr)
668 {
669 mesh = new G4ScoringProbe(qname, halfSize, checkOverlap);
670 fSMan->RegisterScoringMesh(mesh);
671 }
672 else
673 {
675 ed << "ERROR[" << probeCreateCmd->GetCommandPath() << "] : Mesh name <"
676 << qname << "> already exists. Use another name.";
677 command->CommandFailed(ed);
678 }
679 }
680 }
681 else if(command == probeMatCmd || command == probeLocateCmd)
682 {
683 auto mesh = fSMan->GetCurrentMesh();
684 if(mesh == nullptr)
685 {
687 ed << "ERROR : No mesh is currently open. Open/create a mesh first. "
688 "Command ignored.";
689 command->CommandFailed(ed);
690 return;
691 }
692 if(mesh->GetShape() != MeshShape::probe)
693 {
695 ed << "ERROR : Inconsistent mesh type. Close current mesh and open "
696 "Scoring Probe.";
697 command->CommandFailed(ed);
698 return;
699 }
700
701 if(command == probeMatCmd)
702 {
703 G4bool succ = static_cast<G4ScoringProbe*>(mesh)->SetMaterial(newVal);
704 if(!succ)
705 {
707 ed << "Material <" << newVal
708 << "> is not defind in G4NistManager. Command is ignored.\n"
709 << "Use /material/nist/listMaterials command to see the available "
710 "materials.";
711 command->CommandFailed(ed);
712 return;
713 }
714 }
715 else if(command == probeLocateCmd)
716 {
717 G4ThreeVector loc = probeLocateCmd->GetNew3VectorValue(newVal);
718 static_cast<G4ScoringProbe*>(mesh)->LocateProbe(loc);
719 }
720 }
721 else if(command == listColorMapCmd)
722 {
723 fSMan->ListScoreColorMaps();
724 }
725 else if(command == floatMinMaxCmd)
726 {
727 G4VScoreColorMap* colorMap = fSMan->GetScoreColorMap(newVal);
728 if(colorMap != nullptr)
729 {
730 colorMap->SetFloatingMinMax(true);
731 }
732 else
733 {
735 ed << "ERROR[" << floatMinMaxCmd->GetCommandPath() << "] : color map <"
736 << newVal << "> is not defined. Command ignored.";
737 command->CommandFailed(ed);
738 }
739 }
740 else if(command == colorMapMinMaxCmd)
741 {
742 G4Tokenizer next(newVal);
743 G4String mapName = next();
744 G4double minVal = StoD(next());
745 G4double maxVal = StoD(next());
746 G4VScoreColorMap* colorMap = fSMan->GetScoreColorMap(mapName);
747 if(colorMap != nullptr)
748 {
749 colorMap->SetFloatingMinMax(false);
750 colorMap->SetMinMax(minVal, maxVal);
751 }
752 else
753 {
755 ed << "ERROR[" << colorMapMinMaxCmd->GetCommandPath() << "] : color map <"
756 << newVal << "> is not defined. Command ignored." << G4endl;
757 command->CommandFailed(ed);
758 }
759 }
760 else if(command == meshOpnCmd)
761 {
762 G4VScoringMesh* currentmesh = fSMan->GetCurrentMesh();
763 if(currentmesh != nullptr)
764 {
766 ed << "ERROR[" << meshOpnCmd->GetCommandPath() << "] : Mesh <"
767 << currentmesh->GetWorldName()
768 << "> is still open. Close it first. Command ignored.";
769 command->CommandFailed(ed);
770 }
771 else
772 {
773 G4VScoringMesh* mesh = fSMan->FindMesh(newVal);
774 if(mesh == nullptr)
775 {
777 ed << "ERROR[" << meshOpnCmd->GetCommandPath() << "] : Scoring mesh <"
778 << newVal << "> does not exist. Command ignored.";
779 command->CommandFailed(ed);
780 }
781 else
782 {
783 fSMan->SetCurrentMesh(mesh);
784 }
785 }
786 }
787 else if(command == meshClsCmd)
788 {
789 fSMan->CloseCurrentMesh();
790 }
791 else
792 {
793 //
794 // Get Current Mesh
795 //
796 G4VScoringMesh* mesh = fSMan->GetCurrentMesh();
797 //
798 // Commands for Current Mesh
799 if(mesh != nullptr)
800 {
801 MeshShape shape = mesh->GetShape();
802 if(shape == MeshShape::realWorldLogVol)
803 {
805 ed << "ERROR[" << mBinCmd->GetCommandPath()
806 << "] : Number of mesh command cannot be set for this type of mesh. "
807 "Command ignored.";
808 command->CommandFailed(ed);
809 }
810 else
811 {
812 // Tokens
813 G4TokenVec token;
814 FillTokenVec(newVal, token);
815 //
816 // Mesh Geometry
817 if(command == mBoxSizeCmd)
818 {
819 if(shape == MeshShape::box)
820 {
821 G4ThreeVector size = mBoxSizeCmd->GetNew3VectorValue(newVal);
822 G4double vsize[3];
823 vsize[0] = size.x();
824 vsize[1] = size.y();
825 vsize[2] = size.z();
826 mesh->SetSize(vsize);
827 }
828 else
829 {
831 ed << "ERROR[" << mBoxSizeCmd->GetCommandPath()
832 << "] : This mesh is not Box. Command ignored.";
833 command->CommandFailed(ed);
834 }
835 }
836 else if(command == mCylinderSizeCmd || command == mCylinderRMinCmd ||
837 command == mCylinderAngleCmd)
838 {
839 if(shape != MeshShape::cylinder)
840 {
842 ed << "ERROR[" << command->GetCommandPath()
843 << "] : This mesh is not Cylinder. Command ignored.";
844 command->CommandFailed(ed);
845 }
846 else
847 {
848 if(command == mCylinderSizeCmd)
849 {
850 G4double vsize[3];
851 vsize[0] = (mesh->GetSize()).x();
852 vsize[1] = StoD(token[0]);
853 vsize[2] = StoD(token[1]);
854 G4double unt = mCylinderSizeCmd->ValueOf(token[2]);
855 vsize[1] *= unt;
856 vsize[2] *= unt;
857 mesh->SetSize(vsize);
858 }
859 else if(command == mCylinderRMinCmd)
860 {
861 G4double vsize[3];
862 vsize[0] = mCylinderRMinCmd->GetNewDoubleValue(newVal);
863 vsize[1] = (mesh->GetSize()).y();
864 vsize[2] = (mesh->GetSize()).z();
865 mesh->SetSize(vsize);
866 }
867 else if(command == mCylinderAngleCmd)
868 {
869 G4double stphi = StoD(token[0]);
870 G4double spphi = StoD(token[1]);
871 G4double unt = mCylinderAngleCmd->ValueOf(token[2]);
872 mesh->SetAngles(stphi * unt, spphi * unt);
873 }
874 }
875 }
876 else if(command == mBinCmd)
877 {
878 MeshBinCommand(mesh, token);
879 }
880 else if(command == mTResetCmd)
881 {
882 G4double centerPosition[3] = { 0., 0., 0. };
883 mesh->SetCenterPosition(centerPosition);
884 }
885 else if(command == mTXyzCmd)
886 {
887 G4ThreeVector xyz = mTXyzCmd->GetNew3VectorValue(newVal);
888 G4double centerPosition[3];
889 centerPosition[0] = xyz.x();
890 centerPosition[1] = xyz.y();
891 centerPosition[2] = xyz.z();
892 mesh->SetCenterPosition(centerPosition);
893 }
894 else if(command == mRotXCmd)
895 {
896 G4double value = mRotXCmd->GetNewDoubleValue(newVal);
897 mesh->RotateX(value);
898 }
899 else if(command == mRotYCmd)
900 {
901 G4double value = mRotYCmd->GetNewDoubleValue(newVal);
902 mesh->RotateY(value);
903 }
904 else if(command == mRotZCmd)
905 {
906 G4double value = mRotZCmd->GetNewDoubleValue(newVal);
907 mesh->RotateZ(value);
908 }
909 }
910 }
911 else
912 {
914 ed << "ERROR: No mesh is currently open. Open/create a mesh first. "
915 "Command ignored.";
916 command->CommandFailed(ed);
917 }
918 }
919}
920
922{
923 G4String val;
924 if(command == verboseCmd)
925 {
926 val = verboseCmd->ConvertToString(fSMan->GetVerboseLevel());
927 }
928
929 return val;
930}
931
933{
934 G4Tokenizer next(newValues);
935 G4String val;
936 while(!(val = next()).empty())
937 { // Loop checking 12.18.2015 M.Asai
938 token.push_back(val);
939 }
940}
941
943{
944 G4int Ni = StoI(token[0]);
945 G4int Nj = StoI(token[1]);
946 G4int Nk = StoI(token[2]);
947 G4int nSegment[3];
948
949 if(dynamic_cast<G4ScoringBox*>(mesh) != nullptr)
950 {
951 G4cout << ".... G4ScoringMessenger::MeshBinCommand - G4ScoringBox"
952 << G4endl;
953 nSegment[0] = Ni;
954 nSegment[1] = Nj;
955 nSegment[2] = Nk;
956 }
957 else if(dynamic_cast<G4ScoringCylinder*>(mesh) != nullptr)
958 {
959 G4cout << ".... G4ScoringMessenger::MeshBinCommand - G4ScoringCylinder"
960 << G4endl;
961 nSegment[0] = Nj;
962 nSegment[1] = Nk;
963 nSegment[2] = Ni;
964 }
965 else
966 {
967 G4Exception("G4ScoringMessenger::MeshBinCommand()", "001", FatalException,
968 "invalid mesh type");
969 return;
970 }
971 //
972 mesh->SetNumberOfSegments(nSegment);
973}
974
975#include "G4VPrimitivePlotter.hh"
976#include "G4VScoreHistFiller.hh"
977
979{
980 using MeshShape = G4VScoringMesh::MeshShape;
981
982 G4Tokenizer next(newVal);
983 G4int histID = StoI(next());
984 G4String meshName = next();
985 G4String primName = next();
986 G4int copyNo = StoI(next());
987
988 auto filler = G4VScoreHistFiller::Instance();
989 if(filler == nullptr)
990 {
992 ed << "G4TScoreHistFiller is not instantiated in this application.";
993 cmd->CommandFailed(ed);
994 return;
995 }
996 //
997 // To do : check the validity of histID
998 //
999
1001 auto mesh = sm->FindMesh(meshName);
1002 if(mesh == nullptr)
1003 {
1005 ed << "Mesh name <" << meshName << "> is not found.";
1006 cmd->CommandFailed(ed);
1007 return;
1008 }
1009 auto shape = mesh->GetShape();
1010 if(shape != MeshShape::realWorldLogVol && shape != MeshShape::probe)
1011 {
1013 ed << "Mesh <" << meshName
1014 << "> is not real-world logical volume or probe.";
1015 cmd->CommandFailed(ed);
1016 return;
1017 }
1018
1019 auto prim = mesh->GetPrimitiveScorer(primName);
1020 if(prim == nullptr)
1021 {
1023 ed << "Primitive scorer name <" << primName << "> is not found.";
1024 cmd->CommandFailed(ed);
1025 return;
1026 }
1027 auto pp = dynamic_cast<G4VPrimitivePlotter*>(prim);
1028 if(pp == nullptr)
1029 {
1031 ed << "Primitive scorer <" << primName
1032 << "> does not support direct histogram filling.";
1033 cmd->CommandFailed(ed);
1034 return;
1035 }
1036
1037 pp->Plot(copyNo, histID);
1038}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
std::vector< G4String > G4TokenVec
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
void RegisterScoringMesh(G4VScoringMesh *scm)
G4int GetVerboseLevel() const
void SetVerboseLevel(G4int vl)
G4VScoreColorMap * GetScoreColorMap(const G4String &mapName)
void DumpAllQuantitiesToFile(const G4String &meshName, const G4String &fileName, const G4String &option="")
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
void SetCurrentMesh(G4VScoringMesh *scm)
void DrawMesh(const G4String &meshName, const G4String &psName, const G4String &colorMapName, G4int axflg=111)
void SetFactor(G4double val=1.0)
G4VScoringMesh * GetCurrentMesh() const
static G4ScoringManager * GetScoringManagerIfExist()
void DumpQuantityToFile(const G4String &meshName, const G4String &psName, const G4String &fileName, const G4String &option="")
void FillTokenVec(G4String newValues, G4TokenVec &token)
void MeshBinCommand(G4VScoringMesh *mesh, G4TokenVec &token)
G4String GetCurrentValue(G4UIcommand *command) override
G4ScoringMessenger(G4ScoringManager *SManager)
void Fill1D(G4UIcommand *cmd, G4String newValues)
void SetNewValue(G4UIcommand *command, G4String newValues) override
void SetDefaultUnit(const char *defUnit)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
static G4int GetNewIntValue(const char *paramString)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:362
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:446
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:137
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121
G4double StoD(const G4String &s)
G4bool StoB(G4String s)
G4int StoI(const G4String &s)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)
void SetDefaultUnit(const char *theDefaultUnit)
void SetMinMax(G4double minVal, G4double maxVal)
void SetFloatingMinMax(G4bool vl=true)
static G4VScoreHistFiller * Instance()
G4ThreeVector GetSize() const
MeshShape GetShape() const
void RotateY(G4double delta)
void SetAngles(G4double, G4double)
const G4String & GetWorldName() const
void SetNumberOfSegments(G4int nSegment[3])
void SetCenterPosition(G4double centerPosition[3])
void RotateX(G4double delta)
void SetSize(G4double size[3])
void RotateZ(G4double delta)