ATLAS Offline Software
Loading...
Searching...
No Matches
RtRelationLookUp.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
5
7#include <GaudiKernel/MsgStream.h>
8namespace MuonCalib{
9
12 if (vec.size() < 4) {
13 m_t_min = 9e9;
14 m_bin_size = 1.0; // will be always out of range
15 MsgStream log(Athena::getMessageSvc(), "RtRelationLookUp");
16 log << MSG::WARNING << "<to few parameters>" << endmsg;
17 } else {
18 m_t_min = par(0);
19 m_bin_size = par(1);
20 if (m_bin_size == 0) {
21 MsgStream log(Athena::getMessageSvc(), "RtRelationLookUp");
22 log << MSG::WARNING << "<bin size=0>" << endmsg;
23 }
24 }
25 }
26 unsigned RtRelationLookUp::nDoF() const{
27 return nPar() -2;
28 }
29
30 inline int RtRelationLookUp::getBin(double t) const {
31 double t_minus_tmin{t - m_t_min};
32 double rel = t_minus_tmin / m_bin_size;
33 if (rel < static_cast<double>(INT_MIN)) return INT_MIN;
34 if (rel > static_cast<double>(INT_MAX)) return INT_MAX;
35 return static_cast<int>(rel);
36 }
37
38 double RtRelationLookUp::radius(double t) const {
39 // get best matching bin in rt range
40 int bin = binInRtRange(t);
41
42 // shift bin so we are using the last two bins for extrapolation
43 if (static_cast<unsigned>(bin) >= nDoF() - 1) bin = nDoF() - 2;
44
45 double r1 = getRadius(bin); // get bin value
46 double r2 = getRadius(bin + 1); // get value of next bin
47 double dr = r2 - r1;
48
49 // scale factor for interpolation
50 double scale = (t - m_t_min) / m_bin_size - (double)bin;
51
52 double r = r1 + dr * scale;
53
54 return r >= 0 ? r : 0;
55 }
56
57 double RtRelationLookUp::driftVelocity(double t) const {
58 // get best matching bin in rt range
59 int bin = binInRtRange(t);
60
61 // shift bin so we are using the last two bins for extrapolation
62 if (static_cast<unsigned>(bin) >= nDoF() - 1) bin = nDoF() - 2;
63
64 double r1 = getRadius(bin); // get bin value
65 double r2 = getRadius(bin + 1); // get value of next bin
66 double dr = r2 - r1;
67
68 double v = dr / m_bin_size;
69
70 return v;
71 }
72 double RtRelationLookUp::driftAcceleration(double t) const {
73 return (driftVelocity(t+1) - driftVelocity(t-1)) / 2.;
74 }
75
76 inline int RtRelationLookUp::binInRtRange(double t) const {
77 // get bin
78 int bin = getBin(t);
79
80 // if t corresponds to a negativ bin return first
81 if (bin < 0) bin = 0;
82
83 // if t corresponds to a bin outside the range of the lookup table return the last bin
84 if (static_cast<unsigned>(bin) >= nDoF()) bin = nDoF() - 1;
85
86 return bin;
87 }
88
89 double RtRelationLookUp::tLower() const { return m_t_min; }
90 double RtRelationLookUp::tUpper() const { return m_t_min + m_bin_size * nDoF(); }
91 double RtRelationLookUp::tBinWidth() const {return m_bin_size; }
92}
93
std::vector< size_t > vec
int getBin(double x, double min, double step, int clamp_max)
unsigned int nPar() const
Definition CalibFunc.h:39
std::vector< double > ParVec
Definition CalibFunc.h:35
generic interface for a rt-relation
Definition IRtRelation.h:19
int binInRtRange(double t) const
RtRelationLookUp(const ParVec &vec)
virtual double tBinWidth() const override final
Returns the step-size for the sampling.
virtual double radius(double t) const override final
returns drift radius for a given time
virtual double driftVelocity(double t) const override final
returns drift velocity for a given time
virtual double driftAcceleration(double t) const override final
returns the acceleration for a given time
virtual unsigned nDoF() const override final
Returns the number of degrees of freedom of the relation function.
double getRadius(int bin) const
virtual double tLower() const override final
return rt range
virtual double tUpper() const override final
Returns the upper time covered by the r-t.
singleton-like access to IMessageSvc via open function and helper
int r
Definition globals.cxx:22
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.