ATLAS Offline Software
IParticleCollHandleBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class IParticleCollHandleBase //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: February 2008 //
12 //
13 // Updates:
14 // - 2023, Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch>
15 // //
17 
18 //Local includes
21 #include "IParticleHandleBase.h"
23 #include "AODSysCommonData.h"
24 
25 //VP1 base includes
28 #include "VP1Base/IVP13DSystem.h"
30 #include "VP1Base/VP1Serialise.h"
31 #include "VP1Base/VP1Deserialise.h"
32 
33 //SoCoin
34 #include <Inventor/nodes/SoSeparator.h>
35 #include <Inventor/nodes/SoMaterial.h>
36 #include <Inventor/nodes/SoSwitch.h>
37 #include "Inventor/nodes/SoDrawStyle.h"
38 #include "Inventor/nodes/SoLightModel.h"
39 
40 //Athnea
43 
44 //Qt
45 #include <QComboBox>
46 #include <QTreeWidgetItem>
47 #include <qdatetime.h>
48 #include <vector>
49 #include <QString>
50 #include <sstream>
51 
52 //____________________________________________________________________
54 public:
56 
57  //Vector of iParticle handles:
58  std::vector<IParticleHandleBase*> handles;
59  // QList of xAOD handles
60  QList<AODHandleBase*> handlesList;
61 
62  //For iteration:
65 
66  // N.B. Material button defined in children.
67 };
68 
69 
70 
71 //____________________________________________________________________
73 const QString& name,
75  : AODCollHandleBase(cd,name,type), m_d(new Imp), // Need to add back ObjectType once simple way to create string is added to xAODBase
76  m_cut_allowedPtSq(VP1Interval()),
77  m_cut_allowedEta(VP1Interval()),
78  m_cut_allowedPhi(QList<VP1Interval>()),
79  m_cut_pt_allowall(false),
80  m_cut_eta_allowall(false),
81  m_cut_phi_allowall(false),
82  m_cut_etaptphi_allwillfail(true)
83 {
84  m_d->theclass = this;
85 }
86 
87 //____________________________________________________________________
89 {
90  messageVerbose("destructor start");
91 
92  m_d->handles.clear();
93 
94  // clean the QList<handle>
95  for(AODHandleBase* handle : m_d->handlesList) {
96  delete handle;
97  }
98 
99  // delete the Imp instance
100  delete m_d;
101  messageVerbose("destructor end");
102 }
103 
104 //____________________________________________________________________
106 {
107  m_d->handles.reserve(n);
108 }
109 
110 //____________________________________________________________________
112 {
113  IParticleHandleBase* handle = dynamic_cast<IParticleHandleBase* >(ah);
114  if (!handle) {
115  message("ERROR - wrong handle type passed to IParticleCollHandleBase::addHandle!");
116  return;
117  }
118  m_d->handles.push_back(handle); // for the vector<handle>
119  m_d->handlesList << handle; // for the QList<handle>
120 }
121 
122 //____________________________________________________________________
124 {
125  m_d->itHandles = m_d->handles.begin();
126  m_d->itHandlesEnd = m_d->handles.end();
127 }
128 
129 //____________________________________________________________________
131  if (m_d->itHandles==m_d->itHandlesEnd)
132  // if (m_d->itHandles==m_d->itHandlesEnd || m_d->itHandles!=m_d->handles.begin()) // Only use first handle (for debugging)
133  return 0;
134  else
135  return *(m_d->itHandles++);
136 }
137 
138 //____________________________________________________________________
139 QList<AODHandleBase*> IParticleCollHandleBase::getHandlesList() const
140 {
141  messageVerbose("AODCollHandleBase::getHandlesList()");
142  return m_d->handlesList;
143 }
144 
145 //____________________________________________________________________
147 {
148  messageVerbose("IParticleCollHandleBase::cut()");
149 
150  IParticleHandleBase* handle = dynamic_cast<IParticleHandleBase*>(ahand);
151 
152  if (!handle) {
153  message("ERROR! IParticleCollHandleBase::cut() - passed in a handle of the wrong type! ");
154  return false;
155  }
156 
158  return false;
159 
160  messageVerbose("m_cut_pt_allowall: " + QString::number(m_cut_pt_allowall) + " - m_cut_eta_allowall: " + QString::number(m_cut_eta_allowall) + " - m_cut_phi_allowall: " + QString::number(m_cut_phi_allowall) );
161 
163  {
164  messageVerbose("evaluating cut...");
165 
166  messageVerbose("m_cut_allowedEta: " + m_cut_allowedEta.toString() + " - excludeInterval: " + QString::number(m_cut_allowedEta.excludeInterval()) );
167 
168 
169  // Trk::GlobalMomentum mom(handle->momentum());
170  Amg::Vector3D mom(handle->momentum());
171  // std::cout<<"mom mag2: "<<mom.mag2()<<std::endl;
172 
173  // convention is that if interval is real and negative, then P cut rather than pT
174  bool isPCut = (!m_cut_allowedPtSq.noLowerBound() && m_cut_allowedPtSq.lower()<=0)
176 
177  messageVerbose("mom.eta(): " + QString::number(mom.eta()) );
178 
179  if (mom.mag2()!=0.0) {
180 
181  // *** PT CUT ***
182  if (!m_cut_pt_allowall&&!isPCut && !m_cut_allowedPtSq.contains(mom.perp2()))
183  return false;
184  if (!m_cut_pt_allowall&& isPCut && !m_cut_allowedPtSq.contains(-mom.mag2()))
185  return false;
186 
187  // *** ETA CUT ***
188  // if (!m_cut_eta_allowall&&!m_cut_allowedEta.contains(mom.pseudoRapidity())){
189  if (!m_cut_eta_allowall && !m_cut_allowedEta.contains(mom.eta())){ // migration to Amg (Eigen)
190  messageVerbose("eta cut not passed...");
191  return false;
192  }
193 
194  // *** PHI CUT ***
195  if (!m_cut_phi_allowall) {
196  double phi = VP1LinAlgUtils::phiFromXY(mom.x(), mom.y() );
197  messageVerbose("value oh handle's phi: " + QString::number(phi));
198  bool ok(false);
199  for (const VP1Interval& phirange : m_cut_allowedPhi) {
200  if (phirange.contains(phi)||phirange.contains(phi+2*M_PI)||phirange.contains(phi-2*M_PI)) {
201  ok = true;
202  break;
203  }
204  }
205  if (!ok)
206  return false;
207  }
208  }
209  messageVerbose("IParticleCollHandleBase::cut() - mom.mag2() == 0.0!!!");
210 
211  }
212 
213  messageVerbose("IParticleCollHandleBase::cut() - Returning true!");
214  return true;
215 }
216 
217 //____________________________________________________________________
219 {
220  messageVerbose("IParticleCollHandleBase::setCutAllowedPt()");
221 
222  if (!allowedpt.isSane())
223  return;
224 
225  //why do we need to do this? Why does it matter if it's negative?
226  //double minptsq = allowedpt.lower() <= 0.0 ? -std::numeric_limits<double>::infinity() : allowedpt.lower()*allowedpt.lower();
227  //VP1Interval allowedptsq(minptsq,allowedpt.upper()*allowedpt.upper());
228 
229  //Modified code from EJWM
230  double signMin = allowedpt.lower()<0.0 ? -1.0 : 1.0;
231  double signMax = allowedpt.upper()<0.0 ? -1.0 : 1.0;
232  double minptsq = allowedpt.lower() == -std::numeric_limits<double>::infinity() ? -std::numeric_limits<double>::infinity() : signMin*(allowedpt.lower()*allowedpt.lower());
233  double maxptsq = allowedpt.upper() == std::numeric_limits<double>::infinity() ? std::numeric_limits<double>::infinity() : signMax*(allowedpt.upper()*allowedpt.upper());
234 
235  VP1Interval allowedptsq(minptsq,maxptsq);
236  // std::cout<<"allowedptsq:isAllR"<<allowedptsq.isAllR()<<std::endl;
237  // std::cout<<"allowedptsq.isEmpty()"<<allowedptsq.isEmpty()<<std::endl;
238 
239 
240  if (m_cut_allowedPtSq==allowedptsq)
241  return;
242  m_cut_pt_allowall = allowedptsq.isAllR();
243  m_cut_etaptphi_allwillfail = allowedptsq.isEmpty() || m_cut_allowedEta.isEmpty() || m_cut_allowedPhi.isEmpty();
244 
245  if (!m_cut_allowedPtSq.contains(allowedptsq)&&!allowedptsq.contains(m_cut_allowedPtSq)) {
246  m_cut_allowedPtSq = allowedptsq;
248  return;
249  }
250  bool relaxcut = allowedptsq.contains(m_cut_allowedPtSq);
251  m_cut_allowedPtSq = allowedptsq;
252  if (relaxcut)
254  else
256 }
257 
258 //____________________________________________________________________
260 {
261  messageVerbose("signal received in setCutAllowedEta ("+allowedEta.toString()+")");
262  if (!allowedEta.isSane())
263  return;
264 
265  if (m_cut_allowedEta==allowedEta)
266  return;
267  m_cut_eta_allowall = allowedEta.isAllR();
269 
270  if (!m_cut_allowedEta.contains(allowedEta)&&!allowedEta.contains(m_cut_allowedEta)) {
271  m_cut_allowedEta = allowedEta;
273  return;
274  }
275  bool relaxcut = allowedEta.contains(m_cut_allowedEta);
276  m_cut_allowedEta = allowedEta;
277  if (relaxcut)
279  else
281 }
282 
283 //____________________________________________________________________
284 void IParticleCollHandleBase::setCutAllowedPhi(const QList<VP1Interval>& allowedPhi)
285 {
286  messageVerbose("IParticleCollHandleBase::setCutAllowedPhi() - signal received in setCutAllowedPhi.");
287 
288  if (m_cut_allowedPhi==allowedPhi)
289  return;
290  m_cut_allowedPhi = allowedPhi;
291 
292  m_cut_phi_allowall = m_cut_allowedPhi.count()==1 && m_cut_allowedPhi.at(0).isAllR();
294 
295  if (m_cut_phi_allowall) {
297  return;
298  }
301  return;
302  }
304  recheckCutStatusOfAllNotVisibleHandles(); // Redundant, but needed! TODO: check why it is needed. Without this, when disabling and then re-enabling a phi sector, the corresponding jet is not shown, as the handles were not traversed. This fixes ATLASVPONE-626, look at that ticket for details: https://its.cern.ch/jira/browse/ATLASVPONE-626
305  return;
306 }
307 
308 
309 //____________________________________________________________________
310 void IParticleCollHandleBase::setState(const QByteArray&state)
311 {
312  VP1Deserialise des(state);
313  des.disableUnrestoredChecks();
314  if (des.version()!=0&&des.version()!=1) {
315  messageDebug("Warning: Ignoring state with wrong version");
316  return;
317  }
318  bool vis = des.restoreBool();
319 
320  QByteArray matState = des.restoreByteArray();
321  // m_d->matButton->restoreFromState(matState);
322  QByteArray extraWidgetState = des.version()>=1 ? des.restoreByteArray() : QByteArray();
323  setVisible(vis);
324 
325  if (extraWidgetState!=QByteArray())
326  setExtraWidgetsState(extraWidgetState);
327 }
328 
329 //____________________________________________________________________
331 {
332  messageDebug("IParticleCollHandleBase::persistifiableState() - start...");
333 
334  // if (!m_d->matButton) {
335  // message("ERROR: persistifiableState() called before init()");
336  // return QByteArray();
337  // }
338  VP1Serialise serialise(1/*version*/);
339  serialise.disableUnsavedChecks();
340 
341  // SAVE THE CHECKED/UNCHECKED STATUS OF THE COLLECTION
342  serialise.save(visible());
343 
344  // SAVE THE MATERIAL BUTTON
345  // Q_ASSERT(m_d->matButton&&"Did you forget to call init() on this VP1StdCollection?");
346  // serialise.save(m_d->matButton->saveState());
347 
348  // SAVE THE EXTRA-STATES
349  serialise.save(extraWidgetsState());//version 1+
350 
351  messageDebug("IParticleCollHandleBase::persistifiableState() - end.");
352  return serialise.result();
353 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
VP1Serialise.h
AODCollHandleBase::setExtraWidgetsState
void setExtraWidgetsState(const QByteArray &)
Definition: AODCollHandleBase.cxx:519
VP1Interval::isSane
bool isSane() const
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
IParticleCollHandleBase::m_cut_pt_allowall
bool m_cut_pt_allowall
Definition: IParticleCollHandleBase.h:126
GlobalVariables.phirange
phirange
Definition: GlobalVariables.py:64
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
AODHandleBase
Definition: AODHandleBase.h:43
AODCollHandleBase
Base class for all AOD object collections This class primarily handles setting up the interface,...
Definition: AODCollHandleBase.h:57
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
ObjectType
ObjectType
Definition: BaseObject.h:11
AODSysCommonData
Definition: AODSysCommonData.h:42
VP1ExtraSepLayerHelper.h
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
AODSystemController.h
M_PI
#define M_PI
Definition: ActiveFraction.h:11
IParticleCollHandleBase::IParticleCollHandleBase
IParticleCollHandleBase(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType)
Definition: IParticleCollHandleBase.cxx:72
IParticleCollHandleBase::m_d
Imp * m_d
Definition: IParticleCollHandleBase.h:120
VP1Interval::upper
double upper() const
IParticleCollHandleBase::Imp
Definition: IParticleCollHandleBase.cxx:53
IParticleCollHandleBase::Imp::handlesList
QList< AODHandleBase * > handlesList
Definition: IParticleCollHandleBase.cxx:60
IParticleCollHandleBase::Imp::itHandles
std::vector< IParticleHandleBase * >::iterator itHandles
Definition: IParticleCollHandleBase.cxx:63
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
VP1Interval::excludeInterval
bool excludeInterval() const
IParticleCollHandleBase::setCutAllowedPt
void setCutAllowedPt(const VP1Interval &)
Definition: IParticleCollHandleBase.cxx:218
IParticleCollHandleBase::setCutAllowedPhi
void setCutAllowedPhi(const QList< VP1Interval > &)
Definition: IParticleCollHandleBase.cxx:284
VP1LinAlgUtils::phiFromXY
static double phiFromXY(const double &x, const double &y)
Definition: VP1LinAlgUtils.cxx:374
VP1QtInventorUtils.h
VP1LinAlgUtils.h
IParticleCollHandleBase::persistifiableState
virtual QByteArray persistifiableState() const
Provide specific implementation.
Definition: IParticleCollHandleBase.cxx:330
GeoPrimitives.h
IParticleCollHandleBase::getHandlesList
QList< AODHandleBase * > getHandlesList() const
Definition: IParticleCollHandleBase.cxx:139
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
VP1Interval::lower
double lower() const
VP1StdCollection::setVisible
void setVisible(bool)
Definition: VP1StdCollection.cxx:160
beamspotman.n
n
Definition: beamspotman.py:731
IParticleHandleBase
Definition: IParticleHandleBase.h:42
IParticleHandleBase::momentum
virtual Amg::Vector3D momentum() const
Definition: IParticleHandleBase.h:52
IParticleCollHandleBase::m_cut_etaptphi_allwillfail
bool m_cut_etaptphi_allwillfail
Definition: IParticleCollHandleBase.h:129
IVP13DSystem.h
IParticleHandleBase.h
IParticleCollHandleBase::Imp::theclass
IParticleCollHandleBase * theclass
Definition: IParticleCollHandleBase.cxx:55
AODCollHandleBase::recheckCutStatusOfAllNotVisibleHandles
void recheckCutStatusOfAllNotVisibleHandles()
Definition: AODCollHandleBase.cxx:177
AODCollHandleBase::extraWidgetsState
QByteArray extraWidgetsState() const
Definition: AODCollHandleBase.cxx:510
AODCollHandleBase::recheckCutStatusOfAllHandles
void recheckCutStatusOfAllHandles()
Definition: AODCollHandleBase.cxx:203
VP1AODSystem.h
IParticleCollHandleBase::cut
virtual bool cut(AODHandleBase *)
Definition: IParticleCollHandleBase.cxx:146
IParticleCollHandleBase::setCutAllowedEta
void setCutAllowedEta(const VP1Interval &)
Definition: IParticleCollHandleBase.cxx:259
VP1Deserialise
Definition: VP1Deserialise.h:44
AODSysCommonData.h
VP1Interval::isEmpty
bool isEmpty() const
EventPrimitives.h
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
VP1Interval::contains
bool contains(const double &x) const
IParticleCollHandleBase::Imp::itHandlesEnd
std::vector< IParticleHandleBase * >::iterator itHandlesEnd
Definition: IParticleCollHandleBase.cxx:64
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
VP1Interval::toString
QString toString() const
VP1Interval::noUpperBound
bool noUpperBound() const
IParticleCollHandleBase::m_cut_eta_allowall
bool m_cut_eta_allowall
Definition: IParticleCollHandleBase.h:127
IParticleCollHandleBase::handleIterationBegin
virtual void handleIterationBegin()
Definition: IParticleCollHandleBase.cxx:123
IParticleCollHandleBase::Imp::handles
std::vector< IParticleHandleBase * > handles
Definition: IParticleCollHandleBase.cxx:58
VP1Interval
Definition: VP1Interval.h:23
IParticleCollHandleBase::hintNumberOfHandlesInEvent
virtual void hintNumberOfHandlesInEvent(unsigned)
Definition: IParticleCollHandleBase.cxx:105
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IParticleCollHandleBase::getNextHandle
virtual AODHandleBase * getNextHandle()
Definition: IParticleCollHandleBase.cxx:130
IParticleCollHandleBase::~IParticleCollHandleBase
virtual ~IParticleCollHandleBase()
Definition: IParticleCollHandleBase.cxx:88
VP1Interval::isAllR
bool isAllR() const
VP1StdCollection::visible
bool visible() const
Definition: VP1StdCollection.cxx:142
IParticleCollHandleBase::addHandle
void addHandle(AODHandleBase *)
Definition: IParticleCollHandleBase.cxx:111
IParticleCollHandleBase::m_cut_allowedPtSq
VP1Interval m_cut_allowedPtSq
Definition: IParticleCollHandleBase.h:123
calibdata.cd
cd
Definition: calibdata.py:51
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
IParticleCollHandleBase.h
IParticleCollHandleBase
Base class for collections holding AOD objects of iParticle type Handles pt etc cuts Local data:
Definition: IParticleCollHandleBase.h:50
AODCollHandleBase::recheckCutStatusOfAllVisibleHandles
void recheckCutStatusOfAllVisibleHandles()
Definition: AODCollHandleBase.cxx:144
IParticleCollHandleBase::m_cut_allowedPhi
QList< VP1Interval > m_cut_allowedPhi
Definition: IParticleCollHandleBase.h:125
IParticleCollHandleBase::m_cut_phi_allowall
bool m_cut_phi_allowall
Definition: IParticleCollHandleBase.h:128
query_example.des
des
Definition: query_example.py:9
VP1Interval::noLowerBound
bool noLowerBound() const
IParticleCollHandleBase::setState
virtual void setState(const QByteArray &)
Provide specific implementation.
Definition: IParticleCollHandleBase.cxx:310
IParticleCollHandleBase::m_cut_allowedEta
VP1Interval m_cut_allowedEta
Definition: IParticleCollHandleBase.h:124