ATLAS Offline Software
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 
20 #include "VP1Base/VP1Serialise.h"
21 #include "VP1Base/VP1Deserialise.h"
22 
23 #include "ui_vp1etaphicutform.h"
24 
25 #include <cmath>
26 
27 //____________________________________________________________________
29 
30 public:
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 
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 //____________________________________________________________________
71 {
72  delete m_d;
73 }
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 //____________________________________________________________________
106 QList<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 //____________________________________________________________________
229 void 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 //____________________________________________________________________
249 void 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);
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 //____________________________________________________________________
301 void 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 }
VP1Serialise.h
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
VP1EtaPhiCutWidget::setEtaCutEnabled
void setEtaCutEnabled(bool)
Definition: VP1EtaPhiCutWidget.cxx:220
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
VP1EtaPhiCutWidget::possibleChange_allowedPhi
void possibleChange_allowedPhi()
Definition: VP1EtaPhiCutWidget.cxx:202
max
#define max(a, b)
Definition: cfImp.cxx:41
VP1EtaPhiCutWidget::Imp
Definition: VP1EtaPhiCutWidget.cxx:28
VP1EtaPhiCutWidget::handleEtaCutSymmetry
void handleEtaCutSymmetry()
Definition: VP1EtaPhiCutWidget.cxx:152
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
egammaEnergyPositionAllSamples::e1
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1EtaPhiCutWidget::Imp::adaptSpinBoxRangesForSymmetry
void adaptSpinBoxRangesForSymmetry(bool symmetric)
Definition: VP1EtaPhiCutWidget.cxx:139
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
VP1EtaPhiCutWidget::~VP1EtaPhiCutWidget
virtual ~VP1EtaPhiCutWidget()
Definition: VP1EtaPhiCutWidget.cxx:70
VP1EtaPhiCutWidget::togglePhiCheckboxes
void togglePhiCheckboxes()
Definition: VP1EtaPhiCutWidget.cxx:190
VP1EtaPhiCutWidget::allowedEta
VP1Interval allowedEta() const
Definition: VP1EtaPhiCutWidget.cxx:76
VP1EtaPhiCutWidget::m_d
Imp * m_d
Definition: VP1EtaPhiCutWidget.h:54
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
VP1EtaPhiCutWidget.h
VP1Deserialise::version
qint32 version() const
Definition: VP1Deserialise.cxx:143
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
IVP1System
Definition: IVP1System.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1EtaPhiCutWidget::possibleChange_allowedEta
void possibleChange_allowedEta()
Definition: VP1EtaPhiCutWidget.cxx:177
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1EtaPhiCutWidget::Imp::last_allowedPhi
QList< VP1Interval > last_allowedPhi
Definition: VP1EtaPhiCutWidget.cxx:34
VP1EtaPhiCutWidget::Imp::ui
Ui::VP1EtaPhiCutForm ui
Definition: VP1EtaPhiCutWidget.cxx:32
VP1Deserialise::restore
void restore(QCheckBox *sb)
Definition: VP1Deserialise.cxx:245
VP1EtaPhiCutWidget::VP1EtaPhiCutWidget
VP1EtaPhiCutWidget(QWidget *parent=0, IVP1System *sys=0)
Definition: VP1EtaPhiCutWidget.cxx:41
VP1EtaPhiCutWidget::showEtaCut
void showEtaCut(bool b)
Definition: VP1EtaPhiCutWidget.cxx:236
VP1Deserialise
Definition: VP1Deserialise.h:44
VP1EtaPhiCutWidget::allowedPhi
QList< VP1Interval > allowedPhi() const
Definition: VP1EtaPhiCutWidget.cxx:106
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
VP1EtaPhiCutWidget::allowedEtaChanged
void allowedEtaChanged(const VP1Interval &)
min
#define min(a, b)
Definition: cfImp.cxx:40
VP1HelperClassBase::systemBase
IVP1System * systemBase() const
Definition: VP1HelperClassBase.h:50
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1Deserialise::widgetHandled
void widgetHandled(QWidget *)
Definition: VP1Deserialise.cxx:658
VP1EtaPhiCutWidget::restoreFromState
void restoreFromState(const QByteArray &)
Definition: VP1EtaPhiCutWidget.cxx:301
VP1Interval::toString
QString toString() const
VP1Deserialise::warnUnrestored
void warnUnrestored(QObject *)
Definition: VP1Deserialise.cxx:696
VP1EtaPhiCutWidget::setEtaCut
void setEtaCut(const double &)
Definition: VP1EtaPhiCutWidget.cxx:229
VP1EtaPhiCutWidget::saveState
QByteArray saveState() const
Definition: VP1EtaPhiCutWidget.cxx:283
VP1Interval
Definition: VP1Interval.h:23
a
TList * a
Definition: liststreamerinfos.cxx:10
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
VP1Deserialise::ignoreObsoletePhiSectionWidgetState
void ignoreObsoletePhiSectionWidgetState()
Definition: VP1Deserialise.cxx:638
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
VP1Deserialise::ignoreWidget
void ignoreWidget(QWidget *)
Definition: VP1Deserialise.cxx:648
VP1EtaPhiCutWidget::allowedPhiChanged
void allowedPhiChanged(const QList< VP1Interval > &)
VP1EtaPhiCutWidget::showPhiCut
void showPhiCut(bool b)
Definition: VP1EtaPhiCutWidget.cxx:242
VP1EtaPhiCutWidget::Imp::last_allowedEta
VP1Interval last_allowedEta
Definition: VP1EtaPhiCutWidget.cxx:33