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