Geant4  10.02.p01
G4P2Messenger.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$
27 
28 // Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4P2Messenger.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  fCreateP2Cmd(nullptr),
49  fSetP2Cmd(nullptr),
50  fSetP2XCmd(nullptr),
51  fSetP2YCmd(nullptr),
52  fSetP2ZCmd(nullptr),
53  fSetP2TitleCmd(nullptr),
54  fSetP2XAxisCmd(nullptr),
55  fSetP2YAxisCmd(nullptr)
56 {
57  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p2");
58 
59  fDirectory = fHelper->CreateHnDirectory();
60 
61  CreateP2Cmd();
62 
63  SetP2Cmd();
64  fSetP2XCmd = fHelper->CreateSetBinsCommand("x", this);
65  fSetP2YCmd = fHelper->CreateSetBinsCommand("y", this);
66  fSetP2YCmd = fHelper->CreateSetValuesCommand("z", this);
67 
68  fSetP2TitleCmd = fHelper->CreateSetTitleCommand(this);
69  fSetP2XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
70  fSetP2YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
71  fSetP2ZAxisCmd = fHelper->CreateSetAxisCommand("z", this);
72 }
73 
74 //_____________________________________________________________________________
76 {}
77 
78 //
79 // private functions
80 //
81 
82 //_____________________________________________________________________________
84 {
85  auto p2Name = new G4UIparameter("name", 's', false);
86  p2Name->SetGuidance("Profile name (label)");
87 
88  auto p2Title = new G4UIparameter("title", 's', false);
89  p2Title->SetGuidance("Profile title");
90 
91  auto p2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
92  p2xNbins0->SetGuidance("Number of x-bins (default = 100)");
93  p2xNbins0->SetGuidance("Can be reset with /analysis/p2/set command");
94  p2xNbins0->SetDefaultValue(100);
95 
96  auto p2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
97  p2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
98  p2xValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
99  p2xValMin0->SetDefaultValue(0.);
100 
101  auto p2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
102  p2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
103  p2xValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
104  p2xValMax0->SetDefaultValue(1.);
105 
106  auto p2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
107  p2xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
108  p2xValUnit0->SetDefaultValue("none");
109 
110  auto p2xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
111  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
112  p2xValFcn0->SetGuidance(fcnxGuidance);
113  p2xValFcn0->SetParameterCandidates("log log10 exp none");
114  p2xValFcn0->SetDefaultValue("none");
115 
116  auto p2xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
117  G4String binSchemeGuidance = "The binning scheme (linear, log).";
118  p2xValBinScheme0->SetParameterCandidates("linear log");
119  p2xValBinScheme0->SetGuidance(binSchemeGuidance);
120  p2xValBinScheme0->SetDefaultValue("linear");
121 
122  auto p2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
123  p2yNbins0->SetGuidance("Number of y-bins (default = 100)");
124  p2yNbins0->SetGuidance("Can be reset with /analysis/p2/set command");
125  p2yNbins0->SetDefaultValue(100);
126 
127  auto p2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
128  p2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
129  p2yValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
130  p2yValMin0->SetDefaultValue(0.);
131 
132  auto p2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
133  p2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
134  p2yValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
135  p2yValMax0->SetDefaultValue(1.);
136 
137  auto p2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
138  p2yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
139  p2yValUnit0->SetDefaultValue("none");
140 
141  auto p2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
142  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
143  p2yValFcn0->SetGuidance(fcnyGuidance);
144  p2yValFcn0->SetParameterCandidates("log log10 exp none");
145  p2yValFcn0->SetDefaultValue("none");
146 
147  auto p2yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
148  p2yValBinScheme0->SetParameterCandidates("linear log");
149  p2yValBinScheme0->SetGuidance(binSchemeGuidance);
150  p2yValBinScheme0->SetDefaultValue("linear");
151 
152  auto p2zValMin0 = new G4UIparameter("zvalMin0", 'd', true);
153  p2zValMin0->SetGuidance("Minimum z-value, expressed in unit (default = 0.)");
154  p2zValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
155  p2zValMin0->SetDefaultValue(0.);
156 
157  auto p2zValMax0 = new G4UIparameter("zvalMax0", 'd', true);
158  p2zValMax0->SetGuidance("Maximum z-value, expressed in unit (default = 1.)");
159  p2zValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
160  p2zValMax0->SetDefaultValue(1.);
161 
162  auto p2zValUnit0 = new G4UIparameter("zvalUnit0", 's', true);
163  p2zValUnit0->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
164  p2zValUnit0->SetDefaultValue("none");
165 
166  auto p2zValFcn0 = new G4UIparameter("zvalFcn0", 's', true);
167  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
168  p2zValFcn0->SetGuidance(fcnzGuidance);
169  p2zValFcn0->SetParameterCandidates("log log10 exp none");
170  p2zValFcn0->SetDefaultValue("none");
171 
172  fCreateP2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p2/create", this);
173  fCreateP2Cmd->SetGuidance("Create 2D profile");
174  fCreateP2Cmd->SetParameter(p2Name);
175  fCreateP2Cmd->SetParameter(p2Title);
176  fCreateP2Cmd->SetParameter(p2xNbins0);
177  fCreateP2Cmd->SetParameter(p2xValMin0);
178  fCreateP2Cmd->SetParameter(p2xValMax0);
179  fCreateP2Cmd->SetParameter(p2xValUnit0);
180  fCreateP2Cmd->SetParameter(p2xValFcn0);
181  fCreateP2Cmd->SetParameter(p2xValBinScheme0);
182  fCreateP2Cmd->SetParameter(p2yNbins0);
183  fCreateP2Cmd->SetParameter(p2yValMin0);
184  fCreateP2Cmd->SetParameter(p2yValMax0);
185  fCreateP2Cmd->SetParameter(p2yValUnit0);
186  fCreateP2Cmd->SetParameter(p2yValFcn0);
187  fCreateP2Cmd->SetParameter(p2yValBinScheme0);
188  fCreateP2Cmd->SetParameter(p2zValMin0);
189  fCreateP2Cmd->SetParameter(p2zValMax0);
190  fCreateP2Cmd->SetParameter(p2zValUnit0);
191  fCreateP2Cmd->SetParameter(p2zValFcn0);
192  fCreateP2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
193 }
194 
195 
196 //_____________________________________________________________________________
198 {
199  auto p2Id = new G4UIparameter("id", 'i', false);
200  p2Id->SetGuidance("Profile id");
201  p2Id->SetParameterRange("id>=0");
202 
203  auto p2xNbins = new G4UIparameter("xnbins", 'i', false);
204  p2xNbins->SetGuidance("Number of x-bins");
205 
206  auto p2xValMin = new G4UIparameter("xvalMin", 'd', false);
207  p2xValMin->SetGuidance("Minimum x-value, expressed in unit");
208 
209  auto p2xValMax = new G4UIparameter("xvalMax", 'd', false);
210  p2xValMax->SetGuidance("Maximum x-value, expressed in unit");
211 
212  auto p2xValUnit = new G4UIparameter("xvalUnit", 's', false);
213  p2xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
214  p2xValUnit->SetDefaultValue("none");
215 
216  auto p2xValFcn = new G4UIparameter("xvalFcn", 's', false);
217  p2xValFcn->SetParameterCandidates("log log10 exp none");
218  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
219  p2xValFcn->SetGuidance(fcnxGuidance);
220  p2xValFcn->SetDefaultValue("none");
221 
222  auto p2xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
223  G4String binSchemeGuidance = "The binning scheme (linear, log).";
224  p2xValBinScheme->SetParameterCandidates("linear log");
225  p2xValBinScheme->SetGuidance(binSchemeGuidance);
226  p2xValBinScheme->SetDefaultValue("linear");
227 
228  auto p2yNbins = new G4UIparameter("nybins", 'i', false);
229  p2yNbins->SetGuidance("Number of y-bins");
230 
231  auto p2yValMin = new G4UIparameter("yvalMin", 'd', false);
232  p2yValMin->SetGuidance("Minimum y-value, expressed in unit");
233 
234  auto p2yValMax = new G4UIparameter("yvalMax", 'd', false);
235  p2yValMax->SetGuidance("Maximum y-value, expressed in unit");
236 
237  auto p2yValUnit = new G4UIparameter("yvalUnit", 's', true);
238  p2yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
239  p2yValUnit->SetDefaultValue("none");
240 
241  auto p2yValFcn = new G4UIparameter("yvalFcn", 's', false);
242  p2yValFcn->SetParameterCandidates("log log10 exp none");
243  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
244  p2yValFcn->SetGuidance(fcnyGuidance);
245  p2yValFcn->SetDefaultValue("none");
246 
247  auto p2yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
248  p2yValBinScheme->SetParameterCandidates("linear log");
249  p2yValBinScheme->SetGuidance(binSchemeGuidance);
250  p2yValBinScheme->SetDefaultValue("linear");
251 
252  auto p2zValMin = new G4UIparameter("zvalMin", 'd', false);
253  p2zValMin->SetGuidance("Minimum z-value, expressed in unit");
254 
255  auto p2zValMax = new G4UIparameter("zvalMax", 'd', false);
256  p2zValMax->SetGuidance("Maximum z-value, expressed in unit");
257 
258  auto p2zValUnit = new G4UIparameter("zvalUnit", 's', true);
259  p2zValUnit->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
260  p2zValUnit->SetDefaultValue("none");
261 
262  auto p2zValFcn = new G4UIparameter("zvalFcn", 's', false);
263  p2zValFcn->SetParameterCandidates("log log10 exp none");
264  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
265  p2zValFcn->SetGuidance(fcnzGuidance);
266  p2zValFcn->SetDefaultValue("none");
267 
268  fSetP2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p2/set", this);
269  fSetP2Cmd->SetGuidance("Set parameters for the 2D profile of given id:");
270  fSetP2Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xbinScheme");
271  fSetP2Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; ybinScheme");
272  fSetP2Cmd->SetGuidance(" zvalMin; zvalMax; zunit; zfunction");
273  fSetP2Cmd->SetParameter(p2Id);
274  fSetP2Cmd->SetParameter(p2xNbins);
275  fSetP2Cmd->SetParameter(p2xValMin);
276  fSetP2Cmd->SetParameter(p2xValMax);
277  fSetP2Cmd->SetParameter(p2xValUnit);
278  fSetP2Cmd->SetParameter(p2xValFcn);
279  fSetP2Cmd->SetParameter(p2xValBinScheme);
280  fSetP2Cmd->SetParameter(p2yNbins);
281  fSetP2Cmd->SetParameter(p2yValMin);
282  fSetP2Cmd->SetParameter(p2yValMax);
283  fSetP2Cmd->SetParameter(p2yValUnit);
284  fSetP2Cmd->SetParameter(p2yValFcn);
285  fSetP2Cmd->SetParameter(p2yValBinScheme);
286  fSetP2Cmd->SetParameter(p2zValMin);
287  fSetP2Cmd->SetParameter(p2zValMax);
288  fSetP2Cmd->SetParameter(p2zValUnit);
289  fSetP2Cmd->SetParameter(p2zValFcn);
290  fSetP2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
291 }
292 
293 
294 //
295 // public functions
296 //
297 
298 //_____________________________________________________________________________
300 {
301  // tokenize parameters in a vector
302  std::vector<G4String> parameters;
303  G4Analysis::Tokenize(newValues, parameters);
304  // check consistency
305  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
306  // Should never happen but let's check anyway for consistency
307  fHelper->WarnAboutParameters(command, parameters.size());
308  return;
309  }
310 
311  if ( command == fCreateP2Cmd.get() ) {
312  auto counter = 0;
313  auto name = parameters[counter++];
314  auto title = parameters[counter++];
316  fHelper->GetBinData(xdata, parameters, counter);
317  auto xunit = GetUnitValue(xdata.fSunit);
319  fHelper->GetBinData(ydata, parameters, counter);
320  auto yunit = GetUnitValue(ydata.fSunit);
322  fHelper->GetValueData(zdata, parameters, counter);
323  auto zunit = GetUnitValue(zdata.fSunit);
324  fManager->CreateP2(name, title,
325  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
326  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
327  zdata.fVmin*zunit, zdata.fVmax*zunit,
328  xdata.fSunit, ydata.fSunit, zdata.fSunit,
329  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
330  xdata.fSbinScheme, ydata.fSbinScheme);
331  }
332  else if ( command == fSetP2Cmd.get() ) {
333  auto counter = 0;
334  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
336  fHelper->GetBinData(xdata, parameters, counter);
337  auto xunit = GetUnitValue(xdata.fSunit);
339  fHelper->GetBinData(ydata, parameters, counter);
340  auto yunit = GetUnitValue(ydata.fSunit);
342  fHelper->GetValueData(zdata, parameters, counter);
343  auto zunit = GetUnitValue(zdata.fSunit);
344  fManager->SetP2(id,
345  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
346  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
347  zdata.fVmin*zunit, zdata.fVmax*zunit,
348  xdata.fSunit, ydata.fSunit, zdata.fSunit,
349  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
350  xdata.fSbinScheme, ydata.fSbinScheme);
351  }
352  else if ( command == fSetP2XCmd.get() ) {
353  // Only save values
354  auto counter = 0;
355  fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
356  fHelper->GetBinData(fXData, parameters, counter);
357  }
358  else if ( command == fSetP2YCmd.get() ) {
359  // Only save values
360  auto counter = 0;
361  fYId = G4UIcommand::ConvertToInt(parameters[counter++]);
362  fHelper->GetBinData(fYData, parameters, counter);
363  }
364  else if ( command == fSetP2ZCmd.get() ) {
365  auto counter = 0;
366  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
367  // Check if setX and setY command was called
368  if ( fXId == -1 || fXId != id ||
369  fYId == -1 || fYId != id ) {
370  fHelper->WarnAboutSetCommands();
371  return;
372  }
373  auto xunit = GetUnitValue(fXData.fSunit);
374  auto yunit = GetUnitValue(fYData.fSunit);
376  fHelper->GetValueData(zdata, parameters, counter);
377  auto zunit = GetUnitValue(zdata.fSunit);
378  fManager->SetP2(id,
379  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
380  fYData.fNbins, fYData.fVmin*yunit, fYData.fVmax*yunit,
381  zdata.fVmin*zunit, zdata.fVmax*zunit,
382  fXData.fSunit, fYData.fSunit, zdata.fSunit,
383  fXData.fSfcn, fYData.fSfcn, zdata.fSfcn,
385  fXId = -1;
386  fYId = -1;
387  }
388  else if ( command == fSetP2TitleCmd.get() ) {
389  auto counter = 0;
390  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
391  auto title = parameters[counter++];
392  fManager->SetP2Title(id, title);
393  }
394  else if ( command == fSetP2XAxisCmd.get() ) {
395  auto counter = 0;
396  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
397  auto xaxis = parameters[counter++];
398  fManager->SetP2XAxisTitle(id, xaxis);
399  }
400  else if ( command == fSetP2YAxisCmd.get() ) {
401  auto counter = 0;
402  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
403  auto yaxis = parameters[counter++];
404  fManager->SetP2YAxisTitle(id, yaxis);
405  }
406  else if ( command == fSetP2ZAxisCmd.get() ) {
407  auto counter = 0;
408  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
409  auto zaxis = parameters[counter++];
410  fManager->SetP2ZAxisTitle(id, zaxis);
411  }
412 }
G4bool SetP2ZAxisTitle(G4int id, const G4String &title)
std::unique_ptr< G4UIcommand > fSetP2XCmd
std::unique_ptr< G4UIcommand > fSetP2ZCmd
std::unique_ptr< G4UIcommand > fSetP2XAxisCmd
G4String name
Definition: TRTMaterials.hh:40
std::unique_ptr< G4AnalysisMessengerHelper > fHelper
std::unique_ptr< G4UIdirectory > fDirectory
G4bool SetP2Title(G4int id, const G4String &title)
int G4int
Definition: G4Types.hh:78
G4AnalysisMessengerHelper::BinData fXData
virtual ~G4P2Messenger()
std::unique_ptr< G4UIcommand > fCreateP2Cmd
G4bool SetP2XAxisTitle(G4int id, const G4String &title)
G4P2Messenger(G4VAnalysisManager *manager)
G4double GetUnitValue(const G4String &unit)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
G4bool SetP2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4double zmin=0, G4double zmax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &zunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &zfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
G4AnalysisMessengerHelper::BinData fYData
G4bool SetP2YAxisTitle(G4int id, const G4String &title)
G4VAnalysisManager * fManager
Associated class.
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4int CreateP2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4double zmin=0, G4double zmax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &zunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &zfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
std::unique_ptr< G4UIcommand > fSetP2ZAxisCmd
void CreateP2Cmd()
std::unique_ptr< G4UIcommand > fSetP2TitleCmd
std::unique_ptr< G4UIcommand > fSetP2Cmd
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
virtual void SetNewValue(G4UIcommand *command, G4String value) final
std::unique_ptr< G4UIcommand > fSetP2YAxisCmd
std::unique_ptr< G4UIcommand > fSetP2YCmd