ATLAS Offline Software
PolygonBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 #include <cstdlib>
8 #include "GeoModelKernel/throwExcept.h"
9 using namespace MuonCalib;
10 
11 PolygonBase::PolygonBase(const std::vector<double> & x) {
12 
13  // CHECK FOR CORRECT FILLING
14  for (unsigned int k=0; k<x.size()-1; k++) {
15  if (x[k]>=x[k+1]) {
16  THROW_EXCEPTION("PolygonBase::init - Abscissae not in increasing order!");
17  }
18  }
19  // TRANSFER THE INPUT DATA //
20  m_x = x;
21 }
22 double PolygonBase::value(const int k, const double x) const {
23 
24  // CHECK THE BASE FUNCTION INDEX //
25  if (k<0 || k>static_cast<int>(m_x.size()-1)) {
26  THROW_EXCEPTION("PolygonBase::value - Illegal function index "<<k<<"! Should be >0 and "<<m_x.size());
27  }
28 
29  // outside the domain of the polygon //
30  if (x<m_x[0] || x>m_x[m_x.size()-1]) {
31  return 0.0;
32  }
33  // inside the domain of the polygon //
34  if (k==0 && x<m_x[0]) {
35  return 0.0;
36  }
37  if (k==0 && x<=m_x[1]) {
38  return (m_x[1]-x)/(m_x[1]-m_x[0]);
39  }
40  if (k==0 && x>m_x[1]) {
41  return 0.0;
42  }
43  if (static_cast<unsigned int>(k)==m_x.size()-1 &&
44  x<=m_x[m_x.size()-2]) {
45  return 0.0;
46  }
47  if (static_cast<unsigned int>(k)==m_x.size()-1 &&
48  x<=m_x[m_x.size()-1]) {
49  return (x-m_x[k-1])/(m_x[k]-m_x[k-1]);
50  }
51  if (static_cast<unsigned int>(k)==m_x.size()-1 &&
52  x>m_x[m_x.size()-1]) {
53  return 0.0;
54  }
55  if (x<m_x[k-1] || x>m_x[k+1]) {
56  return 0.0;
57  }
58 
59  if (x<m_x[k]) {
60  return (x-m_x[k-1])/(m_x[k]-m_x[k-1]);
61  }
62  return (m_x[k+1]-x)/(m_x[k+1]-m_x[k]);
63 }
MuonCalib::PolygonBase::PolygonBase
PolygonBase(const std::vector< double > &x)
Constructor: the vector x contains the abscissae of the base points of the polygon.
Definition: PolygonBase.cxx:11
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
x
#define x
MuonCalib::PolygonBase::value
double value(const int k, const double x) const
get the value of the k-th base function at x
Definition: PolygonBase.cxx:22
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::PolygonBase::m_x
std::vector< double > m_x
Definition: PolygonBase.h:54
PolygonBase.h
fitman.k
k
Definition: fitman.py:528