GEMC  2.3
Geant4 Monte-Carlo Framework
momControls.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "momControls.h"
3 #include "string_utilities.h"
4 
5 // G4 headers
6 #include "G4ParticleTable.hh"
7 
8 
9 // CLHEP units
10 #include "CLHEP/Units/PhysicalConstants.h"
11 using namespace CLHEP;
12 
14 {
15  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
16 
17  // vector of string - filled from the various option
18  vector<string> values;
19 
20  // Getting momentum from option value
21  if(type == "Primary") values = get_info(Opts->optMap["BEAM_P"].args);
22  if(type == "Lumi1") values = get_info(Opts->optMap["LUMI_P"].args);
23  if(type == "Lumi2") values = get_info(Opts->optMap["LUMI2_P"].args);
24  string pname = TrimSpaces(values[0]);
25 
26  // check that particle is in particle table
27  if(!particleTable->FindParticle(pname))
28  cout << " !! GUI Control: Particle " << pname << " not found in G4 table." << endl << endl;
29 
30  // filling drop down menu with all particles availabe
31  beam_particle = new QComboBox;
32  // most important particles on top
33  beam_particle->addItem(pname.c_str());
34  beam_particle->addItem("e-");
35  beam_particle->addItem("proton");
36  beam_particle->addItem("pi+");
37  beam_particle->addItem("pi-");
38  beam_particle->addItem("kaon+");
39  beam_particle->addItem("kaon-");
40  for(int i=0; i<particleTable->entries(); i++)
41  beam_particle->addItem(particleTable->GetParticleName(i).c_str());
42 
43  // Particle Type Layout
44  QHBoxLayout *beam_particleLayout = new QHBoxLayout;
45  beam_particleLayout->addSpacing(40);
46  beam_particleLayout->addWidget(new QLabel(tr("Particle Type:")));
47  beam_particleLayout->addWidget(beam_particle);
48  beam_particleLayout->addStretch(1);
49 
50 
51 
52  // momentum
53  momLE = new QLineEdit(tr("10"));
54  momLE->setMaximumWidth(100);
55 
56  rmomLE = new QLineEdit(tr("0"));
57  rmomLE->setMaximumWidth(100);
58 
59  // momentum units
60  momUnits = new QComboBox;
61  momUnits->addItem(tr("GeV"));
62  momUnits->addItem(tr("MeV"));
63  momUnits->addItem(tr("eV"));
64  momUnits->addItem(tr("KeV"));
65  momUnits->addItem(tr("TeV"));
66 
67  QHBoxLayout *momLayout = new QHBoxLayout;
68  momLayout->addWidget(new QLabel(tr("p: ")));
69  momLayout->addWidget(momLE);
70  momLayout->addWidget(new QLabel(tr(" ± ")));
71  momLayout->addWidget(rmomLE);
72  momLayout->addWidget(momUnits);
73  momLayout->addStretch(1);
74 
75 
76  // theta
77  theLE = new QLineEdit(tr("0"));
78  theLE->setMaximumWidth(100);
79 
80  rtheLE = new QLineEdit(tr("0"));
81  rtheLE->setMaximumWidth(100);
82 
83  // theta units
84  theUnits = new QComboBox;
85  theUnits->addItem(tr("deg"));
86  theUnits->addItem(tr("rad"));
87 
88  QHBoxLayout *theLayout = new QHBoxLayout;
89  theLayout->addWidget(new QLabel(tr("θ: ")));
90  theLayout->addWidget(theLE);
91  theLayout->addWidget(new QLabel(tr(" ± ")));
92  theLayout->addWidget(rtheLE);
93  theLayout->addWidget(theUnits);
94  theLayout->addStretch(1);
95 
96 
97 
98  // phi
99  phiLE = new QLineEdit(tr("0"));
100  phiLE->setMaximumWidth(100);
101 
102  rphiLE = new QLineEdit(tr("0"));
103  rphiLE->setMaximumWidth(100);
104 
105  // phi units
106  phiUnits = new QComboBox;
107  phiUnits->addItem(tr("deg"));
108  phiUnits->addItem(tr("rad"));
109 
110  QHBoxLayout *phiLayout = new QHBoxLayout;
111  phiLayout->addWidget(new QLabel(tr("φ: ")));
112  phiLayout->addWidget(phiLE);
113  phiLayout->addWidget(new QLabel(tr(" ± ")));
114  phiLayout->addWidget(rphiLE);
115  phiLayout->addWidget(phiUnits);
116  phiLayout->addStretch(1);
117 
118 
119  // kinematic layout
120  QVBoxLayout *mLayout = new QVBoxLayout;
121  mLayout->addLayout(beam_particleLayout);
122  mLayout->addSpacing(10);
123  mLayout->addLayout(momLayout);
124  mLayout->addLayout(theLayout);
125  mLayout->addLayout(phiLayout);
126 
127  momentumGroup = new QGroupBox(tr("Momentum:"));
128  momentumGroup->setLayout(mLayout);
129 
130 
131 // if(type == "Primary")
132 // momentumGroup->setStyleSheet(" * { background-color: rgb(220, 230, 240);} QLabel {background-color: transparent; }");
133 //
134 // if(type == "Lumi1")
135 // momentumGroup->setStyleSheet(" * { background-color: rgb(220, 245, 235);} QLabel {background-color: transparent; }");
136 //
137 // if(type == "Lumi2")
138 // momentumGroup->setStyleSheet(" * { background-color: rgb(195, 240, 195);} QLabel {background-color: transparent; }");
139 
140 }
141 
142 
143 
144 
145 
147 {
148  string particle = qs_tostring(beam_particle->currentText());
149  string mom = qs_tostring(momLE->text());
150  string momU = qs_tostring(momUnits->currentText());
151  string the = qs_tostring(theLE->text());
152  string theU = qs_tostring(theUnits->currentText());
153  string phi = qs_tostring(phiLE->text());
154  string phiU = qs_tostring(phiUnits->currentText());
155 
156  string beam_p = particle + ", " +
157  mom + "*" + momU + ", " +
158  the + "*" + theU + ", " +
159  phi + "*" + phiU;
160 
161  if(verbosity)
162  cout << " - GUI BEAM_P: " << beam_p << endl;
163 
164  return beam_p;
165 }
166 
167 
168 void momControls::set_momentum(string momOption)
169 {
170  vector<string> values = get_info(momOption);
171 
172  if(values.size() == 4)
173  {
174  string pname = TrimSpaces(values[0]);
175 
176  // default values of units are from the GUI
177  double mom = get_number(values[1])/GeV;
178  double theta = get_number(values[2])/deg;
179  double phi = get_number(values[3])/deg;
180 
181  beam_particle->setCurrentIndex(beam_particle->findText(QString(pname.c_str())));
182  momLE->setText(QString(stringify(mom).c_str()));
183  theLE->setText(QString(stringify(theta).c_str()));
184  phiLE->setText(QString(stringify(phi).c_str()));
185  }
186 }
187 
188 
189 
190 
192 {
193 
194  string rmom = qs_tostring(rmomLE->text());
195  string momU = qs_tostring(momUnits->currentText());
196  string rthe = qs_tostring(rtheLE->text());
197  string theU = qs_tostring(theUnits->currentText());
198  string rphi = qs_tostring(rphiLE->text());
199  string phiU = qs_tostring(phiUnits->currentText());
200 
201  string spread_p = rmom + "*" + momU + ", " +
202  rthe + "*" + theU + ", " +
203  rphi + "*" + phiU;
204 
205  if(verbosity)
206  cout << " - GUI SPREAD_P: " << spread_p << endl;
207  return spread_p;
208 }
209 
210 void momControls::set_rmomentum(string momOption)
211 {
212  vector<string> values = get_info(momOption);
213 
214  if(values.size() == 3)
215  {
216  // default values of units are from the GUI
217  double dmom = get_number(values[0])/GeV;
218  double dtheta = get_number(values[1])/deg;
219  double dphi = get_number(values[2])/deg;
220 
221  rmomLE->setText(QString(stringify(dmom).c_str()));
222  rtheLE->setText(QString(stringify(dtheta).c_str()));
223  rphiLE->setText(QString(stringify(dphi).c_str()));
224  }
225 }
226 
227 
228 
229 
230 
231 
232 
233 
234 
double verbosity
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
string get_momentum(double verbosity)
Definition: momControls.cc:146
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
string stringify(double x)
map< string, aopt > optMap
Options map.
Definition: options.h:75
string qs_tostring(QString input)
string get_rmomentum(double verbosity)
Definition: momControls.cc:191
string TrimSpaces(string in)
Removes leading and trailing spaces.
void set_rmomentum(string momOption)
Definition: momControls.cc:210
void set_momentum(string momOption)
Definition: momControls.cc:168
momControls(goptions *Opts, string type)
Definition: momControls.cc:13