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 <float.h> //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  {
30  coeff = C; np[0] = nr; np[1] = nz;
31  }
32  void Print(std::ostream &out = std::cout, bool first_term = true);
33 };
34 
36 // //
37 // Base class that represent a polynomial of 2 variables. It isn't supposed //
38 // to be used directly and provides no way of setting coefficients directly. //
39 // Such methods must be defined in derived classes. //
40 // //
42 
43 //_______________________________________________________________________________
44 class poly2d_base { // a general polynomial of 2 variables
45 
46 protected:
47  //Group of static members for the class memory management
48  //----------------------------------------------------------------------------
49  static double rval; //last r-value used in calculation
50  static double zval; //last z-value used in calculation
51 
52  static double **rz_pow; //table with calculated r^n*z^m values
53  static unsigned NTab; //rz_pow table size
54  static unsigned NPwr; //max power in use by CLASS
55  static bool rz_set;
56 
57  static const double MIN_COEFF; //Threshold for assigning a coeff. to 0
58 
59  static std::set<poly2d_base*> poly2d_base_set; //Set of all poly2d_base objects
60 // static std::set<poly2d_base*, less<poly2d_base*> > poly2d_base_set; //Set of all poly2d_base objects
61 
62  static void SetTabSize(const unsigned N); //Set rz-table size
63  static void FillTable (const double r, const double z);
64 
65  static void AdjustTab();
66  //----------------------------------------------------------------------------
67 
68  std::vector<poly2d_term> data; //polynomial terms
69  unsigned max_pwr; //max power in use by INSTANCE
70 
71 public:
72  static void IncNPwr(const unsigned N) {if (N > NPwr) NPwr = N;}
73  static int GetMaxPow();
74  static unsigned Count() { return poly2d_base_set.size();}
75  static void PrintTab(std::ostream &out = std::cout, const std::streamsize prec = 5);
76 
77  static void SetPoint(const double r, const double z);
78 
80  max_pwr = 0;
81  poly2d_base_set.insert(this);
82  }
84  data = S.data;
85  max_pwr = S.max_pwr;
86  poly2d_base_set.insert(this);
87  }
88 
89  virtual ~poly2d_base();
90 
91  bool IsOn() { return bool(data.size());}
92  bool IsRZSet() { return rz_set;}
93 
94  void Collect(); //Collect terms and remove zero terms
95  void Compress() { Collect();}
96 
97  void Diff (int nvar); //differentiate the polynomial by variable# nvar
98  void Int (int nvar); //Integrate the polynomial by variable# nvar
99  void IncPow(int nvar); //Multiply the polynomial by variable# nvar
100  void DecPow(int nvar); //Divide the polynomial by variable# nvar
101 
102  void Scale(const double C);
103 // poly2d_base& operator*=(const double C) { Scale(C); return *this;}
104 
105  double Eval(); //Evaluation with no check that rz_pow table exist
106  double GetVal() {if (rz_set) return Eval(); else return 0.;}
107  double GetVal(const double r, const double z) { SetPoint(r,z); return Eval();}
108 
109  void Print(std::ostream &out = std::cout, const std::streamsize prec = 5);
110 
111 }; //Class poly2d_base
112 }
113 
114 #endif
static unsigned NTab
Definition: poly2d_base.h:53
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
poly2d_base(const poly2d_base &S)
Definition: poly2d_base.h:83
double GetVal(const double r, const double z)
Definition: poly2d_base.h:107
static double ** rz_pow
Definition: poly2d_base.h:52
poly2d_term(double C, unsigned nr, unsigned nz)
Definition: poly2d_base.h:28
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
void Print(std::ostream &out=std::cout, bool first_term=true)
Definition: poly2d_base.cc:12
static void IncNPwr(const unsigned N)
Definition: poly2d_base.h:72
int Int
Definition: forwards.h:16
#define N
Definition: blowfish.cc:9
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
static unsigned NPwr
Definition: poly2d_base.h:54
static const double MIN_COEFF
Definition: poly2d_base.h:57
static unsigned Count()
Definition: poly2d_base.h:74