ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4H1Messenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4H1Messenger.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/06/2013 (ivana@ipno.in2p3.fr)
28 //
29 // This messenger class is a generalization of the HistoMessenger class,
30 // originally developed for the extended/electromagnetic examples
31 // by Michel Maire (michel.maire@lapp.in2p3.fr)
32 
33 #include "G4H1Messenger.hh"
34 #include "G4VAnalysisManager.hh"
35 #include "G4AnalysisUtilities.hh"
37 
38 #include "G4UIdirectory.hh"
39 #include "G4UIcommand.hh"
40 #include "G4UIparameter.hh"
41 #include "G4Tokenizer.hh"
42 
43 #include <iostream>
44 #include <vector>
45 
46 using namespace G4Analysis;
47 
48 //_____________________________________________________________________________
50  : G4UImessenger(),
51  fManager(manager),
52  fHelper(nullptr),
53  fDirectory(nullptr),
54  fCreateH1Cmd(nullptr),
55  fSetH1Cmd(nullptr),
56  fSetH1TitleCmd(nullptr),
57  fSetH1XAxisCmd(nullptr),
58  fSetH1YAxisCmd(nullptr)
59 {
60  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("h1");
61 
62  fDirectory = fHelper->CreateHnDirectory();
63 
64  CreateH1Cmd();
65 
66  SetH1Cmd();
67  fSetH1XCmd = fHelper->CreateSetBinsCommand("x", this);
68 
69 
70  fSetH1TitleCmd = fHelper->CreateSetTitleCommand(this);
71  fSetH1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
72  fSetH1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
73  fSetH1XAxisLogCmd = fHelper->CreateSetAxisLogCommand("x", this);
74  fSetH1YAxisLogCmd = fHelper->CreateSetAxisLogCommand("y", this);
75 }
76 
77 //_____________________________________________________________________________
79 {}
80 
81 //
82 // private functions
83 //
84 
85 //_____________________________________________________________________________
87 {
88  auto h1Name = new G4UIparameter("name", 's', false);
89  h1Name->SetGuidance("Histogram name (label)");
90 
91  auto h1Title = new G4UIparameter("title", 's', false);
92  h1Title->SetGuidance("Histogram title");
93 
94  auto h1Nbins0 = new G4UIparameter("nbins0", 'i', true);
95  h1Nbins0->SetGuidance("Number of bins (default = 100)");
96  h1Nbins0->SetGuidance("Can be reset with /analysis/h1/set command");
97  h1Nbins0->SetDefaultValue(100);
98 
99  auto h1ValMin0 = new G4UIparameter("valMin0", 'd', true);
100  h1ValMin0->SetGuidance("Minimum value, expressed in unit (default = 0.)");
101  h1ValMin0->SetGuidance("Can be reset with /analysis/h1/set command");
102  h1ValMin0->SetDefaultValue(0.);
103 
104  auto h1ValMax0 = new G4UIparameter("valMax0", 'd', true);
105  h1ValMax0->SetGuidance("Maximum value, expressed in unit (default = 1.)");
106  h1ValMax0->SetGuidance("Can be reset with /analysis/h1/set command");
107  h1ValMax0->SetDefaultValue(1.);
108 
109  auto h1ValUnit0 = new G4UIparameter("valUnit0", 's', true);
110  h1ValUnit0->SetGuidance("The unit applied to filled values and valMin0, valMax0");
111  h1ValUnit0->SetDefaultValue("none");
112 
113  auto h1ValFcn0 = new G4UIparameter("valFcn0", 's', true);
114  G4String fcnGuidance = "The function applied to filled values (log, log10, exp).\n";
115  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
116  fcnGuidance += "but none value should be used instead.";
117  h1ValFcn0->SetGuidance(fcnGuidance);
118  h1ValFcn0->SetParameterCandidates("log log10 exp none");
119  h1ValFcn0->SetDefaultValue("none");
120 
121  auto h1ValBinScheme0 = new G4UIparameter("valBinScheme0", 's', true);
122  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
123  h1ValBinScheme0->SetParameterCandidates("linear log");
124  binSchemeGuidance
125  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
126  binSchemeGuidance += "but none value should be used instead.";
127  h1ValBinScheme0->SetGuidance(binSchemeGuidance);
128  h1ValBinScheme0->SetDefaultValue("linear");
129 
130  fCreateH1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h1/create", this);
131  fCreateH1Cmd->SetGuidance("Create 1D histogram");
132  fCreateH1Cmd->SetParameter(h1Name);
133  fCreateH1Cmd->SetParameter(h1Title);
134  fCreateH1Cmd->SetParameter(h1Nbins0);
135  fCreateH1Cmd->SetParameter(h1ValMin0);
136  fCreateH1Cmd->SetParameter(h1ValMax0);
137  fCreateH1Cmd->SetParameter(h1ValUnit0);
138  fCreateH1Cmd->SetParameter(h1ValFcn0);
139  fCreateH1Cmd->SetParameter(h1ValBinScheme0);
140  fCreateH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
141 }
142 
143 
144 //_____________________________________________________________________________
146 {
147  auto h1Id = new G4UIparameter("id", 'i', false);
148  h1Id->SetGuidance("Histogram id");
149  h1Id->SetParameterRange("id>=0");
150 
151  auto h1Nbins = new G4UIparameter("nbins", 'i', false);
152  h1Nbins->SetGuidance("Number of bins");
153 
154  auto h1ValMin = new G4UIparameter("valMin", 'd', false);
155  h1ValMin->SetGuidance("Minimum value, expressed in unit");
156 
157  auto h1ValMax = new G4UIparameter("valMax", 'd', false);
158  h1ValMax->SetGuidance("Maximum value, expressed in unit");
159 
160  auto h1ValUnit = new G4UIparameter("valUnit", 's', true);
161  h1ValUnit->SetGuidance("The unit applied to filled values and valMin, valMax");
162  h1ValUnit->SetDefaultValue("none");
163 
164  auto h1ValFcn = new G4UIparameter("valFcn", 's', true);
165  h1ValFcn->SetParameterCandidates("log log10 exp none");
166  G4String fcnGuidance = "The function applied to filled values (log, log10, exp, none).\n";
167  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
168  fcnGuidance += "but none value should be used instead.";
169  h1ValFcn->SetGuidance(fcnGuidance);
170  h1ValFcn->SetDefaultValue("none");
171 
172  auto h1ValBinScheme = new G4UIparameter("valBinScheme", 's', true);
173  h1ValBinScheme->SetParameterCandidates("linear log");
174  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
175  binSchemeGuidance
176  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
177  binSchemeGuidance += "but none value should be used instead.";
178  h1ValBinScheme->SetGuidance(binSchemeGuidance);
179  h1ValBinScheme->SetDefaultValue("linear");
180 
181  fSetH1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h1/set", this);
182  fSetH1Cmd->SetGuidance("Set parameters for the 1D histogram of given id:");
183  fSetH1Cmd->SetGuidance(" nbins; valMin; valMax; unit; function; binScheme");
184  fSetH1Cmd->SetParameter(h1Id);
185  fSetH1Cmd->SetParameter(h1Nbins);
186  fSetH1Cmd->SetParameter(h1ValMin);
187  fSetH1Cmd->SetParameter(h1ValMax);
188  fSetH1Cmd->SetParameter(h1ValUnit);
189  fSetH1Cmd->SetParameter(h1ValFcn);
190  fSetH1Cmd->SetParameter(h1ValBinScheme);
191  fSetH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
192 }
193 
194 //
195 // public functions
196 //
197 
198 //_____________________________________________________________________________
200 {
201  // tokenize parameters in a vector
202  std::vector<G4String> parameters;
203  G4Analysis::Tokenize(newValues, parameters);
204  // check consistency
205  if ( parameters.size() != command->GetParameterEntries() ) {
206  // Should never happen but let's check anyway for consistency
207  fHelper->WarnAboutParameters(command, parameters.size());
208  return;
209  }
210 
211  if ( command == fCreateH1Cmd.get() ) {
212  auto counter = 0;
213  auto name = parameters[counter++];
214  auto title = parameters[counter++];
216  fHelper->GetBinData(xdata, parameters, counter);
217  auto unit = GetUnitValue(xdata.fSunit);
219  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
220  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
221  }
222  else if ( command == fSetH1Cmd.get() ) {
223  auto counter = 0;
224  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
226  fHelper->GetBinData(xdata, parameters, counter);
227  auto unit = GetUnitValue(xdata.fSunit);
228  fManager->SetH1(id,
229  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
230  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
231  }
232  else if ( command == fSetH1XCmd.get() ) {
233  auto counter = 0;
234  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
236  fHelper->GetBinData(xdata, parameters, counter);
237  auto unit = GetUnitValue(xdata.fSunit);
238  fManager->SetH1(id,
239  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
240  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
241  }
242  else if ( command == fSetH1TitleCmd.get() ) {
243  auto counter = 0;
244  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
245  auto title = parameters[counter++];
246  fManager->SetH1Title(id, title);
247  }
248  else if ( command == fSetH1XAxisCmd.get() ) {
249  auto counter = 0;
250  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
251  auto xaxis = parameters[counter++];
253  }
254  else if ( command == fSetH1YAxisCmd.get() ) {
255  auto counter = 0;
256  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
257  auto yaxis = parameters[counter++];
258  fManager->SetH1YAxisTitle(id, yaxis);
259  }
260  else if ( command == fSetH1XAxisLogCmd.get() ) {
261  auto counter = 0;
262  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
263  auto xaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
264  fManager->SetH1XAxisIsLog(id, xaxisLog);
265  }
266  else if ( command == fSetH1YAxisLogCmd.get() ) {
267  auto counter = 0;
268  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
269  auto yaxisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
270  fManager->SetH1YAxisIsLog(id, yaxisLog);
271  }
272 }