File indexing completed on 2026-09-18 08:31:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "HistoMessenger.hh"
0030
0031 #include "HistoManager.hh"
0032
0033 #include "G4UIcmdWithAString.hh"
0034 #include "G4UIcmdWithAnInteger.hh"
0035 #include "G4UIcommand.hh"
0036 #include "G4UIdirectory.hh"
0037 #include "G4UIparameter.hh"
0038
0039 #include <sstream>
0040
0041
0042
0043 HistoMessenger::HistoMessenger(HistoManager* manager)
0044 : G4UImessenger(),
0045 fHistoManager(manager),
0046 fHistoDir(0),
0047 fFileNameCmd(0),
0048 fHistoCmd(0),
0049 fPrtHistoCmd(0)
0050 {
0051 fHistoDir = new G4UIdirectory("/testem/histo/");
0052 fHistoDir->SetGuidance("histograms control");
0053
0054 fFileNameCmd = new G4UIcmdWithAString("/testem/histo/setFileName", this);
0055 fFileNameCmd->SetGuidance("set name for the histograms file");
0056
0057 fHistoCmd = new G4UIcommand("/testem/histo/setHisto", this);
0058 fHistoCmd->SetGuidance("Set bining of the histo number ih :");
0059 fHistoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
0060
0061 G4UIparameter* ih = new G4UIparameter("ih", 'i', false);
0062 ih->SetGuidance("histo number : from 1 to kMaxHisto");
0063 ih->SetParameterRange("ih>0");
0064 fHistoCmd->SetParameter(ih);
0065
0066 G4UIparameter* nbBins = new G4UIparameter("nbBins", 'i', false);
0067 nbBins->SetGuidance("number of bins");
0068 nbBins->SetParameterRange("nbBins>0");
0069 fHistoCmd->SetParameter(nbBins);
0070
0071 G4UIparameter* valMin = new G4UIparameter("valMin", 'd', false);
0072 valMin->SetGuidance("valMin, expressed in unit");
0073 fHistoCmd->SetParameter(valMin);
0074
0075 G4UIparameter* valMax = new G4UIparameter("valMax", 'd', false);
0076 valMax->SetGuidance("valMax, expressed in unit");
0077 fHistoCmd->SetParameter(valMax);
0078
0079 G4UIparameter* unit = new G4UIparameter("unit", 's', true);
0080 unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
0081 unit->SetDefaultValue("none");
0082 fHistoCmd->SetParameter(unit);
0083
0084 fPrtHistoCmd = new G4UIcmdWithAnInteger("/testem/histo/printHisto", this);
0085 fPrtHistoCmd->SetGuidance("print histo #id on ascii file");
0086 fPrtHistoCmd->SetParameterName("id", false);
0087 fPrtHistoCmd->SetRange("id>0");
0088 }
0089
0090
0091
0092 HistoMessenger::~HistoMessenger()
0093 {
0094 delete fPrtHistoCmd;
0095 delete fHistoCmd;
0096 delete fFileNameCmd;
0097 delete fHistoDir;
0098 }
0099
0100
0101
0102 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
0103 {
0104 if (command == fFileNameCmd) fHistoManager->SetFileName(newValues);
0105
0106 if (command == fHistoCmd) {
0107 G4int ih, nbBins;
0108 G4double vmin, vmax;
0109 G4String unit;
0110 const char* t = newValues;
0111 std::istringstream is(t);
0112 is >> ih >> nbBins >> vmin >> vmax >> unit;
0113 fHistoManager->SetHisto(ih, nbBins, vmin, vmax, unit);
0114 }
0115
0116 if (command == fPrtHistoCmd) fHistoManager->PrintHisto(fPrtHistoCmd->GetNewIntValue(newValues));
0117 }
0118
0119