Geant4_10
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 
33 #include "G4UIdirectory.hh"
34 #include "G4UIcommand.hh"
35 #include "G4UIparameter.hh"
36 
37 #include <iostream>
38 
39 //_____________________________________________________________________________
41  : G4UImessenger(),
42  fManager(manager),
43  fH2Dir(0),
44  fCreateH2Cmd(0),
45  fSetH2Cmd(0),
46  fSetH2TitleCmd(0),
47  fSetH2XAxisCmd(0),
48  fSetH2YAxisCmd(0)
49 {
50  fH2Dir = new G4UIdirectory("/analysis/h2/");
51  fH2Dir->SetGuidance("2D histograms control");
52 
53  CreateH2Cmd();
54  SetH2Cmd();
55 
56  SetH2TitleCmd();
57  SetH2XAxisCmd();
58  SetH2YAxisCmd();
59  SetH2ZAxisCmd();
60 }
61 
62 //_____________________________________________________________________________
64 {
65  delete fCreateH2Cmd;
66  delete fSetH2Cmd;
67  delete fSetH2TitleCmd;
68  delete fSetH2XAxisCmd;
69  delete fSetH2YAxisCmd;
70  delete fSetH2ZAxisCmd;
71  delete fH2Dir;
72 }
73 
74 //
75 // private functions
76 //
77 
78 //_____________________________________________________________________________
79 void G4H2Messenger::CreateH2Cmd()
80 {
81  G4UIparameter* h2Name = new G4UIparameter("name", 's', false);
82  h2Name->SetGuidance("Histogram name (label)");
83 
84  G4UIparameter* h2Title = new G4UIparameter("title", 's', false);
85  h2Title->SetGuidance("Histogram title");
86 
87  G4UIparameter* h2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
88  h2xNbins0->SetGuidance("Number of x-bins (default = 100)");
89  h2xNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
90  h2xNbins0->SetDefaultValue(100);
91 
92  G4UIparameter* h2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
93  h2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
94  h2xValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
95  h2xValMin0->SetDefaultValue(0.);
96 
97  G4UIparameter* h2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
98  h2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
99  h2xValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
100  h2xValMax0->SetDefaultValue(1.);
101 
102  G4UIparameter* h2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
103  h2xValUnit0->SetGuidance("The unit of xvalMin0 and xvalMax0");
104  h2xValUnit0->SetDefaultValue("none");
105 
106  G4UIparameter* h2xValFcn0 = 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  h2xValFcn0->SetGuidance(fcnxGuidance);
111  h2xValFcn0->SetParameterCandidates("log log10 exp none");
112  h2xValFcn0->SetDefaultValue("none");
113 
114  G4UIparameter* h2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
115  h2yNbins0->SetGuidance("Number of y-bins (default = 100)");
116  h2yNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
117  h2yNbins0->SetDefaultValue(100);
118 
119  G4UIparameter* h2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
120  h2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
121  h2yValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
122  h2yValMin0->SetDefaultValue(0.);
123 
124  G4UIparameter* h2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
125  h2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
126  h2yValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
127  h2yValMax0->SetDefaultValue(1.);
128 
129  G4UIparameter* h2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
130  h2yValUnit0->SetGuidance("The unit of xvalMin0 and yvalMax0");
131  h2yValUnit0->SetDefaultValue("none");
132 
133  G4UIparameter* h2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
134  G4String fcnyGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
135  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
136  fcnyGuidance += "but none value should be used insted.";
137  h2yValFcn0->SetGuidance(fcnyGuidance);
138  h2yValFcn0->SetParameterCandidates("log log10 exp none");
139  h2yValFcn0->SetDefaultValue("none");
140 
141  fCreateH2Cmd = new G4UIcommand("/analysis/h2/create", this);
142  fCreateH2Cmd->SetGuidance("Create 2D histogram");
143  fCreateH2Cmd->SetParameter(h2Name);
144  fCreateH2Cmd->SetParameter(h2Title);
145  fCreateH2Cmd->SetParameter(h2xNbins0);
146  fCreateH2Cmd->SetParameter(h2xValMin0);
147  fCreateH2Cmd->SetParameter(h2xValMax0);
148  fCreateH2Cmd->SetParameter(h2xValUnit0);
149  fCreateH2Cmd->SetParameter(h2xValFcn0);
150  fCreateH2Cmd->SetParameter(h2yNbins0);
151  fCreateH2Cmd->SetParameter(h2yValMin0);
152  fCreateH2Cmd->SetParameter(h2yValMax0);
153  fCreateH2Cmd->SetParameter(h2yValUnit0);
154  fCreateH2Cmd->SetParameter(h2yValFcn0);
156 }
157 
158 
159 //_____________________________________________________________________________
160 void G4H2Messenger::SetH2Cmd()
161 {
162  G4UIparameter* h2Id = new G4UIparameter("id", 'i', false);
163  h2Id->SetGuidance("Histogram id");
164  h2Id->SetParameterRange("id>=0");
165 
166  G4UIparameter* h2xNbins = new G4UIparameter("xnbins", 'i', false);
167  h2xNbins->SetGuidance("Number of x-bins");
168 
169  G4UIparameter* h2xValMin = new G4UIparameter("xvalMin", 'd', false);
170  h2xValMin->SetGuidance("Minimum x-value, expressed in unit");
171 
172  G4UIparameter* h2xValMax = new G4UIparameter("xvalMax", 'd', false);
173  h2xValMax->SetGuidance("Maximum x-value, expressed in unit");
174 
175  G4UIparameter* h2xValFcn = new G4UIparameter("xvalFcn", 's', false);
176  h2xValFcn->SetParameterCandidates("log log10 exp none");
177  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
178  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
179  fcnxGuidance += "but none value should be used insted.";
180  h2xValFcn->SetGuidance(fcnxGuidance);
181  h2xValFcn->SetDefaultValue("none");
182 
183  G4UIparameter* h2yValUnit = new G4UIparameter("yvalUnit", 's', false);
184  h2yValUnit->SetGuidance("The unit of yvalMin and yvalMax");
185  h2yValUnit->SetDefaultValue("none");
186 
187  G4UIparameter* h2yNbins = new G4UIparameter("nybins", 'i', false);
188  h2yNbins->SetGuidance("Number of y-bins");
189 
190  G4UIparameter* h2yValMin = new G4UIparameter("yvalMin", 'd', false);
191  h2yValMin->SetGuidance("Minimum y-value, expressed in unit");
192 
193  G4UIparameter* h2yValMax = new G4UIparameter("yvalMax", 'd', false);
194  h2yValMax->SetGuidance("Maximum y-value, expressed in unit");
195 
196  G4UIparameter* h2xValUnit = new G4UIparameter("xvalUnit", 's', true);
197  h2xValUnit->SetGuidance("The unit of xvalMin and xvalMax");
198  h2xValUnit->SetDefaultValue("none");
199 
200  G4UIparameter* h2yValFcn = new G4UIparameter("yvalFcn", 's', false);
201  h2yValFcn->SetParameterCandidates("log log10 exp none");
202  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
203  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
204  fcnyGuidance += "but none value should be used insted.";
205  h2yValFcn->SetGuidance(fcnyGuidance);
206  h2yValFcn->SetDefaultValue("none");
207 
208  fSetH2Cmd = new G4UIcommand("/analysis/h2/set", this);
209  fSetH2Cmd->SetGuidance("Set parameters for the 2D histogram of #Id :");
210  fSetH2Cmd->SetGuidance(" nbins; valMin; valMax; unit (of vmin and vmax)");
211  fSetH2Cmd->SetParameter(h2Id);
212  fSetH2Cmd->SetParameter(h2xNbins);
213  fSetH2Cmd->SetParameter(h2xValMin);
214  fSetH2Cmd->SetParameter(h2xValMax);
215  fSetH2Cmd->SetParameter(h2xValUnit);
216  fSetH2Cmd->SetParameter(h2xValFcn);
217  fSetH2Cmd->SetParameter(h2yNbins);
218  fSetH2Cmd->SetParameter(h2yValMin);
219  fSetH2Cmd->SetParameter(h2yValMax);
220  fSetH2Cmd->SetParameter(h2yValUnit);
221  fSetH2Cmd->SetParameter(h2yValFcn);
223 }
224 
225 //_____________________________________________________________________________
226 void G4H2Messenger::SetH2TitleCmd()
227 {
228  G4UIparameter* h2Id = new G4UIparameter("idTitle", 'i', false);
229  h2Id->SetGuidance("Histogram id");
230  h2Id->SetParameterRange("idTitle>=0");
231 
232  G4UIparameter* h2Title = new G4UIparameter("h2Title", 's', true);
233  h2Title->SetGuidance("Histogram title");
234  h2Title->SetDefaultValue("none");
235 
236  fSetH2TitleCmd = new G4UIcommand("/analysis/h2/setTitle", this);
237  fSetH2TitleCmd->SetGuidance("Set title for the 2D histogram of #Id");
238  fSetH2TitleCmd->SetParameter(h2Id);
239  fSetH2TitleCmd->SetParameter(h2Title);
241 }
242 
243 //_____________________________________________________________________________
244 void G4H2Messenger::SetH2XAxisCmd()
245 {
246  G4UIparameter* h2Id = new G4UIparameter("idXaxis", 'i', false);
247  h2Id->SetGuidance("Histogram id");
248  h2Id->SetParameterRange("idXaxis>=0");
249 
250  G4UIparameter* h2XAxis = new G4UIparameter("h2Xaxis", 's', true);
251  h2XAxis->SetGuidance("Histogram x-axis title");
252  h2XAxis->SetDefaultValue("none");
253 
254  fSetH2XAxisCmd = new G4UIcommand("/analysis/h2/setXaxis", this);
255  fSetH2XAxisCmd->SetGuidance("Set x-axis title for the 2D histogram of #Id");
256  fSetH2XAxisCmd->SetParameter(h2Id);
257  fSetH2XAxisCmd->SetParameter(h2XAxis);
259 }
260 
261 //_____________________________________________________________________________
262 void G4H2Messenger::SetH2YAxisCmd()
263 {
264  G4UIparameter* h2Id = new G4UIparameter("idYaxis", 'i', false);
265  h2Id->SetGuidance("Histogram id");
266  h2Id->SetParameterRange("idYaxis>=0");
267 
268  G4UIparameter* h2YAxis = new G4UIparameter("h2Yaxis", 's', true);
269  h2YAxis->SetGuidance("Histogram y-axis title");
270  h2YAxis->SetDefaultValue("none");
271 
272  fSetH2YAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
273  fSetH2YAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
274  fSetH2YAxisCmd->SetParameter(h2Id);
275  fSetH2YAxisCmd->SetParameter(h2YAxis);
277 }
278 
279 //_____________________________________________________________________________
280 void G4H2Messenger::SetH2ZAxisCmd()
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  fSetH2ZAxisCmd = new G4UIcommand("/analysis/h2/setYaxis", this);
291  fSetH2ZAxisCmd->SetGuidance("Set y-axis title for the 2D histogram of #Id");
292  fSetH2ZAxisCmd->SetParameter(h2Id);
293  fSetH2ZAxisCmd->SetParameter(h2YAxis);
295 }
296 
297 //
298 // public functions
299 //
300 
301 //_____________________________________________________________________________
303 {
304  if ( command == fCreateH2Cmd ) {
306  G4int xnbins, ynbins;
307  G4double xvmin, xvmax, yvmin, yvmax;
308  G4String xsunit,xsfcn, ysunit, ysfcn;
309  std::istringstream is(newValues.data());
310  is >> name >> title
311  >> xnbins >> xvmin >> xvmax >> xsunit >> xsfcn
312  >> ynbins >> yvmin >> yvmax >> ysunit >> ysfcn;
313  fManager->CreateH2(name, title,
314  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
315  ysunit, ysfcn, ysunit, ysfcn);
316  }
317  else if ( command == fSetH2Cmd ) {
318  G4int id;
319  G4int xnbins, ynbins;
320  G4double xvmin, xvmax, yvmin, yvmax;
321  G4String xsunit,xsfcn, ysunit, ysfcn;
322  std::istringstream is(newValues.data());
323  is >> id
324  >> xnbins >> xvmin >> xvmax >> xsunit >> xsfcn
325  >> ynbins >> yvmin >> yvmax >> ysunit >> ysfcn;
326  fManager->SetH2(id,
327  xnbins, xvmin, xvmax, ynbins, yvmin, yvmax,
328  ysunit, ysfcn, ysunit, ysfcn);
329  }
330  else if ( command == fSetH2TitleCmd ) {
331  G4int id;
332  G4String title;
333  std::istringstream is(newValues.data());
334  is >> id;
335  getline(is, title);
336  fManager->SetH2Title(id, title);
337  }
338  else if ( command == fSetH2XAxisCmd ) {
339  G4int id;
340  G4String xaxis;
341  std::istringstream is(newValues.data());
342  is >> id;
343  getline(is, xaxis);
344  fManager->SetH2XAxisTitle(id, xaxis);
345  }
346  else if ( command == fSetH2YAxisCmd ) {
347  G4int id;
348  G4String yaxis;
349  std::istringstream is(newValues.data());
350  is >> id;
351  getline(is, yaxis);
352  fManager->SetH2YAxisTitle(id, yaxis);
353  }
354  else if ( command == fSetH2ZAxisCmd ) {
355  G4int id;
356  G4String zaxis;
357  std::istringstream is(newValues.data());
358  is >> id;
359  getline(is, zaxis);
360  fManager->SetH2ZAxisTitle(id, zaxis);
361  }
362 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
virtual ~G4H2Messenger()
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
G4bool SetH2YAxisTitle(G4int id, const G4String &title)
void SetDefaultValue(const char *theDefaultValue)
const XML_Char * name
Definition: expat.h:151
int G4int
Definition: G4Types.hh:78
G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
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")
G4bool SetH2Title(G4int id, const G4String &title)
const char * data() const
subroutine title(NA, NB, NCA, NCB)
Definition: dpm25nuc7.f:1744
virtual void SetNewValue(G4UIcommand *command, G4String value)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
G4H2Messenger(G4VAnalysisManager *manager)
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")