Geant4  10.00.p03
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 // $Id: G4H2Messenger.cc 66310 2012-12-17 11:56:35Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4H2Messenger.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 namespace {
41 
42 void Exception(G4UIcommand* command, G4int nofParameters)
43 {
44  G4ExceptionDescription description;
45  description
46  << "Got wrong number of \"" << command->GetCommandName()
47  << "\" parameters: " << nofParameters
48  << " instead of " << command->GetParameterEntries()
49  << " expected" << G4endl;
50  G4Exception("G4H2Messenger::SetNewValue",
51  "Analysis_W013", JustWarning, description);
52 }
53 
54 }
55 
56 
57 //_____________________________________________________________________________
59  : G4UImessenger(),
60  fManager(manager),
61  fH2Dir(0),
62  fCreateH2Cmd(0),
63  fSetH2Cmd(0),
64  fSetH2TitleCmd(0),
65  fSetH2XAxisCmd(0),
66  fSetH2YAxisCmd(0)
67 {
68  fH2Dir = new G4UIdirectory("/analysis/h2/");
69  fH2Dir->SetGuidance("2D histograms control");
70 
71  CreateH2Cmd();
72  SetH2Cmd();
73 
74  SetH2TitleCmd();
75  SetH2XAxisCmd();
76  SetH2YAxisCmd();
77  SetH2ZAxisCmd();
78 }
79 
80 //_____________________________________________________________________________
82 {
83  delete fCreateH2Cmd;
84  delete fSetH2Cmd;
85  delete fSetH2TitleCmd;
86  delete fSetH2XAxisCmd;
87  delete fSetH2YAxisCmd;
88  delete fSetH2ZAxisCmd;
89  delete fH2Dir;
90 }
91 
92 //
93 // private functions
94 //
95 
96 //_____________________________________________________________________________
98 {
99  G4UIparameter* h2Name = new G4UIparameter("name", 's', false);
100  h2Name->SetGuidance("Histogram name (label)");
101 
102  G4UIparameter* h2Title = new G4UIparameter("title", 's', false);
103  h2Title->SetGuidance("Histogram title");
104 
105  G4UIparameter* h2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
106  h2xNbins0->SetGuidance("Number of x-bins (default = 100)");
107  h2xNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
108  h2xNbins0->SetDefaultValue(100);
109 
110  G4UIparameter* h2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
111  h2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
112  h2xValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
113  h2xValMin0->SetDefaultValue(0.);
114 
115  G4UIparameter* h2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
116  h2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
117  h2xValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
118  h2xValMax0->SetDefaultValue(1.);
119 
120  G4UIparameter* h2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
121  h2xValUnit0->SetGuidance("The unit of xvalMin0 and xvalMax0");
122  h2xValUnit0->SetDefaultValue("none");
123 
124  G4UIparameter* h2xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
125  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
126  h2xValFcn0->SetGuidance(fcnxGuidance);
127  h2xValFcn0->SetParameterCandidates("log log10 exp none");
128  h2xValFcn0->SetDefaultValue("none");
129 
130  G4UIparameter* h2xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
131  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
132  h2xValBinScheme0->SetParameterCandidates("linear log");
133  h2xValBinScheme0->SetGuidance(xbinSchemeGuidance);
134  h2xValBinScheme0->SetDefaultValue("linear");
135 
136  G4UIparameter* h2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
137  h2yNbins0->SetGuidance("Number of y-bins (default = 100)");
138  h2yNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
139  h2yNbins0->SetDefaultValue(100);
140 
141  G4UIparameter* h2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
142  h2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
143  h2yValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
144  h2yValMin0->SetDefaultValue(0.);
145 
146  G4UIparameter* h2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
147  h2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
148  h2yValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
149  h2yValMax0->SetDefaultValue(1.);
150 
151  G4UIparameter* h2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
152  h2yValUnit0->SetGuidance("The unit of yvalMin0 and yvalMax0");
153  h2yValUnit0->SetDefaultValue("none");
154 
155  G4UIparameter* h2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
156  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
157  h2yValFcn0->SetGuidance(fcnyGuidance);
158  h2yValFcn0->SetParameterCandidates("log log10 exp none");
159  h2yValFcn0->SetDefaultValue("none");
160 
161  G4UIparameter* h2yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
162  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
163  h2yValBinScheme0->SetParameterCandidates("linear log");
164  h2yValBinScheme0->SetGuidance(ybinSchemeGuidance);
165  h2yValBinScheme0->SetDefaultValue("linear");
166 
167  fCreateH2Cmd = new G4UIcommand("/analysis/h2/create", this);
168  fCreateH2Cmd->SetGuidance("Create 2D histogram");
169  fCreateH2Cmd->SetParameter(h2Name);
170  fCreateH2Cmd->SetParameter(h2Title);
171  fCreateH2Cmd->SetParameter(h2xNbins0);
172  fCreateH2Cmd->SetParameter(h2xValMin0);
173  fCreateH2Cmd->SetParameter(h2xValMax0);
174  fCreateH2Cmd->SetParameter(h2xValUnit0);
175  fCreateH2Cmd->SetParameter(h2xValFcn0);
176  fCreateH2Cmd->SetParameter(h2xValBinScheme0);
177  fCreateH2Cmd->SetParameter(h2yNbins0);
178  fCreateH2Cmd->SetParameter(h2yValMin0);
179  fCreateH2Cmd->SetParameter(h2yValMax0);
180  fCreateH2Cmd->SetParameter(h2yValUnit0);
181  fCreateH2Cmd->SetParameter(h2yValFcn0);
182  fCreateH2Cmd->SetParameter(h2yValBinScheme0);
184 }
185 
186 
187 //_____________________________________________________________________________
189 {
190  G4UIparameter* h2Id = new G4UIparameter("id", 'i', false);
191  h2Id->SetGuidance("Histogram id");
192  h2Id->SetParameterRange("id>=0");
193 
194  G4UIparameter* h2xNbins = new G4UIparameter("xnbins", 'i', false);
195  h2xNbins->SetGuidance("Number of x-bins");
196 
197  G4UIparameter* h2xValMin = new G4UIparameter("xvalMin", 'd', false);
198  h2xValMin->SetGuidance("Minimum x-value, expressed in unit");
199 
200  G4UIparameter* h2xValMax = new G4UIparameter("xvalMax", 'd', false);
201  h2xValMax->SetGuidance("Maximum x-value, expressed in unit");
202 
203  G4UIparameter* h2xValUnit = new G4UIparameter("xvalUnit", 's', false);
204  h2xValUnit->SetGuidance("The unit of xvalMin and xvalMax");
205  h2xValUnit->SetDefaultValue("none");
206 
207  G4UIparameter* h2xValFcn = new G4UIparameter("xvalFcn", 's', false);
208  h2xValFcn->SetParameterCandidates("log log10 exp none");
209  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
210  h2xValFcn->SetGuidance(fcnxGuidance);
211  h2xValFcn->SetDefaultValue("none");
212 
213  G4UIparameter* h2xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
214  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
215  h2xValBinScheme->SetParameterCandidates("linear log");
216  h2xValBinScheme->SetGuidance(xbinSchemeGuidance);
217  h2xValBinScheme->SetDefaultValue("linear");
218 
219  G4UIparameter* h2yNbins = new G4UIparameter("nybins", 'i', false);
220  h2yNbins->SetGuidance("Number of y-bins");
221 
222  G4UIparameter* h2yValMin = new G4UIparameter("yvalMin", 'd', false);
223  h2yValMin->SetGuidance("Minimum y-value, expressed in unit");
224 
225  G4UIparameter* h2yValMax = new G4UIparameter("yvalMax", 'd', false);
226  h2yValMax->SetGuidance("Maximum y-value, expressed in unit");
227 
228  G4UIparameter* h2yValUnit = new G4UIparameter("yvalUnit", 's', true);
229  h2yValUnit->SetGuidance("The unit of yvalMin and yvalMax");
230  h2yValUnit->SetDefaultValue("none");
231 
232  G4UIparameter* h2yValFcn = new G4UIparameter("yvalFcn", 's', false);
233  h2yValFcn->SetParameterCandidates("log log10 exp none");
234  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
235  h2yValFcn->SetGuidance(fcnyGuidance);
236  h2yValFcn->SetDefaultValue("none");
237 
238  G4UIparameter* h2yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
239  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
240  h2yValBinScheme->SetParameterCandidates("linear log");
241  h2yValBinScheme->SetGuidance(ybinSchemeGuidance);
242  h2yValBinScheme->SetDefaultValue("linear");
243 
244  fSetH2Cmd = new G4UIcommand("/analysis/h2/set", this);
245  fSetH2Cmd->SetGuidance("Set parameters for the 2D histogram of #Id :");
246  fSetH2Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
247  fSetH2Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; yfunction; ybinScheme");
248  fSetH2Cmd->SetParameter(h2Id);
249  fSetH2Cmd->SetParameter(h2xNbins);
250  fSetH2Cmd->SetParameter(h2xValMin);
251  fSetH2Cmd->SetParameter(h2xValMax);
252  fSetH2Cmd->SetParameter(h2xValUnit);
253  fSetH2Cmd->SetParameter(h2xValFcn);
254  fSetH2Cmd->SetParameter(h2xValBinScheme);
255  fSetH2Cmd->SetParameter(h2yNbins);
256  fSetH2Cmd->SetParameter(h2yValMin);
257  fSetH2Cmd->SetParameter(h2yValMax);
258  fSetH2Cmd->SetParameter(h2yValUnit);
259  fSetH2Cmd->SetParameter(h2yValFcn);
260  fSetH2Cmd->SetParameter(h2yValBinScheme);
262 }
263 
264 //_____________________________________________________________________________
266 {
267  G4UIparameter* h2Id = new G4UIparameter("idTitle", 'i', false);
268  h2Id->SetGuidance("Histogram id");
269  h2Id->SetParameterRange("idTitle>=0");
270 
271  G4UIparameter* h2Title = new G4UIparameter("h2Title", 's', true);
272  h2Title->SetGuidance("Histogram title");
273  h2Title->SetDefaultValue("none");
274 
275  fSetH2TitleCmd = new G4UIcommand("/analysis/h2/setTitle", this);
276  fSetH2TitleCmd->SetGuidance("Set title for the 2D histogram of #Id");
278  fSetH2TitleCmd->SetParameter(h2Title);
280 }
281 
282 //_____________________________________________________________________________
284 {
285  G4UIparameter* h2Id = new G4UIparameter("idXaxis", 'i', false);
286  h2Id->SetGuidance("Histogram id");
287  h2Id->SetParameterRange("idXaxis>=0");
288 
289  G4UIparameter* h2XAxis = new G4UIparameter("h2Xaxis", 's', true);
290  h2XAxis->SetGuidance("Histogram x-axis title");
291  h2XAxis->SetDefaultValue("none");
292 
293  fSetH2XAxisCmd = new G4UIcommand("/analysis/h2/setXaxis", this);
294  fSetH2XAxisCmd->SetGuidance("Set x-axis title for the 2D histogram of #Id");
296  fSetH2XAxisCmd->SetParameter(h2XAxis);
298 }
299 
300 //_____________________________________________________________________________
302 {
303  G4UIparameter* h2Id = new G4UIparameter("idYaxis", 'i', false);
304  h2Id->SetGuidance("Histogram id");
305  h2Id->SetParameterRange("idYaxis>=0");
306 
307  G4UIparameter* h2YAxis = new G4UIparameter("h2Yaxis", 's', true);
308  h2YAxis->SetGuidance("Histogram y-axis title");
309  h2YAxis->SetDefaultValue("none");
310 
311  fSetH2YAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
312  fSetH2YAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
314  fSetH2YAxisCmd->SetParameter(h2YAxis);
316 }
317 
318 //_____________________________________________________________________________
320 {
321  G4UIparameter* h2Id = new G4UIparameter("idYaxis", 'i', false);
322  h2Id->SetGuidance("Histogram id");
323  h2Id->SetParameterRange("idYaxis>=0");
324 
325  G4UIparameter* h2YAxis = new G4UIparameter("h2Yaxis", 's', true);
326  h2YAxis->SetGuidance("Histogram y-axis title");
327  h2YAxis->SetDefaultValue("none");
328 
329  fSetH2ZAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
330  fSetH2ZAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
332  fSetH2ZAxisCmd->SetParameter(h2YAxis);
334 }
335 
336 //
337 // public functions
338 //
339 
340 //_____________________________________________________________________________
342 {
343  // tokenize parameters in a vector
344  std::vector<G4String> parameters;
345  G4Analysis::Tokenize(newValues, parameters);
346  // check consistency
347  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
348  // Should never happen but let's check anyway for consistency
349  Exception(command, parameters.size());
350  return;
351  }
352 
353  if ( command == fCreateH2Cmd ) {
354  G4int counter = 0;
355  G4String name = parameters[counter++];
356  G4String title = parameters[counter++];
357  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
358  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
359  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
360  G4String xsunit = parameters[counter++];
361  G4String xsfcn = parameters[counter++];
362  G4String xsbinScheme = parameters[counter++];
363  G4int ynbins = G4UIcommand::ConvertToInt(parameters[counter++]);
364  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
365  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
366  G4String ysunit = parameters[counter++];
367  G4String ysfcn = parameters[counter++];
368  G4String ysbinScheme = parameters[counter++];
369  fManager->CreateH2(name, title,
370  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
371  xsunit, ysunit, xsfcn, ysfcn, xsbinScheme, ysbinScheme);
372  }
373  else if ( command == fSetH2Cmd ) {
374  G4int counter = 0;
375  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
376  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
377  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
378  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
379  G4String xsunit = parameters[counter++];
380  G4String xsfcn = parameters[counter++];
381  G4String xsbinScheme = parameters[counter++];
382  G4int ynbins = G4UIcommand::ConvertToInt(parameters[counter++]);
383  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
384  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
385  G4String ysunit = parameters[counter++];
386  G4String ysfcn = parameters[counter++];
387  G4String ysbinScheme = parameters[counter++];
388  fManager->SetH2(id,
389  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
390  xsunit, ysunit, xsfcn, ysfcn, xsbinScheme, ysbinScheme);
391  }
392  else if ( command == fSetH2TitleCmd ) {
393  G4int counter = 0;
394  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
395  G4String title = parameters[counter++];
396  fManager->SetH2Title(id, title);
397  }
398  else if ( command == fSetH2XAxisCmd ) {
399  G4int counter = 0;
400  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
401  G4String xaxis = parameters[counter++];
402  fManager->SetH2XAxisTitle(id, xaxis);
403  }
404  else if ( command == fSetH2YAxisCmd ) {
405  G4int counter = 0;
406  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
407  G4String yaxis = parameters[counter++];
408  fManager->SetH2YAxisTitle(id, yaxis);
409  }
410  else if ( command == fSetH2ZAxisCmd ) {
411  G4int counter = 0;
412  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
413  G4String zaxis = parameters[counter++];
414  fManager->SetH2ZAxisTitle(id, zaxis);
415  }
416 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetH2XAxisCmd()
G4UIcommand * fSetH2Cmd
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetH2TitleCmd()
virtual ~G4H2Messenger()
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
G4bool SetH2YAxisTitle(G4int id, const G4String &title)
G4String name
Definition: TRTMaterials.hh:40
void SetDefaultValue(const char *theDefaultValue)
int G4int
Definition: G4Types.hh:78
G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
G4UIcommand * fSetH2XAxisCmd
void SetH2ZAxisCmd()
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetH2YAxisCmd()
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:429
G4UIdirectory * fH2Dir
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4UIcommand * fSetH2ZAxisCmd
G4UIcommand * fSetH2YAxisCmd
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:421
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
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")
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
G4bool SetH2Title(G4int id, const G4String &title)
G4VAnalysisManager * fManager
Associated class.
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
void CreateH2Cmd()
virtual void SetNewValue(G4UIcommand *command, G4String value)
#define G4endl
Definition: G4ios.hh:61
G4UIcommand * fSetH2TitleCmd
void Exception(const char *originOfException, const char *exceptionCode, ExceptionSeverity severity, int level, const char *description)
Definition: UUtils.cc:122
double G4double
Definition: G4Types.hh:76
G4UIcommand * fCreateH2Cmd
void SetGuidance(const char *theGuidance)
G4H2Messenger(G4VAnalysisManager *manager)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool SetH2XAxisTitle(G4int id, const G4String &title)
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 &xbinScheme="linear", const G4String &ybinScheme="linear")