2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
9 TBProfiler<T>::TBProfiler()
10 : m_channelFill(false)
16 TBProfiler<T>::TBProfiler(size_t theSize)
20 m_skipFlag = ! this->setupAction(theSize);
24 TBProfiler<T>::TBProfiler(size_t storeSize, const T& lowerLimit,
26 : m_channelFill(false),
29 if ( storeSize > 0 && upperLimit > lowerLimit )
31 m_binLimits.resize(storeSize+1,0);
32 m_binLimits[0] = lowerLimit;
33 m_deltaBin = ( upperLimit - lowerLimit ) / ((T)storeSize);
34 for ( unsigned int i=1; i<m_binLimits.size(); i++ )
36 m_binLimits[i] = m_binLimits[i-1] + m_deltaBin;
38 m_skipFlag = ! this->setupAction(storeSize);
47 TBProfiler<T>::~TBProfiler()
51 void TBProfiler<T>::addData(const T& theChannel, const T& theData)
53 if ( ! m_skipFlag && ! m_channelFill )
56 if ( ( theIndex = this->getIndex(theChannel) ) != size_t(-1) )
58 this->addData(theIndex,theData);
64 void TBProfiler<T>::addData(const std::vector<T>& theData)
66 if ( m_skipFlag ) return;
68 for ( size_t i=0; i<std::min(theData.size(),m_sum.size()); i++ )
70 m_sum[i] += theData[i];
71 m_sumOfSquares[i] += theData[i] * theData[i];
78 void TBProfiler<T>::addData(size_t theIndex,const T& theData)
80 if ( m_skipFlag ) return;
82 if ( theIndex < m_sum.size() )
84 m_sum[theIndex] += theData;
85 m_sumOfSquares[theIndex] += theData * theData;
86 m_entries[theIndex]++;
91 bool TBProfiler<T>::getAverages(std::vector<T>& theAverages) const
93 if ( m_skipFlag ) return false;
96 for ( size_t i=0; i<std::min(theAverages.size(),m_sum.size()); i++ )
98 if ( m_entries[i] > 0 )
101 theAverages[i] = m_sum[i] / ((T)m_entries[i]);
104 return changeCtr > 0;
108 bool TBProfiler<T>::getAverages(size_t theIndex, T& theAverage) const
110 if ( m_skipFlag ) return false;
113 if ( (checkOut = ( theIndex < m_sum.size() && m_entries[theIndex] > 0 ) ) )
115 theAverage = m_sum[theIndex]/((T)m_entries[theIndex]);
121 bool TBProfiler<T>::getStandardDevs(std::vector<T>& theVariances) const
123 if ( m_skipFlag ) return false;
125 size_t changeCtr = 0;
126 for ( size_t i=0; i<std::min(theVariances.size(),m_sum.size()); i++ )
128 if ( m_entries[i] > 0 )
131 T theDiff = m_sumOfSquares[i] - m_sum[i] * m_sum[i];
132 theVariances[i] = theDiff >=0
133 ? sqrt(theDiff) : -sqrt(fabs(theDiff));
136 return changeCtr > 0;
140 bool TBProfiler<T>::getStandardDevs(size_t theIndex,T& theVariance) const
142 if ( m_skipFlag ) return false;
145 if (( checkOut = ( theIndex < m_sum.size() && m_entries[theIndex] > 0 ) ))
147 T theDev = m_sumOfSquares[theIndex] - m_sum[theIndex] * m_sum[theIndex];
148 theVariance = theDev > 0 ? sqrt(theDev) : -sqrt(fabs(theDev));
154 bool TBProfiler<T>::getErrors(std::vector<T>& theErrors) const
156 if ( m_skipFlag ) return false;
158 size_t changeCtr = 0;
159 std::vector<T> theDevs;
160 if ( this->getStandardDevs(theDevs) )
162 for ( size_t i=0; i<std::min(theErrors.size(),m_sum.size()); i++ )
164 if ( m_entries[i] > 0 )
167 theErrors[i] = theDevs[i] / sqrt((T)m_entries[i]);
171 return changeCtr > 0;
175 bool TBProfiler<T>::getErrors(size_t theIndex, T& theError) const
177 if ( m_skipFlag ) return false;
180 if (( checkOut = this->getStandardDevs(theIndex,theError) ))
182 theError /= sqrt((T)m_entries[theIndex]);
188 bool TBProfiler<T>::getBinEntries(std::vector<size_t>& theEntries) const
190 if ( m_skipFlag ) return false;
193 theEntries.insert(++theEntries.begin(),m_entries.begin(),m_entries.end());
195 return theEntries.size() > 0;
199 bool TBProfiler<T>::getBinEntries(size_t theIndex,size_t& theEntries) const
201 if ( m_skipFlag ) return false;
203 if ( theIndex < m_entries.size() )
205 theEntries = m_entries[theIndex];
216 const std::vector<T>& TBProfiler<T>::getSums() const
222 const std::vector<T>& TBProfiler<T>::getSumOfSquares() const
224 return m_sumOfSquares;
228 const std::vector<size_t>& TBProfiler<T>::getEntries() const
234 size_t TBProfiler<T>::getNumberOfChannels() const
236 return m_binLimits.size()-1;
240 T TBProfiler<T>::getChannelWidth() const
246 T TBProfiler<T>::getMinChannel() const
248 return ! m_channelFill && ! m_skipFlag
254 T TBProfiler<T>::getMaxChannel() const
256 return ! m_channelFill && ! m_skipFlag
257 ? m_binLimits[m_binLimits.size()-1]
262 size_t TBProfiler<T>::getIndex(const T& theChannel) const
264 if ( m_skipFlag ) return size_t(-1);
267 ( theChannel >= m_binLimits[0] ||
268 theChannel < m_binLimits[m_binLimits.size()-1] )
269 ? (size_t)floor(( theChannel - m_binLimits[0] ) / m_deltaBin)
274 bool TBProfiler<T>::setupAction(size_t theSize)
278 m_sum.resize(theSize,0);
279 m_sumOfSquares.resize(theSize,0);
280 m_entries.resize(theSize,0);