CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

magfieldparam::rz_harm_poly Class Reference

#include <rz_harm_poly.h>

Inheritance diagram for magfieldparam::rz_harm_poly:
magfieldparam::poly2d_base

List of all members.

Public Member Functions

void CheatL (const unsigned newL)
double GetCos ()
rz_harm_poly GetDecPow (int nvar)
rz_harm_poly GetDiff (int nvar)
rz_harm_poly GetIncPow (int nvar)
rz_harm_poly GetInt (int nvar)
unsigned GetL ()
int GetM ()
double GetSin ()
bool IsPhiSet ()
rz_harm_poly LadderDwn ()
rz_harm_poly LadderUp ()
void Print (std::ostream &out=std::cout, const std::streamsize prec=5)
 rz_harm_poly (const rz_harm_poly &S)
 rz_harm_poly (const unsigned N)
 rz_harm_poly (const poly2d_base &S)
 rz_harm_poly ()
 ~rz_harm_poly ()

Static Public Member Functions

static unsigned Count ()
static int GetMaxM ()
static unsigned ParentCount ()
static void PrintTrigArr (std::ostream &out=std::cout, const std::streamsize prec=5)
static void SetPhi (const double phi)
static void SetPoint (const double r, const double z, const double phi)

Private Member Functions

void PrintLM (std::ostream &out=std::cout)

Static Private Member Functions

static void FillTrigArr (const double phi)
static void SetTrigArrSize (const unsigned N)

Private Attributes

unsigned L
int M

Static Private Attributes

static unsigned Cnt = 0
static unsigned MaxM = 0
static bool phi_set = false
static double phival = -11111.
static unsigned TASize = 0
static trig_pairTrigArr = 0

Detailed Description

Definition at line 38 of file rz_harm_poly.h.


Constructor & Destructor Documentation

magfieldparam::rz_harm_poly::rz_harm_poly ( ) [inline]

Definition at line 72 of file rz_harm_poly.h.

References Cnt.

Referenced by GetMaxM().

: poly2d_base(), L(0), M(0) {++Cnt;} 
magfieldparam::rz_harm_poly::rz_harm_poly ( const poly2d_base S) [inline]

Definition at line 73 of file rz_harm_poly.h.

References Cnt.

: poly2d_base(S), L(0), M(0) {++Cnt;}
magfieldparam::rz_harm_poly::rz_harm_poly ( const rz_harm_poly S) [inline]

Definition at line 74 of file rz_harm_poly.h.

References Cnt.

: poly2d_base(S), L(S.L), M(S.M) {++Cnt;}
rz_harm_poly::rz_harm_poly ( const unsigned  N)

Definition at line 23 of file rz_harm_poly.cc.

References Cnt, magfieldparam::poly2d_base::data, L, M, magfieldparam::poly2d_base::max_pwr, N, magfieldparam::poly2d_base::NPwr, phi_set, magfieldparam::poly2d_base::poly2d_base_set, and magfieldparam::poly2d_base::rz_set.

{
//Constructor for rz_harm_poly of length N. The polynomial P(r,z) is normalized
//in such a way that dP/dz(r=0,z)=z^(N-1)
//
   unsigned nz = N, nr = 0, nv = 0;
   poly2d_term v3(1./N, nr, nz);

   data = std::vector<poly2d_term>((N + 2) / 2, v3);

   while (nz >= 2) {
      nz -= 2;
      nr += 2;
      nv += 1;
      data[nv].coeff = -data[nv-1].coeff*(nz+1)*(nz+2)/(nr*nr);
      data[nv].np[0] = nr;
      data[nv].np[1] = nz;
   }
   max_pwr = N;
   if (max_pwr > NPwr) {
      NPwr = max_pwr;
      rz_set = false;
      phi_set = false;
   }
   L = N;
   M = 0;
   poly2d_base_set.insert(this);
   ++Cnt;
}
rz_harm_poly::~rz_harm_poly ( )

Definition at line 54 of file rz_harm_poly.cc.

References abs, Cnt, GetMaxM(), M, MaxM, phi_set, phival, TASize, and TrigArr.

