ATLAS Offline Software
RtRelationLookUp.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONCALIB_RTRELATIONLOOKUP_H
6 #define MUONCALIB_RTRELATIONLOOKUP_H
7 
8 #include <climits>
9 #include <iostream>
10 
12 #include "GaudiKernel/MsgStream.h"
14 
15 namespace MuonCalib {
16 
24  class RtRelationLookUp : public IRtRelation {
25  public:
26  explicit RtRelationLookUp(const ParVec &vec) : IRtRelation(vec) {
27  if (vec.size() < 4) {
28  m_t_min = 9e9;
29  m_bin_size = 1.0; // will be always out of range
30  MsgStream log(Athena::getMessageSvc(), "RtRelationLookUp");
31  log << MSG::WARNING << "<to few parameters>" << endmsg;
32  } else {
33  m_t_min = par(0);
34  m_bin_size = par(1);
35  if (m_bin_size == 0) {
36  MsgStream log(Athena::getMessageSvc(), "RtRelationLookUp");
37  log << MSG::WARNING << "<bin size=0>" << endmsg;
38  }
39  }
40  }
41 
42  std::string name() const { return "RtRelationLookUp"; }
43 
45  double radius(double t) const;
46 
48  double driftvelocity(double t) const;
49 
51  inline double tLower(void) const;
52  inline double tUpper(void) const;
53 
54  private:
55  int getBin(double t) const {
56  double t_minus_tmin(t - m_t_min);
57  double rel = t_minus_tmin / m_bin_size;
58  if (rel < static_cast<double>(INT_MIN)) return INT_MIN;
59  if (rel > static_cast<double>(INT_MAX)) return INT_MAX;
60  return static_cast<int>(rel);
61  }
62 
63  // take offset due to m_t_min and binsize into account
64  int rtBins() const { return nPar() - 2; }
65  double getRadius(int bin) const { return par(bin + 2); }
66  // returns best matching bin within rtRange
67  int binInRtRange(double t) const;
68 
69  double m_t_min;
70  double m_bin_size;
71  };
72 
73  inline double RtRelationLookUp::radius(double t) const {
74  // get best matching bin in rt range
75  int bin = binInRtRange(t);
76 
77  // shift bin so we are using the last two bins for extrapolation
78  if (bin >= rtBins() - 1) bin = rtBins() - 2;
79 
80  double r1 = getRadius(bin); // get bin value
81  double r2 = getRadius(bin + 1); // get value of next bin
82  double dr = r2 - r1;
83 
84  // scale factor for interpolation
85  double scale = (t - m_t_min) / m_bin_size - (double)bin;
86 
87  double r = r1 + dr * scale;
88 
89  return r >= 0 ? r : 0;
90  }
91 
92  inline double RtRelationLookUp::driftvelocity(double t) const {
93  // get best matching bin in rt range
94  int bin = binInRtRange(t);
95 
96  // shift bin so we are using the last two bins for extrapolation
97  if (bin >= rtBins() - 1) bin = rtBins() - 2;
98 
99  double r1 = getRadius(bin); // get bin value
100  double r2 = getRadius(bin + 1); // get value of next bin
101  double dr = r2 - r1;
102 
103  double v = dr / m_bin_size;
104 
105  return v;
106  }
107 
108  inline int RtRelationLookUp::binInRtRange(double t) const {
109  // get bin
110  int bin = getBin(t);
111 
112  // if t corresponds to a negativ bin return first
113  if (bin < 0) bin = 0;
114 
115  // if t corresponds to a bin outside the range of the lookup table return the last bin
116  if (bin >= rtBins()) bin = rtBins() - 1;
117 
118  return bin;
119  }
120 
121  inline double RtRelationLookUp::tLower(void) const { return m_t_min; }
122 
123  inline double RtRelationLookUp::tUpper(void) const { return m_t_min + m_bin_size * rtBins(); }
124 
125 } // namespace MuonCalib
126 #endif
beamspotman.r
def r
Definition: beamspotman.py:676
MuonCalib::RtRelationLookUp::binInRtRange
int binInRtRange(double t) const
Definition: RtRelationLookUp.h:108
skel.rel
rel
Announce start of JO checkingrelease nimber checking.
Definition: skel.GENtoEVGEN.py:182
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::RtRelationLookUp::getBin
int getBin(double t) const
Definition: RtRelationLookUp.h:55
MuonCalib::RtRelationLookUp::tLower
double tLower(void) const
return rt range
Definition: RtRelationLookUp.h:121
MuonCalib::RtRelationLookUp::RtRelationLookUp
RtRelationLookUp(const ParVec &vec)
Definition: RtRelationLookUp.h:26
bin
Definition: BinsDiffFromStripMedian.h:43
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
MuonCalib::RtRelationLookUp::getRadius
double getRadius(int bin) const
Definition: RtRelationLookUp.h:65
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MuonCalib::RtRelationLookUp
Equidistant look up table for rt-relations with the time as key.
Definition: RtRelationLookUp.h:24
MuonCalib::RtRelationLookUp::driftvelocity
double driftvelocity(double t) const
returns drift velocity for a given time
Definition: RtRelationLookUp.h:92
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
MuonCalib::RtRelationLookUp::m_bin_size
double m_bin_size
Definition: RtRelationLookUp.h:70
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::CalibFunc::par
double par(unsigned int index) const
Definition: CalibFunc.h:41
MuonCalib::CalibFunc::ParVec
std::vector< double > ParVec
Definition: CalibFunc.h:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::RtRelationLookUp::m_t_min
double m_t_min
Definition: RtRelationLookUp.h:69
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
MuonCalib::RtRelationLookUp::name
std::string name() const
Definition: RtRelationLookUp.h:42
python.PyAthena.v
v
Definition: PyAthena.py:157
IRtRelation.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::CalibFunc::nPar
unsigned int nPar() const
Definition: CalibFunc.h:39
MuonCalib::RtRelationLookUp::radius
double radius(double t) const
returns drift radius for a given time
Definition: RtRelationLookUp.h:73
MuonCalib::RtRelationLookUp::rtBins
int rtBins() const
Definition: RtRelationLookUp.h:64
MuonCalib::IRtRelation
generic interface for a rt-relation
Definition: IRtRelation.h:14
MuonCalib::RtRelationLookUp::tUpper
double tUpper(void) const
Definition: RtRelationLookUp.h:123