ATLAS Offline Software
Loading...
Searching...
No Matches
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
9NAME: IdentifiedProfileHistogram
10PACKAGE: TRT_AlignData
11
12AUTHORS: Jorgen Beck Hansen
13CREATED: December 2005
14
15PURPOSE: 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
33template <typename SomeIDTag>
35public:
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
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;
70
71 //modifiers
72 bool fillEntry(const SomeIDTag& ident, const float& abcissa, const float& ordinate, const float& weight = 1.0);
73
74private:
75
76 unsigned int m_NumberOfBins;
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
89template <typename SomeIDTag>
90inline const std::string& IdentifiedProfileHistogram<SomeIDTag>::title() const {return m_NumberOfEntries.tag();}
91
92template <typename SomeIDTag>
94
95template <typename SomeIDTag>
97
98template <typename SomeIDTag>
100
101template <typename SomeIDTag>
103
104template <typename SomeIDTag>
105inline const std::vector<int>& IdentifiedProfileHistogram<SomeIDTag>::numberOfEntries(const SomeIDTag& ident) const {return m_NumberOfEntries[ident];}
106
107template <typename SomeIDTag>
108inline const std::vector<float>& IdentifiedProfileHistogram<SomeIDTag>::content(const SomeIDTag& ident) const {return m_Content[ident];}
109
110template <typename SomeIDTag>
111inline const std::vector<float>& IdentifiedProfileHistogram<SomeIDTag>::contentSquared(const SomeIDTag& ident) const {return m_ContentSquared[ident];}
112
113template <typename SomeIDTag>
115
116template <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
125template <typename SomeIDTag>
127{
128 return m_NumberOfEntries.existID(ident) ?
129 std::accumulate(m_NumberOfEntries[ident].begin(),m_NumberOfEntries[ident].end(),0) : 0;
130}
131
132template <typename SomeIDTag>
133inline 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
138template <typename SomeIDTag>
139inline 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
144template <typename SomeIDTag>
145inline 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
151template <typename SomeIDTag>
152inline float IdentifiedProfileHistogram<SomeIDTag>::globalAverageError(const SomeIDTag& ident) const{
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
160template <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
170template <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
189template <typename SomeIDTag>
190const std::vector<float> IdentifiedProfileHistogram<SomeIDTag>::abcissa() const{
191 std::vector<float> result(m_NumberOfBins, m_BinWidth);
193 for (int i=1;i<m_NumberOfBins;i++)
194 result[i]=result[i-1]+m_BinWidth;
195 return result;
196}
197
198template <typename SomeIDTag>
199const 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
209template <typename SomeIDTag>
210const 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
220template <typename SomeIDTag>
221const 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
231template <typename SomeIDTag>
232bool IdentifiedProfileHistogram<SomeIDTag>::fillEntry(const SomeIDTag& ident, const float& abcissa, const float& ordinate, const float& weight) {
234 return false;
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
Access and manipulate an indexed storage.
Definition ArrayStore.h:32
float globalAverage(const SomeIDTag &ident) const
const std::vector< float > & contentSquared(const SomeIDTag &ident) const
IdentifiedProfileHistogram(const std::string &a_title, const unsigned int &a_numberofbins, const float &a_loweredge, const float &a_upperedge, const std::vector< float > &a_lowerlimit, const std::vector< float > &a_upperlimit)
float globalAverageError(const SomeIDTag &ident) const
const std::string & title() const
ArrayStore< Identifier, std::vector< int > > m_NumberOfEntries
ArrayStore< Identifier, std::vector< float > > m_Content
int globalNumberOfEntries(const SomeIDTag &ident) const
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)
ArrayStore< Identifier, std::vector< float > > m_ContentSquared
const std::vector< float > abcissaError() const
const std::vector< float > average(const SomeIDTag &ident) const
const std::vector< int > & numberOfEntries(const SomeIDTag &ident) const
const std::vector< float > averageError(const SomeIDTag &ident) const
const std::vector< float > & content(const SomeIDTag &ident) const
float globalRMS(const SomeIDTag &ident) const
const std::vector< float > abcissa() const
const std::vector< float > rms(const SomeIDTag &ident) const
bool fillEntry(const SomeIDTag &ident, const float &abcissa, const float &ordinate, const float &weight=1.0)