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 ATH_CHECK( m_pt_varcone30_key.initialize() );
50
51 return StatusCode::SUCCESS;
52 }
53
54 StatusCode SoftElectronDecoratorAlg::execute(const EventContext& ctx) const {
55 ATH_MSG_DEBUG( "Executing " << name() << "... " );
56
57 using EC = xAOD::ElectronContainer;
58
59 // read collections
61 ATH_CHECK( electrons.isValid() );
62 ATH_MSG_DEBUG( "Retrieved " << electrons->size() << " electrons..." );
64 ATH_CHECK( primary_vertices.isValid() );
65 ATH_MSG_DEBUG( "Retrieved " << primary_vertices->size() << " primary vertices..." );
66
67 // instantiate decorators
73 SG::WriteDecorHandle<EC, float> dec_electron_z0_significance(m_dec_electron_z0_significance, ctx);
74
76
77 // get the primary vertex
78 const xAOD::Vertex* pv = primary(*primary_vertices);
79
80 for (const auto el : *electrons)
81 {
82 // kinematic vars
83 float el_et = -1;
84 float el_qoverp = -1;
85 // tracking vars
86 float el_z0 = -1;
87 float el_z0_sig = -1;
88 // additional var (x1)
89 float el_iso_pt = -1;
90 // tracking dnn
91 float el_dpop = -1;
92 // kinematic vars
93 float el_pt = el->pt();
94
95 float energy = el->caloCluster()->e();
96 auto track = el->trackParticle();
97 el_et = energy / std::cosh(track->eta());
98
99 // tracking vars
100 el_z0 = track->z0() + (track->vz() - pv->z());
101 el_z0_sig = el_z0 / std::sqrt(track->definingParametersCovMatrixDiagVec().at(1));
102
103 // additional vars
104 el_iso_pt = pt_varcone30(*el) / el_pt;
105 // tracking dnn
106 unsigned int index;
107 el_qoverp = track->qOverP();
108 if (track->indexOfParameterAtPosition(index, xAOD::LastMeasurement))
109 {
110 double refittedTrack_LMqoverp = track->charge() / std::sqrt(std::pow(track->parameterPX(index), 2) +
111 std::pow(track->parameterPY(index), 2) +
112 std::pow(track->parameterPZ(index), 2));
113 el_dpop = 1 - el_qoverp / (refittedTrack_LMqoverp);
114 }
115
116 // kinematic var
117 dec_electron_et(*el) = el_et;
118 // track var
119 dec_electron_z0(*el) = el_z0;
120 dec_electron_z0_significance(*el) = el_z0_sig;
121 // additional var (x1)
122 dec_electron_isoPtOverPt(*el) = el_iso_pt;
123 // dnn tracking
124 dec_electron_deltaPOverP(*el) = el_dpop;
125 // track cluster
126 dec_electron_energyOverP(*el) = energy * std::abs(track->qOverP());
127 }
128 return StatusCode::SUCCESS;
129 }
130
132 if (vertices.size() == 0) {
133 throw std::runtime_error("no primary vertices");
134 }
135 for ( const xAOD::Vertex *vertex : vertices ) {
136 if ( vertex->vertexType() == xAOD::VxType::PriVtx ) {
137 return vertex;
138 }
139 }
140 // if we find nothing else this should be the beam spot
141 return vertices.front();
142 }
143}
144
145
146
147
#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::ReadHandleKey< xAOD::VertexContainer > m_VertexContainerKey
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_pt_varcone30_key
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
Handle class for reading a decoration on an object.
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.