2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
6 /********************************************************************************************/
7 /// Public Implementations
8 /********************************************************************************************/
12 inline unsigned int EMAPMatrixAxis::getNumberOfBins() const
14 return m_vecBins.size()-1;
17 inline int EMAPMatrixAxis::getBinIndex(double x) const
19 if ((x<m_vecBins[0]) || (m_vecBins[m_vecBins.size()-1]<x)) return -1;
20 for (unsigned int i=0; i<m_vecBins.size(); i++) {
21 if ((m_vecBins[i]<=x) && (x<m_vecBins[i+1])) {
28 inline bool EMAPMatrixAxis::isInRange(double x) const
30 return !((x<m_vecBins[0]) || (m_vecBins[m_vecBins.size()-1]<x));
33 // double EMAPMatrixAxis::getMeanOfBin(unsigned int i) const
35 // if (i>=m_vecBins.size()-1) return -1.0;
36 // return 0.5*(m_vecBins[i+1]-m_vecBins[i])+m_vecBins[i];
39 // double EMAPMatrixAxis::getWidthOfBin(unsigned int i) const
41 // if (i>=m_vecBins.size()-1) return -1.0;
42 // return (m_vecBins[i+1]-m_vecBins[i]);
46 // void EMAPMatrixAxis::setName(std::string name)
55 EMAPMatrix<T>::EMAPMatrix()
63 EMAPMatrix<T>::EMAPMatrix(const std::vector<EMAPMatrixAxis>& axes, const std::string& textDescription)
66 StatusCode sc = setupMatrix(axes);
68 throw std::invalid_argument("Could not set up the EMAPMatrix.");
70 setTextDescription(textDescription);
75 // EMAPMatrix<T>::EMAPMatrix(std::vector<EMAPMatrixAxis> axes, T emptyObject)
77 // // m_emptyObject = 0;
78 // setupMatrix(axes, emptyObject);
83 StatusCode EMAPMatrix<T>::setupMatrix(std::vector<EMAPMatrixAxis> axes)
87 m_dimensions=axes.size();
89 for (unsigned int i=0;i<m_dimensions;++i)
91 m_axis.push_back(axes.at(i));
93 return setupEntries();
98 EMAPMatrix<T>::~EMAPMatrix()
105 void EMAPMatrix<T>::clear()
111 m_textDescription = "";
116 unsigned int EMAPMatrix<T>::Index(const std::vector<unsigned int>& x) const
118 unsigned int index=0;
119 //assert(x.size()==m_dimensions);
120 if (x.size()!=m_dimensions)
122 std::cout<<"EMAPMatrix ERROR: Illegal Acces of Matrix "<<std::endl;
126 for (unsigned int i=0;i<m_dimensions;++i)
128 //assert(x.at(i)<=m_axis.at(i).getNumberOfBins());
129 if (!(x.at(i)<=m_axis.at(i).getNumberOfBins()))
131 std::cout<<"EMAPMatrix ERROR: Illegal Acces of Matrix "<<std::endl;
134 index+=m_base.at(i)*x.at(i);
140 std::vector<unsigned int> EMAPMatrix<T>::Index(unsigned int id)
142 std::vector<unsigned int> x;
143 for (int i=(int)(m_dimensions)-1;i>=0;i--) x.push_back(0);
144 //assert(id<m_matrix.size());
145 if (!(id<m_matrix.size()))
147 std::cout<<"EMAPMatrix ERROR: Illegal Acces of Matrix "<<std::endl;
151 for (int i=m_dimensions-1;i>0;i--)
153 x[i]=int((id*1.0)/(m_base.at(i)*1.0));
154 id-=x[i]*m_base.at(i);
161 // template <class T>
162 // T& EMAPMatrix<T>::Access(std::vector<unsigned int> x)
164 // return m_matrix[Index(x)];
169 // cppcheck-suppress passedByValue
170 StatusCode EMAPMatrix<T>::setBinContent(const std::vector<double>& x, T value)
172 std::vector<unsigned int> id;
173 if (x.size()==m_dimensions) {
174 for (unsigned int i=0;i<m_dimensions;++i) {
175 int bi=m_axis.at(i).getBinIndex(x.at(i));
179 return StatusCode::FAILURE;
182 m_matrix[Index(id)]=value;
183 return StatusCode::SUCCESS;
185 return StatusCode::FAILURE;
190 // cppcheck-suppress passedByValue
191 StatusCode EMAPMatrix<T>::setBinContent(double x, T value)
193 if (m_dimensions!=1) return StatusCode::FAILURE;;
194 std::vector<double> vec;
196 return setBinContent(vec, value);
200 // cppcheck-suppress passedByValue
201 StatusCode EMAPMatrix<T>::setBinContent(double x, double y, T value)
203 if (m_dimensions!=2) return StatusCode::FAILURE;;
204 std::vector<double> vec;
207 return setBinContent(vec, value);
211 // cppcheck-suppress passedByValue
212 StatusCode EMAPMatrix<T>::setBinContent(double x, double y, double z, T value)
214 if (m_dimensions!=3) return StatusCode::FAILURE;;
215 std::vector<double> vec;
219 return setBinContent(vec, value);
223 // cppcheck-suppress passedByValue
224 StatusCode EMAPMatrix<T>::setBinContent(double x, double y, double z, double u, T value)
226 if (m_dimensions!=4) return StatusCode::FAILURE;;
227 std::vector<double> vec;
232 return setBinContent(vec, value);
236 // cppcheck-suppress passedByValue
237 StatusCode EMAPMatrix<T>::setBinContent(double x, double y, double z, double u, double v, T value)
239 if (m_dimensions!=5) return StatusCode::FAILURE;
240 std::vector<double> vec;
246 return setBinContent(vec, value);
251 const T* EMAPMatrix<T>::getBinContent(double x) const
257 std::vector<double> vec;
259 return getBinContent(vec);
263 const T* EMAPMatrix<T>::getBinContent(double x, double y) const
269 std::vector<double> vec;
272 return getBinContent(vec);
276 const T* EMAPMatrix<T>::getBinContent(double x, double y, double z) const
282 std::vector<double> vec;
286 return getBinContent(vec);
290 const T* EMAPMatrix<T>::getBinContent(double x, double y, double z, double u) const
296 std::vector<double> vec;
301 return getBinContent(vec);
306 const T* EMAPMatrix<T>::getBinContent(double x, double y, double z, double u, double v) const
312 std::vector<double> vec;
318 return getBinContent(vec);
325 const T* EMAPMatrix<T>::getBinContent(const std::vector<double>& x) const
327 bool statusCode = true;
328 std::vector<unsigned int> id;
329 if (x.size()==m_dimensions)
331 for (unsigned int i=0;i<m_dimensions;++i)
333 int bi=m_axis.at(i).getBinIndex(x.at(i));
344 return &(m_matrix.at(Index(id)));
354 StatusCode EMAPMatrix<T>::setupEntries()
358 m_dimensions = m_axis.size();
359 for (unsigned int i=0;i<m_dimensions;++i) {
360 for (unsigned int j=i+1;j<m_dimensions;++j) {
361 if (m_axis.at(i).getName()==m_axis.at(j).getName()) {
362 return StatusCode::FAILURE;
367 unsigned int entries=1;
368 for (unsigned int i=0;i<m_dimensions;++i) {
369 entries*=m_axis.at(i).getNumberOfBins();
374 for (unsigned int i=0;i<entries;++i) {
375 m_matrix.push_back(dummyObject);
380 for (unsigned int i=0;i<m_dimensions;++i)
382 m_base.push_back(ib);
383 ib*=m_axis.at(i).getNumberOfBins();
386 return StatusCode::SUCCESS;
390 void EMAPMatrix<T>::clearEntries()
392 unsigned int entries=1;
393 for (unsigned int i=0;i<m_dimensions;++i)
395 entries*=m_axis.at(i).getNumberOfBins();
401 for (unsigned int i=0;i<entries;++i) {
402 m_matrix.push_back(dummyObject);
408 bool EMAPMatrix<T>::isInRange(const std::vector<double>& x) const
410 if (x.size()!=m_dimensions) return false;
411 for (unsigned int i=0;i<m_dimensions;++i) if (m_axis.at(i).isInRange(x.at(i))==false) return false;
416 void EMAPMatrix<T>::setTextDescription(const std::string& text)
418 m_textDescription = text;
422 const std::string& EMAPMatrix<T>::getTextDescription() const
424 return m_textDescription;