CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
magfieldparam::poly2d_base Class Reference

#include <poly2d_base.h>

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

Public Member Functions

void Collect ()
 
void Compress ()
 
void DecPow (int nvar)
 
void Diff (int nvar)
 
double Eval ()
 
double GetVal ()
 
double GetVal (const double r, const double z)
 
void IncPow (int nvar)
 
void Int (int nvar)
 
bool IsOn ()
 
bool IsRZSet ()
 
 poly2d_base ()
 
 poly2d_base (const poly2d_base &S)
 
void Print (std::ostream &out=std::cout, const std::streamsize prec=5)
 
void Scale (const double C)
 
virtual ~poly2d_base ()
 

Static Public Member Functions

static unsigned Count ()
 
static int GetMaxPow ()
 
static void IncNPwr (const unsigned N)
 
static void PrintTab (std::ostream &out=std::cout, const std::streamsize prec=5)
 
static void SetPoint (const double r, const double z)
 

Static Protected Member Functions

static void AdjustTab ()
 
static void FillTable (const double r, const double z)
 
static void SetTabSize (const unsigned N)
 

Protected Attributes

std::vector< poly2d_termdata
 
unsigned max_pwr
 

Static Protected Attributes

static const double MIN_COEFF = DBL_EPSILON
 
static unsigned NPwr = 0
 
static unsigned NTab = 0
 
static std::set< poly2d_base * > poly2d_base_set
 
static double rval = 0.
 
static double ** rz_pow = nullptr
 
static bool rz_set = false
 
static double zval = 0.
 

Detailed Description

Definition at line 44 of file poly2d_base.h.

Constructor & Destructor Documentation

magfieldparam::poly2d_base::poly2d_base ( )
inline

Definition at line 79 of file poly2d_base.h.

79  {
80  max_pwr = 0;
81  poly2d_base_set.insert(this);
82  }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
magfieldparam::poly2d_base::poly2d_base ( const poly2d_base S)
inline

Definition at line 83 of file poly2d_base.h.

References data, and max_pwr.

83  {
84  data = S.data;
85  max_pwr = S.max_pwr;
86  poly2d_base_set.insert(this);
87  }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
poly2d_base::~poly2d_base ( )
virtual

Definition at line 49 of file poly2d_base.cc.

