Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
GarfieldMessenger.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: GarfieldMessenger.cc 999995 2015-12-11 14:47:43Z dpfeiffe $
27//
28/// \file GarfieldMessenger.cc
29/// \brief Implementation of the GarfieldMessenger class
30
31#include "GarfieldMessenger.hh"
32
33#include "G4UIcmdWithADoubleAndUnit.hh"
34#include "G4UIcmdWithAString.hh"
35#include "G4UIcmdWithoutParameter.hh"
36#include "G4UIcommand.hh"
37#include "G4UIdirectory.hh"
38#include "G4UIparameter.hh"
40#include "GarfieldPhysics.hh"
41
43 : G4UImessenger(),
44 fDetector(Det),
45 fExampleDir(0),
46 fAbsorberDir(0),
47 fGarfieldPhysicsDir(0),
48 fMaterialCmd(0),
49 fIsotopeCmd(0),
50 fIonizationModelCmd(0),
51 fGeant4ParticleCmd(0) {
52 fExampleDir = new G4UIdirectory("/exampleGarfield/");
53 fExampleDir->SetGuidance("Commands specific to this example");
54
55 G4bool broadcast = false;
56 fAbsorberDir = new G4UIdirectory("/exampleGarfield/absorber/", broadcast);
57 fAbsorberDir->SetGuidance("Absorber construction commands");
58
59 fGarfieldPhysicsDir =
60 new G4UIdirectory("/exampleGarfield/physics/", broadcast);
61 fGarfieldPhysicsDir->SetGuidance(
62 "Particle and energy ranges for Garfield++ physics model");
63
64 fMaterialCmd =
65 new G4UIcmdWithAString("/exampleGarfield/absorber/setMat", this);
66 fMaterialCmd->SetGuidance("Select material of the absorber:");
67 fMaterialCmd->SetParameterName("choice", false);
68 fMaterialCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
69
70 fIsotopeCmd =
71 new G4UIcommand("/exampleGarfield/absorber/setIsotopeMat", this);
72 fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
73 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
74 //
75 G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
76 symbPrm->SetGuidance("isotope symbol");
77 fIsotopeCmd->SetParameter(symbPrm);
78 //
79 G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
80 ZPrm->SetGuidance("Z");
81 ZPrm->SetParameterRange("Z>0");
82 fIsotopeCmd->SetParameter(ZPrm);
83 //
84 G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
85 APrm->SetGuidance("A");
86 APrm->SetParameterRange("A>0");
87 fIsotopeCmd->SetParameter(APrm);
88 //
89 G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
90 densityPrm->SetGuidance("density of material");
91 densityPrm->SetParameterRange("density>0.");
92 fIsotopeCmd->SetParameter(densityPrm);
93 //
94 G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
95 unitPrm->SetGuidance("unit of density");
96 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
97 unitPrm->SetParameterCandidates(unitList);
98 fIsotopeCmd->SetParameter(unitPrm);
99 //
100 fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
101
102 fIonizationModelCmd =
103 new G4UIcommand("/exampleGarfield/physics/setIonizationModel", this);
104 fIonizationModelCmd->SetGuidance("Select ionization model for Garfield++");
105 fIonizationModelCmd->SetGuidance(
106 " and choose whether to use default particles");
107 fIonizationModelCmd->SetGuidance(" and energy ranges for the chosen model");
108 //
109 G4UIparameter* ionizationModelPrm =
110 new G4UIparameter("ionizationModel", 's', false);
111 ionizationModelPrm->SetGuidance(
112 "ionization model (1. PAIPhot, 2. PAI or 3. Heed)");
113 ionizationModelPrm->SetGuidance(
114 " 1. PAIPhot model in Geant4, delta electrons transported by Heed");
115 ionizationModelPrm->SetGuidance(
116 " 2. PAI model in Geant4, delta electrons transported by Heed");
117 ionizationModelPrm->SetGuidance(" 3. Use directly Heed");
118 fIonizationModelCmd->SetParameter(ionizationModelPrm);
119 //
120 G4UIparameter* useDefaultsPrm = new G4UIparameter("useDefaults", 'b', false);
121 useDefaultsPrm->SetGuidance(
122 "true to use default, false to manually choose particles and energies");
123 fIonizationModelCmd->SetParameter(useDefaultsPrm);
124 //
125 fIonizationModelCmd->AvailableForStates(G4State_PreInit);
126
127 fGeant4ParticleCmd = new G4UIcommand(
128 "/exampleGarfield/physics/setGeant4ParticleTypeAndEnergy", this);
129 fGeant4ParticleCmd->SetGuidance(
130 "Select particle types and energies for PAI and PAIPhot model");
131 fGeant4ParticleCmd->SetGuidance(" in Geant4");
132 //
133 G4UIparameter* particleGeant4Prm =
134 new G4UIparameter("particleName", 's', false);
135 particleGeant4Prm->SetGuidance(
136 "Particle name (e-, e+, mu-, mu+, proton, pi-, pi+, alpha, He3, "
137 "GenericIon)");
138 fGeant4ParticleCmd->SetParameter(particleGeant4Prm);
139 //
140 G4UIparameter* minEnergyGeant4Prm =
141 new G4UIparameter("minimumEnergyGeant4", 'd', false);
142 minEnergyGeant4Prm->SetGuidance("minimum energy");
143 minEnergyGeant4Prm->SetParameterRange("minimumEnergyGeant4>=0");
144 fGeant4ParticleCmd->SetParameter(minEnergyGeant4Prm);
145 //
146 G4UIparameter* maxEnergyGeant4Prm =
147 new G4UIparameter("maximumEnergyGeant4", 'd', false);
148 maxEnergyGeant4Prm->SetGuidance("maximum energy");
149 maxEnergyGeant4Prm->SetParameterRange("maximumEnergyGeant4>=0");
150 fGeant4ParticleCmd->SetParameter(maxEnergyGeant4Prm);
151 //
152 G4UIparameter* unitGeant4Prm = new G4UIparameter("unit", 's', false);
153 unitGeant4Prm->SetGuidance("unit of energy");
154 G4String unitListGeant4 =
155 G4UIcommand::UnitsList(G4UIcommand::CategoryOf("MeV"));
156 unitGeant4Prm->SetParameterCandidates(unitListGeant4);
157 fGeant4ParticleCmd->SetParameter(unitGeant4Prm);
158 //
159 fGeant4ParticleCmd->AvailableForStates(G4State_PreInit);
160
161 fGarfieldParticleCmd = new G4UIcommand(
162 "/exampleGarfield/physics/setGarfieldParticleTypeAndEnergy", this);
163 fGarfieldParticleCmd->SetGuidance(
164 "Select particle types and energies for Heed model.");
165 fGarfieldParticleCmd->SetGuidance(
166 " For PAI and PAIPhot model choose at which energy electrons are");
167 fGarfieldParticleCmd->SetGuidance(
168 " transported as delta electrons by Heed, and treatment of gammas");
169 //
170 G4UIparameter* particleGarfieldPrm =
171 new G4UIparameter("particleName", 's', false);
172 particleGarfieldPrm->SetGuidance(
173 "Particle name (gamma, e-, e+, mu-, mu+, proton, anti_proton, pi-, pi+, "
174 "kaon, kaon+, alpha, deuteron)");
175 fGarfieldParticleCmd->SetParameter(particleGarfieldPrm);
176 //
177 G4UIparameter* minEnergyGarfieldPrm =
178 new G4UIparameter("minimumEnergyGarfield", 'd', false);
179 minEnergyGarfieldPrm->SetGuidance("minimum energy");
180 minEnergyGarfieldPrm->SetParameterRange("minimumEnergyGarfield>=0");
181 fGarfieldParticleCmd->SetParameter(minEnergyGarfieldPrm);
182 //
183 G4UIparameter* maxEnergyGarfieldPrm =
184 new G4UIparameter("maximumEnergyGarfield", 'd', false);
185 maxEnergyGarfieldPrm->SetGuidance("maximum energy");
186 maxEnergyGarfieldPrm->SetParameterRange("maximumEnergyGarfield>=0");
187 fGarfieldParticleCmd->SetParameter(maxEnergyGarfieldPrm);
188 //
189 G4UIparameter* unitGarfieldPrm = new G4UIparameter("unit", 's', false);
190 unitGarfieldPrm->SetGuidance("unit of energy");
191 G4String unitListGarfield =
192 G4UIcommand::UnitsList(G4UIcommand::CategoryOf("MeV"));
193 unitGarfieldPrm->SetParameterCandidates(unitListGarfield);
194 fGarfieldParticleCmd->SetParameter(unitGarfieldPrm);
195 //
196 fGarfieldParticleCmd->AvailableForStates(G4State_PreInit);
197}
198
199//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
200
202 delete fMaterialCmd;
203 delete fIsotopeCmd;
204 delete fAbsorberDir;
205 delete fExampleDir;
206 delete fGarfieldPhysicsDir;
207 delete fIonizationModelCmd;
208 delete fGeant4ParticleCmd;
209 delete fGarfieldParticleCmd;
210}
211
212//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
213
214void GarfieldMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
215 if (command == fMaterialCmd) {
216 fDetector->SetAbsorberMaterial(newValue);
217 } else if (command == fIsotopeCmd) {
218 G4int Z;
219 G4int A;
220 G4double dens;
221 G4String name, unt;
222 std::istringstream is(newValue);
223 is >> name >> Z >> A >> dens >> unt;
224 dens *= G4UIcommand::ValueOf(unt);
225 fDetector->AbsorberMaterialWithSingleIsotope(name, name, dens, Z, A);
226 fDetector->SetAbsorberMaterial(name);
227 } else if (command == fIonizationModelCmd) {
229 G4String modelName;
230 G4bool useDefaults;
231 std::istringstream is(newValue);
232 is >> modelName >> std::boolalpha >> useDefaults;
233 garfieldPhysics->SetIonizationModel(modelName, useDefaults);
234 } else if (command == fGeant4ParticleCmd) {
236 G4String particleName, unit, programName;
237 G4double minEnergy;
238 G4double maxEnergy;
239 std::istringstream is(newValue);
240 is >> particleName >> minEnergy >> maxEnergy >> unit;
241 minEnergy *= G4UIcommand::ValueOf(unit);
242 maxEnergy *= G4UIcommand::ValueOf(unit);
243 garfieldPhysics->AddParticleName(particleName, minEnergy, maxEnergy,
244 "geant4");
245 } else if (command == fGarfieldParticleCmd) {
247 G4String particleName, unit, programName;
248 G4double minEnergy;
249 G4double maxEnergy;
250 std::istringstream is(newValue);
251 is >> particleName >> minEnergy >> maxEnergy >> unit;
252 minEnergy *= G4UIcommand::ValueOf(unit);
253 maxEnergy *= G4UIcommand::ValueOf(unit);
254 garfieldPhysics->AddParticleName(particleName, minEnergy, maxEnergy,
255 "garfield");
256 }
257}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the GarfieldDetectorConstruction class.
Definition of the GarfieldMessenger class.
Definition of the GarfieldPhysics class.
void SetAbsorberMaterial(G4String materialChoice)
G4Material * AbsorberMaterialWithSingleIsotope(G4String name, G4String symbol, G4double density, G4int Z, G4int A)
GarfieldMessenger(GarfieldDetectorConstruction *)
virtual void SetNewValue(G4UIcommand *, G4String)
static GarfieldPhysics * GetInstance()
void SetIonizationModel(std::string model, bool useDefaults=true)
void AddParticleName(const std::string particleName, double ekin_min_MeV, double ekin_max_MeV, std::string program)