{
   if (--Cnt) {
     if (std::abs(M) >= int(MaxM)) { //a number of objects still left
         M = 0;
         MaxM = GetMaxM();
      }
   } else { //last instance -> memory cleanup
      if (TrigArr) delete [] TrigArr;
      TrigArr = 0;
      TASize = 0;
      MaxM = 0;
      phival = -11111.;
      phi_set = false;
   }
}

Member Function Documentation

void magfieldparam::rz_harm_poly::CheatL ( const unsigned  newL) [inline]

Definition at line 97 of file rz_harm_poly.h.

References L.

{ L = newL;}
static unsigned magfieldparam::rz_harm_poly::Count ( ) [inline, static]

Reimplemented from magfieldparam::poly2d_base.

Definition at line 65 of file rz_harm_poly.h.

References Cnt.

Referenced by ParentCount().

{ return Cnt;}
void rz_harm_poly::FillTrigArr ( const double  phi) [static, private]

Definition at line 113 of file rz_harm_poly.cc.

References MaxM, and TrigArr.

Referenced by SetPhi().

{
//Fill TrigArr with trig_pair(jp*phi)
   if (!TrigArr) return;
   trig_pair tp(phi);
   TrigArr[1] = tp;
   for (unsigned jp = 2; jp <= MaxM; ++jp) TrigArr[jp] = TrigArr[jp-1].Add(tp);
}
double magfieldparam::rz_harm_poly::GetCos ( ) [inline]
rz_harm_poly magfieldparam::rz_harm_poly::GetDecPow ( int  nvar) [inline]

Definition at line 83 of file rz_harm_poly.h.

References magfieldparam::poly2d_base::DecPow(), and dttmaxenums::R.

{ rz_harm_poly R(*this); R.DecPow(nvar); return R;}
rz_harm_poly magfieldparam::rz_harm_poly::GetDiff ( int  nvar) [inline]

Definition at line 80 of file rz_harm_poly.h.

References magfieldparam::poly2d_base::Diff(), and dttmaxenums::R.

{ rz_harm_poly R(*this); R.Diff  (nvar); return R;}
rz_harm_poly magfieldparam::rz_harm_poly::GetIncPow ( int  nvar) [inline]

Definition at line 82 of file rz_harm_poly.h.

References magfieldparam::poly2d_base::IncPow(), and dttmaxenums::R.

{ rz_harm_poly R(*this); R.IncPow(nvar); return R;}
rz_harm_poly magfieldparam::rz_harm_poly::GetInt ( int  nvar) [inline]

Definition at line 81 of file rz_harm_poly.h.

References magfieldparam::poly2d_base::Int(), and dttmaxenums::R.

{ rz_harm_poly R(*this); R.Int   (nvar); return R;}
unsigned magfieldparam::rz_harm_poly::GetL ( ) [inline]

Definition at line 88 of file rz_harm_poly.h.

References L.

{ return L;}
int magfieldparam::rz_harm_poly::GetM ( ) [inline]

Definition at line 89 of file rz_harm_poly.h.

References M.

{ return M;}
int rz_harm_poly::GetMaxM ( ) [static]

Definition at line 72 of file rz_harm_poly.cc.

References abs, M, magfieldparam::poly2d_base::poly2d_base_set, and rz_harm_poly().

Referenced by ~rz_harm_poly().

{
//Return max abs(M) for all rz_harm_poly objects created
//
   int M_cur, M_max = 0;
   std::set<poly2d_base*>::iterator it;
   for (it = poly2d_base_set.begin(); it != poly2d_base_set.end(); ++it) {
      if (typeid(**it) == typeid(rz_harm_poly)) {
         M_cur = std::abs(((rz_harm_poly*)(*it))->M);
         if (M_cur > M_max) M_max = M_cur;
      }
   }
   return M_max;
}
double magfieldparam::rz_harm_poly::GetSin ( ) [inline]
bool magfieldparam::rz_harm_poly::IsPhiSet ( ) [inline]

Definition at line 78 of file rz_harm_poly.h.

