test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
magfieldparam::poly2d_base Class Reference

#include <poly2d_base.h>

Inheritance diagram for magfieldparam::poly2d_base:
magfieldparam::rz_harm_poly

Public Member Functions

void Collect ()
 
void Compress ()
 
void DecPow (int nvar)
 
void Diff (int nvar)
 
double Eval ()
 
double GetVal ()
 
double GetVal (const double r, const double z)
 
void IncPow (int nvar)
 
void Int (int nvar)
 
bool IsOn ()
 
bool IsRZSet ()
 
 poly2d_base ()
 
 poly2d_base (const poly2d_base &S)
 
void Print (std::ostream &out=std::cout, const std::streamsize prec=5)
 
void Scale (const double C)
 
virtual ~poly2d_base ()
 

Static Public Member Functions

static unsigned Count ()
 
static int GetMaxPow ()
 
static void IncNPwr (const unsigned N)
 
static void PrintTab (std::ostream &out=std::cout, const std::streamsize prec=5)
 
static void SetPoint (const double r, const double z)
 

Static Protected Member Functions

static void AdjustTab ()
 
static void FillTable (const double r, const double z)
 
static void SetTabSize (const unsigned N)
 

Protected Attributes

std::vector< poly2d_termdata
 
unsigned max_pwr
 

Static Protected Attributes

static const double MIN_COEFF = DBL_EPSILON
 
static unsigned NPwr = 0
 
static unsigned NTab = 0
 
static std::set< poly2d_base * > poly2d_base_set
 
static double rval = 0.
 
static double ** rz_pow = 0
 
static bool rz_set = false
 
static double zval = 0.
 

Detailed Description

Definition at line 44 of file poly2d_base.h.

Constructor & Destructor Documentation

magfieldparam::poly2d_base::poly2d_base ( )
inline

Definition at line 79 of file poly2d_base.h.

References max_pwr, and poly2d_base_set.

79  {
80  max_pwr = 0;
81  poly2d_base_set.insert(this);
82  }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
magfieldparam::poly2d_base::poly2d_base ( const poly2d_base S)
inline

Definition at line 83 of file poly2d_base.h.

References data, max_pwr, and poly2d_base_set.

83  {
84  data = S.data;
85  max_pwr = S.max_pwr;
86  poly2d_base_set.insert(this);
87  }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
poly2d_base::~poly2d_base ( )
virtual

Definition at line 49 of file poly2d_base.cc.

References GetMaxPow(), max_pwr, NPwr, NTab, poly2d_base_set, rz_pow, rz_set, and zval.

