GEMC  1.8
Geant4 Monte-Carlo Framework
run_control.cc
Go to the documentation of this file.
1 // %%%%%%%%%%
2 // G4 headers
3 // %%%%%%%%%%
4 #include "G4ParticleTable.hh"
5 
6 // %%%%%%%%%%
7 // Qt headers
8 // %%%%%%%%%%
9 #include <QtGui>
10 
11 // %%%%%%%%%%%%%
12 // gemc headers
13 // %%%%%%%%%%%%%
14 #include "detector.h"
15 #include "run_control.h"
16 #include "string_utilities.h"
17 
18 // %%%%%%%%%%%
19 // C++ headers
20 // %%%%%%%%%%%
21 #include <ctime>
22 
24 {
25  gemcOpt = Opts;
26  UImanager = G4UImanager::GetUIpointer();
27 
28  QTabWidget* BeamType = new QTabWidget;
29  pbeamtab = new PrimaryBeamTab(this, gemcOpt);
30  lbeamtab = new LuminosityBeamTab(this, gemcOpt);
31  lbeamtab2 = new LuminosityBeamTab(this, gemcOpt, 2);
32 
33  BeamType->addTab(pbeamtab, tr("Primary Particle"));
34  BeamType->addTab(lbeamtab, tr("Primary Beam"));
35  BeamType->addTab(lbeamtab2, tr("Secondary Beam"));
36 
37  QPushButton *BeamOn = new QPushButton(tr("Beam On"));
38  connect ( BeamOn , SIGNAL( pressed() ), this, SLOT( beamOn() ) );
39 
40  QPushButton *BeamE2S = new QPushButton(tr("Beam Every 2 seconds"));
41  connect ( BeamE2S , SIGNAL( pressed() ), this, SLOT( beam_every2sec() ) );
42 
43 
44 
45  QGroupBox *neventsGroup = new QGroupBox(tr("Number of Events"));
46 
47  QLabel *set_nevents = new QLabel(tr("Set N:"));
48 
49  n_units = new QComboBox;
50  n_units->addItem(tr("1")); n_units->addItem(tr("5"));
51  n_units->addItem(tr("10")); n_units->addItem(tr("15"));
52  n_units->addItem(tr("20")); n_units->addItem(tr("25"));
53  n_units->addItem(tr("30")); n_units->addItem(tr("35"));
54  n_units->addItem(tr("40")); n_units->addItem(tr("45"));
55  n_units->addItem(tr("50")); n_units->addItem(tr("55"));
56  n_units->addItem(tr("60")); n_units->addItem(tr("65"));
57  n_units->addItem(tr("70")); n_units->addItem(tr("75"));
58  n_units->addItem(tr("80")); n_units->addItem(tr("85"));
59  n_units->addItem(tr("90")); n_units->addItem(tr("95"));
60  n_units->setMaximumWidth(55);
61  connect ( n_units , SIGNAL( currentIndexChanged(int) ), this, SLOT( set_beam_values() ) );
62 
63 
64  QLabel *times = new QLabel(tr("X"));
65 
66  n_mult = new QComboBox;
67  n_mult->addItem(tr("1"));
68  n_mult->addItem(tr("10"));
69  n_mult->addItem(tr("100"));
70  n_mult->addItem(tr("1000"));
71  n_mult->addItem(tr("10000"));
72  n_mult->addItem(tr("100000"));
73  n_mult->addItem(tr("1000000"));
74  n_mult->setMaximumWidth(95);
75  connect ( n_mult , SIGNAL( currentIndexChanged(int) ), this, SLOT( set_beam_values() ) );
76 
77  nevents = new QLabel(tr(""));
78 
79 
80 
81  QHBoxLayout *bottomLayout = new QHBoxLayout;
82  bottomLayout->addWidget(set_nevents);
83  bottomLayout->addWidget(n_units);
84  bottomLayout->addWidget(times);
85  bottomLayout->addWidget(n_mult);
86  bottomLayout->addSpacing(30);
87  bottomLayout->addWidget(nevents);
88  bottomLayout->addSpacing(30);
89  bottomLayout->addWidget(BeamE2S);
90  bottomLayout->addStretch(2);
91  neventsGroup->setLayout(bottomLayout);
92 
93  QVBoxLayout *mainLayout = new QVBoxLayout;
94  mainLayout->addWidget(BeamType);
95  mainLayout->addWidget(neventsGroup);
96  mainLayout->addSpacing(10);
97  mainLayout->addWidget(BeamOn);
98  setLayout(mainLayout);
99 
100  set_beam_values();
101  set_vertex_values();
102  gemcOpt->args["N"].arg = 0;
103 
104 }
105 
107 {
108  string hd_msg = gemcOpt->args["LOG_MSG"].args ;
109  double VERB = gemcOpt->args["GEO_VERBOSITY"].arg ;
110  if(VERB>2)
111  cout << hd_msg << " Run Control Widget Deleted." << endl;
112 
113 }
114 
116 {
117  string hd_msg = Opts->args["LOG_MSG"].args + " Beam Settings >> " ;
118  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
119 
120  // vector of string - filled from the various option
121  vector<string> values;
122  string units;
123 
124  // Getting momentum from option value
125  values = get_info(Opts->args["BEAM_P"].args);
126  string pname = TrimSpaces(values[0]);
127  double arg_mom = get_number(values[1]);
128  double arg_theta = get_number(values[2]);
129  double arg_phi = get_number(values[3]);
130 
131  // Getting spread of momentum from option value
132  values = get_info(Opts->args["SPREAD_P"].args);
133  double arg_dmom = get_number(values[0]);
134  double arg_dtheta = get_number(values[1]);
135  double arg_dphi = get_number(values[2]);
136 
137 
138 
139  G4ParticleDefinition *Particle = particleTable->FindParticle(pname);
140  if(!Particle)
141  cout << hd_msg << " Particle " << pname << " not found in G4 table." << endl << endl;
142 
143  // Momentum Group
144  QGroupBox *momentumGroup = new QGroupBox(tr(""));
145 
146  QLabel *beam_particleLabel = new QLabel(tr("Particle Type:"));
147  beam_particle = new QComboBox;
148  // most important particles on top
149  beam_particle->addItem(pname.c_str());
150  beam_particle->addItem(tr("e-"));
151  beam_particle->addItem(tr("proton"));
152  beam_particle->addItem(tr("pi+"));
153  beam_particle->addItem(tr("pi-"));
154  for(int i=0; i<particleTable->entries(); i++)
155  beam_particle->addItem(particleTable->GetParticleName(i).c_str());
156  QHBoxLayout *beam_particleLayout = new QHBoxLayout;
157  beam_particleLayout->addSpacing(40);
158  beam_particleLayout->addWidget(beam_particleLabel);
159  beam_particleLayout->addWidget(beam_particle);
160  beam_particleLayout->addSpacing(80);
161  connect ( beam_particle , SIGNAL( currentIndexChanged(int) ), parent, SLOT( set_beam_values() ) );
162 
163 
164  QLabel *col1Label = new QLabel(tr(""));
165  QLabel *col2Label = new QLabel(tr("Value"));
166  QLabel *col3Label = new QLabel(tr("Dispersion"));
167  QHBoxLayout *explanaLayout = new QHBoxLayout;
168  explanaLayout->addWidget(col1Label);
169  explanaLayout->addWidget(col2Label);
170  explanaLayout->addWidget(col3Label);
171 
172  QLabel *momentumLabel = new QLabel(tr("p:"));
173  momentum_slider = new QSlider(Qt::Horizontal);
174  momentum_slider->setRange(1, 2000);
175  momentum_slider->setSliderPosition((int) (arg_mom/MeV/10.0));
176  rmomentum_slider = new QSlider(Qt::Horizontal);
177  rmomentum_slider->setRange(0, 2000);
178  rmomentum_slider->setSliderPosition((int) (arg_dmom/MeV/10.0));
179  connect ( momentum_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
180  connect ( rmomentum_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
181 
182 
183  QHBoxLayout *momentumLayout = new QHBoxLayout;
184  momentumLayout->addWidget(momentumLabel);
185  momentumLayout->addSpacing(27);
186  momentumLayout->addWidget(momentum_slider);
187  momentumLayout->addWidget(rmomentum_slider);
188 
189  QLabel *thetaLabel = new QLabel(tr("theta:"));
190  theta_slider = new QSlider(Qt::Horizontal);
191  theta_slider->setRange(0, 3600);
192  theta_slider->setSliderPosition( (int) (20.0*arg_theta/deg));
193  rtheta_slider = new QSlider(Qt::Horizontal);
194  rtheta_slider->setRange(0, 3600);
195  rtheta_slider->setSliderPosition((int) (20.0*arg_dtheta/deg));
196  connect ( theta_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
197  connect ( rtheta_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
198 
199 
200  QHBoxLayout *thetaLayout = new QHBoxLayout;
201  thetaLayout->addWidget(thetaLabel);
202  thetaLayout->addWidget(theta_slider);
203  thetaLayout->addWidget(rtheta_slider);
204 
205 
206  QLabel *phiLabel = new QLabel(tr("phi:"));
207  phi_slider = new QSlider(Qt::Horizontal);
208  phi_slider->setRange(0, 7200);
209  phi_slider->setSliderPosition((int) (20*arg_phi/deg));
210  rphi_slider = new QSlider(Qt::Horizontal);
211  rphi_slider->setRange(0, 3600);
212  rphi_slider->setSliderPosition((int) (20*arg_dphi/deg));
213  connect ( phi_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
214  connect ( rphi_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
215 
216  QHBoxLayout *phiLayout = new QHBoxLayout;
217  phiLayout->addWidget(phiLabel);
218  phiLayout->addSpacing(14);
219  phiLayout->addWidget(phi_slider);
220  phiLayout->addWidget(rphi_slider);
221 
222  QVBoxLayout *mLayout = new QVBoxLayout;
223  mLayout->addLayout(beam_particleLayout);
224  mLayout->addSpacing(10);
225  mLayout->addLayout(explanaLayout);
226  mLayout->addLayout(momentumLayout);
227  mLayout->addLayout(thetaLayout);
228  mLayout->addLayout(phiLayout);
229  momentumGroup->setLayout(mLayout);
230 
231 
232  // Momentum Readout Group
233  QGroupBox *mroGroup = new QGroupBox(tr("Beam Values"));
234 
235  QLabel *rmomentumLabel = new QLabel(tr("p:"));
236  momentum_ro = new QLabel(tr(""));
237  QHBoxLayout *momentum_roLayout = new QHBoxLayout;
238  momentum_roLayout->addWidget(rmomentumLabel);
239  momentum_roLayout->addWidget(momentum_ro);
240 
241  QLabel *rthetaLabel = new QLabel(tr("theta:"));
242  theta_ro = new QLabel(tr(""));
243  QHBoxLayout *theta_roLayout = new QHBoxLayout;
244  theta_roLayout->addWidget(rthetaLabel);
245  theta_roLayout->addWidget(theta_ro);
246 
247  QLabel *rphiLabel = new QLabel(tr("phi:"));
248  phi_ro = new QLabel(tr(""));
249  QHBoxLayout *phi_roLayout = new QHBoxLayout;
250  phi_roLayout->addWidget(rphiLabel);
251  phi_roLayout->addWidget(phi_ro);
252 
253  QVBoxLayout *mroLayout = new QVBoxLayout;
254  mroLayout->addLayout(momentum_roLayout);
255  mroLayout->addLayout(theta_roLayout);
256  mroLayout->addLayout(phi_roLayout);
257  mroGroup->setLayout(mroLayout);
258 
259  // Vertex read out Group
260  QGroupBox *vroGroup = new QGroupBox(tr("Vertex Values"));
261 
262  QLabel *rvxyzLabel = new QLabel(tr("(x,y,z):"));
263  vxyz_ro = new QLabel(tr("(0, 0, 0) mm"));
264  QHBoxLayout *vxy_roLayout = new QHBoxLayout;
265  vxy_roLayout->addWidget(rvxyzLabel);
266  vxy_roLayout->addWidget(vxyz_ro);
267 
268  QLabel *rvdrLabel = new QLabel(tr("radius:"));
269  vdr_ro = new QLabel(tr("0 mm"));
270  QHBoxLayout *vdr_roLayout = new QHBoxLayout;
271  vdr_roLayout->addWidget(rvdrLabel);
272  vdr_roLayout->addWidget(vdr_ro);
273 
274  QLabel *rvdzLabel = new QLabel(tr("delta z:"));
275  vdz_ro = new QLabel(tr("0 mm"));
276  QHBoxLayout *vdz_roLayout = new QHBoxLayout;
277  vdz_roLayout->addWidget(rvdzLabel);
278  vdz_roLayout->addWidget(vdz_ro);
279 
280  QVBoxLayout *vroLayout = new QVBoxLayout;
281  vroLayout->addLayout(vxy_roLayout);
282  vroLayout->addLayout(vdr_roLayout);
283  vroLayout->addLayout(vdz_roLayout);
284  vroGroup->setLayout(vroLayout);
285 
286 
287  QHBoxLayout *beamroLayout = new QHBoxLayout;
288  beamroLayout->addWidget(mroGroup);
289  beamroLayout->addWidget(vroGroup);
290 
291 
292 
293  // Getting vertex from option value
294  values = get_info(Opts->args["BEAM_V"].args);
295  units = TrimSpaces(values[3]);
296  double cvx = get_number(values[0] + "*" + units);
297  double cvy = get_number(values[1] + "*" + units);
298  double cvz = get_number(values[2] + "*" + units);
299 
300  // Getting vertex spread from option value
301  values = get_info(Opts->args["SPREAD_V"].args);
302  units = TrimSpaces(values[2]);
303  double cdvr = get_number(values[0] + "*" + units);
304  double cdvz = get_number(values[1] + "*" + units);
305 
306 
307 
308 
309  // Vertex Group
310  QGroupBox *vertexGroup = new QGroupBox(tr("Vertex"));
311 
312  QLabel *col1Label2 = new QLabel(tr(""));
313  QLabel *col2Label2 = new QLabel(tr("Value"));
314  QLabel *col3Label2 = new QLabel(tr("Dispersion"));
315  QHBoxLayout *explanaLayout2 = new QHBoxLayout;
316  explanaLayout2->addWidget(col1Label2);
317  explanaLayout2->addWidget(col2Label2);
318  explanaLayout2->addWidget(col3Label2);
319 
320  QLabel *vxLabel = new QLabel(tr("vx:"));
321  vx_slider = new QSlider(Qt::Horizontal);
322  vx_slider->setRange(-200, 200);
323  vx_slider->setSliderPosition((int) (cvx/mm));
324  QLabel *vrLabel = new QLabel(tr("radius:"));
325  rv_slider = new QSlider(Qt::Horizontal);
326  rv_slider->setRange(0, 100);
327  rv_slider->setSliderPosition((int) (cdvr/mm));
328  QHBoxLayout *vxLayout = new QHBoxLayout;
329  vxLayout->addWidget(vxLabel);
330  vxLayout->addWidget(vx_slider);
331  vxLayout->addSpacing(30);
332  vxLayout->addWidget(vrLabel);
333  vxLayout->addWidget(rv_slider);
334  connect ( vx_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
335  connect ( rv_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
336 
337 
338  QLabel *vyLabel = new QLabel(tr("vy:"));
339  vy_slider = new QSlider(Qt::Horizontal);
340  vy_slider->setRange(-200, 200);
341  vy_slider->setSliderPosition((int) (cvy/mm));
342  QLabel *rvzLabel = new QLabel(tr("dvz:"));
343  rvz_slider = new QSlider(Qt::Horizontal);
344  rvz_slider->setRange(0, 400);
345  rvz_slider->setSliderPosition((int) (cdvz/mm));
346  QHBoxLayout *vyLayout = new QHBoxLayout;
347  vyLayout->addWidget(vyLabel);
348  vyLayout->addWidget(vy_slider);
349  vyLayout->addSpacing(46);
350  vyLayout->addWidget(rvzLabel);
351  vyLayout->addWidget(rvz_slider);
352  connect ( vy_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
353  connect ( rvz_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
354 
355  QLabel *vzLabel = new QLabel(tr("vz:"));
356  vz_slider = new QSlider(Qt::Horizontal);
357  vz_slider->setRange(-10000, 10000);
358  vz_slider->setTickInterval(1);
359  vz_slider->setSliderPosition((int) (cvz/mm));
360  QHBoxLayout *vzLayout = new QHBoxLayout;
361  vzLayout->addWidget(vzLabel);
362  vzLayout->addWidget(vz_slider);
363  vzLayout->addSpacing(236);
364  QVBoxLayout *vLayout = new QVBoxLayout;
365  vLayout->addLayout(explanaLayout2);
366  vLayout->addLayout(vxLayout);
367  vLayout->addLayout(vyLayout);
368  vLayout->addLayout(vzLayout);
369  vertexGroup->setLayout(vLayout);
370  connect ( vz_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
371 
372 
373  momentumGroup->setStyleSheet(" * { background-color: rgb(215, 220, 215);} QLabel {background-color: transparent; }");
374  mroGroup->setStyleSheet(" * { background-color: rgb(215, 220, 215);} QLabel {background-color: transparent; }");
375  vroGroup->setStyleSheet(" * { background-color: rgb(215, 215, 220);} QLabel {background-color: transparent; }");
376  vertexGroup->setStyleSheet(" * { background-color: rgb(215, 215, 220);} QLabel {background-color: transparent; }");
377 
378  // All together
379  QVBoxLayout *mainLayout = new QVBoxLayout;
380  mainLayout->addWidget(momentumGroup);
381  mainLayout->addLayout(beamroLayout);
382  mainLayout->addSpacing(10);
383  mainLayout->addWidget(vertexGroup);
384  setLayout(mainLayout);
385 
386 
387 
388 }
389 
391 {
392  string hd_msg = Opts->args["LOG_MSG"].args + " Beam Settings >> " ;
393  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
394 
395 
396  vector<string> values;
397 
398  // Getting Luminosity Event infos from command line
399  values = get_info(Opts->args["LUMI_EVENT"].args);
400  int lnevents = (int) get_number(values[0]);
401  int twindow = (int) get_number(values[1]);
402  int tbunch = (int) get_number(values[2]);
403 
404  if(type == 2)
405  {
406  values = get_info(Opts->args["LUMI2_EVENT"].args);
407  lnevents = (int) get_number(values[0]);
408  tbunch = (int) get_number(values[1]);
409  }
410  QGroupBox *LumiGroup = new QGroupBox(tr(""));
411 
412  QLabel *neventLabel = new QLabel(tr("N. Particles/Event"));
413  QLabel *timewindowLabel = NULL;
414  if(type==1) timewindowLabel = new QLabel(tr("Time Window\n"));
415  if(type==2) timewindowLabel = new QLabel(tr("Time Window\n Set on\n Primary Tab"));
416  QLabel *bunchLabel = new QLabel(tr("Bunch Time"));
417  QHBoxLayout *lumiHLayout = new QHBoxLayout;
418  lumiHLayout->addSpacing(45);
419  lumiHLayout->addWidget(neventLabel);
420  lumiHLayout->addWidget(timewindowLabel);
421  lumiHLayout->addSpacing(20);
422  lumiHLayout->addWidget(bunchLabel);
423 
424  nevents = new QLineEdit();
425  timewindow = new QLineEdit();
426  time_bunch = new QLineEdit();
427  nevents->setMaximumWidth(100);
428  timewindow->setMaximumWidth(100);
429  time_bunch->setMaximumWidth(100);
430  QHBoxLayout *lumiHLayout2 = new QHBoxLayout;
431  lumiHLayout2->addWidget(nevents);
432  if(type==1) lumiHLayout2->addWidget(timewindow);
433  if(type==2) lumiHLayout2->addSpacing(135);
434  lumiHLayout2->addWidget(time_bunch);
435 
436  QString L_ne = stringify(lnevents).c_str();
437  nevents->setText(L_ne);
438 
439  QString L_tw = stringify(twindow/ns).c_str() + QString("*ns");
440  timewindow->setText(L_tw);
441 
442  QString L_tb = stringify(tbunch/ns).c_str() + QString("*ns");
443  time_bunch->setText(L_tb);
444 
445  connect ( nevents , SIGNAL( textChanged(const QString & ) ), parent, SLOT( set_beam_values() ) );
446  connect ( timewindow , SIGNAL( textChanged(const QString & ) ), parent, SLOT( set_beam_values() ) );
447  connect ( time_bunch , SIGNAL( textChanged(const QString & ) ), parent, SLOT( set_beam_values() ) );
448 
449 
450  QVBoxLayout *LLayout = new QVBoxLayout;
451  LLayout->addLayout(lumiHLayout);
452  LLayout->addLayout(lumiHLayout2);
453  LumiGroup->setLayout(LLayout);
454 
455 
456  // Getting momentum, particle infos from command line
457  values = get_info(Opts->args["LUMI_P"].args);
458  if(type == 2)
459  values = get_info(Opts->args["LUMI2_P"].args);
460 
461  string pname = TrimSpaces(values[0]);
462  double arg_mom = get_number(values[1]);
463  double arg_theta = get_number(values[2]);
464  double arg_phi = get_number(values[3]);
465 
466  G4ParticleDefinition *Particle = particleTable->FindParticle(pname);
467  if(!Particle)
468  cout << hd_msg << " Particle " << pname << " not found in G4 table." << endl << endl;
469 
470  // Momentum Group
471  QGroupBox *momentumGroup = new QGroupBox(tr(""));
472 
473  QLabel *beam_particleLabel = new QLabel(tr("Particle Type:"));
474  beam_particle = new QComboBox;
475  // first add most important particles, then all the rest
476  beam_particle->addItem(pname.c_str());
477  for(int i=0; i<particleTable->entries(); i++)
478  beam_particle->addItem(particleTable->GetParticleName(i).c_str());
479  QHBoxLayout *beam_particleLayout = new QHBoxLayout;
480  beam_particleLayout->addSpacing(40);
481  beam_particleLayout->addWidget(beam_particleLabel);
482  beam_particleLayout->addWidget(beam_particle);
483  beam_particleLayout->addSpacing(80);
484  connect ( beam_particle , SIGNAL( currentIndexChanged(int) ), parent, SLOT( set_beam_values() ) );
485 
486 
487 
488  QLabel *momentumLabel = new QLabel(tr("p:"));
489  momentum_slider = new QSlider(Qt::Horizontal);
490  momentum_slider->setRange(1, 11000);
491  if(type == 2)
492  momentum_slider->setRange(1, 11000);
493  momentum_slider->setSliderPosition((int) (arg_mom/MeV/10.0));
494  connect ( momentum_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
495 
496 
497  QHBoxLayout *momentumLayout = new QHBoxLayout;
498  momentumLayout->addWidget(momentumLabel);
499  momentumLayout->addSpacing(27);
500  momentumLayout->addWidget(momentum_slider);
501 
502  QLabel *thetaLabel = new QLabel(tr("theta:"));
503  theta_slider = new QSlider(Qt::Horizontal);
504  theta_slider->setRange(0, 3600);
505  theta_slider->setSliderPosition((int) (20.0*arg_theta/deg));
506  connect ( theta_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
507 
508 
509  QHBoxLayout *thetaLayout = new QHBoxLayout;
510  thetaLayout->addWidget(thetaLabel);
511  thetaLayout->addWidget(theta_slider);
512 
513  QLabel *phiLabel = new QLabel(tr("phi:"));
514  phi_slider = new QSlider(Qt::Horizontal);
515  phi_slider->setRange(0, 7200);
516  phi_slider->setSliderPosition((int) (20.0*arg_phi/deg));
517  connect ( phi_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_beam_values() ) );
518 
519  QHBoxLayout *phiLayout = new QHBoxLayout;
520  phiLayout->addWidget(phiLabel);
521  phiLayout->addSpacing(14);
522  phiLayout->addWidget(phi_slider);
523 
524  QVBoxLayout *mLayout = new QVBoxLayout;
525  mLayout->addLayout(beam_particleLayout);
526  mLayout->addSpacing(10);
527  mLayout->addLayout(momentumLayout);
528  mLayout->addLayout(thetaLayout);
529  mLayout->addLayout(phiLayout);
530  momentumGroup->setLayout(mLayout);
531 
532 
533  // Momentum Readout Group
534  QGroupBox *mroGroup = new QGroupBox(tr("Beam Values"));
535 
536  QLabel *rmomentumLabel = new QLabel(tr("p:"));
537  momentum_ro = new QLabel(tr(""));
538  QHBoxLayout *momentum_roLayout = new QHBoxLayout;
539  momentum_roLayout->addWidget(rmomentumLabel);
540  momentum_roLayout->addWidget(momentum_ro);
541 
542  QLabel *rthetaLabel = new QLabel(tr("theta:"));
543  theta_ro = new QLabel(tr(""));
544  QHBoxLayout *theta_roLayout = new QHBoxLayout;
545  theta_roLayout->addWidget(rthetaLabel);
546  theta_roLayout->addWidget(theta_ro);
547 
548  QLabel *rphiLabel = new QLabel(tr("phi:"));
549  phi_ro = new QLabel(tr(""));
550  QHBoxLayout *phi_roLayout = new QHBoxLayout;
551  phi_roLayout->addWidget(rphiLabel);
552  phi_roLayout->addWidget(phi_ro);
553 
554  QVBoxLayout *mroLayout = new QVBoxLayout;
555  mroLayout->addLayout(momentum_roLayout);
556  mroLayout->addLayout(theta_roLayout);
557  mroLayout->addLayout(phi_roLayout);
558  mroGroup->setLayout(mroLayout);
559 
560  // Vertex read out Group
561  QGroupBox *vroGroup = new QGroupBox(tr("Vertex Values"));
562 
563  QLabel *rvxyzLabel = new QLabel(tr("(x,y,z):"));
564  vxyz_ro = new QLabel(tr("(0, 0, 0) mm"));
565  QHBoxLayout *vxy_roLayout = new QHBoxLayout;
566  vxy_roLayout->addWidget(rvxyzLabel);
567  vxy_roLayout->addWidget(vxyz_ro);
568 
569 
570  QVBoxLayout *vroLayout = new QVBoxLayout;
571  vroLayout->addLayout(vxy_roLayout);
572  vroGroup->setLayout(vroLayout);
573 
574 
575  QHBoxLayout *beamroLayout = new QHBoxLayout;
576  beamroLayout->addWidget(mroGroup);
577  beamroLayout->addWidget(vroGroup);
578 
579 
580 
581 
582  // Getting vertex infos from command line
583  values = get_info(Opts->args["LUMI_V"].args);
584  if(type == 2)
585  values = get_info(Opts->args["LUMI2_V"].args);
586 
587  string units = TrimSpaces(values[3]);
588  double cvx = get_number(values[0] + "*" + units);
589  double cvy = get_number(values[1] + "*" + units);
590  double cvz = get_number(values[2] + "*" + units);
591 
592 
593  // Vertex Group
594  QGroupBox *vertexGroup = new QGroupBox(tr("Vertex"));
595 
596  QLabel *vxLabel = new QLabel(tr("vx:"));
597  vx_slider = new QSlider(Qt::Horizontal);
598  vx_slider->setRange(-200, 200);
599  vx_slider->setSliderPosition((int) (cvx/mm));
600  QHBoxLayout *vxLayout = new QHBoxLayout;
601  vxLayout->addWidget(vxLabel);
602  vxLayout->addWidget(vx_slider);
603  connect ( vx_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
604 
605 
606  QLabel *vyLabel = new QLabel(tr("vy:"));
607  vy_slider = new QSlider(Qt::Horizontal);
608  vy_slider->setRange(-200, 200);
609  vy_slider->setSliderPosition((int) (cvy/mm));
610  QHBoxLayout *vyLayout = new QHBoxLayout;
611  vyLayout->addWidget(vyLabel);
612  vyLayout->addWidget(vy_slider);
613  connect ( vy_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
614 
615  QLabel *vzLabel = new QLabel(tr("vz:"));
616  vz_slider = new QSlider(Qt::Horizontal);
617  vz_slider->setRange(-51000, 51000);
618  vz_slider->setSliderPosition((int) (cvz/mm));
619  QHBoxLayout *vzLayout = new QHBoxLayout;
620  vzLayout->addWidget(vzLabel);
621  vzLayout->addWidget(vz_slider);
622  QVBoxLayout *vLayout = new QVBoxLayout;
623  vLayout->addLayout(vxLayout);
624  vLayout->addLayout(vyLayout);
625  vLayout->addLayout(vzLayout);
626  vertexGroup->setLayout(vLayout);
627  connect ( vz_slider , SIGNAL( valueChanged(int) ), parent, SLOT( set_vertex_values() ) );
628 
629 
630  momentumGroup->setStyleSheet(" * { background-color: rgb(225, 210, 210);} QLabel {background-color: transparent; }");
631  mroGroup->setStyleSheet(" * { background-color: rgb(225, 210, 210);} QLabel {background-color: transparent; }");
632  vroGroup->setStyleSheet(" * { background-color: rgb(210, 220, 210);} QLabel {background-color: transparent; }");
633  vertexGroup->setStyleSheet(" * { background-color: rgb(210, 220, 210);} QLabel {background-color: transparent; }");
634 
635  // All together
636  QVBoxLayout *mainLayout = new QVBoxLayout;
637  mainLayout->addWidget(LumiGroup);
638  mainLayout->addWidget(momentumGroup);
639  mainLayout->addLayout(beamroLayout);
640  mainLayout->addSpacing(10);
641  mainLayout->addWidget(vertexGroup);
642  setLayout(mainLayout);
643 }
644 
645 
646 void run_control::beamOn()
647 {
648  double N_units = atoi(gemc_tostring(n_units->currentText()).c_str());
649  double N_mult = atoi(gemc_tostring(n_mult->currentText()).c_str());
650  double NEVENTS = N_units*N_mult;
651  gemcOpt->args["N"].arg = NEVENTS;
652 
653  char command[100];
654  sprintf(command, "/run/beamOn %d", (int) NEVENTS);
655  UImanager->ApplyCommand(command);
656 }
657 
658 void run_control::beam_every2sec()
659 {
660  // will execute beam on every 2 seconds for 7200 times (4 hours)
661 
662  for(int s=0; s<7200; s++)
663  {
664  char command[100];
665 
666  sprintf(command, "/vis/viewer/refresh");
667  UImanager->ApplyCommand(command);
668 
669  clock_t endwait = clock () + 2 * CLOCKS_PER_SEC ;
670  while (clock() < endwait) {}
671 
672  sprintf(command, "/run/beamOn 1");
673  UImanager->ApplyCommand(command);
674 
675 
676  }
677 }
678 
679 
680 
681 
682 #include "MPrimaryGeneratorAction.h"
683 
684 void run_control::set_beam_values()
685 {
686  // Primary Beam
687  double mom = pbeamtab->momentum_slider->sliderPosition()*10;
688  double rmom = pbeamtab->rmomentum_slider->sliderPosition()*10;
689 
690  QString mro = stringify(mom).c_str();
691  mro.append(QString::fromUtf8(" ± "));
692  mro.append(stringify(rmom).c_str());
693  mro.append(" MeV");
694  pbeamtab->momentum_ro->setText(mro);
695 
696  double the = pbeamtab->theta_slider->sliderPosition()/20.0;
697  double rthe = pbeamtab->rtheta_slider->sliderPosition()/20.0;
698 
699  QString tro = stringify(the).c_str();
700  tro.append(QString::fromUtf8(" ± "));
701  tro.append(stringify(rthe).c_str());
702  tro.append(" deg");
703  pbeamtab->theta_ro->setText(tro);
704 
705  double phi = pbeamtab->phi_slider->sliderPosition()/20.0;
706  double rphi = pbeamtab->rphi_slider->sliderPosition()/20.0;
707 
708  QString pro = stringify(phi).c_str();
709  pro.append(QString::fromUtf8(" ± "));
710  pro.append(stringify(rphi).c_str());
711  pro.append(" deg");
712  pbeamtab->phi_ro->setText(pro);
713 
714  double N_units = atoi(gemc_tostring(n_units->currentText()).c_str());
715  double N_mult = atoi(gemc_tostring(n_mult->currentText()).c_str());
716  double NEVENTS = N_units*N_mult;
717  QString nev = "Number of Events: " ;
718  nev.append(stringify(NEVENTS).c_str());
719  nevents->setText(nev);
720 
721 
722  // Luminosity Beam
723  double L_mom = lbeamtab->momentum_slider->sliderPosition()*10;
724  QString L_mro = stringify(L_mom).c_str();
725  L_mro.append(" MeV");
726  lbeamtab->momentum_ro->setText(L_mro);
727 
728  double L_theta = lbeamtab->theta_slider->sliderPosition()/20.0;
729  QString L_tro = stringify(L_theta).c_str();
730  L_tro.append(" deg");
731  lbeamtab->theta_ro->setText(L_tro);
732 
733  double L_phi = lbeamtab->phi_slider->sliderPosition()/20.0;
734  QString L_pro = stringify(L_phi).c_str();
735  L_pro.append(" deg");
736  lbeamtab->phi_ro->setText(L_pro);
737 
738 
739  // Luminosity Beam 2
740  double L_mom2 = lbeamtab2->momentum_slider->sliderPosition()*10;
741  QString L_mro2 = stringify(L_mom2).c_str();
742  L_mro2.append(" MeV");
743  lbeamtab2->momentum_ro->setText(L_mro2);
744 
745  double L_theta2 = lbeamtab2->theta_slider->sliderPosition()/20.0;
746  QString L_tro2 = stringify(L_theta2).c_str();
747  L_tro2.append(" deg");
748  lbeamtab2->theta_ro->setText(L_tro2);
749 
750  double L_phi2 = lbeamtab2->phi_slider->sliderPosition()/20.0;
751  QString L_pro2 = stringify(L_phi2).c_str();
752  L_pro2.append(" deg");
753  lbeamtab2->phi_ro->setText(L_pro2);
754 
755  change_beam_pars();
756 }
757 
758 void run_control::set_vertex_values()
759 {
760  // Primary Beam
761  double vx = pbeamtab->vx_slider->sliderPosition();
762  double vy = pbeamtab->vy_slider->sliderPosition();
763  double vz = pbeamtab->vz_slider->sliderPosition();
764 
765  QString vro = "(";
766  vro.append(stringify(vx).c_str());
767  vro.append(", ");
768  vro.append(stringify(vy).c_str());
769  vro.append(", ");
770  vro.append(stringify(vz).c_str());
771  vro.append(") mm");
772  pbeamtab->vxyz_ro->setText(vro);
773 
774 
775  double dvr = pbeamtab->rv_slider->sliderPosition();
776  QString dvro = stringify(dvr).c_str();
777  dvro.append(" mm");
778  pbeamtab->vdr_ro->setText(dvro);
779 
780  double dvz = pbeamtab->rvz_slider->sliderPosition();
781  QString dvzro = stringify(dvz).c_str();
782  dvzro.append(" mm");
783  pbeamtab->vdz_ro->setText(dvzro);
784 
785  // Luminosity Beam
786  double L_vx = lbeamtab->vx_slider->sliderPosition();
787  double L_vy = lbeamtab->vy_slider->sliderPosition();
788  double L_vz = lbeamtab->vz_slider->sliderPosition();
789 
790  QString L_vro = "(";
791  L_vro.append(stringify(L_vx).c_str());
792  L_vro.append(", ");
793  L_vro.append(stringify(L_vy).c_str());
794  L_vro.append(", ");
795  L_vro.append(stringify(L_vz).c_str());
796  L_vro.append(") mm");
797  lbeamtab->vxyz_ro->setText(L_vro);
798 
799  // Luminosity Beam 2
800  double L_vx2 = lbeamtab2->vx_slider->sliderPosition();
801  double L_vy2 = lbeamtab2->vy_slider->sliderPosition();
802  double L_vz2 = lbeamtab2->vz_slider->sliderPosition();
803 
804  QString L_vro2 = "(";
805  L_vro2.append(stringify(L_vx2).c_str());
806  L_vro2.append(", ");
807  L_vro2.append(stringify(L_vy2).c_str());
808  L_vro2.append(", ");
809  L_vro2.append(stringify(L_vz2).c_str());
810  L_vro2.append(") mm");
811  lbeamtab2->vxyz_ro->setText(L_vro2);
812 
813  change_beam_pars();
814 }
815 
816 
817 void run_control::change_beam_pars()
818 {
819  string hd_msg = gemcOpt->args["LOG_MSG"].args + " Beam Settings >> " ;
820 
821  // Primary Beam momentum
822  string particle = gemc_tostring(pbeamtab->beam_particle->currentText());
823  double mom = pbeamtab->momentum_slider->sliderPosition()*10*MeV;
824  double theta = pbeamtab->theta_slider->sliderPosition()/20.0*deg;
825  double phi = pbeamtab->phi_slider->sliderPosition()/20.0*deg;
826 
827  string beam_p = particle + ", " +
828  stringify(mom) + "*MeV" + ", " +
829  stringify(theta/deg) + "*deg" + ", " +
830  stringify(phi/deg) + "*deg";
831 
832  gemcOpt->args["BEAM_P"].args = beam_p;
833 
834  // Primary Beam momentum dispersion
835  double dmom = pbeamtab->rmomentum_slider->sliderPosition()*10*MeV;
836  double dtheta = pbeamtab->rtheta_slider->sliderPosition()/20.0*deg;
837  double dphi = pbeamtab->rphi_slider->sliderPosition()/20.0*deg;
838 
839  string spread_p = stringify(dmom/MeV) + "*MeV" + ", " +
840  stringify(dtheta/deg) + "*deg" + ", " +
841  stringify(dphi/deg) + "*deg";
842 
843  gemcOpt->args["SPREAD_P"].args = spread_p;
844 
845  // Luminosity Event
846  string L_ne = gemc_tostring(lbeamtab->nevents->text());
847  string L_tw = gemc_tostring(lbeamtab->timewindow->text());
848  string L_tb = gemc_tostring(lbeamtab->time_bunch->text());
849 
850  string L_event = L_ne + ", " + L_tw + ", " + L_tb;
851  gemcOpt->args["LUMI_EVENT"].args = L_event;
852 
853  // Luminosity Event 2
854  string L_ne2 = gemc_tostring(lbeamtab2->nevents->text());
855  string L_tb2 = gemc_tostring(lbeamtab2->time_bunch->text());
856 
857  string L_event2 = L_ne2 + ", " + L_tb2;
858  gemcOpt->args["LUMI2_EVENT"].args = L_event2;
859 
860 
861  // Luminosity Beam momentum
862  string L_particle = gemc_tostring(lbeamtab->beam_particle->currentText());
863  double L_mom = lbeamtab->momentum_slider->sliderPosition()*10*MeV;
864  double L_theta = lbeamtab->theta_slider->sliderPosition()/20.0*deg;
865  double L_phi = lbeamtab->phi_slider->sliderPosition()/20.0*deg;
866 
867  string L_beam_p = L_particle + ", " +
868  stringify(L_mom) + "*MeV" + "," +
869  stringify(L_theta/deg) + "*deg" + "," +
870  stringify(L_phi/deg) + "*deg";
871 
872  gemcOpt->args["LUMI_P"].args = L_beam_p;
873 
874  // Luminosity Beam momentum 2
875  string L_particle2 = gemc_tostring(lbeamtab2->beam_particle->currentText());
876  double L_mom2 = lbeamtab2->momentum_slider->sliderPosition()*10*MeV;
877  double L_theta2 = lbeamtab2->theta_slider->sliderPosition()/20.0*deg;
878  double L_phi2 = lbeamtab2->phi_slider->sliderPosition()/20.0*deg;
879 
880  string L_beam_p2 = L_particle2 + ", " +
881  stringify(L_mom2) + "*MeV" + ", " +
882  stringify(L_theta2/deg) + "*deg" + ", " +
883  stringify(L_phi2/deg) + "*deg";
884 
885  gemcOpt->args["LUMI2_P"].args = L_beam_p2;
886 
887 
888 
889  // Primary vertex
890  double vx = pbeamtab->vx_slider->sliderPosition()*mm;
891  double vy = pbeamtab->vy_slider->sliderPosition()*mm;
892  double vz = pbeamtab->vz_slider->sliderPosition()*mm;
893 
894  string beam_v = "(" +
895  stringify(vx/mm) + "," +
896  stringify(vy/mm) + "," +
897  stringify(vz/mm) + ") mm";
898 
899  gemcOpt->args["BEAM_V"].args = beam_v;
900 
901 
902 
903  // Primary vertex dispersion
904  double vdr = pbeamtab->rv_slider->sliderPosition()*mm;
905  double vdz = pbeamtab->rvz_slider->sliderPosition()*mm;
906  string spread_v = "(" +
907  stringify(vdr/mm) + "," +
908  stringify(vdz/mm) + ") mm";
909 
910  gemcOpt->args["SPREAD_V"].args = spread_v;
911 
912  // Luminosity vertex
913  double L_vx = lbeamtab->vx_slider->sliderPosition()*mm;
914  double L_vy = lbeamtab->vy_slider->sliderPosition()*mm;
915  double L_vz = lbeamtab->vz_slider->sliderPosition()*mm;
916 
917  string L_beam_v = "(" +
918  stringify(L_vx/mm) + ", " +
919  stringify(L_vy/mm) + ", " +
920  stringify(L_vz/mm) + ") mm";
921 
922  gemcOpt->args["LUMI_V"].args = L_beam_v;
923 
924  // Luminosity vertex 2
925  double L_vx2 = lbeamtab2->vx_slider->sliderPosition()*mm;
926  double L_vy2 = lbeamtab2->vy_slider->sliderPosition()*mm;
927  double L_vz2 = lbeamtab2->vz_slider->sliderPosition()*mm;
928 
929  string L_beam_v2 = "(" +
930  stringify(L_vx2/mm) + ", " +
931  stringify(L_vy2/mm) + ", " +
932  stringify(L_vz2/mm) + " ) mm";
933 
934  gemcOpt->args["LUMI2_V"].args = L_beam_v2;
935 }
936 
937 
938 
939 
940 
941 
942 
943 
944 
945 
946 
947 
948 
QLabel * theta_ro
Definition: run_control.h:89
QLineEdit * time_bunch
Definition: run_control.h:77
QSlider * theta_slider
Definition: run_control.h:81
vector< string > get_info(string input)
get information from strings such as "5*GeV, 2*deg, 10*deg"
QLabel * phi_ro
Definition: run_control.h:59
QSlider * vx_slider
Definition: run_control.h:51
QSlider * phi_slider
Definition: run_control.h:82
run_control(QWidget *parent, gemc_opts *)
Definition: run_control.cc:23
string gemc_tostring(QString input)
QSlider * vx_slider
Definition: run_control.h:84
QSlider * phi_slider
Definition: run_control.h:48
QSlider * rvz_slider
Definition: run_control.h:55
QLineEdit * timewindow
Definition: run_control.h:76
QLabel * vxyz_ro
Definition: run_control.h:92
QLabel * vdr_ro
Definition: run_control.h:62
QLabel * theta_ro
Definition: run_control.h:58
QSlider * vz_slider
Definition: run_control.h:86
QLabel * momentum_ro
Definition: run_control.h:57
string stringify(double x)
QComboBox * beam_particle
Definition: run_control.h:43
QSlider * rphi_slider
Definition: run_control.h:49
QSlider * rmomentum_slider
Definition: run_control.h:45
QLabel * momentum_ro
Definition: run_control.h:88
LuminosityBeamTab(QWidget *parent=0, gemc_opts *=0, int type=1)
Definition: run_control.cc:390
QSlider * momentum_slider
Definition: run_control.h:44
map< string, opts > args
Options map.
Definition: usage.h:68
gemc_opts * gemcOpt
Definition: run_control.h:106
QLabel * vdz_ro
Definition: run_control.h:63
QComboBox * beam_particle
Definition: run_control.h:79
string TrimSpaces(string in)
Removes leading and trailing spaces.
QSlider * theta_slider
Definition: run_control.h:46
QSlider * momentum_slider
Definition: run_control.h:80
QSlider * vz_slider
Definition: run_control.h:53
double get_number(string)
Returns dimension from string, i.e. 100*cm.
QLabel * vxyz_ro
Definition: run_control.h:61
QSlider * rv_slider
Definition: run_control.h:54
QSlider * rtheta_slider
Definition: run_control.h:47
PrimaryBeamTab(QWidget *parent=0, gemc_opts *=0)
Definition: run_control.cc:115
G4UImanager * UImanager
Definition: run_control.h:107
QLineEdit * nevents
Definition: run_control.h:75
QSlider * vy_slider
Definition: run_control.h:52
QSlider * vy_slider
Definition: run_control.h:85