ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4P1Messenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4P1Messenger.cc
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 
27 // Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
28 
29 #include "G4P1Messenger.hh"
30 #include "G4VAnalysisManager.hh"
31 #include "G4AnalysisUtilities.hh"
32 
33 #include "G4UIdirectory.hh"
34 #include "G4UIcommand.hh"
35 #include "G4UIparameter.hh"
36 
37 #include <iostream>
38 
39 using namespace G4Analysis;
40 
41 //_____________________________________________________________________________
43  : G4UImessenger(),
44  fManager(manager),
45  fHelper(nullptr),
46  fDirectory(nullptr),
47  fCreateP1Cmd(nullptr),
48  fSetP1Cmd(nullptr),
49  fSetP1TitleCmd(nullptr),
50  fSetP1XAxisCmd(nullptr),
51  fSetP1YAxisCmd(nullptr),
52  fXData()
53 {
54  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p1");
55 
56  fDirectory = fHelper->CreateHnDirectory();
57 
58  CreateP1Cmd();
59 
60  SetP1Cmd();
61  fSetP1XCmd = fHelper->CreateSetBinsCommand("x", this);
62  fSetP1YCmd = fHelper->CreateSetValuesCommand("y", this);
63 
64  fSetP1TitleCmd = fHelper->CreateSetTitleCommand(this);
65  fSetP1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
66  fSetP1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
67  fSetP1XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
68  fSetP1YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
69 }
70 
71 //_____________________________________________________________________________
73 {}
74 
75 //
76 // private functions
77 //
78 
79 //_____________________________________________________________________________
81 {
82  auto p1Name = new G4UIparameter("name", 's', false);
83  p1Name->SetGuidance("Profile name (label)");
84 
85  auto p1Title = new G4UIparameter("title", 's', false);
86  p1Title->SetGuidance("Profile title");
87 
88  auto p1xNbins0 = new G4UIparameter("xnbins0", 'i', true);
89  p1xNbins0->SetGuidance("Number of x-bins (default = 100)");
90  p1xNbins0->SetGuidance("Can be reset with /analysis/p1/set command");
91  p1xNbins0->SetDefaultValue(100);
92 
93  auto p1xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
94  p1xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
95  p1xValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
96  p1xValMin0->SetDefaultValue(0.);
97 
98  auto p1xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
99  p1xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
100  p1xValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
101  p1xValMax0->SetDefaultValue(1.);
102 
103  auto p1xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
104  p1xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
105  p1xValUnit0->SetDefaultValue("none");
106 
107  auto p1xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
108  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
109  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
110  fcnxGuidance += "but none value should be used instead.";
111  p1xValFcn0->SetGuidance(fcnxGuidance);
112  p1xValFcn0->SetParameterCandidates("log log10 exp none");
113  p1xValFcn0->SetDefaultValue("none");
114 
115  auto p1xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
116  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
117  p1xValBinScheme0->SetParameterCandidates("linear log");
118  binSchemeGuidance
119  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
120  binSchemeGuidance += "but none value should be used instead.";
121  p1xValBinScheme0->SetGuidance(binSchemeGuidance);
122  p1xValBinScheme0->SetDefaultValue("linear");
123 
124  auto p1yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
125  p1yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
126  p1yValMin0->SetGuidance("Can be reset with /analysis/p1/set command");
127  p1yValMin0->SetDefaultValue(0.);
128 
129  auto p1yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
130  p1yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
131  p1yValMax0->SetGuidance("Can be reset with /analysis/p1/set command");
132  p1yValMax0->SetDefaultValue(1.);
133 
134  auto p1yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
135  p1yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
136  p1yValUnit0->SetDefaultValue("none");
137 
138  auto p1yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
139  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
140  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
141  fcnyGuidance += "but none value should be used instead.";
142  p1yValFcn0->SetGuidance(fcnyGuidance);
143  p1yValFcn0->SetParameterCandidates("log log10 exp none");
144  p1yValFcn0->SetDefaultValue("none");
145 
146  fCreateP1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p1/create", this);
147  fCreateP1Cmd->SetGuidance("Create 1D profile");
148  fCreateP1Cmd->SetParameter(p1Name);
149  fCreateP1Cmd->SetParameter(p1Title);
150  fCreateP1Cmd->SetParameter(p1xNbins0);
151  fCreateP1Cmd->SetParameter(p1xValMin0);
152  fCreateP1Cmd->SetParameter(p1xValMax0);
153  fCreateP1Cmd->SetParameter(p1xValUnit0);
154  fCreateP1Cmd->SetParameter(p1xValFcn0);
155  fCreateP1Cmd->SetParameter(p1xValBinScheme0);
156  fCreateP1Cmd->SetParameter(p1yValMin0);
157  fCreateP1Cmd->SetParameter(p1yValMax0);
158  fCreateP1Cmd->SetParameter(p1yValUnit0);
159  fCreateP1Cmd->SetParameter(p1yValFcn0);
160  fCreateP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
161 }
162 
163 
164 //_____________________________________________________________________________
166 {
167  auto p1Id = new G4UIparameter("id", 'i', false);
168  p1Id->SetGuidance("Profile id");
169  p1Id->SetParameterRange("id>=0");
170 
171  auto p1xNbins = new G4UIparameter("xnbins", 'i', false);
172  p1xNbins->SetGuidance("Number of x-bins");
173 
174  auto p1xValMin = new G4UIparameter("xvalMin", 'd', false);
175  p1xValMin->SetGuidance("Minimum x-value, expressed in unit");
176 
177  auto p1xValMax = new G4UIparameter("xvalMax", 'd', false);
178  p1xValMax->SetGuidance("Maximum x-value, expressed in unit");
179 
180  auto p1xValUnit = new G4UIparameter("xvalUnit", 's', true);
181  p1xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
182  p1xValUnit->SetDefaultValue("none");
183 
184  auto p1xValFcn = new G4UIparameter("xvalFcn", 's', true);
185  p1xValFcn->SetParameterCandidates("log log10 exp none");
186  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).\n";
187  fcnxGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
188  fcnxGuidance += "but none value should be used instead.";
189  p1xValFcn->SetGuidance(fcnxGuidance);
190  p1xValFcn->SetDefaultValue("none");
191 
192  auto p1xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
193  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
194  p1xValBinScheme->SetParameterCandidates("linear log");
195  binSchemeGuidance
196  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
197  binSchemeGuidance += "but none value should be used instead.";
198  p1xValBinScheme->SetGuidance(binSchemeGuidance);
199  p1xValBinScheme->SetDefaultValue("linear");
200 
201  auto p1yValMin = new G4UIparameter("yvalMin", 'd', true);
202  p1yValMin->SetGuidance("Minimum y-value, expressed in unit");
203 
204  auto p1yValMax = new G4UIparameter("yvalMax", 'd', true);
205  p1yValMax->SetGuidance("Maximum y-value, expressed in unit");
206 
207  auto p1yValUnit = new G4UIparameter("yvalUnit", 's', true);
208  p1yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
209  p1yValUnit->SetDefaultValue("none");
210 
211  auto p1yValFcn = new G4UIparameter("yvalFcn", 's', true);
212  p1yValFcn->SetParameterCandidates("log log10 exp none");
213  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).\n";
214  fcnyGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
215  fcnyGuidance += "but none value should be used instead.";
216  p1yValFcn->SetGuidance(fcnyGuidance);
217  p1yValFcn->SetDefaultValue("none");
218 
219  fSetP1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p1/set", this);
220  fSetP1Cmd->SetGuidance("Set parameters for the 1D profile of given id:");
221  fSetP1Cmd->SetGuidance(" nbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
222  fSetP1Cmd->SetGuidance(" yvalMin; yvalMax; yunit; yfunction");
223  fSetP1Cmd->SetParameter(p1Id);
224  fSetP1Cmd->SetParameter(p1xNbins);
225  fSetP1Cmd->SetParameter(p1xValMin);
226  fSetP1Cmd->SetParameter(p1xValMax);
227  fSetP1Cmd->SetParameter(p1xValUnit);
228  fSetP1Cmd->SetParameter(p1xValFcn);
229  fSetP1Cmd->SetParameter(p1xValBinScheme);
230  fSetP1Cmd->SetParameter(p1yValMin);
231  fSetP1Cmd->SetParameter(p1yValMax);
232  fSetP1Cmd->SetParameter(p1yValUnit);
233  fSetP1Cmd->SetParameter(p1yValFcn);
234  fSetP1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
235 }
236 
237 //
238 // public functions
239 //
240 
241 //_____________________________________________________________________________
243 {
244  // tokenize parameters in a vector
245  std::vector<G4String> parameters;
246  G4Analysis::Tokenize(newValues, parameters);
247  // check consistency
248  if ( parameters.size() != command->GetParameterEntries() ) {
249  // Should never happen but let's check anyway for consistency
250  fHelper->WarnAboutParameters(command, parameters.size());
251  return;
252  }
253 
254  if ( command == fCreateP1Cmd.get() ) {
255  auto counter = 0;
256  auto name = parameters[counter++];
257  auto title = parameters[counter++];
259  fHelper->GetBinData(xdata, parameters, counter);
260  auto xunit = GetUnitValue(xdata.fSunit);
262  fHelper->GetValueData(ydata, parameters, counter);
263  auto yunit = GetUnitValue(ydata.fSunit);
265  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
266  ydata.fVmin*yunit, ydata.fVmax*yunit,
267  xdata.fSunit, ydata.fSunit,
268  xdata.fSfcn, ydata.fSfcn,
269  xdata.fSbinScheme);
270  }
271  else if ( command == fSetP1Cmd.get() ) {
272  auto counter = 0;
273  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
275  fHelper->GetBinData(xdata, parameters, counter);
276  auto xunit = GetUnitValue(xdata.fSunit);
278  fHelper->GetValueData(ydata, parameters, counter);
279  auto yunit = GetUnitValue(ydata.fSunit);
280  fManager->SetP1(id,
281  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
282  ydata.fVmin*yunit, ydata.fVmax*yunit,
283  xdata.fSunit, ydata.fSunit,
284  xdata.fSfcn, ydata.fSfcn,
285  xdata.fSbinScheme);
286  }
287  else if ( command == fSetP1XCmd.get() ) {
288  // Save values
289  auto counter = 0;
290  fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
291  fHelper->GetBinData(fXData, parameters, counter);
292  // Set values
293  // (another set may follow if setY is also called)
294  auto xunit = GetUnitValue(fXData.fSunit);
295  fManager->SetP1(fXId,
296  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
297  0., 0.,
298  fXData.fSunit, "none",
299  fXData.fSfcn, "none",
301  }
302  else if ( command == fSetP1YCmd.get() ) {
303  // Check if setX command was called
304  auto counter = 0;
305  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
306  if ( fXId == -1 || fXId != id ) {
307  fHelper->WarnAboutSetCommands();
308  return;
309  }
310  auto xunit = GetUnitValue(fXData.fSunit);
312  fHelper->GetValueData(ydata, parameters, counter);
313  auto yunit = GetUnitValue(ydata.fSunit);
314  fManager->SetP1(id,
315  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
316  ydata.fVmin*yunit, ydata.fVmax*yunit,
317  fXData.fSunit, ydata.fSunit,
318  fXData.fSfcn, ydata.fSfcn,
320  fXId = -1;
321  }
322  else if ( command == fSetP1TitleCmd.get() ) {
323  auto counter = 0;
324  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
325  auto title = parameters[counter++];
326  fManager->SetP1Title(id, title);
327  }
328  else if ( command == fSetP1XAxisCmd.get() ) {
329  auto counter = 0;
330  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
331  auto xaxis = parameters[counter++];
333  }
334  else if ( command == fSetP1YAxisCmd.get() ) {
335  auto counter = 0;
336  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
337  auto yaxis = parameters[counter++];
338  fManager->SetP1YAxisTitle(id, yaxis);
339  }
340  else if ( command == fSetP1XAxisLogCmd.get() ) {
341  auto counter = 0;
342  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
343  auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
344  fManager->SetP1XAxisIsLog(id, xaxisLog);
345  }
346  else if ( command == fSetP1YAxisLogCmd.get() ) {
347  auto counter = 0;
348  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
349  auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
350  fManager->SetP1YAxisIsLog(id, yaxisLog);
351  }
352 }