EDepSimUserPrimaryGeneratorMessenger.cc
Go to the documentation of this file.
3 #include "EDepSimException.hh"
4 
11 
15 
21 
26 
27 
28 #include <G4UIdirectory.hh>
29 #include <G4UIcmdWithoutParameter.hh>
30 #include <G4UIcmdWithADoubleAndUnit.hh>
31 #include <G4UIcmdWith3VectorAndUnit.hh>
32 #include <G4UIcmdWith3Vector.hh>
33 #include <G4UIcmdWithABool.hh>
34 #include <G4UIcmdWithAString.hh>
35 #include <G4UIcmdWithAnInteger.hh>
36 #include <G4UIcommand.hh>
37 
38 #include <EDepSimLog.hh>
39 
42  : fAction(gen) {
43 
44  /////////////////////////////////////////
45  // The directories must be created first.
46  /////////////////////////////////////////
47 
48  fDir = new G4UIdirectory("/generator/");
49  fDir->SetGuidance("Control of the particle generator.");
50 
51  fCountDir = new G4UIdirectory("/generator/count/");
52  fCountDir->SetGuidance("Control number of primary vertices per event.");
53 
54  fKinematicsDir = new G4UIdirectory("/generator/kinematics/");
55  fKinematicsDir->SetGuidance("Control kinematics generators.");
56 
57  fPositionDir = new G4UIdirectory("/generator/position/");
58  fPositionDir->SetGuidance("Control vertex position the generators.");
59 
60  fTimeDir = new G4UIdirectory("/generator/time/");
61  fTimeDir->SetGuidance("Control vertex time the generators.");
62 
63  /////////////////////////////////////////
64  // The factories must be created after the directories.
65  /////////////////////////////////////////
66 
70 
73 
78 
82 
83  /////////////////////////////////////////
84  // The UI commands must be created after the factories.
85  /////////////////////////////////////////
86 
87  fClearCMD = new G4UIcmdWithoutParameter("/generator/clear",this);
88  fClearCMD->SetGuidance("Clear the current list of vertex generators.");
89 
90  fAddCMD = new G4UIcmdWithoutParameter("/generator/add",this);
91  fAddCMD->SetGuidance("Add a generator using the current factories.");
92 
93  fCombineCMD = new G4UIcommand("/generator/combine",this);
94  fCombineCMD->SetGuidance("Combine the previous two vertices into one.");
95  fCombineCMD->SetParameter(new G4UIparameter("src",'i',false));
96  fCombineCMD->SetParameter(new G4UIparameter("dest",'i',false));
97  fCombineCMD->SetParameter(new G4UIparameter("relative",'b',true));
98  fCombineCMD->GetParameter(2)->SetDefaultValue("false");
99 
101  = new G4UIcmdWithAString("/generator/kinematics/set",this);
102  fSetKinematicsCMD->SetGuidance("Set the current kinematics factory.");
103  fSetKinematicsCMD->SetParameterName("Factory",false);
104  fSetKinematicsCMD->SetCandidates(GetKinematicsFactories());
105 
107  = new G4UIcmdWithAString("/generator/count/set",this);
108  fSetCountCMD->SetGuidance("Set the current count factory.");
109  fSetCountCMD->SetParameterName("Factory",false);
110  fSetCountCMD->SetCandidates(GetCountFactories());
111 
113  = new G4UIcmdWithAString("/generator/position/set",this);
114  fSetPositionCMD->SetGuidance("Set the current position factory.");
115  fSetPositionCMD->SetParameterName("Factory",false);
116  fSetPositionCMD->SetCandidates(GetPositionFactories());
117 
119  = new G4UIcmdWithAString("/generator/time/set",this);
120  fSetTimeCMD->SetGuidance("Set the current time factory.");
121  fSetTimeCMD->SetParameterName("Factory",false);
122  fSetTimeCMD->SetCandidates(GetTimeFactories());
123 
125  = new G4UIcmdWithABool("/generator/allowEmptyEvents",this);
126  fAllowEmptyEventsCMD->SetGuidance("If true, then generate events even"
127  " if they don't contain a vertex.");
128 
130  = new G4UIcmdWithABool("/generator/addFakeGeantino",this);
131  fAddFakeGeantinoCMD->SetGuidance("If true, then guarantee a primary vertex"
132  " by adding a geantino.");
133 
135  = new G4UIcmdWithABool("/generator/allowPartialEvents",this);
136  fAllowEmptyEventsCMD->SetGuidance("If true, then generate the final event"
137  " even if it ran out of interactions"
138  " in the input kinematics file.");
139 
140  //////////////////////////////////
141  // Set default values for the factories.
142  SetKinematicsFactory("gps");
143  SetCountFactory("fixed");
144  SetPositionFactory("free");
145  SetTimeFactory("fixed");
146 
147 }
148 
150  delete fDir;
151  delete fCountDir;
152  delete fKinematicsDir;
153  delete fPositionDir;
154  delete fTimeDir;
155  delete fClearCMD;
156  delete fAddCMD;
157  delete fCombineCMD;
158  delete fSetKinematicsCMD;
159  delete fSetCountCMD;
160  delete fSetPositionCMD;
161  delete fSetTimeCMD;
162  delete fAllowEmptyEventsCMD;
163  delete fAddFakeGeantinoCMD;
164  delete fAllowPartialEventsCMD;
165 }
166 
168  G4String newValue) {
169  if (command == fClearCMD) {
171  }
172  else if (command == fAddCMD) {
174  fAction->AddGenerator(generator);
175  }
176  else if (command == fCombineCMD) {
177  int src, dest;
178  std::string relative;
179  std::istringstream is(newValue);
180  is >> src >> dest >> relative;
183  src,dest,G4UIcommand::ConvertToBool(relative.c_str()));
184  fAction->AddGenerator(generator);
185  }
186  else if (command == fSetKinematicsCMD) {
187  SetKinematicsFactory(newValue);
188  }
189  else if (command == fSetCountCMD) {
190  SetCountFactory(newValue);
191  }
192  else if (command == fSetPositionCMD) {
193  SetPositionFactory(newValue);
194  }
195  else if (command == fSetTimeCMD) {
196  SetTimeFactory(newValue);
197  }
198  else if (command == fAllowEmptyEventsCMD) {
200  fAllowEmptyEventsCMD->GetNewBoolValue(newValue));
201  }
202  else if (command == fAddFakeGeantinoCMD) {
204  fAddFakeGeantinoCMD->GetNewBoolValue(newValue));
205  }
206  else if (command == fAllowPartialEventsCMD) {
208  fAllowPartialEventsCMD->GetNewBoolValue(newValue));
209  }
210  else {
211  EDepSimThrow("EDepSim::UserPrimaryGeneratorMessenger:: "
212  "Unimplemented command");
213  }
214 }
215 
223  = new EDepSim::PrimaryGenerator(kine,count,position,time);
224  EDepSimLog("#############################################");
225  EDepSimLog("# Create a new EDepSim_PrimaryGenerator: "
226  << gen->GetName());
227  EDepSimLog("#############################################");
228  return gen;
229 }
230 
232  return fDir->GetCommandPath();
233 }
234 
236  EDepSim::VKinematicsFactory* factory) {
237  fKinematicsFactories[factory->GetName()] = factory;
238 }
239 
241  const G4String& name) {
243  = fKinematicsFactories.find(name);
244  if (p != fKinematicsFactories.end()) {
245  fKinematics = p->second;
246  EDepSimLog(" Kinematics factory set to: " << fKinematics->GetName());
247  }
248  else {
249  EDepSimThrow(" Illegal kinematics factory name.");
250  }
251 }
252 
254  G4String list = "";
256  = fKinematicsFactories.begin();
257  p != fKinematicsFactories.end();
258  ++p) {
259  list = list + p->first + " ";
260  }
261  return list;
262 }
263 
265  EDepSim::VCountFactory* factory) {
266  fCountFactories[factory->GetName()] = factory;
267 }
268 
270  const G4String& name) {
272  = fCountFactories.find(name);
273  if (p != fCountFactories.end()) {
274  fCount = p->second;
275  EDepSimLog(" Count factory set to: " << fCount->GetName());
276  }
277  else {
278  EDepSimThrow(" Illegal count factory name.");
279  }
280 }
281 
283  G4String list = "";
285  = fCountFactories.begin();
286  p != fCountFactories.end();
287  ++p) {
288  list = list + p->first + " ";
289  }
290  return list;
291 }
292 
294  EDepSim::VPositionFactory* factory) {
295  fPositionFactories[factory->GetName()] = factory;
296 }
297 
299  const G4String& name) {
301  = fPositionFactories.find(name);
302  if (p != fPositionFactories.end()) {
303  fPosition = p->second;
304  EDepSimLog(" Position factory set to: " << fPosition->GetName());
305  }
306  else {
307  EDepSimThrow(" Illegal position factory name.");
308  }
309 }
310 
312  G4String list = "";
314  = fPositionFactories.begin();
315  p != fPositionFactories.end();
316  ++p) {
317  list = list + p->first + " ";
318  }
319  return list;
320 }
321 
323  EDepSim::VTimeFactory* factory) {
324  fTimeFactories[factory->GetName()] = factory;
325 }
326 
328  const G4String& name) {
330  = fTimeFactories.find(name);
331  if (p != fTimeFactories.end()) {
332  fTime = p->second;
333  EDepSimLog(" Time factory set to: " << fTime->GetName());
334  }
335  else {
336  EDepSimThrow(" Illegal time factory name.");
337  }
338 }
339 
341  G4String list = "";
343  = fTimeFactories.begin();
344  p != fTimeFactories.end();
345  ++p) {
346  list = list + p->first + " ";
347  }
348  return list;
349 }
static QCString name
Definition: declinfo.cpp:673
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
void SetTimeFactory(const G4String &factory)
Set the current time factory for the messenger.
std::map< G4String, EDepSim::VTimeFactory * > fTimeFactories
The list of available time factories;.
std::string string
Definition: nybbler.cc:12
int command
virtual EDepSim::VCountGenerator * GetGenerator()=0
std::map< G4String, EDepSim::VPositionFactory * > fPositionFactories
The list of available position factories;.
virtual EDepSim::VTimeGenerator * GetGenerator()=0
void SetPositionFactory(const G4String &factory)
Set the current position factory for the messenger.
G4String GetTimeFactories()
Get the list of time factories available to the messenger.
EDepSim::VTimeFactory * fTime
The current time factory.
EDepSim::VCountFactory * fCount
The current count factory.
EDepSim::PrimaryGenerator * CreateGenerator()
Create a new generator using the current generator factories.
void SetKinematicsFactory(const G4String &factory)
Set the current kinematics factory for the messenger.
void AddGenerator(G4VPrimaryGenerator *generator)
intermediate_table::const_iterator const_iterator
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
virtual EDepSim::VPositionGenerator * GetGenerator()=0
G4String GetCountFactories()
Get the list of count factories available to the messenger.
void ClearGenerators()
Clear the current list of generators.
G4String GetPositionFactories()
Get the list of position factories available to the messenger.
void SetNewValue(G4UIcommand *, G4String)
Handle messages from the UI processor.
void AddTimeFactory(EDepSim::VTimeFactory *factory)
Add a new time factory to the messenger.
UserPrimaryGeneratorMessenger(EDepSim::UserPrimaryGeneratorAction *)
p
Definition: test.py:223
G4String GetKinematicsFactories()
Get the list of kinematics factories available to the messenger.
G4String GetPath()
Get the base directory for the messenger commands.
gen
Definition: demo.py:24
void AddCountFactory(EDepSim::VCountFactory *factory)
Add a new count factory to the messenger.
std::map< G4String, EDepSim::VCountFactory * > fCountFactories
The list of available count factories;.
virtual EDepSim::VKinematicsGenerator * GetGenerator()=0
generator
Definition: train.py:468
G4String GetName()
Return the name of this generator.
std::map< G4String, EDepSim::VKinematicsFactory * > fKinematicsFactories
The list of available kinematics factories;.
void SetCountFactory(const G4String &factory)
Set the current count factory for the messenger.
void AddPositionFactory(EDepSim::VPositionFactory *factory)
Add a new position factory to the messenger.
EDepSim::VKinematicsFactory * fKinematics
The current kinematics factory.
void AddKinematicsFactory(EDepSim::VKinematicsFactory *factory)
Add a new kinematics factory to the messenger.
EDepSim::VPositionFactory * fPosition
The current position factory.