File indexing completed on 2025-02-23 09:21:06
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
0030
0031
0032
0033 #include "HistoMessenger.hh"
0034
0035 #include "Histo.hh"
0036
0037 #include "G4UIcmdWithAString.hh"
0038 #include "G4UIcommand.hh"
0039 #include "G4UIdirectory.hh"
0040 #include "G4UIparameter.hh"
0041
0042 #include <sstream>
0043
0044
0045
0046 HistoMessenger::HistoMessenger(Histo* hist)
0047 : G4UImessenger(), fHisto(hist), fHistoDir(0), fFactoryCmd(0), fFileCmd(0), fHistoCmd(0)
0048 {
0049 fHistoDir = new G4UIdirectory("/testem/histo/");
0050 fHistoDir->SetGuidance("histograms control");
0051
0052 fFactoryCmd = new G4UIcmdWithAString("/testem/histo/fileName", this);
0053 fFactoryCmd->SetGuidance("set name for the histograms file");
0054
0055 fFileCmd = new G4UIcmdWithAString("/testem/histo/fileType", this);
0056 fFileCmd->SetGuidance("set type (hbook, XML) for the histograms file");
0057
0058 fHistoCmd = new G4UIcommand("/testem/histo/setHisto", this);
0059 fHistoCmd->SetGuidance("Set bining of the histo number ih :");
0060 fHistoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
0061
0062 G4UIparameter* ih = new G4UIparameter("ih", 'i', false);
0063 ih->SetGuidance("histo number : from 0 to MaxHisto-1");
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
0085
0086
0087 HistoMessenger::~HistoMessenger()
0088 {
0089 delete fFileCmd;
0090 delete fHistoCmd;
0091 delete fFactoryCmd;
0092 delete fHistoDir;
0093 }
0094
0095
0096
0097 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
0098 {
0099 if (command == fFactoryCmd) {
0100 fHisto->SetFileName(newValues);
0101 }
0102
0103 if (command == fFileCmd) {
0104 fHisto->SetFileType(newValues);
0105 }
0106
0107 if (command == fHistoCmd) {
0108 G4int ih, nbBins;
0109 G4double vmin, vmax;
0110 std::istringstream is(newValues);
0111 G4String unts;
0112 is >> ih >> nbBins >> vmin >> vmax >> unts;
0113 G4String unit = unts;
0114 G4double vUnit = 1.;
0115 if (unit != "none") {
0116 vUnit = G4UIcommand::ValueOf(unit);
0117 }
0118 if (vUnit <= 0.0) {
0119 vUnit = 1.;
0120 }
0121 fHisto->SetHisto1D(ih, nbBins, vmin, vmax, vUnit);
0122 }
0123 }
0124
0125