Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
38 
39 #include "G4UIdirectory.hh"
40 #include "G4UIcommand.hh"
41 #include "G4UIparameter.hh"
42 #include "G4Tokenizer.hh"
43 
44 #include <iostream>
45 #include <vector>
46 
47 using namespace G4Analysis;
48 
49 //_____________________________________________________________________________
51  : G4UImessenger(),
52  fManager(manager),
53  fHelper(nullptr),
54  fDirectory(nullptr),
55  fCreateH1Cmd(nullptr),
56  fSetH1Cmd(nullptr),
57  fSetH1TitleCmd(nullptr),
58  fSetH1XAxisCmd(nullptr),
59  fSetH1YAxisCmd(nullptr)
60 {
61  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("h1");
62 
63  fDirectory = fHelper->CreateHnDirectory();
64 
65  CreateH1Cmd();
66 
67  SetH1Cmd();
68  fSetH1XCmd = fHelper->CreateSetBinsCommand("x", this);
69 
70 
71  fSetH1TitleCmd = fHelper->CreateSetTitleCommand(this);
72  fSetH1XAxisCmd = fHelper->CreateSetAxisCommand("x", this);
73  fSetH1YAxisCmd = fHelper->CreateSetAxisCommand("y", this);
74 }
75 
76 //_____________________________________________________________________________
78 {}
79 
80 //
81 // private functions
82 //
83 
84 //_____________________________________________________________________________
85 void G4H1Messenger::CreateH1Cmd()
86 {
87  auto h1Name = new G4UIparameter("name", 's', false);
88  h1Name->SetGuidance("Histogram name (label)");
89 
90  auto h1Title = new G4UIparameter("title", 's', false);
91  h1Title->SetGuidance("Histogram title");
92 
93  auto h1Nbins0 = new G4UIparameter("nbins0", 'i', true);
94  h1Nbins0->SetGuidance("Number of bins (default = 100)");
95  h1Nbins0->SetGuidance("Can be reset with /analysis/h1/set command");
96  h1Nbins0->SetDefaultValue(100);
97 
98  auto h1ValMin0 = new G4UIparameter("valMin0", 'd', true);
99  h1ValMin0->SetGuidance("Minimum value, expressed in unit (default = 0.)");
100  h1ValMin0->SetGuidance("Can be reset with /analysis/h1/set command");
101  h1ValMin0->SetDefaultValue(0.);
102 
103  auto h1ValMax0 = new G4UIparameter("valMax0", 'd', true);
104  h1ValMax0->SetGuidance("Maximum value, expressed in unit (default = 1.)");
105  h1ValMax0->SetGuidance("Can be reset with /analysis/h1/set command");
106  h1ValMax0->SetDefaultValue(1.);
107 
108  auto h1ValUnit0 = new G4UIparameter("valUnit0", 's', true);
109  h1ValUnit0->SetGuidance("The unit applied to filled values and valMin0, valMax0");
110  h1ValUnit0->SetDefaultValue("none");
111 
112  auto h1ValFcn0 = new G4UIparameter("valFcn0", 's', true);
113  G4String fcnGuidance = "The function applied to filled values (log, log10, exp).\n";
114  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
115  fcnGuidance += "but none value should be used instead.";
116  h1ValFcn0->SetGuidance(fcnGuidance);
117  h1ValFcn0->SetParameterCandidates("log log10 exp none");
118  h1ValFcn0->SetDefaultValue("none");
119 
120  auto h1ValBinScheme0 = new G4UIparameter("valBinScheme0", 's', true);
121  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
122  h1ValBinScheme0->SetParameterCandidates("linear log");
123  binSchemeGuidance
124  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
125  binSchemeGuidance += "but none value should be used instead.";
126  h1ValBinScheme0->SetGuidance(binSchemeGuidance);
127  h1ValBinScheme0->SetDefaultValue("linear");
128 
129  fCreateH1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h1/create", this);
130  fCreateH1Cmd->SetGuidance("Create 1D histogram");
131  fCreateH1Cmd->SetParameter(h1Name);
132  fCreateH1Cmd->SetParameter(h1Title);
133  fCreateH1Cmd->SetParameter(h1Nbins0);
134  fCreateH1Cmd->SetParameter(h1ValMin0);
135  fCreateH1Cmd->SetParameter(h1ValMax0);
136  fCreateH1Cmd->SetParameter(h1ValUnit0);
137  fCreateH1Cmd->SetParameter(h1ValFcn0);
138  fCreateH1Cmd->SetParameter(h1ValBinScheme0);
139  fCreateH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
140 }
141 
142 
143 //_____________________________________________________________________________
144 void G4H1Messenger::SetH1Cmd()
145 {
146  auto h1Id = new G4UIparameter("id", 'i', false);
147  h1Id->SetGuidance("Histogram id");
148  h1Id->SetParameterRange("id>=0");
149 
150  auto h1Nbins = new G4UIparameter("nbins", 'i', false);
151  h1Nbins->SetGuidance("Number of bins");
152 
153  auto h1ValMin = new G4UIparameter("valMin", 'd', false);
154  h1ValMin->SetGuidance("Minimum value, expressed in unit");
155 
156  auto h1ValMax = new G4UIparameter("valMax", 'd', false);
157  h1ValMax->SetGuidance("Maximum value, expressed in unit");
158 
159  auto h1ValUnit = new G4UIparameter("valUnit", 's', true);
160  h1ValUnit->SetGuidance("The unit applied to filled values and valMin, valMax");
161  h1ValUnit->SetDefaultValue("none");
162 
163  auto h1ValFcn = new G4UIparameter("valFcn", 's', true);
164  h1ValFcn->SetParameterCandidates("log log10 exp none");
165  G4String fcnGuidance = "The function applied to filled values (log, log10, exp, none).\n";
166  fcnGuidance += "Note that the unit parameter cannot be omitted in this case,\n";
167  fcnGuidance += "but none value should be used instead.";
168  h1ValFcn->SetGuidance(fcnGuidance);
169  h1ValFcn->SetDefaultValue("none");
170 
171  auto h1ValBinScheme = new G4UIparameter("valBinScheme", 's', true);
172  h1ValBinScheme->SetParameterCandidates("linear log");
173  G4String binSchemeGuidance = "The binning scheme (linear, log).\n";
174  binSchemeGuidance
175  += "Note that the unit and fcn parameters cannot be omitted in this case,\n";
176  binSchemeGuidance += "but none value should be used instead.";
177  h1ValBinScheme->SetGuidance(binSchemeGuidance);
178  h1ValBinScheme->SetDefaultValue("linear");
179 
180  fSetH1Cmd = G4Analysis::make_unique<G4UIcommand>("/analysis/h1/set", this);
181  fSetH1Cmd->SetGuidance("Set parameters for the 1D histogram of given id:");
182  fSetH1Cmd->SetGuidance(" nbins; valMin; valMax; unit; function; binScheme");
183  fSetH1Cmd->SetParameter(h1Id);
184  fSetH1Cmd->SetParameter(h1Nbins);
185  fSetH1Cmd->SetParameter(h1ValMin);
186  fSetH1Cmd->SetParameter(h1ValMax);
187  fSetH1Cmd->SetParameter(h1ValUnit);
188  fSetH1Cmd->SetParameter(h1ValFcn);
189  fSetH1Cmd->SetParameter(h1ValBinScheme);
190  fSetH1Cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
191 }
192 
193 //
194 // public functions
195 //
196 
197 //_____________________________________________________________________________
199 {
200  // tokenize parameters in a vector
201  std::vector<G4String> parameters;
202  G4Analysis::Tokenize(newValues, parameters);
203  // check consistency
204  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
205  // Should never happen but let's check anyway for consistency
206  fHelper->WarnAboutParameters(command, parameters.size());
207  return;
208  }
209 
210  if ( command == fCreateH1Cmd.get() ) {
211  auto counter = 0;
212  auto name = parameters[counter++];
213  auto title = parameters[counter++];
215  fHelper->GetBinData(xdata, parameters, counter);
216  auto unit = GetUnitValue(xdata.fSunit);
217  fManager->CreateH1(name, title,
218  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
219  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
220  }
221  else if ( command == fSetH1Cmd.get() ) {
222  auto counter = 0;
223  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
225  fHelper->GetBinData(xdata, parameters, counter);
226  auto unit = GetUnitValue(xdata.fSunit);
227  fManager->SetH1(id,
228  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
229  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
230  }
231  else if ( command == fSetH1XCmd.get() ) {
232  auto counter = 0;
233  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
235  fHelper->GetBinData(xdata, parameters, counter);
236  auto unit = GetUnitValue(xdata.fSunit);
237  fManager->SetH1(id,
238  xdata.fNbins, xdata.fVmin*unit, xdata.fVmax*unit,
239  xdata.fSunit, xdata.fSfcn, xdata.fSbinScheme);
240  }
241  else if ( command == fSetH1TitleCmd.get() ) {
242  auto counter = 0;
243  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
244  auto title = parameters[counter++];
245  fManager->SetH1Title(id, title);
246  }
247  else if ( command == fSetH1XAxisCmd.get() ) {
248  auto counter = 0;
249  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
250  auto xaxis = parameters[counter++];
251  fManager->SetH1XAxisTitle(id, xaxis);
252  }
253  else if ( command == fSetH1YAxisCmd.get() ) {
254  auto counter = 0;
255  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
256  auto yaxis = parameters[counter++];
257  fManager->SetH1YAxisTitle(id, yaxis);
258  }
259 }
const XML_Char * name
Definition: expat.h:151
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")
int G4int
Definition: G4Types.hh:78
G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
G4double GetUnitValue(const G4String &unit)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:447
virtual void SetNewValue(G4UIcommand *command, G4String value) final
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4H1Messenger(G4VAnalysisManager *manager)
virtual ~G4H1Messenger()
G4bool SetH1Title(G4int id, const G4String &title)
subroutine title
Definition: hijing1.383.f:5980
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool SetH1XAxisTitle(G4int id, const G4String &title)