CMS 3D CMS Logo

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 = nullptr
 
static bool rz_set = false
 
static double zval = 0.
 

Detailed Description

Definition at line 45 of file poly2d_base.h.

Constructor & Destructor Documentation

◆ poly2d_base() [1/2]

magfieldparam::poly2d_base::poly2d_base ( )
inline

Definition at line 83 of file poly2d_base.h.

References max_pwr, and poly2d_base_set.

83  {
84  max_pwr = 0;
85  poly2d_base_set.insert(this);
86  }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60

◆ poly2d_base() [2/2]

magfieldparam::poly2d_base::poly2d_base ( const poly2d_base S)
inline

Definition at line 87 of file poly2d_base.h.

References data, max_pwr, and poly2d_base_set.

87  {
88  data = S.data;
89  max_pwr = S.max_pwr;
90  poly2d_base_set.insert(this);
91  }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60

◆ ~poly2d_base()

poly2d_base::~poly2d_base ( )
virtual

Definition at line 53 of file poly2d_base.cc.

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

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

Member Function Documentation

◆ AdjustTab()

void poly2d_base::AdjustTab ( )
staticprotected

Definition at line 120 of file poly2d_base.cc.

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

120  {
121  NPwr = GetMaxPow();
122  if (NPwr >= NTab)
123  SetTabSize(NPwr + 1);
124 }
static unsigned NTab
Definition: poly2d_base.h:54
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:73
static unsigned NPwr
Definition: poly2d_base.h:55

◆ Collect()

void poly2d_base::Collect ( )

Definition at line 171 of file poly2d_base.cc.

References correctionTermsCaloMet_cff::C, data, gpuClustering::pixelStatus::mask, max_pwr, MIN_COEFF, and np.

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

