Geant4-11
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 (ivana@ipno.in2p3.fr)
28
29#include "G4P1Messenger.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>("p1");
44
45 fDirectory = fHelper->CreateHnDirectory();
46
48
49 SetP1Cmd();
50 fSetP1XCmd = fHelper->CreateSetBinsCommand("x", this);
51 fSetP1YCmd = fHelper->CreateSetValuesCommand("y", this);
52
53 fSetP1TitleCmd = fHelper->CreateSetTitleCommand(this);
54 fSetP1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
55 fSetP1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
56 fSetP1XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
57 fSetP1YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
58}
59
60//_____________________________________________________________________________
62
63//
64// private functions
65//
66
67//_____________________________________________________________________________
69{
70 auto p1Name = new G4UIparameter("name", 's', false);
71 p1Name->SetGuidance("Profile name (label)");
72
73 auto p1Title = new G4UIparameter("title", 's', false);
74 p1Title->SetGuidance("Profile title");
75
76 auto p1xNbins0 = new G4UIparameter("xnbins0", 'i', true);
77 p1xNbins0->SetGuidance("Number of x-bins (default = 100)");
78 p1xNbins0->SetGuidance("Can be reset with /analysis/p1/set command");
79 p1xNbins0->SetDefaultValue(100);
80
81 auto p1xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
82 p1xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
83 p1xValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
84 p1xValMin0->SetDefaultValue(0.);
85
86 auto p1xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
87 p1xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
88 p1xValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
89 p1xValMax0->SetDefaultValue(1.);
90
91 auto p1xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
92 p1xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
93 p1xValUnit0->SetDefaultValue("none");
94
95 auto p1xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
96 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
97 fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
98 fcnxGuidance += "but none value should be used instead.";
99 p1xValFcn0->SetGuidance(fcnxGuidance);
100 p1xValFcn0->SetParameterCandidates("log log10 exp none");
101 p1xValFcn0->SetDefaultValue("none");
102
103 auto p1xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
104 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
105 p1xValBinScheme0->SetParameterCandidates("linear log");
106 binSchemeGuidance
107 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
108 binSchemeGuidance += "but none value should be used instead.";
109 p1xValBinScheme0->SetGuidance(binSchemeGuidance);
110 p1xValBinScheme0->SetDefaultValue("linear");
111
112 auto p1yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
113 p1yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
114 p1yValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
115 p1yValMin0->SetDefaultValue(0.);
116
117 auto p1yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
118 p1yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
119 p1yValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
120 p1yValMax0->SetDefaultValue(1.);
121
122 auto p1yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
123 p1yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
124 p1yValUnit0->SetDefaultValue("none");
125
126 auto p1yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
127 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
128 fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
129 fcnyGuidance += "but none value should be used instead.";
130 p1yValFcn0->SetGuidance(fcnyGuidance);
131 p1yValFcn0->SetParameterCandidates("log log10 exp none");
132 p1yValFcn0->SetDefaultValue("none");
133
134 fCreateP1Cmd = std::make_unique<G4UIcommand>("/analysis/p1/create", this);
135 fCreateP1Cmd->SetGuidance("Create 1D profile");
136 fCreateP1Cmd->SetParameter(p1Name);
137 fCreateP1Cmd->SetParameter(p1Title);
138 fCreateP1Cmd->SetParameter(p1xNbins0);
139 fCreateP1Cmd->SetParameter(p1xValMin0);
140 fCreateP1Cmd->SetParameter(p1xValMax0);
141 fCreateP1Cmd->SetParameter(p1xValUnit0);
142 fCreateP1Cmd->SetParameter(p1xValFcn0);
143 fCreateP1Cmd->SetParameter(p1xValBinScheme0);
144 fCreateP1Cmd->SetParameter(p1yValMin0);
145 fCreateP1Cmd->SetParameter(p1yValMax0);
146 fCreateP1Cmd->SetParameter(p1yValUnit0);
147 fCreateP1Cmd->SetParameter(p1yValFcn0);
148 fCreateP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
149}
150
151
152//_____________________________________________________________________________
154{
155 auto p1Id = new G4UIparameter("id", 'i', false);
156 p1Id->SetGuidance("Profile id");
157 p1Id->SetParameterRange("id>=0");
158
159 auto p1xNbins = new G4UIparameter("xnbins", 'i', false);
160 p1xNbins->SetGuidance("Number of x-bins");
161
162 auto p1xValMin = new G4UIparameter("xvalMin", 'd', false);
163 p1xValMin->SetGuidance("Minimum x-value, expressed in unit");
164
165 auto p1xValMax = new G4UIparameter("xvalMax", 'd', false);
166 p1xValMax->SetGuidance("Maximum x-value, expressed in unit");
167
168 auto p1xValUnit = new G4UIparameter("xvalUnit", 's', true);
169 p1xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
170 p1xValUnit->SetDefaultValue("none");
171
172 auto p1xValFcn = new G4UIparameter("xvalFcn", 's', true);
173 p1xValFcn->SetParameterCandidates("log log10 exp none");
174 G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
175 fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
176 fcnxGuidance += "but none value should be used instead.";
177 p1xValFcn->SetGuidance(fcnxGuidance);
178 p1xValFcn->SetDefaultValue("none");
179
180 auto p1xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
181 G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
182 p1xValBinScheme->SetParameterCandidates("linear log");
183 binSchemeGuidance
184 += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
185 binSchemeGuidance += "but none value should be used instead.";
186 p1xValBinScheme->SetGuidance(binSchemeGuidance);
187 p1xValBinScheme->SetDefaultValue("linear");
188
189 auto p1yValMin = new G4UIparameter("yvalMin", 'd', true);
190 p1yValMin->SetGuidance("Minimum y-value, expressed in unit");
191
192 auto p1yValMax = new G4UIparameter("yvalMax", 'd', true);
193 p1yValMax->SetGuidance("Maximum y-value, expressed in unit");
194
195 auto p1yValUnit = new G4UIparameter("yvalUnit", 's', true);
196 p1yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
197 p1yValUnit->SetDefaultValue("none");
198
199 auto p1yValFcn = new G4UIparameter("yvalFcn", 's', true);
200 p1yValFcn->SetParameterCandidates("log log10 exp none");
201 G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
202 fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
203 fcnyGuidance += "but none value should be used instead.";
204 p1yValFcn->SetGuidance(fcnyGuidance);
205 p1yValFcn->SetDefaultValue("none");
206
207 fSetP1Cmd = std::make_unique<G4UIcommand>("/analysis/p1/set", this);
208 fSetP1Cmd->SetGuidance("Set parameters for the 1D profile of given id:");
209 fSetP1Cmd->SetGuidance(" nbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
210 fSetP1Cmd->SetGuidance(" yvalMin; yvalMax; yunit; yfunction");
211 fSetP1Cmd->SetParameter(p1Id);
212 fSetP1Cmd->SetParameter(p1xNbins);
213 fSetP1Cmd->SetParameter(p1xValMin);
214 fSetP1Cmd->SetParameter(p1xValMax);
215 fSetP1Cmd->SetParameter(p1xValUnit);
216 fSetP1Cmd->SetParameter(p1xValFcn);
217 fSetP1Cmd->SetParameter(p1xValBinScheme);
218 fSetP1Cmd->SetParameter(p1yValMin);
219 fSetP1Cmd->SetParameter(p1yValMax);
220 fSetP1Cmd->SetParameter(p1yValUnit);
221 fSetP1Cmd->SetParameter(p1yValFcn);
222 fSetP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
223}
224
225//
226// public functions
227//
228
229//_____________________________________________________________________________
231{
232 // tokenize parameters in a vector
233 std::vector<G4String> parameters;
234 G4Analysis::Tokenize(newValues, parameters);
235 // check consistency
236 if ( parameters.size() != command->GetParameterEntries() ) {
237 // Should never happen but let's check anyway for consistency
238 fHelper->WarnAboutParameters(command, parameters.size());
239 return;
240 }
241
242 if ( command == fCreateP1Cmd.get() ) {
243 auto counter = 0;
244 auto name = parameters[counter++];
245 auto title = parameters[counter++];
247 fHelper->GetBinData(xdata, parameters, counter);
248 auto xunit = GetUnitValue(xdata.fSunit);
250 fHelper->GetValueData(ydata, parameters, counter);
251 auto yunit = GetUnitValue(ydata.fSunit);
252 fManager->CreateP1(name, title,
253 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
254 ydata.fVmin*yunit, ydata.fVmax*yunit,
255 xdata.fSunit, ydata.fSunit,
256 xdata.fSfcn, ydata.fSfcn,
257 xdata.fSbinScheme);
258 }
259 else if ( command == fSetP1Cmd.get() ) {
260 auto counter = 0;
261 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
263 fHelper->GetBinData(xdata, parameters, counter);
264 auto xunit = GetUnitValue(xdata.fSunit);
266 fHelper->GetValueData(ydata, parameters, counter);
267 auto yunit = GetUnitValue(ydata.fSunit);
268 fManager->SetP1(id,
269 xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
270 ydata.fVmin*yunit, ydata.fVmax*yunit,
271 xdata.fSunit, ydata.fSunit,
272 xdata.fSfcn, ydata.fSfcn,
273 xdata.fSbinScheme);
274 }
275 else if ( command == fSetP1XCmd.get() ) {
276 // Save values
277 auto counter = 0;
278 fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
279 fHelper->GetBinData(fXData, parameters, counter);
280 // Set values
281 // (another set may follow if setY is also called)
282 auto xunit = GetUnitValue(fXData.fSunit);
284 fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
285 0., 0.,
286 fXData.fSunit, "none",
287 fXData.fSfcn, "none",
289 }
290 else if ( command == fSetP1YCmd.get() ) {
291 // Check if setX command was called
292 auto counter = 0;
293 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
294 if ( fXId == -1 || fXId != id ) {
295 fHelper->WarnAboutSetCommands();
296 return;
297 }
298 auto xunit = GetUnitValue(fXData.fSunit);
300 fHelper->GetValueData(ydata, parameters, counter);
301 auto yunit = GetUnitValue(ydata.fSunit);
302 fManager->SetP1(id,
303 fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
304 ydata.fVmin*yunit, ydata.fVmax*yunit,
305 fXData.fSunit, ydata.fSunit,
306 fXData.fSfcn, ydata.fSfcn,
308 fXId = -1;
309 }
310 else if ( command == fSetP1TitleCmd.get() ) {
311 auto counter = 0;
312 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
313 auto title = parameters[counter++];
314 fManager->SetP1Title(id, title);
315 }
316 else if ( command == fSetP1XAxisCmd.get() ) {
317 auto counter = 0;
318 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
319 auto xaxis = parameters[counter++];
320 fManager->SetP1XAxisTitle(id, xaxis);
321 }
322 else if ( command == fSetP1YAxisCmd.get() ) {
323 auto counter = 0;
324 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
325 auto yaxis = parameters[counter++];
326 fManager->SetP1YAxisTitle(id, yaxis);
327 }
328 else if ( command == fSetP1XAxisLogCmd.get() ) {
329 auto counter = 0;
330 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
331 auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
332 fManager->SetP1XAxisIsLog(id, xaxisLog);
333 }
334 else if ( command == fSetP1YAxisLogCmd.get() ) {
335 auto counter = 0;
336 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
337 auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
338 fManager->SetP1YAxisIsLog(id, yaxisLog);
339 }
340}
@ G4State_Idle
@ G4State_PreInit
std::unique_ptr< G4UIcommand > fSetP1XAxisLogCmd
G4VAnalysisManager * fManager
Associated class.
G4P1Messenger()=delete
std::unique_ptr< G4UIcommand > fSetP1YAxisCmd
std::unique_ptr< G4UIcommand > fSetP1YCmd
virtual void SetNewValue(G4UIcommand *command, G4String value) final
std::unique_ptr< G4AnalysisMessengerHelper > fHelper
std::unique_ptr< G4UIcommand > fSetP1TitleCmd
G4AnalysisMessengerHelper::BinData fXData
std::unique_ptr< G4UIcommand > fSetP1YAxisLogCmd
std::unique_ptr< G4UIcommand > fSetP1Cmd
std::unique_ptr< G4UIcommand > fSetP1XAxisCmd
std::unique_ptr< G4UIcommand > fSetP1XCmd
void CreateP1Cmd()
virtual ~G4P1Messenger()
std::unique_ptr< G4UIcommand > fCreateP1Cmd
std::unique_ptr< G4UIdirectory > fDirectory
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 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)
const char * name(G4int ptype)