ATLAS Offline Software
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 
8 namespace 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 }
beamspotman.r
def r
Definition: beamspotman.py:676
TRTCond::BinnedRtRelation::m_tmax
float m_tmax
maximum drifttime
Definition: BinnedRtRelation.h:86
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TRTCond::BinnedRtRelation::drdt
virtual float drdt(float driftime) const
driftvelocity for given drifttime
Definition: BinnedRtRelation.cxx:35
TRTCond::BinnedRtRelation::read
virtual std::istream & read(std::istream &)
read from to ascii ostream
Definition: BinnedRtRelation.cxx:68
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TRTCond::BinnedRtRelation::write
virtual std::ostream & write(std::ostream &) const
write to ascii ostream
Definition: BinnedRtRelation.cxx:61
athena.value
value
Definition: athena.py:122
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TRTCond::BinnedRtRelation::drifttime
virtual float drifttime(float radius) const
drifttime for given radius
Definition: BinnedRtRelation.cxx:44
TRTCond::BinnedRtRelation::isequal
virtual bool isequal(const RtRelation &rhs) const
equality operator
Definition: BinnedRtRelation.cxx:13
TRTCond::RtRelation
Definition: RtRelation.h:27
TRTCond::BinnedRtRelation::m_values
std::vector< float > m_values
number of elements
Definition: BinnedRtRelation.h:87
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
CaloNoise_fillDB.dt
dt
Definition: CaloNoise_fillDB.py:58
BinnedRtRelation.h
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TRTCond
Definition: BasicRtRelation.cxx:8
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
TRTCond::BinnedRtRelation::binsize
float binsize() const
get access to bin size
Definition: BinnedRtRelation.h:81
TRTCond::BinnedRtRelation
Definition: BinnedRtRelation.h:27
TRTCond::BinnedRtRelation::radius
virtual float radius(float driftime) const
radius for given drifttime
Definition: BinnedRtRelation.cxx:20
TRTCond::BinnedRtRelation::m_tmin
float m_tmin
minimum drifttime
Definition: BinnedRtRelation.h:85