ATLAS Offline Software
IdentifiedProfileHistogram.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRT_CALIBDATA__IDENTIFIEDPROFILEHISTOGRAM_H
6 #define TRT_CALIBDATA__IDENTIFIEDPROFILEHISTOGRAM_H
7 /********************************************************************
8 
9 NAME: IdentifiedProfileHistogram
10 PACKAGE: TRT_AlignData
11 
12 AUTHORS: Jorgen Beck Hansen
13 CREATED: December 2005
14 
15 PURPOSE: Mapped Storage/Access of profile-histograms
16 
17 
18 ********************************************************************/
19 
20 // INCLUDES:
21 
22 #include <vector>
23 #include <numeric>
24 #include <string>
25 #include <iostream>
26 
27 #include "CLHEP/Matrix/SymMatrix.h"
28 #include "CLHEP/Matrix/Vector.h"
29 #include <CLHEP/Matrix/Matrix.h>
30 
32 
33 template <typename SomeIDTag>
35 public:
36 
37  // Constructors
38  IdentifiedProfileHistogram(const std::string& a_title, const unsigned int& a_numberofbins,
39  const float& a_loweredge, const float& a_upperedge,
40  const float& a_lowerlimit = 0.0, const float& a_upperlimit = 0.0);
41  IdentifiedProfileHistogram(const std::string& a_title, const unsigned int& a_numberofbins,
42  const float& a_loweredge, const float& a_upperedge,
43  const std::vector<float>& a_lowerlimit, const std::vector<float>& a_upperlimit );
44 
45  // Destructor
46  virtual ~IdentifiedProfileHistogram() {}
47 
48  // Accessors
49  const std::string& title() const;
50  unsigned int numberOfBins() const;
51  float lowerEdge() const;
52  float upperEdge() const;
53  float binWidth() const;
54  const std::vector<int>& numberOfEntries(const SomeIDTag& ident) const;
55  const std::vector<float>& content(const SomeIDTag& ident) const;
56  const std::vector<float>& contentSquared(const SomeIDTag& ident) const;
57  int numberOfIDs() const;
58 
59  // Statistics calculators
60  const std::vector<float> abcissa() const;
61  const std::vector<float> abcissaError() const;
62  const std::vector<float> average(const SomeIDTag& ident) const;
63  const std::vector<float> rms(const SomeIDTag& ident) const;
64  const std::vector<float> averageError(const SomeIDTag& ident) const;
65  float globalAverage(const SomeIDTag& ident) const;
66  float globalRMS(const SomeIDTag& ident) const;
67  float globalAverageError(const SomeIDTag& ident) const;
68  int globalNumberOfEntries(const SomeIDTag& ident) const;
69  int totalNumberOfEntries() const;
70 
71  //modifiers
72  bool fillEntry(const SomeIDTag& ident, const float& abcissa, const float& ordinate, const float& weight = 1.0);
73 
74 private:
75 
76  unsigned int m_NumberOfBins;
77  float m_LowerEdge;
78  float m_BinWidth;
79  std::vector<float> m_LowerLimit;
80  std::vector<float> m_UpperLimit;
84 
85  // Do we want histograms summed over several IDs?
86 
87 };
88 
89 template <typename SomeIDTag>
90 inline const std::string& IdentifiedProfileHistogram<SomeIDTag>::title() const {return m_NumberOfEntries.tag();}
91 
92 template <typename SomeIDTag>
93 inline unsigned int IdentifiedProfileHistogram<SomeIDTag>::numberOfBins() const {return m_NumberOfBins;}
94 
95 template <typename SomeIDTag>
96 inline float IdentifiedProfileHistogram<SomeIDTag>::lowerEdge() const {return m_LowerEdge;}
97 
98 template <typename SomeIDTag>
99 inline float IdentifiedProfileHistogram<SomeIDTag>::upperEdge() const {return m_LowerEdge+float(m_NumberOfBins)*m_BinWidth;}
100 
101 template <typename SomeIDTag>
102 inline float IdentifiedProfileHistogram<SomeIDTag>::binWidth() const {return m_BinWidth;}
103 
104 template <typename SomeIDTag>
105 inline const std::vector<int>& IdentifiedProfileHistogram<SomeIDTag>::numberOfEntries(const SomeIDTag& ident) const {return m_NumberOfEntries[ident];}
106 
107 template <typename SomeIDTag>
108 inline const std::vector<float>& IdentifiedProfileHistogram<SomeIDTag>::content(const SomeIDTag& ident) const {return m_Content[ident];}
109 
110 template <typename SomeIDTag>
111 inline const std::vector<float>& IdentifiedProfileHistogram<SomeIDTag>::contentSquared(const SomeIDTag& ident) const {return m_ContentSquared[ident];}
112 
113 template <typename SomeIDTag>
114 inline int IdentifiedProfileHistogram<SomeIDTag>::numberOfIDs() const {return m_NumberOfEntries.numberOfIDs();}
115 
116 template <typename SomeIDTag>
118 {
119  int i=0;
120  for (typename ArrayStore<SomeIDTag, std::vector<int> >::map_citr itr=m_NumberOfEntries.cbegin();itr!=m_NumberOfEntries.cend();++itr)
121  i=std::accumulate(m_NumberOfEntries[itr->first].begin(),m_NumberOfEntries[itr->first].end(),i);
122  return i;
123 }
124 
125 template <typename SomeIDTag>
127 {
128  return m_NumberOfEntries.existID(ident) ?
129  std::accumulate(m_NumberOfEntries[ident].begin(),m_NumberOfEntries[ident].end(),0) : 0;
130 }
131 
132 template <typename SomeIDTag>
133 inline const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::abcissaError() const{
134  const std::vector<float> result(m_NumberOfBins, m_BinWidth/sqrt(12.0)); // strictly only valid for weight=CONST
135  return result;
136 }
137 
138 template <typename SomeIDTag>
139 inline float IdentifiedProfileHistogram<SomeIDTag>::globalAverage(const SomeIDTag& ident) const{
140  return globalNumberOfEntries(ident)>0 ?
141  std::accumulate(m_Content[ident].begin(),m_Content[ident].end(),0.0)/(float)globalNumberOfEntries(ident) : 0.0;
142 }
143 
144 template <typename SomeIDTag>
145 inline float IdentifiedProfileHistogram<SomeIDTag>::globalRMS(const SomeIDTag& ident) const{
146  return globalNumberOfEntries(ident)>0 ?
147  sqrt(std::accumulate(m_ContentSquared[ident].begin(),m_ContentSquared[ident].end(),0.0)/
148  (float)globalNumberOfEntries(ident)-globalAverage(ident)*globalAverage(ident)) : 0.0;
149 }
150 
151 template <typename SomeIDTag>
153  return globalNumberOfEntries(ident)>0 ?
154  globalRMS(ident)/sqrt((float)globalNumberOfEntries(ident)) : 0.0;
155 }
156 
157 #ifndef TRT_ALIGNDATA__IDENTIFIEDPROFILEHISTOGRAM_ICC
158 #define TRT_ALIGNDATA__IDENTIFIEDPROFILEHISTOGRAM_ICC
159 
160 template <typename SomeIDTag>
162  const unsigned int& a_numberofbins,
163  const float& a_loweredge, const float& a_upperedge,
164  const float& a_lowerlimit, const float& a_upperlimit) :
165  m_NumberOfBins(a_numberofbins),m_LowerEdge(a_loweredge),
166  m_BinWidth((a_upperedge-a_loweredge)/(float)a_numberofbins),
167  m_LowerLimit(a_numberofbins,a_lowerlimit),m_UpperLimit(a_numberofbins,a_upperlimit),
168  m_NumberOfEntries(a_title) {}
169 
170 template <typename SomeIDTag>
172  const unsigned int& a_numberofbins,
173  const float& a_loweredge, const float& a_upperedge,
174  const std::vector<float>& a_lowerlimit,
175  const std::vector<float>& a_upperlimit ) :
176  m_NumberOfBins(a_numberofbins),m_LowerEdge(a_loweredge),
177  m_BinWidth((a_upperedge-a_loweredge)/(float)a_numberofbins),
178  m_LowerLimit(a_lowerlimit), m_UpperLimit(a_upperlimit),m_NumberOfEntries(a_title){
179  if (a_lowerlimit.size()!=a_upperlimit.size()&& a_lowerlimit.size()!=a_numberofbins) {
180  std::cout<<"Inconsistent vector(s) of limits passed to IdentifiedProfileHistogram: "
181  << a_title << " -- limits ignored..." <<std::endl;
182  m_LowerLimit.clear();
183  m_UpperLimit.clear();
184  std::fill_n(std::back_inserter(m_LowerLimit), m_NumberOfBins, 0.0);
185  std::fill_n(std::back_inserter(m_UpperLimit), m_NumberOfBins, 0.0);
186  }
187 }
188 
189 template <typename SomeIDTag>
190 const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::abcissa() const{
191  std::vector<float> result(m_NumberOfBins, m_BinWidth);
192  result[0]=m_LowerEdge+m_BinWidth/2.0;
193  for (int i=1;i<m_NumberOfBins;i++)
194  result[i]=result[i-1]+m_BinWidth;
195  return result;
196 }
197 
198 template <typename SomeIDTag>
199 const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::average(const SomeIDTag& ident) const{
200  std::vector<float> result(m_NumberOfBins, 0.0);
201  if (!m_NumberOfEntries.existID(ident))
202 // return result();
203  return result;
204  for (int i=0;i<m_NumberOfBins;i++)
205  result[i]= m_NumberOfEntries[ident][i]>0 ? m_Content[ident][i]/(float)m_NumberOfEntries[ident][i] : 0.0;
206  return result;
207 }
208 
209 template <typename SomeIDTag>
210 const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::rms(const SomeIDTag& ident) const{
211  std::vector<float> result(m_NumberOfBins, 0.0);
212  if (!m_NumberOfEntries.existID(ident))
213 // return result();
214  return result;
215  for (int i=0;i<m_NumberOfBins;i++)
216  result[i]= m_NumberOfEntries[ident][i]>0 ? sqrt((m_ContentSquared[ident][i]-m_Content[ident][i]*m_Content[ident][i]/(float)m_NumberOfEntries[ident][i])/(float)m_NumberOfEntries[ident][i]) : 0.0;
217  return result;
218 }
219 
220 template <typename SomeIDTag>
221 const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::averageError(const SomeIDTag& ident) const{
222  std::vector<float> result(m_NumberOfBins, 0.0);
223  if (!m_NumberOfEntries.existID(ident))
224 // return result();
225  return result;
226  for (int i=0;i<m_NumberOfBins;i++)
227  result[i]= m_NumberOfEntries[ident][i]>0 ? sqrt(m_ContentSquared[ident][i]-m_Content[ident][i]*m_Content[ident][i]/(float)m_NumberOfEntries[ident][i])/(float)m_NumberOfEntries[ident][i] : 0.0;
228  return result;
229 }
230 
231 template <typename SomeIDTag>
232 bool IdentifiedProfileHistogram<SomeIDTag>::fillEntry(const SomeIDTag& ident, const float& abcissa, const float& ordinate, const float& weight) {
233  if (abcissa<m_LowerEdge||abcissa>m_LowerEdge+m_BinWidth*(float)m_NumberOfBins||m_NumberOfBins==0)
234  return false;
235  int bin=int((abcissa-m_LowerEdge)/m_BinWidth);
236  if (m_LowerLimit[bin]<m_UpperLimit[bin]&&(ordinate<m_LowerLimit[bin]||ordinate>m_UpperLimit[bin]))
237  return false;
238  if (!m_NumberOfEntries.existID(ident)){
239  m_NumberOfEntries.push_back(ident,std::vector<int>(m_NumberOfBins,0));
240  m_Content.push_back(ident, std::vector<float>(m_NumberOfBins, 0.0));
241  m_ContentSquared.push_back(ident, std::vector<float>(m_NumberOfBins, 0.0));
242  }
243  m_NumberOfEntries[ident][bin]++;
244  m_Content[ident][bin]+=weight*ordinate;
245  m_ContentSquared[ident][bin]+=weight*ordinate*ordinate;
246  return true;
247 }
248 
249 #endif // TRT_CALIBDATA__IDENTIFIEDPROFILEHISTOGRAM_ICC
250 
251 #endif // TRT_CALIBDATA__IDENTIFIEDPROFILEHISTOGRAM_H
252 
IdentifiedProfileHistogram::lowerEdge
float lowerEdge() const
Definition: IdentifiedProfileHistogram.h:96
IdentifiedProfileHistogram::m_ContentSquared
ArrayStore< SomeIDTag, std::vector< float > > m_ContentSquared
Definition: IdentifiedProfileHistogram.h:94
IdentifiedProfileHistogram::fillEntry
bool fillEntry(const SomeIDTag &ident, const float &abcissa, const float &ordinate, const float &weight=1.0)
Definition: IdentifiedProfileHistogram.h:232
IdentifiedProfileHistogram::binWidth
float binWidth() const
Definition: IdentifiedProfileHistogram.h:102
get_generator_info.result
result
Definition: get_generator_info.py:21
IdentifiedProfileHistogram::globalAverage
float globalAverage(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:139
IdentifiedProfileHistogram
Definition: IdentifiedProfileHistogram.h:34
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
IdentifiedProfileHistogram::title
const std::string & title() const
Definition: IdentifiedProfileHistogram.h:90
IdentifiedProfileHistogram::contentSquared
const std::vector< float > & contentSquared(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:111
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
ArrayStore.h
bin
Definition: BinsDiffFromStripMedian.h:43
ArrayStore
Definition: ArrayStore.h:32
IdentifiedProfileHistogram::IdentifiedProfileHistogram
IdentifiedProfileHistogram(const std::string &a_title, const unsigned int &a_numberofbins, const float &a_loweredge, const float &a_upperedge, const float &a_lowerlimit=0.0, const float &a_upperlimit=0.0)
Definition: IdentifiedProfileHistogram.h:161
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ArrayStore::cbegin
map_citr cbegin() const
begin/end const iterators
Definition: ArrayStore.h:144
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
IdentifiedProfileHistogram::numberOfIDs
int numberOfIDs() const
Definition: IdentifiedProfileHistogram.h:114
IdentifiedProfileHistogram::m_UpperLimit
std::vector< float > m_UpperLimit
Definition: IdentifiedProfileHistogram.h:91
IdentifiedProfileHistogram::rms
const std::vector< float > rms(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdentifiedProfileHistogram::average
const std::vector< float > average(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:199
IdentifiedProfileHistogram::m_LowerLimit
std::vector< float > m_LowerLimit
Definition: IdentifiedProfileHistogram.h:90
IdentifiedProfileHistogram::m_Content
ArrayStore< SomeIDTag, std::vector< float > > m_Content
Definition: IdentifiedProfileHistogram.h:93
IdentifiedProfileHistogram::upperEdge
float upperEdge() const
Definition: IdentifiedProfileHistogram.h:99
IdentifiedProfileHistogram::~IdentifiedProfileHistogram
virtual ~IdentifiedProfileHistogram()
Definition: IdentifiedProfileHistogram.h:57
IdentifiedProfileHistogram::globalRMS
float globalRMS(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:145
IdentifiedProfileHistogram::numberOfBins
unsigned int numberOfBins() const
Definition: IdentifiedProfileHistogram.h:93
IdentifiedProfileHistogram::m_BinWidth
float m_BinWidth
Definition: IdentifiedProfileHistogram.h:89
IdentifiedProfileHistogram::averageError
const std::vector< float > averageError(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:221
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
IdentifiedProfileHistogram::abcissa
const std::vector< float > abcissa() const
Definition: IdentifiedProfileHistogram.h:190
IdentifiedProfileHistogram::m_LowerEdge
float m_LowerEdge
Definition: IdentifiedProfileHistogram.h:88
IdentifiedProfileHistogram::totalNumberOfEntries
int totalNumberOfEntries() const
Definition: IdentifiedProfileHistogram.h:117
IdentifiedProfileHistogram::abcissaError
const std::vector< float > abcissaError() const
Definition: IdentifiedProfileHistogram.h:133
IdentifiedProfileHistogram::globalAverageError
float globalAverageError(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:152
IdentifiedProfileHistogram::m_NumberOfBins
unsigned int m_NumberOfBins
Definition: IdentifiedProfileHistogram.h:87
IdentifiedProfileHistogram::globalNumberOfEntries
int globalNumberOfEntries(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:126
IdentifiedProfileHistogram::m_NumberOfEntries
ArrayStore< SomeIDTag, std::vector< int > > m_NumberOfEntries
Definition: IdentifiedProfileHistogram.h:92
readCCLHist.float
float
Definition: readCCLHist.py:83
IdentifiedProfileHistogram::content
const std::vector< float > & content(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:108
IdentifiedProfileHistogram::numberOfEntries
const std::vector< int > & numberOfEntries(const SomeIDTag &ident) const
Definition: IdentifiedProfileHistogram.h:105