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