Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4P1Messenger.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/07/2014 ([email protected])
28
29#include "G4P1Messenger.hh"
30#include "G4VAnalysisManager.hh"
32
33#include "G4UIdirectory.hh"
34#include "G4UIcommand.hh"
35#include "G4UIparameter.hh"
36
37#include <iostream>
38
39using namespace G4Analysis;
40
41//_____________________________________________________________________________
43 : G4UImessenger(),
44 fManager(manager),
45 fHelper(nullptr),
46 fDirectory(nullptr),
47 fCreateP1Cmd(nullptr),
48 fSetP1Cmd(nullptr),
49 fSetP1TitleCmd(nullptr),
50 fSetP1XAxisCmd(nullptr),
51 fSetP1YAxisCmd(nullptr),
52 fXId(-1),
53 fXData()
54{
55 fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p1");
56
57 fDirectory = fHelper->CreateHnDirectory();
58
59 CreateP1Cmd();
60
61 SetP1Cmd();
62 fSetP1XCmd = fHelper->CreateSetBinsCommand("x", this);
63 fSetP1YCmd = fHelper->CreateSetValuesCommand("y", this);
64
65 fSetP1TitleCmd = fHelper->CreateSetTitleCommand(this);
66 fSetP1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
67 fSetP1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
68 fSetP1XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
69 fSetP1YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
70}
71
72//_____________________________________________________________________________
74{}
75
76//
77// private functions
78//
79
80//_____________________________________________________________________________
81void G4P1Messenger::CreateP1Cmd()
82{
83 auto p1Name = new G4UIparameter("name", 's', false);
84 p1Name->SetGuidance("Profile name (label)");
85
86 auto p1Title = new G4UIparameter("title", 's', false);
87 p1Title->SetGuidance("Profile title");
88
89 auto p1xNbins0 = new G4UIparameter("xnbins0", 'i', true);
90 p1xNbins0->SetGuidance("Number of x-bins (default = 100)");
91 p1xNbins0->SetGuidance("Can be reset with /analysis/p1/set command");
92 p1xNbins0->SetDefaultValue(100);
93
94 auto p1xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
95 p1xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
96 p1xValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
97 p1xValMin0->SetDefaultValue(0.);
98
99 auto p1xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
100 p1xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
101 p1xValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
102 p1xValMax0->SetDefaultValue(1.);
103
104 auto p1xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
105 p1xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
106 p1xValUnit0->SetDefaultValue("none");
107
108 auto p1xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
109 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
110 fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
111 fcnxGuidance += "but none value should be used instead.";
112 p1xValFcn0->SetGuidance(fcnxGuidance);
113 p1xValFcn0->SetParameterCandidates("log log10 exp none");
114 p1xValFcn0->SetDefaultValue("none");
115
116 auto p1xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
117 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
118 p1xValBinScheme0->SetParameterCandidates("linear log");
119 binSchemeGuidance
120 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
121 binSchemeGuidance += "but none value should be used instead.";
122 p1xValBinScheme0->SetGuidance(binSchemeGuidance);
123 p1xValBinScheme0->SetDefaultValue("linear");
124
125 auto p1yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
126 p1yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
127 p1yValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
128 p1yValMin0->SetDefaultValue(0.);
129
130 auto p1yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
131 p1yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
132 p1yValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
133 p1yValMax0->SetDefaultValue(1.);
134
135 auto p1yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
136 p1yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
137 p1yValUnit0->SetDefaultValue("none");
138
139 auto p1yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
140 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
141 fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
142 fcnyGuidance += "but none value should be used instead.";
143 p1yValFcn0->SetGuidance(fcnyGuidance);
144 p1yValFcn0->SetParameterCandidates("log log10 exp none");
145 p1yValFcn0->SetDefaultValue("none");
146
147 fCreateP1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p1/create", this);
148 fCreateP1Cmd->SetGuidance("Create 1D profile");
149 fCreateP1Cmd->SetParameter(p1Name);
150 fCreateP1Cmd->SetParameter(p1Title);
151 fCreateP1Cmd->SetParameter(p1xNbins0);
152 fCreateP1Cmd->SetParameter(p1xValMin0);
153 fCreateP1Cmd->SetParameter(p1xValMax0);
154 fCreateP1Cmd->SetParameter(p1xValUnit0);
155 fCreateP1Cmd->SetParameter(p1xValFcn0);
156 fCreateP1Cmd->SetParameter(p1xValBinScheme0);
157 fCreateP1Cmd->SetParameter(p1yValMin0);
158 fCreateP1Cmd->SetParameter(p1yValMax0);
159 fCreateP1Cmd->SetParameter(p1yValUnit0);
160 fCreateP1Cmd->SetParameter(p1yValFcn0);
161 fCreateP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
162}
163
164
165//_____________________________________________________________________________
166void G4P1Messenger::SetP1Cmd()
167{
168 auto p1Id = new G4UIparameter("id", 'i', false);
169 p1Id->SetGuidance("Profile id");
170 p1Id->SetParameterRange("id>=0");
171
172 auto p1xNbins = new G4UIparameter("xnbins", 'i', false);
173 p1xNbins->SetGuidance("Number of x-bins");
174
175 auto p1xValMin = new G4UIparameter("xvalMin", 'd', false);
176 p1xValMin->SetGuidance("Minimum x-value, expressed in unit");
177
178 auto p1xValMax = new G4UIparameter("xvalMax", 'd', false);
179 p1xValMax->SetGuidance("Maximum x-value, expressed in unit");
180
181 auto p1xValUnit = new G4UIparameter("xvalUnit", 's', true);
182 p1xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
183 p1xValUnit->SetDefaultValue("none");
184
185 auto p1xValFcn = new G4UIparameter("xvalFcn", 's', true);
186 p1xValFcn->SetParameterCandidates("log log10 exp none");
187 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
188 fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
189 fcnxGuidance += "but none value should be used instead.";
190 p1xValFcn->SetGuidance(fcnxGuidance);
191 p1xValFcn->SetDefaultValue("none");
192
193 auto p1xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
194 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
195 p1xValBinScheme->SetParameterCandidates("linear log");
196 binSchemeGuidance
197 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
198 binSchemeGuidance += "but none value should be used instead.";
199 p1xValBinScheme->SetGuidance(binSchemeGuidance);
200 p1xValBinScheme->SetDefaultValue("linear");
201
202 auto p1yValMin = new G4UIparameter("yvalMin", 'd', true);
203 p1yValMin->SetGuidance("Minimum y-value, expressed in unit");
204
205 auto p1yValMax = new G4UIparameter("yvalMax", 'd', true);
206 p1yValMax->SetGuidance("Maximum y-value, expressed in unit");
207
208 auto p1yValUnit = new G4UIparameter("yvalUnit", 's', true);
209 p1yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
210 p1yValUnit->SetDefaultValue("none");
211
212 auto p1yValFcn = new G4UIparameter("yvalFcn", 's', true);
213 p1yValFcn->SetParameterCandidates("log log10 exp none");
214 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
215 fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
216 fcnyGuidance += "but none value should be used instead.";
217 p1yValFcn->SetGuidance(fcnyGuidance);
218 p1yValFcn->SetDefaultValue("none");
219
220 fSetP1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p1/set", this);
221 fSetP1Cmd->SetGuidance("Set parameters for the 1D profile of given id:");
222 fSetP1Cmd->SetGuidance(" nbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
223 fSetP1Cmd->SetGuidance(" yvalMin; yvalMax; yunit; yfunction");
224 fSetP1Cmd->SetParameter(p1Id);
225 fSetP1Cmd->SetParameter(p1xNbins);
226 fSetP1Cmd->SetParameter(p1xValMin);
227 fSetP1Cmd->SetParameter(p1xValMax);
228 fSetP1Cmd->SetParameter(p1xValUnit);
229 fSetP1Cmd->SetParameter(p1xValFcn);
230 fSetP1Cmd->SetParameter(p1xValBinScheme);
231 fSetP1Cmd->SetParameter(p1yValMin);
232 fSetP1Cmd->SetParameter(p1yValMax);
233 fSetP1Cmd->SetParameter(p1yValUnit);
234 fSetP1Cmd->SetParameter(p1yValFcn);
235 fSetP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
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 == fCreateP1Cmd.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->GetValueData(ydata, parameters, counter);
264 auto yunit = GetUnitValue(ydata.fSunit);
265 fManager->CreateP1(name, title,
266 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
267 ydata.fVmin*yunit, ydata.fVmax*yunit,
268 xdata.fSunit, ydata.fSunit,
269 xdata.fSfcn, ydata.fSfcn,
270 xdata.fSbinScheme);
271 }
272 else if ( command == fSetP1Cmd.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->GetValueData(ydata, parameters, counter);
280 auto yunit = GetUnitValue(ydata.fSunit);
281 fManager->SetP1(id,
282 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
283 ydata.fVmin*yunit, ydata.fVmax*yunit,
284 xdata.fSunit, ydata.fSunit,
285 xdata.fSfcn, ydata.fSfcn,
286 xdata.fSbinScheme);
287 }
288 else if ( command == fSetP1XCmd.get() ) {
289 // Save values
290 auto counter = 0;
291 fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
292 fHelper->GetBinData(fXData, parameters, counter);
293 // Set values
294 // (another set may follow if setY is also called)
295 auto xunit = GetUnitValue(fXData.fSunit);
296 fManager->SetP1(fXId,
297 fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
298 0., 0.,
299 fXData.fSunit, "none",
300 fXData.fSfcn, "none",
301 fXData.fSbinScheme);
302 }
303 else if ( command == fSetP1YCmd.get() ) {
304 // Check if setX command was called
305 auto counter = 0;
306 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
307 if ( fXId == -1 || fXId != id ) {
308 fHelper->WarnAboutSetCommands();
309 return;
310 }
311 auto xunit = GetUnitValue(fXData.fSunit);
313 fHelper->GetValueData(ydata, parameters, counter);
314 auto yunit = GetUnitValue(ydata.fSunit);
315 fManager->SetP1(id,
316 fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
317 ydata.fVmin*yunit, ydata.fVmax*yunit,
318 fXData.fSunit, ydata.fSunit,
319 fXData.fSfcn, ydata.fSfcn,
320 fXData.fSbinScheme);
321 fXId = -1;
322 }
323 else if ( command == fSetP1TitleCmd.get() ) {
324 auto counter = 0;
325 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
326 auto title = parameters[counter++];
327 fManager->SetP1Title(id, title);
328 }
329 else if ( command == fSetP1XAxisCmd.get() ) {
330 auto counter = 0;
331 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
332 auto xaxis = parameters[counter++];
333 fManager->SetP1XAxisTitle(id, xaxis);
334 }
335 else if ( command == fSetP1YAxisCmd.get() ) {
336 auto counter = 0;
337 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
338 auto yaxis = parameters[counter++];
339 fManager->SetP1YAxisTitle(id, yaxis);
340 }
341 else if ( command == fSetP1XAxisLogCmd.get() ) {
342 auto counter = 0;
343 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
344 auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
345 fManager->SetP1XAxisIsLog(id, xaxisLog);
346 }
347 else if ( command == fSetP1YAxisLogCmd.get() ) {
348 auto counter = 0;
349 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
350 auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
351 fManager->SetP1YAxisIsLog(id, yaxisLog);
352 }
353}
@ G4State_Idle
@ G4State_PreInit
virtual void SetNewValue(G4UIcommand *command, G4String value) final
virtual ~G4P1Messenger()
G4P1Messenger(G4VAnalysisManager *manager)
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:543
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:530
G4int CreateP1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, G4double ymin=0, G4double ymax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear")
G4bool SetP1XAxisTitle(G4int id, const G4String &title)
G4bool SetP1(G4int id, G4int nbins, G4double xmin, G4double xmax, G4double ymin=0, G4double ymax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear")
G4bool SetP1YAxisIsLog(G4int id, G4bool isLog)
G4bool SetP1YAxisTitle(G4int id, const G4String &title)
G4bool SetP1XAxisIsLog(G4int id, G4bool isLog)
G4bool SetP1Title(G4int id, const G4String &title)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4double GetUnitValue(const G4String &unit)