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