ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleCollHandle_Muon.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 IParticleCollHandle_Muon //
9// //
10// //
12
13//Local
17#include "AODSysCommonData.h"
18
19//xAOD
21#include "xAODMuon/Muon.h"
22
23//VP1
24#include "VP1Base/IVP1System.h"
25#ifndef BUILDVP1LIGHT
28#endif // BUILDVP1LIGHT
29
30//Qt
31#include <QStringList>
32
33// SoCoin
34#include <Inventor/C/errors/debugerror.h>
35#include <Inventor/nodes/SoSeparator.h>
36#include <Inventor/nodes/SoSwitch.h>
37#include <Inventor/nodes/SoMaterial.h>
38#include "Inventor/nodes/SoDrawStyle.h"
39#include "Inventor/nodes/SoLightModel.h"
40
41#ifdef BUILDVP1LIGHT
42 #include <QSettings>
43 #include "xAODRootAccess/Init.h"
45#endif // BUILDVP1LIGHT
46
47//____________________________________________________________________
48#if defined BUILDVP1LIGHT
50 {
51 return sys->getObjectList(xAOD::Type::Muon);
52 }
53#else
58#endif // BUILDVP1LIGHT
59
60//____________________________________________________________________
62public:
66
67 unsigned int last_minimumQuality;
69
70 void possiblyUpdateGUI() {//Fixme: to IParticleCollHandleBase
71 if (!((updateGUICounter++)%50)) {
72 theclass->systemBase()->updateGUI();
73 }
74 }
75};
76
77//____________________________________________________________________
79 const QString& name, xAOD::Type::ObjectType type)
81{
82 m_d->theclass = this;
83 m_d->updateGUICounter = 0;
84 m_d->collSettingsButton = 0;
85 m_d->last_minimumQuality = 0;
86 m_d->hasPrimaryTrackParticleInfo = false;
87
88 //The object names should not contain all sorts of funky chars (mat button style sheets wont work for instance):
89 QString safetext(text());
90 safetext.replace(' ','_');
91 safetext.replace('[','_');
92 safetext.replace(']','_');
93 safetext.replace('/','_');
94 safetext.replace('.','_');
95 safetext.replace(',','_');
96 safetext.replace('<','_');
97 safetext.replace('>','_');
98 safetext.replace('&','_');
99
100 // SoMaterial* mat
101 // = m_d->collSettingsButton->defaultParameterMaterial();
102 // mat->setName(("IParticleCollHandle_Muon"+safetext).toStdString().c_str()); // Useful for debugging
103 // m_d->collSettingsButton->setDefaultParameterMaterial(m_d->defaultParametersMaterial); FIXME
104}
105
106//____________________________________________________________________
111
112//____________________________________________________________________
114{
115 // std::cout<<"IParticleCollHandle_Muon::init 1"<<std::endl;
116 m_d->collSettingsButton = new MuonCollectionSettingsButton;
117 m_d->collSettingsButton->setMaterialText(name());
118 // std::cout<<"Calling VP1StdCollection::init with m_d->collSettingsButton (MuonCollectionSettingsButton)="<<m_d->collSettingsButton<<std::endl;
119 VP1StdCollection::init(m_d->collSettingsButton);//this call is required. Passing in m_d->collSettingsButton means we have the more complex button.
120 setupSettingsFromController(common()->controller());
121 connect(this,SIGNAL(visibilityChanged(bool)),this,SLOT(collVisibilityChanged(bool)));
122
123 // Connections back to system
124 connect(this,SIGNAL(shownAssociatedObjectsChanged(const QList<const xAOD::TrackParticle*>&)),systemBase(),SLOT(updateAssociatedObjects(const QList<const xAOD::TrackParticle*>&))) ;
125
126 // std::cout<<"IParticleCollHandle_Muon::init 2"<<std::endl; // debug
127 // std::cout<<"swi: "<<collSwitch()<<std::endl;
128 // std::cout<<"sep: "<<collSep()<<std::endl;
129 // std::cout<<"mat: "<<material()<<std::endl;
130
131 collSwitch()->addChild(m_d->collSettingsButton->trackLightModel());
132 collSwitch()->addChild(m_d->collSettingsButton->trackDrawStyle());
133}
134
136 //cuts
137 connect(m_d->collSettingsButton,SIGNAL(cutAllowedPtChanged(const VP1Interval&)),this,SLOT(setCutAllowedPt(const VP1Interval&)));
138 setCutAllowedPt(m_d->collSettingsButton->cutAllowedPt());
139 //
140
141 connect(m_d->collSettingsButton,SIGNAL(cutAllowedEtaChanged(const VP1Interval&)),this,SLOT(setCutAllowedEta(const VP1Interval&)));
142 setCutAllowedEta(m_d->collSettingsButton->cutAllowedEta());
143 //
144
145 connect(m_d->collSettingsButton,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(setCutAllowedPhi(const QList<VP1Interval>&)));
146 setCutAllowedPhi(m_d->collSettingsButton->cutAllowedPhi());
147
148 connect(m_d->collSettingsButton,SIGNAL(minimumQualityChanged(unsigned int)),this,SLOT(setMinimumQuality(unsigned int)));
149 setMinimumQuality(m_d->collSettingsButton->minimumQuality());
150
151 connect(m_d->collSettingsButton,SIGNAL(shownAssociatedObjectsChanged(MuonCollectionSettingsButton::ShownAssociatedObjects)),this,SLOT(updateShownAssociatedObjects()));
152}
153
154
156{
157 // TODO: it is not used so far! Check Other collections and update accordingly
158
159 // kinetic cuts
160 setCutAllowedPt(m_d->collSettingsButton->cutAllowedPt());
161 setCutAllowedEta(m_d->collSettingsButton->cutAllowedEta());
162 setCutAllowedPhi(m_d->collSettingsButton->cutAllowedPhi());
163 // other settings
164 setMinimumQuality(m_d->collSettingsButton->minimumQuality());
165
166 // TODO: adding "shownAssociatedObjectsChanged" settings as well??
167}
168
169
170
172 if (!m_d->collSettingsButton){
173 messageVerbose("No collSettingsButton set! Can't call init(), so crash is imminent...");
174 throw std::runtime_error("Muon - No collSettingsButton set!");
175 }
176 return *m_d->collSettingsButton;
177}
178
179//____________________________________________________________________
181{
182 messageVerbose("loading Muon collection");
183
184 //Get collection:
185 const xAOD::MuonContainer * coll(nullptr);
186
187 #if defined BUILDVP1LIGHT
188 // Retrieve objects from the event
189 if( !(systemBase()->getEvent())->retrieve( coll, name().toStdString()).isSuccess() ) {
190 message("Error: Could not retrieve collection with key="+name());
191 return false;
192 }
193 #else
194 if (!VP1SGAccessHelper(systemBase()).retrieve(coll, name())) {
195 message("Error: Could not retrieve Muon collection with key="+name());
196 return false;
197 }
198 #endif // BUILDVP1LIGHT
199
200 // // Retrieve the xAOD particles:
201 // const xAOD::MuonContainer* xaod = evtStore()->retrieve<const xAOD::MuonContainer>( m_MuonCollection );
202
203 // Check that the auxiliary store association was made successfully:
204 if( ! coll->hasStore() ) {
205 message("No auxiliary store got associated to the Muon container with key: " +name());
206 }
207
208 // This is needed for now, until the issues around the DV code are
209 // sorted out...
210 const_cast< xAOD::MuonContainer* >( coll )->setStore(
211 ( SG::IAuxStore* ) coll->getConstStore() );
212
213 QList<const xAOD::TrackParticle*> listOfTrackParticles;
214 //Make appropriate trk::track handles:
215 // hintNumberOfTracksInEvent(coll->size());
216 xAOD::MuonContainer::const_iterator it, itEnd = coll->end();
217 for ( it = coll->begin() ; it != itEnd; ++it) {
218 m_d->possiblyUpdateGUI();
219 if (!*it) {
220 messageDebug("WARNING: Ignoring null Muon pointer.");
221 continue;
222 }
223 // if ((*it)->primaryTrackParticle()->charge()==0.0) {
224 // messageDebug("WARNING: Ignoring Muon which claims to be neutral (charge()==0.0).");
225 // continue;
226 // }
227 IParticleHandle_Muon* muonH = new IParticleHandle_Muon(this,*it);
228 addHandle(muonH );
229 //std::cout << "muons ---> " << muonH->muon().eta() // debug
230 // << ", " << muonH->muon().primaryTrackParticle() << std::endl;
231 if( muonH->muon().primaryTrackParticle() ) {
232 m_d->hasPrimaryTrackParticleInfo = true;
233 listOfTrackParticles << muonH->muon().primaryTrackParticle();
234 } else {
235 m_d->hasPrimaryTrackParticleInfo = false;
237 }
238 }
239 if(listOfTrackParticles.size()>0) {
240 emit shownAssociatedObjectsChanged(listOfTrackParticles);
241 }
242 return true;
243}
244
245
246//____________________________________________________________________
248{
249 QString msg = "SEVERE WARNING! No 'primaryTrackParticle' information found within the Muons collection of the input file! As a consequence, several quantities cannot be calculated. Also, expect crashes... Please, check the data contained in your input data file.";
252 return;
253}
255{
256 return m_d->hasPrimaryTrackParticleInfo;
257}
258
259//____________________________________________________________________
261{
262
263 if (!IParticleCollHandleBase::cut(handle))
264 return false;
265
266 IParticleHandle_Muon * muon = dynamic_cast<IParticleHandle_Muon*>(handle);
267 if (not muon) return false;
268 std::cout<<"muon: "<<muon<<"\t muon->quality()="<<muon->quality()<<" collSettingsButton().minimumQuality()="<<collSettingsButton().minimumQuality()<<std::endl;
269 if (static_cast<unsigned int>(muon->quality()) > collSettingsButton().minimumQuality() )
270 return false;
271 //Fixme: more? Or just use base class method and remove this?
272
273 return true;
274}
275
277 if (quality == m_d->last_minimumQuality)
278 return;
279 std::cout<<"IParticleCollHandle_Muon::setMinimumQuality : "<<quality<<" last = "<<m_d->last_minimumQuality<<std::endl;
280 bool relaxcut = quality > m_d->last_minimumQuality;
281 m_d->last_minimumQuality = quality;
282
283 if (relaxcut)
285 else
287
288 // If we shift this to the base class, then we can probably put it into one of the check methods
290}
291
293{
294 QList<const xAOD::TrackParticle*> listOfTrackParticles;
295 MuonCollectionSettingsButton::ShownAssociatedObjects so = collSettingsButton().shownAssociatedObjects();
296
298 AODHandleBase * handle;
299 while ( (handle = getNextHandle() ) ) {
300 if (handle->visible()){
301 IParticleHandle_Muon* mhandle = dynamic_cast<IParticleHandle_Muon*>(handle);
302 if (mhandle && so) {
303 // Only add if bit set, and if link!=0;
304 if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesPrimary) && mhandle->muon().trackParticle( xAOD::Muon::Primary) )
305 listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::Primary);
306 if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesCB) && mhandle->muon().trackParticle( xAOD::Muon::CombinedTrackParticle) )
307 listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::CombinedTrackParticle);
308 if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesID) && mhandle->muon().trackParticle( xAOD::Muon::InnerDetectorTrackParticle) )
309 listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::InnerDetectorTrackParticle);
310 if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesMS) && mhandle->muon().trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle) )
311 listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle);
312 if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesME) && mhandle->muon().trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle) )
313 listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
314 }
315 }
316 }
317 std::cout<<"IParticleCollHandle_Muon::updateAssociatedTrackParticles Emitting "<<listOfTrackParticles.size()<<" track particles."<<std::endl;
318 emit shownAssociatedObjectsChanged(listOfTrackParticles);
319}
320
322{
323 std::cout<<"IParticleCollHandle_Muon::setShownAssociatedObjects : "<<std::endl;
325}
326
327
328
const AODSysCommonData * common() const
void recheckCutStatusOfAllNotVisibleHandles()
void recheckCutStatusOfAllVisibleHandles()
void setupSettingsFromController(const AODSystemController *)
const QString & name() const
bool visible() 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.
IParticleCollHandleBase(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType)
virtual AODHandleBase * getNextHandle()
void setCutAllowedPt(const VP1Interval &)
virtual bool cut(AODHandleBase *)
void setCutAllowedPhi(const QList< VP1Interval > &)
void setCutAllowedEta(const VP1Interval &)
MuonCollectionSettingsButton * collSettingsButton
virtual bool cut(AODHandleBase *)
virtual void setupSettingsFromControllerSpecific(const AODSystemController *)
For extensions specific to this collection.
void shownAssociatedObjectsChanged(const QList< const xAOD::TrackParticle * > &)
const MuonCollectionSettingsButton & collSettingsButton() const
IParticleCollHandle_Muon(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType type)
static QStringList availableCollections(IVP1System *)
virtual void init(VP1MaterialButtonBase *matBut=0)
const xAOD::Muon & muon() const
void message(const QString &) const
ShownAssociatedObjects shownAssociatedObjects() const
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
void messageVerbose(const QString &) const
void message(const QString &) const
IVP1System * systemBase() const
void messageDebug(const QString &) const
static void messageWarningAllRed(const QString &str, IVP1System *sys=0)
Definition VP1Msg.cxx:70
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
const TrackParticle * primaryTrackParticle() const
Returns a pointer (which should not usually be NULL, but might be if the muon has been stripped of in...
Definition Muon_v1.cxx:396
const TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be NULL) to the TrackParticle used in identification of this muon.
Definition Muon_v1.cxx:482
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Muon
The object is a muon.
Definition ObjectType.h:48
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
MsgStream & msg
Definition testRead.cxx:32