ATLAS Offline Software
Loading...
Searching...
No Matches
MissingEtCollHandle.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 MissingEtCollHandle //
9// //
10// Author: Riccardo-Maria BIANCHI (rbianchi@cern.ch) //
11// Initial version: May 2014 //
12// //
14
15//Local
16#include "MissingEtCollHandle.h"
17
18#include "AODHandleBase.h"
19#include "AODCollHandleBase.h"
20#include "AODSysCommonData.h"
21
22//xAOD
23//#include "xAODJet/MissingETContainer.h"
25
26
27//VP1
28#include "VP1Base/IVP1System.h"
29#include "VP1Base/VP1Msg.h"
30#include "VP1Base/VP1Interval.h"
33#ifndef BUILDVP1LIGHT
36#endif
37
38//Qt
39#include <QStringList>
40
41// SoCoin
42#include <Inventor/C/errors/debugerror.h>
43#include <Inventor/nodes/SoSeparator.h>
44#include <Inventor/nodes/SoSwitch.h>
45#include <Inventor/nodes/SoMaterial.h>
46
48#include "MissingEtHandle.h"
49//#include "Inventor/nodes/SoDrawStyle.h"
50//#include "Inventor/nodes/SoLightModel.h"
51
52#ifdef BUILDVP1LIGHT
53 #include <QSettings>
54 #include "xAODRootAccess/Init.h"
56#endif // BUILDVP1LIGHT
57
58
59//____________________________________________________________________
60#if defined BUILDVP1LIGHT
62 {
63 return sys->getObjectList(xAOD::Type::Other);
64 }
65#else
70#endif // BUILDVP1LIGHT
71
72//____________________________________________________________________
74public:
78
79 //Vector of iParticle handles:
80 std::vector<MissingEtHandle*> handles;
81 // QList of xAOD handles
82 QList<AODHandleBase*> handlesList;
83
84 //For iteration:
85 std::vector<MissingEtHandle*>::iterator itHandles;
86 std::vector<MissingEtHandle*>::iterator itHandlesEnd;
87
88 // settings
89 double scale = 1.; // the default scale of all jets
90 bool randomColours = false;
91
92 // SoMaterial* defaultParametersMaterial; /// This will be given to the VP1MaterialButton in
93
94 void possiblyUpdateGUI() {//Fixme: to AODCollHandleBase
95 if (!((updateGUICounter++)%50)) {
96 theclass->systemBase()->updateGUI();
97 }
98 }
99};
100
101//____________________________________________________________________
104{
105 m_d->theclass = this;
106 m_d->updateGUICounter = 0;
107 m_d->collSettingsButton=0;
108
109
110 //The object names should not contain all sorts of funky chars (mat button style sheets wont work for instance):
111 QString safetext(text());
112 safetext.replace(' ','_');
113 safetext.replace('[','_');
114 safetext.replace(']','_');
115 safetext.replace('/','_');
116 safetext.replace('.','_');
117 safetext.replace(',','_');
118 safetext.replace('<','_');
119 safetext.replace('>','_');
120 safetext.replace('&','_');
121
122 // m_d->defaultParametersMaterial = new SoMaterial;
123 // m_d->defaultParametersMaterial->setName(("MissingEtCollHandle"+safetext).toStdString().c_str());
124 // m_d->defaultParametersMaterial->ref();
125 // m_d->matButton->setDefaultParameterMaterial(m_d->defaultParametersMaterial); FIXME
126}
127
128//____________________________________________________________________
130{
131 // m_d->defaultParametersMaterial->unref();
132
133 // clean the QList<handle>
134 for(AODHandleBase* handle : m_d->handles) {
135 delete handle;
136 }
137
138 // TODO: implemet this del
139 // if (m_d->bTaggingSwitch) m_d->bTaggingSwitch->unref();
140
141 delete m_d;
142}
143
144//____________________________________________________________________
146{
147 // std::cout<<"MissingEtCollHandle::init 1"<<std::endl;
148
149 // m_d->matButton = new MissingEtCollectionSettingsButton; // TODO: update for jet
150 // m_d->matButton->setMaterialText(name());
151 m_d->collSettingsButton = new MissingEtCollectionSettingsButton;
152 m_d->collSettingsButton->setMaterialText(name());
153
154 // std::cout<<"Calling VP1StdCollection::init with m_d->matButton (MissingEtCollectionSettingsButton)="<<m_d->matButton<<std::endl;
155 VP1StdCollection::init(m_d->collSettingsButton);//this call is required. Passing in m_d->collSettingsButton means we have the more complex button.
156 setupSettingsFromController(common()->controller());
157 connect(this,SIGNAL(visibilityChanged(bool)),this,SLOT(collVisibilityChanged(bool)));
158
159 // std::cout<<"MissingEtCollHandle::init 2"<<std::endl;
160 // std::cout<<"swi: "<<collSwitch()<<std::endl;
161 // std::cout<<"sep: "<<collSep()<<std::endl;
162 // std::cout<<"mat: "<<material()<<std::endl;
163
164 // collSwitch()->addChild(m_d->collSettingsButton->trackLightModel()); // TODO: update for jets
165 // collSwitch()->addChild(m_d->collSettingsButton->trackDrawStyle()); // TODO: update for jets
166}
167
168//____________________________________________________________________
170{
171 m_d->handles.reserve(n);
172}
173
174//____________________________________________________________________
176{
177 MissingEtHandle* handle = dynamic_cast<MissingEtHandle* >(ah);
178 if (!handle) {
179 message("ERROR - wrong handle type passed to MissingEtCollHandle::addHandle!");
180 return;
181 }
182 m_d->handles.push_back(handle); // for the vector<handle>
183 m_d->handlesList << handle; // for the QList<handle>
184}
185
186//____________________________________________________________________
188{
189 m_d->itHandles = m_d->handles.begin();
190 m_d->itHandlesEnd = m_d->handles.end();
191}
192
193//____________________________________________________________________
195 if (m_d->itHandles==m_d->itHandlesEnd)
196 return 0;
197 else
198 return *(m_d->itHandles++);
199}
200
201//____________________________________________________________________
202QList<AODHandleBase*> MissingEtCollHandle::getHandlesList() const
203{
204 messageVerbose("AODCollHandleBase::getHandlesList()");
205 return m_d->handlesList;
206}
207
208
209
211
212 //cuts
213 // connect(m_d->collSettingsButton,SIGNAL(cutAllowedPtChanged(const VP1Interval&)),this,SLOT(setCutAllowedPt(const VP1Interval&)));
214 // setCutAllowedPt(m_d->collSettingsButton->cutAllowedPt());
215 //
216 // connect(m_d->collSettingsButton,SIGNAL(cutAllowedEtaChanged(const VP1Interval&)),this,SLOT(setCutAllowedEta(const VP1Interval&)));
217 // setCutAllowedEta(m_d->collSettingsButton->cutAllowedEta());
218 //
219 // connect(m_d->collSettingsButton,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(setCutAllowedPhi(const QList<VP1Interval>&)));
220 // setCutAllowedPhi(m_d->collSettingsButton->cutAllowedPhi());
221
222 // // Parameters
223 // connect(m_d->collSettingsButton,SIGNAL(showParametersChanged(bool)), this,SLOT(showParametersChanged(bool)));
224 // connect(m_d->collSettingsButton,SIGNAL(colourParametersByTypeChanged(bool)),this,SLOT(showParametersChanged(bool)));
225 // Just reusing the same slot, since it doesn't
226
227 // scale
228 //connect(m_d->collSettingsButton,SIGNAL(scaleChanged(const double&)),this,SLOT(setScale(const double&)));
229 //setScale( this->scale() );
230
231 // MET length and thickness
232 connect(m_d->collSettingsButton,SIGNAL(metSizeChanged(int)),this,SLOT(setMetSize(int)));
233 setMetSize(m_d->collSettingsButton->metLength());
234
235 // Phi cut
236 connect(m_d->collSettingsButton,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(setCutAllowedPhi(const QList<VP1Interval>&)));
237 setCutAllowedPhi(m_d->collSettingsButton->cutAllowedPhi());
238
239 // random jet colors
240 // connect(m_d->collSettingsButton,SIGNAL(rerandomise()),this,SLOT(rerandomise()));
241 // connect(m_d->collSettingsButton,SIGNAL(randomJetColoursChanged(const bool&)),this,SLOT(setRandomJetColours(const bool&)));
242 // setRandomJetColours(m_d->collSettingsButton->randomJetColours());
243}
244
245
247{
248 // TODO: it is not used so far! Check Other collections and update accordingly
249
250 // kinetic cuts
251 setCutAllowedPhi(m_d->collSettingsButton->cutAllowedPhi());
252 // other settings
253 setMetSize(m_d->collSettingsButton->metLength());
254
255}
256
257//SoMaterial* MissingEtCollHandle::defaultParameterMaterial() const {
258// return m_d->defaultParametersMaterial;
259//}
260
261
263 if (!m_d->collSettingsButton){
264 messageVerbose("MET - No collSettingsButton set! Can't call init(), so crash is imminent...");
265 throw std::runtime_error("MET - No collSettingsButton set!");
266 }
267 return *m_d->collSettingsButton;
268}
269
270
271
273//void MissingEtCollHandle::setScale(const double& sca)
274//{
275//
276// messageVerbose("MissingEtCollHandle::setScale() - scale: " + QString::number(sca));
277//
278// if (m_d->handlesList.isEmpty()) {
279// messageVerbose("no jet handles defined! returning.");
280// return;
281// }
282//
283// if (m_d->scale == sca)
284// return;
285//
286// m_d->scale = std::max(1*Gaudi::Units::mm/(100*Gaudi::Units::GeV),
287// std::min(99*Gaudi::Units::m/(1*Gaudi::Units::MeV),
288// // m_d->collSettingsButton->lengthOf100GeV() * Gaudi::Units::m/(100.0*Gaudi::Units::GeV)));
289// sca * Gaudi::Units::m/(100.0*Gaudi::Units::GeV)));
290//
291// if (!isLoaded())
292// return;
293//
294// messageVerbose("Scale change: to "+str(m_d->scale/(Gaudi::Units::m/(100.0 * Gaudi::Units::GeV)))+" m/100GeV. Updating "+str(m_d->handlesList.count())+" jets");
295// std::cout << "Scale change: m_d->scale/(Gaudi::Units::m/(100.0*Gaudi::Units::GeV)))" << "m/100GeV. Updating " << m_d->handlesList.count() << " jets" << std::endl;
296// largeChangesBegin();
297//
298// for(AODHandleBase* partHandle : m_d->handles) {
299// MissingEtHandle* met = dynamic_cast<MissingEtHandle*>(partHandle);
300// if (met->has3DObjects()) {
301// met->setScale(m_d->scale);
302// met->updateHeight();
303// }
304// }
305// largeChangesEnd();
306//}
307
308
310{
311 messageVerbose("signal received: metSizeChanged ("+str(size)+")");
312
314}
315
316
318//double MissingEtCollHandle::scale() const
319//{
320// return m_d->scale;
321//}
322
323
325//bool MissingEtCollHandle::isRandomColors() const
326//{
327// VP1Msg::messageDebug("MissingEtCollHandle::isRandomColors()");
328// return m_d->randomColours;
329//}
330//
331//
333//void MissingEtCollHandle::setRandomJetColours(const bool& b)
334//{
335// messageVerbose("MissingEtCollHandle::setRandomJetColours() - b: "+QString::number(b));
336//
337// if (m_d->randomColours == b)
338// return;
339//
340// m_d->randomColours = b;
341// std::cout << "isRandom: " << m_d->randomColours << std::endl;
342//
343// if (!isLoaded())
344// return;
345//
346// largeChangesBegin();
347// int ijet = 0;
348// for(AODHandleBase* partHandle : m_d->handles) {
349// ++ijet;
350// messageVerbose("considering jet: "+QString::number(ijet));
351// MissingEtCollHandle* jet = dynamic_cast<MissingEtCollHandle*>(partHandle);
352// if (jet->has3DObjects()) {
353// int randomColors = isRandomColors();
354// messageVerbose("setting random material on jet: "+QString::number(ijet)+" - random colors? "+QString::number(randomColors));
356// jet->updateMaterial( randomColors );
357// }
358// }
359// largeChangesEnd();
360//}
361
362
363
365//void MissingEtCollHandle::rerandomise()
366//{
367// messageVerbose("MissingEtCollHandle::rerandomise()");
368//
369// if (!isLoaded()) {
370// messageVerbose("MissingEtCollHandle::rerandomise() - Returning.");
371// return;
372// }
373// if (!isRandomColors()) {
374// VP1Msg::message("'Random jet colours' is not checked. Nothing to do. Returning.");
375// return;
376// }
377//
378// largeChangesBegin();
379// for(AODHandleBase* partHandle : m_d->handles) {
380// MissingEtCollHandle* jet = dynamic_cast<MissingEtCollHandle*>(partHandle);
381// if (jet->has3DObjects())
382// jet->rerandomiseMaterial();
383// }
384// largeChangesEnd();
385//}
386
387
388
389
390
391
392
393//____________________________________________________________________
395{
396 messageVerbose("loading MissingEt collection");
397
398 //Get collection:
399 const xAOD::MissingETContainer * coll(nullptr);
400
401 #if defined BUILDVP1LIGHT
402 // Retrieve objects from the event
403 if( !(systemBase()->getEvent())->retrieve( coll, name().toStdString()).isSuccess() ) {
404 QString errMsg = "Failed to retrieve " + name();
405 message("Error: Could not retrieve collection with key="+name());
406 return false;
407 }
408 #else
409 if (!VP1SGAccessHelper(systemBase()).retrieve(coll, name())) {
410 message("Error: Could not retrieve MET collection with key="+name());
411 return false;
412 }
413 #endif // BUILDVP1LIGHT
414
415 // // Retrieve the xAOD particles:
416 // const xAOD::MissingETContainer* xaod = evtStore()->retrieve<const xAOD::MissingETContainer>( m_JetCollection );
417
418 // Check that the auxiliary store association was made successfully:
419 if( ! coll->hasStore() ) {
420 message("No auxiliary store got associated to the MET container with key: " +name());
421 }
422
423 // This is needed for now, until the issues around the DV code are
424 // sorted out...
425 const_cast< xAOD::MissingETContainer* >( coll )->setStore(
426 ( SG::IAuxStore* ) coll->getConstStore() );
427
428 //Make appropriate Jet handles:
429 // hintNumberOfTracksInEvent(coll->size());
431 for ( it = coll->begin() ; it != itEnd; ++it) {
432 m_d->possiblyUpdateGUI();
433 if (!*it) {
434 messageDebug("WARNING: Ignoring null MET pointer.");
435 continue;
436 }
437 /*
438 if ((*it)->charge()==0.0) {
439 messageDebug("WARNING: Ignoring Jet which claims to be neutral (charge()==0.0).");
440 continue;
441 }
442 */
443 addHandle(new MissingEtHandle(this,*it));
444 }
445
446 return true;
447}
448
449
450
451//Cuts:
452//____________________________________________________________________
454 messageVerbose("MissingEtCollHandle::cut()");
455
456 if (MissingEtHandle* handle = dynamic_cast<MissingEtHandle*>(c))
457 {
458
459 // //------ ENERGY CUTS
460 // messageVerbose("jet's energy, allowedPt^2, PtAll: - " + QString::number(handle->energyForCuts()) + " - " + getCutAllowedPt().toString() + " - " + QString::number(int(getPtAllowall())) );
461 // double jEnergy = handle->energyForCuts();
462 // double jEnergySqr = jEnergy * jEnergy; // in AODCollHandleBase the allowedPt is stored as squared, to avoid square-root operations
463 // if (!getPtAllowall() && !getCutAllowedPt().contains(jEnergySqr) ) {
464 // messageVerbose("Pt cut not passed");
465 // return false;
466 // }
467 //
468 // //------ ETA CUTS
469 // messageVerbose("jet's eta, etaCut, EtaAll: " + QString::number(handle->eta()) + " - " + getCutAllowedEta().toString() + " - " + QString::number(int(getEtaAllowall())) );
470 // if (!getEtaAllowall() && !getCutAllowedEta().contains(handle->eta())) {
471 // messageVerbose("Eta cut not passed");
472 // return false;
473 // }
474 //
475 //------ PHI CUTS
476 if (!getPhiAllowall() ) {
477 double phi = handle->phi();
478 bool ok(false);
479 for (const VP1Interval& phirange : getCutAllowedPhi() ) {
480 messageVerbose("MET phi, phiCut, PhiAll: " + QString::number(phi) + " - " + phirange.toString() + " - " + QString::number(int(getPhiAllowall())) );
481 if (phirange.contains(phi)||phirange.contains(phi+2*M_PI)||phirange.contains(phi-2*M_PI)) {
482 ok = true;
483 break;
484 }
485 }
486 if (!ok) {
487 messageVerbose("Phi cut not passed");
488 return false;
489 }
490 }
491
492
493 } // if(dynamic_cast)
494 else{
495 messageVerbose("Not a MissingEtCollHandle. Check your code! Returning 'false'...");
496// if (! AODCollHandleBase::cut(c)) // AODCollHandleBase::cut is pure virtual, now
497 return false;
498 }
499
500 return true; //default
501
502}
503
504
505
507//void MissingEtCollHandle::showParametersChanged(bool val) {
508// messageVerbose("MissingEtCollHandle::showParametersChanged to "+str(val));
509// update3DObjectsOfAllHandles();
510//}
511
512
513//____________________________________________________________________
514void MissingEtCollHandle::setCutAllowedPhi(const QList<VP1Interval>& allowedPhi)
515{
516 VP1Msg::messageVerbose("MissingEtCollHandle::setCutAllowedPhi() - signal received in setCutAllowedPhi.");
517
518 if (m_cut_allowedPhi==allowedPhi)
519 return;
520
521 m_cut_allowedPhi = allowedPhi;
522
523 m_cut_phi_allowall = m_cut_allowedPhi.count()==1 && m_cut_allowedPhi.at(0).isAllR();
524 m_cut_phi_allwillfail = m_cut_allowedPhi.isEmpty(); // || m_cut_allowedPtSq.isEmpty() || m_cut_allowedEta.isEmpty();
525
526 if (m_cut_phi_allowall) {
528 return;
529 }
532 return;
533 }
534
535 // Test: is the current interval larger than the previous one?
536 //bool relaxcut = allowedPhi.contains(m_cut_allowedPhi); // TODO: implement this 'contains' function
537 // Store the current interval
538// m_cut_allowedPhi = allowedPhi;
539
540// if (relaxcut)
541// recheckCutStatusOfAllNotVisibleHandles();
542// else
543// recheckCutStatusOfAllVisibleHandles();
544
546 recheckCutStatusOfAllNotVisibleHandles(); // Redundant, but needed! TODO: remove this when new 'contains' is ready
547
548 return;
549}
550
551//____________________________________________________________________
553{
554 messageDebug("MissingEtCollHandle::persistifiableState() - start...");
555
556 // if (!m_d->matButton) {
557 // message("ERROR: persistifiableState() called before init()");
558 // return QByteArray();
559 // }
560
561
562 VP1Serialise serialise(1/*version*/);
563
564 // settings
565 serialise.disableUnsavedChecks();
566
567 // SAVE THE CHECKED/UNCHECKED STATUS OF THE COLLECTION
568 serialise.save(visible());
569
570 // SAVE THE MATERIAL BUTTON
571 //Q_ASSERT(m_d->matButton&&"Did you forget to call init() on this VP1StdCollection?");
572 //serialise.save(m_d->matButton->saveState());
573
574 // SAVE THE EXTRA-STATES
575 serialise.save(extraWidgetsState());//version 1+
576
577 // SAVE MATERIAL SETTINGS / CUTS
578 serialise.save(m_d->collSettingsButton->saveState());
579
580 messageDebug("MissingEtCollHandle::persistifiableState() - end.");
581 return serialise.result();
582}
583
584//____________________________________________________________________
585void MissingEtCollHandle::setState(const QByteArray&state)
586{
587 messageDebug("MissingEtCollHandle::setState()");
588
589 VP1Deserialise des(state);
591 if (des.version()!=0&&des.version()!=1) {
592 messageDebug("Warning: Ignoring state with wrong version");
593 return;
594 }
595
596 // save state
597
598 bool vis = des.restoreBool();
599
600 // QByteArray matState = des.restoreByteArray();
601 // m_d->matButton->restoreFromState(matState);
602 QByteArray extraWidgetState = des.version()>=1 ? des.restoreByteArray() : QByteArray();
603 setVisible(vis);
604
605 if (extraWidgetState!=QByteArray())
606 setExtraWidgetsState(extraWidgetState);
607
608 // MATERIAL SETTINGS / CUTS
609 messageDebug("restoring material collection button...");
610 des.restore(m_d->collSettingsButton);
611
612 messageDebug("reset all caches storing values for cuts...");
614
615 messageDebug("recheck all handles...");
617
618}
#define M_PI
Scalar phi() const
phi method
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.
QList< AODHandleBase * > handlesList
std::vector< MissingEtHandle * >::iterator itHandlesEnd
std::vector< MissingEtHandle * >::iterator itHandles
MissingEtCollHandle * theclass
std::vector< MissingEtHandle * > handles
MissingEtCollectionSettingsButton * collSettingsButton
const QList< VP1Interval > & getCutAllowedPhi()
MissingEtCollHandle(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType type)
void addHandle(AODHandleBase *)
virtual void init(VP1MaterialButtonBase *matBut=0)
const MissingEtCollectionSettingsButton & collSettingsButton() const
virtual bool cut(AODHandleBase *)
void setState(const QByteArray &)
Provide specific implementation.
QByteArray persistifiableState() const
Provide specific implementation.
static QStringList availableCollections(IVP1System *)
virtual AODHandleBase * getNextHandle()
void setCutAllowedPhi(const QList< VP1Interval > &)
virtual void handleIterationBegin()
QList< VP1Interval > m_cut_allowedPhi
QList< AODHandleBase * > getHandlesList() const
virtual void hintNumberOfHandlesInEvent(unsigned)
virtual void setupSettingsFromControllerSpecific(const AODSystemController *)
For extensions specific to this collection.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
QByteArray restoreByteArray()
void disableUnrestoredChecks()
void restore(QCheckBox *sb)
qint32 version() const
void messageVerbose(const QString &) const
void message(const QString &) const
IVP1System * systemBase() const
void messageDebug(const QString &) const
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
QStringList getKeys() const
virtual void init(VP1MaterialButtonBase *button=0)
void visibilityChanged(bool)
QString text() const
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Other
An object not falling into any of the other categories.
Definition ObjectType.h:34