ATLAS Offline Software
Loading...
Searching...
No Matches
SoftElectronDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
10
14
15
16namespace FlavorTagDiscriminants {
17
19 const std::string& name, ISvcLocator* loc )
20 : AthReentrantAlgorithm(name, loc) {}
21
23 ATH_MSG_DEBUG( "Initializing " << name() << "... " );
24
25 // Initialize Container keys
26 ATH_MSG_DEBUG( "Initializing containers:" );
29
30 ATH_CHECK( m_ElectronContainerKey.initialize() );
31 ATH_CHECK( m_VertexContainerKey.initialize() );
32
33 // Initialize decorators
34 ATH_MSG_DEBUG( "Initializing decorators:" );
41
42 ATH_CHECK( m_dec_electron_et.initialize() );
46 ATH_CHECK( m_dec_electron_z0.initialize() );
48
49 return StatusCode::SUCCESS;
50 }
51
52 StatusCode SoftElectronDecoratorAlg::execute(const EventContext& ctx) const {
53 ATH_MSG_DEBUG( "Executing " << name() << "... " );
54
55 using EC = xAOD::ElectronContainer;
56
57 // read collections
59 ATH_CHECK( electrons.isValid() );
60 ATH_MSG_DEBUG( "Retrieved " << electrons->size() << " electrons..." );
62 ATH_CHECK( primary_vertices.isValid() );
63 ATH_MSG_DEBUG( "Retrieved " << primary_vertices->size() << " primary vertices..." );
64
65 // instantiate decorators
71 SG::WriteDecorHandle<EC, float> dec_electron_z0_significance(m_dec_electron_z0_significance, ctx);
72
73 // get the primary vertex
74 const xAOD::Vertex* pv = primary(*primary_vertices);
75
76 for (const auto el : *electrons)
77 {
78 // kinematic vars
79 float el_et = -1;
80 float el_qoverp = -1;
81 // tracking vars
82 float el_z0 = -1;
83 float el_z0_sig = -1;
84 // additional var (x1)
85 float el_iso_pt = -1;
86 // tracking dnn
87 float el_dpop = -1;
88 // kinematic vars
89 float el_pt = el->pt();
90
91 float energy = el->caloCluster()->e();
92 auto track = el->trackParticle();
93 el_et = energy / std::cosh(track->eta());
94
95 // tracking vars
96 el_z0 = track->z0() + (track->vz() - pv->z());
97 el_z0_sig = el_z0 / std::sqrt(track->definingParametersCovMatrixDiagVec().at(1));
98
99 // additional vars
100 el_iso_pt = m_pt_varcone30(*el) / el_pt;
101 // tracking dnn
102 unsigned int index;
103 el_qoverp = track->qOverP();
104 if (track->indexOfParameterAtPosition(index, xAOD::LastMeasurement))
105 {
106 double refittedTrack_LMqoverp = track->charge() / std::sqrt(std::pow(track->parameterPX(index), 2) +
107 std::pow(track->parameterPY(index), 2) +
108 std::pow(track->parameterPZ(index), 2));
109 el_dpop = 1 - el_qoverp / (refittedTrack_LMqoverp);
110 }
111
112 // kinematic var
113 dec_electron_et(*el) = el_et;
114 // track var
115 dec_electron_z0(*el) = el_z0;
116 dec_electron_z0_significance(*el) = el_z0_sig;
117 // additional var (x1)
118 dec_electron_isoPtOverPt(*el) = el_iso_pt;
119 // dnn tracking
120 dec_electron_deltaPOverP(*el) = el_dpop;
121 // track cluster
122 dec_electron_energyOverP(*el) = energy * std::abs(track->qOverP());
123 }
124 return StatusCode::SUCCESS;
125 }
126
128 if (vertices.size() == 0) {
129 throw std::runtime_error("no primary vertices");
130 }
131 for ( const xAOD::Vertex *vertex : vertices ) {
132 if ( vertex->vertexType() == xAOD::VxType::PriVtx ) {
133 return vertex;
134 }
135 }
136 // if we find nothing else this should be the beam spot
137 return vertices.front();
138 }
139}
140
141
142
143
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::AuxElement::ConstAccessor< float > m_pt_varcone30
SG::ReadHandleKey< xAOD::VertexContainer > m_VertexContainerKey
const xAOD::Vertex * primary(const xAOD::VertexContainer &vertices) const
virtual StatusCode execute(const EventContext &) const override
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_deltaPOverP
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
SoftElectronDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_isoPtOverPt
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_z0
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_energyOverP
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_z0_significance
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_dec_electron_et
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
Definition index.py:1
@ PriVtx
Primary vertex.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
@ LastMeasurement
Parameter defined at the position of the last measurement.