Geant4-11
G4H1Messenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// Author: Ivana Hrivnacova, 24/06/2013 (ivana@ipno.in2p3.fr)
28//
29// This messenger class is a generalization of the HistoMessenger class,
30// originally developed for the extended/electromagnetic examples
31// by Michel Maire (michel.maire@lapp.in2p3.fr)
32
33#include "G4H1Messenger.hh"
34#include "G4VAnalysisManager.hh"
37
38#include "G4UIdirectory.hh"
39#include "G4UIcommand.hh"
40#include "G4UIparameter.hh"
41#include "G4Tokenizer.hh"
42
43#include <vector>
44
45using namespace G4Analysis;
46
47//_____________________________________________________________________________
49 : G4UImessenger(),
50 fManager(manager)
51{
52 fHelper = std::make_unique<G4AnalysisMessengerHelper>("h1");
53
54 fDirectory = fHelper->CreateHnDirectory();
55
57
58 SetH1Cmd();
59 fSetH1XCmd = fHelper->CreateSetBinsCommand("x", this);
60
61
62 fSetH1TitleCmd = fHelper->CreateSetTitleCommand(this);
63 fSetH1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
64 fSetH1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
65 fSetH1XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
66 fSetH1YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
67}
68
69//_____________________________________________________________________________
71
72//
73// private functions
74//
75
76//_____________________________________________________________________________
78{
79 auto h1Name = new G4UIparameter("name", 's', false);
80 h1Name->SetGuidance("Histogram name (label)");
81
82 auto h1Title = new G4UIparameter("title", 's', false);
83 h1Title->SetGuidance("Histogram title");
84
85 auto h1Nbins0 = new G4UIparameter("nbins0", 'i', true);
86 h1Nbins0->SetGuidance("Number of bins (default = 100)");
87 h1Nbins0->SetGuidance("Can be reset with /analysis/h1/set command");
88 h1Nbins0->SetDefaultValue(100);
89
90 auto h1ValMin0 = new G4UIparameter("valMin0", 'd', true);
91 h1ValMin0->SetGuidance("Minimum value, expressed in unit (default = 0.)");
92 h1ValMin0->SetGuidance("Can be reset with /analysis/h1/set command");
93 h1ValMin0->SetDefaultValue(0.);
94
95 auto h1ValMax0 = new G4UIparameter("valMax0", 'd', true);
96 h1ValMax0->SetGuidance("Maximum value, expressed in unit (default = 1.)");
97 h1ValMax0->SetGuidance("Can be reset with /analysis/h1/set command");
98 h1ValMax0->SetDefaultValue(1.);
99
100 auto h1ValUnit0 = new G4UIparameter("valUnit0", 's', true);
101 h1ValUnit0->SetGuidance("The unit applied to filled values and valMin0, valMax0");
102 h1ValUnit0->SetDefaultValue("none");
103
104 auto h1ValFcn0 = new G4UIparameter("valFcn0", 's', true);
105 G4String fcnGuidance = "The function applied to filled values (log, log10, exp).\n";
106 fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
107 fcnGuidance += "but none value should be used instead.";
108 h1ValFcn0->SetGuidance(fcnGuidance);
109 h1ValFcn0->SetParameterCandidates("log log10 exp none");
110 h1ValFcn0->SetDefaultValue("none");
111
112 auto h1ValBinScheme0 = new G4UIparameter("valBinScheme0", 's', true);
113 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
114 h1ValBinScheme0->SetParameterCandidates("linear log");
115 binSchemeGuidance
116 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
117 binSchemeGuidance += "but none value should be used instead.";
118 h1ValBinScheme0->SetGuidance(binSchemeGuidance);
119 h1ValBinScheme0->SetDefaultValue("linear");
120
121 fCreateH1Cmd = std::make_unique<G4UIcommand>("/analysis/h1/create", this);
122 fCreateH1Cmd->SetGuidance("Create 1D histogram");
123 fCreateH1Cmd->SetParameter(h1Name);
124 fCreateH1Cmd->SetParameter(h1Title);
125 fCreateH1Cmd->SetParameter(h1Nbins0);
126 fCreateH1Cmd->SetParameter(h1ValMin0);
127 fCreateH1Cmd->SetParameter(h1ValMax0);
128 fCreateH1Cmd->SetParameter(h1ValUnit0);
129 fCreateH1Cmd->SetParameter(h1ValFcn0);
130 fCreateH1Cmd->SetParameter(h1ValBinScheme0);
131 fCreateH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
132}
133
134
135//_____________________________________________________________________________
137{
138 auto h1Id = new G4UIparameter("id", 'i', false);
139 h1Id->SetGuidance("Histogram id");
140 h1Id->SetParameterRange("id>=0");
141
142 auto h1Nbins = new G4UIparameter("nbins", 'i', false);
143 h1Nbins->SetGuidance("Number of bins");
144
145 auto h1ValMin = new G4UIparameter("valMin", 'd', false);
146 h1ValMin->SetGuidance("Minimum value, expressed in unit");
147
148 auto h1ValMax = new G4UIparameter("valMax", 'd', false);
149 h1ValMax->SetGuidance("Maximum value, expressed in unit");
150
151 auto h1ValUnit = new G4UIparameter("valUnit", 's', true);
152 h1ValUnit->SetGuidance("The unit applied to filled values and valMin, valMax");
153 h1ValUnit->SetDefaultValue("none");
154
155 auto h1ValFcn = new G4UIparameter("valFcn", 's', true);
156 h1ValFcn->SetParameterCandidates("log log10 exp none");
157 G4String fcnGuidance = "The function applied to filled values (log, log10, exp, none).\n";
158 fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
159 fcnGuidance += "but none value should be used instead.";
160 h1ValFcn->SetGuidance(fcnGuidance);
161 h1ValFcn->SetDefaultValue("none");
162
163 auto h1ValBinScheme = new G4UIparameter("valBinScheme", 's', true);
164 h1ValBinScheme->SetParameterCandidates("linear log");
165 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
166 binSchemeGuidance
167 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
168 binSchemeGuidance += "but none value should be used instead.";
169 h1ValBinScheme->SetGuidance(binSchemeGuidance);
170 h1ValBinScheme->SetDefaultValue("linear");
171
172 fSetH1Cmd = std::make_unique<G4UIcommand>("/analysis/h1/set", this);
173 fSetH1Cmd->SetGuidance("Set parameters for the 1D histogram of given id:");
174 fSetH1Cmd->SetGuidance(" nbins; valMin; valMax; unit; function; binScheme");
175 fSetH1Cmd->SetParameter(h1Id);
176 fSetH1Cmd->SetParameter(h1Nbins);
177 fSetH1Cmd->SetParameter(h1ValMin);
178 fSetH1Cmd->SetParameter(h1ValMax);
179 fSetH1Cmd->SetParameter(h1ValUnit);
180 fSetH1Cmd->SetParameter(h1ValFcn);
181 fSetH1Cmd->SetParameter(h1ValBinScheme);
182 fSetH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
183}
184
185//
186// public functions
187//
188
189//_____________________________________________________________________________
191{
192 // tokenize parameters in a vector
193 std::vector<G4String> parameters;
194 G4Analysis::Tokenize(newValues, parameters);
195 // check consistency
196 if ( parameters.size() != command->GetParameterEntries() ) {
197 // Should never happen but let's check anyway for consistency
198 fHelper->WarnAboutParameters(command, parameters.size());
199 return;
200 }
201
202 if ( command == fCreateH1Cmd.get() ) {
203 auto counter = 0;
204 auto name = parameters[counter++];
205 auto title = parameters[counter++];
207 fHelper->GetBinData(xdata, parameters, counter);
208 auto unit = GetUnitValue(xdata.fSunit);
209 fManager->CreateH1(name, title,
210 xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
211 xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
212 }
213 else if ( command == fSetH1Cmd.get() ) {
214 auto counter = 0;
215 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
217 fHelper->GetBinData(xdata, parameters, counter);
218 auto unit = GetUnitValue(xdata.fSunit);
219 fManager->SetH1(id,
220 xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
221 xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
222 }
223 else if ( command == fSetH1XCmd.get() ) {
224 auto counter = 0;
225 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
227 fHelper->GetBinData(xdata, parameters, counter);
228 auto unit = GetUnitValue(xdata.fSunit);
229 fManager->SetH1(id,
230 xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
231 xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
232 }
233 else if ( command == fSetH1TitleCmd.get() ) {
234 auto counter = 0;
235 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
236 auto title = parameters[counter++];
237 fManager->SetH1Title(id, title);
238 }
239 else if ( command == fSetH1XAxisCmd.get() ) {
240 auto counter = 0;
241 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
242 auto xaxis = parameters[counter++];
243 fManager->SetH1XAxisTitle(id, xaxis);
244 }
245 else if ( command == fSetH1YAxisCmd.get() ) {
246 auto counter = 0;
247 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
248 auto yaxis = parameters[counter++];
249 fManager->SetH1YAxisTitle(id, yaxis);
250 }
251 else if ( command == fSetH1XAxisLogCmd.get() ) {
252 auto counter = 0;
253 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
254 auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
255 fManager->SetH1XAxisIsLog(id, xaxisLog);
256 }
257 else if ( command == fSetH1YAxisLogCmd.get() ) {
258 auto counter = 0;
259 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
260 auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
261 fManager->SetH1YAxisIsLog(id, yaxisLog);
262 }
263}
@ G4State_Idle
@ G4State_PreInit
std::unique_ptr< G4UIcommand > fCreateH1Cmd
std::unique_ptr< G4UIdirectory > fDirectory
std::unique_ptr< G4UIcommand > fSetH1Cmd
std::unique_ptr< G4UIcommand > fSetH1TitleCmd
std::unique_ptr< G4UIcommand > fSetH1YAxisCmd
std::unique_ptr< G4UIcommand > fSetH1YAxisLogCmd
virtual ~G4H1Messenger()
void CreateH1Cmd()
G4VAnalysisManager * fManager
Associated class.
std::unique_ptr< G4AnalysisMessengerHelper > fHelper
G4H1Messenger()=delete
std::unique_ptr< G4UIcommand > fSetH1XCmd
std::unique_ptr< G4UIcommand > fSetH1XAxisLogCmd
std::unique_ptr< G4UIcommand > fSetH1XAxisCmd
virtual void SetNewValue(G4UIcommand *command, G4String value) final
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:557
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:545
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4bool SetH1YAxisIsLog(G4int id, G4bool isLog)
G4bool SetH1Title(G4int id, const G4String &title)
G4bool SetH1XAxisTitle(G4int id, const G4String &title)
G4bool SetH1XAxisIsLog(G4int id, G4bool isLog)
G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4double GetUnitValue(const G4String &unit)
const char * name(G4int ptype)