References phi_set.

{ return phi_set;}
rz_harm_poly rz_harm_poly::LadderDwn ( )

Definition at line 193 of file rz_harm_poly.cc.

References abs, magfieldparam::poly2d_term::coeff, magfieldparam::poly2d_base::Collect(), magfieldparam::poly2d_base::data, L, M, MaxM, magfieldparam::poly2d_term::np, magfieldparam::poly2d_base::Scale(), and mathSSE::sqrt().

{
//Return a polynomial with decreased M
//
   rz_harm_poly p_out; p_out.data.reserve(2*L);
   unsigned it;
   poly2d_term term;

   //In 2 passes (for-cycles) to get terms in z-descending order
   for(it = 0; it < data.size(); ++it) {
      term = data[it];
      if (term.np[0]) {
         term.coeff *= -int(term.np[0]) - M;
         --term.np[0];
         ++term.np[1];
         p_out.data.push_back(term);
      }
   }
   for(it = 0; it < data.size(); ++it) {
      term = data[it];
      if (term.np[1]) {
         term.coeff *= term.np[1];
         --term.np[1];
         ++term.np[0];
         p_out.data.push_back(term);
      }
   }
   p_out.Collect();
   if (p_out.data.size()) {
      p_out.L = L;
      p_out.M = M-1;
      if (std::abs(p_out.M) > int(MaxM)) MaxM = std::abs(p_out.M);
      p_out.Scale(1./sqrt(double((L+M)*(L-M+1))));
   }
   return p_out;
}
rz_harm_poly rz_harm_poly::LadderUp ( )

Definition at line 155 of file rz_harm_poly.cc.

References abs, magfieldparam::poly2d_term::coeff, magfieldparam::poly2d_base::Collect(), magfieldparam::poly2d_base::data, L, M, MaxM, magfieldparam::poly2d_term::np, magfieldparam::poly2d_base::Scale(), and mathSSE::sqrt().

{
//Return a polynomial with increased M
//
   rz_harm_poly p_out; p_out.data.reserve(2*L);
   unsigned it;
   poly2d_term term;

   //In 2 passes (for-cycles) to get terms in z-descending order
   for(it = 0; it < data.size(); ++it) {
      term = data[it];
      if (term.np[0]) {
         term.coeff *= int(term.np[0]) - M;
         --term.np[0];
         ++term.np[1];
         p_out.data.push_back(term);
      }
   }
   for(it = 0; it < data.size(); ++it) {
      term = data[it];
      if (term.np[1]) {
         term.coeff *= -(int)term.np[1];
         --term.np[1];
         ++term.np[0];
         p_out.data.push_back(term);
      }
   }
   p_out.Collect();
   if (p_out.data.size()) {
      p_out.L = L;
      p_out.M = M+1;
      if (std::abs(p_out.M) > int(MaxM)) MaxM = std::abs(p_out.M);
      p_out.Scale(1./sqrt(double((L-M)*(L+M+1))));
   }
   return p_out;
}
static unsigned magfieldparam::rz_harm_poly::ParentCount ( ) [inline, static]

Definition at line 64 of file rz_harm_poly.h.

References Count().

{ return poly2d_base::Count();}
void magfieldparam::rz_harm_poly::Print ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
) [inline]

Reimplemented from magfieldparam::poly2d_base.

Definition at line 98 of file rz_harm_poly.h.

References dbtoconf::out, and PrintLM().

void magfieldparam::rz_harm_poly::PrintLM ( std::ostream &  out = std::cout) [inline, private]

Definition at line 55 of file rz_harm_poly.h.

References L, M, and dbtoconf::out.

Referenced by Print().

   {
      out <<  "L=" << std::setw(3)  << std::left << L
          <<", M=" << std::setw(3)  << std::left << M << "; ";
   }
void rz_harm_poly::PrintTrigArr ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
) [static]

Definition at line 123 of file rz_harm_poly.cc.

References magfieldparam::trig_pair::CosPhi, MaxM, magfieldparam::trig_pair::SinPhi, TASize, and TrigArr.

