ATLAS Offline Software
Loading...
Searching...
No Matches
VP1EtaPhiCutWidget.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class VP1EtaPhiCutWidget //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: July 2008 //
12//
13// Updates:
14// - 2022 Nov, Riccardo Maria BIANCHI - added numerical phi cuts
15// - 2023 Mar, Riccardo Maria BIANCHI - set dynamic widget size
16//
18
22
23#include "ui_vp1etaphicutform.h"
24
25#include <cmath>
26
27//____________________________________________________________________
29
30public:
31
32 Ui::VP1EtaPhiCutForm ui;
34 QList<VP1Interval> last_allowedPhi;
35
36 void adaptSpinBoxRangesForSymmetry(bool symmetric);
37};
38
39
40//____________________________________________________________________
42 : QWidget(parent), VP1HelperClassBase(sys,"VP1EtaPhiCutWidget"), m_d(new Imp)
43{
44 m_d->ui.setupUi(this);
45
46 m_d->last_allowedEta = allowedEta();
47 m_d->last_allowedPhi = allowedPhi();
48
49 // -> allowedEta (a bit special due to the "force symmetric" ability)
50 connect(m_d->ui.checkBox_cut_etarange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_allowedEta()));
51 connect(m_d->ui.checkBox_cut_etarange_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(handleEtaCutSymmetry()));
52 connect(m_d->ui.doubleSpinBox_cut_etalower,SIGNAL(valueChanged(double)),this,SLOT(handleEtaCutSymmetry()));
53 connect(m_d->ui.doubleSpinBox_cut_etaupper,SIGNAL(valueChanged(double)),this,SLOT(handleEtaCutSymmetry()));
54
55 // -> allowedPhi
56 connect(m_d->ui.checkBox_cut_phi,SIGNAL(toggled(bool)),this,SLOT(possibleChange_allowedPhi()));
57 connect(m_d->ui.phisectionwidget,SIGNAL(enabledPhiRangesChanged(const QList<VP1Interval>&)),
58 this,SLOT(possibleChange_allowedPhi()));
59
60 connect(m_d->ui.checkBox_cut_phi,SIGNAL(toggled(bool)),this,SLOT(togglePhiCheckboxes()));
61 connect(m_d->ui.checkBox_phiCuts,SIGNAL(toggled(bool)),this,SLOT(togglePhiCheckboxes()));
62
63 connect(m_d->ui.checkBox_phiCuts,SIGNAL(toggled(bool)),this,SLOT(possibleChange_allowedPhi()));
64 connect(m_d->ui.dsb_phiCuts_min,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_allowedPhi()));
65 connect(m_d->ui.dsb_phiCuts_max,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_allowedPhi()));
66
67}
68
69//____________________________________________________________________
74
75//____________________________________________________________________
77{
78 if(VP1Msg::verbose()){
79 messageVerbose("VP1EtaPhiCutWidget::allowedEta()");
80 }
81
82 // if "eta cut" is not set: we return an interval ]-inf,inf[, so all objects will pass the internal eta cut
83 if (!m_d->ui.checkBox_cut_etarange->isChecked()) {
84 return VP1Interval(-std::numeric_limits<double>::infinity(),std::numeric_limits<double>::infinity());
85 }
86
87 const double min = m_d->ui.doubleSpinBox_cut_etalower->value();
88 const double max = m_d->ui.doubleSpinBox_cut_etaupper->value();
89
90 // if max < min: we return what??
91 if (max<min)
92 return VP1Interval();
93
94 // FIXME: checkBox_etacut_excludeRange is not actually used now, check and fix!
95 // if "Exclude Eta range" is selected, we set the "excludeInterval" flag in the instance of the VP1Interval class
96 if (m_d->ui.checkBox_etacut_excludeRange) {
97 if(VP1Msg::verbose()){
98 messageVerbose("excludeRange=true");
99 }
100 return VP1Interval(min, max, true, true, true);
101 }
102 return VP1Interval( min, max );//fixme: closed interval?? Ckeck!
103}
104
105//____________________________________________________________________
106QList<VP1Interval> VP1EtaPhiCutWidget::allowedPhi() const
107{
108 QList<VP1Interval> l;
109
110 if (!m_d->ui.checkBox_cut_phi && !m_d->ui.checkBox_phiCuts)
111 return l;
112
113
114 if ( !m_d->ui.checkBox_cut_phi->isChecked() && !m_d->ui.checkBox_phiCuts->isChecked() ) {
115 l << VP1Interval(-std::numeric_limits<double>::infinity(),std::numeric_limits<double>::infinity());
116 return l;
117 }
118
119 if ( m_d->ui.checkBox_cut_phi->isChecked() && ( !m_d->ui.phisectionwidget || m_d->ui.phisectionwidget->allSectorsOff() ) )
120 return l;
121
122 if ( m_d->ui.checkBox_cut_phi->isChecked() && m_d->ui.phisectionwidget->allSectorsOn() ) {
123 l << VP1Interval(-std::numeric_limits<double>::infinity(),std::numeric_limits<double>::infinity());
124 return l;
125 } else if ( m_d->ui.checkBox_cut_phi->isChecked() ) {
126 return m_d->ui.phisectionwidget->enabledPhiRanges();
127 }
128 if ( m_d->ui.checkBox_phiCuts->isChecked() ) {
129 double phi_min = m_d->ui.dsb_phiCuts_min->value();
130 double phi_max = m_d->ui.dsb_phiCuts_max->value();
131 return m_d->ui.phisectionwidget->enabledPhiRanges(phi_min, phi_max);
132 }
133
134 return l; // we should not get here
135
136}
137
138//____________________________________________________________________
140{
141 if (symmetric) {
142 ui.doubleSpinBox_cut_etalower->setMaximum(0.0);
143 ui.doubleSpinBox_cut_etaupper->setMinimum(0.0);
144 } else {
145 const double rangemax = ui.doubleSpinBox_cut_etaupper->maximum();
146 ui.doubleSpinBox_cut_etalower->setMaximum(rangemax);
147 ui.doubleSpinBox_cut_etaupper->setMinimum(-rangemax);
148 }
149}
150
151//____________________________________________________________________
153{
154 if (!m_d->ui.checkBox_cut_etarange_forcesymmetric)
155 return;
156 if (sender()==m_d->ui.checkBox_cut_etarange_forcesymmetric) {
157 //update allowed ranges, change values if necessary.
158 m_d->adaptSpinBoxRangesForSymmetry(m_d->ui.checkBox_cut_etarange_forcesymmetric->isChecked());
159 if (m_d->ui.checkBox_cut_etarange_forcesymmetric->isChecked()) {
160 //Enforce symmetry:
161 const double eta = std::max(fabs(m_d->ui.doubleSpinBox_cut_etalower->value()),fabs(m_d->ui.doubleSpinBox_cut_etaupper->value()));
162 m_d->ui.doubleSpinBox_cut_etalower->setValue(-eta);
163 m_d->ui.doubleSpinBox_cut_etaupper->setValue(eta);
164 }
165 } else if (m_d->ui.checkBox_cut_etarange_forcesymmetric->isChecked()) {
166 //Update other value:
167 if (sender()==m_d->ui.doubleSpinBox_cut_etalower) {
168 m_d->ui.doubleSpinBox_cut_etaupper->setValue(-m_d->ui.doubleSpinBox_cut_etalower->value());
169 } else if (sender()==m_d->ui.doubleSpinBox_cut_etaupper) {
170 m_d->ui.doubleSpinBox_cut_etalower->setValue(-m_d->ui.doubleSpinBox_cut_etaupper->value());
171 }
172 }
174}
175
176//____________________________________________________________________
178{
179 VP1Interval newAllowedEta = allowedEta();
180 if ( m_d->last_allowedEta == newAllowedEta )
181 return;
182 m_d->last_allowedEta = newAllowedEta;
183 if(VP1Msg::verbose()){
184 messageVerbose("Emitting allowedEtaChanged("+newAllowedEta.toString()+")");
185 }
186 emit allowedEtaChanged(newAllowedEta);
187}
188
189
191
192 // If 'range' is checked, then 'cuts' must be unchecked; and viceversa
193 // We only use one option at a time: or we use the dots/ranges, or the numerical values
194 if (sender()==m_d->ui.checkBox_phiCuts) {
195 if ( m_d->ui.checkBox_phiCuts->isChecked() ) m_d->ui.checkBox_cut_phi->setChecked(false);
196 } else if (sender()==m_d->ui.checkBox_cut_phi) {
197 if ( m_d->ui.checkBox_cut_phi->isChecked() ) m_d->ui.checkBox_phiCuts->setChecked(false);
198 }
199}
200
201//____________________________________________________________________
203{
204
205
206 QList<VP1Interval> newAllowedPhi = allowedPhi();
207 if ( m_d->last_allowedPhi == newAllowedPhi )
208 return;
209 m_d->last_allowedPhi = newAllowedPhi;
210 if(VP1Msg::verbose()){
211 QString s;
212 for(int i=0;i<newAllowedPhi.count();++i)
213 s+= newAllowedPhi.at(i).toString()+(i==newAllowedPhi.count()-1?"":", ");
214 messageVerbose("Emitting allowedPhiChanged("+s+")");
215 }
216 emit allowedPhiChanged(newAllowedPhi);
217}
218
219//____________________________________________________________________
221{
222 if (b==m_d->ui.checkBox_cut_etarange->isChecked())
223 return;
224 m_d->ui.checkBox_cut_etarange->setChecked(b);
226}
227
228//____________________________________________________________________
229void VP1EtaPhiCutWidget::setEtaCut(const double& e)
230{
231 setEtaCut(-fabs(e),fabs(e));
232}
233
234
235//____________________________________________________________________
237{
238 m_d->ui.checkBox_cut_etarange->setChecked(b);
239 m_d->ui.widget_etacut->setVisible(b);
240}
241//____________________________________________________________________
243{
244 m_d->ui.checkBox_cut_phi->setChecked(b);
245 m_d->ui.widget_phicut->setVisible(b);
246}
247
248//____________________________________________________________________
249void VP1EtaPhiCutWidget::setEtaCut(const double& a,const double&b)
250{
251 double e1(a),e2(b);
252 const double rangemax = m_d->ui.doubleSpinBox_cut_etaupper->maximum();
253 e1 = std::max(-rangemax,e1);
254 e1 = std::min(rangemax,e1);
255 e2 = std::max(-rangemax,e2);
256 e2 = std::min(rangemax,e2);
257 if (e1>=e2||e1!=e1||e2!=e2) {
258 e1 = 0;
259 e2 = 0;
260 }
261
262 bool save = blockSignals(true);
263 bool save1 = m_d->ui.doubleSpinBox_cut_etalower->blockSignals(true);
264 bool save2 = m_d->ui.doubleSpinBox_cut_etaupper->blockSignals(true);
265 bool save3 = m_d->ui.checkBox_cut_etarange->blockSignals(true);
266 bool save4 = m_d->ui.checkBox_cut_etarange_forcesymmetric->blockSignals(true);
267
268 m_d->ui.checkBox_cut_etarange->setChecked(true);
269 m_d->ui.checkBox_cut_etarange_forcesymmetric->setChecked(e1==-e2);
270 m_d->adaptSpinBoxRangesForSymmetry(e1==-e2);
271 m_d->ui.doubleSpinBox_cut_etalower->setValue(e1);
272 m_d->ui.doubleSpinBox_cut_etaupper->setValue(e2);
273
274 blockSignals(save);
275 m_d->ui.doubleSpinBox_cut_etalower->blockSignals(save1);
276 m_d->ui.doubleSpinBox_cut_etaupper->blockSignals(save2);
277 m_d->ui.checkBox_cut_etarange->blockSignals(save3);
278 m_d->ui.checkBox_cut_etarange_forcesymmetric->blockSignals(save4);
280}
281
282//____________________________________________________________________
284{
285 //NB: We can't use the VP1Serialise::save(VP1EtaPhiCutWidget*) here
286 //(that would give infinite recursion).
287
288 VP1Serialise serialise(1/*version*/,systemBase());
289 serialise.save(m_d->ui.checkBox_cut_etarange);
290 serialise.save(m_d->ui.checkBox_cut_etarange_forcesymmetric);
291 serialise.save(m_d->ui.doubleSpinBox_cut_etalower);
292 serialise.save(m_d->ui.doubleSpinBox_cut_etaupper);
293 serialise.save(m_d->ui.checkBox_cut_phi);
294 serialise.save(m_d->ui.phisectionwidget);//Version 0 saved the old-style phisection widget states.
295 serialise.widgetHandled(this);
296 serialise.warnUnsaved(this);
297 return serialise.result();
298}
299
300//____________________________________________________________________
301void VP1EtaPhiCutWidget::restoreFromState( const QByteArray& ba)
302{
303 //NB: We can't use the VP1Deserialise::restore(VP1EtaPhiCutWidget*) here
304 //(that would give infinite recursion).
305
306 VP1Deserialise state(ba,systemBase());
307 if (state.version()<0||state.version()>1)
308 return;//Ignore silently
309
310 state.restore(m_d->ui.checkBox_cut_etarange);
311 state.restore(m_d->ui.checkBox_cut_etarange_forcesymmetric);
312 state.restore(m_d->ui.doubleSpinBox_cut_etalower);
313 state.restore(m_d->ui.doubleSpinBox_cut_etaupper);
314 state.restore(m_d->ui.checkBox_cut_phi);
315 if (state.version()==0) {
317 state.ignoreWidget(m_d->ui.phisectionwidget);
318 } else {
319 state.restore(m_d->ui.phisectionwidget);
320 }
321 state.widgetHandled(this);
322 state.warnUnrestored(this);
323
326}
Scalar eta() const
pseudorapidity method
static Double_t a
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
void ignoreWidget(QWidget *)
void ignoreObsoletePhiSectionWidgetState()
void restore(QCheckBox *sb)
void warnUnrestored(QObject *)
void widgetHandled(QWidget *)
qint32 version() const
void adaptSpinBoxRangesForSymmetry(bool symmetric)
QList< VP1Interval > last_allowedPhi
VP1EtaPhiCutWidget(QWidget *parent=0, IVP1System *sys=0)
QByteArray saveState() const
QList< VP1Interval > allowedPhi() const
void restoreFromState(const QByteArray &)
VP1Interval allowedEta() const
void setEtaCut(const double &)
void allowedEtaChanged(const VP1Interval &)
void allowedPhiChanged(const QList< VP1Interval > &)
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
IVP1System * systemBase() const
QString toString() const
static bool verbose()
Definition VP1Msg.h:31