Geant4  10.01.p01
G4H1Messenger.cc
Go to the documentation of this file.
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 // $Id: G4H1Messenger.cc 66310 2012-12-17 11:56:35Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 24/06/2013 (ivana@ipno.in2p3.fr)
29 //
30 // This messenger class is a generalization of the HistoMessenger class,
31 // originally developed for the extended/electromagnetic examples
32 // by Michel Maire (michel.maire@lapp.in2p3.fr)
33 
34 #include "G4H1Messenger.hh"
35 #include "G4VAnalysisManager.hh"
36 #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 namespace {
49 
50 void Exception(G4UIcommand* command, G4int nofParameters)
51 {
52  G4ExceptionDescription description;
53  description
54  << "Got wrong number of \"" << command->GetCommandName()
55  << "\" parameters: " << nofParameters
56  << " instead of " << command->GetParameterEntries()
57  << " expected" << G4endl;
58  G4Exception("G4H1Messenger::SetNewValue",
59  "Analysis_W013", JustWarning, description);
60 }
61 
62 }
63 
64 //_____________________________________________________________________________
66  : G4UImessenger(),
67  fManager(manager),
68  fH1Dir(0),
69  fCreateH1Cmd(0),
70  fSetH1Cmd(0),
71  fSetH1TitleCmd(0),
72  fSetH1XAxisCmd(0),
73  fSetH1YAxisCmd(0)
74 {
75  fH1Dir = new G4UIdirectory("/analysis/h1/");
76  fH1Dir->SetGuidance("1D histograms control");
77 
78  CreateH1Cmd();
79  SetH1Cmd();
80  SetH1TitleCmd();
81  SetH1XAxisCmd();
82  SetH1YAxisCmd();
83 }
84 
85 //_____________________________________________________________________________
87 {
88  delete fCreateH1Cmd;
89  delete fSetH1Cmd;
90  delete fSetH1TitleCmd;
91  delete fSetH1XAxisCmd;
92  delete fSetH1YAxisCmd;
93  delete fH1Dir;
94 }
95 
96 //
97 // private functions
98 //
99 
100 //_____________________________________________________________________________
102 {
103  G4UIparameter* h1Name = new G4UIparameter("name", 's', false);
104  h1Name->SetGuidance("Histogram name (label)");
105 
106  G4UIparameter* h1Title = new G4UIparameter("title", 's', false);
107  h1Title->SetGuidance("Histogram title");
108 
109  G4UIparameter* h1Nbins0 = new G4UIparameter("nbins0", 'i', true);
110  h1Nbins0->SetGuidance("Number of bins (default = 100)");
111  h1Nbins0->SetGuidance("Can be reset with /analysis/h1/set command");
112  h1Nbins0->SetDefaultValue(100);
113 
114  G4UIparameter* h1ValMin0 = new G4UIparameter("valMin0", 'd', true);
115  h1ValMin0->SetGuidance("Minimum value, expressed in unit (default = 0.)");
116  h1ValMin0->SetGuidance("Can be reset with /analysis/h1/set command");
117  h1ValMin0->SetDefaultValue(0.);
118 
119  G4UIparameter* h1ValMax0 = new G4UIparameter("valMax0", 'd', true);
120  h1ValMax0->SetGuidance("Maximum value, expressed in unit (default = 1.)");
121  h1ValMax0->SetGuidance("Can be reset with /analysis/h1/set command");
122  h1ValMax0->SetDefaultValue(1.);
123 
124  G4UIparameter* h1ValUnit0 = new G4UIparameter("valUnit0", 's', true);
125  h1ValUnit0->SetGuidance("The unit applied to filled values and valMin0, valMax0");
126  h1ValUnit0->SetDefaultValue("none");
127 
128  G4UIparameter* h1ValFcn0 = new G4UIparameter("valFcn0", 's', true);
129  G4String fcnGuidance = "The function applied to filled values (log, log10, exp).\n";
130  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
131  fcnGuidance += "but none value should be used instead.";
132  h1ValFcn0->SetGuidance(fcnGuidance);
133  h1ValFcn0->SetParameterCandidates("log log10 exp none");
134  h1ValFcn0->SetDefaultValue("none");
135 
136  G4UIparameter* h1ValBinScheme0 = new G4UIparameter("valBinScheme0", 's', true);
137  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
138  h1ValBinScheme0->SetParameterCandidates("linear log");
139  binSchemeGuidance
140  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
141  binSchemeGuidance += "but none value should be used instead.";
142  h1ValBinScheme0->SetGuidance(binSchemeGuidance);
143  h1ValBinScheme0->SetDefaultValue("linear");
144 
145  fCreateH1Cmd = new G4UIcommand("/analysis/h1/create", this);
146  fCreateH1Cmd->SetGuidance("Create 1D histogram");
147  fCreateH1Cmd->SetParameter(h1Name);
148  fCreateH1Cmd->SetParameter(h1Title);
149  fCreateH1Cmd->SetParameter(h1Nbins0);
150  fCreateH1Cmd->SetParameter(h1ValMin0);
151  fCreateH1Cmd->SetParameter(h1ValMax0);
152  fCreateH1Cmd->SetParameter(h1ValUnit0);
153  fCreateH1Cmd->SetParameter(h1ValFcn0);
154  fCreateH1Cmd->SetParameter(h1ValBinScheme0);
156 }
157 
158 
159 //_____________________________________________________________________________
161 {
162  G4UIparameter* h1Id = new G4UIparameter("id", 'i', false);
163  h1Id->SetGuidance("Histogram id");
164  h1Id->SetParameterRange("id>=0");
165 
166  G4UIparameter* h1Nbins = new G4UIparameter("nbins", 'i', false);
167  h1Nbins->SetGuidance("Number of bins");
168 
169  G4UIparameter* h1ValMin = new G4UIparameter("valMin", 'd', false);
170  h1ValMin->SetGuidance("Minimum value, expressed in unit");
171 
172  G4UIparameter* h1ValMax = new G4UIparameter("valMax", 'd', false);
173  h1ValMax->SetGuidance("Maximum value, expressed in unit");
174 
175  G4UIparameter* h1ValUnit = new G4UIparameter("valUnit", 's', true);
176  h1ValUnit->SetGuidance("The unit applied to filled values and valMin, valMax");
177  h1ValUnit->SetDefaultValue("none");
178 
179  G4UIparameter* h1ValFcn = new G4UIparameter("valFcn", 's', true);
180  h1ValFcn->SetParameterCandidates("log log10 exp none");
181  G4String fcnGuidance = "The function applied to filled values (log, log10, exp, none).\n";
182  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
183  fcnGuidance += "but none value should be used instead.";
184  h1ValFcn->SetGuidance(fcnGuidance);
185  h1ValFcn->SetDefaultValue("none");
186 
187  G4UIparameter* h1ValBinScheme = new G4UIparameter("valBinScheme", 's', true);
188  h1ValBinScheme->SetParameterCandidates("linear log");
189  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
190  binSchemeGuidance
191  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
192  binSchemeGuidance += "but none value should be used instead.";
193  h1ValBinScheme->SetGuidance(binSchemeGuidance);
194  h1ValBinScheme->SetDefaultValue("linear");
195 
196  fSetH1Cmd = new G4UIcommand("/analysis/h1/set", this);
197  fSetH1Cmd->SetGuidance("Set parameters for the 1D histogram of #Id :");
198  fSetH1Cmd->SetGuidance(" nbins; valMin; valMax; unit; function; binScheme");
199  fSetH1Cmd->SetParameter(h1Id);
200  fSetH1Cmd->SetParameter(h1Nbins);
201  fSetH1Cmd->SetParameter(h1ValMin);
202  fSetH1Cmd->SetParameter(h1ValMax);
203  fSetH1Cmd->SetParameter(h1ValUnit);
204  fSetH1Cmd->SetParameter(h1ValFcn);
205  fSetH1Cmd->SetParameter(h1ValBinScheme);
207 }
208 
209 //_____________________________________________________________________________
211 {
212  G4UIparameter* h1Id = new G4UIparameter("idTitle", 'i', false);
213  h1Id->SetGuidance("Histogram id");
214  h1Id->SetParameterRange("idTitle>=0");
215 
216  G4UIparameter* h1Title = new G4UIparameter("h1Title", 's', true);
217  h1Title->SetGuidance("Histogram title");
218  h1Title->SetDefaultValue("none");
219 
220  fSetH1TitleCmd = new G4UIcommand("/analysis/h1/setTitle", this);
221  fSetH1TitleCmd->SetGuidance("Set title for the 1D histogram of #Id");
223  fSetH1TitleCmd->SetParameter(h1Title);
225 }
226 
227 //_____________________________________________________________________________
229 {
230  G4UIparameter* h1Id = new G4UIparameter("idXaxis", 'i', false);
231  h1Id->SetGuidance("Histogram id");
232  h1Id->SetParameterRange("idXaxis>=0");
233 
234  G4UIparameter* h1XAxis = new G4UIparameter("h1Xaxis", 's', true);
235  h1XAxis->SetGuidance("Histogram x-axis title");
236  h1XAxis->SetDefaultValue("none");
237 
238  fSetH1XAxisCmd = new G4UIcommand("/analysis/h1/setXaxis", this);
239  fSetH1XAxisCmd->SetGuidance("Set x-axis title for the 1D histogram of #Id");
241  fSetH1XAxisCmd->SetParameter(h1XAxis);
243 }
244 
245 //_____________________________________________________________________________
247 {
248  G4UIparameter* h1Id = new G4UIparameter("idYaxis", 'i', false);
249  h1Id->SetGuidance("Histogram id");
250  h1Id->SetParameterRange("idYaxis>=0");
251 
252  G4UIparameter* h1YAxis = new G4UIparameter("h1Yaxis", 's', true);
253  h1YAxis->SetGuidance("Histogram y-axis title");
254  h1YAxis->SetDefaultValue("none");
255 
256  fSetH1YAxisCmd = new G4UIcommand("/analysis/h1/setYaxis", this);
257  fSetH1YAxisCmd->SetGuidance("Set y-axis title for the 1D histogram of #Id");
259  fSetH1YAxisCmd->SetParameter(h1YAxis);
261 }
262 
263 //
264 // public functions
265 //
266 
267 //_____________________________________________________________________________
269 {
270  // tokenize parameters in a vector
271  std::vector<G4String> parameters;
272  G4Analysis::Tokenize(newValues, parameters);
273  // check consistency
274  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
275  // Should never happen but let's check anyway for consistency
276  Exception(command, parameters.size());
277  return;
278  }
279 
280  if ( command == fCreateH1Cmd ) {
281  G4int counter = 0;
282  G4String name = parameters[counter++];
283  G4String title = parameters[counter++];
284  G4int nbins = G4UIcommand::ConvertToInt(parameters[counter++]);
285  G4double vmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
286  G4double vmax = G4UIcommand::ConvertToDouble(parameters[counter++]); ;
287  G4String sunit = parameters[counter++];
288  G4String sfcn = parameters[counter++];
289  G4String sbinScheme = parameters[counter++];
290  G4double unit = GetUnitValue(sunit);
291  fManager->CreateH1(name, title, nbins, vmin*unit, vmax*unit, sunit, sfcn, sbinScheme);
292  }
293  else if ( command == fSetH1Cmd ) {
294  G4int counter = 0;
295  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
296  G4int nbins = G4UIcommand::ConvertToInt(parameters[counter++]);
297  G4double vmin = G4UIcommand::ConvertToDouble(parameters[counter++]);
298  G4double vmax = G4UIcommand::ConvertToDouble(parameters[counter++]);
299  G4String sunit = parameters[counter++];
300  G4String sfcn = parameters[counter++];
301  G4String sbinScheme = parameters[counter++];
302  G4double unit = GetUnitValue(sunit);
303  fManager->SetH1(id, nbins, vmin*unit, vmax*unit, sunit, sfcn, sbinScheme);
304  }
305  else if ( command == fSetH1TitleCmd ) {
306  G4int counter = 0;
307  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
308  G4String title = parameters[counter++];
309  fManager->SetH1Title(id, title);
310  }
311  else if ( command == fSetH1XAxisCmd ) {
312  G4int counter = 0;
313  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
314  G4String xaxis = parameters[counter++];
315  fManager->SetH1XAxisTitle(id, xaxis);
316  }
317  else if ( command == fSetH1YAxisCmd ) {
318  G4int counter = 0;
319  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
320  G4String yaxis = parameters[counter++];
321  fManager->SetH1YAxisTitle(id, yaxis);
322  }
323 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetH1XAxisCmd()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
G4UIcommand * fSetH1YAxisCmd
G4String name
Definition: TRTMaterials.hh:40
void SetDefaultValue(const char *theDefaultValue)
int G4int
Definition: G4Types.hh:78
G4UIcommand * fCreateH1Cmd
void SetH1TitleCmd()
void SetH1YAxisCmd()
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:443
G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:239
G4UIcommand * fSetH1XAxisCmd
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
G4double GetUnitValue(const G4String &unit)
G4UIcommand * fSetH1TitleCmd
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
virtual void SetNewValue(G4UIcommand *command, G4String value)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
void Exception(const char *originOfException, const char *exceptionCode, UExceptionSeverity severity, int level, const char *description)
Definition: UUtils.cc:122
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4H1Messenger(G4VAnalysisManager *manager)
virtual ~G4H1Messenger()
G4UIcommand * fSetH1Cmd
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
G4bool SetH1Title(G4int id, const G4String &title)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool SetH1XAxisTitle(G4int id, const G4String &title)
G4UIdirectory * fH1Dir
G4VAnalysisManager * fManager
Associated class.