{
   out << "TrigArr: TASize = " << TASize
       << "\tMaxM = " << MaxM << std::endl;
   if (TrigArr) {
      if (MaxM < TASize) {
         unsigned jm;
         std::streamsize old_prec = out.precision(), wdt = prec+7;
         out.precision(prec);
         out << "M:     ";
         for (jm = 0; jm <= MaxM; ++jm) {
            out << std::setw(wdt) << std::left << jm;
         }
         out << "|\nCos_M: ";
         for (jm = 0; jm <= MaxM; ++jm) {
            out << std::setw(wdt) << std::left << TrigArr[jm].CosPhi;
         }
         out << "|\nSin_M: ";
         for (jm = 0; jm <= MaxM; ++jm) {
            out << std::setw(wdt) << std::left << TrigArr[jm].SinPhi;
         }
         out << "|" << std::endl;
         out.precision(old_prec);
      } else {
         out << "\tTrigArr size is not adjusted." << std::endl;
      }
   } else {
      out << "\tTrigArr is not allocated." << std::endl;
   }
}
void rz_harm_poly::SetPhi ( const double  phi) [static]

Definition at line 88 of file rz_harm_poly.cc.

References FillTrigArr(), MaxM, phi, phi_set, phival, SetTrigArrSize(), and TASize.

Referenced by SetPoint().

{
//Set value of the angle argument, adjust the TrigArr size if neccessary
//and fill TrigArr if the phi value is changed
//
   if (MaxM >= TASize) { SetTrigArrSize(MaxM+1); FillTrigArr(phi);}
   else if (phi != phival) FillTrigArr(phi);
   phival = phi;
   phi_set = true;
}
static void magfieldparam::rz_harm_poly::SetPoint ( const double  r,
const double  z,
const double  phi 
) [inline, static]

Definition at line 67 of file rz_harm_poly.h.

References SetPhi().

void rz_harm_poly::SetTrigArrSize ( const unsigned  N) [static, private]

Definition at line 100 of file rz_harm_poly.cc.

References N, phi_set, TASize, and TrigArr.

Referenced by SetPhi().

{
//Increase TrigArr size if neccessary
//
   if (N <= TASize) return;
   if (TrigArr) delete [] TrigArr;
   TrigArr = new trig_pair [N];
   (*TrigArr) = trig_pair(1., 0.);
   TASize = N;
   phi_set = false;
}

Member Data Documentation

unsigned rz_harm_poly::Cnt = 0 [static, private]

Definition at line 44 of file rz_harm_poly.h.

Referenced by Count(), rz_harm_poly(), and ~rz_harm_poly().

unsigned magfieldparam::rz_harm_poly::L [private]

Definition at line 41 of file rz_harm_poly.h.

Referenced by CheatL(), GetL(), LadderDwn(), LadderUp(), PrintLM(), and rz_harm_poly().

unsigned rz_harm_poly::MaxM = 0 [static, private]

Definition at line 47 of file rz_harm_poly.h.

Referenced by FillTrigArr(), LadderDwn(), LadderUp(), PrintTrigArr(), SetPhi(), and ~rz_harm_poly().

bool rz_harm_poly::phi_set = false [static, private]

Definition at line 46 of file rz_harm_poly.h.

Referenced by IsPhiSet(), rz_harm_poly(), SetPhi(), SetTrigArrSize(), and ~rz_harm_poly().

double rz_harm_poly::phival = -11111. [static, private]

Definition at line 45 of file rz_harm_poly.h.

Referenced by SetPhi(), and ~rz_harm_poly().

unsigned rz_harm_poly::TASize = 0 [static, private]

Definition at line 49 of file rz_harm_poly.h.

Referenced by PrintTrigArr(), SetPhi(), SetTrigArrSize(), and ~rz_harm_poly().

trig_pair * rz_harm_poly::TrigArr = 0 [static, private]

Definition at line 50 of file rz_harm_poly.h.

Referenced by FillTrigArr(), GetCos(), GetSin(), PrintTrigArr(), SetTrigArrSize(), and ~rz_harm_poly().