ATLAS Offline Software
AsgLeptonTrackSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
52  if (m_d0sigDecoration.empty()){
53  ANA_MSG_ERROR ("No d0significance decoration name set");
54  return StatusCode::FAILURE;
55  } else {
56  m_d0sigDecorator = std::make_unique<SG::AuxElement::Decorator<float> > (m_d0sigDecoration);
57  }
58  if (m_z0sinthetaDecoration.empty()){
59  ANA_MSG_ERROR ("No z0sintheta decoration name set");
60  return StatusCode::FAILURE;
61  } else {
62  m_z0sinthetaDecorator = std::make_unique<SG::AuxElement::Decorator<float> > (m_z0sinthetaDecoration);
63  }
64  } else{
65  if (!m_d0sigDecoration.empty()){
66  ANA_MSG_WARNING ("d0significance decoration name set, please set decorateTTVVars to True if you want this to be written out");
67  }
68  if (!m_z0sinthetaDecoration.empty()){
69  ANA_MSG_WARNING ("z0sintheta decoration name set, please set decorateTTVVars to True if you want this to be written out");
70  }
71  }
72 
77 
79  ANA_CHECK (m_primaryVerticesKey.initialize());
80 
81  if (!m_nameSvc.empty())
82  {
83  ANA_CHECK (m_nameSvc.retrieve());
84  ANA_CHECK (m_nameSvc->addAcceptInfo (m_particlesHandle.getNamePattern(), m_selectionHandle.getLabel(),
85  m_accept));
86  }
87 
88  return StatusCode::SUCCESS;
89  }
90 
91 
92 
94  execute ()
95  {
98  const xAOD::Vertex *primaryVertex {nullptr};
99 
100  for (const xAOD::Vertex *vertex : *vertices)
101  {
102  if (vertex->vertexType() == xAOD::VxType::PriVtx)
103  {
104  // The default "PrimaryVertex" container is ordered in
105  // sum-pt, and the tracking group recommends to pick the one
106  // with the maximum sum-pt, so this will do the right thing.
107  // If the user needs a different primary vertex, they need to
108  // provide a reordered primary vertex container and point
109  // this algorithm to it. Currently there is no central
110  // algorithm to do that, so users will have to write their
111  // own (15 Aug 18).
112  if (primaryVertex == nullptr)
113  {
114  primaryVertex = vertex;
115  break;
116  }
117  }
118  }
119 
120  for (const auto& sys : m_systematicsList.systematicsVector())
121  {
122  const xAOD::IParticleContainer *particles = nullptr;
124  for (const xAOD::IParticle *particle : *particles)
125  {
126  asg::AcceptData acceptData (&m_accept);
127  float d0sig = -999;
128  float deltaZ0SinTheta = -999;
129 
131  {
132  std::size_t cutIndex {0};
133 
134  const xAOD::TrackParticle *track {nullptr};
135  if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
136  track = muon->primaryTrackParticle();
137  } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
138  track = electron->trackParticle();
139  } else {
140  ANA_MSG_ERROR ("failed to cast input to electron or muon");
141  return StatusCode::FAILURE;
142  }
143 
144  acceptData.setCutResult (cutIndex ++, track != nullptr);
145 
146  if (track != nullptr) {
147  try {
148  d0sig = xAOD::TrackingHelpers::d0significance(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY());
149  if (m_maxD0Significance > 0) acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
150 
151  } catch (const std::runtime_error &) {
152  acceptData.setCutResult (cutIndex ++, false);
153  }
154 
155  const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
156  deltaZ0SinTheta = (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
157  if (m_maxDeltaZ0SinTheta > 0) acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
158 
159  if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
161  track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
162  bool accept = true;
163  if(m_nMinPixelHits != -1) {
165  }
166  if(m_nMaxPixelHits != -1) {
168  }
169  acceptData.setCutResult (cutIndex++, accept);
170  }
171  if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
173  track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
174  bool accept = true;
175  if(m_nMinSCTHits != -1) {
177  }
178  if(m_nMaxSCTHits != -1) {
180  }
181  acceptData.setCutResult (cutIndex++, accept);
182  }
183  }
184  }
185  if(m_decorateTTVAVars){
186  (*m_z0sinthetaDecorator)(*particle) = deltaZ0SinTheta;
187  (*m_d0sigDecorator)(*particle) = d0sig;
188  }
190  }
191  }
192 
193  return StatusCode::SUCCESS;
194  }
195 }
CP::AsgLeptonTrackSelectionAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo key
Definition: AsgLeptonTrackSelectionAlg.h:72
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
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:84
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
CP::AsgLeptonTrackSelectionAlg::m_z0sinthetaDecorator
std::unique_ptr< const SG::AuxElement::Decorator< float > > m_z0sinthetaDecorator
the name of the variable being decorated for z0sintheta
Definition: AsgLeptonTrackSelectionAlg.h:102
CP::AsgLeptonTrackSelectionAlg::m_nameSvc
ServiceHandle< ISelectionNameSvc > m_nameSvc
the ISelectionNameSvc
Definition: AsgLeptonTrackSelectionAlg.h:94
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:70
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
xAOD::EventInfo_v1::beamPosSigmaX
float beamPosSigmaX() const
The width of the beam spot in the X direction.
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:259
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:48
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::AsgLeptonTrackSelectionAlg::m_decorateTTVAVars
Gaudi::Property< bool > m_decorateTTVAVars
Definition: AsgLeptonTrackSelectionAlg.h:60
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
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:75
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
CP::AsgLeptonTrackSelectionAlg::execute
StatusCode execute() override
Definition: AsgLeptonTrackSelectionAlg.cxx:94
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
CP::AsgLeptonTrackSelectionAlg::m_z0sinthetaDecoration
Gaudi::Property< std::string > m_z0sinthetaDecoration
Definition: AsgLeptonTrackSelectionAlg.h:62
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:89
xAOD::EventInfo_v1::beamPosSigmaY
float beamPosSigmaY() const
The width of the beam spot in the Y direction.
CP::AsgLeptonTrackSelectionAlg::m_d0sigDecorator
std::unique_ptr< const SG::AuxElement::Decorator< float > > m_d0sigDecorator
the name of the variable being decorated for d0significance
Definition: AsgLeptonTrackSelectionAlg.h:98
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::AsgLeptonTrackSelectionAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: AsgLeptonTrackSelectionAlg.h:69
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::EventInfo_v1::beamPosSigmaXY
float beamPosSigmaXY() const
The beam spot shape's X-Y correlation.
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:106
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:79
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
AsgLeptonTrackSelectionAlg.h
CP::AsgLeptonTrackSelectionAlg::m_d0sigDecoration
Gaudi::Property< std::string > m_d0sigDecoration
Definition: AsgLeptonTrackSelectionAlg.h:61
xAOD::numberOfSCTHits
@ numberOfSCTHits
number of hits in SCT [unit8_t].
Definition: TrackingPrimitives.h:268
CP::AsgLeptonTrackSelectionAlg::initialize
StatusCode initialize() override
Definition: AsgLeptonTrackSelectionAlg.cxx:27
Electron.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
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