ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4P2Messenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4P2Messenger.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 "G4P2Messenger.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  fCreateP2Cmd(nullptr),
48  fSetP2Cmd(nullptr),
49  fSetP2XCmd(nullptr),
50  fSetP2YCmd(nullptr),
51  fSetP2ZCmd(nullptr),
52  fSetP2TitleCmd(nullptr),
53  fSetP2XAxisCmd(nullptr),
54  fSetP2YAxisCmd(nullptr)
55 {
56  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p2");
57 
58  fDirectory = fHelper->CreateHnDirectory();
59 
60  CreateP2Cmd();
61 
62  SetP2Cmd();
63  fSetP2XCmd = fHelper->CreateSetBinsCommand("x", this);
64  fSetP2YCmd = fHelper->CreateSetBinsCommand("y", this);
65  fSetP2ZCmd = fHelper->CreateSetValuesCommand("z", this);
66 
67  fSetP2TitleCmd = fHelper->CreateSetTitleCommand(this);
68  fSetP2XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
69  fSetP2YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
70  fSetP2ZAxisCmd = fHelper->CreateSetAxisCommand("z", this);
71  fSetP2XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
72  fSetP2YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
73  fSetP2ZAxisLogCmd = fHelper->CreateSetAxisLogCommand("z", this);
74 }
75 
76 //_____________________________________________________________________________
78 {}
79 
80 //
81 // private functions
82 //
83 
84 //_____________________________________________________________________________
86 {
87  auto p2Name = new G4UIparameter("name", 's', false);
88  p2Name->SetGuidance("Profile name (label)");
89 
90  auto p2Title = new G4UIparameter("title", 's', false);
91  p2Title->SetGuidance("Profile title");
92 
93  auto p2xNbins0 = new G4UIparameter("xnbins0", 'i', true);
94  p2xNbins0->SetGuidance("Number of x-bins (default = 100)");
95  p2xNbins0->SetGuidance("Can be reset with /analysis/p2/set command");
96  p2xNbins0->SetDefaultValue(100);
97 
98  auto p2xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
99  p2xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
100  p2xValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
101  p2xValMin0->SetDefaultValue(0.);
102 
103  auto p2xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
104  p2xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
105  p2xValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
106  p2xValMax0->SetDefaultValue(1.);
107 
108  auto p2xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
109  p2xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
110  p2xValUnit0->SetDefaultValue("none");
111 
112  auto p2xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
113  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
114  p2xValFcn0->SetGuidance(fcnxGuidance);
115  p2xValFcn0->SetParameterCandidates("log log10 exp none");
116  p2xValFcn0->SetDefaultValue("none");
117 
118  auto p2xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
119  G4String binSchemeGuidance = "The binning scheme (linear, log).";
120  p2xValBinScheme0->SetParameterCandidates("linear log");
121  p2xValBinScheme0->SetGuidance(binSchemeGuidance);
122  p2xValBinScheme0->SetDefaultValue("linear");
123 
124  auto p2yNbins0 = new G4UIparameter("ynbins0", 'i', true);
125  p2yNbins0->SetGuidance("Number of y-bins (default = 100)");
126  p2yNbins0->SetGuidance("Can be reset with /analysis/p2/set command");
127  p2yNbins0->SetDefaultValue(100);
128 
129  auto p2yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
130  p2yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
131  p2yValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
132  p2yValMin0->SetDefaultValue(0.);
133 
134  auto p2yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
135  p2yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
136  p2yValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
137  p2yValMax0->SetDefaultValue(1.);
138 
139  auto p2yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
140  p2yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
141  p2yValUnit0->SetDefaultValue("none");
142 
143  auto p2yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
144  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
145  p2yValFcn0->SetGuidance(fcnyGuidance);
146  p2yValFcn0->SetParameterCandidates("log log10 exp none");
147  p2yValFcn0->SetDefaultValue("none");
148 
149  auto p2yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
150  p2yValBinScheme0->SetParameterCandidates("linear log");
151  p2yValBinScheme0->SetGuidance(binSchemeGuidance);
152  p2yValBinScheme0->SetDefaultValue("linear");
153 
154  auto p2zValMin0 = new G4UIparameter("zvalMin0", 'd', true);
155  p2zValMin0->SetGuidance("Minimum z-value, expressed in unit (default = 0.)");
156  p2zValMin0->SetGuidance("Can be reset with /analysis/p2/set command");
157  p2zValMin0->SetDefaultValue(0.);
158 
159  auto p2zValMax0 = new G4UIparameter("zvalMax0", 'd', true);
160  p2zValMax0->SetGuidance("Maximum z-value, expressed in unit (default = 1.)");
161  p2zValMax0->SetGuidance("Can be reset with /analysis/p2/set command");
162  p2zValMax0->SetDefaultValue(1.);
163 
164  auto p2zValUnit0 = new G4UIparameter("zvalUnit0", 's', true);
165  p2zValUnit0->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
166  p2zValUnit0->SetDefaultValue("none");
167 
168  auto p2zValFcn0 = new G4UIparameter("zvalFcn0", 's', true);
169  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
170  p2zValFcn0->SetGuidance(fcnzGuidance);
171  p2zValFcn0->SetParameterCandidates("log log10 exp none");
172  p2zValFcn0->SetDefaultValue("none");
173 
174  fCreateP2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p2/create", this);
175  fCreateP2Cmd->SetGuidance("Create 2D profile");
176  fCreateP2Cmd->SetParameter(p2Name);
177  fCreateP2Cmd->SetParameter(p2Title);
178  fCreateP2Cmd->SetParameter(p2xNbins0);
179  fCreateP2Cmd->SetParameter(p2xValMin0);
180  fCreateP2Cmd->SetParameter(p2xValMax0);
181  fCreateP2Cmd->SetParameter(p2xValUnit0);
182  fCreateP2Cmd->SetParameter(p2xValFcn0);
183  fCreateP2Cmd->SetParameter(p2xValBinScheme0);
184  fCreateP2Cmd->SetParameter(p2yNbins0);
185  fCreateP2Cmd->SetParameter(p2yValMin0);
186  fCreateP2Cmd->SetParameter(p2yValMax0);
187  fCreateP2Cmd->SetParameter(p2yValUnit0);
188  fCreateP2Cmd->SetParameter(p2yValFcn0);
189  fCreateP2Cmd->SetParameter(p2yValBinScheme0);
190  fCreateP2Cmd->SetParameter(p2zValMin0);
191  fCreateP2Cmd->SetParameter(p2zValMax0);
192  fCreateP2Cmd->SetParameter(p2zValUnit0);
193  fCreateP2Cmd->SetParameter(p2zValFcn0);
194  fCreateP2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
195 }
196 
197 
198 //_____________________________________________________________________________
200 {
201  auto p2Id = new G4UIparameter("id", 'i', false);
202  p2Id->SetGuidance("Profile id");
203  p2Id->SetParameterRange("id>=0");
204 
205  auto p2xNbins = new G4UIparameter("xnbins", 'i', false);
206  p2xNbins->SetGuidance("Number of x-bins");
207 
208  auto p2xValMin = new G4UIparameter("xvalMin", 'd', false);
209  p2xValMin->SetGuidance("Minimum x-value, expressed in unit");
210 
211  auto p2xValMax = new G4UIparameter("xvalMax", 'd', false);
212  p2xValMax->SetGuidance("Maximum x-value, expressed in unit");
213 
214  auto p2xValUnit = new G4UIparameter("xvalUnit", 's', true);
215  p2xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
216  p2xValUnit->SetDefaultValue("none");
217 
218  auto p2xValFcn = new G4UIparameter("xvalFcn", 's', true);
219  p2xValFcn->SetParameterCandidates("log log10 exp none");
220  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
221  p2xValFcn->SetGuidance(fcnxGuidance);
222  p2xValFcn->SetDefaultValue("none");
223 
224  auto p2xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
225  G4String binSchemeGuidance = "The binning scheme (linear, log).";
226  p2xValBinScheme->SetParameterCandidates("linear log");
227  p2xValBinScheme->SetGuidance(binSchemeGuidance);
228  p2xValBinScheme->SetDefaultValue("linear");
229 
230  auto p2yNbins = new G4UIparameter("nybins", 'i', true);
231  p2yNbins->SetGuidance("Number of y-bins");
232 
233  auto p2yValMin = new G4UIparameter("yvalMin", 'd', true);
234  p2yValMin->SetGuidance("Minimum y-value, expressed in unit");
235 
236  auto p2yValMax = new G4UIparameter("yvalMax", 'd', true);
237  p2yValMax->SetGuidance("Maximum y-value, expressed in unit");
238 
239  auto p2yValUnit = new G4UIparameter("yvalUnit", 's', true);
240  p2yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
241  p2yValUnit->SetDefaultValue("none");
242 
243  auto p2yValFcn = new G4UIparameter("yvalFcn", 's', true);
244  p2yValFcn->SetParameterCandidates("log log10 exp none");
245  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
246  p2yValFcn->SetGuidance(fcnyGuidance);
247  p2yValFcn->SetDefaultValue("none");
248 
249  auto p2yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
250  p2yValBinScheme->SetParameterCandidates("linear log");
251  p2yValBinScheme->SetGuidance(binSchemeGuidance);
252  p2yValBinScheme->SetDefaultValue("linear");
253 
254  auto p2zValMin = new G4UIparameter("zvalMin", 'd', true);
255  p2zValMin->SetGuidance("Minimum z-value, expressed in unit");
256 
257  auto p2zValMax = new G4UIparameter("zvalMax", 'd', true);
258  p2zValMax->SetGuidance("Maximum z-value, expressed in unit");
259 
260  auto p2zValUnit = new G4UIparameter("zvalUnit", 's', true);
261  p2zValUnit->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
262  p2zValUnit->SetDefaultValue("none");
263 
264  auto p2zValFcn = new G4UIparameter("zvalFcn", 's', true);
265  p2zValFcn->SetParameterCandidates("log log10 exp none");
266  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
267  p2zValFcn->SetGuidance(fcnzGuidance);
268  p2zValFcn->SetDefaultValue("none");
269 
270  fSetP2Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/p2/set", this);
271  fSetP2Cmd->SetGuidance("Set parameters for the 2D profile of given id:");
272  fSetP2Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xbinScheme");
273  fSetP2Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; ybinScheme");
274  fSetP2Cmd->SetGuidance(" zvalMin; zvalMax; zunit; zfunction");
275  fSetP2Cmd->SetParameter(p2Id);
276  fSetP2Cmd->SetParameter(p2xNbins);
277  fSetP2Cmd->SetParameter(p2xValMin);
278  fSetP2Cmd->SetParameter(p2xValMax);
279  fSetP2Cmd->SetParameter(p2xValUnit);
280  fSetP2Cmd->SetParameter(p2xValFcn);
281  fSetP2Cmd->SetParameter(p2xValBinScheme);
282  fSetP2Cmd->SetParameter(p2yNbins);
283  fSetP2Cmd->SetParameter(p2yValMin);
284  fSetP2Cmd->SetParameter(p2yValMax);
285  fSetP2Cmd->SetParameter(p2yValUnit);
286  fSetP2Cmd->SetParameter(p2yValFcn);
287  fSetP2Cmd->SetParameter(p2yValBinScheme);
288  fSetP2Cmd->SetParameter(p2zValMin);
289  fSetP2Cmd->SetParameter(p2zValMax);
290  fSetP2Cmd->SetParameter(p2zValUnit);
291  fSetP2Cmd->SetParameter(p2zValFcn);
292  fSetP2Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
293 }
294 
295 
296 //
297 // public functions
298 //
299 
300 //_____________________________________________________________________________
302 {
303  // tokenize parameters in a vector
304  std::vector<G4String> parameters;
305  G4Analysis::Tokenize(newValues, parameters);
306  // check consistency
307  if ( parameters.size() != command->GetParameterEntries() ) {
308  // Should never happen but let's check anyway for consistency
309  fHelper->WarnAboutParameters(command, parameters.size());
310  return;
311  }
312 
313  if ( command == fCreateP2Cmd.get() ) {
314  auto counter = 0;
315  auto name = parameters[counter++];
316  auto title = parameters[counter++];
318  fHelper->GetBinData(xdata, parameters, counter);
319  auto xunit = GetUnitValue(xdata.fSunit);
321  fHelper->GetBinData(ydata, parameters, counter);
322  auto yunit = GetUnitValue(ydata.fSunit);
324  fHelper->GetValueData(zdata, parameters, counter);
325  auto zunit = GetUnitValue(zdata.fSunit);
327  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
328  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
329  zdata.fVmin*zunit, zdata.fVmax*zunit,
330  xdata.fSunit, ydata.fSunit, zdata.fSunit,
331  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
332  xdata.fSbinScheme, ydata.fSbinScheme);
333  }
334  else if ( command == fSetP2Cmd.get() ) {
335  auto counter = 0;
336  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
338  fHelper->GetBinData(xdata, parameters, counter);
339  auto xunit = GetUnitValue(xdata.fSunit);
341  fHelper->GetBinData(ydata, parameters, counter);
342  auto yunit = GetUnitValue(ydata.fSunit);
344  fHelper->GetValueData(zdata, parameters, counter);
345  auto zunit = GetUnitValue(zdata.fSunit);
346  fManager->SetP2(id,
347  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
348  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
349  zdata.fVmin*zunit, zdata.fVmax*zunit,
350  xdata.fSunit, ydata.fSunit, zdata.fSunit,
351  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
352  xdata.fSbinScheme, ydata.fSbinScheme);
353  }
354  else if ( command == fSetP2XCmd.get() ) {
355  // Only save values
356  auto counter = 0;
357  fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
358  fHelper->GetBinData(fXData, parameters, counter);
359  }
360  else if ( command == fSetP2YCmd.get() ) {
361  // Save values
362  auto counter = 0;
363  fYId = G4UIcommand::ConvertToInt(parameters[counter++]);
364  // Check if setX command was called
365  if ( fXId == -1 || fXId != fYId ) {
366  fHelper->WarnAboutSetCommands();
367  return;
368  }
369  fHelper->GetBinData(fYData, parameters, counter);
370  // Set values
371  // (another set may follow if setZ is also called)
372  auto xunit = GetUnitValue(fXData.fSunit);
373  auto yunit = GetUnitValue(fYData.fSunit);
374  fManager->SetP2(fYId,
375  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
376  fYData.fNbins, fYData.fVmin*yunit, fYData.fVmax*yunit,
377  0., 0.,
378  fXData.fSunit, fYData.fSunit, "none",
379  fXData.fSfcn, fYData.fSfcn, "none",
381  }
382  else if ( command == fSetP2ZCmd.get() ) {
383  auto counter = 0;
384  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
385  // Check if setX and setY command was called
386  if ( fXId == -1 || fXId != id ||
387  fYId == -1 || fYId != id ) {
388  fHelper->WarnAboutSetCommands();
389  return;
390  }
391  auto xunit = GetUnitValue(fXData.fSunit);
392  auto yunit = GetUnitValue(fYData.fSunit);
394  fHelper->GetValueData(zdata, parameters, counter);
395  auto zunit = GetUnitValue(zdata.fSunit);
396  fManager->SetP2(id,
397  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
398  fYData.fNbins, fYData.fVmin*yunit, fYData.fVmax*yunit,
399  zdata.fVmin*zunit, zdata.fVmax*zunit,
400  fXData.fSunit, fYData.fSunit, zdata.fSunit,
401  fXData.fSfcn, fYData.fSfcn, zdata.fSfcn,
403  fXId = -1;
404  fYId = -1;
405  }
406  else if ( command == fSetP2TitleCmd.get() ) {
407  auto counter = 0;
408  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
409  auto title = parameters[counter++];
410  fManager->SetP2Title(id, title);
411  }
412  else if ( command == fSetP2XAxisCmd.get() ) {
413  auto counter = 0;
414  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
415  auto xaxis = parameters[counter++];
417  }
418  else if ( command == fSetP2YAxisCmd.get() ) {
419  auto counter = 0;
420  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
421  auto yaxis = parameters[counter++];
422  fManager->SetP2YAxisTitle(id, yaxis);
423  }
424  else if ( command == fSetP2ZAxisCmd.get() ) {
425  auto counter = 0;
426  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
427  auto zaxis = parameters[counter++];
428  fManager->SetP2ZAxisTitle(id, zaxis);
429  }
430  else if ( command == fSetP2XAxisLogCmd.get() ) {
431  auto counter = 0;
432  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
433  auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
434  fManager->SetP2XAxisIsLog(id, xaxisLog);
435  }
436  else if ( command == fSetP2YAxisLogCmd.get() ) {
437  auto counter = 0;
438  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
439  auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
440  fManager->SetP2YAxisIsLog(id, yaxisLog);
441  }
442  else if ( command == fSetP2ZAxisLogCmd.get() ) {
443  auto counter = 0;
444  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
445  auto zaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
446  fManager->SetP2ZAxisIsLog(id, zaxisLog);
447  }
448 }