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

magfieldparam::rz_poly::rz_poly ( )
inline

Definition at line 38 of file rz_poly.h.

References N.

38  : data(), max_nr(0), max_nz(0), n_active(0),
39  r_pow(nullptr), z_pow(nullptr), is_off(nullptr) {};
rz_poly::rz_poly ( int  N)

Definition at line 8 of file rz_poly.cc.

References magfieldparam::poly_term::coeff, data, lumiContext::fill, funct::m, N, magfieldparam::poly_term::np, and nt.

9 {
10  int nz, nr = 0, nv, nt;
11  poly_term v3;
12 
13  if (N < 2) 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:32
#define N
Definition: blowfish.cc:9
rz_poly::rz_poly ( const rz_poly S)

Definition at line 56 of file rz_poly.cc.

References popcon2dropbox::copy(), data, data, is_off, max_nr, max_nz, n_active, r_pow, and z_pow.

57 {
58  data = S.data;
59  max_nr = S.max_nr;
60  max_nz = S.max_nz;
61  n_active = S.n_active;
62 
63  if (max_nr) {
64  r_pow = new double [max_nr];
65  copy(S.r_pow, S.r_pow+max_nr, r_pow);
66  } else 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 z_pow = nullptr;
72 
73  if (S.is_off) {
74  is_off = new bool [data.size()];
75  copy(S.is_off, S.is_off+data.size(), is_off);
76  } else is_off = nullptr;
77 }
def copy(args, dbName)
rz_poly::~rz_poly ( )

Definition at line 80 of file rz_poly.cc.

81 {
82  if (is_off) delete [] is_off;
83  if (r_pow) delete [] r_pow;
84  if (z_pow) delete [] z_pow;
85 }

Member Function Documentation

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

Definition at line 128 of file rz_poly.cc.

References magfieldparam::poly_term::coeff, popcon2dropbox::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().

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

Definition at line 311 of file rz_poly.cc.

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

312 {
313 //Take C[n_active] - reduced vector of coefficients and return pointer to
314 //expanded vector of coefficients of the data.size() length. It is in user's
315 //responsibility to free the memory after all;
316 //
317  double *rez = new double [data.size()];
318  for (int ip = 0; ip < (int)data.size(); ++ip) {
319  if (is_off[ip]) rez[ip] = 0.;
320  else {
321  rez[ip] = *C;
322  ++C;
323  }
324  }
325  return rez;
326 }
int magfieldparam::rz_poly::GetLength ( ) const
inline

Definition at line 60 of file rz_poly.h.

60 {return (int)data.size();}
int magfieldparam::rz_poly::GetMaxRPow ( ) const
inline

Definition at line 58 of file rz_poly.h.

58 {return max_nr-1;}
int magfieldparam::rz_poly::GetMaxZPow ( ) const
inline

Definition at line 59 of file rz_poly.h.

59 {return max_nz-1;}
int magfieldparam::rz_poly::GetNActive ( ) const
inline

Definition at line 61 of file rz_poly.h.

61 {return n_active;}
double rz_poly::GetSVal ( double  r,
double  z,
const double *  C 
) const

Definition at line 246 of file rz_poly.cc.

References patCaloMETCorrections_cff::C, data, createfilelist::int, and findQualityFiles::size.

247 {
248 //Return value of a polynomial, ignoring terms, that are switched off
249 
250  if (r_pow == nullptr) return 0.;
251 
252  double term, rez = 0.;
253  int ip, it;
254 
255  if (r != r_pow[1]) for (ip = 1; ip < max_nr; ++ip) r_pow[ip] = r*r_pow[ip-1];
256  if (z != z_pow[1]) for (ip = 1; ip < max_nz; ++ip) z_pow[ip] = z*z_pow[ip-1];
257 
258  for (ip = 0; ip < (int)data.size(); ++ip) {
259  if (is_off[ip]) continue;
260  term = 0.;
261  for (it = 0; it < (int)data[ip].size(); ++it) {
262  term += data[ip][it].coeff
263  * r_pow[data[ip][it].np[0]]
264  * z_pow[data[ip][it].np[1]];
265  }
266  rez += *C * term;
267  ++C;
268  }
269 
270  return rez;
271 }
size
Write out results.
double * rz_poly::GetVVal ( double  r,
double  z,
double *  rez_out = nullptr 
)

Definition at line 274 of file rz_poly.cc.

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

275 {
276 //return an array of doubleype with values of the basis functions in the point
277 //(r,z). In a case if rez_out != 0, the rez_out array must be long enough to fit
278 //in n_active elements. In a case if rez_out == 0, a new array of n_active length
279 //is created; it is in user's responsibility to free the memory after all;
280 //
281  if (r_pow == nullptr) return nullptr;
282 
283  double term;
284  int ip, it;
285 
286  double *rez;
287  if (rez_out) rez = rez_out;
288  else rez = new double [n_active];
289 
290  double *pnt = rez;
291 
292  if (r != r_pow[1]) for (ip = 1; ip < max_nr; ++ip) r_pow[ip] = r*r_pow[ip-1];
293  if (z != z_pow[1]) for (ip = 1; ip < max_nz; ++ip) z_pow[ip] = z*z_pow[ip-1];
294 
295  for (ip = 0; ip < (int)data.size(); ++ip) {
296  if (is_off[ip]) continue;
297  term = 0.;
298  for (it = 0; it < (int)data[ip].size(); ++it) {
299  term += data[ip][it].coeff
300  * r_pow[data[ip][it].np[0]]
301  * z_pow[data[ip][it].np[1]];
302  }
303  *pnt = term;
304  ++pnt;
305  }
306 
307  return rez;
308 }
size
Write out results.
rz_poly rz_poly::Int ( int  nvar)

Definition at line 184 of file rz_poly.cc.

References popcon2dropbox::copy(), data, data, is_off, max_nr, max_nz, n_active, r_pow, and z_pow.

185 {
186 //Return the integral of original polynomial by variable nvar
187 //
188  rz_poly p_out;
189  p_out.data = data;
190  for (unsigned int ip = 0; ip < data.size(); ++ip) {
191  for (unsigned int it = 0; it < data[ip].size(); ++it) {
192  p_out.data[ip][it].coeff /= ++p_out.data[ip][it].np[nvar];
193  }
194  }
195 
196  p_out.max_nr = max_nr;
197  p_out.max_nz = max_nz;
198 
199  if (nvar == 0) ++p_out.max_nr; else ++p_out.max_nz;
200 
201  p_out.r_pow = new double [p_out.max_nr];
202  copy(r_pow, r_pow+max_nr, p_out.r_pow);
203  p_out.z_pow = new double [p_out.max_nz];
204  copy(z_pow, z_pow+max_nz, p_out.z_pow);
205 
206  if (nvar == 0) p_out.r_pow[max_nr] = p_out.r_pow[max_nr-1] * r_pow[1];
207  else p_out.z_pow[max_nz] = p_out.z_pow[max_nz-1] * z_pow[1];
208 
209  p_out.n_active = n_active;
210  p_out.is_off = new bool [data.size()];
211  copy(is_off, is_off+data.size(), p_out.is_off);
212 
213  return p_out;
214 }
def copy(args, dbName)
rz_poly & rz_poly::operator*= ( double  C)

Definition at line 217 of file rz_poly.cc.

References patCaloMETCorrections_cff::C, and data.

218 {
219 //Multiply the polynomial by a constant. Skips terms that are switched off
220 
221  for (unsigned int ip = 0; ip < data.size(); ++ip) {
222  if (is_off[ip]) continue;
223  for (unsigned int it = 0; it < data[ip].size(); ++it) {
224  data[ip][it].coeff *= C;
225  }
226  }
227  return *this;
228 }
rz_poly & rz_poly::operator*= ( double *  C)

Definition at line 231 of file rz_poly.cc.

References patCaloMETCorrections_cff::C, and data.

232 {
233 //Multiply the polynomial by an array. Skips terms that are switched off
234 
235  for (unsigned int ip = 0; ip < data.size(); ++ip) {
236  if (is_off[ip]) continue;
237  for (unsigned int it = 0; it < data[ip].size(); ++it) {
238  data[ip][it].coeff *= *C;
239  }
240  ++C;
241  }
242  return *this;
243 }
void rz_poly::Print ( void  )

Definition at line 107 of file rz_poly.cc.

References gather_cfg::cout, and data.

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

Definition at line 47 of file rz_poly.h.

References patCaloMETCorrections_cff::C, lumiContext::fill, operator*=(), and alignCSCRings::r.

47 {if (is_off) std::fill(is_off, is_off+data.size(), false);}
void rz_poly::SetOFF ( int  npoly)

Definition at line 88 of file rz_poly.cc.

References data.

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

89 {
90  if ((npoly < 0) || (npoly >= (int)data.size())) return;
91  if (is_off[npoly]) return;
92  is_off[npoly] = true;
93  --n_active;
94 }
void rz_poly::SetON ( int  npoly)

Definition at line 97 of file rz_poly.cc.

References data.

98 {
99  if ((npoly < 0) || (npoly >= (int)data.size())) return;
100  if (is_off[npoly]) {
101  is_off[npoly] = false;
102  ++n_active;
103  }
104 }

Member Data Documentation

poly_arr magfieldparam::rz_poly::data
private
bool* magfieldparam::rz_poly::is_off
private

Definition at line 34 of file rz_poly.h.

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

int magfieldparam::rz_poly::max_nr
private

Definition at line 31 of file rz_poly.h.

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

int magfieldparam::rz_poly::max_nz
private

Definition at line 31 of file rz_poly.h.

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

int magfieldparam::rz_poly::n_active
private

Definition at line 31 of file rz_poly.h.

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

double* magfieldparam::rz_poly::r_pow
private

Definition at line 32 of file rz_poly.h.

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

double* magfieldparam::rz_poly::z_pow
private

Definition at line 33 of file rz_poly.h.

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