ATLAS Offline Software
TrRelation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <iostream>
9 
11 #include "GaudiKernel/MsgStream.h"
12 
13 using namespace MuonCalib;
14 
15 //*****************************************************************************
16 
17 //::::::::::::::::::::::::::::::::::::::::
18 //:: CONSTRUCTOR (const IRtRelation & ) ::
19 //::::::::::::::::::::::::::::::::::::::::
22  // VARIABLES //
24  unsigned int nb_points(100); // number of r-t points used internally
25  // step size in r
26  double step_size(input_rt.radius(input_rt.tUpper()) / static_cast<double>(nb_points - 1));
27  m_r = std::vector<double>(nb_points);
28  m_t = std::vector<double>(nb_points);
29 
31  // FILL THE (r, t) PAIRS //
33  for (unsigned int k = 0; k < nb_points; k++) {
34  m_r[k] = k * step_size;
35  m_t[k] = getTFromR(m_r[k], input_rt);
36  }
37 
38 } // end TrRelation::TrRelation
39 
40 //*****************************************************************************
41 
42 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43 //:: CONSTRUCTOR (const std::vector<double> & , const std::vector<double> &) ::
44 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
45 TrRelation::TrRelation(const std::vector<double> &r_values, const std::vector<double> &t_values)
46  : m_r (r_values),
47  m_t (t_values)
48 {
49 }
50 
51 //*****************************************************************************
52 
53 //:::::::::::::::::::
54 //:: METHOD tFromR ::
55 //:::::::::::::::::::
56 double TrRelation::tFromR(const double &r, bool &out_of_bound_flag) const {
58  // CHECK BOUNDS //
60  if (r < m_r[0]) {
61  out_of_bound_flag = true;
62  return m_t[0];
63  }
64  if (r > m_r[m_r.size() - 1]) {
65  out_of_bound_flag = true;
66  return m_t[m_r.size() - 1];
67  }
68 
70  // INTERPOLATION //
72  for (unsigned int k = 0; k < m_r.size() - 1; k++) {
73  if (r >= m_r[k] && r <= m_r[k + 1]) {
74  if (m_r[k] == m_r[k + 1]) {
75  out_of_bound_flag = false;
76  return m_t[k];
77  }
78  out_of_bound_flag = false;
79  return m_t[k] + (r - m_r[k]) * (m_t[k + 1] - m_t[k]) / (m_r[k + 1] - m_r[k]);
80  }
81  }
82  MsgStream log(Athena::getMessageSvc(), "TrRelation");
83  log << MSG::ERROR << "Class TrRelation, method tFromR: ERROR!" << endmsg;
84  return 0.0;
85 } // end TrRelation::tFromR
86 
87 //*****************************************************************************
88 
89 //:::::::::::::::::::
90 //:: METHOD rFromT ::
91 //:::::::::::::::::::
92 double TrRelation::rFromT(const double &t, bool &out_of_bound_flag) const {
94  // CHECK BOUNDS //
96  if (t < m_t[0]) {
97  out_of_bound_flag = true;
98  return m_r[0];
99  }
100  if (t > m_t[m_r.size() - 1]) {
101  out_of_bound_flag = true;
102  return m_r[m_r.size() - 1];
103  }
104 
106  // INTERPOLATION //
108  for (unsigned int k = 0; k < m_r.size() - 1; k++) {
109  if (t >= m_t[k] && t <= m_t[k + 1]) {
110  if (m_t[k] == m_t[k + 1]) {
111  out_of_bound_flag = false;
112  return m_r[k];
113  }
114  out_of_bound_flag = false;
115  return m_r[k] + (t - m_t[k]) * (m_r[k + 1] - m_r[k]) / (m_t[k + 1] - m_t[k]);
116  }
117  }
118  MsgStream log(Athena::getMessageSvc(), "TrRelation");
119  log << MSG::ERROR << "Class TrRelation, method rFromT: ERROR!" << endmsg;
120  return 0.0;
121 } // end TrRelation::rFromT
122 
123 //*****************************************************************************
124 
125 //::::::::::::::::::::::
126 //:: METHOD getTFromR ::
127 //::::::::::::::::::::::
128 double TrRelation::getTFromR(const double &r, const IRtRelation &input_rt) {
130  // VARIABLES //
132  double precision(0.001); // spatial precision of the inversion
133  double t_max(input_rt.tUpper()); // upper time search limit
134  double t_min(input_rt.tLower()); // lower time search limit
135 
137  // SEARCH FOR THE CORRESPONDING DRIFT TIME //
139  while (t_max - t_min > 0.1 && std::abs(input_rt.radius(0.5 * (t_min + t_max)) - r) > precision) {
140  if (input_rt.radius(0.5 * (t_min + t_max)) > r) {
141  t_max = 0.5 * (t_min + t_max);
142  } else {
143  t_min = 0.5 * (t_min + t_max);
144  }
145  }
146 
147  return 0.5 * (t_min + t_max);
148 } // end TrRelation::getTFromR
beamspotman.r
def r
Definition: beamspotman.py:676
MuonCalib::IRtRelation::tUpper
virtual double tUpper(void) const =0
TrRelation.h
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::TrRelation::tFromR
double tFromR(const double &r, bool &out_of_bound_flag) const
< Get t(r). out_of_bound_flag is set to true if r is out of bounds.
Definition: TrRelation.cxx:56
MuonCalib::TrRelation::rFromT
double rFromT(const double &t, bool &out_of_bound_flag) const
Definition: TrRelation.cxx:92
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::TrRelation::getTFromR
static double getTFromR(const double &r, const IRtRelation &input_rt)
Definition: TrRelation.cxx:128
MuonCalib::TrRelation::TrRelation
TrRelation(const IRtRelation &input_rt)
< Constructor.
Definition: TrRelation.cxx:20
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::IRtRelation::tLower
virtual double tLower(void) const =0
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::TrRelation::m_t
std::vector< double > m_t
Definition: TrRelation.h:59
MuonCalib::IRtRelation::radius
virtual double radius(double t) const =0
returns drift radius for a given time
MuonCalib::TrRelation::m_r
std::vector< double > m_r
Definition: TrRelation.h:58
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::IRtRelation
generic interface for a rt-relation
Definition: IRtRelation.h:14
fitman.k
k
Definition: fitman.py:528