ATLAS Offline Software
LArWave.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <algorithm>
7 
8 // private constructor from two waves
9 LArWave::LArWave(const LArWave& theWave1 , const LArWave& theWave2)
10  : m_flag(0)
11 {
12  if ( theWave1.m_dt == theWave2.m_dt ) {
13  m_dt = theWave1.m_dt ;
14  m_amplitudes.resize( std::min( theWave1.getSize(),
15  theWave2.getSize() )) ;
16  } else {
17  m_amplitudes.resize(0);
18  m_dt = 0. ;
19  }
20 }
21 
22 // algebra
23 
24 LArWave LArWave::operator+(const LArWave& bWave) const
25 {
26  LArWave result(*this,bWave) ;
27  const size_t s=result.getSize();
28  for ( size_t i=0 ; i<s ; ++i ) {
29  result.m_amplitudes[i] =
30  (*this).m_amplitudes[i] + bWave.m_amplitudes[i] ;
31  }
32  return result ;
33 }
34 
36 {
37  const size_t s=std::min(m_amplitudes.size(), bWave.getSize());
38  for ( size_t i=0 ; i<s ; ++i ) {
39  m_amplitudes[i] += bWave.m_amplitudes[i] ;
40  }
41  return *this;
42 }
43 
44 
45 
46 LArWave LArWave::operator-(const LArWave& bWave) const
47 {
48  LArWave result(*this,bWave) ;
49  const size_t s=result.getSize();
50  for ( size_t i=0 ; i<s ; ++i ) {
51  result.m_amplitudes[i] =
52  (*this).m_amplitudes[i] - bWave.m_amplitudes[i] ;
53  }
54  return result ;
55 }
56 
57 
59 {
60  const size_t s=std::min(m_amplitudes.size(), bWave.getSize());
61  for ( size_t i=0 ; i<s ; ++i ) {
62  m_amplitudes[i] -= bWave.m_amplitudes[i] ;
63  }
64  return *this;
65 }
66 
67 
68 
69 LArWave LArWave::operator*(const LArWave& bWave) const
70 {
71  LArWave result(*this,bWave) ;
72  const size_t s=result.getSize();
73  for ( size_t i=0 ; i<s ; ++i ) {
74  result.m_amplitudes[i] =
75  (*this).m_amplitudes[i] * bWave.m_amplitudes[i] ;
76  }
77  return result ;
78 }
79 
80 LArWave LArWave::operator/(const LArWave& bWave) const
81 {
82  LArWave result(*this,bWave) ;
83  const size_t s=result.getSize();
84  for ( size_t i=0 ; i<s ; ++i ) {
85  result.m_amplitudes[i] =
86  (*this).m_amplitudes[i] / bWave.m_amplitudes[i] ;
87  }
88  return result ;
89 }
90 
91 LArWave LArWave::operator%(const LArWave& bWave) const
92 {
93  //W.L., 2-Sept-09: Speed-up:
94  //This method is called several million times
95  //aggressive optimization pays off.
96 
97  const double* amplPtrA=&(this->m_amplitudes.front());
98  const double* amplPtrB=&(bWave.m_amplitudes.front());
99 
100  LArWave result(*this,bWave) ;
101  const size_t s=result.getSize();
102  for (size_t i=0 ; i<s ; ++i ) {
103  //double& resSample=result.m_amplitudes[i];
104  double sum2 = 0.5 * ( (*this).m_amplitudes[0] * bWave.m_amplitudes[i] +
105  (*this).m_amplitudes[i] * bWave.m_amplitudes[0] ) ;
106  for (size_t k=1 ; k<i ; ++k ) {
107  sum2 += amplPtrA[k] * amplPtrB[i-k] ;
108  }
109  result.m_amplitudes[i] = sum2*result.m_dt ;
110  }
111  return result ;
112 }
113 
114 
115 LArWave LArWave::operator+(const double aBias) const {
116  LArWave result(*this) ;
117  std::vector<double>::iterator it=result.m_amplitudes.begin();
118  std::vector<double>::iterator it_e=result.m_amplitudes.end();
119  for (;it!=it_e;++it) {
120  (*it)+=aBias;
121  }
122  return result ;
123 }
124 
125 
126 LArWave LArWave::operator*(const double aScale) const{
127  LArWave result(*this) ;
128  std::vector<double>::iterator it=result.m_amplitudes.begin();
129  std::vector<double>::iterator it_e=result.m_amplitudes.end();
130  for (;it!=it_e;++it) {
131  (*it)*=aScale;
132  }
133  return result ;
134 }
135 
136 
137 LArWave& LArWave::operator*=(const double aScale) {
138  for (double& a : m_amplitudes) {
139  a*=aScale;
140  }
141  return *this ;
142 }
143 
144 
145 
146 unsigned LArWave::getIndex(const double aTime) const
147 { return (aTime>=0 && m_dt>0) ? (unsigned)(aTime/m_dt) : getSize()+1 ; }
LArWave
Definition: LArWave.h:31
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LArWave::operator%
LArWave operator%(const LArWave &bWave) const
Definition: LArWave.cxx:91
LArWave::m_amplitudes
std::vector< double > m_amplitudes
Definition: LArWave.h:112
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
LArWave::getSize
size_t getSize() const
number of time samples
Definition: LArWave.h:62
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArWave::operator-
LArWave operator-(const LArWave &bWave) const
Definition: LArWave.cxx:46
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
LArWave::m_dt
double m_dt
Definition: LArWave.h:111
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArWave::operator-=
LArWave & operator-=(const LArWave &bWave)
Definition: LArWave.cxx:58
LArWave::operator+=
LArWave & operator+=(const LArWave &bWave)
Definition: LArWave.cxx:35
LArWave::operator/
LArWave operator/(const LArWave &bWave) const
Definition: LArWave.cxx:80
LArWave::operator+
LArWave operator+(const LArWave &bWave) const
Definition: LArWave.cxx:24
min
#define min(a, b)
Definition: cfImp.cxx:40
LArWave::getIndex
unsigned getIndex(double aTime) const
index for a time value
Definition: LArWave.cxx:146
LArWave::LArWave
LArWave()
Definition: LArWave.h:147
a
TList * a
Definition: liststreamerinfos.cxx:10
LArWave::operator*
LArWave operator*(const LArWave &bWave) const
Definition: LArWave.cxx:69
LArWave.h
LArWave::operator*=
LArWave & operator*=(const double aScale)
Definition: LArWave.cxx:137
fitman.k
k
Definition: fitman.py:528