Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AsgLeptonTrackSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
15 #include <xAODEgamma/Electron.h>
16 #include <xAODMuon/Muon.h>
18 
19 //
20 // method implementations
21 //
22 
23 namespace CP
24 {
25 
27  initialize ()
28  {
29 
30  if (m_maxD0Significance < 0 || !std::isfinite (m_maxD0Significance))
31  {
32  ATH_MSG_ERROR ("invalid value of maxD0Significance: " << m_maxD0Significance);
33  return StatusCode::FAILURE;
34  }
35  if (m_maxDeltaZ0SinTheta < 0 || !std::isfinite (m_maxDeltaZ0SinTheta))
36  {
37  ATH_MSG_ERROR ("invalid value of maxDeltaZ0SinTheta: " << m_maxDeltaZ0SinTheta);
38  return StatusCode::FAILURE;
39  }
40 
41  m_accept.addCut ("trackRetrieval", "whether the track retrieval failed");
42  if (m_maxD0Significance > 0)
43  m_accept.addCut ("maxD0Significance", "maximum D0 significance cut");
44  if (m_maxDeltaZ0SinTheta > 0)
45  m_accept.addCut ("maxDeltaZ0SinTheta", "maximum Delta z0 sin theta cut");
46  if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1)
47  m_accept.addCut ("numPixelHits", "Minimum and/or maxiumum Pixel hits");
48  if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1)
49  m_accept.addCut ("numSCTHits", "Minimum and/or maxiumum SCT hits");
50 
55 
57  ANA_CHECK (m_primaryVerticesKey.initialize());
58 
59  if (!m_nameSvc.empty())
60  {
61  ANA_CHECK (m_nameSvc.retrieve());
62  ANA_CHECK (m_nameSvc->addAcceptInfo (m_particlesHandle.getNamePattern(), m_selectionHandle.getLabel(),
63  m_accept));
64  }
65 
66  return StatusCode::SUCCESS;
67  }
68 
69 
70 
72  execute (const EventContext &ctx) const
73  {
76  const xAOD::Vertex *primaryVertex {nullptr};
77 
78  for (const xAOD::Vertex *vertex : *vertices)
79  {
80  if (vertex->vertexType() == xAOD::VxType::PriVtx)
81  {
82  // The default "PrimaryVertex" container is ordered in
83  // sum-pt, and the tracking group recommends to pick the one
84  // with the maximum sum-pt, so this will do the right thing.
85  // If the user needs a different primary vertex, they need to
86  // provide a reordered primary vertex container and point
87  // this algorithm to it. Currently there is no central
88  // algorithm to do that, so users will have to write their
89  // own (15 Aug 18).
90  if (primaryVertex == nullptr)
91  {
92  primaryVertex = vertex;
93  break;
94  }
95  }
96  }
97 
98  for (const auto& sys : m_systematicsList.systematicsVector())
99  {
100  const xAOD::IParticleContainer *particles = nullptr;
102  for (const xAOD::IParticle *particle : *particles)
103  {
104  asg::AcceptData acceptData (&m_accept);
105  float d0sig = -999;
106  float deltaZ0SinTheta = -999;
107 
108  if (m_preselection.getBool (*particle, sys))
109  {
110  std::size_t cutIndex {0};
111 
112  const xAOD::TrackParticle *track {nullptr};
113  if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
114  track = muon->primaryTrackParticle();
115  } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
116  track = electron->trackParticle();
117  } else {
118  ANA_MSG_ERROR ("failed to cast input to electron or muon");
119  return StatusCode::FAILURE;
120  }
121 
122  acceptData.setCutResult (cutIndex ++, track != nullptr);
123 
124  if (track != nullptr) {
125  try {
126  d0sig = xAOD::TrackingHelpers::d0significance(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY());
127  if (m_maxD0Significance > 0) acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
128 
129  } catch (const std::runtime_error &) {
130  acceptData.setCutResult (cutIndex ++, false);
131  }
132 
133  const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
134  deltaZ0SinTheta = (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
135  if (m_maxDeltaZ0SinTheta > 0) acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
136 
137  if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
139  track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
140  bool accept = true;
141  if(m_nMinPixelHits != -1) {
143  }
144  if(m_nMaxPixelHits != -1) {
146  }
147  acceptData.setCutResult (cutIndex++, accept);
148  }
149  if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
151  track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
152  bool accept = true;
153  if(m_nMinSCTHits != -1) {
155  }
156  if(m_nMaxSCTHits != -1) {
158  }
159  acceptData.setCutResult (cutIndex++, accept);
160  }
161  }
162  }
163 
164  m_selectionHandle.setBits(*particle, selectionFromAccept (acceptData), sys);
165  }
166  }
167 
168  return StatusCode::SUCCESS;
169  }
170 }
CP::AsgLeptonTrackSelectionAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo key
Definition: AsgLeptonTrackSelectionAlg.h:69
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
CP::SysWriteSelectionHandle::setBits
void setBits(const SG::AuxElement &element, SelectionType selection, const CP::SystematicSet &sys) const
set the selection decoration
CP::AsgLeptonTrackSelectionAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: AsgLeptonTrackSelectionAlg.h:81
CP::AsgLeptonTrackSelectionAlg::m_nameSvc
ServiceHandle< ISelectionNameSvc > m_nameSvc
the ISelectionNameSvc
Definition: AsgLeptonTrackSelectionAlg.h:91
TrackParticlexAODHelpers.h
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
CP::AsgLeptonTrackSelectionAlg::m_nMaxPixelHits
Gaudi::Property< int > m_nMaxPixelHits
Definition: AsgLeptonTrackSelectionAlg.h:57
CP::AsgLeptonTrackSelectionAlg::m_nMinSCTHits
Gaudi::Property< int > m_nMinSCTHits
Definition: AsgLeptonTrackSelectionAlg.h:58
Muon.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
xAOD::TrackingHelpers::d0significance
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
Definition: TrackParticlexAODHelpers.cxx:42
CP::selectionFromAccept
SelectionType selectionFromAccept(const asg::AcceptData &accept)
the selection decoration made from the given AcceptData object
Definition: SelectionHelpers.cxx:32
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
xAOD::numberOfPixelHits
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Definition: TrackingPrimitives.h:260
CP::AsgLeptonTrackSelectionAlg::m_maxDeltaZ0SinTheta
Gaudi::Property< float > m_maxDeltaZ0SinTheta
Definition: AsgLeptonTrackSelectionAlg.h:55
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
IDTPM::nPixelHits
float nPixelHits(const U &p)
Definition: TrackParametersHelper.h:354
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::SysWriteSelectionHandle::getLabel
std::string getLabel() const
get the name/label of the decoration
Definition: SysWriteSelectionHandle.cxx:76
CP::AsgLeptonTrackSelectionAlg::m_nMinPixelHits
Gaudi::Property< int > m_nMinPixelHits
Definition: AsgLeptonTrackSelectionAlg.h:56
CP::AsgLeptonTrackSelectionAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: AsgLeptonTrackSelectionAlg.cxx:72
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::AsgLeptonTrackSelectionAlg::m_primaryVerticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVerticesKey
the PrimaryVertex key
Definition: AsgLeptonTrackSelectionAlg.h:72
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
IDTPM::nSCTHits
float nSCTHits(const U &p)
Definition: TrackParametersHelper.h:393
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CP::AsgLeptonTrackSelectionAlg::m_selectionHandle
SysWriteSelectionHandle m_selectionHandle
the accessor for m_selectionDecoration
Definition: AsgLeptonTrackSelectionAlg.h:86
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::AsgLeptonTrackSelectionAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: AsgLeptonTrackSelectionAlg.h:66
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
CP::AsgLeptonTrackSelectionAlg::m_accept
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
Definition: AsgLeptonTrackSelectionAlg.h:95
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
CP::AsgLeptonTrackSelectionAlg::m_particlesHandle
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle container we run on
Definition: AsgLeptonTrackSelectionAlg.h:76
AsgLeptonTrackSelectionAlg.h
xAOD::numberOfSCTHits
@ numberOfSCTHits
number of hits in SCT [unit8_t].
Definition: TrackingPrimitives.h:269
CP::AsgLeptonTrackSelectionAlg::initialize
StatusCode initialize() override
Definition: AsgLeptonTrackSelectionAlg.cxx:27
Electron.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
CP::AsgLeptonTrackSelectionAlg::m_nMaxSCTHits
Gaudi::Property< int > m_nMaxSCTHits
Definition: AsgLeptonTrackSelectionAlg.h:59
asg::AcceptData
Definition: AcceptData.h:30
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::SysWriteSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysWriteSelectionHandle.cxx:34
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53
CP::AsgLeptonTrackSelectionAlg::m_maxD0Significance
Gaudi::Property< float > m_maxD0Significance
algorithm properties
Definition: AsgLeptonTrackSelectionAlg.h:54