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.

83  {
84  max_pwr = 0;
85  poly2d_base_set.insert(this);
86  }

References max_pwr, and poly2d_base_set.

◆ poly2d_base() [2/2]

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

Definition at line 87 of file poly2d_base.h.

87  {
88  data = S.data;
89  max_pwr = S.max_pwr;
90  poly2d_base_set.insert(this);
91  }

References data, max_pwr, and poly2d_base_set.

◆ ~poly2d_base()

poly2d_base::~poly2d_base ( )
virtual

Definition at line 53 of file poly2d_base.cc.

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 }

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

Member Function Documentation

◆ AdjustTab()

void poly2d_base::AdjustTab ( )
staticprotected

Definition at line 120 of file poly2d_base.cc.

120  {
121  NPwr = GetMaxPow();
122  if (NPwr >= NTab)
123  SetTabSize(NPwr + 1);
124 }

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

◆ Collect()

void poly2d_base::Collect ( )

Definition at line 171 of file poly2d_base.cc.

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 }

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

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

◆ Compress()

void magfieldparam::poly2d_base::Compress ( )
inline

Definition at line 99 of file poly2d_base.h.

99 { Collect(); }

References Collect().

◆ Count()

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

Definition at line 78 of file poly2d_base.h.

78 { return poly2d_base_set.size(); }

References poly2d_base_set.

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

◆ DecPow()

void poly2d_base::DecPow ( int  nvar)

Definition at line 282 of file poly2d_base.cc.

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 }

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

◆ Diff()

void poly2d_base::Diff ( int  nvar)

Definition at line 231 of file poly2d_base.cc.

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 }

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

◆ Eval()

double poly2d_base::Eval ( )

Definition at line 163 of file poly2d_base.cc.

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 }

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

Referenced by GetVal().

◆ FillTable()

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

Definition at line 93 of file poly2d_base.cc.

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 }

References NPwr, alignCSCRings::r, and rz_pow.

Referenced by SetPoint().

◆ GetMaxPow()

int poly2d_base::GetMaxPow ( )
static

Definition at line 107 of file poly2d_base.cc.

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 }

References poly2d_base_set.

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

◆ GetVal() [1/2]

double magfieldparam::poly2d_base::GetVal ( )
inline

Definition at line 110 of file poly2d_base.h.

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

References Eval(), and rz_set.

◆ GetVal() [2/2]

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

Definition at line 116 of file poly2d_base.h.

116  {
117  SetPoint(r, z);
118  return Eval();
119  }

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

◆ IncNPwr()

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

Definition at line 73 of file poly2d_base.h.

73  {
74  if (N > NPwr)
75  NPwr = N;
76  }

References N, and NPwr.

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

◆ IncPow()

void poly2d_base::IncPow ( int  nvar)

Definition at line 270 of file poly2d_base.cc.

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 }

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

◆ Int()

void poly2d_base::Int ( int  nvar)

Definition at line 256 of file poly2d_base.cc.

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 }

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

◆ IsOn()

bool magfieldparam::poly2d_base::IsOn ( )
inline

Definition at line 95 of file poly2d_base.h.

95 { return bool(!data.empty()); }

References electrons_cff::bool, and data.

◆ IsRZSet()

bool magfieldparam::poly2d_base::IsRZSet ( )
inline

Definition at line 96 of file poly2d_base.h.

96 { return rz_set; }

References 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.

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 }

References data, max_pwr, and MillePedeFileConverter_cfg::out.

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

◆ 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.

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 }

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

◆ Scale()

void poly2d_base::Scale ( const double  C)

Definition at line 307 of file poly2d_base.cc.

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 }

References gen::C, and data.

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

◆ SetPoint()

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

Definition at line 151 of file poly2d_base.cc.

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 }

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

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

◆ SetTabSize()

void poly2d_base::SetTabSize ( const unsigned  N)
staticprotected

Definition at line 73 of file poly2d_base.cc.

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 }

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

Referenced by AdjustTab(), and SetPoint().

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().

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:393
magfieldparam::poly2d_term
Definition: poly2d_base.h:23
magfieldparam::poly2d_base::SetTabSize
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:73
magfieldparam::poly2d_base::Eval
double Eval()
Definition: poly2d_base.cc:163
np
int np
Definition: AMPTWrapper.h:43
magfieldparam::poly2d_base::NTab
static unsigned NTab
Definition: poly2d_base.h:54
magfieldparam::poly2d_base::rz_set
static bool rz_set
Definition: poly2d_base.h:56
magfieldparam::poly2d_base::max_pwr
unsigned max_pwr
Definition: poly2d_base.h:70
magfieldparam::poly2d_term::coeff
double coeff
Definition: poly2d_base.h:24
magfieldparam::poly2d_base::GetMaxPow
static int GetMaxPow()
Definition: poly2d_base.cc:107
magfieldparam::poly2d_base::rval
static double rval
Definition: poly2d_base.h:50
magfieldparam::poly2d_base::zval
static double zval
Definition: poly2d_base.h:51
DDAxes::z
magfieldparam::poly2d_term::np
unsigned np[2]
Definition: poly2d_base.h:25
N
#define N
Definition: blowfish.cc:9
S
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:97
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_base::FillTable
static void FillTable(const double r, const double z)
Definition: poly2d_base.cc:93
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
gen::C
C
Definition: PomwigHadronizer.cc:78
magfieldparam::poly2d_base::MIN_COEFF
static const double MIN_COEFF
Definition: poly2d_base.h:58
S
Definition: CSCDBL1TPParametersExtended.h:16
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
magfieldparam::poly2d_base::poly2d_base_set
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:60