ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4H3Messenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4H3Messenger.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 "G4H3Messenger.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  fCreateH3Cmd(nullptr),
48  fSetH3Cmd(nullptr),
49  fSetH3XCmd(nullptr),
50  fSetH3YCmd(nullptr),
51  fSetH3ZCmd(nullptr),
52  fSetH3TitleCmd(nullptr),
53  fSetH3XAxisCmd(nullptr),
54  fSetH3YAxisCmd(nullptr),
55  fSetH3ZAxisCmd(nullptr),
56  fXId(-1),
57  fYId(-1),
58  fXData(),
59  fYData()
60 {
61  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("h3");
62 
63  fDirectory = fHelper->CreateHnDirectory();
64 
65  CreateH3Cmd();
66 
67  SetH3Cmd();
68  fSetH3XCmd = fHelper->CreateSetBinsCommand("x", this);
69  fSetH3YCmd = fHelper->CreateSetBinsCommand("y", this);
70 
71  fSetH3TitleCmd = fHelper->CreateSetTitleCommand(this);
72  fSetH3XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
73  fSetH3YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
74  fSetH3ZAxisCmd = fHelper->CreateSetAxisCommand("z", this);
75  fSetH3XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
76  fSetH3YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
77  fSetH3ZAxisLogCmd = fHelper->CreateSetAxisLogCommand("z", this);
78 }
79 
80 //_____________________________________________________________________________
82 {}
83 
84 //
85 // private functions
86 //
87 
88 //_____________________________________________________________________________
90 {
91  auto h3Name = new G4UIparameter("name", 's', false);
92  h3Name->SetGuidance("Histogram name (label)");
93 
94  auto h3Title = new G4UIparameter("title", 's', false);
95  h3Title->SetGuidance("Histogram title");
96 
97  auto h3xNbins0 = new G4UIparameter("xnbins0", 'i', true);
98  h3xNbins0->SetGuidance("Number of x-bins (default = 100)");
99  h3xNbins0->SetGuidance("Can be reset with /analysis/h3/set command");
100  h3xNbins0->SetDefaultValue(100);
101 
102  auto h3xValMin0 = new G4UIparameter("xvalMin0", 'd', true);
103  h3xValMin0->SetGuidance("Minimum x-value, expressed in unit (default = 0.)");
104  h3xValMin0->SetGuidance("Can be reset with /analysis/h3/set command");
105  h3xValMin0->SetDefaultValue(0.);
106 
107  auto h3xValMax0 = new G4UIparameter("xvalMax0", 'd', true);
108  h3xValMax0->SetGuidance("Maximum x-value, expressed in unit (default = 1.)");
109  h3xValMax0->SetGuidance("Can be reset with /analysis/h3/set command");
110  h3xValMax0->SetDefaultValue(1.);
111 
112  auto h3xValUnit0 = new G4UIparameter("xvalUnit0", 's', true);
113  h3xValUnit0->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
114  h3xValUnit0->SetDefaultValue("none");
115 
116  auto h3xValFcn0 = new G4UIparameter("xvalFcn0", 's', true);
117  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
118  h3xValFcn0->SetGuidance(fcnxGuidance);
119  h3xValFcn0->SetParameterCandidates("log log10 exp none");
120  h3xValFcn0->SetDefaultValue("none");
121 
122  auto h3xValBinScheme0 = new G4UIparameter("xvalBinScheme0", 's', true);
123  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
124  h3xValBinScheme0->SetParameterCandidates("linear log");
125  h3xValBinScheme0->SetGuidance(xbinSchemeGuidance);
126  h3xValBinScheme0->SetDefaultValue("linear");
127 
128  auto h3yNbins0 = new G4UIparameter("ynbins0", 'i', true);
129  h3yNbins0->SetGuidance("Number of y-bins (default = 100)");
130  h3yNbins0->SetGuidance("Can be reset with /analysis/h3/set command");
131  h3yNbins0->SetDefaultValue(100);
132 
133  auto h3yValMin0 = new G4UIparameter("yvalMin0", 'd', true);
134  h3yValMin0->SetGuidance("Minimum y-value, expressed in unit (default = 0.)");
135  h3yValMin0->SetGuidance("Can be reset with /analysis/h3/set command");
136  h3yValMin0->SetDefaultValue(0.);
137 
138  auto h3yValMax0 = new G4UIparameter("yvalMax0", 'd', true);
139  h3yValMax0->SetGuidance("Maximum y-value, expressed in unit (default = 1.)");
140  h3yValMax0->SetGuidance("Can be reset with /analysis/h3/set command");
141  h3yValMax0->SetDefaultValue(1.);
142 
143  auto h3yValUnit0 = new G4UIparameter("yvalUnit0", 's', true);
144  h3yValUnit0->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
145  h3yValUnit0->SetDefaultValue("none");
146 
147  auto h3yValFcn0 = new G4UIparameter("yvalFcn0", 's', true);
148  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
149  h3yValFcn0->SetGuidance(fcnyGuidance);
150  h3yValFcn0->SetParameterCandidates("log log10 exp none");
151  h3yValFcn0->SetDefaultValue("none");
152 
153  auto h3yValBinScheme0 = new G4UIparameter("yvalBinScheme0", 's', true);
154  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
155  h3yValBinScheme0->SetParameterCandidates("linear log");
156  h3yValBinScheme0->SetGuidance(ybinSchemeGuidance);
157  h3yValBinScheme0->SetDefaultValue("linear");
158 
159  auto h3zNbins0 = new G4UIparameter("znbins0", 'i', true);
160  h3zNbins0->SetGuidance("Number of z-bins (default = 100)");
161  h3zNbins0->SetGuidance("Can be reset with /analysis/h3/set command");
162  h3zNbins0->SetDefaultValue(100);
163 
164  auto h3zValMin0 = new G4UIparameter("zvalMin0", 'd', true);
165  h3zValMin0->SetGuidance("Minimum z-value, expressed in unit (default = 0.)");
166  h3zValMin0->SetGuidance("Can be reset with /analysis/h3/set command");
167  h3zValMin0->SetDefaultValue(0.);
168 
169  auto h3zValMax0 = new G4UIparameter("zvalMax0", 'd', true);
170  h3zValMax0->SetGuidance("Maximum z-value, expressed in unit (default = 1.)");
171  h3zValMax0->SetGuidance("Can be reset with /analysis/h3/set command");
172  h3zValMax0->SetDefaultValue(1.);
173 
174  auto h3zValUnit0 = new G4UIparameter("zvalUnit0", 's', true);
175  h3zValUnit0->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
176  h3zValUnit0->SetDefaultValue("none");
177 
178  auto h3zValFcn0 = new G4UIparameter("zvalFcn0", 's', true);
179  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
180  h3zValFcn0->SetGuidance(fcnzGuidance);
181  h3zValFcn0->SetParameterCandidates("log log10 exp none");
182  h3zValFcn0->SetDefaultValue("none");
183 
184  auto h3zValBinScheme0 = new G4UIparameter("zvalBinScheme0", 's', true);
185  G4String zbinSchemeGuidance = "The binning scheme (linear, log).";
186  h3zValBinScheme0->SetParameterCandidates("linear log");
187  h3zValBinScheme0->SetGuidance(zbinSchemeGuidance);
188  h3zValBinScheme0->SetDefaultValue("linear");
189 
190  fCreateH3Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h3/create", this);
191  fCreateH3Cmd->SetGuidance("Create 3D histogram");
192  fCreateH3Cmd->SetParameter(h3Name);
193  fCreateH3Cmd->SetParameter(h3Title);
194  fCreateH3Cmd->SetParameter(h3xNbins0);
195  fCreateH3Cmd->SetParameter(h3xValMin0);
196  fCreateH3Cmd->SetParameter(h3xValMax0);
197  fCreateH3Cmd->SetParameter(h3xValUnit0);
198  fCreateH3Cmd->SetParameter(h3xValFcn0);
199  fCreateH3Cmd->SetParameter(h3xValBinScheme0);
200  fCreateH3Cmd->SetParameter(h3yNbins0);
201  fCreateH3Cmd->SetParameter(h3yValMin0);
202  fCreateH3Cmd->SetParameter(h3yValMax0);
203  fCreateH3Cmd->SetParameter(h3yValUnit0);
204  fCreateH3Cmd->SetParameter(h3yValFcn0);
205  fCreateH3Cmd->SetParameter(h3yValBinScheme0);
206  fCreateH3Cmd->SetParameter(h3zNbins0);
207  fCreateH3Cmd->SetParameter(h3zValMin0);
208  fCreateH3Cmd->SetParameter(h3zValMax0);
209  fCreateH3Cmd->SetParameter(h3zValUnit0);
210  fCreateH3Cmd->SetParameter(h3zValFcn0);
211  fCreateH3Cmd->SetParameter(h3zValBinScheme0);
212  fCreateH3Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
213 }
214 
215 
216 //_____________________________________________________________________________
218 {
219  auto h3Id = new G4UIparameter("id", 'i', false);
220  h3Id->SetGuidance("Histogram id");
221  h3Id->SetParameterRange("id>=0");
222 
223  auto h3xNbins = new G4UIparameter("xnbins", 'i', false);
224  h3xNbins->SetGuidance("Number of x-bins");
225 
226  auto h3xValMin = new G4UIparameter("xvalMin", 'd', false);
227  h3xValMin->SetGuidance("Minimum x-value, expressed in unit");
228 
229  auto h3xValMax = new G4UIparameter("xvalMax", 'd', false);
230  h3xValMax->SetGuidance("Maximum x-value, expressed in unit");
231 
232  auto h3xValUnit = new G4UIparameter("xvalUnit", 's', false);
233  h3xValUnit->SetGuidance("The unit applied to filled x-values and xvalMin0, xvalMax0");
234  h3xValUnit->SetDefaultValue("none");
235 
236  auto h3xValFcn = new G4UIparameter("xvalFcn", 's', false);
237  h3xValFcn->SetParameterCandidates("log log10 exp none");
238  G4String fcnxGuidance = "The function applied to filled x-values (log, log10, exp, none).";
239  h3xValFcn->SetGuidance(fcnxGuidance);
240  h3xValFcn->SetDefaultValue("none");
241 
242  auto h3xValBinScheme = new G4UIparameter("xvalBinScheme", 's', true);
243  G4String xbinSchemeGuidance = "The binning scheme (linear, log).";
244  h3xValBinScheme->SetParameterCandidates("linear log");
245  h3xValBinScheme->SetGuidance(xbinSchemeGuidance);
246  h3xValBinScheme->SetDefaultValue("linear");
247 
248  auto h3yNbins = new G4UIparameter("nybins", 'i', false);
249  h3yNbins->SetGuidance("Number of y-bins");
250 
251  auto h3yValMin = new G4UIparameter("yvalMin", 'd', false);
252  h3yValMin->SetGuidance("Minimum y-value, expressed in unit");
253 
254  auto h3yValMax = new G4UIparameter("yvalMax", 'd', false);
255  h3yValMax->SetGuidance("Maximum y-value, expressed in unit");
256 
257  auto h3yValUnit = new G4UIparameter("yvalUnit", 's', true);
258  h3yValUnit->SetGuidance("The unit applied to filled y-values and yvalMin0, yvalMax0");
259  h3yValUnit->SetDefaultValue("none");
260 
261  auto h3yValFcn = new G4UIparameter("yvalFcn", 's', false);
262  h3yValFcn->SetParameterCandidates("log log10 exp none");
263  G4String fcnyGuidance = "The function applied to filled y-values (log, log10, exp, none).";
264  h3yValFcn->SetGuidance(fcnyGuidance);
265  h3yValFcn->SetDefaultValue("none");
266 
267  auto h3yValBinScheme = new G4UIparameter("yvalBinScheme", 's', true);
268  G4String ybinSchemeGuidance = "The binning scheme (linear, log).";
269  h3yValBinScheme->SetParameterCandidates("linear log");
270  h3yValBinScheme->SetGuidance(ybinSchemeGuidance);
271  h3yValBinScheme->SetDefaultValue("linear");
272 
273  auto h3zNbins = new G4UIparameter("nzbins", 'i', false);
274  h3zNbins->SetGuidance("Number of z-bins");
275 
276  auto h3zValMin = new G4UIparameter("zvalMin", 'd', false);
277  h3zValMin->SetGuidance("Minimum z-value, expressed in unit");
278 
279  auto h3zValMax = new G4UIparameter("zvalMax", 'd', false);
280  h3zValMax->SetGuidance("Maximum z-value, expressed in unit");
281 
282  auto h3zValUnit = new G4UIparameter("zvalUnit", 's', true);
283  h3zValUnit->SetGuidance("The unit applied to filled z-values and zvalMin0, zvalMax0");
284  h3zValUnit->SetDefaultValue("none");
285 
286  auto h3zValFcn = new G4UIparameter("zvalFcn", 's', false);
287  h3zValFcn->SetParameterCandidates("log log10 exp none");
288  G4String fcnzGuidance = "The function applied to filled z-values (log, log10, exp, none).";
289  h3zValFcn->SetGuidance(fcnzGuidance);
290  h3zValFcn->SetDefaultValue("none");
291 
292  auto h3zValBinScheme = new G4UIparameter("zvalBinScheme", 's', true);
293  G4String zbinSchemeGuidance = "The binning scheme (linear, log).";
294  h3zValBinScheme->SetParameterCandidates("linear log");
295  h3zValBinScheme->SetGuidance(zbinSchemeGuidance);
296  h3zValBinScheme->SetDefaultValue("linear");
297 
298  fSetH3Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h3/set", this);
299  fSetH3Cmd->SetGuidance("Set parameters for the 3D histogram of given id:");
300  fSetH3Cmd->SetGuidance(" nxbins; xvalMin; xvalMax; xunit; xfunction; xbinScheme");
301  fSetH3Cmd->SetGuidance(" nybins; yvalMin; yvalMax; yunit; yfunction; ybinScheme");
302  fSetH3Cmd->SetGuidance(" nzbins; zvalMin; zvalMax; zunit; zfunction; zbinScheme");
303  fSetH3Cmd->SetParameter(h3Id);
304  fSetH3Cmd->SetParameter(h3xNbins);
305  fSetH3Cmd->SetParameter(h3xValMin);
306  fSetH3Cmd->SetParameter(h3xValMax);
307  fSetH3Cmd->SetParameter(h3xValUnit);
308  fSetH3Cmd->SetParameter(h3xValFcn);
309  fSetH3Cmd->SetParameter(h3xValBinScheme);
310  fSetH3Cmd->SetParameter(h3yNbins);
311  fSetH3Cmd->SetParameter(h3yValMin);
312  fSetH3Cmd->SetParameter(h3yValMax);
313  fSetH3Cmd->SetParameter(h3yValUnit);
314  fSetH3Cmd->SetParameter(h3yValFcn);
315  fSetH3Cmd->SetParameter(h3yValBinScheme);
316  fSetH3Cmd->SetParameter(h3zNbins);
317  fSetH3Cmd->SetParameter(h3zValMin);
318  fSetH3Cmd->SetParameter(h3zValMax);
319  fSetH3Cmd->SetParameter(h3zValUnit);
320  fSetH3Cmd->SetParameter(h3zValFcn);
321  fSetH3Cmd->SetParameter(h3zValBinScheme);
322  fSetH3Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
323 }
324 
325 
326 //
327 // public functions
328 //
329 
330 //_____________________________________________________________________________
332 {
333  // tokenize parameters in a vector
334  std::vector<G4String> parameters;
335  G4Analysis::Tokenize(newValues, parameters);
336  // check consistency
337  if ( parameters.size() != command->GetParameterEntries() ) {
338  // Should never happen but let's check anyway for consistency
339  fHelper->WarnAboutParameters(command, parameters.size());
340  return;
341  }
342 
343  if ( command == fCreateH3Cmd.get() ) {
344  auto counter = 0;
345  auto name = parameters[counter++];
346  auto title = parameters[counter++];
348  fHelper->GetBinData(xdata, parameters, counter);
349  auto xunit = GetUnitValue(xdata.fSunit);
351  fHelper->GetBinData(ydata, parameters, counter);
352  auto yunit = GetUnitValue(ydata.fSunit);
354  fHelper->GetBinData(zdata, parameters, counter);
355  auto zunit = GetUnitValue(zdata.fSunit);
357  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
358  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
359  zdata.fNbins, zdata.fVmin*zunit, zdata.fVmax*zunit,
360  xdata.fSunit, ydata.fSunit, zdata.fSunit,
361  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
362  xdata.fSbinScheme, ydata.fSbinScheme, zdata.fSbinScheme);
363  }
364  else if ( command == fSetH3Cmd.get() ) {
365  auto counter = 0;
366  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
368  fHelper->GetBinData(xdata, parameters, counter);
369  auto xunit = GetUnitValue(xdata.fSunit);
371  fHelper->GetBinData(ydata, parameters, counter);
372  auto yunit = GetUnitValue(ydata.fSunit);
374  fHelper->GetBinData(zdata, parameters, counter);
375  auto zunit = GetUnitValue(zdata.fSunit);
376  fManager->SetH3(id,
377  xdata.fNbins, xdata.fVmin*xunit, xdata.fVmax*xunit,
378  ydata.fNbins, ydata.fVmin*yunit, ydata.fVmax*yunit,
379  zdata.fNbins, zdata.fVmin*zunit, zdata.fVmax*zunit,
380  xdata.fSunit, ydata.fSunit, zdata.fSunit,
381  xdata.fSfcn, ydata.fSfcn, zdata.fSfcn,
382  xdata.fSbinScheme, ydata.fSbinScheme, zdata.fSbinScheme);
383  }
384  else if ( command == fSetH3XCmd.get() ) {
385  // Only save values
386  auto counter = 0;
387  fXId = G4UIcommand::ConvertToInt(parameters[counter++]);
388  fHelper->GetBinData(fXData, parameters, counter);
389  }
390  else if ( command == fSetH3YCmd.get() ) {
391  // Only save values
392  auto counter = 0;
393  fYId = G4UIcommand::ConvertToInt(parameters[counter++]);
394  fHelper->GetBinData(fYData, parameters, counter);
395  }
396  else if ( command == fSetH3ZCmd.get() ) {
397  auto counter = 0;
398  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
399  // Check if setX and setY command was called
400  if ( fXId == -1 || fXId != id ||
401  fYId == -1 || fYId != id ) {
402  fHelper->WarnAboutSetCommands();
403  return;
404  }
405  auto xunit = GetUnitValue(fXData.fSunit);
406  auto yunit = GetUnitValue(fYData.fSunit);
408  fHelper->GetBinData(zdata, parameters, counter);
409  auto zunit = GetUnitValue(zdata.fSunit);
410  fManager->SetH3(id,
411  fXData.fNbins, fXData.fVmin*xunit, fXData.fVmax*xunit,
412  fYData.fNbins, fYData.fVmin*yunit, fYData.fVmax*yunit,
413  zdata.fNbins, zdata.fVmin*zunit, zdata.fVmax*zunit,
414  fXData.fSunit, fYData.fSunit, zdata.fSunit,
415  fXData.fSfcn, fYData.fSfcn, zdata.fSfcn,
417  fXId = -1;
418  fYId = -1;
419  }
420  else if ( command == fSetH3TitleCmd.get() ) {
421  auto counter = 0;
422  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
423  auto title = parameters[counter++];
424  fManager->SetH3Title(id, title);
425  }
426  else if ( command == fSetH3XAxisCmd.get() ) {
427  auto counter = 0;
428  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
429  auto xaxis = parameters[counter++];
431  }
432  else if ( command == fSetH3YAxisCmd.get() ) {
433  auto counter = 0;
434  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
435  auto yaxis = parameters[counter++];
436  fManager->SetH3YAxisTitle(id, yaxis);
437  }
438  else if ( command == fSetH3ZAxisCmd.get() ) {
439  auto counter = 0;
440  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
441  auto zaxis = parameters[counter++];
442  fManager->SetH3ZAxisTitle(id, zaxis);
443  }
444  else if ( command == fSetH3XAxisLogCmd.get() ) {
445  auto counter = 0;
446  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
447  auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
448  fManager->SetH3XAxisIsLog(id, xaxisLog);
449  }
450  else if ( command == fSetH3YAxisLogCmd.get() ) {
451  auto counter = 0;
452  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
453  auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
454  fManager->SetH3YAxisIsLog(id, yaxisLog);
455  }
456  else if ( command == fSetH3ZAxisLogCmd.get() ) {
457  auto counter = 0;
458  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
459  auto zaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
460  fManager->SetH3ZAxisIsLog(id, zaxisLog);
461  }
462 }