171  {
172  if (!(data.size()))
173  return;
174 
175  unsigned j1, j2, rpow, zpow, noff = 0, jend = data.size();
176  double C;
177  std::vector<bool> mask(jend, false);
178  max_pwr = 0;
179 
180  for (j1 = 0; j1 < jend; ++j1) {
181  if (mask[j1])
182  continue;
183  C = data[j1].coeff;
184  rpow = data[j1].np[0];
185  zpow = data[j1].np[1];
186  for (j2 = j1 + 1; j2 < jend; ++j2) {
187  if (mask[j2])
188  continue;
189  if ((rpow == data[j2].np[0]) && (zpow == data[j2].np[1])) {
190  C += data[j2].coeff;
191  mask[j2] = true;
192  ++noff;
193  }
194  }
195  if (fabs(C) > MIN_COEFF) {
196  data[j1].coeff = C;
197  if ((rpow = rpow + zpow) > max_pwr)
198  max_pwr = rpow;
199  } else {
200  mask[j1] = true;
201  ++noff;
202  }
203  }
204  std::vector<poly2d_term> newdata;
205  newdata.reserve(jend - noff);
206  for (j1 = 0; j1 < jend; ++j1) {
207  if (!(mask[j1]))
208  newdata.push_back(data[j1]);
209  }
210  data.swap(newdata);
211 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
constexpr uint32_t mask
Definition: gpuClustering.h:24
int np
Definition: AMPTWrapper.h:43
static const double MIN_COEFF
Definition: poly2d_base.h:58

◆ Compress()

void magfieldparam::poly2d_base::Compress ( )
inline

Definition at line 99 of file poly2d_base.h.

References Collect().

◆ Count()

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

Definition at line 78 of file poly2d_base.h.

References poly2d_base_set.

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

78 { return poly2d_base_set.size(); }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60

◆ DecPow()

void poly2d_base::DecPow ( int  nvar)

Definition at line 282 of file poly2d_base.cc.

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

282  {
283  //Divide the polynomial by variable# nvar. Remove terms with zero coefficients
284  //and also terms where the initial power of nvar is equal zero
285  //
286  poly2d_term v3;
287  std::vector<poly2d_term> newdata;
288  newdata.reserve(data.size());
289  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
290  for (unsigned it = 0; it < data.size(); ++it) {
291  v3 = data[it];
292  if ((v3.coeff != 0.) && (v3.np[nvar] > 0)) {
293  --v3.np[nvar];
294  newdata.push_back(v3);
295  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp)
296  maxp = cur_pwr;
297  }
298  }
299  newdata.resize(newdata.size());
300  max_pwr = maxp;
301  data.swap(newdata);
302  if (oldp >= NPwr)
303  NPwr = GetMaxPow();
304 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static unsigned NPwr
Definition: poly2d_base.h:55

◆ Diff()

void poly2d_base::Diff ( int  nvar)

Definition at line 231 of file poly2d_base.cc.

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

231  {
232  //differentiate the polynomial by variable nvar.
233  //
234  poly2d_term v3;
235  std::vector<poly2d_term> newdata;
236  newdata.reserve(data.size());
237  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
238  for (unsigned it = 0; it < data.size(); ++it) {
239  v3 = data[it];
240  v3.coeff *= v3.np[nvar];
241  if (v3.coeff != 0.) {
242  --v3.np[nvar];
243  newdata.push_back(v3);
244  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp)
245  maxp = cur_pwr;
246  }
247  }
248  newdata.resize(newdata.size());
249  max_pwr = maxp;
250  data.swap(newdata);
251  if (oldp >= NPwr)
252  NPwr = GetMaxPow();
253 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static unsigned NPwr
Definition: poly2d_base.h:55

◆ Eval()

double poly2d_base::Eval ( )

Definition at line 163 of file poly2d_base.cc.

References data, dqmiolumiharvest::j, np, and rz_pow.

Referenced by GetVal().

163  {
164  double S = 0.;
165  for (unsigned j = 0; j < data.size(); ++j)
166  S += data[j].coeff * rz_pow[data[j].np[0]][data[j].np[1]];
167  return S;
168 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static double ** rz_pow
Definition: poly2d_base.h:53
int np
Definition: AMPTWrapper.h:43

◆ FillTable()

void poly2d_base::FillTable ( const double  r,
const double  z 
)
staticprotected

Definition at line 93 of file poly2d_base.cc.

References NPwr, alignCSCRings::r, and rz_pow.

Referenced by SetPoint().

93  {
94  if (!rz_pow)
95  return;
96  unsigned jr, jz;
97  for (jz = 1; jz <= NPwr; ++jz)
98  rz_pow[0][jz] = z * rz_pow[0][jz - 1];
99  for (jr = 1; jr <= NPwr; ++jr) {
100  for (jz = 0; jz <= (NPwr - jr); ++jz) {
101  rz_pow[jr][jz] = r * rz_pow[jr - 1][jz];
102  }
103  }
104 }
static double ** rz_pow
Definition: poly2d_base.h:53
static unsigned NPwr
Definition: poly2d_base.h:55

◆ GetMaxPow()

int poly2d_base::GetMaxPow ( )
static

Definition at line 107 of file poly2d_base.cc.

References poly2d_base_set.

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

107  {
108  int curp, maxp = 0;
109  std::set<poly2d_base *>::iterator it;
110 
111  for (it = poly2d_base_set.begin(); it != poly2d_base_set.end(); ++it) {
112  curp = (*it)->max_pwr;
113  if (curp > maxp)
114  maxp = curp;
115  }
116  return maxp;
117 }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60

◆ GetVal() [1/2]

double magfieldparam::poly2d_base::GetVal ( )
inline

Definition at line 110 of file poly2d_base.h.

References Eval(), and rz_set.

110  {
111  if (rz_set)
112  return Eval();
113  else
114  return 0.;
115  }

◆ GetVal() [2/2]

double magfieldparam::poly2d_base::GetVal ( const double  r,
const double  z 
)
inline

Definition at line 116 of file poly2d_base.h.

References Eval(), alignCSCRings::r, and SetPoint().

116  {
117  SetPoint(r, z);
118  return Eval();
119  }
static void SetPoint(const double r, const double z)
Definition: poly2d_base.cc:151

◆ IncNPwr()

static void magfieldparam::poly2d_base::IncNPwr ( const unsigned  N)
inlinestatic

Definition at line 73 of file poly2d_base.h.

References N, and NPwr.

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

73  {
74  if (N > NPwr)
75  NPwr = N;
76  }
#define N
Definition: blowfish.cc:9
static unsigned NPwr
Definition: poly2d_base.h:55

◆ IncPow()

void poly2d_base::IncPow ( int  nvar)

Definition at line 270 of file poly2d_base.cc.

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

270  {
271  //Multiply the polynomial by variable# nvar
272  //
273  for (unsigned it = 0; it < data.size(); ++it) {
274  ++data[it].np[nvar];
275  }
276  ++max_pwr;
277  if (max_pwr > NPwr)
278  NPwr = GetMaxPow();
279 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static unsigned NPwr
Definition: poly2d_base.h:55

◆ Int()

void poly2d_base::Int ( int  nvar)

Definition at line 256 of file poly2d_base.cc.

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

256  {
257  //Integrate the polynomial by variable# nvar. Doesn't remove terms
258  //with zero coefficients; if you suspect they can appear, use Compress()
259  //after the integration.
260  //
261  for (unsigned it = 0; it < data.size(); ++it) {
262  data[it].coeff /= ++data[it].np[nvar];
263  }
264  ++max_pwr;
265  if (max_pwr > NPwr)
266  NPwr = GetMaxPow();
267 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69
static unsigned NPwr
Definition: poly2d_base.h:55

◆ IsOn()

bool magfieldparam::poly2d_base::IsOn ( )
inline

Definition at line 95 of file poly2d_base.h.

References electrons_cff::bool, and data.

95 { return bool(!data.empty()); }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69

◆ IsRZSet()

bool magfieldparam::poly2d_base::IsRZSet ( )
inline

Definition at line 96 of file poly2d_base.h.

References rz_set.

96 { return rz_set; }

◆ Print()

void poly2d_base::Print ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)

Definition at line 214 of file poly2d_base.cc.

References data, max_pwr, and MillePedeFileConverter_cfg::out.

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

214  {
215  if (data.empty()) {
216  out << "\"poly2d_base\" object contains no terms." << std::endl;
217  return;
218  }
219  out << data.size() << " terms; max. degree = " << max_pwr << ":" << std::endl;
220  std::streamsize old_prec = out.precision();
221  out.precision(prec);
222  data[0].Print(out);
223  for (unsigned it = 1; it < data.size(); ++it) {
224  data[it].Print(out, false);
225  }
226  out << std::endl;
227  out.precision(old_prec);
228 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69

◆ PrintTab()

void poly2d_base::PrintTab ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)
static

Definition at line 127 of file poly2d_base.cc.

References NPwr, NTab, MillePedeFileConverter_cfg::out, and rz_pow.

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

◆ Scale()

void poly2d_base::Scale ( const double  C)

Definition at line 307 of file poly2d_base.cc.

References correctionTermsCaloMet_cff::C, and data.

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

307  {
308  //Multiply the polynomial by a constant.
309  //
310  if (C != 0.) {
311  for (unsigned it = 0; it < data.size(); ++it) {
312  data[it].coeff *= C;
313  }
314  } else
315  data.resize(0);
316 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:69

◆ SetPoint()

void poly2d_base::SetPoint ( const double  r,
const double  z 
)
static

Definition at line 151 of file poly2d_base.cc.

References Count(), FillTable(), NPwr, NTab, alignCSCRings::r, rval, rz_set, SetTabSize(), and zval.

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

151  {
152  if (!Count())
153  return;
154  if (NPwr >= NTab) {
155  SetTabSize(NPwr + 1);
156  FillTable(r, z);
157  } else if ((r != rval) || (z != zval))
158  FillTable(r, z);
159  rz_set = true;
160 }
static unsigned NTab
Definition: poly2d_base.h:54
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:73
static void FillTable(const double r, const double z)
Definition: poly2d_base.cc:93
static unsigned NPwr
Definition: poly2d_base.h:55
static unsigned Count()
Definition: poly2d_base.h:78

◆ SetTabSize()

void poly2d_base::SetTabSize ( const unsigned  N)
staticprotected

Definition at line 73 of file poly2d_base.cc.

References N, NTab, rval, rz_pow, and zval.

Referenced by AdjustTab(), and SetPoint().

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

Member Data Documentation

◆ data

std::vector<poly2d_term> magfieldparam::poly2d_base::data
protected

◆ max_pwr

unsigned magfieldparam::poly2d_base::max_pwr
protected

◆ MIN_COEFF

const double poly2d_base::MIN_COEFF = DBL_EPSILON
staticprotected

Definition at line 58 of file poly2d_base.h.

Referenced by Collect().

◆ NPwr

unsigned poly2d_base::NPwr = 0
staticprotected

◆ NTab

unsigned poly2d_base::NTab = 0
staticprotected

Definition at line 54 of file poly2d_base.h.

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

◆ poly2d_base_set

std::set< poly2d_base * > poly2d_base::poly2d_base_set
staticprotected

◆ rval

double poly2d_base::rval = 0.
staticprotected

Definition at line 50 of file poly2d_base.h.

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

◆ rz_pow

double ** poly2d_base::rz_pow = nullptr
staticprotected

Definition at line 53 of file poly2d_base.h.

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

◆ rz_set

bool poly2d_base::rz_set = false
staticprotected

◆ zval

double poly2d_base::zval = 0.
staticprotected

Definition at line 51 of file poly2d_base.h.

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