-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYSEnergySetter.cpp
275 lines (242 loc) · 8.73 KB
/
YSEnergySetter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// YSEnergySetter.cpp
// Widget for setting the collision energy
//
// Created by Yves Schutz on 09/12/13.
// Copyright (c) 2013 Yves Schutz. All rights reserved.
//
#include <QAction>
#include <QContextMenuEvent>
#include <QDebug>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
#include <QMenuBar>
#include <QRadioButton>
#include <QSlider>
#include "YSCollision.h"
#include "YSEnergySetter.h"
#include "YSNucleus.h"
//______________________________________________________________________________
YSEnergySetter::YSEnergySetter(YSCollision *coll)
{
//ctor default ctor
SetColl(coll);
Draw();
}
//______________________________________________________________________________
YSEnergySetter::YSEnergySetter(QMenuBar *mb, YSCollision *coll)
{
// ctor adopting the common Menubar
SetColl(coll);
Draw();
// adds an entry to the general menu bar
AddToMenu(mb);
}
//______________________________________________________________________________
YSEnergySetter::~YSEnergySetter()
{
delete mActionQuit;
delete mLHC;
delete mRHIC;
delete mSPS;
delete mB1Label;
delete mB2Label;
delete mB1VBox;
delete mB2VBox;
delete mTeVLabel1;
delete mTeVLabel2;
delete mEnergySlider;
delete mSValueBox;
delete mTeVLabel;
delete mBeamsBox;
delete mABBox;
delete mSBox;
}
//______________________________________________________________________________
void YSEnergySetter::contextMenuEvent(QContextMenuEvent *event)
{
QMenu aMenu(this);
aMenu.addAction(mActionQuit);
aMenu.exec(event->globalPos());
}
//______________________________________________________________________________
void YSEnergySetter::AddToMenu(QMenuBar *mb)
{
// add actions to the main menu bar
mMenuBar = mb;
CreateActions();
CreateMenus();
}
//______________________________________________________________________________
void YSEnergySetter::CreateActions()
{
// create the actions for the menu items
mActionQuit = new QAction(tr("&Done"), this);
mActionQuit->setShortcuts(QKeySequence::Quit);
mActionQuit->setStatusTip(tr("Quit this view"));
connect(mActionQuit, SIGNAL(triggered()), this, SLOT(Done()));
}
//______________________________________________________________________________
void YSEnergySetter::CreateMenus()
{
// create the menu (so far only Done implemented)
mMenu = mMenuBar->addMenu(tr("Energy Setter"));
mMenu->addAction(mActionQuit);
}
//______________________________________________________________________________
void YSEnergySetter::CreateABBox()
{
// create the box with radio buttons to select accelerator
mABBox = new QGroupBox(tr("Accelerators"));
QGridLayout *abboxLayout = new QGridLayout();
mLHC = new QRadioButton("LHC", mABBox);
mLHC->setChecked(true);
mEnergyHigh = 7.0; // TeV
mEnergyLow = 0.45; // TeV
mRHIC = new QRadioButton("RHIC", mABBox);
mSPS = new QRadioButton("SPS", mABBox);
abboxLayout->addWidget(mLHC, 0, 0);
abboxLayout->addWidget(mRHIC, 1, 0);
abboxLayout->addWidget(mSPS, 2, 0);
mABBox->setLayout(abboxLayout);
}
//______________________________________________________________________________
void YSEnergySetter::CreateBeamsBox()
{
// box displaying the beams energy
mBeamsBox = new QGroupBox(tr("Beams energy"));
// Beam specie
mB1Label = new QLabel(QString("<body><sup>%1</sup>%2</body>").
arg(mColl->Nucleus(1)->A()).arg(mColl->Nucleus(1)->Symbol()));
mB2Label = new QLabel(QString("<body><sup>%1</sup>%2</body>").
arg(mColl->Nucleus(2)->A()).arg(mColl->Nucleus(2)->Symbol()));
// Energie value
mB1VBox = new QLineEdit(this);
mB1VBox->setAlignment(Qt::AlignRight);
mB1VBox->setText(mSValueBox->text());
mB1VBox->adjustSize();
mB1VBox->setFixedWidth(mB1VBox->width());
mB1VBox->setText(mSValueBox->text());
mB2VBox = new QLineEdit(this);
mB2VBox->setAlignment(Qt::AlignRight);
mB2VBox->setText(mSValueBox->text());
mB2VBox->adjustSize();
mB2VBox->setFixedWidth(mB2VBox->width());
// units
mTeVLabel1 = new QLabel("TeV", this);
mTeVLabel2 = new QLabel("TeV", this);
// position it
QGridLayout *bboxLayout = new QGridLayout();
bboxLayout->addWidget(mB1Label, 0, 0);
bboxLayout->addWidget(mB2Label,1, 0);
bboxLayout->addWidget(mB1VBox, 0, 1);
bboxLayout->addWidget(mB2VBox, 1, 1);
bboxLayout->addWidget(mTeVLabel1, 0, 2);
bboxLayout->addWidget(mTeVLabel2, 1, 2);
mBeamsBox->setLayout(bboxLayout);
}
//______________________________________________________________________________
void YSEnergySetter::CreateSBox()
{
// makes the energy slider in TeV for Z = 1
mSBox = new QGroupBox(tr("Z=1 momentum"));
QGridLayout *sboxLayout = new QGridLayout();
// the slider
mEnergySlider = new QSlider(Qt::Vertical, this);
mEnergySlider->setFocusPolicy(Qt::StrongFocus);
mEnergySlider->setTickPosition(QSlider::TicksBothSides);
mEnergySlider->setTickInterval(10);
mEnergySlider->setSingleStep(1);
mScaleLow = 0;
mScaleHigh = 100;
mEnergySlider->setMinimum(mScaleLow);
mEnergySlider->setMaximum(mScaleHigh);
// the box with the slider value
mSValueBox = new QLineEdit(this);
mSValueBox->setAlignment(Qt::AlignRight);
mSValueBox->adjustSize();
mSValueBox->setFixedWidth(mSValueBox->width());
// the label
mTeVLabel = new QLabel("TeV/c", this);
sboxLayout->addWidget(mEnergySlider, 0, 0, 2, 1);
sboxLayout->addWidget(mSValueBox, 0, 1);
sboxLayout->addWidget(mTeVLabel, 0, 2);
mSBox->setLayout(sboxLayout);
}
//______________________________________________________________________________
void YSEnergySetter::Done()
{
// close window and finish
qreal ene1 = mSliderPos * mColl->Nucleus(1)->Z() / mColl->Nucleus(1)->A();
qreal ene2 = mSliderPos * mColl->Nucleus(2)->Z() / mColl->Nucleus(2)->A();
mColl->SetEnergies(ene1, ene2);
delete this;
}
//______________________________________________________________________________
void YSEnergySetter::Draw()
{
// Draws the window contents
int finalXSize = 400, finalYSize = 400;
mSliderFlag = false;
setWindowTitle(tr("Collision Energy Setter"));
CreateABBox();
CreateSBox();
CreateBeamsBox();
ReadSlider(mEnergySlider->sliderPosition());
QGridLayout *layout = new QGridLayout(this);
layout->addWidget(mABBox, 0, 0);
layout->addWidget(mSBox, 0, 1);
layout->addWidget(mBeamsBox, 1, 0, 1, 2);
setLayout(layout);
resize(finalXSize, finalYSize);
connect(mLHC, SIGNAL(clicked()), this, SLOT(SetSliderScale()));
connect(mRHIC, SIGNAL(clicked()), this, SLOT(SetSliderScale()));
connect(mSPS, SIGNAL(clicked()), this, SLOT(SetSliderScale()));
connect(mEnergySlider, SIGNAL(valueChanged(int)), this, SLOT(ReadSlider(int)));
connect(mSValueBox, SIGNAL(textChanged(const QString)), this, SLOT(SetSliderPos(const QString)));
}
//______________________________________________________________________________
void YSEnergySetter::ReadSlider(int pos)
{
// reads the value of the energy slider
if(mSliderFlag) return;
mSliderPos = pos * (mEnergyHigh - mEnergyLow) / mScaleHigh + mEnergyLow + 0.005;
mSValueBox->setText(QString("%1").arg(mSliderPos, 0, 'f', 2));
qreal ene1 = mSliderPos * mColl->Nucleus(1)->Z() / mColl->Nucleus(1)->A();
qreal ene2 = mSliderPos * mColl->Nucleus(2)->Z() / mColl->Nucleus(2)->A();
mB1VBox->setText(QString("%1").arg(ene1, 0, 'f', 2));
mB2VBox->setText(QString("%1").arg(ene2, 0, 'f', 2));
}
//______________________________________________________________________________
void YSEnergySetter::SetSliderScale()
{
if ( mLHC->isChecked() ) {
mEnergyHigh = 7.0; // *Z TeV
mEnergyLow = 0.45; // *Z TeV
} else if ( mRHIC->isChecked() ) {
mEnergyHigh = 0.26; // *Z TeV
mEnergyLow = 0.096; // *Z TeV
} else if ( mSPS->isChecked() ) {
mEnergyHigh = 0.45; // *Z TeV
mEnergyLow = 0.026; // *Z TeV
}
ReadSlider(mEnergySlider->sliderPosition());
}
//______________________________________________________________________________
void YSEnergySetter::SetSliderPos(const QString txt)
{
// set the position of the cursor on the slider
mSliderFlag = true;
qreal pos = txt.toDouble();
int ipos = (pos - mEnergyLow) * mScaleHigh / (mEnergyHigh - mEnergyLow);
mEnergySlider->setSliderPosition(ipos);
qreal ene1 = pos * mColl->Nucleus(1)->Z() / mColl->Nucleus(1)->A();
qreal ene2 = pos * mColl->Nucleus(2)->Z() / mColl->Nucleus(2)->A();
mB1VBox->setText(QString("%1").arg(ene1, 0, 'f', 2));
mB2VBox->setText(QString("%1").arg(ene2, 0, 'f', 2));
mSliderFlag = false;
}