ATLAS Offline Software
Loading...
Searching...
No Matches
T2TrackBeamSpotTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2020, 2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <string>
6#include <sstream>
7#include <cmath>
8
9// This algorithm
10#include "T2TrackBeamSpotTool.h"
11
12// Specific to this algorithm
13#include "T2Track.h"
15#include "T2TrackBSLLPoly.h"
16
17// Generic Trigger tools
19
20//Conversion units
21#include "GaudiKernel/SystemOfUnits.h"
22
23using Gaudi::Units::GeV;
24using Gaudi::Units::mm;
25
26
27using namespace PESA;
28
29namespace {
30
31
32// BCID is in the range 0 to NUM_BCID-1 (inclusive)
33unsigned const NUM_BCID = 3564;
34
35/*
36* This struct wraps a special monitored array which holds elements of
37* matrices used by LS fitter. Array elements need to be mapped to
38* individual histogram bins (have to use "kVec" option) and summed
39* across whole farm.
40*/
41struct MonitoredLSMatrices {
42
43 // update with a single track
44 void update(T2TrackBeamSpotTool::TrackData const& seed, double beamSize);
45
46 void publish(ToolHandle<GenericMonitoringTool> const& monTool);
47
48 std::vector<double> beamLSMatrices; // 16 elements total
49 std::vector<double> beamLSMatricesBCID; // 8 * NUM_BCID elements
50
51};
52
53// update with a single track
54void MonitoredLSMatrices::update(T2TrackBeamSpotTool::TrackData const& seed, double beamSize) {
55
56 unsigned const sizeBCID = 2*(2+1)/2 + 2 + 2 + 1;
57
58 if (beamLSMatrices.empty()) {
59 // reserve space for elements of all matrices:
60 // - 4x4 symmetrical matrix
61 // - 4-element vector
62 // - 1 sum of d0 squares
63 // - 1 track count
64 beamLSMatrices.resize(4*(4+1)/2 + 4 + 1 + 2 + 1);
65 // per-BCID needs space for:
66 // - 2x2 symmetrical matrix
67 // - 2-element vector
68 beamLSMatricesBCID.resize(sizeBCID * NUM_BCID);
69 }
70
71 double const sin_phi0 = std::sin(seed.phi0);
72 double const cos_phi0 = std::cos(seed.phi0);
73 double const param[] = { -sin_phi0, cos_phi0, -seed.z0*sin_phi0, seed.z0*cos_phi0};
74 double d0_var = seed.d0_var + beamSize*beamSize;
75 int idx = 0;
76 for (int i = 0; i < 4; ++ i) {
77 for (int j = 0; j <= i; ++ j) {
78 beamLSMatrices[idx++] += param[i]*param[j] / d0_var;
79 }
80 }
81 for (int i = 0; i < 4; ++ i) {
82 beamLSMatrices[idx++] += seed.d0*param[i] / d0_var;
83 }
84 beamLSMatrices[idx++] += seed.d0*seed.d0 / d0_var;
85 beamLSMatrices[idx++] += seed.z0;
86 beamLSMatrices[idx++] += seed.z0*seed.z0;
87 beamLSMatrices[idx++] += 1;
88
89 idx = sizeBCID * seed.bcid;
90 beamLSMatricesBCID[idx++] += param[0]*param[0] / d0_var;
91 beamLSMatricesBCID[idx++] += param[0]*param[1] / d0_var;
92 beamLSMatricesBCID[idx++] += param[1]*param[1] / d0_var;
93 beamLSMatricesBCID[idx++] += seed.d0*param[0] / d0_var;
94 beamLSMatricesBCID[idx++] += seed.d0*param[1] / d0_var;
95 beamLSMatricesBCID[idx++] += seed.z0;
96 beamLSMatricesBCID[idx++] += seed.z0*seed.z0;
97 beamLSMatricesBCID[idx++] += 1;
98}
99
100void MonitoredLSMatrices::publish(ToolHandle<GenericMonitoringTool> const& monTool)
101{
102 if (not beamLSMatrices.empty()) {
103 auto matrices = Monitored::Collection("BeamLSMatrices", beamLSMatrices);
104 auto matricesBCID = Monitored::Collection("BeamLSMatricesBCID", beamLSMatricesBCID);
105 auto mon = Monitored::Group(monTool, matrices, matricesBCID);
106 }
107}
108
109} // namespace
110
111
112
113T2TrackBeamSpotTool::T2TrackBeamSpotTool( const std::string& type, const std::string& name, const IInterface* parent )
114 : AthAlgTool(type, name, parent)
115{
116 declareProperty("doLeastSquares", m_doLeastSquares = true);
117 declareProperty("doLogLikelihood", m_doLogLikelihood = true);
118 declareProperty("beamSizeLS", m_beamSizeLS = 0.01*mm);
119}
120
122{
123 ATH_MSG_INFO("Initialising T2TrackBeamSpotTool tool");
124
125 // Retrieve tools
126 ATH_CHECK(m_trackFilterTool.retrieve());
127 if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
128
129 return StatusCode::SUCCESS;
130}
131
132void T2TrackBeamSpotTool::updateBS(const TrackCollection& tracks, EventIDBase const& eventID) const
133{
134 //Select tracks
135 auto selectedTracks = m_trackFilterTool->filter(tracks);
136
137 std::vector<TrackData> bsTracks;
138 bool has_bs = m_trackFilterTool->updateBS(selectedTracks, eventID.lumi_block(),
139 eventID.bunch_crossing_id(), &bsTracks);
140
141 // when beamspot is known we can call actual update methods
142 if (has_bs) {
143 if (not bsTracks.empty()) {
144 updateBS(std::move(bsTracks));
145 } else {
146 updateBS(m_trackFilterTool->filterBS(selectedTracks), eventID.bunch_crossing_id());
147 }
148 }
149}
150
151void T2TrackBeamSpotTool::updateBS(std::vector<const Trk::Track*>&& tracks, unsigned bcid) const
152{
153 auto timer = Monitored::Timer("TIME_updateBS");
154 if (m_doLeastSquares) {
155 ATH_MSG_DEBUG("Fill LS matrices with " << tracks.size() << " Trk::Track tracks");
156 MonitoredLSMatrices lsMatrices;
157 for (auto& track: tracks) {
158 TrackData tdata(*track->perigeeParameters(), 0, bcid);
159 lsMatrices.update(tdata, m_beamSizeLS);
160 }
161 lsMatrices.publish(m_monTool);
162 }
163 if (m_doLogLikelihood) {
164 ATH_MSG_DEBUG("Fill LL coefficients with " << tracks.size() << " Trk::Track tracks");
165 std::vector<double> poly_coeff;
167 for (auto& track: tracks) {
168 auto const& par = track->perigeeParameters()->parameters();
169 auto const& cov = track->perigeeParameters()->covariance();
170 llpoly.update(par[Trk::z0], par[Trk::d0], par[Trk::phi0], (*cov)(Trk::d0, Trk::d0), poly_coeff);
171 }
172 if (not poly_coeff.empty()) {
173 auto coeff = Monitored::Collection("TrackLLPolyCoeff", poly_coeff);
174 auto mon = Monitored::Group(m_monTool, coeff);
175 }
176 }
177 auto mon = Monitored::Group(m_monTool, timer);
178}
179
180void T2TrackBeamSpotTool::updateBS(std::vector<TrackData>&& tracks) const
181{
182 auto timer = Monitored::Timer("TIME_updateBS");
183 if (m_doLeastSquares) {
184 ATH_MSG_DEBUG("Fill LS matrices with " << tracks.size() << " TrackData tracks");
185 MonitoredLSMatrices lsMatrices;
186 for (auto& track: tracks) {
187 lsMatrices.update(track, m_beamSizeLS);
188 }
189 lsMatrices.publish(m_monTool);
190 }
191 if (m_doLogLikelihood) {
192 ATH_MSG_DEBUG("Fill LL coefficients with " << tracks.size() << " TrackData tracks");
193 std::vector<double> poly_coeff;
195 for (auto& track: tracks) {
196 llpoly.update(track.z0, track.d0, track.phi0, track.d0_var, poly_coeff);
197 }
198 auto coeff = Monitored::Collection("TrackLLPolyCoeff", poly_coeff);
199 auto mon = Monitored::Group(m_monTool, coeff);
200 }
201 auto mon = Monitored::Group(m_monTool, timer);
202}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Group of local monitoring quantities and retain correlation when filling histograms
A monitored timer.
Class that knows details of LogLikelihood approximation with a polynomial.
void update(double z0, double d0, double phi0, double d0_var, std::vector< double > &coeff)
Update polynomial coefficients with track data.
ToolHandle< T2BSTrackFilterTool > m_trackFilterTool
ToolHandle< GenericMonitoringTool > m_monTool
void updateBS(const TrackCollection &tracks, EventIDBase const &eventID) const
Update beam spot data with new track information.
T2TrackBeamSpotTool(const std::string &type, const std::string &name, const IInterface *parent)
T2BSTrackFilterTool::TrackData TrackData
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Local tools.
Definition idx.h:9
consteval int idx()
Definition idx.h:85
@ phi0
Definition ParamDefs.h:65
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64