ATLAS Offline Software
TrRelationLookUp.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <algorithm>
9 
10 namespace MuonCalib{
11 
12  TrRelationLookUp::TrRelationLookUp(const IRtRelationPtr& rtRelation, const ParVec& vec) : ITrRelation{rtRelation, vec} {
13 
14  std::size_t numPoints(100);
15  double stepSize{rtRelation->radius(rtRelation->tUpper()) / (numPoints - 1)};
16  m_times = std::vector<double>(numPoints);
17  m_radii = std::vector<double>(numPoints);
18 
19  for(std::size_t i = 0; i < numPoints; ++i){
20  m_radii[i] = i * stepSize;
21  m_times[i] = getTFromR(m_radii[i], rtRelation);
22  }
23  m_minRadius = m_radii.front();
24  m_maxRadius = m_radii.back();
25  }
26 
27  std::string TrRelationLookUp::name() const { return "TrRelationLookUp"; }
28 
29  std::optional<double> TrRelationLookUp::driftTime(const double r) const {
30  if(r < minRadius()) return m_times.front();
31  if(r > maxRadius()) return m_times.back();
32  //Find the first element that is not less than r
33  auto it = std::lower_bound(m_radii.begin(), m_radii.end(), r);
34  //Find the distance to the element right before this one, since r lies between idx and idx+1
35  std::size_t idx = std::distance(m_radii.begin(), it) - 1;
36  double radius1 = m_radii[idx];
37  double radius2 = m_radii[idx + 1];
38  if (radius1 == radius2) return m_times[idx];
39  double time1 = m_times[idx];
40  double time2 = m_times[idx + 1];
41  return time1 + (time2 - time1) * (r - radius1) / (radius2 - radius1);
42  }
43 
44  std::optional<double> TrRelationLookUp::driftTimePrime(const double r) const {
45  if(r < minRadius() || r > maxRadius()) return 0.;
46  //do the same thing as above but return dt/dr
47  auto it = std::lower_bound(m_radii.begin(), m_radii.end(), r);
48  std::size_t idx = std::distance(m_radii.begin(), it) - 1;
49  double radius1 = m_radii[idx];
50  double radius2 = m_radii[idx + 1];
51  if (radius1 == radius2) return std::nullopt;
52  double time1 = m_times[idx];
53  double time2 = m_times[idx + 1];
54  return (time2 - time1) / (radius2 - radius1);
55  }
56 
57  std::optional<double> TrRelationLookUp::driftTime2Prime(const double r) const {
58  if(r < minRadius() || r > maxRadius()) return std::nullopt;
59  return 0.0;
60  }
61 
62  double TrRelationLookUp::minRadius() const { return m_minRadius; }
63  double TrRelationLookUp::maxRadius() const { return m_maxRadius; }
64 
65  double TrRelationLookUp::getTFromR(const double radius, const IRtRelationPtr& rtRelation) const {
66  double precision{0.001};
67  double tMax{rtRelation->tUpper()};
68  double tMin{rtRelation->tLower()};
69 
70  //Search for the drift time
71  while (tMax - tMin > 0.1 and std::abs(rtRelation->radius(0.5 * (tMin + tMax)) - radius) > precision) {
72  double midPoint = 0.5 * (tMin + tMax);
73  if (rtRelation->radius(midPoint) > radius) {
74  tMax = midPoint;
75  } else {
76  tMin = midPoint;
77  }
78  }
79  return 0.5 * (tMin + tMax);
80  }
81 }
beamspotman.r
def r
Definition: beamspotman.py:676
GeoModel::TransientConstSharedPtr< IRtRelation >
MuonCalib::TrRelationLookUp::driftTimePrime
virtual std::optional< double > driftTimePrime(const double r) const override final
Definition: TrRelationLookUp.cxx:44
MuonCalib::TrRelationLookUp::getTFromR
double getTFromR(const double radius, const IRtRelationPtr &rtRelation) const
Definition: TrRelationLookUp.cxx:65
TrRelationLookUp.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
MuonCalib::TrRelationLookUp::TrRelationLookUp
TrRelationLookUp(const IRtRelationPtr &rtRelation, const ParVec &vec={})
Definition: TrRelationLookUp.cxx:12
MuonCalib::TrRelationLookUp::driftTime2Prime
virtual std::optional< double > driftTime2Prime(const double r) const override final
Definition: TrRelationLookUp.cxx:57
MuonCalib::TrRelationLookUp::m_radii
std::vector< double > m_radii
Definition: TrRelationLookUp.h:24
MuonCalib::TrRelationLookUp::minRadius
virtual double minRadius() const override final
Returns the minimum drift-radius.
Definition: TrRelationLookUp.cxx:62
MuonCalib::TrRelationLookUp::m_times
std::vector< double > m_times
Definition: TrRelationLookUp.h:23
MuonCalib::TrRelationLookUp::name
virtual std::string name() const override final
Definition: TrRelationLookUp.cxx:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::CalibFunc::ParVec
std::vector< double > ParVec
Definition: CalibFunc.h:35
MuonCalib::TrRelationLookUp::m_maxRadius
double m_maxRadius
Definition: TrRelationLookUp.h:26
MuonCalib::TrRelationLookUp::maxRadius
virtual double maxRadius() const override final
Returns the maximum drift-radius.
Definition: TrRelationLookUp.cxx:63
MuonCalib::TrRelationLookUp::m_minRadius
double m_minRadius
Definition: TrRelationLookUp.h:25
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
MuonCalib::TrRelationLookUp::driftTime
virtual std::optional< double > driftTime(const double r) const override final
Interface method for fetching the drift-time from the radius Returns a nullopt if the time is out of ...
Definition: TrRelationLookUp.cxx:29
MuonCalib::ITrRelation
Definition: ITrRelation.h:13