50 {
51  poly2d_base_set.erase(poly2d_base_set.find(this));
52  if(poly2d_base_set.size()) { //some objects left
53  if (max_pwr >= NPwr) NPwr = GetMaxPow();
54  } else {
55  if (rz_pow) {
56  delete [] rz_pow[0]; //deleting the last instance -> memory cleanup
57  delete [] rz_pow;
58  }
59  rz_pow = 0;
60  rval = zval = 0.;
61  NPwr = 0;
62  NTab = 0;
63  rz_set = false;
64 // poly2d_base_set.resize(0);
65  }
66 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
unsigned long long int rval
Definition: vlib.h:22
static unsigned NPwr
Definition: poly2d_base.h:54

Member Function Documentation

void poly2d_base::AdjustTab ( )
staticprotected

Definition at line 115 of file poly2d_base.cc.

References GetMaxPow(), NPwr, NTab, and SetTabSize().

116 {
117  NPwr = GetMaxPow();
118  if (NPwr >= NTab) SetTabSize(NPwr+1);
119 }
static unsigned NTab
Definition: poly2d_base.h:53
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:69
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Collect ( )

Definition at line 166 of file poly2d_base.cc.

References funct::C, data, max_pwr, MIN_COEFF, and np.

Referenced by Compress(), magfieldparam::rz_harm_poly::LadderDwn(), and magfieldparam::rz_harm_poly::LadderUp().

167 {
168  if (!(data.size())) return;
169 
170  unsigned j1, j2, rpow, zpow, noff = 0, jend = data.size();
171  double C;
172  std::vector<bool> mask(jend, false);
173  max_pwr = 0;
174 
175  for (j1 = 0; j1 < jend; ++j1) {
176  if (mask[j1]) continue;
177  C = data[j1].coeff;
178  rpow = data[j1].np[0];
179  zpow = data[j1].np[1];
180  for (j2 = j1+1; j2 < jend; ++j2) {
181  if (mask[j2]) continue;
182  if ((rpow == data[j2].np[0]) && (zpow == data[j2].np[1])) {
183  C += data[j2].coeff;
184  mask[j2] = true;
185  ++noff;
186  }
187  }
188  if (fabs(C) > MIN_COEFF) {
189  data[j1].coeff = C;
190  if ((rpow = rpow+zpow) > max_pwr) max_pwr = rpow;
191  } else {
192  mask[j1] = true;
193  ++noff;
194  }
195  }
196  std::vector<poly2d_term> newdata; newdata.reserve(jend - noff);
197  for (j1 = 0; j1 < jend; ++j1) {
198  if (!(mask[j1])) newdata.push_back(data[j1]);
199  }
200  data.swap(newdata);
201 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
int np
Definition: AMPTWrapper.h:33
static const double MIN_COEFF
Definition: poly2d_base.h:57
void magfieldparam::poly2d_base::Compress ( )
inline

Definition at line 95 of file poly2d_base.h.

References Collect().

static unsigned magfieldparam::poly2d_base::Count ( )
inlinestatic

Definition at line 74 of file poly2d_base.h.

References poly2d_base_set.

Referenced by magfieldparam::rz_harm_poly::ParentCount(), and SetPoint().

74 { return poly2d_base_set.size();}
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
void poly2d_base::DecPow ( int  nvar)

Definition at line 272 of file poly2d_base.cc.

References magfieldparam::poly2d_term::coeff, data, GetMaxPow(), max_pwr, magfieldparam::poly2d_term::np, and NPwr.

Referenced by magfieldparam::rz_harm_poly::GetDecPow().

273 {
274 //Divide the polynomial by variable# nvar. Remove terms with zero coefficients
275 //and also terms where the initial power of nvar is equal zero
276 //
277  poly2d_term v3;
278  std::vector<poly2d_term> newdata;
279  newdata.reserve(data.size());
280  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
281  for (unsigned it = 0; it < data.size(); ++it) {
282  v3 = data[it];
283  if ((v3.coeff != 0.) && (v3.np[nvar] > 0)) {
284  --v3.np[nvar];
285  newdata.push_back(v3);
286  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp) maxp = cur_pwr;
287  }
288  }
289  newdata.resize(newdata.size());
290  max_pwr = maxp;
291  data.swap(newdata);
292  if (oldp >= NPwr) NPwr = GetMaxPow();
293 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Diff ( int  nvar)

Definition at line 222 of file poly2d_base.cc.

References magfieldparam::poly2d_term::coeff, data, GetMaxPow(), max_pwr, magfieldparam::poly2d_term::np, and NPwr.

Referenced by magfieldparam::rz_harm_poly::GetDiff().

223 {
224 //differentiate the polynomial by variable nvar.
225 //
226  poly2d_term v3;
227  std::vector<poly2d_term> newdata;
228  newdata.reserve(data.size());
229  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
230  for (unsigned it = 0; it < data.size(); ++it) {
231  v3 = data[it];
232  v3.coeff *= v3.np[nvar];
233  if (v3.coeff != 0.) {
234  --v3.np[nvar];
235  newdata.push_back(v3);
236  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp) maxp = cur_pwr;
237  }
238  }
239  newdata.resize(newdata.size());
240  max_pwr = maxp;
241  data.swap(newdata);
242  if (oldp >= NPwr) NPwr = GetMaxPow();
243 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
double poly2d_base::Eval ( )

Definition at line 157 of file poly2d_base.cc.

References data, j, np, rz_pow, and S().

Referenced by magfieldparam::HarmBasis3DCyl::EvalBphi(), magfieldparam::HarmBasis3DCyl::EvalRZ(), and GetVal().

158 {
159  double S = 0.;
160  for (unsigned j = 0; j < data.size(); ++j)
161  S += data[j].coeff*rz_pow[data[j].np[0]][data[j].np[1]];
162  return S;
163 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static double ** rz_pow
Definition: poly2d_base.h:52
int np
Definition: AMPTWrapper.h:33
int j
Definition: DBlmapReader.cc:9
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
void poly2d_base::FillTable ( const double  r,
const double  z 
)
staticprotected

Definition at line 89 of file poly2d_base.cc.

References NPwr, and rz_pow.

Referenced by SetPoint().

90 {
91  if (!rz_pow) return;
92  unsigned jr, jz;
93  for (jz = 1; jz <= NPwr; ++jz) rz_pow[0][jz] = z*rz_pow[0][jz-1];
94  for (jr = 1; jr <= NPwr; ++jr) {
95  for (jz = 0; jz <= (NPwr - jr); ++jz) {
96  rz_pow[jr][jz] = r*rz_pow[jr-1][jz];
97  }
98  }
99 }
static double ** rz_pow
Definition: poly2d_base.h:52
static unsigned NPwr
Definition: poly2d_base.h:54
int poly2d_base::GetMaxPow ( )
static

Definition at line 102 of file poly2d_base.cc.

References poly2d_base_set.

Referenced by AdjustTab(), DecPow(), Diff(), IncPow(), Int(), and ~poly2d_base().

103 {
104  int curp, maxp = 0;
105  std::set<poly2d_base*>::iterator it;
106 
107  for (it = poly2d_base_set.begin(); it != poly2d_base_set.end(); ++it) {
108  curp = (*it)->max_pwr;
109  if (curp > maxp) maxp = curp;
110  }
111  return maxp;
112 }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
double magfieldparam::poly2d_base::GetVal ( )
inline

Definition at line 106 of file poly2d_base.h.

References Eval(), and rz_set.

106 {if (rz_set) return Eval(); else return 0.;}
double magfieldparam::poly2d_base::GetVal ( const double  r,
const double  z 
)
inline

Definition at line 107 of file poly2d_base.h.

References Eval(), and SetPoint().

107 { SetPoint(r,z); return Eval();}
static void SetPoint(const double r, const double z)
Definition: poly2d_base.cc:148
static void magfieldparam::poly2d_base::IncNPwr ( const unsigned  N)
inlinestatic

Definition at line 72 of file poly2d_base.h.

References N, and NPwr.

Referenced by magfieldparam::HarmBasis3DCyl::HarmBasis3DCyl().

72 {if (N > NPwr) NPwr = N;}
#define N
Definition: blowfish.cc:9
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::IncPow ( int  nvar)

Definition at line 260 of file poly2d_base.cc.

References data, GetMaxPow(), max_pwr, and NPwr.

Referenced by magfieldparam::rz_harm_poly::GetIncPow().

261 {
262 //Multiply the polynomial by variable# nvar
263 //
264  for (unsigned it = 0; it < data.size(); ++it) {
265  ++data[it].np[nvar];
266  }
267  ++max_pwr;
268  if (max_pwr > NPwr) NPwr = GetMaxPow();
269 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Int ( int  nvar)

Definition at line 246 of file poly2d_base.cc.

References data, GetMaxPow(), max_pwr, and NPwr.

Referenced by magfieldparam::rz_harm_poly::GetInt().

247 {
248 //Integrate the polynomial by variable# nvar. Doesn't remove terms
249 //with zero coefficients; if you suspect they can appear, use Compress()
250 //after the integration.
251 //
252  for (unsigned it = 0; it < data.size(); ++it) {
253  data[it].coeff /= ++data[it].np[nvar];
254  }
255  ++max_pwr;
256  if (max_pwr > NPwr) NPwr = GetMaxPow();
257 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
bool magfieldparam::poly2d_base::IsOn ( )
inline

Definition at line 91 of file poly2d_base.h.

References data.

91 { return bool(data.size());}
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
bool magfieldparam::poly2d_base::IsRZSet ( )
inline

Definition at line 92 of file poly2d_base.h.

References rz_set.

92 { return rz_set;}
void poly2d_base::Print ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)

Definition at line 204 of file poly2d_base.cc.

References data, and max_pwr.

Referenced by magfieldparam::rz_harm_poly::Print().

205 {
206  if (!data.size()) {
207  out << "\"poly2d_base\" object contains no terms." << std::endl;
208  return;
209  }
210  out << data.size() << " terms; max. degree = " << max_pwr << ":" << std::endl;
211  std::streamsize old_prec = out.precision();
212  out.precision(prec);
213  data[0].Print(out);
214  for (unsigned it = 1; it < data.size(); ++it) {
215  data[it].Print(out, false);
216  }
217  out << std::endl;
218  out.precision(old_prec);
219 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
void poly2d_base::PrintTab ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)
static

Definition at line 122 of file poly2d_base.cc.

References NPwr, NTab, and rz_pow.

123 {
124  out << "poly2d_base table size NTab = " << NTab
125  << "\tmax. power NPwr = " << NPwr << std::endl;
126  if (rz_pow) {
127  if (NPwr < NTab) {
128  std::streamsize old_prec = out.precision(), wdt = prec+7;
129  out.precision(prec);
130  out << "Table content:" << std::endl;
131  unsigned jr, jz;
132  for (jr = 0; jr <= NPwr; ++jr) {
133  for (jz = 0; jz <= (NPwr-jr); ++jz) {
134  out << std::setw(wdt) << std::left << rz_pow[jr][jz];
135  }
136  out << "|" << std::endl;
137  }
138  out.precision(old_prec);
139  } else {
140  out << "\tTable size is not adjusted." << std::endl;
141  }
142  } else {
143  out << "\tTable is not allocated." << std::endl;
144  }
145 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Scale ( const double  C)

Definition at line 296 of file poly2d_base.cc.

References funct::C, and data.

Referenced by magfieldparam::rz_harm_poly::LadderDwn(), and magfieldparam::rz_harm_poly::LadderUp().

297 {
298 //Multiply the polynomial by a constant.
299 //
300  if (C != 0.) {
301  for (unsigned it = 0; it < data.size(); ++it) {
302  data[it].coeff *= C;
303  }
304  } else data.resize(0);
305 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
void poly2d_base::SetPoint ( const double  r,
const double  z 
)
static

Definition at line 148 of file poly2d_base.cc.

References Count(), FillTable(), NPwr, NTab, rz_set, SetTabSize(), and zval.

Referenced by GetVal(), and magfieldparam::rz_harm_poly::SetPoint().

149 {
150  if (!Count()) return;
151  if (NPwr >= NTab) { SetTabSize(NPwr+1); FillTable(r, z);}
152  else if ((r != rval) || (z != zval)) FillTable(r, z);
153  rz_set = true;
154 }
static unsigned NTab
Definition: poly2d_base.h:53
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:69
static void FillTable(const double r, const double z)
Definition: poly2d_base.cc:89
unsigned long long int rval
Definition: vlib.h:22
static unsigned NPwr
Definition: poly2d_base.h:54
static unsigned Count()
Definition: poly2d_base.h:74
void poly2d_base::SetTabSize ( const unsigned  N)
staticprotected

Definition at line 69 of file poly2d_base.cc.

References N, NTab, rz_pow, and zval.

Referenced by AdjustTab(), and SetPoint().

70 {
71  if (N <= NTab) return;
72  if (rz_pow) {
73  delete [] rz_pow[0];
74  delete [] rz_pow;
75  }
76  rz_pow = new double* [N];
77  unsigned jr, dN = N*(N+1)/2;
78  rz_pow[0] = new double [dN];
79  memset(rz_pow[0], 0, dN*sizeof(double));
80  rz_pow[0][0] = 1.;
81  for (jr = 1, dN = N; jr < N; ++jr, --dN) {
82  rz_pow[jr] = rz_pow[jr-1] + dN;
83  }
84  rval = zval = 0.;
85  NTab = N;
86 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
unsigned long long int rval
Definition: vlib.h:22
#define N
Definition: blowfish.cc:9

Member Data Documentation

std::vector<poly2d_term> magfieldparam::poly2d_base::data
protected
unsigned magfieldparam::poly2d_base::max_pwr
protected
const double poly2d_base::MIN_COEFF = DBL_EPSILON
staticprotected

Definition at line 57 of file poly2d_base.h.

Referenced by Collect().

unsigned poly2d_base::NPwr = 0
staticprotected
unsigned poly2d_base::NTab = 0
staticprotected

Definition at line 53 of file poly2d_base.h.

Referenced by AdjustTab(), PrintTab(), SetPoint(), SetTabSize(), and ~poly2d_base().

std::set< poly2d_base * > poly2d_base::poly2d_base_set
staticprotected
double poly2d_base::rval = 0.
staticprotected

Definition at line 49 of file poly2d_base.h.

double ** poly2d_base::rz_pow = 0
staticprotected

Definition at line 52 of file poly2d_base.h.

Referenced by Eval(), FillTable(), PrintTab(), SetTabSize(), and ~poly2d_base().

bool poly2d_base::rz_set = false
staticprotected
double poly2d_base::zval = 0.
staticprotected

Definition at line 50 of file poly2d_base.h.

Referenced by SetPoint(), SetTabSize(), and ~poly2d_base().