ATLAS Offline Software
Loading...
Searching...
No Matches
FourMomFillerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
13#include "FourMomFillerTool.h"
17#include "CLHEP/Vector/LorentzVector.h"
18#include "TLorentzVector.h"
19#include <typeinfo>
20#include <cmath>
21
22
23namespace D3PD {
24
25
33 const std::string& name,
34 const IInterface* parent)
35 : Base (type, name, parent)
36{
37 m_do_E = true;
38 m_do_p = true;
39 m_do_Et = true;
40 m_do_pt = true;
41 m_do_m = true;
42 m_do_rapidity = true;
43 m_do_tanth = true;
44 m_do_etaphi = true;
45 m_do_rect = true;
46 FourMomFillerTool::book().ignore(); // Avoid coverity warnings.
47
48 declareProperty ("WriteE", m_do_E = false);
49 declareProperty ("WriteP", m_do_p = false);
50 declareProperty ("WriteEt", m_do_Et = false);
51 declareProperty ("WritePt", m_do_pt = true);
52 declareProperty ("WriteM", m_do_m = true);
53 declareProperty ("WriteRapidity", m_do_rapidity = false);
54 declareProperty ("WriteTanTh", m_do_tanth = false);
55 declareProperty ("WriteEtaPhi", m_do_etaphi = true);
56 declareProperty ("WriteRect", m_do_rect = false);
57}
58
59
64{
65 if (m_do_E) CHECK( addVariable ("E", m_E) );
66 if (m_do_p) CHECK( addVariable ("p", m_p) );
67 if (m_do_Et) CHECK( addVariable ("Et", m_Et) );
68 if (m_do_pt) CHECK( addVariable ("pt", m_pt) );
69 if (m_do_m) CHECK( addVariable ("m", m_m) );
70 if (m_do_rapidity) CHECK( addVariable ("y", m_y) );
71 if (m_do_tanth) CHECK( addVariable ("tanth", m_tanth) );
72
73 if (m_do_etaphi) {
74 CHECK( addVariable ("eta", m_eta) );
75 CHECK( addVariable ("phi", m_phi) );
76 }
77
78 if (m_do_rect) {
79 CHECK( addVariable ("px", m_px) );
80 CHECK( addVariable ("py", m_py) );
81 CHECK( addVariable ("pz", m_pz) );
82 }
83
84 return StatusCode::SUCCESS;
85}
86
87
88#define FILL_BODY(P, PT, TANTH) \
89 do { \
90 if (m_do_E) *m_E = static_cast<float> (p.e()); \
91 if (m_do_p) *m_p = static_cast<float> (P); \
92 if (m_do_Et) *m_Et = static_cast<float> (p.et()); \
93 if (m_do_pt) *m_pt = static_cast<float> (PT); \
94 if (m_do_m) *m_m = static_cast<float> (p.m()); \
95 if (m_do_rapidity) *m_y = static_cast<float> (p.rapidity()); \
96 if (m_do_tanth) *m_tanth = static_cast<float> (TANTH); \
97 \
98 if (m_do_etaphi) { \
99 *m_eta = static_cast<float> (p.eta()); \
100 *m_phi = static_cast<float> (p.phi()); \
101 } \
102 \
103 if (m_do_rect) { \
104 *m_px = static_cast<float> (p.px()); \
105 *m_py = static_cast<float> (p.py()); \
106 *m_pz = static_cast<float> (p.pz()); \
107 } \
108 } while(0)
109
110
116{
117 FILL_BODY(p.p(), p.pt(), p.tanTh());
118
119 return StatusCode::SUCCESS;
120}
121
122
128{
129 return fill (static_cast<const I4Momentum&>(p));
130}
131
132
137StatusCode FourMomFillerTool::fill (const CLHEP::HepLorentzVector& p)
138{
139 FILL_BODY(p.mag(), p.perp(), std::tan(p.theta()));
140
141 return StatusCode::SUCCESS;
142}
143
144
150{
151 return fill (p.p4());
152}
153
154
159StatusCode FourMomFillerTool::fill (const TLorentzVector& p)
160{
161 double pt = p.Pt();
162
163 if (m_do_E) *m_E = static_cast<float> (p.E());
164 if (m_do_p) *m_p = static_cast<float> (p.P());
165 if (m_do_Et) *m_Et = static_cast<float> (p.Et());
166 if (m_do_pt) *m_pt = static_cast<float> (pt);
167 if (m_do_m) *m_m = static_cast<float> (p.M());
168 if (m_do_rapidity) *m_y = static_cast<float> (p.Rapidity());
169 if (m_do_tanth) *m_tanth = static_cast<float> (tan(p.Theta()));
170
171 if (m_do_etaphi) {
172 if (pt < 1e-6) {
173 if (p.Pz() > 0)
174 *m_eta = 10e10;
175 else
176 *m_eta = 10e-10;
177 }
178 else
179 *m_eta = static_cast<float> (p.Eta());
180 *m_phi = static_cast<float> (p.Phi());
181 }
182
183 if (m_do_rect) {
184 *m_px = static_cast<float> (p.Px());
185 *m_py = static_cast<float> (p.Py());
186 *m_pz = static_cast<float> (p.Pz());
187 }
188
189 return StatusCode::SUCCESS;
190}
191
192
193} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
#define FILL_BODY(P, PT, TANTH)
Block filler tool for a four-momentum.
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
float * m_pt
Variable: Transverse momentum.
float * m_py
Variable: y-component of momentum.
virtual StatusCode fill(const INavigable4Momentum &p)
Fill one block — type-safe version.
bool m_do_rapidity
Property: Should we fill rapidity?
bool m_do_Et
Property: Should we fill Et?
float * m_pz
Variable: z-component of momentum.
float * m_tanth
Variable: Tangent of polar angle.
bool m_do_m
Property: Should we fill m?
virtual StatusCode book()
Book variables for this block.
bool m_do_p
Property: Should we fill p?
FourMomFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
float * m_m
Variable: Mass.
float * m_y
Variable: Rapidity.
bool m_do_E
Property: Should we fill E?
float * m_E
Variable: Energy.
float * m_p
Variable: Momentum.
bool m_do_etaphi
Property: Should we fill eta/phi?
float * m_phi
Variable: Azimuth.
float * m_Et
Variable: Transverse energy (E*sin(theta)).
bool m_do_pt
Property: Should we fill pt?
BlockFillerTool< Types< INavigable4Momentum, I4Momentum, CLHEP::HepLorentzVector, xAOD::IParticle > > Base
bool m_do_tanth
Property: Should we fill tan(theta)?
float * m_eta
Variable: Pseudorapidity.
float * m_px
Variable: x-component of momentum.
bool m_do_rect
Property: Should we fill px/py/pz?
I4Momentum is an abstract base class providing 4-momentum behavior.
Definition I4Momentum.h:31
Class providing the definition of the 4-vector interface.
Block filler tool for noisy FEB information.