ATLAS Offline Software
Loading...
Searching...
No Matches
VertexCollHandle.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 VertexCollHandle //
9// //
10// Author: edward.moyse@cern.ch //
11// Initial version: June 2015 //
12// //
14
15//Local includes
16#include "VertexHandle.h"
17#include "VertexCollHandle.h"
18#include "AODSysCommonData.h"
22
23//VP1 base includes
30#ifndef BUILDVP1LIGHT
33#endif
34
35//SoCoin
36#include <Inventor/nodes/SoSeparator.h>
37#include <Inventor/nodes/SoMaterial.h>
38#include <Inventor/nodes/SoSwitch.h>
39#include "Inventor/nodes/SoDrawStyle.h"
40#include "Inventor/nodes/SoLightModel.h"
41
42//Athena
45
46//AOD
48
49//Qt
50#include <QComboBox>
51#include <QTreeWidgetItem>
52#include <qdatetime.h>
53#include <vector>
54#include <QString>
55#include <QDebug>
56
57#ifdef BUILDVP1LIGHT
58 #include <QSettings>
59 #include "xAODRootAccess/Init.h"
61#endif // BUILDVP1LIGHT
62
63
64//____________________________________________________________________
66public:
68
69 //Vector of iParticle handles:
70 std::vector<VertexHandle*> handles;
71 // QList of IParticle handles
72 QList<AODHandleBase*> handlesList;
73
74 //For iteration:
75 std::vector<VertexHandle*>::iterator itHandles;
76 std::vector<VertexHandle*>::iterator itHandlesEnd;
77
78 //Extra widgets;
80
81 // int updateGUICounter;
82 //
83 // void possiblyUpdateGUI() {//Fixme: to IParticleCollHandleBase
84 // if (!((updateGUICounter++)%50)) {
85 // theclass->systemBase()->updateGUI();
86 // }
87 // }
88};
89
90
91
92//____________________________________________________________________
95 m_d(new Imp), // Need to add back ObjectType once simple way to create string is added to xAODBase
96 m_cut_allowedY(VP1Interval(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())),
97 m_cut_allowedR(VP1Interval(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())),
98 m_cut_allowedZ(VP1Interval(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())),
99 m_cut_r_allowall(true),
100 m_cut_z_allowall(true),
102{
103 m_d->theclass = this;
104
105 //The object names should not contain all sorts of funky chars (mat button style sheets wont work for instance):
106 QString safetext(text());
107 safetext.replace(' ','_');
108 safetext.replace('[','_');
109 safetext.replace(']','_');
110 safetext.replace('/','_');
111 safetext.replace('.','_');
112 safetext.replace(',','_');
113 safetext.replace('<','_');
114 safetext.replace('>','_');
115 safetext.replace('&','_');
116}
117
118//____________________________________________________________________
120{
121 messageVerbose("destructor start");
122
123 // clean the vector<handle>
124 #ifndef BUILDVP1LIGHT
125 cleanupPtrContainer(m_d->handles);
126 #endif
127
128 // delete the Imp instance
129 delete m_d;
130
131 messageVerbose("destructor end");
132}
133
134//____________________________________________________________________
135#if defined BUILDVP1LIGHT
137 {
138 return sys->getObjectList(xAOD::Type::Vertex);
139 }
140#else
145#endif // BUILDVP1LIGHT
146
147
148//____________________________________________________________________
150{
151 m_d->collSettingsButton = new VertexCollectionSettingsButton;
152 m_d->collSettingsButton->setMaterialText(name());
153 VP1StdCollection::init(m_d->collSettingsButton);//this call is required. Passing in m_d->collSettingsButton means we have the more complex button.
154 setupSettingsFromController(common()->controller());
155 connect(this,SIGNAL(visibilityChanged(bool)),this,SLOT(collVisibilityChanged(bool)));
156
157 collSwitch()->addChild(m_d->collSettingsButton->vertexLightModel());
158 collSwitch()->addChild(m_d->collSettingsButton->vertexDrawStyle());
159}
160
162 //cuts
163 // R
164 connect(m_d->collSettingsButton,SIGNAL(cutAllowedRChanged(const VP1Interval&)),this,SLOT(setCutAllowedR(const VP1Interval&)));
165 setCutAllowedR(m_d->collSettingsButton->cutAllowedR());
166 // Y
167 connect(m_d->collSettingsButton,SIGNAL(cutAllowedYChanged(const VP1Interval&)),this,SLOT(setCutAllowedY(const VP1Interval&)));
168 setCutAllowedY(m_d->collSettingsButton->cutAllowedY());
169 // Z
170 connect(m_d->collSettingsButton,SIGNAL(cutAllowedZChanged(const VP1Interval&)),this,SLOT(setCutAllowedZ(const VP1Interval&)));
171 setCutAllowedZ(m_d->collSettingsButton->cutAllowedZ());
172 // size
173 connect(m_d->collSettingsButton,SIGNAL(vertexSizeChanged(int)),this,SLOT(setVertexSize(int)));
174 setVertexSize(m_d->collSettingsButton->vertexSize());
175}
176
178{
179 // TODO: it is not used so far! Check Other collections and update accordingly
180
181 // kinetic cuts
182 setCutAllowedR(m_d->collSettingsButton->cutAllowedR());
183 setCutAllowedY(m_d->collSettingsButton->cutAllowedY());
184 setCutAllowedZ(m_d->collSettingsButton->cutAllowedZ());
185 // other settings
186 setVertexSize(m_d->collSettingsButton->vertexSize());
187}
188
189
191 if (!m_d->collSettingsButton){
192 messageVerbose("No collSettingsButton set! Can't call init(), so crash is imminent...");
193 throw std::runtime_error("Vertex - No collSettingsButton set!");
194 }
195 return *m_d->collSettingsButton;
196}
197
198//____________________________________________________________________
200{
201 messageVerbose("loading Vertex collection");
202
203 //Get collection:
204 const xAOD::VertexContainer * coll(nullptr);
205
206 #if defined BUILDVP1LIGHT
207 // // Get the name of the application:
208 // const char* appName = "VP1Light";
209
210 // // Initialize the environment:
211 // if( !xAOD::Init( appName ).isSuccess() ) {
212 // message("Failed to execute xAOD::Init");
213 // return false;
214 // }
215
216 // Retrieve objects from the event
217 if( !(systemBase()->getEvent())->retrieve( coll, name().toStdString()).isSuccess() ) {
218 message("Error: Could not retrieve collection with key="+name());
219 return false;
220 }
221 #else
222 if (!VP1SGAccessHelper(systemBase()).retrieve(coll, name())) {
223 message("Error: Could not retrieve vertex collection with key="+name());
224 return false;
225 }
226 #endif //BUILDVP1LIGHT
227
228 // // Retrieve the xAOD particles:
229 // const xAOD::VertexContainer* xaod = evtStore()->retrieve<const xAOD::VertexContainer>( m_VertexCollection );
230
231 // Check that the auxiliary store association was made successfully:
232 if( ! coll->hasStore() ) {
233 message("No auxiliary store got associated to the Vertex container with key: " +name());
234 }
235
236 // This is needed for now, until the issues around the DV code are
237 // sorted out...
238 const_cast< xAOD::VertexContainer* >( coll )->setStore(
239 ( SG::IAuxStore* ) coll->getConstStore() );
240 for (auto vertex : *coll) {
241 qInfo() << " (x, y, z) = (" << vertex->x() << ", " << vertex->y() << ", " << vertex->z() << ")"; // just to print out something
242 } // end for loop over vertices
243
244 //Make appropriate vertex handles:
245 xAOD::VertexContainer::const_iterator it, itEnd = coll->end();
246 for ( it = coll->begin() ; it != itEnd; ++it) {
247 // m_d->possiblyUpdateGUI(); FIXME
249 if (!*it) {
250 messageDebug("WARNING: Ignoring null Vertex pointer.");
251 continue;
252 }
253 addHandle(new VertexHandle(this,*it));
254 }
255 return true;
256}
257
258
259//____________________________________________________________________
260QList<AODHandleBase*> VertexCollHandle::getHandlesList() const
261{
262 messageVerbose("VertexCollHandle::getHandlesList()");
263 return m_d->handlesList;
264}
265
266//____________________________________________________________________
268{
269 messageVerbose("VertexCollHandle::cut()");
270
271 VertexHandle* handle = dynamic_cast<VertexHandle*>(ah);
272 if (!handle) {
273 messageVerbose("VertexCollHandle::cut() - passing in handle of wrong type! Aborting.");
274 return false;
275 }
276
278 messageVerbose("VertexCollHandle::cut() - returning false as m_cut_rz_allwillfail is set.");
279 return false;
280 }
281
282 // FIXME
283 float vertexR = 0.0;
284 //float vertexZ = 0.0;
285
286 float vertexX = handle->getPositionX();
287 float vertexY = handle->getPositionY();
288 float vertexZ = handle->getPositionZ();
289
290 messageVerbose("Vertex R: " + QString::number(vertexR));
291 messageVerbose("Vertex x, y, z: " + QString::number(vertexX) + ", " + QString::number(vertexY)+ ", " + QString::number(vertexZ));
292
293
294
296 {
297 messageVerbose("evaluating cuts...");
298
299 // *** r CUT ***
300 messageVerbose("vertexR: " + QString::number(vertexR) + " - m_cut_allowedR: " + m_cut_allowedR.toString() + " - excludeInterval: " + QString::number(m_cut_allowedR.excludeInterval()) );
301 if (!m_cut_r_allowall && !m_cut_allowedR.contains(vertexR)){
302 messageVerbose("r cut not passed...");
303 return false;
304 }
305
306 // *** Y CUT ***
307 messageVerbose("m_cut_allowedY: " + m_cut_allowedY.toString() + " - excludeInterval: " + QString::number(m_cut_allowedY.excludeInterval()) );
308 if (!m_cut_y_allowall && !m_cut_allowedY.contains(vertexY)){
309 messageVerbose("Y cut not passed...");
310 return false;
311 }
312
313 // *** Z CUT ***
314 messageVerbose("m_cut_allowedZ: " + m_cut_allowedZ.toString() + " - excludeInterval: " + QString::number(m_cut_allowedZ.excludeInterval()) );
315 if (!m_cut_z_allowall && !m_cut_allowedZ.contains(vertexZ)){
316 messageVerbose("Z cut not passed...");
317 return false;
318 }
319 }
320
321 messageVerbose("cut() - Returning true!");
322 return true;
323}
324
325//____________________________________________________________________
327{
328 m_d->handles.reserve(n);
329}
330
331//____________________________________________________________________
333{
334 VertexHandle* handle = dynamic_cast<VertexHandle* >(ah);
335 if (!handle) {
336 message("ERROR - wrong handle type passed to VertexCollHandle::addHandle!");
337 return;
338 }
339 m_d->handles.push_back(handle); // for the vector<handle>
340 m_d->handlesList << handle; // for the QList<handle>
341}
342
343//____________________________________________________________________
345{
346 m_d->itHandles = m_d->handles.begin();
347 m_d->itHandlesEnd = m_d->handles.end();
348}
349
350//____________________________________________________________________
352 if (m_d->itHandles==m_d->itHandlesEnd)
353 return 0;
354 else
355 return *(m_d->itHandles++);
356}
357
358//____________________________________________________________________
360{
361
362 messageVerbose("signal received in setCutAllowedR ("+allowedR.toString()+") with m_cut_allowedR = "+m_cut_allowedR.toString());
363 if (!allowedR.isSane())
364 return;
365
366 if (m_cut_allowedR==allowedR)
367 return;
368
369 m_cut_r_allowall = allowedR.isAllR();
370 m_cut_rz_allwillfail = allowedR.isEmpty() || m_cut_allowedR.isEmpty();
371
372 std::cout<<"m_cut_rz_allwillfail= "<<m_cut_rz_allwillfail<< " because allowedR.isEmpty()="<<allowedR.isEmpty()<<" || m_cut_allowedR.isEmpty() = "<<m_cut_allowedR.isEmpty()<<std::endl;
373
374 if (!m_cut_allowedR.contains(allowedR)&&!allowedR.contains(m_cut_allowedR)) {
375 m_cut_allowedR = allowedR;
377 return;
378 }
379 bool relaxcut = allowedR.contains(m_cut_allowedR);
380 m_cut_allowedR = allowedR;
381 if (relaxcut)
383 else
385}
386
387//____________________________________________________________________
389{
390 messageVerbose("signal received in setCutAllowedY ("+allowedY.toString()+")");
391 if (!allowedY.isSane())
392 return;
393
394 if (m_cut_allowedY==allowedY)
395 return;
396 m_cut_y_allowall = allowedY.isAllR();
397 m_cut_ry_allwillfail = allowedY.isEmpty() || m_cut_allowedY.isEmpty();
398
399 if (!m_cut_allowedY.contains(allowedY) && !allowedY.contains(m_cut_allowedY)) {
400 m_cut_allowedY = allowedY;
402 return;
403 }
404 bool relaxcut = allowedY.contains(m_cut_allowedY);
405 m_cut_allowedY = allowedY;
406 if (relaxcut)
408 else
410}
411//____________________________________________________________________
413{
414 messageVerbose("signal received in setCutAllowedZ ("+allowedZ.toString()+")");
415 if (!allowedZ.isSane())
416 return;
417
418 if (m_cut_allowedZ==allowedZ)
419 return;
420 m_cut_z_allowall = allowedZ.isAllR();
421 m_cut_rz_allwillfail = allowedZ.isEmpty() || m_cut_allowedZ.isEmpty();
422
423 if (!m_cut_allowedZ.contains(allowedZ)&&!allowedZ.contains(m_cut_allowedZ)) {
424 m_cut_allowedZ = allowedZ;
426 return;
427 }
428 bool relaxcut = allowedZ.contains(m_cut_allowedZ);
429 m_cut_allowedZ = allowedZ;
430 if (relaxcut)
432 else
434}
435
437{
438 messageVerbose("signal received in vertexSizeChanged ("+str(size)+")");
439
441}
442
443//____________________________________________________________________
444void VertexCollHandle::setState(const QByteArray&state)
445{
446 VP1Deserialise des(state);
448 if (des.version()!=0&&des.version()!=1) {
449 messageDebug("Warning: Ignoring state with wrong version");
450 return;
451 }
452 bool vis = des.restoreBool();
453
454 QByteArray matState = des.restoreByteArray();
455 // m_d->matButton->restoreFromState(matState);
456 QByteArray extraWidgetState = des.version()>=1 ? des.restoreByteArray() : QByteArray();
457 setVisible(vis);
458
459 if (extraWidgetState!=QByteArray())
460 setExtraWidgetsState(extraWidgetState);
461}
462
463//____________________________________________________________________
465{
466 messageDebug("VertexCollHandle::persistifiableState() - start...");
467
468 // if (!m_d->matButton) {
469 // message("ERROR: persistifiableState() called before init()");
470 // return QByteArray();
471 // }
472 VP1Serialise serialise(1/*version*/);
473 serialise.disableUnsavedChecks();
474
475 // SAVE THE CHECKED/UNCHECKED STATUS OF THE COLLECTION
476 serialise.save(visible());
477
478 // SAVE THE MATERIAL BUTTON
479 // Q_ASSERT(m_d->matButton&&"Did you forget to call init() on this VP1StdCollection?");
480 // serialise.save(m_d->matButton->saveState());
481
482 // SAVE THE EXTRA-STATES
483 serialise.save(extraWidgetsState());//version 1+
484
485 messageDebug("VertexCollHandle::persistifiableState() - end.");
486 return serialise.result();
487}
AODCollHandleBase(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType)
const AODSysCommonData * common() const
void recheckCutStatusOfAllNotVisibleHandles()
void recheckCutStatusOfAllVisibleHandles()
void setExtraWidgetsState(const QByteArray &)
QByteArray extraWidgetsState() const
void setupSettingsFromController(const AODSystemController *)
const QString & name() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void updateGUI()
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
QByteArray restoreByteArray()
void disableUnrestoredChecks()
qint32 version() const
void messageVerbose(const QString &) const
void message(const QString &) const
IVP1System * systemBase() const
void messageDebug(const QString &) const
bool isEmpty() const
QString toString() const
bool isSane() const
bool isAllR() const
bool contains(const double &x) const
QStringList getKeys() const
virtual void init(VP1MaterialButtonBase *button=0)
SoSwitch * collSwitch() const
Add this somewhere in your scenegraph (do not add any children here!)
void visibilityChanged(bool)
QString text() const
VertexCollHandle * theclass
VertexCollectionSettingsButton * collSettingsButton
std::vector< VertexHandle * >::iterator itHandles
std::vector< VertexHandle * >::iterator itHandlesEnd
QList< AODHandleBase * > handlesList
std::vector< VertexHandle * > handles
void cleanupPtrContainer(T &) const
static QStringList availableCollections(IVP1System *)
VertexCollHandle(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType)
virtual void setState(const QByteArray &)
Provide specific implementation.
AODHandleBase * getNextHandle()
virtual QByteArray persistifiableState() const
Provide specific implementation.
virtual void setupSettingsFromControllerSpecific(const AODSystemController *)
For extensions specific to this collection.
virtual bool load()
Actually load the EDM objects.
void setCutAllowedZ(const VP1Interval &)
QList< AODHandleBase * > getHandlesList() const
void setCutAllowedY(const VP1Interval &)
void addHandle(AODHandleBase *)
void hintNumberOfHandlesInEvent(unsigned)
virtual bool cut(AODHandleBase *)
VP1Interval m_cut_allowedZ
virtual void init(VP1MaterialButtonBase *matBut=0)
const VertexCollectionSettingsButton & collSettingsButton() const
void setCutAllowedR(const VP1Interval &)
VP1Interval m_cut_allowedY
VP1Interval m_cut_allowedR
double getPositionZ() const
double getPositionX() const
double getPositionY() const
STL namespace.
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Vertex
The object is a vertex.
Definition ObjectType.h:59
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".