Geant4_10
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 
37 #include "G4UIdirectory.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIparameter.hh"
40 
41 #include <iostream>
42 
43 //_____________________________________________________________________________
45  : G4UImessenger(),
46  fManager(manager),
47  fH1Dir(0),
48  fCreateH1Cmd(0),
49  fSetH1Cmd(0),
50  fSetH1TitleCmd(0),
51  fSetH1XAxisCmd(0),
52  fSetH1YAxisCmd(0)
53 {
54  fH1Dir = new G4UIdirectory("/analysis/h1/");
55  fH1Dir->SetGuidance("1D histograms control");
56 
57  CreateH1Cmd();
58  SetH1Cmd();
59  SetH1TitleCmd();
60  SetH1XAxisCmd();
61  SetH1YAxisCmd();
62 }
63 
64 //_____________________________________________________________________________
66 {
67  delete fCreateH1Cmd;
68  delete fSetH1Cmd;
69  delete fSetH1TitleCmd;
70  delete fSetH1XAxisCmd;
71  delete fSetH1YAxisCmd;
72  delete fH1Dir;
73 }
74 
75 //
76 // private functions
77 //
78 
79 //_____________________________________________________________________________
80 void G4H1Messenger::CreateH1Cmd()
81 {
82  G4UIparameter* h1Name = new G4UIparameter("name", 's', false);
83  h1Name->SetGuidance("Histogram name (label)");
84 
85  G4UIparameter* h1Title = new G4UIparameter("title", 's', false);
86  h1Title->SetGuidance("Histogram title");
87 
88  G4UIparameter* h1Nbins0 = new G4UIparameter("nbins0", 'i', true);
89  h1Nbins0->SetGuidance("Number of bins (default = 100)");
90  h1Nbins0->SetGuidance("Can be reset with /analysis/h1/set command");
91  h1Nbins0->SetDefaultValue(100);
92 
93  G4UIparameter* h1ValMin0 = new G4UIparameter("valMin0", 'd', true);
94  h1ValMin0->SetGuidance("Minimum value, expressed in unit (default = 0.)");
95  h1ValMin0->SetGuidance("Can be reset with /analysis/h1/set command");
96  h1ValMin0->SetDefaultValue(0.);
97 
98  G4UIparameter* h1ValMax0 = new G4UIparameter("valMax0", 'd', true);
99  h1ValMax0->SetGuidance("Maximum value, expressed in unit (default = 1.)");
100  h1ValMax0->SetGuidance("Can be reset with /analysis/h1/set command");
101  h1ValMax0->SetDefaultValue(1.);
102 
103  G4UIparameter* h1ValUnit0 = new G4UIparameter("valUnit0", 's', true);
104  h1ValUnit0->SetGuidance("The unit of valMin0 and valMax0");
105  h1ValUnit0->SetDefaultValue("none");
106 
107  G4UIparameter* h1ValFcn0 = new G4UIparameter("valFcn0", 's', true);
108  G4String fcnGuidance = "The function applied to filled values (log, log10, exp).\n";
109  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
110  fcnGuidance += "but none value should be used insted.";
111  h1ValFcn0->SetGuidance(fcnGuidance);
112  h1ValFcn0->SetParameterCandidates("log log10 exp none");
113  h1ValFcn0->SetDefaultValue("none");
114 
115  G4UIparameter* h1ValBinScheme0 = new G4UIparameter("valBinScheme0", 's', true);
116  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
117  h1ValBinScheme0->SetParameterCandidates("linear log");
118  binSchemeGuidance
119  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
120  binSchemeGuidance += "but none value should be used insted.";
121  h1ValBinScheme0->SetGuidance(binSchemeGuidance);
122  h1ValBinScheme0->SetDefaultValue("linear");
123 
124  fCreateH1Cmd = new G4UIcommand("/analysis/h1/create", this);
125  fCreateH1Cmd->SetGuidance("Create 1D histogram");
126  fCreateH1Cmd->SetParameter(h1Name);
127  fCreateH1Cmd->SetParameter(h1Title);
128  fCreateH1Cmd->SetParameter(h1Nbins0);
129  fCreateH1Cmd->SetParameter(h1ValMin0);
130  fCreateH1Cmd->SetParameter(h1ValMax0);
131  fCreateH1Cmd->SetParameter(h1ValUnit0);
132  fCreateH1Cmd->SetParameter(h1ValFcn0);
133  fCreateH1Cmd->SetParameter(h1ValBinScheme0);
135 }
136 
137 
138 //_____________________________________________________________________________
139 void G4H1Messenger::SetH1Cmd()
140 {
141  G4UIparameter* h1Id = new G4UIparameter("id", 'i', false);
142  h1Id->SetGuidance("Histogram id");
143  h1Id->SetParameterRange("id>=0");
144 
145  G4UIparameter* h1Nbins = new G4UIparameter("nbins", 'i', false);
146  h1Nbins->SetGuidance("Number of bins");
147 
148  G4UIparameter* h1ValMin = new G4UIparameter("valMin", 'd', false);
149  h1ValMin->SetGuidance("Minimum value, expressed in unit");
150 
151  G4UIparameter* h1ValMax = new G4UIparameter("valMax", 'd', false);
152  h1ValMax->SetGuidance("Maximum value, expressed in unit");
153 
154  G4UIparameter* h1ValUnit = new G4UIparameter("valUnit", 's', true);
155  h1ValUnit->SetGuidance("The unit of valMin and valMax");
156  h1ValUnit->SetDefaultValue("none");
157 
158  G4UIparameter* h1ValFcn = new G4UIparameter("valFcn", 's', true);
159  h1ValFcn->SetParameterCandidates("log log10 exp none");
160  G4String fcnGuidance = "The function applied to filled values (log, log10, exp, none).\n";
161  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
162  fcnGuidance += "but none value should be used insted.";
163  h1ValFcn->SetGuidance(fcnGuidance);
164  h1ValFcn->SetDefaultValue("none");
165 
166  G4UIparameter* h1ValBinScheme = new G4UIparameter("valBinScheme", 's', true);
167  h1ValBinScheme->SetParameterCandidates("linear log");
168  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
169  binSchemeGuidance
170  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
171  binSchemeGuidance += "but none value should be used insted.";
172  h1ValBinScheme->SetGuidance(binSchemeGuidance);
173  h1ValBinScheme->SetDefaultValue("linear");
174 
175  fSetH1Cmd = new G4UIcommand("/analysis/h1/set", this);
176  fSetH1Cmd->SetGuidance("Set parameters for the 1D histogram of #Id :");
177  fSetH1Cmd->SetGuidance(" nbins; valMin; valMax; unit (of vmin and vmax)");
178  fSetH1Cmd->SetParameter(h1Id);
179  fSetH1Cmd->SetParameter(h1Nbins);
180  fSetH1Cmd->SetParameter(h1ValMin);
181  fSetH1Cmd->SetParameter(h1ValMax);
182  fSetH1Cmd->SetParameter(h1ValUnit);
183  fSetH1Cmd->SetParameter(h1ValFcn);
184  fSetH1Cmd->SetParameter(h1ValBinScheme);
186 }
187 
188 //_____________________________________________________________________________
189 void G4H1Messenger::SetH1TitleCmd()
190 {
191  G4UIparameter* h1Id = new G4UIparameter("idTitle", 'i', false);
192  h1Id->SetGuidance("Histogram id");
193  h1Id->SetParameterRange("idTitle>=0");
194 
195  G4UIparameter* h1Title = new G4UIparameter("h1Title", 's', true);
196  h1Title->SetGuidance("Histogram title");
197  h1Title->SetDefaultValue("none");
198 
199  fSetH1TitleCmd = new G4UIcommand("/analysis/h1/setTitle", this);
200  fSetH1TitleCmd->SetGuidance("Set title for the 1D histogram of #Id");
201  fSetH1TitleCmd->SetParameter(h1Id);
202  fSetH1TitleCmd->SetParameter(h1Title);
204 }
205 
206 //_____________________________________________________________________________
207 void G4H1Messenger::SetH1XAxisCmd()
208 {
209  G4UIparameter* h1Id = new G4UIparameter("idXaxis", 'i', false);
210  h1Id->SetGuidance("Histogram id");
211  h1Id->SetParameterRange("idXaxis>=0");
212 
213  G4UIparameter* h1XAxis = new G4UIparameter("h1Xaxis", 's', true);
214  h1XAxis->SetGuidance("Histogram x-axis title");
215  h1XAxis->SetDefaultValue("none");
216 
217  fSetH1XAxisCmd = new G4UIcommand("/analysis/h1/setXaxis", this);
218  fSetH1XAxisCmd->SetGuidance("Set x-axis title for the 1D histogram of #Id");
219  fSetH1XAxisCmd->SetParameter(h1Id);
220  fSetH1XAxisCmd->SetParameter(h1XAxis);
222 }
223 
224 //_____________________________________________________________________________
225 void G4H1Messenger::SetH1YAxisCmd()
226 {
227  G4UIparameter* h1Id = new G4UIparameter("idYaxis", 'i', false);
228  h1Id->SetGuidance("Histogram id");
229  h1Id->SetParameterRange("idYaxis>=0");
230 
231  G4UIparameter* h1YAxis = new G4UIparameter("h1Yaxis", 's', true);
232  h1YAxis->SetGuidance("Histogram y-axis title");
233  h1YAxis->SetDefaultValue("none");
234 
235  fSetH1YAxisCmd = new G4UIcommand("/analysis/h1/setYaxis", this);
236  fSetH1YAxisCmd->SetGuidance("Set y-axis title for the 1D histogram of #Id");
237  fSetH1YAxisCmd->SetParameter(h1Id);
238  fSetH1YAxisCmd->SetParameter(h1YAxis);
240 }
241 
242 //
243 // public functions
244 //
245 
246 //_____________________________________________________________________________
248 {
249  if ( command == fCreateH1Cmd ) {
251  G4int nbins;
252  G4double vmin,vmax;
253  G4String sunit;
254  G4String sfcn;
255  G4String sbinScheme;
256  std::istringstream is(newValues.data());
257  is >> name >> title >> nbins >> vmin >> vmax >> sunit >> sfcn >> sbinScheme;
258  fManager->CreateH1(name, title, nbins, vmin, vmax, sunit, sfcn, sbinScheme);
259  }
260  else if ( command == fSetH1Cmd ) {
261  G4int id;
262  G4int nbins;
263  G4double vmin, vmax;
264  G4String sunit;
265  G4String sfcn;
266  G4String sbinScheme;
267  std::istringstream is(newValues.data());
268  is >> id >> nbins >> vmin >> vmax >> sunit >> sfcn >> sbinScheme;
269  fManager->SetH1(id, nbins, vmin, vmax, sunit, sfcn, sbinScheme);
270  }
271  else if ( command == fSetH1TitleCmd ) {
272  G4int id;
273  G4String title;
274  std::istringstream is(newValues.data());
275  is >> id;
276  getline(is, title);
277  fManager->SetH1Title(id, title);
278  }
279  else if ( command == fSetH1XAxisCmd ) {
280  G4int id;
281  G4String xaxis;
282  std::istringstream is(newValues.data());
283  is >> id;
284  getline(is, xaxis);
285  fManager->SetH1XAxisTitle(id, xaxis);
286  }
287  else if ( command == fSetH1YAxisCmd ) {
288  G4int id;
289  G4String yaxis;
290  std::istringstream is(newValues.data());
291  is >> id;
292  getline(is, yaxis);
293  fManager->SetH1YAxisTitle(id, yaxis);
294  }
295 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
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)
void SetDefaultValue(const char *theDefaultValue)
const XML_Char * name
Definition: expat.h:151
int G4int
Definition: G4Types.hh:78
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
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
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
virtual void SetNewValue(G4UIcommand *command, G4String value)
const char * data() const
subroutine title(NA, NB, NCA, NCB)
Definition: dpm25nuc7.f:1744
G4H1Messenger(G4VAnalysisManager *manager)
virtual ~G4H1Messenger()
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
G4bool SetH1Title(G4int id, const G4String &title)
G4bool SetH1XAxisTitle(G4int id, const G4String &title)