Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // Gorad (Geant4 Open-source Radiation Analys 27 // 28 // Author : Makoto Asai (SLAC National Accele 29 // 30 // Development of Gorad is funded by NASA Joh 31 // under the contract NNJ15HK11B. 32 // 33 // ******************************************* 34 // 35 // GRRunActionMessenger.cc 36 // A messenger class that defines histograms 37 // 38 // History 39 // September 8th, 2020 : first implementatio 40 // 41 // ******************************************* 42 43 #include "GRRunActionMessenger.hh" 44 45 #include "GRRunAction.hh" 46 #include "G4UIcommand.hh" 47 #include "G4UIparameter.hh" 48 #include "G4UIdirectory.hh" 49 #include "G4UIcmdWithAString.hh" 50 #include "G4UIcmdWithABool.hh" 51 #include "G4UIcmdWithAnInteger.hh" 52 #include "G4UIcmdWithoutParameter.hh" 53 #include "G4UnitsTable.hh" 54 55 GRRunActionMessenger::GRRunActionMessenger(GRR 56 : pRA(dc), currentID(-1) 57 { 58 G4UIparameter* para = nullptr; 59 60 anaDir = new G4UIdirectory("/gorad/analysis/ 61 anaDir->SetGuidance("GORAD analysis commands 62 63 verboseCmd = new G4UIcmdWithAnInteger("/gora 64 verboseCmd->SetGuidance("Set verbose level") 65 verboseCmd->SetParameterName("level",true); 66 verboseCmd->SetDefaultValue(0); 67 verboseCmd->SetRange("level>=0"); 68 verboseCmd->AvailableForStates(G4State_Idle) 69 70 fileCmd = new G4UIcmdWithAString("/gorad/ana 71 fileCmd->SetGuidance("Define the output file 72 fileCmd->SetParameterName("file",false); 73 fileCmd->AvailableForStates(G4State_Idle); 74 75 listCmd = new G4UIcmdWithoutParameter("/gora 76 listCmd->SetGuidance("List defined histogram 77 listCmd->AvailableForStates(G4State_Idle); 78 79 openCmd = new G4UIcmdWithAnInteger("/gorad/a 80 openCmd->SetGuidance("Open a histogram that 81 openCmd->SetGuidance("\"create\" command ope 82 openCmd->SetGuidance("A histogram is closed 83 openCmd->SetParameterName("id",false); 84 openCmd->AvailableForStates(G4State_Idle); 85 86 plotCmd = new G4UIcmdWithAnInteger("/gorad/a 87 plotCmd->SetGuidance("Create an additional p 88 plotCmd->SetGuidance("Regardless of this com 89 plotCmd->SetGuidance("If id is not specified 90 plotCmd->SetGuidance("If id = -1, all curren 91 plotCmd->SetParameterName("id",true,true); 92 plotCmd->AvailableForStates(G4State_Idle); 93 94 carryCmd = new G4UIcmdWithABool("/gorad/anal 95 carryCmd->SetGuidance("Carry histograms over 96 carryCmd->SetGuidance("Once this is set, his 97 carryCmd->SetGuidance("This command has to b 98 carryCmd->SetParameterName("carry",true); 99 carryCmd->SetDefaultValue(true); 100 carryCmd->AvailableForStates(G4State_Idle); 101 102 flushCmd = new G4UIcmdWithoutParameter("/gor 103 flushCmd->SetGuidance("Make output. This com 104 flushCmd->AvailableForStates(G4State_Idle); 105 106 resetCmd = new G4UIcmdWithoutParameter("/gor 107 resetCmd->SetGuidance("Reset histograms with 108 resetCmd->AvailableForStates(G4State_Idle); 109 110 idOffsetCmd = new G4UIcommand("/gorad/analys 111 idOffsetCmd->SetGuidance("Define offset numb 112 idOffsetCmd->SetGuidance(" The hostogram ID 113 para = new G4UIparameter("offset",'i',true); 114 para->SetParameterRange("offset>=0"); 115 para->SetDefaultValue(0); 116 idOffsetCmd->SetParameter(para); 117 para = new G4UIparameter("factor",'i',true); 118 para->SetParameterRange("factor>0"); 119 para->SetDefaultValue(1000); 120 idOffsetCmd->SetParameter(para); 121 idOffsetCmd->AvailableForStates(G4State_Idle 122 123 oneDDir = new G4UIdirectory("/gorad/analysis 124 oneDDir->SetGuidance("1-dimentional histogra 125 126 create1DCmd = new G4UIcommand("/gorad/analys 127 create1DCmd->SetGuidance("Create a 1D histog 128 create1DCmd->SetGuidance("Scoring mesh (logi 129 create1DCmd->SetGuidance("primitive scorers 130 para = new G4UIparameter("meshName",'s',fals 131 para->SetGuidance("Scoring mesh name. Logica 132 create1DCmd->SetParameter(para); 133 para = new G4UIparameter("primName",'s',fals 134 create1DCmd->SetParameter(para); 135 para = new G4UIparameter("idx",'i',true); 136 para->SetGuidance("Index (i.e. copy number) 137 para->SetDefaultValue(-1); 138 para->SetParameterRange("idx>=-1"); 139 create1DCmd->SetParameter(para); 140 create1DCmd->AvailableForStates(G4State_Idle 141 142 create1DPrimPCmd = new G4UIcommand("/gorad/a 143 create1DPrimPCmd->SetGuidance("Create a 1D e 144 create1DPrimPCmd->SetGuidance("Weight of eac 145 para = new G4UIparameter("histName",'s',fals 146 para->SetGuidance("Histogram name"); 147 create1DPrimPCmd->SetParameter(para); 148 para = new G4UIparameter("weightFlag",'b',tr 149 para->SetGuidance("Weight of each primary tr 150 para->SetDefaultValue(true); 151 create1DPrimPCmd->SetParameter(para); 152 create1DPrimPCmd->AvailableForStates(G4State 153 154 create1DPlotPCmd = new G4UIcommand("/gorad/a 155 create1DPlotPCmd->SetGuidance("Create a 1D e 156 create1DPlotPCmd->SetGuidance("Histogram is 157 create1DPlotPCmd->SetGuidance("So, this comm 158 create1DPlotPCmd->SetGuidance("Currently, th 159 para = new G4UIparameter("meshName",'s',fals 160 para->SetGuidance("Scoring mesh name. Logica 161 create1DPlotPCmd->SetParameter(para); 162 para = new G4UIparameter("primName",'s',fals 163 para->SetGuidance("Scoring primitive name.") 164 create1DPlotPCmd->SetParameter(para); 165 create1DPlotPCmd->AvailableForStates(G4State 166 167 set1DCmd = new G4UIcmdWithoutParameter("/gor 168 set1DCmd->SetGuidance("This command is obsol 169 170 config1DCmd = new G4UIcommand("/gorad/analys 171 config1DCmd->SetGuidance("Set binning parame 172 config1DCmd->SetGuidance("<unit> is applied 173 para = new G4UIparameter("nBin",'i',false); 174 para->SetParameterRange("nBin>0"); 175 config1DCmd->SetParameter(para); 176 para = new G4UIparameter("minVal",'d',false) 177 config1DCmd->SetParameter(para); 178 para = new G4UIparameter("maxVal",'d',false) 179 config1DCmd->SetParameter(para); 180 para = new G4UIparameter("unit",'s',true); 181 para->SetDefaultValue("none"); 182 config1DCmd->SetParameter(para); 183 para = new G4UIparameter("scale",'s',true); 184 para->SetGuidance("Define the binning scale. 185 para->SetParameterCandidates("linear log"); 186 para->SetDefaultValue("linear"); 187 config1DCmd->SetParameter(para); 188 para = new G4UIparameter("logVal",'b',true); 189 para->SetDefaultValue(false); 190 config1DCmd->SetParameter(para); 191 config1DCmd->AvailableForStates(G4State_Idle 192 193 title1DCmd = new G4UIcommand("/gorad/analysi 194 title1DCmd->SetGuidance("Define histogram ti 195 para = new G4UIparameter("title",'s',false); 196 title1DCmd->SetParameter(para); 197 para = new G4UIparameter("x_axis",'s',false) 198 title1DCmd->SetParameter(para); 199 para = new G4UIparameter("y_axis",'s',false) 200 title1DCmd->SetParameter(para); 201 title1DCmd->AvailableForStates(G4State_Idle) 202 203 set1DYaxisLogCmd = new G4UIcmdWithABool("/go 204 set1DYaxisLogCmd->SetGuidance("Set y-axis in 205 set1DYaxisLogCmd->SetParameterName("flag",tr 206 set1DYaxisLogCmd->SetDefaultValue(true); 207 set1DYaxisLogCmd->AvailableForStates(G4State 208 209 onePDir = new G4UIdirectory("/gorad/analysis 210 onePDir->SetGuidance("1-dimentional profile 211 212 create1PCmd = new G4UIcommand("/gorad/analys 213 create1PCmd->SetGuidance("Create a 1D profil 214 create1PCmd->SetGuidance("Scoring mesh (logi 215 create1PCmd->SetGuidance("primitive scorers 216 create1PCmd->SetGuidance("Copy number of the 217 para = new G4UIparameter("meshName",'s',fals 218 para->SetGuidance("Scoring mesh name. Logica 219 create1PCmd->SetParameter(para); 220 para = new G4UIparameter("primName",'s',fals 221 create1PCmd->SetParameter(para); 222 para = new G4UIparameter("idx",'i',false); 223 para->SetGuidance("Maximum index (i.e. copy 224 para->SetParameterRange("idx>0"); 225 create1PCmd->SetParameter(para); 226 create1PCmd->AvailableForStates(G4State_Idle 227 228 set1PCmd = new G4UIcommand("/gorad/analysis/ 229 set1PCmd->SetGuidance("Set binning parameter 230 set1PCmd->SetGuidance("<unit> is applied to 231 para = new G4UIparameter("minYVal",'d',false 232 set1PCmd->SetParameter(para); 233 para = new G4UIparameter("maxYVal",'d',false 234 set1PCmd->SetParameter(para); 235 para = new G4UIparameter("unit",'s',true); 236 para->SetDefaultValue("none"); 237 set1PCmd->SetParameter(para); 238 para = new G4UIparameter("func-x",'s',true); 239 para->SetGuidance("The function applied to t 240 para->SetParameterCandidates("log log10 exp 241 para->SetDefaultValue("none"); 242 set1PCmd->SetParameter(para); 243 para = new G4UIparameter("func-y",'s',true); 244 para->SetGuidance("The function applied to t 245 para->SetParameterCandidates("log log10 exp 246 para->SetDefaultValue("none"); 247 set1PCmd->SetParameter(para); 248 para = new G4UIparameter("scale",'s',true); 249 para->SetGuidance("Define the binning scale. 250 para->SetParameterCandidates("linear log"); 251 para->SetDefaultValue("linear"); 252 set1PCmd->SetParameter(para); 253 set1PCmd->AvailableForStates(G4State_Idle); 254 255 title1PCmd = new G4UIcommand("/gorad/analysi 256 title1PCmd->SetGuidance("Define histogram ti 257 para = new G4UIparameter("title",'s',false); 258 title1PCmd->SetParameter(para); 259 para = new G4UIparameter("x_axis",'s',false) 260 title1PCmd->SetParameter(para); 261 para = new G4UIparameter("y_axis",'s',false) 262 title1PCmd->SetParameter(para); 263 title1PCmd->AvailableForStates(G4State_Idle) 264 265 ntupleDir = new G4UIdirectory("/gorad/analys 266 onePDir->SetGuidance("Define an ntuple"); 267 268 addColumnCmd = new G4UIcommand("/gorad/analy 269 addColumnCmd->SetGuidance("Define a column a 270 addColumnCmd->SetGuidance("Scoring mesh (log 271 addColumnCmd->SetGuidance("primitive scorers 272 para = new G4UIparameter("meshName",'s',fals 273 para->SetGuidance("Scoring mesh name. Logica 274 addColumnCmd->SetParameter(para); 275 para = new G4UIparameter("primName",'s',fals 276 addColumnCmd->SetParameter(para); 277 para = new G4UIparameter("unit",'s',true); 278 para->SetDefaultValue("none"); 279 addColumnCmd->SetParameter(para); 280 para = new G4UIparameter("idx",'i',true); 281 para->SetGuidance("Index (i.e. copy number) 282 para->SetDefaultValue(-1); 283 para->SetParameterRange("idx>=-1"); 284 addColumnCmd->SetParameter(para); 285 addColumnCmd->AvailableForStates(G4State_Idl 286 } 287 288 GRRunActionMessenger::~GRRunActionMessenger() 289 { 290 delete addColumnCmd; 291 delete ntupleDir; 292 293 delete create1PCmd; 294 delete set1PCmd; 295 delete title1PCmd; 296 delete onePDir; 297 298 delete create1DCmd; 299 delete create1DPrimPCmd; 300 delete create1DPlotPCmd; 301 delete set1DCmd; 302 delete config1DCmd; 303 delete title1DCmd; 304 delete set1DYaxisLogCmd; 305 delete oneDDir; 306 307 delete fileCmd; 308 delete verboseCmd; 309 delete listCmd; 310 delete openCmd; 311 delete plotCmd; 312 delete carryCmd; 313 delete flushCmd; 314 delete resetCmd; 315 delete idOffsetCmd; 316 delete anaDir; 317 } 318 319 #include "G4Tokenizer.hh" 320 321 void GRRunActionMessenger::SetNewValue(G4UIcom 322 { 323 if(cmd==fileCmd) 324 { pRA->SetFileName(val); } 325 else if(cmd==verboseCmd) 326 { pRA->SetVerbose(verboseCmd->GetNewIntValue 327 else if(cmd==listCmd) 328 { pRA->ListHistograms(); } 329 else if(cmd==openCmd) 330 { 331 auto id = openCmd->GetNewIntValue(val); 332 if(currentID!=id) 333 { 334 if(!CheckOpenID(cmd)) return; 335 auto valid = pRA->Open(id); 336 if(!valid) 337 { 338 G4ExceptionDescription ed; 339 ed << "<" << id << "> is not a valid h 340 cmd->CommandFailed(ed); 341 } 342 else 343 { currentID = id; } 344 } 345 } 346 else if(cmd==plotCmd) 347 { 348 auto id = plotCmd->GetNewIntValue(val); 349 G4bool valid = true; 350 if(id==-1) 351 { valid = pRA->SetAllPlotting(true); } 352 else 353 { valid = pRA->SetPlotting(id,true); } 354 if(!valid) 355 { 356 G4ExceptionDescription ed; 357 ed << "Histogram/profile id <" << id << 358 cmd->CommandFailed(ed); 359 } 360 } 361 else if(cmd==carryCmd) 362 { pRA->SetCarry(carryCmd->GetNewBoolValue(va 363 else if(cmd==flushCmd) 364 { pRA->Flush(); } 365 else if(cmd==resetCmd) 366 { /*pRA->ResetHistograms();*/ } 367 else if(cmd==idOffsetCmd) 368 { 369 G4Tokenizer next(val); 370 G4int offset = StoI(next()); 371 G4int factor = StoI(next()); 372 pRA->SetOffset(offset,factor); 373 } 374 375 // 1D histogram commands 376 377 else if(cmd==create1DCmd) 378 { 379 if(!CheckOpenID(cmd)) return; 380 G4Tokenizer next(val); 381 G4String meshName = next(); 382 G4String primName = next(); 383 G4int idx = StoI(next()); 384 auto id = pRA->Create1D(meshName,primName, 385 if(id<0) 386 { 387 G4ExceptionDescription ed; 388 ed << "1D histogram <" << val << "> cann 389 cmd->CommandFailed(ed); 390 } 391 else 392 { currentID = id; } 393 } 394 else if(cmd==create1DPrimPCmd) 395 { 396 if(!CheckOpenID(cmd)) return; 397 G4Tokenizer next(val); 398 G4String meshName = next(); 399 G4bool wgt = StoB(next()); 400 auto id = pRA->Create1DForPrimary(meshName 401 if(id<0) 402 { 403 G4ExceptionDescription ed; 404 ed << "1D histogram <" << val << "> cann 405 cmd->CommandFailed(ed); 406 } 407 else 408 { currentID = id; } 409 } 410 else if(cmd==create1DPlotPCmd) 411 { 412 if(!CheckOpenID(cmd)) return; 413 G4Tokenizer next(val); 414 G4String meshName = next(); 415 G4String primName = next(); 416 G4bool wgt = true; 417 auto id = pRA->Create1DForPlotter(meshName 418 if(id<0) 419 { 420 G4ExceptionDescription ed; 421 ed << "1D histogram <" << val << "> cann 422 cmd->CommandFailed(ed); 423 } 424 else 425 { currentID = id; } 426 } 427 else if(cmd==set1DCmd) 428 { 429 G4ExceptionDescription ed; 430 ed << "This command is OBSOLETE. Use /gora 431 cmd->CommandFailed(ed); 432 } 433 else if(cmd==config1DCmd) 434 { 435 if(!CheckID(cmd)) return; 436 G4Tokenizer next(val); 437 G4int nBin = StoI(next()); 438 G4double minVal = StoD(next()); 439 G4double maxVal = StoD(next()); 440 G4String unit = next(); 441 G4String schem = next(); 442 G4bool logVal = StoB(next()); 443 if(unit!="none" && !(G4UnitDefinition::IsU 444 { 445 G4ExceptionDescription ed; 446 ed << "Unknown unit <" << unit << ">. Co 447 cmd->CommandFailed(ed); 448 } 449 else 450 { pRA->Set1D(currentID,nBin,minVal,maxVal, 451 } 452 else if(cmd==title1DCmd) 453 { 454 if(!CheckID(cmd)) return; 455 G4Tokenizer next(val); 456 G4String title = next(); 457 G4String x_axis = next(); 458 G4String y_axis = next(); 459 pRA->Set1DTitle(currentID,title,x_axis,y_a 460 } 461 else if(cmd==set1DYaxisLogCmd) 462 { 463 if(!CheckID(cmd)) return; 464 auto succ = pRA->Set1DYAxisLog(currentID,s 465 if(!succ) 466 { 467 G4ExceptionDescription ed; 468 ed << "This command is not available for 469 cmd->CommandFailed(ed); 470 } 471 } 472 473 // 1D profile commands 474 475 else if(cmd==create1PCmd) 476 { 477 if(!CheckOpenID(cmd)) return; 478 G4Tokenizer next(val); 479 G4String meshName = next(); 480 G4String primName = next(); 481 G4int cn = StoI(next()); 482 auto id = pRA->Create1P(meshName,primName, 483 if(id<0) 484 { 485 G4ExceptionDescription ed; 486 ed << "1D histogram <" << val << "> cann 487 cmd->CommandFailed(ed); 488 } 489 else 490 { currentID = id; } 491 } 492 else if(cmd==set1PCmd) 493 { 494 if(!CheckID(cmd)) return; 495 G4Tokenizer next(val); 496 G4double minYVal = StoD(next()); 497 G4double maxYVal = StoD(next()); 498 G4String unit = next(); 499 G4String funcX = next(); 500 G4String funcY = next(); 501 G4String schem = next(); 502 if(unit!="none" && !(G4UnitDefinition::IsU 503 { 504 G4ExceptionDescription ed; 505 ed << "Unknown unit <" << unit << ">. Co 506 cmd->CommandFailed(ed); 507 } 508 else 509 { pRA->Set1P(currentID,minYVal,maxYVal,uni 510 } 511 else if(cmd==title1PCmd) 512 { 513 if(!CheckID(cmd)) return; 514 G4Tokenizer next(val); 515 G4String title = next(); 516 G4String x_axis = next(); 517 G4String y_axis = next(); 518 pRA->Set1PTitle(currentID,title,x_axis,y_a 519 } 520 521 // ntuple commands 522 523 else if(cmd==addColumnCmd) 524 { 525 G4Tokenizer next(val); 526 G4String meshName = next(); 527 G4String primName = next(); 528 G4String unit = next(); 529 G4int idx = StoI(next()); 530 if(unit!="none" && !(G4UnitDefinition::IsU 531 { 532 G4ExceptionDescription ed; 533 ed << "Unknown unit <" << unit << ">. Co 534 cmd->CommandFailed(ed); 535 } 536 else 537 { 538 auto id = pRA->NtupleColumn(meshName,pri 539 if(id<0) 540 { 541 G4ExceptionDescription ed; 542 ed << "Ntuple column <" << val << "> c 543 cmd->CommandFailed(ed); 544 } 545 } 546 } 547 } 548 549 G4String GRRunActionMessenger::GetCurrentValue 550 { 551 G4String val(""); 552 if(cmd==openCmd) 553 { val = openCmd->ConvertToString(currentID); 554 if(cmd==fileCmd) 555 { val = pRA->GetFileName(); } 556 else if(cmd==verboseCmd) 557 { val = verboseCmd->ConvertToString(pRA->Get 558 else if(cmd==plotCmd) 559 { val = plotCmd->ConvertToString(currentID); 560 else if(cmd==carryCmd) 561 { val = carryCmd->ConvertToString(pRA->GetCa 562 else if(cmd==idOffsetCmd) 563 { 564 G4int offset = 0; 565 G4int factor = 0; 566 pRA->GetOffset(offset,factor); 567 val = idOffsetCmd->ConvertToString(offset) 568 val += " "; 569 val += idOffsetCmd->ConvertToString(factor 570 } 571 572 return val; 573 } 574 575 576