00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "G4ScoreQuantityMessenger.hh"
00039 #include "G4ScoringManager.hh"
00040 #include "G4VScoringMesh.hh"
00041
00042 #include "G4PSCellCharge3D.hh"
00043 #include "G4PSCellFlux3D.hh"
00044 #include "G4PSCellFluxForCylinder3D.hh"
00045 #include "G4PSPassageCellFlux3D.hh"
00046 #include "G4PSPassageCellFluxForCylinder3D.hh"
00047 #include "G4PSEnergyDeposit3D.hh"
00048 #include "G4PSDoseDeposit3D.hh"
00049 #include "G4PSDoseDepositForCylinder3D.hh"
00050 #include "G4PSNofStep3D.hh"
00051 #include "G4PSNofSecondary3D.hh"
00052
00053 #include "G4PSTrackLength3D.hh"
00054 #include "G4PSPassageCellCurrent3D.hh"
00055 #include "G4PSPassageTrackLength3D.hh"
00056 #include "G4PSFlatSurfaceCurrent3D.hh"
00057 #include "G4PSFlatSurfaceFlux3D.hh"
00058 #include "G4PSSphereSurfaceCurrent3D.hh"
00059 #include "G4PSSphereSurfaceFlux3D.hh"
00060 #include "G4PSCylinderSurfaceCurrent3D.hh"
00061 #include "G4PSCylinderSurfaceFlux3D.hh"
00062 #include "G4PSNofCollision3D.hh"
00063 #include "G4PSPopulation3D.hh"
00064 #include "G4PSTrackCounter3D.hh"
00065 #include "G4PSTermination3D.hh"
00066 #include "G4PSMinKinEAtGeneration3D.hh"
00067
00068
00069 #include "G4PSStepChecker3D.hh"
00070
00071 #include "G4SDChargedFilter.hh"
00072 #include "G4SDNeutralFilter.hh"
00073 #include "G4SDKineticEnergyFilter.hh"
00074 #include "G4SDParticleFilter.hh"
00075 #include "G4SDParticleWithEnergyFilter.hh"
00076
00077 #include "G4UIdirectory.hh"
00078 #include "G4UIcmdWithoutParameter.hh"
00079 #include "G4UIcmdWithAnInteger.hh"
00080 #include "G4UIcmdWithAString.hh"
00081 #include "G4UIcmdWithABool.hh"
00082 #include "G4UIcmdWithADoubleAndUnit.hh"
00083 #include "G4UIcmdWith3VectorAndUnit.hh"
00084 #include "G4UIcommand.hh"
00085 #include "G4Tokenizer.hh"
00086 #include "G4UnitsTable.hh"
00087
00088 G4ScoreQuantityMessenger::G4ScoreQuantityMessenger(G4ScoringManager* SManager)
00089 :fSMan(SManager)
00090 {
00091 QuantityCommands();
00092 FilterCommands();
00093 }
00094
00095 void G4ScoreQuantityMessenger::FilterCommands()
00096 {
00097 G4UIparameter* param;
00098
00099
00100
00101 filterDir = new G4UIdirectory("/score/filter/");
00102 filterDir->SetGuidance(" Scoring filter commands.");
00103
00104 fchargedCmd = new G4UIcmdWithAString("/score/filter/charged",this);
00105 fchargedCmd->SetGuidance("Charged particle filter.");
00106 fchargedCmd->SetParameterName("fname",false);
00107
00108 fneutralCmd = new G4UIcmdWithAString("/score/filter/neutral",this);
00109 fneutralCmd->SetGuidance("Neutral particle filter.");
00110 fneutralCmd->SetParameterName("fname",false);
00111
00112 fkinECmd = new G4UIcommand("/score/filter/kineticEnergy",this);
00113 fkinECmd->SetGuidance("Kinetic energy filter.");
00114 fkinECmd->SetGuidance("[usage] /score/filter/kineticEnergy fname Elow Ehigh unit");
00115 fkinECmd->SetGuidance(" fname :(String) Filter Name ");
00116 fkinECmd->SetGuidance(" Elow :(Double) Lower edge of kinetic energy");
00117 fkinECmd->SetGuidance(" Ehigh :(Double) Higher edge of kinetic energy");
00118 fkinECmd->SetGuidance(" unit :(String) unit of given kinetic energy");
00119 param = new G4UIparameter("fname",'s',false);
00120 fkinECmd->SetParameter(param);
00121 param = new G4UIparameter("elow",'d',true);
00122 param->SetDefaultValue("0.0");
00123 fkinECmd->SetParameter(param);
00124 param = new G4UIparameter("ehigh",'d',false);
00125 fkinECmd->SetParameter(param);
00126 G4String smax = DtoS(DBL_MAX);
00127 param->SetDefaultValue(smax);
00128 param = new G4UIparameter("unit",'s',false);
00129 param->SetDefaultValue("keV");
00130 fkinECmd->SetParameter(param);
00131
00132 fparticleCmd = new G4UIcommand("/score/filter/particle",this);
00133 fparticleCmd->SetGuidance("Particle filter.");
00134 fparticleCmd->SetGuidance("[usage] /score/filter/particle fname p0 .. pn");
00135 fparticleCmd->SetGuidance(" fname :(String) Filter Name ");
00136 fparticleCmd->SetGuidance(" p0 .. pn :(String) particle names");
00137 param = new G4UIparameter("fname",'s',false);
00138 fparticleCmd->SetParameter(param);
00139 param = new G4UIparameter("particlelist",'s',false);
00140 param->SetDefaultValue("");
00141 fparticleCmd->SetParameter(param);
00142
00143
00144
00145 fparticleKinECmd = new G4UIcommand("/score/filter/particleWithKineticEnergy",this);
00146 fparticleKinECmd->SetGuidance("Particle with kinetic energy filter.");
00147 fparticleKinECmd->SetGuidance("[usage] /score/filter/particleWithKineticEnergy fname Elow Ehigh unit p0 .. pn");
00148 fparticleKinECmd->SetGuidance(" fname :(String) Filter Name ");
00149 fparticleKinECmd->SetGuidance(" Elow :(Double) Lower edge of kinetic energy");
00150 fparticleKinECmd->SetGuidance(" Ehigh :(Double) Higher edge of kinetic energy");
00151 fparticleKinECmd->SetGuidance(" unit :(String) unit of given kinetic energy");
00152 fparticleKinECmd->SetGuidance(" p0 .. pn :(String) particle names");
00153 param = new G4UIparameter("fname",'s',false);
00154 fparticleKinECmd->SetParameter(param);
00155 param = new G4UIparameter("elow",'d',false);
00156 param->SetDefaultValue("0.0");
00157 fparticleKinECmd->SetParameter(param);
00158 param = new G4UIparameter("ehigh",'d',true);
00159 param->SetDefaultValue(smax);
00160 fparticleKinECmd->SetParameter(param);
00161 param = new G4UIparameter("unit",'s',true);
00162 param->SetDefaultValue("keV");
00163 fparticleKinECmd->SetParameter(param);
00164 param = new G4UIparameter("particlelist",'s',false);
00165 param->SetDefaultValue("");
00166 fparticleKinECmd->SetParameter(param);
00167
00168
00169 }
00170
00171 G4ScoreQuantityMessenger::~G4ScoreQuantityMessenger()
00172 {
00173 delete quantityDir;
00174 delete qTouchCmd;
00175 delete qGetUnitCmd;
00176 delete qSetUnitCmd;
00177
00178
00179 delete qCellChgCmd;
00180 delete qCellFluxCmd;
00181 delete qPassCellFluxCmd;
00182 delete qeDepCmd;
00183 delete qdoseDepCmd;
00184 delete qnOfStepCmd;
00185 delete qnOfSecondaryCmd;
00186
00187 delete qTrackLengthCmd;
00188 delete qPassCellCurrCmd;
00189 delete qPassTrackLengthCmd;
00190 delete qFlatSurfCurrCmd;
00191 delete qFlatSurfFluxCmd;
00192
00193
00194
00195
00196 delete qNofCollisionCmd;
00197 delete qPopulationCmd;
00198 delete qTrackCountCmd;
00199 delete qTerminationCmd;
00200 delete qMinKinEAtGeneCmd;
00201
00202 delete qStepCheckerCmd;
00203
00204 delete filterDir;
00205 delete fchargedCmd;
00206 delete fneutralCmd;
00207 delete fkinECmd;
00208 delete fparticleCmd;
00209 delete fparticleKinECmd;
00210 }
00211
00212 void G4ScoreQuantityMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
00213 {
00214
00215
00216
00217 G4VScoringMesh* mesh = fSMan->GetCurrentMesh();
00218 if(!mesh)
00219 {
00220 G4cerr << "ERROR : No mesh is currently open. Open/create a mesh first. Command ignored." << G4endl;
00221 return;
00222 }
00223
00224 G4TokenVec token;
00225 FillTokenVec(newVal,token);
00226
00227
00228 if(command==qTouchCmd) {
00229 mesh->SetCurrentPrimitiveScorer(newVal);
00230 } else if(command == qGetUnitCmd ){
00231 G4cout << "Unit: "<< mesh->GetCurrentPSUnit() <<G4endl;
00232 } else if(command == qSetUnitCmd ){
00233 mesh->SetCurrentPSUnit(newVal);
00234 } else if(command== qCellChgCmd) {
00235 if ( CheckMeshPS(mesh,token[0]) ){
00236 G4PSCellCharge3D* ps = new G4PSCellCharge3D(token[0]);
00237 ps->SetUnit(token[1]);
00238 mesh->SetPrimitiveScorer(ps);
00239 }
00240 } else if(command== qCellFluxCmd) {
00241 if ( CheckMeshPS(mesh,token[0]) ){
00242 if( mesh->GetShape()==boxMesh ) {
00243 G4PSCellFlux3D* ps = new G4PSCellFlux3D(token[0]);
00244 ps->SetUnit(token[1]);
00245 mesh->SetPrimitiveScorer(ps);
00246 } else if( mesh->GetShape()==cylinderMesh ) {
00247 G4PSCellFluxForCylinder3D* ps =
00248 new G4PSCellFluxForCylinder3D(token[0]);
00249 ps->SetUnit(token[1]);
00250 G4ThreeVector msize = mesh->GetSize();
00251 ps->SetCylinderSize(msize[0],msize[1]);
00252 G4int nSeg[3];
00253 mesh->GetNumberOfSegments(nSeg);
00254 ps->SetNumberOfSegments(nSeg);
00255 mesh->SetPrimitiveScorer(ps);
00256 }
00257 }
00258 } else if(command== qPassCellFluxCmd) {
00259 if ( CheckMeshPS(mesh,token[0]) ){
00260 if( mesh->GetShape()==boxMesh ) {
00261 G4PSPassageCellFlux3D* ps = new G4PSPassageCellFlux3D(token[0]);
00262 ps->SetUnit(token[1]);
00263 mesh->SetPrimitiveScorer(ps);
00264 } else if( mesh->GetShape()==cylinderMesh ) {
00265 G4PSPassageCellFluxForCylinder3D* ps =
00266 new G4PSPassageCellFluxForCylinder3D(token[0]);
00267 ps->SetUnit(token[1]);
00268 G4ThreeVector msize = mesh->GetSize();
00269 ps->SetCylinderSize(msize[0],msize[1]);
00270 G4int nSeg[3];
00271 mesh->GetNumberOfSegments(nSeg);
00272 ps->SetNumberOfSegments(nSeg);
00273 mesh->SetPrimitiveScorer(ps);
00274 }
00275 }
00276 } else if(command==qeDepCmd) {
00277 if ( CheckMeshPS(mesh,token[0]) ){
00278 G4PSEnergyDeposit3D* ps =new G4PSEnergyDeposit3D(token[0]);
00279 ps->SetUnit(token[1]);
00280 mesh->SetPrimitiveScorer(ps);
00281 }
00282 } else if(command== qdoseDepCmd) {
00283 if ( CheckMeshPS(mesh,token[0]) ){
00284 if( mesh->GetShape()==boxMesh ) {
00285 G4PSDoseDeposit3D* ps = new G4PSDoseDeposit3D(token[0]);
00286 ps->SetUnit(token[1]);
00287 mesh->SetPrimitiveScorer(ps);
00288 } else if( mesh->GetShape()==cylinderMesh ) {
00289 G4PSDoseDepositForCylinder3D* ps =
00290 new G4PSDoseDepositForCylinder3D(token[0]);
00291 ps->SetUnit(token[1]);
00292 G4ThreeVector msize = mesh->GetSize();
00293 ps->SetCylinderSize(msize[0],msize[1]);
00294 G4int nSeg[3];
00295 mesh->GetNumberOfSegments(nSeg);
00296 ps->SetNumberOfSegments(nSeg);
00297 mesh->SetPrimitiveScorer(ps);
00298 }
00299 }
00300 } else if(command== qnOfStepCmd) {
00301 if ( CheckMeshPS(mesh,token[0]) ){
00302 G4PSNofStep3D* ps = new G4PSNofStep3D(token[0]);
00303 mesh->SetPrimitiveScorer(ps);
00304 }
00305 } else if(command== qnOfSecondaryCmd) {
00306 if ( CheckMeshPS(mesh,token[0]) ){
00307 G4PSNofSecondary3D* ps =new G4PSNofSecondary3D(token[0]);
00308 mesh->SetPrimitiveScorer(ps);
00309 }
00310 } else if(command== qTrackLengthCmd) {
00311 if ( CheckMeshPS(mesh,token[0]) ){
00312 G4PSTrackLength3D* ps = new G4PSTrackLength3D(token[0]);
00313 ps->Weighted(StoB(token[1]));
00314 ps->MultiplyKineticEnergy(StoB(token[2]));
00315 ps->DivideByVelocity(StoB(token[3]));
00316 ps->SetUnit(token[4]);
00317 mesh->SetPrimitiveScorer(ps);
00318 }
00319 } else if(command== qPassCellCurrCmd){
00320 if( CheckMeshPS(mesh,token[0]) ) {
00321 G4PSPassageCellCurrent* ps = new G4PSPassageCellCurrent3D(token[0]);
00322 ps->Weighted(StoB(token[1]));
00323
00324 mesh->SetPrimitiveScorer(ps);
00325 }
00326 } else if(command== qPassTrackLengthCmd){
00327 if( CheckMeshPS(mesh,token[0]) ) {
00328 G4PSPassageTrackLength* ps = new G4PSPassageTrackLength3D(token[0]);
00329 ps->Weighted(StoB(token[1]));
00330 mesh->SetPrimitiveScorer(ps);
00331 }
00332 } else if(command== qFlatSurfCurrCmd){
00333 if( CheckMeshPS(mesh,token[0])) {
00334 G4PSFlatSurfaceCurrent3D* ps =
00335 new G4PSFlatSurfaceCurrent3D(token[0],StoI(token[1]));
00336 ps->Weighted(StoB(token[2]));
00337 ps->DivideByArea(StoB(token[3]));
00338 if ( StoB(token[3]) ){
00339 ps->SetUnit(token[4]);
00340 }else{
00341 ps->SetUnit("");
00342 }
00343 mesh->SetPrimitiveScorer(ps);
00344 }
00345 } else if(command== qFlatSurfFluxCmd){
00346 if( CheckMeshPS(mesh, token[0] )) {
00347 G4PSFlatSurfaceFlux3D* ps = new G4PSFlatSurfaceFlux3D(token[0],StoI(token[1]));
00348 ps->Weighted(StoB(token[2]));
00349 ps->DivideByArea(StoB(token[3]));
00350 if ( StoB(token[3]) ){
00351 ps->SetUnit(token[4]);
00352 }else{
00353 ps->SetUnit("");
00354 }
00355 mesh->SetPrimitiveScorer(ps);
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 } else if(command== qNofCollisionCmd){
00409 if( CheckMeshPS(mesh,token[0])) {
00410 G4PSNofCollision3D* ps =new G4PSNofCollision3D(token[0]);
00411 ps->Weighted(StoB(token[1]));
00412 mesh->SetPrimitiveScorer(ps);
00413 }
00414 } else if(command== qPopulationCmd){
00415 if( CheckMeshPS(mesh,token[0]) ) {
00416 G4PSPopulation3D* ps =new G4PSPopulation3D(token[0]);
00417 ps->Weighted(StoB(token[1]));
00418 mesh->SetPrimitiveScorer(ps);
00419 }
00420 } else if(command== qTrackCountCmd){
00421 if( CheckMeshPS(mesh,token[0])) {
00422 G4PSTrackCounter3D* ps =new G4PSTrackCounter3D(token[0],StoI(token[1]));
00423 mesh->SetPrimitiveScorer(ps);
00424 }
00425 } else if(command== qTerminationCmd){
00426 if( CheckMeshPS(mesh,token[0])) {
00427 G4PSTermination3D* ps =new G4PSTermination3D(token[0]);
00428 ps->Weighted(StoB(token[1]));
00429 mesh->SetPrimitiveScorer(ps);
00430 }
00431
00432 } else if(command== qMinKinEAtGeneCmd){
00433 if( CheckMeshPS(mesh,token[0]) ){
00434 G4PSMinKinEAtGeneration3D* ps =new G4PSMinKinEAtGeneration3D(token[0]);
00435 ps->SetUnit(token[1]);
00436 mesh->SetPrimitiveScorer(ps);
00437 }
00438 } else if(command== qStepCheckerCmd){
00439 if( CheckMeshPS(mesh,token[0]) ){
00440 G4PSStepChecker3D* ps =new G4PSStepChecker3D(token[0]);
00441 mesh->SetPrimitiveScorer(ps);
00442 }
00443
00444
00445
00446
00447 }else if(command== fchargedCmd){
00448 if(!mesh->IsCurrentPrimitiveScorerNull()) {
00449 mesh->SetFilter(new G4SDChargedFilter(token[0]));
00450 } else {
00451 G4cout << "WARNING[" << fchargedCmd->GetCommandPath()
00452 << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
00453 }
00454 }else if(command== fneutralCmd){
00455 if(!mesh->IsCurrentPrimitiveScorerNull()) {
00456 mesh->SetFilter(new G4SDNeutralFilter(token[0]));
00457 } else {
00458 G4cout << "WARNING[" << fneutralCmd->GetCommandPath()
00459 << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
00460 }
00461 }else if(command== fkinECmd){
00462 if(!mesh->IsCurrentPrimitiveScorerNull()) {
00463 G4String& name = token[0];
00464 G4double elow = StoD(token[1]);
00465 G4double ehigh = StoD(token[2]);
00466 mesh->SetFilter(new G4SDKineticEnergyFilter(name,elow,ehigh));
00467 } else {
00468 G4cout << "WARNING[" << fkinECmd->GetCommandPath()
00469 << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
00470 }
00471 }else if(command== fparticleKinECmd){
00472 if(!mesh->IsCurrentPrimitiveScorerNull()) {
00473 FParticleWithEnergyCommand(mesh,token);
00474 } else {
00475 G4cout << "WARNING[" << fparticleKinECmd->GetCommandPath()
00476 << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
00477 }
00478 } else if(command==fparticleCmd) {
00479 if(!mesh->IsCurrentPrimitiveScorerNull()) {
00480 FParticleCommand(mesh,token);
00481 } else {
00482 G4cout << "WARNING[" << fparticleCmd->GetCommandPath()
00483 << "] : Current quantity is not set. Set or touch a quantity first." << G4endl;
00484 }
00485 }
00486 }
00487
00488 G4String G4ScoreQuantityMessenger::GetCurrentValue(G4UIcommand * )
00489 {
00490 G4String val;
00491
00492 return val;
00493 }
00494
00495 void G4ScoreQuantityMessenger::FillTokenVec(G4String newValues, G4TokenVec& token){
00496
00497 G4Tokenizer next(newValues);
00498 G4String val;
00499 while ( !(val = next()).isNull() ) {
00500 token.push_back(val);
00501 }
00502 }
00503
00504
00505 void G4ScoreQuantityMessenger::FParticleCommand(G4VScoringMesh* mesh, G4TokenVec& token){
00506
00507
00508 G4String name = token[0];
00509
00510
00511 std::vector<G4String> pnames;
00512 for ( G4int i = 1; i<(G4int)token.size(); i++){
00513 pnames.push_back(token[i]);
00514 }
00515
00516
00517 mesh->SetFilter(new G4SDParticleFilter(name,pnames));
00518 }
00519
00520 void G4ScoreQuantityMessenger::FParticleWithEnergyCommand(G4VScoringMesh* mesh,G4TokenVec& token){
00521 G4String& name = token[0];
00522 G4double elow = StoD(token[1]);
00523 G4double ehigh= StoD(token[2]);
00524 G4double unitVal = G4UnitDefinition::GetValueOf(token[3]);
00525 G4SDParticleWithEnergyFilter* filter =
00526 new G4SDParticleWithEnergyFilter(name,elow*unitVal,ehigh*unitVal);
00527 for ( G4int i = 4; i < (G4int)token.size(); i++){
00528 filter->add(token[i]);
00529 }
00530 mesh->SetFilter(filter);
00531 }
00532
00533 G4bool G4ScoreQuantityMessenger::CheckMeshPS(G4VScoringMesh* mesh, G4String& psname){
00534 if(!mesh->FindPrimitiveScorer(psname)) {
00535 return true;
00536 } else {
00537 G4cout << "WARNING[" << qTouchCmd->GetCommandPath()
00538 << "] : Quantity name, \"" << psname << "\", is already existing." << G4endl;
00539 mesh->SetNullToCurrentPrimitiveScorer();
00540 return false;
00541 }
00542 }