CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
magfieldparam::rz_poly Class Reference

#include <rz_poly.h>

Public Member Functions

rz_poly Diff (int nvar, bool keep_empty=false)
 
double * Expand (double *C)
 
int GetLength () const
 
int GetMaxRPow () const
 
int GetMaxZPow () const
 
int GetNActive () const
 
double GetSVal (double r, double z, const double *C) const
 
double * GetVVal (double r, double z, double *rez_out=nullptr)
 
rz_poly Int (int nvar)
 
rz_polyoperator*= (double C)
 
rz_polyoperator*= (double *C)
 
void Print ()
 
 rz_poly ()
 
 rz_poly (int N)
 
 rz_poly (const rz_poly &S)
 
void SetAllON (int npoly)
 
void SetOFF (int npoly)
 
void SetON (int npoly)
 
 ~rz_poly ()
 

Private Attributes

poly_arr data
 
bool * is_off
 
int max_nr
 
int max_nz
 
int n_active
 
double * r_pow
 
double * z_pow
 

Detailed Description

Author
V. Maroussov

Definition at line 26 of file rz_poly.h.

Constructor & Destructor Documentation

◆ rz_poly() [1/3]

magfieldparam::rz_poly::rz_poly ( )
inline

Definition at line 36 of file rz_poly.h.

36 : data(), max_nr(0), max_nz(0), n_active(0), r_pow(nullptr), z_pow(nullptr), is_off(nullptr){};

◆ rz_poly() [2/3]

rz_poly::rz_poly ( int  N)

Definition at line 8 of file rz_poly.cc.

References magfieldparam::poly_term::coeff, data, ntuplemaker::fill, visualization-live-secondInstance_cfg::m, N, magfieldparam::poly_term::np, EgHLTOffHistBins_cfi::nr, and nt.

8  {
9  int nz, nr = 0, nv, nt;
10  poly_term v3;
11 
12  if (N < 2)
13  N = 2;
14  data.reserve(N);
15 
16  v3.coeff = 1.;
17  v3.np[0] = 0;
18  v3.np[1] = 1;
19 
20  data.push_back(poly_vect(1, v3));
21 
22  for (int m = 2; m <= N; ++m) {
23  nz = m;
24  nr = 0;
25  nv = 0;
26  v3.coeff = 1. / m;
27  v3.np[0] = nr;
28  v3.np[1] = nz;
29 
30  nt = (m + 2) / 2;
31  poly_vect v3x(nt, v3);
32 
33  while (nz >= 2) {
34  nz -= 2;
35  nr += 2;
36  nv += 1;
37  v3x[nv].coeff = -v3x[nv - 1].coeff * (nz + 1) * (nz + 2) / (nr * nr);
38  v3x[nv].np[0] = nr;
39  v3x[nv].np[1] = nz;
40  }
41  data.push_back(v3x);
42  }
43  max_nr = nr + 1;
44  max_nz = N + 1;
45  r_pow = new double[max_nr];
46  z_pow = new double[max_nz];
47  fill(r_pow, r_pow + max_nr, 1.);
48  fill(z_pow, z_pow + max_nz, 1.);
49 
50  n_active = data.size();
51  is_off = new bool[n_active];
52  fill(is_off, is_off + n_active, false);
53 }
std::vector< poly_term > poly_vect
Definition: rz_poly.h:21
int nt
Definition: AMPTWrapper.h:42
#define N
Definition: blowfish.cc:9

◆ rz_poly() [3/3]

rz_poly::rz_poly ( const rz_poly S)

Definition at line 56 of file rz_poly.cc.

References filterCSVwithJSON::copy, and data.

56  {
57  data = S.data;
58  max_nr = S.max_nr;
59  max_nz = S.max_nz;
60  n_active = S.n_active;
61 
62  if (max_nr) {
63  r_pow = new double[max_nr];
64  copy(S.r_pow, S.r_pow + max_nr, r_pow);
65  } else
66  r_pow = nullptr;
67 
68  if (max_nz) {
69  z_pow = new double[max_nz];
70  copy(S.z_pow, S.z_pow + max_nz, z_pow);
71  } else
72  z_pow = nullptr;
73 
74  if (S.is_off) {
75  is_off = new bool[data.size()];
76  copy(S.is_off, S.is_off + data.size(), is_off);
77  } else
78  is_off = nullptr;
79 }

◆ ~rz_poly()

