source: trunk/examples/extended/electromagnetic/TestEm11/src/HistoMessenger.cc@ 1310

Last change on this file since 1310 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

File size: 6.0 KB
Line 
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: HistoMessenger.cc,v 1.6 2008/01/11 13:01:57 jjacquem Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "HistoMessenger.hh"
33
34#include <sstream>
35
36#include "HistoManager.hh"
37#include "G4UIdirectory.hh"
38#include "G4UIcommand.hh"
39#include "G4UIparameter.hh"
40#include "G4UIcmdWithAString.hh"
41#include "G4UIcmdWithAnInteger.hh"
42#include "G4UIcmdWithADoubleAndUnit.hh"
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46HistoMessenger::HistoMessenger(HistoManager* manager)
47:histoManager (manager)
48{
49 histoDir = new G4UIdirectory("/testem/histo/");
50 histoDir->SetGuidance("histograms control");
51
52 factoryCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this);
53 factoryCmd->SetGuidance("set name for the histograms file");
54
55 typeCmd = new G4UIcmdWithAString("/testem/histo/setFileType",this);
56 typeCmd->SetGuidance("set histograms file type: hbook, root, XML");
57 typeCmd->SetCandidates("hbook root XML");
58
59 optionCmd = new G4UIcmdWithAString("/testem/histo/setFileOption",this);
60 optionCmd->SetGuidance("set option for the histograms file");
61
62 histoCmd = new G4UIcommand("/testem/histo/setHisto",this);
63 histoCmd->SetGuidance("Set bining of the histo number ih :");
64 histoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
65 //
66 G4UIparameter* ih = new G4UIparameter("ih",'i',false);
67 ih->SetGuidance("histo number : from 1 to MaxHisto");
68 ih->SetParameterRange("ih>0");
69 histoCmd->SetParameter(ih);
70 //
71 G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false);
72 nbBins->SetGuidance("number of bins");
73 nbBins->SetParameterRange("nbBins>0");
74 histoCmd->SetParameter(nbBins);
75 //
76 G4UIparameter* valMin = new G4UIparameter("valMin",'d',false);
77 valMin->SetGuidance("valMin, expressed in unit");
78 histoCmd->SetParameter(valMin);
79 //
80 G4UIparameter* valMax = new G4UIparameter("valMax",'d',false);
81 valMax->SetGuidance("valMax, expressed in unit");
82 histoCmd->SetParameter(valMax);
83 //
84 G4UIparameter* unit = new G4UIparameter("unit",'s',true);
85 unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
86 unit->SetDefaultValue("none");
87 histoCmd->SetParameter(unit);
88
89 prhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/printHisto",this);
90 prhistoCmd->SetGuidance("print histo #id on ascii file");
91 prhistoCmd->SetParameterName("id",false);
92 prhistoCmd->SetRange("id>0");
93
94 rmhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/removeHisto",this);
95 rmhistoCmd->SetGuidance("desactivate histo #id");
96 rmhistoCmd->SetParameterName("id",false);
97 rmhistoCmd->SetRange("id>0");
98
99 csdaCmd = new G4UIcmdWithADoubleAndUnit("/testem/histo/setcsdaRange",this);
100 csdaCmd->SetGuidance("Set csda range for normalisation");
101 csdaCmd->SetParameterName("csda",false);
102 csdaCmd->SetRange("csda>0.");
103 csdaCmd->SetUnitCategory("Length");
104}
105
106//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107
108HistoMessenger::~HistoMessenger()
109{
110 delete csdaCmd;
111 delete rmhistoCmd;
112 delete prhistoCmd;
113 delete histoCmd;
114 delete typeCmd;
115 delete factoryCmd;
116 delete histoDir;
117 delete optionCmd;
118}
119
120//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
121
122void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
123{
124 if (command == factoryCmd)
125 histoManager->SetFileName(newValues);
126
127 if (command == typeCmd)
128 histoManager->SetFileType(newValues);
129
130 if (command == optionCmd)
131 histoManager->SetFileOption(newValues);
132
133 if (command == histoCmd)
134 { G4int ih,nbBins; G4double vmin,vmax; char unts[30];
135 const char* t = newValues;
136 std::istringstream is(t);
137 is >> ih >> nbBins >> vmin >> vmax >> unts;
138 G4String unit = unts;
139 G4double vUnit = 1. ;
140 if (unit != "none") vUnit = G4UIcommand::ValueOf(unit);
141 histoManager->SetHisto (ih,nbBins,vmin*vUnit,vmax*vUnit,unit);
142 }
143
144 if (command == prhistoCmd)
145 histoManager->PrintHisto(prhistoCmd->GetNewIntValue(newValues));
146
147 if (command == rmhistoCmd)
148 histoManager->RemoveHisto(rmhistoCmd->GetNewIntValue(newValues));
149
150 if (command == csdaCmd)
151 histoManager->SetcsdaRange(csdaCmd->GetNewDoubleValue(newValues));
152}
153
154//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155
Note: See TracBrowser for help on using the repository browser.