File indexing completed on 2026-09-19 08:37:23
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 "Histo.hh"
0032
0033 #include "G4UIcmdWithAString.hh"
0034 #include "G4UIcommand.hh"
0035 #include "G4UIdirectory.hh"
0036 #include "G4UIparameter.hh"
0037
0038 #include <sstream>
0039
0040
0041
0042 HistoMessenger::HistoMessenger(Histo* hist)
0043 : G4UImessenger(), fHisto(hist), fHistoDir(0), fFactoryCmd(0), fFileCmd(0), fHistoCmd(0)
0044 {
0045 fHistoDir = new G4UIdirectory("/testem/histo/");
0046 fHistoDir->SetGuidance("histograms control");
0047
0048 fFactoryCmd = new G4UIcmdWithAString("/testem/histo/fileName", this);
0049 fFactoryCmd->SetGuidance("set name for the histograms file");
0050
0051 fFileCmd = new G4UIcmdWithAString("/testem/histo/fileType", this);
0052 fFileCmd->SetGuidance("set type (hbook, XML) for the histograms file");
0053
0054 fHistoCmd = new G4UIcommand("/testem/histo/setHisto", this);
0055 fHistoCmd->SetGuidance("Set bining of the histo number ih :");
0056 fHistoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
0057
0058 G4UIparameter* ih = new G4UIparameter("ih", 'i', false);
0059 ih->SetGuidance("histo number : from 0 to MaxHisto-1");
0060 fHistoCmd->SetParameter(ih);
0061
0062 G4UIparameter* nbBins = new G4UIparameter("nbBins", 'i', false);
0063 nbBins->SetGuidance("number of bins");
0064 nbBins->SetParameterRange("nbBins>0");
0065 fHistoCmd->SetParameter(nbBins);
0066
0067 G4UIparameter* valMin = new G4UIparameter("valMin", 'd', false);
0068 valMin->SetGuidance("valMin, expressed in unit");
0069 fHistoCmd->SetParameter(valMin);
0070
0071 G4UIparameter* valMax = new G4UIparameter("valMax", 'd', false);
0072 valMax->SetGuidance("valMax, expressed in unit");
0073 fHistoCmd->SetParameter(valMax);
0074
0075 G4UIparameter* unit = new G4UIparameter("unit", 's', true);
0076 unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
0077 unit->SetDefaultValue("none");
0078 fHistoCmd->SetParameter(unit);
0079 }
0080
0081
0082
0083 HistoMessenger::~HistoMessenger()
0084 {
0085 delete fFileCmd;
0086 delete fHistoCmd;
0087 delete fFactoryCmd;
0088 delete fHistoDir;
0089 }
0090
0091
0092
0093 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
0094 {
0095 if (command == fFactoryCmd) {
0096 fHisto->SetFileName(newValues);
0097 }
0098
0099 if (command == fFileCmd) {
0100 fHisto->SetFileType(newValues);
0101 }
0102
0103 if (command == fHistoCmd) {
0104 G4int ih, nbBins;
0105 G4double vmin, vmax;
0106 std::istringstream is(newValues);
0107 G4String unts;
0108 is >> ih >> nbBins >> vmin >> vmax >> unts;
0109 G4String unit = unts;
0110 G4double vUnit = 1.;
0111 if (unit != "none") {
0112 vUnit = G4UIcommand::ValueOf(unit);
0113 }
0114 if (vUnit <= 0.0) {
0115 vUnit = 1.;
0116 }
0117 fHisto->SetHisto1D(ih, nbBins, vmin, vmax, vUnit);
0118 }
0119 }
0120
0121