rz_poly::~rz_poly ( )

Definition at line 82 of file rz_poly.cc.

82  {
83  if (is_off)
84  delete[] is_off;
85  if (r_pow)
86  delete[] r_pow;
87  if (z_pow)
88  delete[] z_pow;
89 }

Member Function Documentation

◆ Diff()

rz_poly rz_poly::Diff ( int  nvar,
bool  keep_empty = false 
)

Definition at line 132 of file rz_poly.cc.

References magfieldparam::poly_term::coeff, filterCSVwithJSON::copy, data, data, is_off, max_nr, max_nz, n_active, magfieldparam::poly_term::np, r_pow, findQualityFiles::size, and z_pow.

Referenced by magfieldparam::BFit::BFit().

132  {
133  //Return the derivative of original polynomial by variable nvar.
134  //If keep_empty=true, resulting polynomial may contain zero basis terms,
135  //otherwise the resulting polynomial will be compressed, so that corresponding
136  //basis terms will be shifted relatively to the original polynomial.
137  //
138  poly_term v3;
139  rz_poly p_out;
140  p_out.data.reserve(data.size());
141 
142  bool *tmp_mask = new bool[data.size()];
143  unsigned int ind_tmp = 0;
144  int tmp_act = 0;
145 
146  for (unsigned int ip = 0; ip < data.size(); ++ip) {
147  poly_vect v3x;
148  v3x.reserve(data[ip].size());
149  for (unsigned int it = 0; it < data[ip].size(); ++it) {
150  v3 = data[ip][it];
151  v3.coeff = data[ip][it].coeff * data[ip][it].np[nvar];
152  if (v3.coeff != 0) {
153  v3.np[nvar] = data[ip][it].np[nvar] - 1;
154  v3x.push_back(v3);
155  }
156  }
157  if (!v3x.empty() || keep_empty) {
158  v3x.resize(v3x.size());
159  p_out.data.push_back(v3x);
160  tmp_mask[ind_tmp] = is_off[ip];
161  ++ind_tmp;
162  if (!is_off[ip])
163  ++tmp_act;
164  }
165  }
166 
167  p_out.data.resize(p_out.data.size());
168  p_out.max_nr = max_nr;
169  p_out.max_nz = max_nz;
170 
171  if (nvar == 0)
172  --p_out.max_nr;
173  else
174  --p_out.max_nz;
175 
176  p_out.r_pow = new double[p_out.max_nr];
177  copy(r_pow, r_pow + p_out.max_nr, p_out.r_pow);
178  p_out.z_pow = new double[p_out.max_nz];
179  copy(z_pow, z_pow + p_out.max_nz, p_out.z_pow);
180 
181  p_out.n_active = tmp_act;
182  p_out.is_off = new bool[p_out.data.size()];
183  copy(tmp_mask, tmp_mask + p_out.data.size(), p_out.is_off);
184 
185  delete[] tmp_mask;
186 
187  return p_out;
188 }
size
Write out results.
std::vector< poly_term > poly_vect
Definition: rz_poly.h:21

◆ Expand()

double * rz_poly::Expand ( double *  C)

Definition at line 330 of file rz_poly.cc.

References correctionTermsCaloMet_cff::C, data, and createfilelist::int.

330  {
331  //Take C[n_active] - reduced vector of coefficients and return pointer to
332  //expanded vector of coefficients of the data.size() length. It is in user's
333  //responsibility to free the memory after all;
334  //
335  double *rez = new double[data.size()];
336  for (int ip = 0; ip < (int)data.size(); ++ip) {
337  if (is_off[ip])
338  rez[ip] = 0.;
339  else {
340  rez[ip] = *C;
341  ++C;
342  }
343  }
344  return rez;
345 }

◆ GetLength()

int magfieldparam::rz_poly::GetLength ( ) const
inline

Definition at line 60 of file rz_poly.h.

References data.

60 { return (int)data.size(); }

◆ GetMaxRPow()

int magfieldparam::rz_poly::GetMaxRPow ( ) const
inline

Definition at line 58 of file rz_poly.h.

References max_nr.

58 { return max_nr - 1; }

◆ GetMaxZPow()

int magfieldparam::rz_poly::GetMaxZPow ( ) const
inline

Definition at line 59 of file rz_poly.h.

References max_nz.

59 { return max_nz - 1; }

◆ GetNActive()

int magfieldparam::rz_poly::GetNActive ( ) const
inline

