Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4H2Messenger.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, 18/06/2013 (ivana@ipno.in2p3.fr)
28
29#include "G4H2Messenger.hh"
30#include "G4VAnalysisManager.hh"
31
32#include "G4UIdirectory.hh"
33#include "G4UIcommand.hh"
34#include "G4UIparameter.hh"
35
36using namespace G4Analysis;
37
38//_____________________________________________________________________________
40 : G4UImessenger(),
41 fManager(manager)
42{
43 fHelper = std::make_unique<G4AnalysisMessengerHelper>("h2");
44
45 fDirectory = fHelper->CreateHnDirectory();
46
48
49 SetH2Cmd();
50 fSetH2XCmd = fHelper->CreateSetBinsCommand("x", this);
51 fSetH2YCmd = fHelper->CreateSetBinsCommand("y", this);
52
53 fSetH2TitleCmd = fHelper->CreateSetTitleCommand(this);
54 fSetH2XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
55 fSetH2YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
56 fSetH2ZAxisCmd = fHelper->CreateSetAxisCommand("z", this);
57 fSetH2XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
58 fSetH2YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
59 fSetH2ZAxisLogCmd = fHelper->CreateSetAxisLogCommand("z", this);
60}
61
62//_____________________________________________________________________________
64
65//
66// private functions
67//
68
69//_____________________________________________________________________________
71{
72 auto h2Name = new G4UIparameter("name", 's', false);
73 h2Name->SetGuidance("Histogram name (label)");
74
75 auto h2Title = new G4UIparameter("title", 's', false);
76 h2Title->SetGuidance("Histogram title");
77
78 auto h2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
79 h2xNbins0->SetGuidance("Number of x-bins (default = 100)");
80 h2xNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
81 h2xNbins0->SetDefaultValue(100);
82
83 auto h2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
84 h2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
85 h2xValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
86 h2xValMin0->SetDefaultValue(0.);
87
88 auto h2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
89 h2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
90 h2xValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
91 h2xValMax0->SetDefaultValue(1.);
92
93 auto h2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
94 h2xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
95 h2xValUnit0->SetDefaultValue("none");
96
97 auto h2xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
98 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
99 h2xValFcn0->SetGuidance(fcnxGuidance);
100 h2xValFcn0->SetParameterCandidates("log log10 exp none");
101 h2xValFcn0->SetDefaultValue("none");
102
103 auto h2xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
104 G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
105 h2xValBinScheme0->SetParameterCandidates("linear log");
106 h2xValBinScheme0->SetGuidance(xbinSchemeGuidance);
107 h2xValBinScheme0->SetDefaultValue("linear");
108
109 auto h2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
110 h2yNbins0->SetGuidance("Number of y-bins (default = 100)");
111 h2yNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
112 h2yNbins0->SetDefaultValue(100);
113
114 auto h2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
115 h2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
116 h2yValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
117 h2yValMin0->SetDefaultValue(0.);
118
119 auto h2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
120 h2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
121 h2yValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
122 h2yValMax0->SetDefaultValue(1.);
123
124 auto h2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
125 h2yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
126 h2yValUnit0->SetDefaultValue("none");
127
128 auto h2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
129 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
130 h2yValFcn0->SetGuidance(fcnyGuidance);
131 h2yValFcn0->SetParameterCandidates("log log10 exp none");
132 h2yValFcn0->SetDefaultValue("none");
133
134 auto h2yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
135 G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
136 h2yValBinScheme0->SetParameterCandidates("linear log");
137 h2yValBinScheme0->SetGuidance(ybinSchemeGuidance);
138 h2yValBinScheme0->SetDefaultValue("linear");
139
140 fCreateH2Cmd = std::make_unique<G4UIcommand>("/analysis/h2/create", this);
141 fCreateH2Cmd->SetGuidance("Create 2D histogram");
142 fCreateH2Cmd->SetParameter(h2Name);
143 fCreateH2Cmd->SetParameter(h2Title);
144 fCreateH2Cmd->SetParameter(h2xNbins0);
145 fCreateH2Cmd->SetParameter(h2xValMin0);
146 fCreateH2Cmd->SetParameter(h2xValMax0);
147 fCreateH2Cmd->SetParameter(h2xValUnit0);
148 fCreateH2Cmd->SetParameter(h2xValFcn0);
149 fCreateH2Cmd->SetParameter(h2xValBinScheme0);
150 fCreateH2Cmd->SetParameter(h2yNbins0);
151 fCreateH2Cmd->SetParameter(h2yValMin0);
152 fCreateH2Cmd->SetParameter(h2yValMax0);
153 fCreateH2Cmd->SetParameter(h2yValUnit0);
154 fCreateH2Cmd->SetParameter(h2yValFcn0);
155 fCreateH2Cmd->SetParameter(h2yValBinScheme0);
156 fCreateH2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
157}
158
159
160//_____________________________________________________________________________
162{
163 auto h2Id = new G4UIparameter("id", 'i', false);
164 h2Id->SetGuidance("Histogram id");
165 h2Id->SetParameterRange("id>=0");
166
167 auto h2xNbins = new G4UIparameter("xnbins", 'i', false);
168 h2xNbins->SetGuidance("Number of x-bins");
169
170 auto h2xValMin = new G4UIparameter("xvalMin", 'd', false);
171 h2xValMin->SetGuidance("Minimum x-value, expressed in unit");
172
173 auto h2xValMax = new G4UIparameter("xvalMax", 'd', false);
174 h2xValMax->SetGuidance("Maximum x-value, expressed in unit");
175
176 auto h2xValUnit = new G4UIparameter("xvalUnit", 's', false);
177 h2xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin, xvalMax");
178 h2xValUnit->SetDefaultValue("none");
179
180 auto h2xValFcn = new G4UIparameter("xvalFcn", 's', false);
181 h2xValFcn->SetParameterCandidates("log log10 exp none");
182 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
183 h2xValFcn->SetGuidance(fcnxGuidance);
184 h2xValFcn->SetDefaultValue("none");
185
186 auto h2xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
187 G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
188 h2xValBinScheme->SetParameterCandidates("linear log");
189 h2xValBinScheme->SetGuidance(xbinSchemeGuidance);
190 h2xValBinScheme->SetDefaultValue("linear");
191
192 auto h2yNbins = new G4UIparameter("nybins", 'i', false);
193 h2yNbins->SetGuidance("Number of y-bins");
194
195 auto h2yValMin = new G4UIparameter("yvalMin", 'd', false);
196 h2yValMin->SetGuidance("Minimum y-value, expressed in unit");
197
198 auto h2yValMax = new G4UIparameter("yvalMax", 'd', false);
199 h2yValMax->SetGuidance("Maximum y-value, expressed in unit");
200
201 auto h2yValUnit = new G4UIparameter("yvalUnit", 's', true);
202 h2yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin, yvalMax");
203 h2yValUnit->SetDefaultValue("none");
204
205 auto h2yValFcn = new G4UIparameter("yvalFcn", 's', false);
206 h2yValFcn->SetParameterCandidates("log log10 exp none");
207 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
208 h2yValFcn->SetGuidance(fcnyGuidance);
209 h2yValFcn->SetDefaultValue("none");
210
211 auto h2yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
212 G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
213 h2yValBinScheme->SetParameterCandidates("linear log");
214 h2yValBinScheme->SetGuidance(ybinSchemeGuidance);
215 h2yValBinScheme->SetDefaultValue("linear");
216
217 fSetH2Cmd = std::make_unique<G4UIcommand>("/analysis/h2/set", this);
218 fSetH2Cmd->SetGuidance("Set parameters for the 2D histogram of given id:");
219 fSetH2Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
220 fSetH2Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; yfunction; ybinScheme");
221 fSetH2Cmd->SetParameter(h2Id);
222 fSetH2Cmd->SetParameter(h2xNbins);
223 fSetH2Cmd->SetParameter(h2xValMin);
224 fSetH2Cmd->SetParameter(h2xValMax);
225 fSetH2Cmd->SetParameter(h2xValUnit);
226 fSetH2Cmd->SetParameter(h2xValFcn);
227 fSetH2Cmd->SetParameter(h2xValBinScheme);
228 fSetH2Cmd->SetParameter(h2yNbins);
229 fSetH2Cmd->SetParameter(h2yValMin);
230 fSetH2Cmd->SetParameter(h2yValMax);
231 fSetH2Cmd->SetParameter(h2yValUnit);
232 fSetH2Cmd->SetParameter(h2yValFcn);
233 fSetH2Cmd->SetParameter(h2yValBinScheme);
234 fSetH2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
235}
236
237
238//
239// public functions
240//
241
242//_____________________________________________________________________________
244{
245 // tokenize parameters in a vector
246 std::vector<G4String> parameters;
247 G4Analysis::Tokenize(newValues, parameters);
248 // check consistency
249 if ( parameters.size() != command->GetParameterEntries() ) {
250 // Should never happen but let's check anyway for consistency
251 fHelper->WarnAboutParameters(command, parameters.size());
252 return;
253 }
254
255 if ( command == fCreateH2Cmd.get() ) {
256 auto counter = 0;
257 auto name = parameters[counter++];
258 auto title = parameters[counter++];
260 fHelper->GetBinData(xdata, parameters, counter);
261 auto xunit = GetUnitValue(xdata.fSunit);
263 fHelper->GetBinData(ydata, parameters, counter);
264 auto yunit = GetUnitValue(ydata.fSunit);
265 fManager->CreateH2(name, title,
266 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
267 ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
268 xdata.fSunit, ydata.fSunit,
269 xdata.fSfcn, ydata.fSfcn,
270 xdata.fSbinScheme, ydata.fSbinScheme);
271 }
272 else if ( command == fSetH2Cmd.get() ) {
273 auto counter = 0;
274 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
276 fHelper->GetBinData(xdata, parameters, counter);
277 auto xunit = GetUnitValue(xdata.fSunit);
279 fHelper->GetBinData(ydata, parameters, counter);
280 auto yunit = GetUnitValue(ydata.fSunit);
281 fManager->SetH2(id,
282 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
283 ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
284 xdata.fSunit, ydata.fSunit,
285 xdata.fSfcn, ydata.fSfcn,
286 xdata.fSbinScheme, ydata.fSbinScheme);
287 }
288 else if ( command == fSetH2XCmd.get() ) {
289 // Only save values
290 auto counter = 0;
291 fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
292 fHelper->GetBinData(fXData, parameters, counter);
293 }
294 else if ( command == fSetH2YCmd.get() ) {
295 // Check if setX command was called
296 auto counter = 0;
297 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
298 if ( fXId == -1 || fXId != id ) {
299 fHelper->WarnAboutSetCommands();
300 return;
301 }
302 auto xunit = GetUnitValue(fXData.fSunit);
304 fHelper->GetBinData(ydata, parameters, counter);
305 auto yunit = GetUnitValue(ydata.fSunit);
306 fManager->SetH2(id,
307 fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
308 ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
309 fXData.fSunit, ydata.fSunit,
310 fXData.fSfcn, ydata.fSfcn,
312 fXId = -1;
313 }
314 else if ( command == fSetH2TitleCmd.get() ) {
315 auto counter = 0;
316 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
317 auto title = parameters[counter++];
318 fManager->SetH2Title(id, title);
319 }
320 else if ( command == fSetH2XAxisCmd.get() ) {
321 auto counter = 0;
322 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
323 auto xaxis = parameters[counter++];
324 fManager->SetH2XAxisTitle(id, xaxis);
325 }
326 else if ( command == fSetH2YAxisCmd.get() ) {
327 auto counter = 0;
328 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
329 auto yaxis = parameters[counter++];
330 fManager->SetH2YAxisTitle(id, yaxis);
331 }
332 else if ( command == fSetH2ZAxisCmd.get() ) {
333 auto counter = 0;
334 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
335 auto zaxis = parameters[counter++];
336 fManager->SetH2ZAxisTitle(id, zaxis);
337 }
338 else if ( command == fSetH2XAxisLogCmd.get() ) {
339 auto counter = 0;
340 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
341 auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
342 fManager->SetH2XAxisIsLog(id, xaxisLog);
343 }
344 else if ( command == fSetH2YAxisLogCmd.get() ) {
345 auto counter = 0;
346 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
347 auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
348 fManager->SetH2YAxisIsLog(id, yaxisLog);
349 }
350 else if ( command == fSetH2ZAxisLogCmd.get() ) {
351 auto counter = 0;
352 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
353 auto zaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
354 fManager->SetH2ZAxisIsLog(id, zaxisLog);
355 }
356}
@ G4State_Idle
@ G4State_PreInit
std::unique_ptr< G4UIcommand > fSetH2Cmd
std::unique_ptr< G4UIcommand > fSetH2XAxisCmd
std::unique_ptr< G4UIcommand > fSetH2XAxisLogCmd
G4H2Messenger()=delete
void CreateH2Cmd()
virtual ~G4H2Messenger()
std::unique_ptr< G4UIcommand > fSetH2ZAxisCmd
std::unique_ptr< G4UIdirectory > fDirectory
std::unique_ptr< G4UIcommand > fSetH2XCmd
std::unique_ptr< G4UIcommand > fSetH2YAxisCmd
std::unique_ptr< G4UIcommand > fSetH2YAxisLogCmd
std::unique_ptr< G4UIcommand > fCreateH2Cmd
G4VAnalysisManager * fManager
Associated class.
std::unique_ptr< G4UIcommand > fSetH2YCmd
std::unique_ptr< G4UIcommand > fSetH2ZAxisLogCmd
G4AnalysisMessengerHelper::BinData fXData
std::unique_ptr< G4UIcommand > fSetH2TitleCmd
virtual void SetNewValue(G4UIcommand *command, G4String value) final
std::unique_ptr< G4AnalysisMessengerHelper > fHelper
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
G4bool SetH2XAxisIsLog(G4int id, G4bool isLog)
G4bool SetH2Title(G4int id, const G4String &title)
G4bool SetH2YAxisIsLog(G4int id, G4bool isLog)
G4bool SetH2XAxisTitle(G4int id, const G4String &title)
G4bool SetH2YAxisTitle(G4int id, const G4String &title)
G4bool SetH2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
G4bool SetH2ZAxisIsLog(G4int id, G4bool isLog)
G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4double GetUnitValue(const G4String &unit)
const char * name(G4int ptype)