CMS 3D CMS Logo

Public Member Functions | Private Attributes

magfieldparam::rz_poly Class Reference

#include <rz_poly.h>

List of all members.

Public Member Functions

rz_poly Diff (int nvar, bool keep_empty=false)
double * Expand (double *C)
int GetLength ()
int GetMaxRPow ()
int GetMaxZPow ()
int GetNActive ()
double GetSVal (double r, double z, double *C)
double * GetVVal (double r, double z, double *rez_out=0)
rz_poly Int (int nvar)
rz_polyoperator*= (double C)
rz_polyoperator*= (double *C)
void Print ()
 rz_poly (int N)
 rz_poly ()
 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

Date:
2011/04/16 10:20:40
Revision:
1.1
Author:
V. Maroussov

Definition at line 28 of file rz_poly.h.


Constructor & Destructor Documentation

magfieldparam::rz_poly::rz_poly ( ) [inline]

Definition at line 40 of file rz_poly.h.

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

Definition at line 8 of file rz_poly.cc.

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

{
   int nz, nr = 0, nv, nt;
   poly_term  v3;
   
   if (N < 2) N = 2;
   data.reserve(N);

   v3.coeff = 1.;
   v3.np[0] = 0;
   v3.np[1] = 1;
   
   data.push_back(poly_vect(1, v3));
   
   for (int m = 2; m <=N; ++m) {
      nz = m;
      nr = 0;
      nv = 0;
      v3.coeff = 1./m;
      v3.np[0] = nr;
      v3.np[1] = nz;

      nt = (m + 2) / 2;
      poly_vect v3x(nt, v3);
      
      while (nz >= 2) {
         nz -= 2;
         nr += 2;
         nv += 1;
         v3x[nv].coeff = -v3x[nv-1].coeff*(nz+1)*(nz+2)/(nr*nr);
         v3x[nv].np[0] = nr;
         v3x[nv].np[1] = nz;
      }
      data.push_back(v3x);
   }
   max_nr = nr+1;
   max_nz = N +1;
   r_pow = new double [max_nr];
   z_pow = new double [max_nz];
   fill(r_pow, r_pow+max_nr, 1.);
   fill(z_pow, z_pow+max_nz, 1.);
   
   n_active = data.size();
   is_off = new bool [n_active];
   fill(is_off, is_off+n_active, false);
}
rz_poly::rz_poly ( const rz_poly S)

Definition at line 56 of file rz_poly.cc.

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

{
   data = S.data;
   max_nr = S.max_nr;
   max_nz = S.max_nz;
   n_active = S.n_active;

   if (max_nr) {
      r_pow = new double [max_nr];
      copy(S.r_pow, S.r_pow+max_nr, r_pow);
   } else r_pow = 0;

   if (max_nz) {
      z_pow = new double [max_nz];
      copy(S.z_pow, S.z_pow+max_nz, z_pow);
   } else z_pow = 0;

   if (S.is_off) {
      is_off = new bool [data.size()];
      copy(S.is_off, S.is_off+data.size(), is_off);
   } else is_off = 0;
}
rz_poly::~rz_poly ( )

Definition at line 80 of file rz_poly.cc.

{
   if (is_off) delete [] is_off;
   if (r_pow)  delete [] r_pow;
   if (z_pow)  delete [] z_pow;
}

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, filterCSVwithJSON::copy, data, AlCaHLTBitMon_QueryRunRegistry::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().

{
//Return the derivative of original polynomial by variable nvar. 
//If keep_empty=true, resulting polynomial may contain zero basis terms,
//otherwise the resulting polynomial will be compressed, so that corresponding
//basis terms will be shifted relatively to the original polynomial.
//
   poly_term  v3;
   rz_poly p_out;
   p_out.data.reserve(data.size());
   
   bool *tmp_mask = new bool [data.size()];
   unsigned int  ind_tmp = 0;
   int   tmp_act = 0;
   
   for (unsigned int ip = 0; ip < data.size(); ++ip) {
      poly_vect v3x;
      v3x.reserve(data[ip].size());
      for (unsigned int it = 0; it < data[ip].size(); ++it) {
         v3 = data[ip][it];
         v3.coeff = data[ip][it].coeff * data[ip][it].np[nvar];
         if (v3.coeff != 0) {
            v3.np[nvar] = data[ip][it].np[nvar] - 1;
            v3x.push_back(v3);
         }
      }
      if (v3x.size() || keep_empty) {
         v3x.resize(v3x.size());
         p_out.data.push_back(v3x);
         tmp_mask[ind_tmp] = is_off[ip];
         ++ind_tmp;
         if (! is_off[ip]) ++tmp_act;
      }
   }
   
   p_out.data.resize(p_out.data.size());
   p_out.max_nr = max_nr;
   p_out.max_nz = max_nz;

   if (nvar == 0) --p_out.max_nr; else --p_out.max_nz;
   
   p_out.r_pow = new double [p_out.max_nr];
   copy(r_pow, r_pow+p_out.max_nr, p_out.r_pow);
   p_out.z_pow = new double [p_out.max_nz];
   copy(z_pow, z_pow+p_out.max_nz, p_out.z_pow);
   
   p_out.n_active = tmp_act;
   p_out.is_off = new bool [p_out.data.size()];
   copy(tmp_mask, tmp_mask+p_out.data.size(), p_out.is_off);
   
   delete [] tmp_mask;

   return p_out;
}
double * rz_poly::Expand ( double *  C)

