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