Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //_____________________________________________________________________________
44  : G4UImessenger(),
45  fManager(manager),
46  fHelper(nullptr),
47  fDirectory(nullptr),
48  fCreateH2Cmd(nullptr),
49  fSetH2Cmd(nullptr),
50  fSetH2XCmd(nullptr),
51  fSetH2YCmd(nullptr),
52  fSetH2TitleCmd(nullptr),
53  fSetH2XAxisCmd(nullptr),
54  fSetH2YAxisCmd(nullptr),
55  fXId(-1),
56  fXData()
57 {
58  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("h2");
59 
60  fDirectory = fHelper->CreateHnDirectory();
61 
62  CreateH2Cmd();
63 
64  SetH2Cmd();
65  fSetH2XCmd = fHelper->CreateSetBinsCommand("x", this);
66  fSetH2YCmd = fHelper->CreateSetBinsCommand("y", this);
67 
68  fSetH2TitleCmd = fHelper->CreateSetTitleCommand(this);
69  fSetH2XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
70  fSetH2YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
71  fSetH2ZAxisCmd = fHelper->CreateSetAxisCommand("z", this);
72 }
73 
74 //_____________________________________________________________________________
76 {}
77 
78 //
79 // private functions
80 //
81 
82 //_____________________________________________________________________________
83 void G4H2Messenger::CreateH2Cmd()
84 {
85  auto h2Name = new G4UIparameter("name", 's', false);
86  h2Name->SetGuidance("Histogram name (label)");
87 
88  auto h2Title = new G4UIparameter("title", 's', false);
89  h2Title->SetGuidance("Histogram title");
90 
91  auto h2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
92  h2xNbins0->SetGuidance("Number of x-bins (default = 100)");
93  h2xNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
94  h2xNbins0->SetDefaultValue(100);
95 
96  auto h2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
97  h2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
98  h2xValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
99  h2xValMin0->SetDefaultValue(0.);
100 
101  auto h2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
102  h2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
103  h2xValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
104  h2xValMax0->SetDefaultValue(1.);
105 
106  auto h2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
107  h2xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
108  h2xValUnit0->SetDefaultValue("none");
109 
110  auto h2xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
111  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
112  h2xValFcn0->SetGuidance(fcnxGuidance);
113  h2xValFcn0->SetParameterCandidates("log log10 exp none");
114  h2xValFcn0->SetDefaultValue("none");
115 
116  auto h2xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
117  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
118  h2xValBinScheme0->SetParameterCandidates("linear log");
119  h2xValBinScheme0->SetGuidance(xbinSchemeGuidance);
120  h2xValBinScheme0->SetDefaultValue("linear");
121 
122  auto h2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
123  h2yNbins0->SetGuidance("Number of y-bins (default = 100)");
124  h2yNbins0->SetGuidance("Can be reset with /analysis/h2/set command");
125  h2yNbins0->SetDefaultValue(100);
126 
127  auto h2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
128  h2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
129  h2yValMin0->SetGuidance("Can be reset with /analysis/h2/set command");
130  h2yValMin0->SetDefaultValue(0.);
131 
132  auto h2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
133  h2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
134  h2yValMax0->SetGuidance("Can be reset with /analysis/h2/set command");
135  h2yValMax0->SetDefaultValue(1.);
136 
137  auto h2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
138  h2yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
139  h2yValUnit0->SetDefaultValue("none");
140 
141  auto h2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
142  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
143  h2yValFcn0->SetGuidance(fcnyGuidance);
144  h2yValFcn0->SetParameterCandidates("log log10 exp none");
145  h2yValFcn0->SetDefaultValue("none");
146 
147  auto h2yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
148  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
149  h2yValBinScheme0->SetParameterCandidates("linear log");
150  h2yValBinScheme0->SetGuidance(ybinSchemeGuidance);
151  h2yValBinScheme0->SetDefaultValue("linear");
152 
153  fCreateH2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h2/create", this);
154  fCreateH2Cmd->SetGuidance("Create 2D histogram");
155  fCreateH2Cmd->SetParameter(h2Name);
156  fCreateH2Cmd->SetParameter(h2Title);
157  fCreateH2Cmd->SetParameter(h2xNbins0);
158  fCreateH2Cmd->SetParameter(h2xValMin0);
159  fCreateH2Cmd->SetParameter(h2xValMax0);
160  fCreateH2Cmd->SetParameter(h2xValUnit0);
161  fCreateH2Cmd->SetParameter(h2xValFcn0);
162  fCreateH2Cmd->SetParameter(h2xValBinScheme0);
163  fCreateH2Cmd->SetParameter(h2yNbins0);
164  fCreateH2Cmd->SetParameter(h2yValMin0);
165  fCreateH2Cmd->SetParameter(h2yValMax0);
166  fCreateH2Cmd->SetParameter(h2yValUnit0);
167  fCreateH2Cmd->SetParameter(h2yValFcn0);
168  fCreateH2Cmd->SetParameter(h2yValBinScheme0);
169  fCreateH2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
170 }
171 
172 
173 //_____________________________________________________________________________
174 void G4H2Messenger::SetH2Cmd()
175 {
176  auto h2Id = new G4UIparameter("id", 'i', false);
177  h2Id->SetGuidance("Histogram id");
178  h2Id->SetParameterRange("id>=0");
179 
180  auto h2xNbins = new G4UIparameter("xnbins", 'i', false);
181  h2xNbins->SetGuidance("Number of x-bins");
182 
183  auto h2xValMin = new G4UIparameter("xvalMin", 'd', false);
184  h2xValMin->SetGuidance("Minimum x-value, expressed in unit");
185 
186  auto h2xValMax = new G4UIparameter("xvalMax", 'd', false);
187  h2xValMax->SetGuidance("Maximum x-value, expressed in unit");
188 
189  auto h2xValUnit = new G4UIparameter("xvalUnit", 's', false);
190  h2xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin, xvalMax");
191  h2xValUnit->SetDefaultValue("none");
192 
193  auto 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).";
196  h2xValFcn->SetGuidance(fcnxGuidance);
197  h2xValFcn->SetDefaultValue("none");
198 
199  auto h2xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
200  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
201  h2xValBinScheme->SetParameterCandidates("linear log");
202  h2xValBinScheme->SetGuidance(xbinSchemeGuidance);
203  h2xValBinScheme->SetDefaultValue("linear");
204 
205  auto h2yNbins = new G4UIparameter("nybins", 'i', false);
206  h2yNbins->SetGuidance("Number of y-bins");
207 
208  auto h2yValMin = new G4UIparameter("yvalMin", 'd', false);
209  h2yValMin->SetGuidance("Minimum y-value, expressed in unit");
210 
211  auto h2yValMax = new G4UIparameter("yvalMax", 'd', false);
212  h2yValMax->SetGuidance("Maximum y-value, expressed in unit");
213 
214  auto h2yValUnit = new G4UIparameter("yvalUnit", 's', true);
215  h2yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin, yvalMax");
216  h2yValUnit->SetDefaultValue("none");
217 
218  auto 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).";
221  h2yValFcn->SetGuidance(fcnyGuidance);
222  h2yValFcn->SetDefaultValue("none");
223 
224  auto h2yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
225  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
226  h2yValBinScheme->SetParameterCandidates("linear log");
227  h2yValBinScheme->SetGuidance(ybinSchemeGuidance);
228  h2yValBinScheme->SetDefaultValue("linear");
229 
230  fSetH2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h2/set", this);
231  fSetH2Cmd->SetGuidance("Set parameters for the 2D histogram of given id:");
232  fSetH2Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
233  fSetH2Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; yfunction; ybinScheme");
234  fSetH2Cmd->SetParameter(h2Id);
235  fSetH2Cmd->SetParameter(h2xNbins);
236  fSetH2Cmd->SetParameter(h2xValMin);
237  fSetH2Cmd->SetParameter(h2xValMax);
238  fSetH2Cmd->SetParameter(h2xValUnit);
239  fSetH2Cmd->SetParameter(h2xValFcn);
240  fSetH2Cmd->SetParameter(h2xValBinScheme);
241  fSetH2Cmd->SetParameter(h2yNbins);
242  fSetH2Cmd->SetParameter(h2yValMin);
243  fSetH2Cmd->SetParameter(h2yValMax);
244  fSetH2Cmd->SetParameter(h2yValUnit);
245  fSetH2Cmd->SetParameter(h2yValFcn);
246  fSetH2Cmd->SetParameter(h2yValBinScheme);
247  fSetH2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
248 }
249 
250 
251 //
252 // public functions
253 //
254 
255 //_____________________________________________________________________________
257 {
258  // tokenize parameters in a vector
259  std::vector<G4String> parameters;
260  G4Analysis::Tokenize(newValues, parameters);
261  // check consistency
262  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
263  // Should never happen but let's check anyway for consistency
264  fHelper->WarnAboutParameters(command, parameters.size());
265  return;
266  }
267 
268  if ( command == fCreateH2Cmd.get() ) {
269  auto counter = 0;
270  auto name = parameters[counter++];
271  auto title = parameters[counter++];
273  fHelper->GetBinData(xdata, parameters, counter);
274  auto xunit = GetUnitValue(xdata.fSunit);
276  fHelper->GetBinData(ydata, parameters, counter);
277  auto yunit = GetUnitValue(ydata.fSunit);
278  fManager->CreateH2(name, title,
279  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
280  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
281  xdata.fSunit, ydata.fSunit,
282  xdata.fSfcn, ydata.fSfcn,
283  xdata.fSbinScheme, ydata.fSbinScheme);
284  }
285  else if ( command == fSetH2Cmd.get() ) {
286  auto counter = 0;
287  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
289  fHelper->GetBinData(xdata, parameters, counter);
290  auto xunit = GetUnitValue(xdata.fSunit);
292  fHelper->GetBinData(ydata, parameters, counter);
293  auto yunit = GetUnitValue(ydata.fSunit);
294  fManager->SetH2(id,
295  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
296  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
297  xdata.fSunit, ydata.fSunit,
298  xdata.fSfcn, ydata.fSfcn,
299  xdata.fSbinScheme, ydata.fSbinScheme);
300  }
301  else if ( command == fSetH2XCmd.get() ) {
302  // Only save values
303  auto counter = 0;
304  fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
305  fHelper->GetBinData(fXData, parameters, counter);
306  }
307  else if ( command == fSetH2YCmd.get() ) {
308  // Check if setX command was called
309  auto counter = 0;
310  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
311  if ( fXId == -1 || fXId != id ) {
312  fHelper->WarnAboutSetCommands();
313  return;
314  }
315  auto xunit = GetUnitValue(fXData.fSunit);
317  fHelper->GetBinData(ydata, parameters, counter);
318  auto yunit = GetUnitValue(ydata.fSunit);
319  fManager->SetH2(id,
320  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
321  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
322  fXData.fSunit, ydata.fSunit,
323  fXData.fSfcn, ydata.fSfcn,
324  fXData.fSbinScheme, ydata.fSbinScheme);
325  fXId = -1;
326  }
327  else if ( command == fSetH2TitleCmd.get() ) {
328  auto counter = 0;
329  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
330  auto title = parameters[counter++];
331  fManager->SetH2Title(id, title);
332  }
333  else if ( command == fSetH2XAxisCmd.get() ) {
334  auto counter = 0;
335  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
336  auto xaxis = parameters[counter++];
337  fManager->SetH2XAxisTitle(id, xaxis);
338  }
339  else if ( command == fSetH2YAxisCmd.get() ) {
340  auto counter = 0;
341  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
342  auto yaxis = parameters[counter++];
343  fManager->SetH2YAxisTitle(id, yaxis);
344  }
345  else if ( command == fSetH2ZAxisCmd.get() ) {
346  auto counter = 0;
347  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
348  auto zaxis = parameters[counter++];
349  fManager->SetH2ZAxisTitle(id, zaxis);
350  }
351 }
const XML_Char * name
Definition: expat.h:151
virtual ~G4H2Messenger()
G4bool SetH2YAxisTitle(G4int id, const G4String &title)
int G4int
Definition: G4Types.hh:78
G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
G4double GetUnitValue(const G4String &unit)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:447
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)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
subroutine title
Definition: hijing1.383.f:5980
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)
virtual void SetNewValue(G4UIcommand *command, G4String value) final