Definition at line 311 of file rz_poly.cc.

References funct::C, and AlCaHLTBitMon_QueryRunRegistry::data.

{
//Take C[n_active] - reduced vector of coefficients and return pointer to 
//expanded vector of coefficients of the data.size() length. It is in user's
//responsibility to free the memory after all;
//
   double *rez = new double [data.size()];
   for (int ip = 0; ip < (int)data.size(); ++ip) {
      if (is_off[ip]) rez[ip] = 0.;
      else {
         rez[ip] = *C;
         ++C;
      }
   }
   return rez;
}
int magfieldparam::rz_poly::GetLength ( ) [inline]

Definition at line 62 of file rz_poly.h.

References data.

{return (int)data.size();}
int magfieldparam::rz_poly::GetMaxRPow ( ) [inline]

Definition at line 60 of file rz_poly.h.

References max_nr.

{return max_nr-1;}
int magfieldparam::rz_poly::GetMaxZPow ( ) [inline]

Definition at line 61 of file rz_poly.h.

References max_nz.

{return max_nz-1;}
int magfieldparam::rz_poly::GetNActive ( ) [inline]

Definition at line 63 of file rz_poly.h.

References n_active.

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

Definition at line 246 of file rz_poly.cc.

References funct::C, AlCaHLTBitMon_QueryRunRegistry::data, and findQualityFiles::size.

{
//Return value of a polynomial, ignoring terms, that are switched off

   if (r_pow == 0) return 0.;
   
   double term, rez = 0.;
   int ip, it;
   
   if (r != r_pow[1]) for (ip = 1; ip < max_nr; ++ip) r_pow[ip] = r*r_pow[ip-1];
   if (z != z_pow[1]) for (ip = 1; ip < max_nz; ++ip) z_pow[ip] = z*z_pow[ip-1];

   for (ip = 0; ip < (int)data.size(); ++ip) {
      if (is_off[ip]) continue;
      term = 0.;
      for (it = 0; it < (int)data[ip].size(); ++it) {
         term += data[ip][it].coeff
               * r_pow[data[ip][it].np[0]]
               * z_pow[data[ip][it].np[1]];
      }
      rez += *C * term;
      ++C;
   }
   
   return rez;
}
double * rz_poly::GetVVal ( double  r,
double  z,
double *  rez_out = 0 
)

Definition at line 274 of file rz_poly.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, and findQualityFiles::size.

{
//return an array of doubleype with values of the basis functions in the point
//(r,z). In a case if rez_out != 0, the rez_out array must be long enough to fit
//in n_active elements. In a case if rez_out == 0, a new array of n_active length
//is created; it is in user's responsibility to free the memory after all;
//
   if (r_pow == 0) return 0;
   
   double term;
   int ip, it;

   double *rez;
   if (rez_out) rez = rez_out;
   else rez = new double [n_active];

   double *pnt = rez;
   
   if (r != r_pow[1]) for (ip = 1; ip < max_nr; ++ip) r_pow[ip] = r*r_pow[ip-1];
   if (z != z_pow[1]) for (ip = 1; ip < max_nz; ++ip) z_pow[ip] = z*z_pow[ip-1];

   for (ip = 0; ip < (int)data.size(); ++ip) {
      if (is_off[ip]) continue;
      term = 0.;
      for (it = 0; it < (int)data[ip].size(); ++it) {
         term += data[ip][it].coeff
               * r_pow[data[ip][it].np[0]]
               * z_pow[data[ip][it].np[1]];
      }
      *pnt = term;
      ++pnt;
   }
   
   return rez;
}
rz_poly rz_poly::Int ( int  nvar)