Definition at line 61 of file rz_poly.h.

References n_active.

61 { return n_active; }

◆ GetSVal()

double rz_poly::GetSVal ( double  r,
double  z,
const double *  C 
) const

Definition at line 257 of file rz_poly.cc.

References correctionTermsCaloMet_cff::C, data, createfilelist::int, alignCSCRings::r, and findQualityFiles::size.

257  {
258  //Return value of a polynomial, ignoring terms, that are switched off
259 
260  if (r_pow == nullptr)
261  return 0.;
262 
263  double term, rez = 0.;
264  int ip, it;
265 
266  if (r != r_pow[1])
267  for (ip = 1; ip < max_nr; ++ip)
268  r_pow[ip] = r * r_pow[ip - 1];
269  if (z != z_pow[1])
270  for (ip = 1; ip < max_nz; ++ip)
271  z_pow[ip] = z * z_pow[ip - 1];
272 
273  for (ip = 0; ip < (int)data.size(); ++ip) {
274  if (is_off[ip])
275  continue;
276  term = 0.;
277  for (it = 0; it < (int)data[ip].size(); ++it) {
278  term += data[ip][it].coeff * r_pow[data[ip][it].np[0]] * z_pow[data[ip][it].np[1]];
279  }
280  rez += *C * term;
281  ++C;
282  }
283 
284  return rez;
285 }
size
Write out results.

◆ GetVVal()

double * rz_poly::GetVVal ( double  r,
double  z,
double *  rez_out = nullptr 
)

Definition at line 288 of file rz_poly.cc.

References data, createfilelist::int, alignCSCRings::r, and findQualityFiles::size.

288  {
289  //return an array of doubleype with values of the basis functions in the point
290  //(r,z). In a case if rez_out != 0, the rez_out array must be long enough to fit
291  //in n_active elements. In a case if rez_out == 0, a new array of n_active length
292  //is created; it is in user's responsibility to free the memory after all;
293  //
294  if (r_pow == nullptr)
295  return nullptr;
296 
297  double term;
298  int ip, it;
299 
300  double *rez;
301  if (rez_out)
302  rez = rez_out;
303  else
304  rez = new double[n_active];
305 
306  double *pnt = rez;
307 
308  if (r != r_pow[1])
309  for (ip = 1; ip < max_nr; ++ip)
310  r_pow[ip] = r * r_pow[ip - 1];
311  if (z != z_pow[1])
312  for (ip = 1; ip < max_nz; ++ip)
313  z_pow[ip] = z * z_pow[ip - 1];
314 
315  for (ip = 0; ip < (int)data.size(); ++ip) {
316  if (is_off[ip])
317  continue;
318  term = 0.;
319  for (it = 0; it < (int)data[ip].size(); ++it) {
320  term += data[ip][it].coeff * r_pow[data[ip][it].np[0]] * z_pow[data[ip][it].np[1]];
321  }
322  *pnt = term;
323  ++pnt;
324  }
325 
326  return rez;
327 }
size
Write out results.

◆ Int()

rz_poly rz_poly::Int ( int  nvar)

Definition at line 191 of file rz_poly.cc.

References filterCSVwithJSON::copy, data, data, is_off, max_nr, max_nz, n_active, r_pow, and z_pow.

191  {
192  //Return the integral of original polynomial by variable nvar
193  //
194  rz_poly p_out;
195  p_out.data = data;
196  for (unsigned int ip = 0; ip < data.size(); ++ip) {
197  for (unsigned int it = 0; it < data[ip].size(); ++it) {
198  p_out.data[ip][it].coeff /= ++p_out.data[ip][it].np[nvar];
199  }
200  }
201 
202  p_out.max_nr = max_nr;
203  p_out.max_nz = max_nz;
204 
205  if (nvar == 0)
206  ++p_out.max_nr;
207  else
208  ++p_out.max_nz;
209 
210  p_out.r_pow = new double[p_out.max_nr];
211  copy(r_pow, r_pow + max_nr, p_out.r_pow);
212  p_out.z_pow = new double[p_out.max_nz];
213  copy(z_pow, z_pow + max_nz, p_out.z_pow);
214 
215  if (nvar == 0)
216  p_out.r_pow[max_nr] = p_out.r_pow[max_nr - 1] * r_pow[1];
217  else
218  p_out.z_pow[max_nz] = p_out.z_pow[max_nz - 1] * z_pow[1];
219 
220  p_out.n_active = n_active;
221  p_out.is_off = new bool[data.size()];
222  copy(is_off, is_off + data.size(), p_out.is_off);
223 
224  return p_out;
225 }

