Geant4  10.01.p02
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 namespace {
43 
44 void Exception(G4UIcommand* command, G4int nofParameters)
45 {
46  G4ExceptionDescription description;
47  description
48  << "Got wrong number of \"" << command->GetCommandName()
49  << "\" parameters: " << nofParameters
50  << " instead of " << command->GetParameterEntries()
51  << " expected" << G4endl;
52  G4Exception("G4P1Messenger::SetNewValue",
53  "Analysis_W013", JustWarning, description);
54 }
55 
56 }
57 
58 
59 //_____________________________________________________________________________
61  : G4UImessenger(),
62  fManager(manager),
63  fP1Dir(0),
64  fCreateP1Cmd(0),
65  fSetP1Cmd(0),
66  fSetP1TitleCmd(0),
67  fSetP1XAxisCmd(0),
68  fSetP1YAxisCmd(0)
69 {
70  fP1Dir = new G4UIdirectory("/analysis/p1/");
71  fP1Dir->SetGuidance("1D profiles control");
72 
73  CreateP1Cmd();
74  SetP1Cmd();
75 
76  SetP1TitleCmd();
77  SetP1XAxisCmd();
78  SetP1YAxisCmd();
79 }
80 
81 //_____________________________________________________________________________
83 {
84  delete fCreateP1Cmd;
85  delete fSetP1Cmd;
86  delete fSetP1TitleCmd;
87  delete fSetP1XAxisCmd;
88  delete fSetP1YAxisCmd;
89  delete fP1Dir;
90 }
91 
92 //
93 // private functions
94 //
95 
96 //_____________________________________________________________________________
98 {
99  G4UIparameter* p1Name = new G4UIparameter("name", 's', false);
100  p1Name->SetGuidance("Profile name (label)");
101 
102  G4UIparameter* p1Title = new G4UIparameter("title", 's', false);
103  p1Title->SetGuidance("Profile title");
104 
105  G4UIparameter* p1xNbins0 = new G4UIparameter("xnbins0", 'i', true);
106  p1xNbins0->SetGuidance("Number of x-bins (default = 100)");
107  p1xNbins0->SetGuidance("Can be reset with /analysis/p1/set command");
108  p1xNbins0->SetDefaultValue(100);
109 
110  G4UIparameter* p1xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
111  p1xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
112  p1xValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
113  p1xValMin0->SetDefaultValue(0.);
114 
115  G4UIparameter* p1xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
116  p1xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
117  p1xValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
118  p1xValMax0->SetDefaultValue(1.);
119 
120  G4UIparameter* p1xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
121  p1xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
122  p1xValUnit0->SetDefaultValue("none");
123 
124  G4UIparameter* p1xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
125  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
126  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
127  fcnxGuidance += "but none value should be used insted.";
128  p1xValFcn0->SetGuidance(fcnxGuidance);
129  p1xValFcn0->SetParameterCandidates("log log10 exp none");
130  p1xValFcn0->SetDefaultValue("none");
131 
132  G4UIparameter* p1xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
133  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
134  p1xValBinScheme0->SetParameterCandidates("linear log");
135  binSchemeGuidance
136  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
137  binSchemeGuidance += "but none value should be used insted.";
138  p1xValBinScheme0->SetGuidance(binSchemeGuidance);
139  p1xValBinScheme0->SetDefaultValue("linear");
140 
141  G4UIparameter* p1yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
142  p1yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
143  p1yValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
144  p1yValMin0->SetDefaultValue(0.);
145 
146  G4UIparameter* p1yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
147  p1yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
148  p1yValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
149  p1yValMax0->SetDefaultValue(1.);
150 
151  G4UIparameter* p1yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
152  p1yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
153  p1yValUnit0->SetDefaultValue("none");
154 
155  G4UIparameter* p1yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
156  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
157  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
158  fcnyGuidance += "but none value should be used insted.";
159  p1yValFcn0->SetGuidance(fcnyGuidance);
160  p1yValFcn0->SetParameterCandidates("log log10 exp none");
161  p1yValFcn0->SetDefaultValue("none");
162 
163  fCreateP1Cmd = new G4UIcommand("/analysis/p1/create", this);
164  fCreateP1Cmd->SetGuidance("Create 1D profile");
165  fCreateP1Cmd->SetParameter(p1Name);
166  fCreateP1Cmd->SetParameter(p1Title);
167  fCreateP1Cmd->SetParameter(p1xNbins0);
168  fCreateP1Cmd->SetParameter(p1xValMin0);
169  fCreateP1Cmd->SetParameter(p1xValMax0);
170  fCreateP1Cmd->SetParameter(p1xValUnit0);
171  fCreateP1Cmd->SetParameter(p1xValFcn0);
172  fCreateP1Cmd->SetParameter(p1xValBinScheme0);
173  fCreateP1Cmd->SetParameter(p1yValMin0);
174  fCreateP1Cmd->SetParameter(p1yValMax0);
175  fCreateP1Cmd->SetParameter(p1yValUnit0);
176  fCreateP1Cmd->SetParameter(p1yValFcn0);
178 }
179 
180 
181 //_____________________________________________________________________________
183 {
184  G4UIparameter* p1Id = new G4UIparameter("id", 'i', false);
185  p1Id->SetGuidance("Profile id");
186  p1Id->SetParameterRange("id>=0");
187 
188  G4UIparameter* p1xNbins = new G4UIparameter("xnbins", 'i', false);
189  p1xNbins->SetGuidance("Number of x-bins");
190 
191  G4UIparameter* p1xValMin = new G4UIparameter("xvalMin", 'd', false);
192  p1xValMin->SetGuidance("Minimum x-value, expressed in unit");
193 
194  G4UIparameter* p1xValMax = new G4UIparameter("xvalMax", 'd', false);
195  p1xValMax->SetGuidance("Maximum x-value, expressed in unit");
196 
197  G4UIparameter* p1xValUnit = new G4UIparameter("xvalUnit", 's', false);
198  p1xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
199  p1xValUnit->SetDefaultValue("none");
200 
201  G4UIparameter* p1xValFcn = new G4UIparameter("xvalFcn", 's', false);
202  p1xValFcn->SetParameterCandidates("log log10 exp none");
203  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
204  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
205  fcnxGuidance += "but none value should be used insted.";
206  p1xValFcn->SetGuidance(fcnxGuidance);
207  p1xValFcn->SetDefaultValue("none");
208 
209  G4UIparameter* p1xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
210  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
211  p1xValBinScheme->SetParameterCandidates("linear log");
212  binSchemeGuidance
213  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
214  binSchemeGuidance += "but none value should be used insted.";
215  p1xValBinScheme->SetGuidance(binSchemeGuidance);
216  p1xValBinScheme->SetDefaultValue("linear");
217 
218  G4UIparameter* p1yValMin = new G4UIparameter("yvalMin", 'd', false);
219  p1yValMin->SetGuidance("Minimum y-value, expressed in unit");
220 
221  G4UIparameter* p1yValMax = new G4UIparameter("yvalMax", 'd', false);
222  p1yValMax->SetGuidance("Maximum y-value, expressed in unit");
223 
224  G4UIparameter* p1yValUnit = new G4UIparameter("yvalUnit", 's', true);
225  p1yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
226  p1yValUnit->SetDefaultValue("none");
227 
228  G4UIparameter* p1yValFcn = new G4UIparameter("yvalFcn", 's', false);
229  p1yValFcn->SetParameterCandidates("log log10 exp none");
230  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
231  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
232  fcnyGuidance += "but none value should be used insted.";
233  p1yValFcn->SetGuidance(fcnyGuidance);
234  p1yValFcn->SetDefaultValue("none");
235 
236  fSetP1Cmd = new G4UIcommand("/analysis/p1/set", this);
237  fSetP1Cmd->SetGuidance("Set parameters for the 1D profile of #Id :");
238  fSetP1Cmd->SetGuidance(" nbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
239  fSetP1Cmd->SetGuidance(" yvalMin; yvalMax; yunit; yfunction");
240  fSetP1Cmd->SetParameter(p1Id);
241  fSetP1Cmd->SetParameter(p1xNbins);
242  fSetP1Cmd->SetParameter(p1xValMin);
243  fSetP1Cmd->SetParameter(p1xValMax);
244  fSetP1Cmd->SetParameter(p1xValUnit);
245  fSetP1Cmd->SetParameter(p1xValFcn);
246  fSetP1Cmd->SetParameter(p1xValBinScheme);
247  fSetP1Cmd->SetParameter(p1yValMin);
248  fSetP1Cmd->SetParameter(p1yValMax);
249  fSetP1Cmd->SetParameter(p1yValUnit);
250  fSetP1Cmd->SetParameter(p1yValFcn);
252 }
253 
254 //_____________________________________________________________________________
256 {
257  G4UIparameter* p1Id = new G4UIparameter("idTitle", 'i', false);
258  p1Id->SetGuidance("Profile id");
259  p1Id->SetParameterRange("idTitle>=0");
260 
261  G4UIparameter* p1Title = new G4UIparameter("p1Title", 's', true);
262  p1Title->SetGuidance("Profile title");
263  p1Title->SetDefaultValue("none");
264 
265  fSetP1TitleCmd = new G4UIcommand("/analysis/p1/setTitle", this);
266  fSetP1TitleCmd->SetGuidance("Set title for the 1D profile of #Id");
268  fSetP1TitleCmd->SetParameter(p1Title);
270 }
271 
272 //_____________________________________________________________________________
274 {
275  G4UIparameter* p1Id = new G4UIparameter("idXaxis", 'i', false);
276  p1Id->SetGuidance("Profile id");
277  p1Id->SetParameterRange("idXaxis>=0");
278 
279  G4UIparameter* p1XAxis = new G4UIparameter("p1Xaxis", 's', true);
280  p1XAxis->SetGuidance("Profile x-axis title");
281  p1XAxis->SetDefaultValue("none");
282 
283  fSetP1XAxisCmd = new G4UIcommand("/analysis/p1/setXaxis", this);
284  fSetP1XAxisCmd->SetGuidance("Set x-axis title for the 1D profile of #Id");
286  fSetP1XAxisCmd->SetParameter(p1XAxis);
288 }
289 
290 //_____________________________________________________________________________
292 {
293  G4UIparameter* p1Id = new G4UIparameter("idYaxis", 'i', false);
294  p1Id->SetGuidance("Profile id");
295  p1Id->SetParameterRange("idYaxis>=0");
296 
297  G4UIparameter* p1YAxis = new G4UIparameter("p1Yaxis", 's', true);
298  p1YAxis->SetGuidance("Profile y-axis title");
299  p1YAxis->SetDefaultValue("none");
300 
301  fSetP1YAxisCmd = new G4UIcommand("/analysis/p1/setYaxis", this);
302  fSetP1YAxisCmd->SetGuidance("Set y-axis title for the 1D profile of #Id");
304  fSetP1YAxisCmd->SetParameter(p1YAxis);
306 }
307 
308 //
309 // public functions
310 //
311 
312 //_____________________________________________________________________________
314 {
315  // tokenize parameters in a vector
316  std::vector<G4String> parameters;
317  G4Analysis::Tokenize(newValues, parameters);
318  // check consistency
319  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
320  // Should never happen but let's check anyway for consistency
321  Exception(command, parameters.size());
322  return;
323  }
324 
325  if ( command == fCreateP1Cmd ) {
326  G4int counter = 0;
327  G4String name = parameters[counter++];
328  G4String title = parameters[counter++];
329  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
330  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
331  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
332  G4String xsunit = parameters[counter++];
333  G4String xsfcn = parameters[counter++];
334  G4String xsbinScheme = parameters[counter++];
335  G4double xunit = GetUnitValue(xsunit);
336  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
337  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
338  G4String ysunit = parameters[counter++];
339  G4String ysfcn = parameters[counter++];
340  G4double yunit = GetUnitValue(ysunit);
341  fManager->CreateP1(name, title,
342  xnbins, xvmin*xunit, xvmax*xunit,
343  yvmin*yunit, yvmax*yunit,
344  xsunit, ysunit, xsfcn, ysfcn, xsbinScheme);
345  }
346  else if ( command == fSetP1Cmd ) {
347  G4int counter = 0;
348  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
349  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
350  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
351  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
352  G4String xsunit = parameters[counter++];
353  G4String xsfcn = parameters[counter++];
354  G4String xsbinScheme = parameters[counter++];
355  G4double xunit = GetUnitValue(xsunit);
356  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
357  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
358  G4String ysunit = parameters[counter++];
359  G4String ysfcn = parameters[counter++];
360  G4double yunit = GetUnitValue(ysunit);
361  fManager->SetP1(id,
362  xnbins, xvmin*xunit, xvmax*xunit,
363  yvmin*yunit, yvmax*yunit,
364  xsunit, ysunit, xsfcn, ysfcn, xsbinScheme);
365  }
366  else if ( command == fSetP1TitleCmd ) {
367  G4int counter = 0;
368  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
369  G4String title = parameters[counter++];
370  fManager->SetP1Title(id, title);
371  }
372  else if ( command == fSetP1XAxisCmd ) {
373  G4int counter = 0;
374  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
375  G4String xaxis = parameters[counter++];
376  fManager->SetP1XAxisTitle(id, xaxis);
377  }
378  else if ( command == fSetP1YAxisCmd ) {
379  G4int counter = 0;
380  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
381  G4String yaxis = parameters[counter++];
382  fManager->SetP1YAxisTitle(id, yaxis);
383  }
384 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
G4String name
Definition: TRTMaterials.hh:40
void SetDefaultValue(const char *theDefaultValue)
G4UIcommand * fSetP1YAxisCmd
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")
G4UIcommand * fSetP1TitleCmd
G4VAnalysisManager * fManager
Associated class.
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")
virtual void SetNewValue(G4UIcommand *command, G4String value)
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:443
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:239
G4double GetUnitValue(const G4String &unit)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetP1XAxisCmd()
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
G4bool SetP1XAxisTitle(G4int id, const G4String &title)
void Exception(const char *originOfException, const char *exceptionCode, UExceptionSeverity severity, int level, const char *description)
Definition: UUtils.cc:122
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4bool SetP1Title(G4int id, const G4String &title)
G4UIdirectory * fP1Dir
void SetP1TitleCmd()
#define G4endl
Definition: G4ios.hh:61
G4UIcommand * fSetP1Cmd
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
void SetP1YAxisCmd()
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4UIcommand * fCreateP1Cmd
G4UIcommand * fSetP1XAxisCmd
void CreateP1Cmd()
G4P1Messenger(G4VAnalysisManager *manager)