ATLAS Offline Software
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 
22 namespace {
23  constexpr float MeVtoGeV = 1.e-3;
24 }
25 
26 namespace Muon {
27  MuonAlignmentUncertTool::MuonAlignmentUncertTool(const std::string& type, const std::string& name, const IInterface* 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 
58  ATH_CHECK(m_trackingVolumesSvc.retrieve());
60  std::make_unique<Trk::Volume>(m_trackingVolumesSvc->volume(Trk::ITrackingVolumesSvc::MuonSpectrometerEntryLayer));
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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
Trk::TrackStateOnSurface::trackParameters
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
EnergyLoss.h
ScatteringAngles.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Muon::MuonAlignmentUncertTool::m_x_reader
std::function< int(const Trk::Track *trk)> m_x_reader
Standard functions used to read the histogram having as input a Trk::Track.
Definition: MuonAlignmentUncertTool.h:69
TrackParameters.h
Muon::MuonAlignmentUncertTool::m_trackingVolumesSvc
ServiceHandle< Trk::ITrackingVolumesSvc > m_trackingVolumesSvc
Volume service to.
Definition: MuonAlignmentUncertTool.h:57
Muon::MuonAlignmentUncertTool::get_uncertainty
float get_uncertainty(const Trk::Track *trk) const override
IMuonAlignmentUncertTool interface: retrieve the associated uncertainties.
Definition: MuonAlignmentUncertTool.cxx:64
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Muon::MuonAlignmentUncertTool::m_z_reader
std::function< int(const Trk::Track *trk)> m_z_reader
Definition: MuonAlignmentUncertTool.h:71
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
Trk::ITrackingVolumesSvc::MuonSpectrometerEntryLayer
@ MuonSpectrometerEntryLayer
Tracking Volume which defines the entrance surfaces of the MS.
Definition: ITrackingVolumesSvc.h:41
CP::MeVtoGeV
constexpr float MeVtoGeV
Definition: IsolationCloseByCorrectionTool.cxx:33
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
MaterialEffectsOnTrack.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::MuonAlignmentUncertTool::m_y_reader
std::function< int(const Trk::Track *trk)> m_y_reader
Definition: MuonAlignmentUncertTool.h:70
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Muon::MuonAlignmentUncertTool::MuonAlignmentUncertTool
MuonAlignmentUncertTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MuonAlignmentUncertTool.cxx:27
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ITrackingVolumesSvc::CalorimeterEntryLayer
@ CalorimeterEntryLayer
Tracking Volume which defines the entrance srufaces of the calorimeter.
Definition: ITrackingVolumesSvc.h:40
Muon::MuonAlignmentUncertTool::make_reader
std::function< int(const Trk::Track *trk)> make_reader(const TAxis *axis) const
Helper function to assign the uncertainty from the Axis.
Definition: MuonAlignmentUncertTool.cxx:76
PathResolver.h
Muon::MuonAlignmentUncertTool::m_histo
std::unique_ptr< TH1 > m_histo
Histogram to be cached.
Definition: MuonAlignmentUncertTool.h:65
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Muon::MuonAlignmentUncertTool::m_calorimeterVolume
std::unique_ptr< const Trk::Volume > m_calorimeterVolume
Definition: MuonAlignmentUncertTool.h:73
Muon::MuonAlignmentUncertTool::m_histo_name
Gaudi::Property< std::string > m_histo_name
Definition: MuonAlignmentUncertTool.h:62
Units.h
Wrapper to avoid constant divisions when using units.
CheckAppliedSFs.axis_title
axis_title
Definition: CheckAppliedSFs.py:241
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
MuonAlignmentUncertTool.h
Muon::MuonAlignmentUncertTool::m_in_file
Gaudi::Property< std::string > m_in_file
Definition: MuonAlignmentUncertTool.h:59
Muon::MuonAlignmentUncertTool::m_dim
unsigned int m_dim
Definition: MuonAlignmentUncertTool.h:66
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::TrackStateOnSurface::Scatterer
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Definition: TrackStateOnSurface.h:113
Muon::MuonAlignmentUncertTool::get_track_state_measures
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...
Definition: MuonAlignmentUncertTool.cxx:219
Muon::MuonAlignmentUncertTool::m_indetVolume
std::unique_ptr< const Trk::Volume > m_indetVolume
Definition: MuonAlignmentUncertTool.h:74
Muon::MuonAlignmentUncertTool::initialize
StatusCode initialize() override
Definition: MuonAlignmentUncertTool.cxx:36
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AthAlgTool
Definition: AthAlgTool.h:26
ITrackingVolumesSvc.h
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
TrackStateOnSurface.h