50 {
51  poly2d_base_set.erase(poly2d_base_set.find(this));
52  if(!poly2d_base_set.empty()) { //some objects left
53  if (max_pwr >= NPwr) NPwr = GetMaxPow();
54  } else {
55  if (rz_pow) {
56  delete [] rz_pow[0]; //deleting the last instance -> memory cleanup
57  delete [] rz_pow;
58  }
59  rz_pow = nullptr;
60  rval = zval = 0.;
61  NPwr = 0;
62  NTab = 0;
63  rz_set = false;
64 // poly2d_base_set.resize(0);
65  }
66 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
unsigned long long int rval
Definition: vlib.h:22
static unsigned NPwr
Definition: poly2d_base.h:54

Member Function Documentation

void poly2d_base::AdjustTab ( )
staticprotected

Definition at line 115 of file poly2d_base.cc.

116 {
117  NPwr = GetMaxPow();
118  if (NPwr >= NTab) SetTabSize(NPwr+1);
119 }
static unsigned NTab
Definition: poly2d_base.h:53
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:69
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Collect ( )

Definition at line 166 of file poly2d_base.cc.

References patCaloMETCorrections_cff::C, data, RecoTauDiscriminantConfiguration::mask, and magfieldparam::poly2d_term::np.

Referenced by magfieldparam::rz_harm_poly::LadderDwn(), and magfieldparam::rz_harm_poly::LadderUp().

167 {
168  if (!(data.size())) return;
169 
170  unsigned j1, j2, rpow, zpow, noff = 0, jend = data.size();
171  double C;
172  std::vector<bool> mask(jend, false);
173  max_pwr = 0;
174 
175  for (j1 = 0; j1 < jend; ++j1) {
176  if (mask[j1]) continue;
177  C = data[j1].coeff;
178  rpow = data[j1].np[0];
179  zpow = data[j1].np[1];
180  for (j2 = j1+1; j2 < jend; ++j2) {
181  if (mask[j2]) continue;
182  if ((rpow == data[j2].np[0]) && (zpow == data[j2].np[1])) {
183  C += data[j2].coeff;
184  mask[j2] = true;
185  ++noff;
186  }
187  }
188  if (fabs(C) > MIN_COEFF) {
189  data[j1].coeff = C;
190  if ((rpow = rpow+zpow) > max_pwr) max_pwr = rpow;
191  } else {
192  mask[j1] = true;
193  ++noff;
194  }
195  }
196  std::vector<poly2d_term> newdata; newdata.reserve(jend - noff);
197  for (j1 = 0; j1 < jend; ++j1) {
198  if (!(mask[j1])) newdata.push_back(data[j1]);
199  }
200  data.swap(newdata);
201 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
int np
Definition: AMPTWrapper.h:33
static const double MIN_COEFF
Definition: poly2d_base.h:57
void magfieldparam::poly2d_base::Compress ( )
inline

Definition at line 95 of file poly2d_base.h.

References patCaloMETCorrections_cff::C.

static unsigned magfieldparam::poly2d_base::Count ( )
inlinestatic

Definition at line 74 of file poly2d_base.h.

References gather_cfg::cout, MillePedeFileConverter_cfg::out, and alignCSCRings::r.

Referenced by magfieldparam::rz_harm_poly::ParentCount().

74 { return poly2d_base_set.size();}
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
void poly2d_base::DecPow ( int  nvar)

Definition at line 272 of file poly2d_base.cc.

References magfieldparam::poly2d_term::coeff, data, and magfieldparam::poly2d_term::np.

Referenced by magfieldparam::rz_harm_poly::GetDecPow().

273 {
274 //Divide the polynomial by variable# nvar. Remove terms with zero coefficients
275 //and also terms where the initial power of nvar is equal zero
276 //
277  poly2d_term v3;
278  std::vector<poly2d_term> newdata;
279  newdata.reserve(data.size());
280  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
281  for (unsigned it = 0; it < data.size(); ++it) {
282  v3 = data[it];
283  if ((v3.coeff != 0.) && (v3.np[nvar] > 0)) {
284  --v3.np[nvar];
285  newdata.push_back(v3);
286  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp) maxp = cur_pwr;
287  }
288  }
289  newdata.resize(newdata.size());
290  max_pwr = maxp;
291  data.swap(newdata);
292  if (oldp >= NPwr) NPwr = GetMaxPow();
293 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Diff ( int  nvar)

Definition at line 222 of file poly2d_base.cc.

References magfieldparam::poly2d_term::coeff, data, and magfieldparam::poly2d_term::np.

Referenced by magfieldparam::rz_harm_poly::GetDiff().

223 {
224 //differentiate the polynomial by variable nvar.
225 //
226  poly2d_term v3;
227  std::vector<poly2d_term> newdata;
228  newdata.reserve(data.size());
229  unsigned cur_pwr = 0, maxp = 0, oldp = max_pwr;
230  for (unsigned it = 0; it < data.size(); ++it) {
231  v3 = data[it];
232  v3.coeff *= v3.np[nvar];
233  if (v3.coeff != 0.) {
234  --v3.np[nvar];
235  newdata.push_back(v3);
236  if ((cur_pwr = v3.np[0] + v3.np[1]) > maxp) maxp = cur_pwr;
237  }
238  }
239  newdata.resize(newdata.size());
240  max_pwr = maxp;
241  data.swap(newdata);
242  if (oldp >= NPwr) NPwr = GetMaxPow();
243 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
double poly2d_base::Eval ( )

Definition at line 157 of file poly2d_base.cc.

References magfieldparam::poly2d_term::coeff, data, magfieldparam::poly2d_term::np, and S().

Referenced by magfieldparam::HarmBasis3DCyl::EvalBphi(), and magfieldparam::HarmBasis3DCyl::EvalRZ().

158 {
159  double S = 0.;
160  for (unsigned j = 0; j < data.size(); ++j)
161  S += data[j].coeff*rz_pow[data[j].np[0]][data[j].np[1]];
162  return S;
163 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static double ** rz_pow
Definition: poly2d_base.h:52
int np
Definition: AMPTWrapper.h:33
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
void poly2d_base::FillTable ( const double  r,
const double  z 
)
staticprotected

Definition at line 89 of file poly2d_base.cc.

90 {
91  if (!rz_pow) return;
92  unsigned jr, jz;
93  for (jz = 1; jz <= NPwr; ++jz) rz_pow[0][jz] = z*rz_pow[0][jz-1];
94  for (jr = 1; jr <= NPwr; ++jr) {
95  for (jz = 0; jz <= (NPwr - jr); ++jz) {
96  rz_pow[jr][jz] = r*rz_pow[jr-1][jz];
97  }
98  }
99 }
static double ** rz_pow
Definition: poly2d_base.h:52
static unsigned NPwr
Definition: poly2d_base.h:54
int poly2d_base::GetMaxPow ( )
static

Definition at line 102 of file poly2d_base.cc.

103 {
104  int curp, maxp = 0;
105  std::set<poly2d_base*>::iterator it;
106 
107  for (it = poly2d_base_set.begin(); it != poly2d_base_set.end(); ++it) {
108  curp = (*it)->max_pwr;
109  if (curp > maxp) maxp = curp;
110  }
111  return maxp;
112 }
static std::set< poly2d_base * > poly2d_base_set
Definition: poly2d_base.h:59
double magfieldparam::poly2d_base::GetVal ( )
inline

Definition at line 106 of file poly2d_base.h.

106 {if (rz_set) return Eval(); else return 0.;}
double magfieldparam::poly2d_base::GetVal ( const double  r,
const double  z 
)
inline

Definition at line 107 of file poly2d_base.h.

References gather_cfg::cout, MillePedeFileConverter_cfg::out, and magfieldparam::poly2d_term::Print().

107 { SetPoint(r,z); return Eval();}
static void SetPoint(const double r, const double z)
Definition: poly2d_base.cc:148
static void magfieldparam::poly2d_base::IncNPwr ( const unsigned  N)
inlinestatic

Definition at line 72 of file poly2d_base.h.

References N.

Referenced by magfieldparam::HarmBasis3DCyl::HarmBasis3DCyl().

72 {if (N > NPwr) NPwr = N;}
#define N
Definition: blowfish.cc:9
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::IncPow ( int  nvar)

Definition at line 260 of file poly2d_base.cc.

References data.

Referenced by magfieldparam::rz_harm_poly::GetIncPow().

261 {
262 //Multiply the polynomial by variable# nvar
263 //
264  for (unsigned it = 0; it < data.size(); ++it) {
265  ++data[it].np[nvar];
266  }
267  ++max_pwr;
268  if (max_pwr > NPwr) NPwr = GetMaxPow();
269 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Int ( int  nvar)

Definition at line 246 of file poly2d_base.cc.

References data.

Referenced by magfieldparam::rz_harm_poly::GetInt().

247 {
248 //Integrate the polynomial by variable# nvar. Doesn't remove terms
249 //with zero coefficients; if you suspect they can appear, use Compress()
250 //after the integration.
251 //
252  for (unsigned it = 0; it < data.size(); ++it) {
253  data[it].coeff /= ++data[it].np[nvar];
254  }
255  ++max_pwr;
256  if (max_pwr > NPwr) NPwr = GetMaxPow();
257 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
static unsigned NPwr
Definition: poly2d_base.h:54
bool magfieldparam::poly2d_base::IsOn ( )
inline

Definition at line 91 of file poly2d_base.h.

References electrons_cff::bool.

91 { return bool(!data.empty());}
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
bool magfieldparam::poly2d_base::IsRZSet ( )
inline

Definition at line 92 of file poly2d_base.h.

92 { return rz_set;}
void poly2d_base::Print ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)

Definition at line 204 of file poly2d_base.cc.

References data.

Referenced by magfieldparam::rz_harm_poly::Print().

205 {
206  if (data.empty()) {
207  out << "\"poly2d_base\" object contains no terms." << std::endl;
208  return;
209  }
210  out << data.size() << " terms; max. degree = " << max_pwr << ":" << std::endl;
211  std::streamsize old_prec = out.precision();
212  out.precision(prec);
213  data[0].Print(out);
214  for (unsigned it = 1; it < data.size(); ++it) {
215  data[it].Print(out, false);
216  }
217  out << std::endl;
218  out.precision(old_prec);
219 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
void poly2d_base::PrintTab ( std::ostream &  out = std::cout,
const std::streamsize  prec = 5 
)
static

Definition at line 122 of file poly2d_base.cc.

123 {
124  out << "poly2d_base table size NTab = " << NTab
125  << "\tmax. power NPwr = " << NPwr << std::endl;
126  if (rz_pow) {
127  if (NPwr < NTab) {
128  std::streamsize old_prec = out.precision(), wdt = prec+7;
129  out.precision(prec);
130  out << "Table content:" << std::endl;
131  unsigned jr, jz;
132  for (jr = 0; jr <= NPwr; ++jr) {
133  for (jz = 0; jz <= (NPwr-jr); ++jz) {
134  out << std::setw(wdt) << std::left << rz_pow[jr][jz];
135  }
136  out << "|" << std::endl;
137  }
138  out.precision(old_prec);
139  } else {
140  out << "\tTable size is not adjusted." << std::endl;
141  }
142  } else {
143  out << "\tTable is not allocated." << std::endl;
144  }
145 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
static unsigned NPwr
Definition: poly2d_base.h:54
void poly2d_base::Scale ( const double  C)

Definition at line 296 of file poly2d_base.cc.

References patCaloMETCorrections_cff::C, and data.

Referenced by magfieldparam::rz_harm_poly::LadderDwn(), and magfieldparam::rz_harm_poly::LadderUp().

297 {
298 //Multiply the polynomial by a constant.
299 //
300  if (C != 0.) {
301  for (unsigned it = 0; it < data.size(); ++it) {
302  data[it].coeff *= C;
303  }
304  } else data.resize(0);
305 }
std::vector< poly2d_term > data
Definition: poly2d_base.h:68
void poly2d_base::SetPoint ( const double  r,
const double  z 
)
static

Definition at line 148 of file poly2d_base.cc.

Referenced by magfieldparam::rz_harm_poly::SetPoint().

149 {
150  if (!Count()) return;
151  if (NPwr >= NTab) { SetTabSize(NPwr+1); FillTable(r, z);}
152  else if ((r != rval) || (z != zval)) FillTable(r, z);
153  rz_set = true;
154 }
static unsigned NTab
Definition: poly2d_base.h:53
static void SetTabSize(const unsigned N)
Definition: poly2d_base.cc:69
static void FillTable(const double r, const double z)
Definition: poly2d_base.cc:89
unsigned long long int rval
Definition: vlib.h:22
static unsigned NPwr
Definition: poly2d_base.h:54
static unsigned Count()
Definition: poly2d_base.h:74
void poly2d_base::SetTabSize ( const unsigned  N)
staticprotected

Definition at line 69 of file poly2d_base.cc.

References N.

70 {
71  if (N <= NTab) return;
72  if (rz_pow) {
73  delete [] rz_pow[0];
74  delete [] rz_pow;
75  }
76  rz_pow = new double* [N];
77  unsigned jr, dN = N*(N+1)/2;
78  rz_pow[0] = new double [dN];
79  memset(rz_pow[0], 0, dN*sizeof(double));
80  rz_pow[0][0] = 1.;
81  for (jr = 1, dN = N; jr < N; ++jr, --dN) {
82  rz_pow[jr] = rz_pow[jr-1] + dN;
83  }
84  rval = zval = 0.;
85  NTab = N;
86 }
static unsigned NTab
Definition: poly2d_base.h:53
static double ** rz_pow
Definition: poly2d_base.h:52
unsigned long long int rval
Definition: vlib.h:22
#define N
Definition: blowfish.cc:9

Member Data Documentation

std::vector<poly2d_term> magfieldparam::poly2d_base::data
protected
unsigned magfieldparam::poly2d_base::max_pwr
protected

Definition at line 69 of file poly2d_base.h.

Referenced by poly2d_base(), and magfieldparam::rz_harm_poly::rz_harm_poly().

const double poly2d_base::MIN_COEFF = DBL_EPSILON
staticprotected

Definition at line 57 of file poly2d_base.h.

Referenced by magfieldparam::poly2d_term::Print().

unsigned poly2d_base::NPwr = 0
staticprotected
unsigned poly2d_base::NTab = 0
staticprotected

Definition at line 53 of file poly2d_base.h.

Referenced by magfieldparam::poly2d_term::Print().

std::set< poly2d_base * > poly2d_base::poly2d_base_set
staticprotected
double poly2d_base::rval = 0.
staticprotected

Definition at line 49 of file poly2d_base.h.

Referenced by magfieldparam::poly2d_term::Print().

double ** poly2d_base::rz_pow = nullptr
staticprotected

Definition at line 52 of file poly2d_base.h.

Referenced by magfieldparam::poly2d_term::Print().

bool poly2d_base::rz_set = false
staticprotected
double poly2d_base::zval = 0.
staticprotected

Definition at line 50 of file poly2d_base.h.

Referenced by magfieldparam::poly2d_term::Print().