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