Geant4  10.00.p02
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).\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  h2xValFcn0->SetGuidance(fcnxGuidance);
129  h2xValFcn0->SetParameterCandidates("log log10 exp none");
130  h2xValFcn0->SetDefaultValue("none");
131 
132  G4UIparameter* h2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
133  h2yNbins0->SetGuidance("Number of y-bins (default = 100)");
134  h2yNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
135  h2yNbins0->SetDefaultValue(100);
136 
137  G4UIparameter* h2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
138  h2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
139  h2yValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
140  h2yValMin0->SetDefaultValue(0.);
141 
142  G4UIparameter* h2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
143  h2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
144  h2yValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
145  h2yValMax0->SetDefaultValue(1.);
146 
147  G4UIparameter* h2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
148  h2yValUnit0->SetGuidance("The unit of xvalMin0 and yvalMax0");
149  h2yValUnit0->SetDefaultValue("none");
150 
151  G4UIparameter* h2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
152  G4String fcnyGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
153  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
154  fcnyGuidance += "but none value should be used insted.";
155  h2yValFcn0->SetGuidance(fcnyGuidance);
156  h2yValFcn0->SetParameterCandidates("log log10 exp none");
157  h2yValFcn0->SetDefaultValue("none");
158 
159  fCreateH2Cmd = new G4UIcommand("/analysis/h2/create", this);
160  fCreateH2Cmd->SetGuidance("Create 2D histogram");
161  fCreateH2Cmd->SetParameter(h2Name);
162  fCreateH2Cmd->SetParameter(h2Title);
163  fCreateH2Cmd->SetParameter(h2xNbins0);
164  fCreateH2Cmd->SetParameter(h2xValMin0);
165  fCreateH2Cmd->SetParameter(h2xValMax0);
166  fCreateH2Cmd->SetParameter(h2xValUnit0);
167  fCreateH2Cmd->SetParameter(h2xValFcn0);
168  fCreateH2Cmd->SetParameter(h2yNbins0);
169  fCreateH2Cmd->SetParameter(h2yValMin0);
170  fCreateH2Cmd->SetParameter(h2yValMax0);
171  fCreateH2Cmd->SetParameter(h2yValUnit0);
172  fCreateH2Cmd->SetParameter(h2yValFcn0);
174 }
175 
176 
177 //_____________________________________________________________________________
179 {
180  G4UIparameter* h2Id = new G4UIparameter("id", 'i', false);
181  h2Id->SetGuidance("Histogram id");
182  h2Id->SetParameterRange("id>=0");
183 
184  G4UIparameter* h2xNbins = new G4UIparameter("xnbins", 'i', false);
185  h2xNbins->SetGuidance("Number of x-bins");
186 
187  G4UIparameter* h2xValMin = new G4UIparameter("xvalMin", 'd', false);
188  h2xValMin->SetGuidance("Minimum x-value, expressed in unit");
189 
190  G4UIparameter* h2xValMax = new G4UIparameter("xvalMax", 'd', false);
191  h2xValMax->SetGuidance("Maximum x-value, expressed in unit");
192 
193  G4UIparameter* h2xValFcn = new G4UIparameter("xvalFcn", 's', false);
194  h2xValFcn->SetParameterCandidates("log log10 exp none");
195  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
196  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
197  fcnxGuidance += "but none value should be used insted.";
198  h2xValFcn->SetGuidance(fcnxGuidance);
199  h2xValFcn->SetDefaultValue("none");
200 
201  G4UIparameter* h2yValUnit = new G4UIparameter("yvalUnit", 's', false);
202  h2yValUnit->SetGuidance("The unit of yvalMin and yvalMax");
203  h2yValUnit->SetDefaultValue("none");
204 
205  G4UIparameter* h2yNbins = new G4UIparameter("nybins", 'i', false);
206  h2yNbins->SetGuidance("Number of y-bins");
207 
208  G4UIparameter* h2yValMin = new G4UIparameter("yvalMin", 'd', false);
209  h2yValMin->SetGuidance("Minimum y-value, expressed in unit");
210 
211  G4UIparameter* h2yValMax = new G4UIparameter("yvalMax", 'd', false);
212  h2yValMax->SetGuidance("Maximum y-value, expressed in unit");
213 
214  G4UIparameter* h2xValUnit = new G4UIparameter("xvalUnit", 's', true);
215  h2xValUnit->SetGuidance("The unit of xvalMin and xvalMax");
216  h2xValUnit->SetDefaultValue("none");
217 
218  G4UIparameter* h2yValFcn = new G4UIparameter("yvalFcn", 's', false);
219  h2yValFcn->SetParameterCandidates("log log10 exp none");
220  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
221  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
222  fcnyGuidance += "but none value should be used insted.";
223  h2yValFcn->SetGuidance(fcnyGuidance);
224  h2yValFcn->SetDefaultValue("none");
225 
226  fSetH2Cmd = new G4UIcommand("/analysis/h2/set", this);
227  fSetH2Cmd->SetGuidance("Set parameters for the 2D histogram of #Id :");
228  fSetH2Cmd->SetGuidance(" nbins; valMin; valMax; unit (of vmin and vmax)");
229  fSetH2Cmd->SetParameter(h2Id);
230  fSetH2Cmd->SetParameter(h2xNbins);
231  fSetH2Cmd->SetParameter(h2xValMin);
232  fSetH2Cmd->SetParameter(h2xValMax);
233  fSetH2Cmd->SetParameter(h2xValUnit);
234  fSetH2Cmd->SetParameter(h2xValFcn);
235  fSetH2Cmd->SetParameter(h2yNbins);
236  fSetH2Cmd->SetParameter(h2yValMin);
237  fSetH2Cmd->SetParameter(h2yValMax);
238  fSetH2Cmd->SetParameter(h2yValUnit);
239  fSetH2Cmd->SetParameter(h2yValFcn);
241 }
242 
243 //_____________________________________________________________________________
245 {
246  G4UIparameter* h2Id = new G4UIparameter("idTitle", 'i', false);
247  h2Id->SetGuidance("Histogram id");
248  h2Id->SetParameterRange("idTitle>=0");
249 
250  G4UIparameter* h2Title = new G4UIparameter("h2Title", 's', true);
251  h2Title->SetGuidance("Histogram title");
252  h2Title->SetDefaultValue("none");
253 
254  fSetH2TitleCmd = new G4UIcommand("/analysis/h2/setTitle", this);
255  fSetH2TitleCmd->SetGuidance("Set title for the 2D histogram of #Id");
257  fSetH2TitleCmd->SetParameter(h2Title);
259 }
260 
261 //_____________________________________________________________________________
263 {
264  G4UIparameter* h2Id = new G4UIparameter("idXaxis", 'i', false);
265  h2Id->SetGuidance("Histogram id");
266  h2Id->SetParameterRange("idXaxis>=0");
267 
268  G4UIparameter* h2XAxis = new G4UIparameter("h2Xaxis", 's', true);
269  h2XAxis->SetGuidance("Histogram x-axis title");
270  h2XAxis->SetDefaultValue("none");
271 
272  fSetH2XAxisCmd = new G4UIcommand("/analysis/h2/setXaxis", this);
273  fSetH2XAxisCmd->SetGuidance("Set x-axis title for the 2D histogram of #Id");
275  fSetH2XAxisCmd->SetParameter(h2XAxis);
277 }
278 
279 //_____________________________________________________________________________
281 {
282  G4UIparameter* h2Id = new G4UIparameter("idYaxis", 'i', false);
283  h2Id->SetGuidance("Histogram id");
284  h2Id->SetParameterRange("idYaxis>=0");
285 
286  G4UIparameter* h2YAxis = new G4UIparameter("h2Yaxis", 's', true);
287  h2YAxis->SetGuidance("Histogram y-axis title");
288  h2YAxis->SetDefaultValue("none");
289 
290  fSetH2YAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
291  fSetH2YAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
293  fSetH2YAxisCmd->SetParameter(h2YAxis);
295 }
296 
297 //_____________________________________________________________________________
299 {
300  G4UIparameter* h2Id = new G4UIparameter("idYaxis", 'i', false);
301  h2Id->SetGuidance("Histogram id");
302  h2Id->SetParameterRange("idYaxis>=0");
303 
304  G4UIparameter* h2YAxis = new G4UIparameter("h2Yaxis", 's', true);
305  h2YAxis->SetGuidance("Histogram y-axis title");
306  h2YAxis->SetDefaultValue("none");
307 
308  fSetH2ZAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
309  fSetH2ZAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
311  fSetH2ZAxisCmd->SetParameter(h2YAxis);
313 }
314 
315 //
316 // public functions
317 //
318 
319 //_____________________________________________________________________________
321 {
322  // tokenize parameters in a vector
323  std::vector<G4String> parameters;
324  G4Analysis::Tokenize(newValues, parameters);
325  // check consistency
326  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
327  // Should never happen but let's check anyway for consistency
328  Exception(command, parameters.size());
329  return;
330  }
331 
332  if ( command == fCreateH2Cmd ) {
333  G4int counter = 0;
334  G4String name = parameters[counter++];
335  G4String title = parameters[counter++];
336  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
337  G4int ynbins = G4UIcommand::ConvertToInt(parameters[counter++]);
338  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
339  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
340  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
341  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
342  G4String xsunit = parameters[counter++];
343  G4String ysunit = parameters[counter++];
344  G4String xsfcn = parameters[counter++];
345  G4String ysfcn = parameters[counter++];
346  G4String xsbinScheme = parameters[counter++];
347  G4String ysbinScheme = parameters[counter++];
348  fManager->CreateH2(name, title,
349  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
350  ysunit, ysfcn, ysunit, ysfcn);
351  }
352  else if ( command == fSetH2Cmd ) {
353  G4int counter = 0;
354  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
355  G4int xnbins = G4UIcommand::ConvertToInt(parameters[counter++]);
356  G4int ynbins = G4UIcommand::ConvertToInt(parameters[counter++]);
357  G4double xvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
358  G4double xvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
359  G4double yvmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
360  G4double yvmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
361  G4String xsunit = parameters[counter++];
362  G4String ysunit = parameters[counter++];
363  G4String xsfcn = parameters[counter++];
364  G4String ysfcn = parameters[counter++];
365  fManager->SetH2(id,
366  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
367  ysunit, ysfcn, ysunit, ysfcn);
368  }
369  else if ( command == fSetH2TitleCmd ) {
370  G4int counter = 0;
371  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
372  G4String title = parameters[counter++];
373  fManager->SetH2Title(id, title);
374  }
375  else if ( command == fSetH2XAxisCmd ) {
376  G4int counter = 0;
377  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
378  G4String xaxis = parameters[counter++];
379  fManager->SetH2XAxisTitle(id, xaxis);
380  }
381  else if ( command == fSetH2YAxisCmd ) {
382  G4int counter = 0;
383  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
384  G4String yaxis = parameters[counter++];
385  fManager->SetH2YAxisTitle(id, yaxis);
386  }
387  else if ( command == fSetH2ZAxisCmd ) {
388  G4int counter = 0;
389  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
390  G4String zaxis = parameters[counter++];
391  fManager->SetH2ZAxisTitle(id, zaxis);
392  }
393 }
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")