ATLAS Offline Software
IParticleCollHandle_Muon.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class IParticleCollHandle_Muon //
9 // //
10 // //
12 
13 //Local
15 #include "IParticleHandle_Muon.h"
17 #include "AODSysCommonData.h"
18 
19 //xAOD
20 #include "xAODMuon/MuonContainer.h"
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"
44  #include "xAODRootAccess/TEvent.h"
45 #endif // BUILDVP1LIGHT
46 
47 //____________________________________________________________________
48 #if defined BUILDVP1LIGHT
50  {
51  return sys->getObjectList(xAOD::Type::Muon);
52  }
53 #else
55  {
57  }
58 #endif // BUILDVP1LIGHT
59 
60 //____________________________________________________________________
62 public:
66 
67  unsigned int last_minimumQuality;
69 
70  void possiblyUpdateGUI() {//Fixme: to IParticleCollHandleBase
71  if (!((updateGUICounter++)%50)) {
73  }
74  }
75 };
76 
77 //____________________________________________________________________
79  const QString& name, xAOD::Type::ObjectType type)
81 {
82  m_d->theclass = this;
83  m_d->updateGUICounter = 0;
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 //____________________________________________________________________
108 {
109  delete m_d;
110 }
111 
112 //____________________________________________________________________
114 {
115  // std::cout<<"IParticleCollHandle_Muon::init 1"<<std::endl;
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 
133 }
134 
136  //cuts
137  connect(m_d->collSettingsButton,SIGNAL(cutAllowedPtChanged(const VP1Interval&)),this,SLOT(setCutAllowedPt(const VP1Interval&)));
139  //
140 
141  connect(m_d->collSettingsButton,SIGNAL(cutAllowedEtaChanged(const VP1Interval&)),this,SLOT(setCutAllowedEta(const VP1Interval&)));
143  //
144 
145  connect(m_d->collSettingsButton,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(setCutAllowedPhi(const QList<VP1Interval>&)));
147 
148  connect(m_d->collSettingsButton,SIGNAL(minimumQualityChanged(unsigned int)),this,SLOT(setMinimumQuality(unsigned int)));
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
163  // other settings
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  }
175  return *m_d->collSettingsButton;
176 }
177 
178 //____________________________________________________________________
180 {
181  messageVerbose("loading Muon collection");
182 
183  //Get collection:
184  const xAOD::MuonContainer * coll(nullptr);
185 
186  #if defined BUILDVP1LIGHT
187  // Retrieve objects from the event
188  if( !(systemBase()->getEvent())->retrieve( coll, name().toStdString()).isSuccess() ) {
189  message("Error: Could not retrieve collection with key="+name());
190  return false;
191  }
192  #else
193  if (!VP1SGAccessHelper(systemBase()).retrieve(coll, name())) {
194  message("Error: Could not retrieve Muon collection with key="+name());
195  return false;
196  }
197  #endif // BUILDVP1LIGHT
198 
199  // // Retrieve the xAOD particles:
200  // const xAOD::MuonContainer* xaod = evtStore()->retrieve<const xAOD::MuonContainer>( m_MuonCollection );
201 
202  // Check that the auxiliary store association was made successfully:
203  if( ! coll->hasStore() ) {
204  message("No auxiliary store got associated to the Muon container with key: " +name());
205  }
206 
207  // This is needed for now, until the issues around the DV code are
208  // sorted out...
209  const_cast< xAOD::MuonContainer* >( coll )->setStore(
210  ( SG::IAuxStore* ) coll->getConstStore() );
211 
212  QList<const xAOD::TrackParticle*> listOfTrackParticles;
213  //Make appropriate trk::track handles:
214  // hintNumberOfTracksInEvent(coll->size());
215  xAOD::MuonContainer::const_iterator it, itEnd = coll->end();
216  for ( it = coll->begin() ; it != itEnd; ++it) {
218  if (!*it) {
219  messageDebug("WARNING: Ignoring null Muon pointer.");
220  continue;
221  }
222  // if ((*it)->primaryTrackParticle()->charge()==0.0) {
223  // messageDebug("WARNING: Ignoring Muon which claims to be neutral (charge()==0.0).");
224  // continue;
225  // }
226  IParticleHandle_Muon* muonH = new IParticleHandle_Muon(this,*it);
227  addHandle(muonH );
228  //std::cout << "muons ---> " << muonH->muon().eta() // debug
229  // << ", " << muonH->muon().primaryTrackParticle() << std::endl;
230  if( muonH->muon().primaryTrackParticle() ) {
232  listOfTrackParticles << muonH->muon().primaryTrackParticle();
233  } else {
236  }
237  }
238  if(listOfTrackParticles.size()>0) {
239  emit shownAssociatedObjectsChanged(listOfTrackParticles);
240  }
241  return true;
242 }
243 
244 
245 //____________________________________________________________________
247 {
248  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.";
250  systemBase()->message(msg);
251  return;
252 }
254 {
256 }
257 
258 //____________________________________________________________________
260 {
261 
262  if (!IParticleCollHandleBase::cut(handle))
263  return false;
264 
265  IParticleHandle_Muon * muon = dynamic_cast<IParticleHandle_Muon*>(handle);
266  if (not muon) return false;
267  std::cout<<"muon: "<<muon<<"\t muon->quality()="<<muon->quality()<<" collSettingsButton().minimumQuality()="<<collSettingsButton().minimumQuality()<<std::endl;
268  if (static_cast<unsigned int>(muon->quality()) > collSettingsButton().minimumQuality() )
269  return false;
270  //Fixme: more? Or just use base class method and remove this?
271 
272  return true;
273 }
274 
276  if (quality == m_d->last_minimumQuality)
277  return;
278  std::cout<<"IParticleCollHandle_Muon::setMinimumQuality : "<<quality<<" last = "<<m_d->last_minimumQuality<<std::endl;
279  bool relaxcut = quality > m_d->last_minimumQuality;
280  m_d->last_minimumQuality = quality;
281 
282  if (relaxcut)
284  else
286 
287  // If we shift this to the base class, then we can probably put it into one of the check methods
289 }
290 
292 {
293  QList<const xAOD::TrackParticle*> listOfTrackParticles;
294  MuonCollectionSettingsButton::ShownAssociatedObjects so = collSettingsButton().shownAssociatedObjects();
295 
297  AODHandleBase * handle;
298  while ( (handle = getNextHandle() ) ) {
299  if (handle->visible()){
300  IParticleHandle_Muon* mhandle = dynamic_cast<IParticleHandle_Muon*>(handle);
301  if (mhandle && so) {
302  // Only add if bit set, and if link!=0;
304  listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::Primary);
305  if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesCB) && mhandle->muon().trackParticle( xAOD::Muon::CombinedTrackParticle) )
306  listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::CombinedTrackParticle);
307  if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesID) && mhandle->muon().trackParticle( xAOD::Muon::InnerDetectorTrackParticle) )
308  listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::InnerDetectorTrackParticle);
309  if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesMS) && mhandle->muon().trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle) )
310  listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle);
311  if (so.testFlag(MuonCollectionSettingsButton::TrackParticlesME) && mhandle->muon().trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle) )
312  listOfTrackParticles<<mhandle->muon().trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
313  }
314  }
315  }
316  std::cout<<"IParticleCollHandle_Muon::updateAssociatedTrackParticles Emitting "<<listOfTrackParticles.size()<<" track particles."<<std::endl;
317  emit shownAssociatedObjectsChanged(listOfTrackParticles);
318 }
319 
321 {
322  std::cout<<"IParticleCollHandle_Muon::setShownAssociatedObjects : "<<std::endl;
324 }
325 
326 
327 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AODHandleBase::visible
bool visible() const
Definition: AODHandleBase.h:54
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
IParticleCollHandle_Muon::cut
virtual bool cut(AODHandleBase *)
Definition: IParticleCollHandle_Muon.cxx:259
MuonCollectionSettingsButton::TrackParticlesCB
@ TrackParticlesCB
Definition: MuonCollectionSettingsButton.h:58
AODHandleBase
Definition: AODHandleBase.h:43
MuonCollectionSettingsButton::setMaterialText
void setMaterialText(const QString &)
Definition: MuonCollectionSettingsButton.cxx:84
xAOD::Muon_v1::trackParticle
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:486
IParticleCollHandle_Muon::collSettingsButton
const MuonCollectionSettingsButton & collSettingsButton() const
Definition: IParticleCollHandle_Muon.cxx:171
ObjectType
ObjectType
Definition: BaseObject.h:11
AODSysCommonData
Definition: AODSysCommonData.h:42
IParticleCollHandle_Muon::m_d
Imp * m_d
Definition: IParticleCollHandle_Muon.h:64
Muon.h
IParticleCollHandle_Muon::Imp::theclass
IParticleCollHandle_Muon * theclass
Definition: IParticleCollHandle_Muon.cxx:63
IParticleCollHandle_Muon::Imp::last_minimumQuality
unsigned int last_minimumQuality
Definition: IParticleCollHandle_Muon.cxx:67
MuonCollectionSettingsButton::cutAllowedPhi
QList< VP1Interval > cutAllowedPhi() const
Definition: MuonCollectionSettingsButton.cxx:495
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
VP1StdCollection::collSwitch
SoSwitch * collSwitch() const
Add this somewhere in your scenegraph (do not add any children here!)
Definition: VP1StdCollection.cxx:204
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1StdCollection::init
virtual void init(VP1MaterialButtonBase *button=0)
Definition: VP1StdCollection.cxx:73
IParticleCollHandle_Muon.h
VP1Msg::messageWarningAllRed
static void messageWarningAllRed(const QString &str, IVP1System *sys=0)
Definition: VP1Msg.cxx:70
IParticleCollHandle_Muon::Imp::possiblyUpdateGUI
void possiblyUpdateGUI()
Definition: IParticleCollHandle_Muon.cxx:70
IParticleCollHandle_Muon::setupSettingsFromControllerSpecific
virtual void setupSettingsFromControllerSpecific(const AODSystemController *)
For extensions specific to this collection.
Definition: IParticleCollHandle_Muon.cxx:135
IParticleCollHandle_Muon::Imp
Definition: IParticleCollHandle_Muon.cxx:61
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
IParticleCollHandleBase::setCutAllowedPt
void setCutAllowedPt(const VP1Interval &)
Definition: IParticleCollHandleBase.cxx:218
IParticleCollHandle_Muon::setMinimumQuality
void setMinimumQuality(unsigned int)
Definition: IParticleCollHandle_Muon.cxx:275
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
IParticleCollHandleBase::setCutAllowedPhi
void setCutAllowedPhi(const QList< VP1Interval > &)
Definition: IParticleCollHandleBase.cxx:284
AODCollHandleBase::common
const AODSysCommonData * common() const
Definition: AODCollHandleBase.h:88
IParticleCollHandle_Muon::Imp::updateGUICounter
int updateGUICounter
Definition: IParticleCollHandle_Muon.cxx:64
VP1SGContentsHelper::getKeys
QStringList getKeys() const
Definition: VP1SGContentsHelper.h:55
MuonCollectionSettingsButton::minimumQuality
unsigned int minimumQuality() const
Definition: MuonCollectionSettingsButton.cxx:295
InDet::ExclusiveOrigin::Primary
@ Primary
Definition: InDetTrackTruthOriginDefs.h:163
IParticleCollHandle_Muon::load
virtual bool load()
Definition: IParticleCollHandle_Muon.cxx:179
IParticleCollHandle_Muon::Imp::collSettingsButton
MuonCollectionSettingsButton * collSettingsButton
Definition: IParticleCollHandle_Muon.cxx:65
IVP1System
Definition: IVP1System.h:36
MuonCollectionSettingsButton::TrackParticlesME
@ TrackParticlesME
Definition: MuonCollectionSettingsButton.h:61
MuonCollectionSettingsButton::TrackParticlesID
@ TrackParticlesID
Definition: MuonCollectionSettingsButton.h:59
AODSystemController
Definition: AODSystemController.h:43
IParticleCollHandle_Muon::printMsgNoTrackParticle
void printMsgNoTrackParticle()
Definition: IParticleCollHandle_Muon.cxx:246
VP1StdCollection::visibilityChanged
void visibilityChanged(bool)
TEvent.h
IParticleCollHandle_Muon::~IParticleCollHandle_Muon
virtual ~IParticleCollHandle_Muon()
Definition: IParticleCollHandle_Muon.cxx:107
IParticleHandle_Muon::muon
const xAOD::Muon & muon() const
Definition: IParticleHandle_Muon.cxx:477
AODCollHandleBase::recheckCutStatusOfAllNotVisibleHandles
void recheckCutStatusOfAllNotVisibleHandles()
Definition: AODCollHandleBase.cxx:177
Init.h
VP1StdCollection::text
QString text() const
Definition: VP1StdCollection.cxx:132
IParticleCollHandle_Muon::updateAssociatedTrackParticles
void updateAssociatedTrackParticles()
Definition: IParticleCollHandle_Muon.cxx:291
IParticleCollHandleBase::cut
virtual bool cut(AODHandleBase *)
Definition: IParticleCollHandleBase.cxx:146
IParticleCollHandleBase::setCutAllowedEta
void setCutAllowedEta(const VP1Interval &)
Definition: IParticleCollHandleBase.cxx:259
MuonCollectionSettingsButton::TrackParticlesPrimary
@ TrackParticlesPrimary
Definition: MuonCollectionSettingsButton.h:57
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AODSysCommonData.h
IParticleHandle_Muon
Definition: IParticleHandle_Muon.h:22
AODCollHandleBase::setupSettingsFromController
void setupSettingsFromController(const AODSystemController *)
Definition: AODCollHandleBase.cxx:112
VP1HelperClassBase::systemBase
IVP1System * systemBase() const
Definition: VP1HelperClassBase.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
VP1SGContentsHelper
Definition: VP1SGContentsHelper.h:26
VP1MaterialButtonBase
Definition: VP1MaterialButton.h:25
MuonContainer.h
Muon
struct TBPatternUnitContext Muon
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
IParticleCollHandleBase::handleIterationBegin
virtual void handleIterationBegin()
Definition: IParticleCollHandleBase.cxx:123
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
AODCollHandleBase::collVisibilityChanged
void collVisibilityChanged(bool)
Definition: AODCollHandleBase.cxx:393
IParticleCollHandle_Muon::hasPrimaryTrackParticleInfo
bool hasPrimaryTrackParticleInfo()
Definition: IParticleCollHandle_Muon.cxx:253
VP1Interval
Definition: VP1Interval.h:23
IParticleCollHandle_Muon::init
virtual void init(VP1MaterialButtonBase *matBut=0)
Definition: IParticleCollHandle_Muon.cxx:113
MuonCollectionSettingsButton
Definition: MuonCollectionSettingsButton.h:16
IVP1System::updateGUI
void updateGUI()
Definition: IVP1System.cxx:262
IParticleCollHandle_Muon::Imp::hasPrimaryTrackParticleInfo
bool hasPrimaryTrackParticleInfo
Definition: IParticleCollHandle_Muon.cxx:68
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IParticleCollHandle_Muon::resetCachedValuesCuts
void resetCachedValuesCuts()
Definition: IParticleCollHandle_Muon.cxx:155
IParticleCollHandleBase::getNextHandle
virtual AODHandleBase * getNextHandle()
Definition: IParticleCollHandleBase.cxx:130
IParticleCollHandle_Muon::shownAssociatedObjectsChanged
void shownAssociatedObjectsChanged(const QList< const xAOD::TrackParticle * > &)
MuonCollectionSettingsButton::shownAssociatedObjects
ShownAssociatedObjects shownAssociatedObjects() const
Definition: MuonCollectionSettingsButton.cxx:310
IParticleCollHandleBase::addHandle
void addHandle(AODHandleBase *)
Definition: IParticleCollHandleBase.cxx:111
IParticleCollHandle_Muon::availableCollections
static QStringList availableCollections(IVP1System *)
Definition: IParticleCollHandle_Muon.cxx:54
MuonCollectionSettingsButton::cutAllowedEta
VP1Interval cutAllowedEta() const
Definition: MuonCollectionSettingsButton.cxx:487
calibdata.cd
cd
Definition: calibdata.py:51
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
MuonCollectionSettingsButton::trackLightModel
SoLightModel * trackLightModel() const
Definition: MuonCollectionSettingsButton.cxx:269
MuonCollectionSettingsButton::TrackParticlesMS
@ TrackParticlesMS
Definition: MuonCollectionSettingsButton.h:60
xAOD::Muon_v1::primaryTrackParticle
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:400
VP1SGAccessHelper
Definition: VP1SGAccessHelper.h:25
IParticleCollHandle_Muon::IParticleCollHandle_Muon
IParticleCollHandle_Muon(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType type)
Definition: IParticleCollHandle_Muon.cxx:78
IParticleCollHandle_Muon::updateShownAssociatedObjects
void updateShownAssociatedObjects()
Definition: IParticleCollHandle_Muon.cxx:320
IParticleHandle_Muon.h
IParticleCollHandleBase
Base class for collections holding AOD objects of iParticle type Handles pt etc cuts Local data:
Definition: IParticleCollHandleBase.h:50
MuonCollectionSettingsButton::cutAllowedPt
VP1Interval cutAllowedPt() const
Definition: MuonCollectionSettingsButton.cxx:451
AODCollHandleBase::recheckCutStatusOfAllVisibleHandles
void recheckCutStatusOfAllVisibleHandles()
Definition: AODCollHandleBase.cxx:144
VP1SGAccessHelper.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IVP1System.h
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
IParticleCollHandle_Muon
Definition: IParticleCollHandle_Muon.h:28
AODCollHandleBase::name
QString name() const
Definition: AODCollHandleBase.cxx:130
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
MuonCollectionSettingsButton::trackDrawStyle
SoDrawStyle * trackDrawStyle() const
Definition: MuonCollectionSettingsButton.cxx:264
VP1SGContentsHelper.h
MuonCollectionSettingsButton.h