ATLAS Offline Software
Loading...
Searching...
No Matches
BinnedRtRelation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
7
8namespace TRTCond
9{
10
11
12
13 bool BinnedRtRelation::isequal( const RtRelation& rhs) const
14 {
15 const BinnedRtRelation* rhscast=dynamic_cast<const BinnedRtRelation*>(&rhs) ;
16 return rhscast!=nullptr && *this==*rhscast ;
17 }
18
19
20 float BinnedRtRelation::radius( float time ) const
21 {
22 float r(0) ;
23 if( time <= m_tmin ) r = m_values.front() ;
24 else if(time >= m_tmax ) r = m_values.back() ;
25 else {
26 // interpolate
27 float rtimebin = (time - m_tmin) / binsize() ;
28 size_t timebin = int(rtimebin) ;
29 float fracbin = rtimebin - timebin ;
30 r = (1-fracbin)*m_values[timebin] + fracbin*m_values[timebin+1] ;
31 }
32 return r ;
33 }
34
35 float BinnedRtRelation::drdt( float time ) const
36 {
37 float dt = binsize() ;
38 int timebin = int((time - m_tmin) / dt) ;
39 if( time <= m_tmin ) return 0 ;
40 else if(time >= m_tmax ) return 0 ;
41 else return (m_values[timebin+1]-m_values[timebin])/dt ;
42 }
43
44 float BinnedRtRelation::drifttime(float r) const
45 {
46 double t ;
47 if(r <= m_values.front()) t = m_tmin ;
48 else if(r >= m_values.back()) t = m_tmax ;
49 else {
50 // first find the bin with a binary search
51 std::vector<float>::const_iterator it = std::lower_bound(m_values.begin(),m_values.end(),r) ;
52 size_t timebin = it - m_values.begin() - 1 ;
53 // fraction in this bin
54 float fracbin = (r - m_values[timebin])/(m_values[timebin+1]-m_values[timebin]) ;
55 // now get the time
56 t = m_tmin + binsize() * (timebin + fracbin) ;
57 }
58 return t ;
59 }
60
61 std::ostream& BinnedRtRelation::write( std::ostream& os ) const
62 {
63 os << m_tmin << " " << m_tmax << " " << m_values.size() << " " ;
64 for(float value : m_values) os << value << " " ;
65 return os ;
66 }
67
68 std::istream& BinnedRtRelation::read( std::istream& is )
69 {
70 size_t n(0) ;
71 is >> m_tmin >> m_tmax >> n ;
72 if(n<UINT_MAX){
73 m_values.resize(n) ;
74 for(size_t i=0; i<n; ++i) is >> m_values[i] ;
75 }
76 return is ;
77 }
78
79}
virtual std::istream & read(std::istream &)
read from to ascii ostream
std::vector< float > m_values
number of elements
virtual bool isequal(const RtRelation &rhs) const
equality operator
float m_tmin
minimum drifttime
float m_tmax
maximum drifttime
float binsize() const
get access to bin size
virtual float drdt(float driftime) const
driftvelocity for given drifttime
virtual float radius(float driftime) const
radius for given drifttime
virtual std::ostream & write(std::ostream &) const
write to ascii ostream
virtual float drifttime(float radius) const
drifttime for given radius
BinnedRtRelation()
default constructor
RtRelation()=default
constructors, desctructors, cloners
int r
Definition globals.cxx:22