Definition at line 184 of file rz_poly.cc.

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

{
//Return the integral of original polynomial by variable nvar
//
   rz_poly p_out;
   p_out.data = data;
   for (unsigned int ip = 0; ip < data.size(); ++ip) {
      for (unsigned int it = 0; it < data[ip].size(); ++it) {
         p_out.data[ip][it].coeff /= ++p_out.data[ip][it].np[nvar];
      }
   }
   
   p_out.max_nr = max_nr;
   p_out.max_nz = max_nz;

   if (nvar == 0) ++p_out.max_nr; else ++p_out.max_nz;
   
   p_out.r_pow = new double [p_out.max_nr];
   copy(r_pow, r_pow+max_nr, p_out.r_pow);
   p_out.z_pow = new double [p_out.max_nz];
   copy(z_pow, z_pow+max_nz, p_out.z_pow);
   
   if (nvar == 0) p_out.r_pow[max_nr] = p_out.r_pow[max_nr-1] * r_pow[1];
   else           p_out.z_pow[max_nz] = p_out.z_pow[max_nz-1] * z_pow[1];

   p_out.n_active = n_active;
   p_out.is_off = new bool [data.size()];
   copy(is_off, is_off+data.size(), p_out.is_off);
   
   return p_out;
}
rz_poly & rz_poly::operator*= ( double *  C)

Definition at line 231 of file rz_poly.cc.

References funct::C, and AlCaHLTBitMon_QueryRunRegistry::data.

{
//Multiply the polynomial by an array. Skips terms that are switched off

   for (unsigned int ip = 0; ip < data.size(); ++ip) {
      if (is_off[ip]) continue;
      for (unsigned int it = 0; it < data[ip].size(); ++it) {
         data[ip][it].coeff *= *C;
      }
      ++C;
   }
   return *this;
}
rz_poly & rz_poly::operator*= ( double  C)

Definition at line 217 of file rz_poly.cc.

References funct::C, and AlCaHLTBitMon_QueryRunRegistry::data.

{
//Multiply the polynomial by a constant. Skips terms that are switched off

   for (unsigned int ip = 0; ip < data.size(); ++ip) {
      if (is_off[ip]) continue;
      for (unsigned int it = 0; it < data[ip].size(); ++it) {
         data[ip][it].coeff *= C;
      }
   }
   return *this;
}
void rz_poly::Print ( void  )

Definition at line 107 of file rz_poly.cc.

References gather_cfg::cout, and AlCaHLTBitMon_QueryRunRegistry::data.

{
   if (!data.size()) {
      cout << "The \"rz_poly\" object is NOT initialized!" << endl;
      return;
   }
   
   for (unsigned int ip = 0; ip < data.size(); ++ip) {
      cout << "Polynomial " << ip << " (size=" << data[ip].size() << ", status=";
      if (is_off[ip]) cout << "OFF):" << endl;
      else            cout << "ON):"  << endl;
      for (unsigned int it = 0; it < data[ip].size(); ++it) {
         cout << "\tnr="    << data[ip][it].np[0]
              << "\tnz="    << data[ip][it].np[1]
              << "\tcoeff=" << data[ip][it].coeff
              << endl;
      }
   }
}
void magfieldparam::rz_poly::SetAllON ( int  npoly) [inline]

Definition at line 49 of file rz_poly.h.

References data, lumiContext::fill, and is_off.

{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 AlCaHLTBitMon_QueryRunRegistry::data.

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

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

Definition at line 97 of file rz_poly.cc.

References AlCaHLTBitMon_QueryRunRegistry::data.

{
   if ((npoly < 0) || (npoly >= (int)data.size())) return;
   if (is_off[npoly]) {
      is_off[npoly] = false;
      ++n_active;
   }
}

Member Data Documentation

Definition at line 32 of file rz_poly.h.

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

Definition at line 36 of file rz_poly.h.

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

Definition at line 33 of file rz_poly.h.

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

Definition at line 33 of file rz_poly.h.

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

Definition at line 33 of file rz_poly.h.

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

double* magfieldparam::rz_poly::r_pow [private]

Definition at line 34 of file rz_poly.h.

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

double* magfieldparam::rz_poly::z_pow [private]

Definition at line 35 of file rz_poly.h.

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