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