Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ScoreQuantityMessenger.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 // $Id$
28 //
29 // ---------------------------------------------------------------------
30 // Modifications
31 // 08-Oct-2010 T.Aso remove unit of G4PSPassageCellCurrent.
32 // 24-Mar-2011 T.Aso Add StepChecker for debugging.
33 // 24-Mar-2011 T.Aso Size and segmentation for replicated cylinder.
34 // 01-Jun-2012 T.Aso Support weighted/dividedByArea options
35 // in flatCurrent and flatFulx commands.
36 // ---------------------------------------------------------------------
37 
39 #include "G4ScoringManager.hh"
40 #include "G4VScoringMesh.hh"
41 
42 #include "G4PSCellCharge3D.hh"
43 #include "G4PSCellFlux3D.hh"
45 #include "G4PSPassageCellFlux3D.hh"
47 #include "G4PSEnergyDeposit3D.hh"
48 #include "G4PSDoseDeposit3D.hh"
50 #include "G4PSNofStep3D.hh"
51 #include "G4PSNofSecondary3D.hh"
52 //
53 #include "G4PSTrackLength3D.hh"
57 #include "G4PSFlatSurfaceFlux3D.hh"
62 #include "G4PSNofCollision3D.hh"
63 #include "G4PSPopulation3D.hh"
64 #include "G4PSTrackCounter3D.hh"
65 #include "G4PSTermination3D.hh"
67 //
68 // For debug purpose
69 #include "G4PSStepChecker3D.hh"
70 
71 #include "G4SDChargedFilter.hh"
72 #include "G4SDNeutralFilter.hh"
74 #include "G4SDParticleFilter.hh"
76 
77 #include "G4UIdirectory.hh"
79 #include "G4UIcmdWithAnInteger.hh"
80 #include "G4UIcmdWithAString.hh"
81 #include "G4UIcmdWithABool.hh"
84 #include "G4UIcommand.hh"
85 #include "G4Tokenizer.hh"
86 #include "G4UnitsTable.hh"
87 
89 :fSMan(SManager)
90 {
91  QuantityCommands();
92  FilterCommands();
93 }
94 
95 void G4ScoreQuantityMessenger::FilterCommands()
96 {
97  G4UIparameter* param;
98 
99  //
100  // Filter commands
101  filterDir = new G4UIdirectory("/score/filter/");
102  filterDir->SetGuidance(" Scoring filter commands.");
103  //
104  fchargedCmd = new G4UIcmdWithAString("/score/filter/charged",this);
105  fchargedCmd->SetGuidance("Charged particle filter.");
106  fchargedCmd->SetParameterName("fname",false);
107  //
108  fneutralCmd = new G4UIcmdWithAString("/score/filter/neutral",this);
109  fneutralCmd->SetGuidance("Neutral particle filter.");
110  fneutralCmd->SetParameterName("fname",false);
111  //
112  fkinECmd = new G4UIcommand("/score/filter/kineticEnergy",this);
113  fkinECmd->SetGuidance("Kinetic energy filter.");
114  fkinECmd->SetGuidance("[usage] /score/filter/kineticEnergy fname Elow Ehigh unit");
115  fkinECmd->SetGuidance(" fname :(String) Filter Name ");
116  fkinECmd->SetGuidance(" Elow :(Double) Lower edge of kinetic energy");
117  fkinECmd->SetGuidance(" Ehigh :(Double) Higher edge of kinetic energy");
118  fkinECmd->SetGuidance(" unit :(String) unit of given kinetic energy");
119  param = new G4UIparameter("fname",'s',false);
120  fkinECmd->SetParameter(param);
121  param = new G4UIparameter("elow",'d',true);
122  param->SetDefaultValue("0.0");
123  fkinECmd->SetParameter(param);
124  param = new G4UIparameter("ehigh",'d',false);
125  fkinECmd->SetParameter(param);
127  param->SetDefaultValue(smax);
128  param = new G4UIparameter("unit",'s',false);
129  param->SetDefaultValue("keV");
130  fkinECmd->SetParameter(param);
131  //
132  fparticleCmd = new G4UIcommand("/score/filter/particle",this);
133  fparticleCmd->SetGuidance("Particle filter.");
134  fparticleCmd->SetGuidance("[usage] /score/filter/particle fname p0 .. pn");
135  fparticleCmd->SetGuidance(" fname :(String) Filter Name ");
136  fparticleCmd->SetGuidance(" p0 .. pn :(String) particle names");
137  param = new G4UIparameter("fname",'s',false);
138  fparticleCmd->SetParameter(param);
139  param = new G4UIparameter("particlelist",'s',false);
140  param->SetDefaultValue("");
141  fparticleCmd->SetParameter(param);
142  //
143  //
144  //
145  fparticleKinECmd = new G4UIcommand("/score/filter/particleWithKineticEnergy",this);
146  fparticleKinECmd->SetGuidance("Particle with kinetic energy filter.");
147  fparticleKinECmd->SetGuidance("[usage] /score/filter/particleWithKineticEnergy fname Elow Ehigh unit p0 .. pn");
148  fparticleKinECmd->SetGuidance(" fname :(String) Filter Name ");
149  fparticleKinECmd->SetGuidance(" Elow :(Double) Lower edge of kinetic energy");
150  fparticleKinECmd->SetGuidance(" Ehigh :(Double) Higher edge of kinetic energy");
151  fparticleKinECmd->SetGuidance(" unit :(String) unit of given kinetic energy");
152  fparticleKinECmd->SetGuidance(" p0 .. pn :(String) particle names");
153  param = new G4UIparameter("fname",'s',false);
154  fparticleKinECmd->SetParameter(param);
155  param = new G4UIparameter("elow",'d',false);
156  param->SetDefaultValue("0.0");
157  fparticleKinECmd->SetParameter(param);
158  param = new G4UIparameter("ehigh",'d',true);
159  param->SetDefaultValue(smax);
160  fparticleKinECmd->SetParameter(param);
161  param = new G4UIparameter("unit",'s',true);
162  param->SetDefaultValue("keV");
163  fparticleKinECmd->SetParameter(param);
164  param = new G4UIparameter("particlelist",'s',false);
165  param->SetDefaultValue("");
166  fparticleKinECmd->SetParameter(param);
167  //
168  //
169 }
170 
172 {
173  delete quantityDir;
174  delete qTouchCmd;
175  delete qGetUnitCmd;
176  delete qSetUnitCmd;
177 
178  //
179  delete qCellChgCmd;
180  delete qCellFluxCmd;
181  delete qPassCellFluxCmd;
182  delete qeDepCmd;
183  delete qdoseDepCmd;
184  delete qnOfStepCmd;
185  delete qnOfSecondaryCmd;
186  //
187  delete qTrackLengthCmd;
188  delete qPassCellCurrCmd;
189  delete qPassTrackLengthCmd;
190  delete qFlatSurfCurrCmd;
191  delete qFlatSurfFluxCmd;
192 // delete qSphereSurfCurrCmd;
193 // delete qSphereSurfFluxCmd;
194 // delete qCylSurfCurrCmd;
195 // delete qCylSurfFluxCmd;
196  delete qNofCollisionCmd;
197  delete qPopulationCmd;
198  delete qTrackCountCmd;
199  delete qTerminationCmd;
200  delete qMinKinEAtGeneCmd;
201  //
202  delete qStepCheckerCmd;
203  //
204  delete filterDir;
205  delete fchargedCmd;
206  delete fneutralCmd;
207  delete fkinECmd;
208  delete fparticleCmd;
209  delete fparticleKinECmd;
210 }
211 
213 {
214  //
215  // Get Current Mesh
216  //
217  G4VScoringMesh* mesh = fSMan->GetCurrentMesh();
218  if(!mesh)
219  {
220  G4cerr << "ERROR : No mesh is currently open. Open/create a mesh first. Command ignored." << G4endl;
221  return;
222  }
223  // Tokens
224  G4TokenVec token;
225  FillTokenVec(newVal,token);
226  //
227  // Commands for Current Mesh
228  if(command==qTouchCmd) {
229  mesh->SetCurrentPrimitiveScorer(newVal);
230  } else if(command == qGetUnitCmd ){
231  G4cout << "Unit: "<< mesh->GetCurrentPSUnit() <<G4endl;
232  } else if(command == qSetUnitCmd ){
233  mesh->SetCurrentPSUnit(newVal);
234  } else if(command== qCellChgCmd) {
235  if ( CheckMeshPS(mesh,token[0]) ){
236  G4PSCellCharge3D* ps = new G4PSCellCharge3D(token[0]);
237  ps->SetUnit(token[1]);
238  mesh->SetPrimitiveScorer(ps);
239  }
240  } else if(command== qCellFluxCmd) {
241  if ( CheckMeshPS(mesh,token[0]) ){
242  if( mesh->GetShape()==boxMesh ) {
243  G4PSCellFlux3D* ps = new G4PSCellFlux3D(token[0]);
244  ps->SetUnit(token[1]);
245  mesh->SetPrimitiveScorer(ps);
246  } else if( mesh->GetShape()==cylinderMesh ) {
248  new G4PSCellFluxForCylinder3D(token[0]);
249  ps->SetUnit(token[1]);
250  G4ThreeVector msize = mesh->GetSize(); // gevin in R Z N/A
251  ps->SetCylinderSize(msize[0],msize[1]); // given in dr dz
252  G4int nSeg[3];
253  mesh->GetNumberOfSegments(nSeg);
254  ps->SetNumberOfSegments(nSeg);
255  mesh->SetPrimitiveScorer(ps);
256  }
257  }
258  } else if(command== qPassCellFluxCmd) {
259  if ( CheckMeshPS(mesh,token[0]) ){
260  if( mesh->GetShape()==boxMesh ) {
261  G4PSPassageCellFlux3D* ps = new G4PSPassageCellFlux3D(token[0]);
262  ps->SetUnit(token[1]);
263  mesh->SetPrimitiveScorer(ps);
264  } else if( mesh->GetShape()==cylinderMesh ) {
266  new G4PSPassageCellFluxForCylinder3D(token[0]);
267  ps->SetUnit(token[1]);
268  G4ThreeVector msize = mesh->GetSize(); // gevin in R Z N/A
269  ps->SetCylinderSize(msize[0],msize[1]); // given in dr dz
270  G4int nSeg[3];
271  mesh->GetNumberOfSegments(nSeg);
272  ps->SetNumberOfSegments(nSeg);
273  mesh->SetPrimitiveScorer(ps);
274  }
275  }
276  } else if(command==qeDepCmd) {
277  if ( CheckMeshPS(mesh,token[0]) ){
278  G4PSEnergyDeposit3D* ps =new G4PSEnergyDeposit3D(token[0]);
279  ps->SetUnit(token[1]);
280  mesh->SetPrimitiveScorer(ps);
281  }
282  } else if(command== qdoseDepCmd) {
283  if ( CheckMeshPS(mesh,token[0]) ){
284  if( mesh->GetShape()==boxMesh ) {
285  G4PSDoseDeposit3D* ps = new G4PSDoseDeposit3D(token[0]);
286  ps->SetUnit(token[1]);
287  mesh->SetPrimitiveScorer(ps);
288  } else if( mesh->GetShape()==cylinderMesh ) {
290  new G4PSDoseDepositForCylinder3D(token[0]);
291  ps->SetUnit(token[1]);
292  G4ThreeVector msize = mesh->GetSize(); // gevin in R Z N/A
293  ps->SetCylinderSize(msize[0],msize[1]); // given in dr dz
294  G4int nSeg[3];
295  mesh->GetNumberOfSegments(nSeg);
296  ps->SetNumberOfSegments(nSeg);
297  mesh->SetPrimitiveScorer(ps);
298  }
299  }
300  } else if(command== qnOfStepCmd) {
301  if ( CheckMeshPS(mesh,token[0]) ){
302  G4PSNofStep3D* ps = new G4PSNofStep3D(token[0]);
303  mesh->SetPrimitiveScorer(ps);
304  }
305  } else if(command== qnOfSecondaryCmd) {
306  if ( CheckMeshPS(mesh,token[0]) ){
307  G4PSNofSecondary3D* ps =new G4PSNofSecondary3D(token[0]);
308  mesh->SetPrimitiveScorer(ps);
309  }
310  } else if(command== qTrackLengthCmd) {
311  if ( CheckMeshPS(mesh,token[0]) ){
312  G4PSTrackLength3D* ps = new G4PSTrackLength3D(token[0]);
313  ps->Weighted(StoB(token[1]));
314  ps->MultiplyKineticEnergy(StoB(token[2]));
315  ps->DivideByVelocity(StoB(token[3]));
316  ps->SetUnit(token[4]);
317  mesh->SetPrimitiveScorer(ps);
318  }
319  } else if(command== qPassCellCurrCmd){
320  if( CheckMeshPS(mesh,token[0]) ) {
322  ps->Weighted(StoB(token[1]));
323  //ps->SetUnit(token[2]);
324  mesh->SetPrimitiveScorer(ps);
325  }
326  } else if(command== qPassTrackLengthCmd){
327  if( CheckMeshPS(mesh,token[0]) ) {
329  ps->Weighted(StoB(token[1]));
330  mesh->SetPrimitiveScorer(ps);
331  }
332  } else if(command== qFlatSurfCurrCmd){
333  if( CheckMeshPS(mesh,token[0])) {
335  new G4PSFlatSurfaceCurrent3D(token[0],StoI(token[1]));
336  ps->Weighted(StoB(token[2]));
337  ps->DivideByArea(StoB(token[3]));
338  if ( StoB(token[3]) ){
339  ps->SetUnit(token[4]);
340  }else{
341  ps->SetUnit("");
342  }
343  mesh->SetPrimitiveScorer(ps);
344  }
345  } else if(command== qFlatSurfFluxCmd){
346  if( CheckMeshPS(mesh, token[0] )) {
347  G4PSFlatSurfaceFlux3D* ps = new G4PSFlatSurfaceFlux3D(token[0],StoI(token[1]));
348  ps->Weighted(StoB(token[2]));
349  ps->DivideByArea(StoB(token[3]));
350  if ( StoB(token[3]) ){
351  ps->SetUnit(token[4]);
352  }else{
353  ps->SetUnit("");
354  }
355  mesh->SetPrimitiveScorer(ps);
356  }
357 // } else if(command== qSphereSurfCurrCmd){
358 // if( CheckMeshPS(mesh, token[0] )) {
359 // G4PSSphereSurfaceCurrent3D* ps =
360 // new G4PSSphereSurfaceCurrent3D(token[0],StoI(token[1]));
361 // ps->Weighted(StoB(token[2]));
362 // ps->DivideByArea(StoB(token[3]));
363 // if ( StoB(token[3]) ){
364 // ps->SetUnit(token[4]);
365 // }else{
366 // ps->SetUnit("");
367 // }
368 // mesh->SetPrimitiveScorer(ps);
369 // }
370 // } else if(command== qSphereSurfFluxCmd){
371 // if( CheckMeshPS(mesh,token[0])) {
372 // G4PSSphereSurfaceFlux3D* ps = new G4PSSphereSurfaceFlux3D(token[0], StoI(token[1]));
373 // ps->Weighted(StoB(token[2]));
374 // ps->DivideByArea(StoB(token[3]));
375 // if ( StoB(token[3]) ){
376 // ps->SetUnit(token[4]);
377 // }else{
378 // ps->SetUnit("");
379 // }
380 // mesh->SetPrimitiveScorer(ps);
381 // }
382 // } else if(command== qCylSurfCurrCmd){
383 // if( CheckMeshPS(mesh, token[0] ) ) {
384 // G4PSCylinderSurfaceCurrent3D* ps =
385 // new G4PSCylinderSurfaceCurrent3D(token[0],StoI(token[1]));
386 // ps->Weighted(StoB(token[2]));
387 // ps->DivideByArea(StoB(token[3]));
388 // if ( StoB(token[3]) ){
389 // ps->SetUnit(token[4]);
390 // }else{
391 // ps->SetUnit("");
392 // }
393 // ps->SetUnit(token[4]);
394 // mesh->SetPrimitiveScorer(ps);
395 // }
396 // } else if(command== qCylSurfFluxCmd){
397 // if( CheckMeshPS(mesh, token[0] ) {
398 // G4PSCylinerSurfaceFlux3D* ps =new G4PSCylinderSurfaceFlux3D(token[0], StoI(token[1]));
399 // ps->Weighted(StoB(token[2]));
400 // ps->DivideByArea(StoB(token[3]));
401 // if ( StoB(token[3]) ){
402 // ps->SetUnit(token[4]);
403 // }else{
404 // ps->SetUnit("");
405 // }
406 // mesh->SetPrimitiveScorer(ps);
407 // }
408  } else if(command== qNofCollisionCmd){
409  if( CheckMeshPS(mesh,token[0])) {
410  G4PSNofCollision3D* ps =new G4PSNofCollision3D(token[0]);
411  ps->Weighted(StoB(token[1]));
412  mesh->SetPrimitiveScorer(ps);
413  }
414  } else if(command== qPopulationCmd){
415  if( CheckMeshPS(mesh,token[0]) ) {
416  G4PSPopulation3D* ps =new G4PSPopulation3D(token[0]);
417  ps->Weighted(StoB(token[1]));
418  mesh->SetPrimitiveScorer(ps);
419  }
420  } else if(command== qTrackCountCmd){
421  if( CheckMeshPS(mesh,token[0])) {
422  G4PSTrackCounter3D* ps =new G4PSTrackCounter3D(token[0],StoI(token[1]));
423  mesh->SetPrimitiveScorer(ps);
424  }
425  } else if(command== qTerminationCmd){
426  if( CheckMeshPS(mesh,token[0])) {
427  G4PSTermination3D* ps =new G4PSTermination3D(token[0]);
428  ps->Weighted(StoB(token[1]));
429  mesh->SetPrimitiveScorer(ps);
430  }
431 
432  } else if(command== qMinKinEAtGeneCmd){
433  if( CheckMeshPS(mesh,token[0]) ){
435  ps->SetUnit(token[1]);
436  mesh->SetPrimitiveScorer(ps);
437  }
438  } else if(command== qStepCheckerCmd){
439  if( CheckMeshPS(mesh,token[0]) ){
440  G4PSStepChecker3D* ps =new G4PSStepChecker3D(token[0]);
441  mesh->SetPrimitiveScorer(ps);
442  }
443 
444  //
445  // Filters
446  //
447  }else if(command== fchargedCmd){
448  if(!mesh->IsCurrentPrimitiveScorerNull()) {
449  mesh->SetFilter(new G4SDChargedFilter(token[0]));
450  } else {
451  G4cout << "WARNING[" << fchargedCmd->GetCommandPath()
452  << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
453  }
454  }else if(command== fneutralCmd){
455  if(!mesh->IsCurrentPrimitiveScorerNull()) {
456  mesh->SetFilter(new G4SDNeutralFilter(token[0]));
457  } else {
458  G4cout << "WARNING[" << fneutralCmd->GetCommandPath()
459  << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
460  }
461  }else if(command== fkinECmd){
462  if(!mesh->IsCurrentPrimitiveScorerNull()) {
463  G4String& name = token[0];
464  G4double elow = StoD(token[1]);
465  G4double ehigh = StoD(token[2]);
466  mesh->SetFilter(new G4SDKineticEnergyFilter(name,elow,ehigh));
467  } else {
468  G4cout << "WARNING[" << fkinECmd->GetCommandPath()
469  << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
470  }
471  }else if(command== fparticleKinECmd){
472  if(!mesh->IsCurrentPrimitiveScorerNull()) {
473  FParticleWithEnergyCommand(mesh,token);
474  } else {
475  G4cout << "WARNING[" << fparticleKinECmd->GetCommandPath()
476  << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
477  }
478  } else if(command==fparticleCmd) {
479  if(!mesh->IsCurrentPrimitiveScorerNull()) {
480  FParticleCommand(mesh,token);
481  } else {
482  G4cout << "WARNING[" << fparticleCmd->GetCommandPath()
483  << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
484  }
485  }
486 }
487 
489 {
490  G4String val;
491 
492  return val;
493 }
494 
496 
497  G4Tokenizer next(newValues);
498  G4String val;
499  while ( !(val = next()).isNull() ) {
500  token.push_back(val);
501  }
502 }
503 
504 
506  //
507  // Filter name
508  G4String name = token[0];
509  //
510  // particle list
511  std::vector<G4String> pnames;
512  for ( G4int i = 1; i<(G4int)token.size(); i++){
513  pnames.push_back(token[i]);
514  }
515  //
516  // Attach Filter
517  mesh->SetFilter(new G4SDParticleFilter(name,pnames));
518 }
519 
521  G4String& name = token[0];
522  G4double elow = StoD(token[1]);
523  G4double ehigh= StoD(token[2]);
524  G4double unitVal = G4UnitDefinition::GetValueOf(token[3]);
526  new G4SDParticleWithEnergyFilter(name,elow*unitVal,ehigh*unitVal);
527  for ( G4int i = 4; i < (G4int)token.size(); i++){
528  filter->add(token[i]);
529  }
530  mesh->SetFilter(filter);
531 }
532 
534  if(!mesh->FindPrimitiveScorer(psname)) {
535  return true;
536  } else {
537  G4cout << "WARNING[" << qTouchCmd->GetCommandPath()
538  << "] : Quantity name, \"" << psname << "\", is already existing." << G4endl;
540  return false;
541  }
542 }