ATLAS Offline Software
Loading...
Searching...
No Matches
MuonAlignmentUncertTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include <TFile.h>
9
10#include <cmath>
11#include <iomanip>
12
13#include "AthenaKernel/Units.h"
14#include "GaudiKernel/ServiceHandle.h"
21
22namespace {
23 constexpr float MeVtoGeV = 1.e-3;
24}
25
26namespace Muon {
27 MuonAlignmentUncertTool::MuonAlignmentUncertTool(const std::string& type, const std::string& name, const IInterface* parent) :
28 AthAlgTool(type, name, parent),
29 m_histo(nullptr),
30 m_dim(-1),
31 m_x_reader(make_reader(nullptr)),
32 m_y_reader(make_reader(nullptr)),
33 m_z_reader(make_reader(nullptr)),
34 m_calorimeterVolume(nullptr),
35 m_indetVolume(nullptr) {}
38 std::unique_ptr<TFile> r_file(TFile::Open(PathResolverFindCalibFile(m_in_file).c_str(), "READ"));
39 if (!r_file || !r_file->IsOpen()) {
40 ATH_MSG_FATAL("No such file or directory " << m_in_file);
41 return StatusCode::FAILURE;
42 }
44 TH1* histo_in_file = nullptr;
45 r_file->GetObject(m_histo_name.value().c_str(), histo_in_file);
46 m_histo = std::unique_ptr<TH1>(histo_in_file);
47 if (!m_histo) {
48 ATH_MSG_FATAL("File " << m_in_file << " does not contain the histogram " << m_histo_name << ".");
49 return StatusCode::FAILURE;
50 }
51 m_histo->SetDirectory(nullptr);
53 m_dim = m_histo->GetDimension();
54 m_x_reader = make_reader(m_histo->GetXaxis());
55 m_y_reader = make_reader(m_histo->GetYaxis());
56 m_z_reader = make_reader(m_histo->GetZaxis());
57
62 return StatusCode::SUCCESS;
63 }
65 if (!trk) {
66 ATH_MSG_ERROR("No track has been given. Return FLT_MAX");
67 return FLT_MAX;
68 }
69 const int bin_x = m_x_reader(trk);
72 const int bin_y = m_dim > 1 ? m_y_reader(trk) : 0;
73 const int bin_z = m_dim > 2 ? m_z_reader(trk) : 0;
74 return m_histo->GetBinContent(bin_x, bin_y, bin_z);
75 }
76 std::function<int(const Trk::Track* trk)> MuonAlignmentUncertTool::make_reader(const TAxis* axis) const {
78 if (!axis) {
79 return [](const Trk::Track*) { return 0; };
80 }
81 std::string axis_title = axis->GetTitle();
82 if (axis_title == "#eta" || axis_title == "eta") {
83 return [axis](const Trk::Track* trk) {
84 const Trk::Perigee* perigee = trk->perigeeParameters();
85 return axis->FindBin(perigee->eta());
86 };
87 } else if (axis_title == "|#eta|" || axis_title == "abseta") {
88 return [axis](const Trk::Track* trk) {
89 const Trk::Perigee* perigee = trk->perigeeParameters();
90 return axis->FindBin(std::abs(perigee->eta()));
91 };
92 } else if (axis_title == "#phi" || axis_title == "phi") {
93 return [axis](const Trk::Track* trk) {
94 const Trk::Perigee* perigee = trk->perigeeParameters();
95 return axis->FindBin(perigee->parameters()[2]);
96 };
97 } else if (axis_title == "|#phi|" || axis_title == "absphi") {
98 return [axis](const Trk::Track* trk) {
99 const Trk::Perigee* perigee = trk->perigeeParameters();
100 return axis->FindBin(std::abs(perigee->parameters()[2]));
101 };
102 } else if (axis_title == "#theta" || axis_title == "theta") {
103 return [axis](const Trk::Track* trk) {
104 const Trk::Perigee* perigee = trk->perigeeParameters();
105 return axis->FindBin(perigee->parameters()[3]);
106 };
107 } else if (axis_title == "|#theta|" || axis_title == "abstheta") {
108 return [axis](const Trk::Track* trk) {
109 const Trk::Perigee* perigee = trk->perigeeParameters();
110 return axis->FindBin(std::abs(perigee->parameters()[3]));
111 };
112 } else if (axis_title == "p_{T}" || axis_title == "pT") {
113 return [axis](const Trk::Track* trk) {
114 const Trk::Perigee* perigee = trk->perigeeParameters();
115 return axis->FindBin(perigee->pT());
116 };
117 } else if (axis_title == "p_{T} [GeV]" || axis_title == "pTinGeV") {
118 return [axis](const Trk::Track* trk) {
119 const Trk::Perigee* perigee = trk->perigeeParameters();
120 return axis->FindBin(perigee->pT() * MeVtoGeV);
121 };
122 } else if (axis_title == "#rho @ ID-exit") {
123 return [axis, this](const Trk::Track* trk) {
124 const Trk::TrackStateOnSurface* id_exit;
125 const Trk::TrackStateOnSurface* dummy;
126 get_track_state_measures(trk, id_exit, dummy, dummy, dummy);
127 return axis->FindBin(id_exit->trackParameters()->position().perp());
128 };
129 } else if (axis_title == "R @ ID-exit") {
130 return [axis, this](const Trk::Track* trk) {
131 const Trk::TrackStateOnSurface* id_exit;
132 const Trk::TrackStateOnSurface* dummy;
133 get_track_state_measures(trk, id_exit, dummy, dummy, dummy);
134 return axis->FindBin(id_exit->trackParameters()->position().mag());
135 };
136 } else if (axis_title == "z @ ID-exit") {
137 return [axis, this](const Trk::Track* trk) {
138 const Trk::TrackStateOnSurface* id_exit;
139 const Trk::TrackStateOnSurface* dummy;
140 get_track_state_measures(trk, id_exit, dummy, dummy, dummy);
141 return axis->FindBin(id_exit->trackParameters()->position()[2]);
142 };
143 } else if (axis_title == "#rho @ Calo-entrance") {
144 return [axis, this](const Trk::Track* trk) {
145 const Trk::TrackStateOnSurface* calo_entrance;
146 const Trk::TrackStateOnSurface* dummy;
147 get_track_state_measures(trk, dummy, calo_entrance, dummy, dummy);
148 return axis->FindBin(calo_entrance->trackParameters()->position().perp());
149 };
150 } else if (axis_title == "R @ Calo-entrance") {
151 return [axis, this](const Trk::Track* trk) {
152 const Trk::TrackStateOnSurface* calo_entrance;
153 const Trk::TrackStateOnSurface* dummy;
154 get_track_state_measures(trk, dummy, calo_entrance, dummy, dummy);
155 return axis->FindBin(calo_entrance->trackParameters()->position().mag());
156 };
157 } else if (axis_title == "z @ Calo-entrance") {
158 return [axis, this](const Trk::Track* trk) {
159 const Trk::TrackStateOnSurface* calo_entrance;
160 const Trk::TrackStateOnSurface* dummy;
161 get_track_state_measures(trk, dummy, calo_entrance, dummy, dummy);
162 return axis->FindBin(calo_entrance->trackParameters()->position()[2]);
163 };
164 } else if (axis_title == "#rho @ Calo-centre") {
165 return [axis, this](const Trk::Track* trk) {
166 const Trk::TrackStateOnSurface* calo_entrance;
167 const Trk::TrackStateOnSurface* calo_exit;
168 const Trk::TrackStateOnSurface* dummy;
169 get_track_state_measures(trk, dummy, calo_entrance, calo_exit, dummy);
170 const Amg::Vector3D calo_centre =
171 0.5 * (calo_entrance->trackParameters()->position() + calo_exit->trackParameters()->position());
172 return axis->FindBin(calo_centre.perp());
173 };
174 } else if (axis_title == "R @ Calo-centre") {
175 return [axis, this](const Trk::Track* trk) {
176 const Trk::TrackStateOnSurface* calo_entrance;
177 const Trk::TrackStateOnSurface* calo_exit;
178 const Trk::TrackStateOnSurface* dummy;
179 get_track_state_measures(trk, dummy, calo_entrance, calo_exit, dummy);
180 const Amg::Vector3D calo_centre =
181 0.5 * (calo_entrance->trackParameters()->position() + calo_exit->trackParameters()->position());
182 return axis->FindBin(calo_centre.mag());
183 };
184 } else if (axis_title == "z @ Calo-centre") {
185 return [axis, this](const Trk::Track* trk) {
186 const Trk::TrackStateOnSurface* calo_entrance;
187 const Trk::TrackStateOnSurface* calo_exit;
188 const Trk::TrackStateOnSurface* dummy;
189 get_track_state_measures(trk, dummy, calo_entrance, calo_exit, dummy);
190 const Amg::Vector3D calo_centre =
191 0.5 * (calo_entrance->trackParameters()->position() + calo_exit->trackParameters()->position());
192 return axis->FindBin(calo_centre[2]);
193 };
194 } else if (axis_title == "#rho @ MS-entrance") {
195 return [axis, this](const Trk::Track* trk) {
196 const Trk::TrackStateOnSurface* ms_entrance;
197 const Trk::TrackStateOnSurface* dummy;
198 get_track_state_measures(trk, dummy, dummy, dummy, ms_entrance);
199 return axis->FindBin(ms_entrance->trackParameters()->position().perp());
200 };
201 } else if (axis_title == "R @ MS-entrance") {
202 return [axis, this](const Trk::Track* trk) {
203 const Trk::TrackStateOnSurface* ms_entrance;
204 const Trk::TrackStateOnSurface* dummy;
205 get_track_state_measures(trk, dummy, dummy, dummy, ms_entrance);
206 return axis->FindBin(ms_entrance->trackParameters()->position().mag());
207 };
208 } else if (axis_title == "z @ MS-entrance") {
209 return [axis, this](const Trk::Track* trk) {
210 const Trk::TrackStateOnSurface* ms_entrance;
211 const Trk::TrackStateOnSurface* dummy;
212 get_track_state_measures(trk, dummy, dummy, dummy, ms_entrance);
213 return axis->FindBin(ms_entrance->trackParameters()->position()[2]);
214 };
215 }
216 return make_reader(nullptr);
217 }
218
220 const Trk::TrackStateOnSurface*& calo_entrance,
221 const Trk::TrackStateOnSurface*& calo_exit,
222 const Trk::TrackStateOnSurface*& ms_entrance) const {
223 id_exit = calo_entrance = calo_exit = ms_entrance = nullptr;
224 if (!track) {
225 ATH_MSG_DEBUG("No track has been given. Where is my track?!");
226 return;
227 }
228 for (const Trk::TrackStateOnSurface* trk_srf : *track->trackStateOnSurfaces()) {
229 if (!trk_srf->trackParameters()) { continue; }
230 if (m_indetVolume->inside(trk_srf->trackParameters()->position())) {
231 if (trk_srf->type(Trk::TrackStateOnSurface::Measurement)) id_exit = trk_srf;
232 continue;
233 }
235 if (m_calorimeterVolume->inside(trk_srf->trackParameters()->position())) {
236 // first scattering plane in Calorimeter
237 if (trk_srf->type(Trk::TrackStateOnSurface::Scatterer) && trk_srf->materialEffectsOnTrack()) {
238 if (trk_srf->materialEffectsOnTrack()->thicknessInX0() < 10) { continue; }
239 if (!calo_entrance) {
240 calo_entrance = trk_srf;
241 } else {
242 calo_exit = trk_srf;
243 }
244 }
245 }
247 else if (trk_srf->measurementOnTrack()) {
248 ms_entrance = trk_srf;
249 break;
250 }
251 }
252 }
253
254} // namespace Muon
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Wrapper to avoid constant divisions when using units.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
std::unique_ptr< const Trk::Volume > m_calorimeterVolume
Gaudi::Property< std::string > m_in_file
std::function< int(const Trk::Track *trk)> make_reader(const TAxis *axis) const
Helper function to assign the uncertainty from the Axis.
ServiceHandle< Trk::ITrackingVolumesSvc > m_trackingVolumesSvc
Volume service to.
MuonAlignmentUncertTool(const std::string &type, const std::string &name, const IInterface *parent)
void get_track_state_measures(const Trk::Track *track, const Trk::TrackStateOnSurface *&id_exit, const Trk::TrackStateOnSurface *&calo_entrance, const Trk::TrackStateOnSurface *&calo_exit, const Trk::TrackStateOnSurface *&ms_entrance) const override
Helper method to retrieve the last measurement of the ID, the first and last scatterer in the calorim...
std::function< int(const Trk::Track *trk)> m_y_reader
Gaudi::Property< std::string > m_histo_name
float get_uncertainty(const Trk::Track *trk) const override
IMuonAlignmentUncertTool interface: retrieve the associated uncertainties.
std::unique_ptr< TH1 > m_histo
Histogram to be cached.
std::function< int(const Trk::Track *trk)> m_x_reader
Standard functions used to read the histogram having as input a Trk::Track.
std::unique_ptr< const Trk::Volume > m_indetVolume
std::function< int(const Trk::Track *trk)> m_z_reader
@ CalorimeterEntryLayer
Tracking Volume which defines the entrance srufaces of the calorimeter.
@ MuonSpectrometerEntryLayer
Tracking Volume which defines the entrance surfaces of the MS.
double eta() const
Access method for pseudorapidity - from momentum.
const Amg::Vector3D & position() const
Access method for the position.
double pT() const
Access method for transverse momentum.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr float MeVtoGeV
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee