CMS 3D CMS Logo

poly2d_base.h
Go to the documentation of this file.
1 #ifndef poly2d_base_h
2 #define poly2d_base_h
3 
4 #include <iostream>
5 #include <fstream>
6 #include <iomanip>
7 #include <vector>
8 #include <set>
9 #include <cstring>
10 
11 #include <cmath>
12 #include <cfloat> //in order to use DBL_EPSILON (1+DBL_EPSILON > 1)
13 
15 // //
16 // The "poly2d_term" represent a term of a polynomial of 2 variables. //
17 // //
19 
20 //_______________________________________________________________________________
21 namespace magfieldparam {
22 
23  struct poly2d_term {
24  double coeff; //Coefficient of the term
25  unsigned np[2]; //Powers of variables
26 
27  poly2d_term() { memset(this, 0, sizeof(*this)); }
28  poly2d_term(double C, unsigned nr, unsigned nz) {
29  coeff = C;
30  np[0] = nr;
31  np[1] = nz;
32  }
33  void Print(std::ostream &out = std::cout, bool first_term = true);
34  };
35 
37  // //
38  // Base class that represent a polynomial of 2 variables. It isn't supposed //
39  // to be used directly and provides no way of setting coefficients directly. //
40  // Such methods must be defined in derived classes. //
41  // //
43 
44  //_______________________________________________________________________________
45  class poly2d_base { // a general polynomial of 2 variables
46 
47  protected:
48  //Group of static members for the class memory management
49  //----------------------------------------------------------------------------
50  static double rval; //last r-value used in calculation
51  static double zval; //last z-value used in calculation
52 
53  static double **rz_pow; //table with calculated r^n*z^m values
54  static unsigned NTab; //rz_pow table size
55  static unsigned NPwr; //max power in use by CLASS
56  static bool rz_set;
57 
58  static const double MIN_COEFF; //Threshold for assigning a coeff. to 0
59 
60  static std::set<poly2d_base *> poly2d_base_set; //Set of all poly2d_base objects
61  // static std::set<poly2d_base*, less<poly2d_base*> > poly2d_base_set; //Set of all poly2d_base objects
62 
63  static void SetTabSize(const unsigned N); //Set rz-table size
64  static void FillTable(const double r, const double z);
65 
66  static void AdjustTab();
67  //----------------------------------------------------------------------------
68 
69  std::vector<poly2d_term> data; //polynomial terms
70  unsigned max_pwr; //max power in use by INSTANCE
71 
72  public:
73  static void IncNPwr(const unsigned N) {
74  if (N > NPwr)
75  NPwr = N;
76  }
77  static int GetMaxPow();
78  static unsigned Count() { return poly2d_base_set.size(); }
79  static void PrintTab(std::ostream &out = std::cout, const std::streamsize prec = 5);
80 
81  static void SetPoint(const double r, const double z);
82 
84  max_pwr = 0;
85  poly2d_base_set.insert(this);
86  }
88  data = S.data;
89  max_pwr = S.max_pwr;
90  poly2d_base_set.insert(this);
91  }
92 
93  virtual ~poly2d_base();
94 
95  bool IsOn() { return bool(!data.empty()); }
96  bool IsRZSet() { return rz_set; }
97 
98  void Collect(); //Collect terms and remove zero terms
99  void Compress() { Collect(); }
100 
101  void Diff(int nvar); //differentiate the polynomial by variable# nvar
102  void Int(int nvar); //Integrate the polynomial by variable# nvar
103  void IncPow(int nvar); //Multiply the polynomial by variable# nvar
104  void DecPow(int nvar); //Divide the polynomial by variable# nvar
105 
106  void Scale(const double C);
107  // poly2d_base& operator*=(const double C) { Scale(C); return *this;}
108 
109  double Eval(); //Evaluation with no check that rz_pow table exist
110  double GetVal() {
111  if (rz_set)
112  return Eval();
113  else
114  return 0.;
115  }
116  double GetVal(const double r, const double z) {
117  SetPoint(r, z);
118  return Eval();
119  }
120 
121  void Print(std::ostream &out = std::cout, const std::streamsize prec = 5);
122 
123  }; //Class poly2d_base
124 } // namespace magfieldparam
125 
126 #endif
magfieldparam::poly2d_base::Collect
void Collect()
Definition: poly2d_base.cc:171
magfieldparam::poly2d_base::Count
static unsigned Count()
Definition: poly2d_base.h:78
electrons_cff.bool
bool
Definition: electrons_cff.py:366
magfieldparam::poly2d_term
Definition: poly2d_base.h:23
magfieldparam::poly2d_base::Diff
void Diff(int nvar)
Definition: poly2d_base.cc:231
magfieldparam::poly2d_base::SetTabSize
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:73
gather_cfg.cout
cout
Definition: gather_cfg.py:144
magfieldparam::poly2d_base::Eval
double Eval()
Definition: poly2d_base.cc:163
magfieldparam::poly2d_base::NTab
static unsigned NTab
Definition: poly2d_base.h:54
magfieldparam::poly2d_base::~poly2d_base
virtual ~poly2d_base()
Definition: poly2d_base.cc:53
magfieldparam::poly2d_base::IncNPwr
static void IncNPwr(const unsigned N)
Definition: poly2d_base.h:73
magfieldparam::poly2d_base::rz_set
static bool rz_set
Definition: poly2d_base.h:56
magfieldparam::poly2d_base::Int
void Int(int nvar)
Definition: poly2d_base.cc:256
magfieldparam::poly2d_base::max_pwr
unsigned max_pwr
Definition: poly2d_base.h:70
magfieldparam::poly2d_base::Scale
void Scale(const double C)
Definition: poly2d_base.cc:307
magfieldparam::poly2d_term::coeff
double coeff
Definition: poly2d_base.h:24
magfieldparam::poly2d_base
Definition: poly2d_base.h:45
magfieldparam::poly2d_base::GetMaxPow
static int GetMaxPow()
Definition: poly2d_base.cc:107
magfieldparam::poly2d_base::AdjustTab
static void AdjustTab()
Definition: poly2d_base.cc:120
magfieldparam::poly2d_base::Print
void Print(std::ostream &out=std::cout, const std::streamsize prec=5)
Definition: poly2d_base.cc:214
magfieldparam::poly2d_base::rval
static double rval
Definition: poly2d_base.h:50
magfieldparam::poly2d_base::IsRZSet
bool IsRZSet()
Definition: poly2d_base.h:96
magfieldparam::poly2d_base::zval
static double zval
Definition: poly2d_base.h:51
magfieldparam::poly2d_term::np
unsigned np[2]
Definition: poly2d_base.h:25
N
#define N
Definition: blowfish.cc:9
magfieldparam
Definition: BCyl.h:23
magfieldparam::poly2d_base::DecPow
void DecPow(int nvar)
Definition: poly2d_base.cc:282
magfieldparam::poly2d_base::SetPoint
static void SetPoint(const double r, const double z)
Definition: poly2d_base.cc:151
magfieldparam::poly2d_base::rz_pow
static double ** rz_pow
Definition: poly2d_base.h:53
magfieldparam::poly2d_term::Print
void Print(std::ostream &out=std::cout, bool first_term=true)
Definition: poly2d_base.cc:12
magfieldparam::poly2d_base::FillTable
static void FillTable(const double r, const double z)
Definition: poly2d_base.cc:93
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
magfieldparam::poly2d_base::PrintTab
static void PrintTab(std::ostream &out=std::cout, const std::streamsize prec=5)
Definition: poly2d_base.cc:127
magfieldparam::poly2d_base::NPwr
static unsigned NPwr
Definition: poly2d_base.h:55
magfieldparam::poly2d_base::data
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
alignCSCRings.r
r
Definition: alignCSCRings.py:93
magfieldparam::poly2d_base::poly2d_base
poly2d_base()
Definition: poly2d_base.h:83
magfieldparam::poly2d_base::IsOn
bool IsOn()
Definition: poly2d_base.h:95
magfieldparam::poly2d_term::poly2d_term
poly2d_term()
Definition: poly2d_base.h:27
magfieldparam::poly2d_term::poly2d_term
poly2d_term(double C, unsigned nr, unsigned nz)
Definition: poly2d_base.h:28
gen::C
C
Definition: PomwigHadronizer.cc:78
magfieldparam::poly2d_base::MIN_COEFF
static const double MIN_COEFF
Definition: poly2d_base.h:58
magfieldparam::poly2d_base::IncPow
void IncPow(int nvar)
Definition: poly2d_base.cc:270
S
Definition: CSCDBL1TPParametersExtended.h:16
magfieldparam::poly2d_base::poly2d_base
poly2d_base(const poly2d_base &S)
Definition: poly2d_base.h:87
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
magfieldparam::poly2d_base::GetVal
double GetVal(const double r, const double z)
Definition: poly2d_base.h:116
magfieldparam::poly2d_base::Compress
void Compress()
Definition: poly2d_base.h:99
magfieldparam::poly2d_base::poly2d_base_set
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60
magfieldparam::poly2d_base::GetVal
double GetVal()
Definition: poly2d_base.h:110