◆ operator*=() [1/2]

rz_poly & rz_poly::operator*= ( double  C)

Definition at line 228 of file rz_poly.cc.

References correctionTermsCaloMet_cff::C, and data.

228  {
229  //Multiply the polynomial by a constant. Skips terms that are switched off
230 
231  for (unsigned int ip = 0; ip < data.size(); ++ip) {
232  if (is_off[ip])
233  continue;
234  for (unsigned int it = 0; it < data[ip].size(); ++it) {
235  data[ip][it].coeff *= C;
236  }
237  }
238  return *this;
239 }

◆ operator*=() [2/2]

rz_poly & rz_poly::operator*= ( double *  C)

Definition at line 242 of file rz_poly.cc.

References correctionTermsCaloMet_cff::C, and data.

242  {
243  //Multiply the polynomial by an array. Skips terms that are switched off
244 
245  for (unsigned int ip = 0; ip < data.size(); ++ip) {
246  if (is_off[ip])
247  continue;
248  for (unsigned int it = 0; it < data[ip].size(); ++it) {
249  data[ip][it].coeff *= *C;
250  }
251  ++C;
252  }
253  return *this;
254 }

◆ Print()

void rz_poly::Print ( void  )

Definition at line 112 of file rz_poly.cc.

References gather_cfg::cout, and data.

112  {
113  if (data.empty()) {
114  cout << "The \"rz_poly\" object is NOT initialized!" << endl;
115  return;
116  }
117 
118  for (unsigned int ip = 0; ip < data.size(); ++ip) {
119  cout << "Polynomial " << ip << " (size=" << data[ip].size() << ", status=";
120  if (is_off[ip])
121  cout << "OFF):" << endl;
122  else
123  cout << "ON):" << endl;
124  for (unsigned int it = 0; it < data[ip].size(); ++it) {
125  cout << "\tnr=" << data[ip][it].np[0] << "\tnz=" << data[ip][it].np[1] << "\tcoeff=" << data[ip][it].coeff
126  << endl;
127  }
128  }
129 }

◆ SetAllON()

void magfieldparam::rz_poly::SetAllON ( int  npoly)
inline

Definition at line 44 of file rz_poly.h.

References data, ntuplemaker::fill, and is_off.

44  {
45  if (is_off)
46  std::fill(is_off, is_off + data.size(), false);
47  }

◆ SetOFF()

void rz_poly::SetOFF ( int  npoly)

Definition at line 92 of file rz_poly.cc.

References data.

Referenced by magfieldparam::BFit::BFit().

92  {
93  if ((npoly < 0) || (npoly >= (int)data.size()))
94  return;
95  if (is_off[npoly])
96  return;
97  is_off[npoly] = true;
98  --n_active;
99 }

◆ SetON()

void rz_poly::SetON ( int  npoly)

Definition at line 102 of file rz_poly.cc.

References data.

102  {
103  if ((npoly < 0) || (npoly >= (int)data.size()))
104  return;
105  if (is_off[npoly]) {
106  is_off[npoly] = false;
107  ++n_active;
108  }
109 }

Member Data Documentation

◆ data

poly_arr magfieldparam::rz_poly::data
private

◆ is_off

bool* magfieldparam::rz_poly::is_off
private

Definition at line 33 of file rz_poly.h.

Referenced by Diff(), Int(), and SetAllON().

◆ max_nr

int magfieldparam::rz_poly::max_nr
private

Definition at line 30 of file rz_poly.h.

Referenced by Diff(), GetMaxRPow(), and Int().

◆ max_nz

int magfieldparam::rz_poly::max_nz
private

Definition at line 30 of file rz_poly.h.

Referenced by Diff(), GetMaxZPow(), and Int().

◆ n_active

int magfieldparam::rz_poly::n_active
private

Definition at line 30 of file rz_poly.h.

Referenced by Diff(), GetNActive(), and Int().

◆ r_pow

double* magfieldparam::rz_poly::r_pow
private

Definition at line 31 of file rz_poly.h.

Referenced by Diff(), and Int().

◆ z_pow

double* magfieldparam::rz_poly::z_pow
private

Definition at line 32 of file rz_poly.h.

Referenced by Diff(), and Int().