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 (const rz_poly &S)
 
 rz_poly (int N)
 
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.

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 }

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

◆ rz_poly() [3/3]

rz_poly::rz_poly ( const rz_poly S)

Definition at line 56 of file rz_poly.cc.

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 }

References filterCSVwithJSON::copy, and data.

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

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 }

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

◆ Expand()

double * rz_poly::Expand ( double *  C)

Definition at line 330 of file rz_poly.cc.

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 }

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

◆ GetLength()

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

Definition at line 60 of file rz_poly.h.

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

References data.

◆ GetMaxRPow()

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

Definition at line 58 of file rz_poly.h.

58 { return max_nr - 1; }

References max_nr.

◆ GetMaxZPow()

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

Definition at line 59 of file rz_poly.h.

59 { return max_nz - 1; }

References max_nz.

◆ GetNActive()

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

Definition at line 61 of file rz_poly.h.

61 { return n_active; }

References n_active.

◆ GetSVal()

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

Definition at line 257 of file rz_poly.cc.

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 }

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

◆ GetVVal()

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

Definition at line 288 of file rz_poly.cc.

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 }

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

◆ Int()

rz_poly rz_poly::Int ( int  nvar)

Definition at line 191 of file rz_poly.cc.

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 }

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

◆ operator*=() [1/2]

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

Definition at line 242 of file rz_poly.cc.

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 }

References gen::C, and data.

◆ operator*=() [2/2]

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

Definition at line 228 of file rz_poly.cc.

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 }

References gen::C, and data.

◆ Print()

void rz_poly::Print ( void  )

Definition at line 112 of file rz_poly.cc.

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 }

References gather_cfg::cout, and data.

◆ SetAllON()

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

Definition at line 44 of file rz_poly.h.

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

References data, ntuplemaker::fill, and is_off.

◆ SetOFF()

void rz_poly::SetOFF ( int  npoly)

Definition at line 92 of file rz_poly.cc.

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 }

References data.

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

◆ SetON()

void rz_poly::SetON ( int  npoly)

Definition at line 102 of file rz_poly.cc.

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 }

References data.

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

filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
nt
int nt
Definition: AMPTWrapper.h:42
magfieldparam::rz_poly::data
poly_arr data
Definition: rz_poly.h:29
gather_cfg.cout
cout
Definition: gather_cfg.py:144
magfieldparam::poly_vect
std::vector< poly_term > poly_vect
Definition: rz_poly.h:21
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
DDAxes::z
N
#define N
Definition: blowfish.cc:9
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
createfilelist.int
int
Definition: createfilelist.py:10
magfieldparam::rz_poly
Definition: rz_poly.h:26
magfieldparam::poly_term
Definition: rz_poly.h:15
magfieldparam::rz_poly::r_pow
double * r_pow
Definition: rz_poly.h:31
magfieldparam::rz_poly::max_nz
int max_nz
Definition: rz_poly.h:30
alignCSCRings.r
r
Definition: alignCSCRings.py:93
magfieldparam::rz_poly::n_active
int n_active
Definition: rz_poly.h:30
magfieldparam::poly_term::np
int np[2]
Definition: rz_poly.h:17
gen::C
C
Definition: PomwigHadronizer.cc:78
magfieldparam::rz_poly::max_nr
int max_nr
Definition: rz_poly.h:30
S
Definition: CSCDBL1TPParametersExtended.h:16
magfieldparam::poly_term::coeff
double coeff
Definition: rz_poly.h:16
magfieldparam::rz_poly::is_off
bool * is_off
Definition: rz_poly.h:33
magfieldparam::rz_poly::z_pow
double * z_pow
Definition: rz_poly.h:32
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443