ATLAS Offline Software
Loading...
Searching...
No Matches
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
10namespace MuonCalib{
11 unsigned TrRelationLookUp::nDoF() const {
12 return m_times.size();
13 }
15
16 constexpr std::size_t numPoints(100);
17 double stepSize{rtRelation.radius(rtRelation.tUpper()) / (numPoints - 1)};
18 m_times.resize(numPoints);
19 m_radii.resize(numPoints);
20
21 for(std::size_t i = 0; i < numPoints; ++i){
22 m_radii[i] = i * stepSize;
23 m_times[i] = getTFromR(m_radii[i], rtRelation);
24 }
25 m_minRadius = m_radii.front();
26 m_maxRadius = m_radii.back();
27 }
28
29 std::string TrRelationLookUp::name() const { return "TrRelationLookUp"; }
30
31 std::optional<double> TrRelationLookUp::driftTime(const double r) const {
32 if(r < minRadius()) return m_times.front();
33 if(r > maxRadius()) return m_times.back();
34 //Find the first element that is not less than r
35 auto it = std::lower_bound(m_radii.begin(), m_radii.end(), r);
36 //Find the distance to the element right before this one, since r lies between idx and idx+1
37 std::size_t idx = std::distance(m_radii.begin(), it) - 1;
38 double radius1 = m_radii[idx];
39 double radius2 = m_radii[idx + 1];
40 if (radius1 == radius2) return m_times[idx];
41 double time1 = m_times[idx];
42 double time2 = m_times[idx + 1];
43 return time1 + (time2 - time1) * (r - radius1) / (radius2 - radius1);
44 }
45
46 std::optional<double> TrRelationLookUp::driftTimePrime(const double r) const {
47 if(r < minRadius() || r > maxRadius()) return 0.;
48 //do the same thing as above but return dt/dr
49 auto it = std::lower_bound(m_radii.begin(), m_radii.end(), r);
50 std::size_t idx = std::distance(m_radii.begin(), it) - 1;
51 double radius1 = m_radii[idx];
52 double radius2 = m_radii[idx + 1];
53 if (radius1 == radius2) return std::nullopt;
54 double time1 = m_times[idx];
55 double time2 = m_times[idx + 1];
56 return (time2 - time1) / (radius2 - radius1);
57 }
58
59 std::optional<double> TrRelationLookUp::driftTime2Prime(const double r) const {
60 if(r < minRadius() || r > maxRadius()) return std::nullopt;
61 return 0.0;
62 }
63
64 double TrRelationLookUp::minRadius() const { return m_minRadius; }
65 double TrRelationLookUp::maxRadius() const { return m_maxRadius; }
66
67 double TrRelationLookUp::getTFromR(const double radius, const IRtRelation& rtRelation) const {
68 double precision{0.001};
69 double tMax{rtRelation.tUpper()};
70 double tMin{rtRelation.tLower()};
71
72 //Search for the drift time
73 while (tMax - tMin > 0.1 and std::abs(rtRelation.radius(0.5 * (tMin + tMax)) - radius) > precision) {
74 double midPoint = 0.5 * (tMin + tMax);
75 if (rtRelation.radius(midPoint) > radius) {
76 tMax = midPoint;
77 } else {
78 tMin = midPoint;
79 }
80 }
81 return 0.5 * (tMin + tMax);
82 }
83}
std::vector< double > ParVec
Definition CalibFunc.h:35
generic interface for a rt-relation
Definition IRtRelation.h:19
virtual double tLower() const =0
Returns the lower time covered by the r-t.
virtual double radius(double t) const =0
returns drift radius for a given time
virtual double tUpper() const =0
Returns the upper time covered by the r-t.
ITrRelation(const ParVec &parameters)
Constructor taking the input r-t relation & the vector of parameters.
Definition ITrRelation.h:20
std::vector< double > m_radii
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 ...
virtual std::optional< double > driftTimePrime(const double r) const override final
virtual std::string name() const override final
double getTFromR(const double radius, const IRtRelation &rtRelation) const
virtual std::optional< double > driftTime2Prime(const double r) const override final
std::vector< double > m_times
virtual double minRadius() const override final
Returns the minimum drift-radius.
virtual unsigned nDoF() const override final
Returns the number of degrees of freedom of the tr relation.
virtual double maxRadius() const override final
Returns the maximum drift-radius.
TrRelationLookUp(const IRtRelation &rtRelation)
int r
Definition globals.cxx:22
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.