source: trunk/source/interfaces/test/G4EvGenMessenger.icc@ 1232

Last change on this file since 1232 was 989, checked in by garnier, 17 years ago

fichiers manquants

File size: 8.5 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//
27// $Id: G4EvGenMessenger.icc,v 1.6 2006/06/29 19:10:30 gunter Exp $
28// GEANT4 tag $Name: $
29//
30
31#include "G4EventManager.hh"
32#include "G4UImessenger.hh"
33#include "G4UIcommand.hh"
34#include "G4UIparameter.hh"
35#include "G4ParticleGun.hh"
36#include "G4ParticleTypes.hh"
37#include "G4ThreeVector.hh"
38#include "globals.hh"
39#include "G4ios.hh"
40#include <strstream>
41
42
43class G4EvGenMessenger: public G4UImessenger
44{
45 public:
46 G4EvGenMessenger(G4ParticleGun * fPtclGun);
47 void SetNewValue(G4UIcommand * command,G4String newValues);
48 G4String GetCurrentValue(G4UIcommand * command);
49 private:
50 G4ParticleGun * fParticleGun;
51 G4ParticleDefinition* geantino;
52 G4ParticleDefinition* MuonPlus;
53 G4ParticleDefinition* Electron;
54};
55
56G4EvGenMessenger::G4EvGenMessenger(G4ParticleGun * fPtclGun)
57:fParticleGun(fPtclGun)
58{
59 G4UIcommand * command;
60 G4UIparameter * param;
61
62 geantino = G4Geantino::Geantino();
63 MuonPlus = G4MuonPlus::MuonPlus();
64 Electron = G4Electron::Electron();
65
66 command = new G4UIcommand("/gun/",this);
67 command->SetGuidance("Particle Gun control commands.");
68 AddUIcommand(command);
69
70 command = new G4UIcommand("/gun/particle",this);
71 command->SetGuidance("Set particle to be generated.");
72 command->SetGuidance("Currently implimented are :");
73 command->SetGuidance(" geantino (default)");
74 command->SetGuidance(" muonPlus");
75 command->SetGuidance(" electron");
76 param = new G4UIparameter("particle name",'c',true);
77 param->SetDefaultValue("geantino");
78 fParticleGun->SetParticleDefinition( geantino );
79 param->SetGuidance("Particle name.");
80 command->SetParameter(param);
81 AddUIcommand(command);
82
83 command = new G4UIcommand("/gun/momentum",this);
84 command->SetGuidance("Set momentum direction.");
85 command->SetGuidance("Direction needs not to be a unit vector.");
86 param = new G4UIparameter("Px",'d',true);
87 param->SetDefaultValue(1.0);
88 param->SetGuidance("X-direction.");
89 command->SetParameter(param);
90 param = new G4UIparameter("Py",'d',true);
91 param->SetDefaultValue(0.0);
92 param->SetGuidance("Y-direction.");
93 command->SetParameter(param);
94 param = new G4UIparameter("Pz",'d',true);
95 param->SetDefaultValue(0.0);
96 param->SetGuidance("Z-direction.");
97 command->SetParameter(param);
98 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
99 AddUIcommand(command);
100
101 command = new G4UIcommand("/gun/energy",this);
102 command->SetGuidance("Set particle energy.");
103 command->SetGuidance("Unit of the energy can be :");
104 command->SetGuidance(" Tev, GeV (default), MeV");
105 param = new G4UIparameter("Energy",'d',true);
106 param->SetDefaultValue(1.0);
107 param->SetGuidance("Energy");
108 command->SetParameter(param);
109 param = new G4UIparameter("Unit",'c',true);
110 param->SetDefaultValue("GeV");
111 param->SetGuidance("Unit : TeV, GeV (default), MeV");
112 command->SetParameter(param);
113 fParticleGun->SetParticleEnergy( 1.0*GeV );
114 AddUIcommand(command);
115
116 command = new G4UIcommand("/gun/position",this);
117 command->SetGuidance("Set starting position of the particle.");
118 command->SetGuidance("Unit of the position can be :");
119 command->SetGuidance(" m, cm (default), mm");
120 param = new G4UIparameter("X",'d',true);
121 param->SetDefaultValue(0.0);
122 param->SetGuidance("X position");
123 command->SetParameter(param);
124 param = new G4UIparameter("Y",'d',true);
125 param->SetDefaultValue(0.0);
126 param->SetGuidance("Y position");
127 command->SetParameter(param);
128 param = new G4UIparameter("Z",'d',true);
129 param->SetDefaultValue(0.0);
130 param->SetGuidance("Z position");
131 command->SetParameter(param);
132 param = new G4UIparameter("Unit",'c',true);
133 param->SetDefaultValue("cm");
134 param->SetGuidance("Unit : m, cm (default), mm");
135 command->SetParameter(param);
136 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
137 AddUIcommand(command);
138
139 command = new G4UIcommand("/gun/time",this);
140 command->SetGuidance("Set initial time of the particle.");
141 command->SetGuidance("Unit of the time can be :");
142 command->SetGuidance(" s, ms, ns (default)");
143 param = new G4UIparameter("t",'d',true);
144 param->SetDefaultValue(0.0);
145 param->SetGuidance("Initial time");
146 command->SetParameter(param);
147 param = new G4UIparameter("Unit",'c',true);
148 param->SetDefaultValue("ns");
149 param->SetGuidance("Unit : s, ms, ns (default)");
150 command->SetParameter(param);
151 fParticleGun->SetParticleTime( 0.0*ns );
152 AddUIcommand(command);
153}
154
155void G4EvGenMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
156{
157 const char* t = newValues;
158 if( command->GetCommandName() == "particle" )
159 {
160 if(newValues == "geantino")
161 { fParticleGun->SetParticleDefinition( geantino ); }
162 else if(newValues == "muonPlus")
163 { fParticleGun->SetParticleDefinition( MuonPlus ); }
164 else if(newValues == "electron")
165 { fParticleGun->SetParticleDefinition( Electron ); }
166 else
167 {
168 G4cout << "Unknown particle <" << newValues
169 << ">. Command ignored." << G4endl;
170 }
171 }
172 if( command->GetCommandName() == "momentum" )
173 {
174 G4double px;
175 G4double py;
176 G4double pz;
177 std::istrstream is((char*)t);
178 is >> px >> py >> pz;
179 G4double pp = std::sqrt( sqr(px) + sqr(py) + sqr(pz) );
180 if( pp == 0.0 )
181 { G4cout << "Zero vector! command ignored." << G4endl; }
182 else
183 {
184 fParticleGun->SetParticleMomentumDirection(
185 G4ThreeVector( px/pp, py/pp, pz/pp ) );
186 }
187 }
188 if( command->GetCommandName() == "energy" )
189 {
190 G4double ee;
191 char ues[10];
192 std::istrstream is((char*)t);
193 is >> ee >> ues;
194 G4String ue(ues);
195 if( ue == "TeV" )
196 { fParticleGun->SetParticleEnergy(ee*TeV); }
197 else if( ue == "GeV" )
198 { fParticleGun->SetParticleEnergy(ee*GeV); }
199 else if( ue == "MeV" )
200 { fParticleGun->SetParticleEnergy(ee*MeV); }
201 else
202 { G4cout << "Unknown unit <" << ue << ">. Command ignored." << G4endl; }
203 }
204 if( command->GetCommandName() == "position" )
205 {
206 G4double xx;
207 G4double xy;
208 G4double xz;
209 char uxs[10];
210 std::istrstream is((char*)t);
211 is >> xx >> xy >> xz >> uxs;
212 G4String ux(uxs);
213 if( ux == "m" )
214 { fParticleGun->SetParticlePosition(G4ThreeVector(xx*m,xy*m,xz*m)); }
215 else if( ux == "cm" )
216 { fParticleGun->SetParticlePosition(G4ThreeVector(xx*cm,xy*cm,xz*cm)); }
217 else if( ux == "mm" )
218 { fParticleGun->SetParticlePosition(G4ThreeVector(xx*mm,xy*mm,xz*mm)); }
219 else
220 { G4cout << "Unknown unit <" << ux << ">. Command ignored." << G4endl; }
221 }
222 if( command->GetCommandName() == "time" )
223 {
224 G4double et;
225 char uts[10];
226 std::istrstream is((char*)t);
227 is >> et >> uts;
228 G4String ut(uts);
229 if( ut == "s" )
230 { fParticleGun->SetParticleTime(et*s); }
231 else if( ut == "ms" )
232 { fParticleGun->SetParticleTime(et*ms); }
233 else if( ut == "ns" )
234 { fParticleGun->SetParticleTime(et*ns); }
235 else
236 { G4cout << "Unknown unit <" << ut << ">. Command ignored." << G4endl; }
237 }
238}
239
240G4String G4EvGenMessenger::GetCurrentValue(G4UIcommand * command)
241{
242 return G4String('\0');
243}
244
Note: See TracBrowser for help on using the repository browser.