CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
npstat::LinInterpolatedTableND< Numeric, Axis > Class Template Reference

#include <LinInterpolatedTableND.h>

Public Types

typedef Axis axis_type
 
typedef Numeric value_type
 

Public Member Functions

void getCoords (unsigned long linearIndex, double *coords, unsigned coordsBufferSize) const
 
template<class Functor1 , class Functor2 >
std::unique_ptr< LinInterpolatedTableNDinvertRatioResponse (unsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, Functor1 invg, Functor2 invh, const char *functionLabel=0) const
 
template<class Functor1 , class Functor2 >
std::unique_ptr< LinInterpolatedTableND< Numeric, Axis > > invertRatioResponse (const unsigned axisNumber, const Axis &replacementAxis, const bool leftLinear, const bool rightLinear, Functor1 invg, Functor2 invh, const char *functionLabel) const
 
template<typename ConvertibleToUnsigned >
std::unique_ptr< LinInterpolatedTableNDinvertWRTAxis (ConvertibleToUnsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, const char *functionLabel=0) const
 
template<typename ConvertibleToUnsigned >
std::unique_ptr< LinInterpolatedTableND< Numeric, Axis > > invertWRTAxis (const ConvertibleToUnsigned axisNumC, const Axis &replacementAxis, const bool leftLinear, const bool rightLinear, const char *functionLabel) const
 
bool isUniformlyBinned () const
 
bool isWithinLimits (const double *point, unsigned dim) const
 
 LinInterpolatedTableND (const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &extrapolationType, const char *functionLabel=0)
 
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=0)
 
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const char *functionLabel=0)
 
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const char *functionLabel=0)
 
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const char *functionLabel=0)
 
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const Axis &vAxis, bool leftV, bool rightV, const char *functionLabel=0)
 
template<class Num2 >
 LinInterpolatedTableND (const LinInterpolatedTableND< Num2, Axis > &)
 
bool operator!= (const LinInterpolatedTableND &r) const
 
Numeric operator() (const double *point, unsigned dim) const
 
bool operator== (const LinInterpolatedTableND &) const
 
void setFunctionLabel (const char *newlabel)
 
Numeric operator() (const double &x0) const
 
Numeric operator() (const double &x0, const double &x1) const
 
Numeric operator() (const double &x0, const double &x1, const double &x2) const
 
Numeric operator() (const double &x0, const double &x1, const double &x2, const double &x3) const
 
Numeric operator() (const double &x0, const double &x1, const double &x2, const double &x3, const double &x4) const
 
unsigned dim () const
 
const std::vector< Axis > & axes () const
 
const Axis & axis (const unsigned i) const
 
unsigned long length () const
 
bool leftInterpolationLinear (unsigned i) const
 
bool rightInterpolationLinear (unsigned i) const
 
std::vector< std::pair< bool, bool > > interpolationType () const
 
const std::string & functionLabel () const
 
const ArrayND< Numeric > & table () const
 
ArrayND< Numeric > & table ()
 
gs::ClassId classId () const
 
bool write (std::ostream &of) const
 

Static Public Member Functions

static const char * classname ()
 
static LinInterpolatedTableNDread (const gs::ClassId &id, std::istream &in)
 
static unsigned version ()
 

Private Member Functions

bool allConstInterpolated () const
 
 LinInterpolatedTableND ()=delete
 
 LinInterpolatedTableND (const ArrayND< Numeric > &data, const std::vector< Axis > &axes, const char *leftInterpolation, const char *rightInterpolation, const std::string &label)
 

Static Private Member Functions

template<class Functor1 >
static void invert1DResponse (const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, bool newLeftLinear, bool newRightLinear, Functor1 invg, const double *rawx, const double *rawf, double *workspace, ArrayND< Numeric > *toSlice)
 
template<class Functor1 >
static double solveForRatioArg (double xmin, double xmax, double rmin, double rmax, double fval, Functor1 invg)
 

Private Attributes

bool allConstInterpolated_
 
std::vector< Axis > axes_
 
ArrayND< Numeric > data_
 
unsigned dim_
 
std::string functionLabel_
 
char leftInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)]
 
char rightInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)]
 

Friends

template<typename Num2 , typename Axis2 >
class LinInterpolatedTableND
 

Detailed Description

template<class Numeric, class Axis = UniformAxis>
class npstat::LinInterpolatedTableND< Numeric, Axis >

Template for multilinear interpolation/extrapolation of values provided on a rectangular coordinate grid. "Numeric" is the type stored in the table. "Axis" should be one of GridAxis, UniformAxis, or DualAxis classes or a user-provided class with a similar set of methods.

Definition at line 31 of file LinInterpolatedTableND.h.

Member Typedef Documentation

template<class Numeric, class Axis = UniformAxis>
typedef Axis npstat::LinInterpolatedTableND< Numeric, Axis >::axis_type

Definition at line 37 of file LinInterpolatedTableND.h.

template<class Numeric, class Axis = UniformAxis>
typedef Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::value_type

Definition at line 36 of file LinInterpolatedTableND.h.

Constructor & Destructor Documentation

template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const std::vector< Axis > &  axes,
const std::vector< std::pair< bool, bool > > &  extrapolationType,
const char *  functionLabel = 0 
)

Main constructor for arbitrary-dimensional interpolators.

"axes" are the axes of the rectangular coordinate grid.

In each pair provided by the "extrapolationType" argument, the first element of the pair specifies whether the extrapolation to negative infinity should be linear (if "true") or constant (if "false"). The second element of the pair specifies whether to extrapolate linearly to positive infinity.

"functionLabel" is an arbitrary string which can potentially be used by plotting programs and such.

Definition at line 528 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType(), npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

531  if (dim_ == 0 || dim_ >= CHAR_BIT * sizeof(unsigned long))
533  "In npstat::LinInterpolatedTableND constructor: requested "
534  "table dimensionality is not supported");
535  if (dim_ != interpolationType.size())
537  "In npstat::LinInterpolatedTableND constructor: "
538  "incompatible number of interpolation specifications");
539  for (unsigned i = 0; i < dim_; ++i) {
540  const std::pair<bool, bool>& pair(interpolationType[i]);
541  leftInterpolationLinear_[i] = pair.first;
542  rightInterpolationLinear_[i] = pair.second;
543  }
544 
546  }
char const * label
std::vector< std::pair< bool, bool > > interpolationType() const
const std::vector< Axis > & axes() const
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const char *  functionLabel = 0 
)

Convenience constructor for 1-d interpolators

Definition at line 702 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

707  axes_.reserve(dim_);
708  axes_.push_back(xAxis);
709 
710  leftInterpolationLinear_[0] = leftX;
711  rightInterpolationLinear_[0] = rightX;
712 
714  }
char const * label
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const char *  functionLabel = 0 
)

Convenience constructor for 2-d interpolators

Definition at line 684 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

687  axes_.reserve(dim_);
688  axes_.push_back(xAxis);
689  axes_.push_back(yAxis);
690 
691  unsigned i = 0;
692  leftInterpolationLinear_[i] = leftX;
693  rightInterpolationLinear_[i++] = rightX;
694  leftInterpolationLinear_[i] = leftY;
695  rightInterpolationLinear_[i++] = rightY;
696  assert(i == dim_);
697 
699  }
char const * label
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const char *  functionLabel = 0 
)

Convenience constructor for 3-d interpolators

Definition at line 655 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

666  axes_.reserve(dim_);
667  axes_.push_back(xAxis);
668  axes_.push_back(yAxis);
669  axes_.push_back(zAxis);
670 
671  unsigned i = 0;
672  leftInterpolationLinear_[i] = leftX;
673  rightInterpolationLinear_[i++] = rightX;
674  leftInterpolationLinear_[i] = leftY;
675  rightInterpolationLinear_[i++] = rightY;
676  leftInterpolationLinear_[i] = leftZ;
677  rightInterpolationLinear_[i++] = rightZ;
678  assert(i == dim_);
679 
681  }
char const * label
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const Axis &  tAxis,
bool  leftT,
bool  rightT,
const char *  functionLabel = 0 
)

Convenience constructor for 4-d interpolators

Definition at line 620 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

634  axes_.reserve(dim_);
635  axes_.push_back(xAxis);
636  axes_.push_back(yAxis);
637  axes_.push_back(zAxis);
638  axes_.push_back(tAxis);
639 
640  unsigned i = 0;
641  leftInterpolationLinear_[i] = leftX;
642  rightInterpolationLinear_[i++] = rightX;
643  leftInterpolationLinear_[i] = leftY;
644  rightInterpolationLinear_[i++] = rightY;
645  leftInterpolationLinear_[i] = leftZ;
646  rightInterpolationLinear_[i++] = rightZ;
647  leftInterpolationLinear_[i] = leftT;
648  rightInterpolationLinear_[i++] = rightT;
649  assert(i == dim_);
650 
652  }
char const * label
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const Axis &  tAxis,
bool  leftT,
bool  rightT,
const Axis &  vAxis,
bool  leftV,
bool  rightV,
const char *  functionLabel = 0 
)

Convenience constructor for 5-d interpolators

Definition at line 577 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

593  : data_(Private::makeTableShape(xAxis, yAxis, zAxis, tAxis, vAxis)),
594  functionLabel_(label ? label : ""),
595  dim_(5U) {
596  axes_.reserve(dim_);
597  axes_.push_back(xAxis);
598  axes_.push_back(yAxis);
599  axes_.push_back(zAxis);
600  axes_.push_back(tAxis);
601  axes_.push_back(vAxis);
602 
603  unsigned i = 0;
604  leftInterpolationLinear_[i] = leftX;
605  rightInterpolationLinear_[i++] = rightX;
606  leftInterpolationLinear_[i] = leftY;
607  rightInterpolationLinear_[i++] = rightY;
608  leftInterpolationLinear_[i] = leftZ;
609  rightInterpolationLinear_[i++] = rightZ;
610  leftInterpolationLinear_[i] = leftT;
611  rightInterpolationLinear_[i++] = rightT;
612  leftInterpolationLinear_[i] = leftV;
613  rightInterpolationLinear_[i++] = rightV;
614  assert(i == dim_);
615 
617  }
char const * label
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
ArrayShape makeTableShape(const std::vector< Axis > &axes)
template<typename Numeric , class Axis >
template<class Num2 >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const LinInterpolatedTableND< Num2, Axis > &  r)

Converting copy constructor from interpolator with another storage type

Definition at line 550 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

551  : data_(r.data_),
552  axes_(r.axes_),
553  functionLabel_(r.functionLabel_),
554  dim_(r.dim_),
555  allConstInterpolated_(r.allConstInterpolated_) {
556  for (unsigned i = 0; i < dim_; ++i) {
557  leftInterpolationLinear_[i] = r.leftInterpolationLinear_[i];
558  rightInterpolationLinear_[i] = r.rightInterpolationLinear_[i];
559  }
560  }
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
template<class Numeric, class Axis = UniformAxis>
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( )
privatedelete
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const ArrayND< Numeric > &  data,
const std::vector< Axis > &  axes,
const char *  leftInterpolation,
const char *  rightInterpolation,
const std::string &  label 
)
private

Definition at line 563 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

568  : data_(data), axes_(axes), functionLabel_(label), dim_(data.rank()) {
569  for (unsigned i = 0; i < dim_; ++i) {
570  leftInterpolationLinear_[i] = leftInterpolation[i];
571  rightInterpolationLinear_[i] = rightInterpolation[i];
572  }
574  }
unsigned rank() const
Definition: ArrayND.h:242
char const * label
const std::vector< Axis > & axes() const
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]

Member Function Documentation

template<class Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated ( ) const
private
template<class Numeric, class Axis = UniformAxis>
const std::vector<Axis>& npstat::LinInterpolatedTableND< Numeric, Axis >::axes ( ) const
inline
template<class Numeric, class Axis = UniformAxis>
const Axis& npstat::LinInterpolatedTableND< Numeric, Axis >::axis ( const unsigned  i) const
inline

Definition at line 140 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_.

140 { return axes_.at(i); }
template<class Numeric, class Axis = UniformAxis>
gs::ClassId npstat::LinInterpolatedTableND< Numeric, Axis >::classId ( ) const
inline
template<typename Numeric , class Axis >
const char * npstat::LinInterpolatedTableND< Numeric, Axis >::classname ( )
static

Definition at line 449 of file LinInterpolatedTableND.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::classId().

449  {
450  static const std::string myClass(gs::template_class_name<Numeric, Axis>("npstat::LinInterpolatedTableND"));
451  return myClass.c_str();
452  }
template<class Numeric, class Axis = UniformAxis>
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim ( ) const
inline
template<class Numeric, class Axis = UniformAxis>
const std::string& npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel ( ) const
inline
template<typename Numeric , class Axis >
void npstat::LinInterpolatedTableND< Numeric, Axis >::getCoords ( unsigned long  linearIndex,
double *  coords,
unsigned  coordsBufferSize 
) const

Convenience function for getting coordinates of the grid points

Definition at line 868 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::ArrayND< Numeric, StackLen, StackDim >::convertLinearIndex(), npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, and mps_fire::i.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::table().

870  {
871  if (coordsBufferSize < dim_)
873  "In LinInterpolatedTableND::getCoords: "
874  "insufficient buffer size");
875  assert(coords);
876  unsigned index[CHAR_BIT * sizeof(unsigned long)];
877  data_.convertLinearIndex(linearIndex, index, dim_);
878  for (unsigned i = 0; i < dim_; ++i)
879  coords[i] = axes_[i].coordinate(index[i]);
880  }
void convertLinearIndex(unsigned long l, unsigned *index, unsigned indexLen) const
Definition: ArrayND.h:3048
template<typename Numeric , class Axis >
std::vector< std::pair< bool, bool > > npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType ( ) const
template<typename Numeric , class Axis >
template<class Functor1 >
void npstat::LinInterpolatedTableND< Numeric, Axis >::invert1DResponse ( const ArrayND< Numeric > &  fromSlice,
const Axis &  fromAxis,
const Axis &  toAxis,
bool  newLeftLinear,
bool  newRightLinear,
Functor1  invg,
const double *  rawx,
const double *  rawf,
double *  workspace,
ArrayND< Numeric > *  toSlice 
)
staticprivate

Definition at line 1083 of file LinInterpolatedTableND.h.

References npstat::ArrayND< Numeric, StackLen, StackDim >::data(), mps_fire::i, npstat::ArrayND< Numeric, StackLen, StackDim >::length(), npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), npstat::LinInterpolatedTableND< Numeric, Axis >::solveForRatioArg(), and mitigatedMETSequence_cff::U.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::invertRatioResponse().

1092  {
1093  assert(toSlice);
1094  assert(fromSlice.rank() == 1U);
1095  assert(toSlice->rank() == 1U);
1096 
1097  const Numeric zero = Numeric();
1098  const Numeric* fromData = fromSlice.data();
1099  const unsigned fromLen = fromSlice.length();
1100  assert(fromLen > 1U);
1101  assert(fromLen == fromAxis.nCoords());
1102  Numeric* toD = const_cast<Numeric*>(toSlice->data());
1103  const unsigned nAxisPoints = toAxis.nCoords();
1104  assert(toSlice->length() == nAxisPoints);
1105 
1106  for (unsigned i = 0; i < fromLen; ++i) {
1107  if (fromData[i] <= zero)
1109  "In LinInterpolatedTableND::invert1DResponse: "
1110  "non-positive response found. This ratio "
1111  "response table is not invertible.");
1112  workspace[i] = rawx[i] * fromData[i];
1113  }
1114 
1115  const double yfirst = workspace[0];
1116  const double ylast = workspace[fromLen - 1U];
1117 
1118  bool adjustZero = false;
1119  unsigned nBelow = 0;
1120  for (unsigned ipt = 0; ipt < nAxisPoints; ++ipt) {
1121  const double y = rawf[ipt];
1122  unsigned i0 = 0;
1123  bool solve = false;
1124  if (y == 0.0) {
1125  assert(ipt == 0U);
1126  if (newLeftLinear)
1127  adjustZero = true;
1128  } else if (y <= yfirst) {
1129  ++nBelow;
1130  solve = newLeftLinear;
1131  } else if (y >= ylast) {
1132  solve = newRightLinear;
1133  i0 = solve ? fromLen - 2 : fromLen - 1;
1134  } else {
1135  solve = true;
1136  i0 = static_cast<unsigned>(std::lower_bound(workspace, workspace + fromLen, y) - workspace) - 1U;
1137  }
1138  if (solve) {
1139  const double x = solveForRatioArg(
1140  fromAxis.coordinate(i0), fromAxis.coordinate(i0 + 1), fromData[i0], fromData[i0 + 1], y, invg);
1141  toD[ipt] = invg(x) / y;
1142  } else
1143  toD[ipt] = 1.0 / fromData[i0];
1144  }
1145  if (adjustZero && nBelow)
1146  toD[0] = toD[1];
1147  }
unsigned rank() const
Definition: ArrayND.h:242
unsigned long length() const
Definition: ArrayND.h:233
static double solveForRatioArg(double xmin, double xmax, double rmin, double rmax, double fval, Functor1 invg)
const Numeric * data() const
Definition: ArrayND.h:236
template<class Numeric, class Axis = UniformAxis>
template<class Functor1 , class Functor2 >
std::unique_ptr<LinInterpolatedTableND> npstat::LinInterpolatedTableND< Numeric, Axis >::invertRatioResponse ( unsigned  axisNumber,
const Axis &  replacementAxis,
bool  newAxisLeftLinear,
bool  newAxisRightLinear,
Functor1  invg,
Functor2  invh,
const char *  functionLabel = 0 
) const

This method inverts the ratio response. That is, we assume that the table encodes r(x) for some function f(x) = x*r(x). We also assume that the original axis does not represent x directly – instead, axis coordinates are given by g(x) (in practice, g is often the natural log). We will also assume that the new axis is not going to represent f(x) directly – it will be h(f(x)) instead. The functors "invg" and "invh" below must do the inverse: taking the axes coordinates to the actual values of x and f(x). Both "invg" and "invh" must be monotonously increasing functions. The code assumes that x*r(x) -> 0 when x->0 (that is, r(x) is bounded at 0) and it also assumes (but does not check explicitly) that x*r(x) is monotonously increasing with x.

The returned interpolation table encodes the values of x/f(x). Of course, they are just 1/r(x), but the trick is to be able to look them up quickly as a function of h(f(x)). Naturally, this whole operation is meaningful only in case "Numeric" type is either float or double.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel().

template<class Numeric, class Axis = UniformAxis>
template<class Functor1 , class Functor2 >
std::unique_ptr<LinInterpolatedTableND<Numeric, Axis> > npstat::LinInterpolatedTableND< Numeric, Axis >::invertRatioResponse ( const unsigned  axisNumber,
const Axis &  replacementAxis,
const bool  leftLinear,
const bool  rightLinear,
Functor1  invg,
Functor2  invh,
const char *  functionLabel 
) const

Definition at line 769 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, KineDebug3::count(), npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::ArrayND< Numeric, StackLen, StackDim >::exportSlice(), f, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType(), npstat::LinInterpolatedTableND< Numeric, Axis >::invert1DResponse(), npstat::ArrayNDScanner::isValid(), npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), npstat::ArrayND< Numeric, StackLen, StackDim >::span(), and mitigatedMETSequence_cff::U.

776  {
777  if (axisNumber >= dim_)
779  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
780  "axis number is out of range");
781 
782  // Generate the new set of axes
783  std::vector<Axis> newAxes(axes_);
784  newAxes[axisNumber] = replacementAxis;
785 
786  std::vector<std::pair<bool, bool> > iType(interpolationType());
787  iType[axisNumber] = std::pair<bool, bool>(leftLinear, rightLinear);
788 
789  // Transform the original axis to the raw x values
790  const Axis& oldAxis(axes_[axisNumber]);
791  std::vector<double> rawx;
792  const unsigned nCoords = oldAxis.nCoords();
793  rawx.reserve(nCoords);
794  for (unsigned i = 0; i < nCoords; ++i) {
795  const double x = invg(oldAxis.coordinate(i));
796  if (x < 0.0)
798  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
799  "invalid original axis definition (negative transformed "
800  "coordinate)");
801  rawx.push_back(x);
802  }
803 
804  // Transform the new axis to the raw f(x) values
805  std::vector<double> rawf;
806  const unsigned nFuncs = replacementAxis.nCoords();
807  rawf.reserve(nFuncs);
808  for (unsigned i = 0; i < nFuncs; ++i) {
809  const double f = invh(replacementAxis.coordinate(i));
810  if (f < 0.0)
812  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
813  "invalid new axis definition (negative transformed "
814  "coordinate)");
815  rawf.push_back(f);
816  }
817 
818  // Workspace needed for the inversion code
819  std::vector<double> workspace(nCoords);
820 
821  // Create the new table
822  CPP11_auto_ptr<LinInterpolatedTableND> pTable(new LinInterpolatedTableND(newAxes, iType, functionLabel));
823 
824  if (dim_ > 1U) {
825  // Prepare array slices
826  unsigned sliceIndex[CHAR_BIT * sizeof(unsigned long)];
827  unsigned fixedIndices[CHAR_BIT * sizeof(unsigned long)];
828  unsigned count = 0;
829  for (unsigned i = 0; i < dim_; ++i)
830  if (i != axisNumber) {
831  sliceIndex[count] = data_.span(i);
832  fixedIndices[count++] = i;
833  }
834  ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
835  ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);
836 
837  // Cycle over the slices
838  for (ArrayNDScanner scan(sliceIndex, count); scan.isValid(); ++scan) {
839  scan.getIndex(sliceIndex, count);
840  data_.exportSlice(&parentSlice, fixedIndices, sliceIndex, count);
841  invert1DResponse(parentSlice,
842  oldAxis,
843  replacementAxis,
844  leftLinear,
845  rightLinear,
846  invg,
847  &rawx[0],
848  &rawf[0],
849  &workspace[0],
850  &dauSlice);
851  pTable->data_.importSlice(dauSlice, fixedIndices, sliceIndex, count);
852  }
853  } else
855  oldAxis,
856  replacementAxis,
857  leftLinear,
858  rightLinear,
859  invg,
860  &rawx[0],
861  &rawf[0],
862  &workspace[0],
863  &pTable->data_);
864  return pTable;
865  }
static void invert1DResponse(const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, bool newLeftLinear, bool newRightLinear, Functor1 invg, const double *rawx, const double *rawf, double *workspace, ArrayND< Numeric > *toSlice)
unsigned span(unsigned dim) const
Definition: ArrayND.h:5088
std::vector< std::pair< bool, bool > > interpolationType() const
double f[11][100]
const std::string & functionLabel() const
Numeric * data_
Definition: ArrayND.h:1049
void exportSlice(ArrayND< Num2, Len2, Dim2 > *slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices) const
Definition: ArrayND.h:696
template<class Numeric, class Axis = UniformAxis>
template<typename ConvertibleToUnsigned >
std::unique_ptr<LinInterpolatedTableND> npstat::LinInterpolatedTableND< Numeric, Axis >::invertWRTAxis ( ConvertibleToUnsigned  axisNumber,
const Axis &  replacementAxis,
bool  newAxisLeftLinear,
bool  newAxisRightLinear,
const char *  functionLabel = 0 
) const

Invert the function w.r.t. the variable represented by one of the axes. The function values must change monotonously along the chosen axis. Note that this operation is meaningful only in case "Numeric" type is either float or double.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel().

template<class Numeric, class Axis = UniformAxis>
template<typename ConvertibleToUnsigned >
std::unique_ptr<LinInterpolatedTableND<Numeric, Axis> > npstat::LinInterpolatedTableND< Numeric, Axis >::invertWRTAxis ( const ConvertibleToUnsigned  axisNumC,
const Axis &  replacementAxis,
const bool  leftLinear,
const bool  rightLinear,
const char *  functionLabel 
) const

Definition at line 718 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, KineDebug3::count(), npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::ArrayND< Numeric, StackLen, StackDim >::exportSlice(), mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType(), npstat::ArrayNDScanner::isValid(), npstat::Private::lind_invert1DSlice(), npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), npstat::ArrayND< Numeric, StackLen, StackDim >::span(), and mitigatedMETSequence_cff::U.

723  {
724  const unsigned axisNumber = static_cast<unsigned>(axisNumC);
725 
726  if (axisNumber >= dim_)
728  "In npstat::LinInterpolatedTableND::invertAxis: "
729  "axis number is out of range");
730 
731  // Generate the new set of axes
732  std::vector<Axis> newAxes(axes_);
733  newAxes[axisNumber] = replacementAxis;
734 
735  std::vector<std::pair<bool, bool> > iType(interpolationType());
736  iType[axisNumber] = std::pair<bool, bool>(leftLinear, rightLinear);
737 
738  // Create the new table
739  CPP11_auto_ptr<LinInterpolatedTableND> pTable(new LinInterpolatedTableND(newAxes, iType, functionLabel));
740 
741  if (dim_ > 1U) {
742  // Prepare array slices
743  unsigned sliceIndex[CHAR_BIT * sizeof(unsigned long)];
744  unsigned fixedIndices[CHAR_BIT * sizeof(unsigned long)];
745  unsigned count = 0;
746  for (unsigned i = 0; i < dim_; ++i)
747  if (i != axisNumber) {
748  sliceIndex[count] = data_.span(i);
749  fixedIndices[count++] = i;
750  }
751  ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
752  ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);
753 
754  // Cycle over the slices
755  for (ArrayNDScanner scan(sliceIndex, count); scan.isValid(); ++scan) {
756  scan.getIndex(sliceIndex, count);
757  data_.exportSlice(&parentSlice, fixedIndices, sliceIndex, count);
759  parentSlice, axes_[axisNumber], replacementAxis, leftLinear, rightLinear, &dauSlice);
760  pTable->data_.importSlice(dauSlice, fixedIndices, sliceIndex, count);
761  }
762  } else
763  Private::lind_invert1DSlice(data_, axes_[0], replacementAxis, leftLinear, rightLinear, &pTable->data_);
764  return pTable;
765  }
unsigned span(unsigned dim) const
Definition: ArrayND.h:5088
std::vector< std::pair< bool, bool > > interpolationType() const
void lind_invert1DSlice(const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, const bool leftLinear, const bool rightLinear, ArrayND< Numeric > *toSlice)
const std::string & functionLabel() const
void exportSlice(ArrayND< Num2, Len2, Dim2 > *slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices) const
Definition: ArrayND.h:696
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isUniformlyBinned ( ) const

This method returns "true" if the method isUniform() of each interpolator axis returns "true"

Definition at line 511 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, and mps_fire::i.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::table().

511  {
512  for (unsigned i = 0; i < dim_; ++i)
513  if (!axes_[i].isUniform())
514  return false;
515  return true;
516  }
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isWithinLimits ( const double *  point,
unsigned  dim 
) const

This method will return "true" if the point is inside the grid limits or on the boundary

Definition at line 883 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, SiStripPI::max, and min().

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::table().

883  {
884  if (len != dim_)
886  "In npstat::LinInterpolatedTableND::isWithinLimits: "
887  "incompatible point dimensionality");
888  assert(point);
889 
890  for (unsigned i = 0; i < dim_; ++i)
891  if (point[i] < axes_[i].min() || point[i] > axes_[i].max())
892  return false;
893  return true;
894  }
T min(T a, T b)
Definition: MathUtil.h:58
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear ( unsigned  i) const

Definition at line 493 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, and npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::length().

493  {
494  if (i >= dim_)
496  "In npstat::LinInterpolatedTableND::leftInterpolationLinear: "
497  "index out of range");
498  return leftInterpolationLinear_[i];
499  }
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
template<class Numeric, class Axis = UniformAxis>
unsigned long npstat::LinInterpolatedTableND< Numeric, Axis >::length ( ) const
inline
template<class Numeric, class Axis = UniformAxis>
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator!= ( const LinInterpolatedTableND< Numeric, Axis > &  r) const
inline

Logical negation of operator==

Definition at line 220 of file LinInterpolatedTableND.h.

References alignCSCRings::r.

220 { return !(*this == r); }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double *  point,
unsigned  dim 
) const

Basic interpolation result. Argument point dimensionality must be compatible with the interpolator dimensionality.

Definition at line 897 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::ArrayND< Numeric, StackLen, StackDim >::data(), npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, npstat::ArrayND< Numeric, StackLen, StackDim >::interpolate1(), npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, linear(), SiStripPI::max, min(), npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_, npstat::ArrayND< Numeric, StackLen, StackDim >::strides(), mitigatedMETSequence_cff::U, and w.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::operator()().

897  {
898  typedef typename ProperDblFromCmpl<Numeric>::type proper_double;
899 
900  if (len != dim_)
902  "In npstat::LinInterpolatedTableND::operator(): "
903  "incompatible point dimensionality");
904  assert(point);
905 
906  bool interpolateArray = true;
908  for (unsigned i = 0; i < dim_; ++i)
909  if ((leftInterpolationLinear_[i] && point[i] < axes_[i].min()) ||
910  (rightInterpolationLinear_[i] && point[i] > axes_[i].max())) {
911  interpolateArray = false;
912  break;
913  }
914 
915  if (interpolateArray) {
916  // Translate coordinates into the array system and
917  // simply use the ArrayND interpolation facilities
918  double buf[CHAR_BIT * sizeof(unsigned long)];
919  for (unsigned i = 0; i < dim_; ++i) {
920  const std::pair<unsigned, double>& pair = axes_[i].getInterval(point[i]);
921  buf[i] = pair.first + 1U - pair.second;
922  }
923  return data_.interpolate1(buf, dim_);
924  } else {
925  unsigned ix[CHAR_BIT * sizeof(unsigned long)];
926  double weight[CHAR_BIT * sizeof(unsigned long)];
927  for (unsigned i = 0; i < dim_; ++i) {
928  const bool linear = (leftInterpolationLinear_[i] && point[i] < axes_[i].min()) ||
930  const std::pair<unsigned, double>& pair =
931  linear ? axes_[i].linearInterval(point[i]) : axes_[i].getInterval(point[i]);
932  ix[i] = pair.first;
933  weight[i] = pair.second;
934  }
935 
936  Numeric sum = Numeric();
937  const unsigned long maxcycle = 1UL << dim_;
938  const unsigned long* strides = data_.strides();
939  const Numeric* dat = data_.data();
940  for (unsigned long icycle = 0UL; icycle < maxcycle; ++icycle) {
941  double w = 1.0;
942  unsigned long icell = 0UL;
943  for (unsigned i = 0; i < dim_; ++i) {
944  if (icycle & (1UL << i)) {
945  w *= (1.0 - weight[i]);
946  icell += strides[i] * (ix[i] + 1U);
947  } else {
948  w *= weight[i];
949  icell += strides[i] * ix[i];
950  }
951  }
952  sum += dat[icell] * static_cast<proper_double>(w);
953  }
954  return sum;
955  }
956  }
const double w
Definition: UKUtility.cc:23
Definition: weight.py:1
Numeric interpolate1(const double *x, unsigned xDim) const
Definition: ArrayND.h:4211
const Numeric * data() const
Definition: ArrayND.h:236
T min(T a, T b)
Definition: MathUtil.h:58
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
const unsigned long * strides() const
Definition: ArrayND.h:263
float linear(float x)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0) const

Convenience function for low-dimensional interpolators

Definition at line 959 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::operator()(), createJobs::tmp, and mitigatedMETSequence_cff::U.

959  {
960  const unsigned nArgs = 1U;
961  if (dim_ != nArgs)
963  "In npstat::LinInterpolatedTableND::operator(): number of "
964  "arguments, 1, is incompatible with the interpolator dimensionality");
965  double tmp[nArgs];
966  tmp[0] = x0;
967  return operator()(tmp, nArgs);
968  }
Numeric operator()(const double *point, unsigned dim) const
tmp
align.sh
Definition: createJobs.py:716
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1 
) const

Definition at line 971 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::operator()(), createJobs::tmp, mitigatedMETSequence_cff::U, and testProducerWithPsetDescEmpty_cfi::x1.

971  {
972  const unsigned nArgs = 2U;
973  if (dim_ != nArgs)
975  "In npstat::LinInterpolatedTableND::operator(): number of "
976  "arguments, 2, is incompatible with the interpolator dimensionality");
977  double tmp[nArgs];
978  tmp[0] = x0;
979  tmp[1] = x1;
980  return operator()(tmp, nArgs);
981  }
Numeric operator()(const double *point, unsigned dim) const
tmp
align.sh
Definition: createJobs.py:716
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2 
) const

Definition at line 984 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::operator()(), createJobs::tmp, mitigatedMETSequence_cff::U, testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

986  {
987  const unsigned nArgs = 3U;
988  if (dim_ != nArgs)
990  "In npstat::LinInterpolatedTableND::operator(): number of "
991  "arguments, 3, is incompatible with the interpolator dimensionality");
992  double tmp[nArgs];
993  tmp[0] = x0;
994  tmp[1] = x1;
995  tmp[2] = x2;
996  return operator()(tmp, nArgs);
997  }
Numeric operator()(const double *point, unsigned dim) const
tmp
align.sh
Definition: createJobs.py:716
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2,
const double &  x3 
) const

Definition at line 1000 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::operator()(), createJobs::tmp, mitigatedMETSequence_cff::U, testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

1003  {
1004  const unsigned nArgs = 4U;
1005  if (dim_ != nArgs)
1007  "In npstat::LinInterpolatedTableND::operator(): number of "
1008  "arguments, 4, is incompatible with the interpolator dimensionality");
1009  double tmp[nArgs];
1010  tmp[0] = x0;
1011  tmp[1] = x1;
1012  tmp[2] = x2;
1013  tmp[3] = x3;
1014  return operator()(tmp, nArgs);
1015  }
Numeric operator()(const double *point, unsigned dim) const
tmp
align.sh
Definition: createJobs.py:716
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2,
const double &  x3,
const double &  x4 
) const

Definition at line 1018 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::operator()(), createJobs::tmp, mitigatedMETSequence_cff::U, testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

1019  {
1020  const unsigned nArgs = 5U;
1021  if (dim_ != nArgs)
1023  "In npstat::LinInterpolatedTableND::operator(): number of "
1024  "arguments, 5, is incompatible with the interpolator dimensionality");
1025  double tmp[nArgs];
1026  tmp[0] = x0;
1027  tmp[1] = x1;
1028  tmp[2] = x2;
1029  tmp[3] = x3;
1030  tmp[4] = x4;
1031  return operator()(tmp, nArgs);
1032  }
Numeric operator()(const double *point, unsigned dim) const
tmp
align.sh
Definition: createJobs.py:716
template<class Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator== ( const LinInterpolatedTableND< Numeric, Axis > &  r) const

Comparison for equality

Definition at line 436 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_, mps_fire::i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel().

436  {
437  if (dim_ != r.dim_)
438  return false;
439  for (unsigned i = 0; i < dim_; ++i) {
440  if (leftInterpolationLinear_[i] != r.leftInterpolationLinear_[i])
441  return false;
442  if (rightInterpolationLinear_[i] != r.rightInterpolationLinear_[i])
443  return false;
444  }
445  return data_ == r.data_ && axes_ == r.axes_ && functionLabel_ == r.functionLabel_;
446  }
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
template<typename Numeric , class Axis >
LinInterpolatedTableND< Numeric, Axis > * npstat::LinInterpolatedTableND< Numeric, Axis >::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 466 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes(), data, npstat::LinInterpolatedTableND< Numeric, Axis >::dim(), label, npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), npstat::ArrayND< Numeric, StackLen, StackDim >::restore(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::read(), and npstat::LinInterpolatedTableND< Numeric, Axis >::version().

467  {
468  static const gs::ClassId current(gs::ClassId::makeId<LinInterpolatedTableND<Numeric, Axis> >());
469  current.ensureSameId(id);
470 
471  gs::ClassId ida(in, 1);
472  ArrayND<Numeric> data;
473  ArrayND<Numeric>::restore(ida, in, &data);
474  std::vector<Axis> axes;
475  gs::read_heap_obj_vector_as_placed(in, &axes);
476  const unsigned dim = axes.size();
477  if (dim > CHAR_BIT * sizeof(unsigned long) || data.rank() != dim)
478  throw gs::IOInvalidData(
479  "In npstat::LinInterpolatedTableND::read: "
480  "read back invalid dimensionality");
481  char leftInterpolation[CHAR_BIT * sizeof(unsigned long)];
482  gs::read_pod_array(in, leftInterpolation, dim);
483  char rightInterpolation[CHAR_BIT * sizeof(unsigned long)];
484  gs::read_pod_array(in, rightInterpolation, dim);
486  gs::read_pod(in, &label);
487  if (in.fail())
488  throw gs::IOReadFailure("In npstat::LinInterpolatedTableND::read: input stream failure");
489  return new LinInterpolatedTableND(data, axes, leftInterpolation, rightInterpolation, label);
490  }
char const * label
const std::vector< Axis > & axes() const
static void restore(const gs::ClassId &id, std::istream &in, ArrayND *array)
Definition: ArrayND.h:5386
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear ( unsigned  i) const

Definition at line 502 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, mps_fire::i, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::length().

502  {
503  if (i >= dim_)
505  "In npstat::LinInterpolatedTableND::rightInterpolationLinear: "
506  "index out of range");
508  }
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
template<class Numeric, class Axis = UniformAxis>
void npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel ( const char *  newlabel)
inline
template<typename Numeric , class Axis >
template<class Functor1 >
double npstat::LinInterpolatedTableND< Numeric, Axis >::solveForRatioArg ( double  xmin,
double  xmax,
double  rmin,
double  rmax,
double  fval,
Functor1  invg 
)
staticprivate

Definition at line 1036 of file LinInterpolatedTableND.h.

References funct::abs(), npstat::Private::lind_interpolateSimple(), mitigatedMETSequence_cff::U, testProducerWithPsetDescEmpty_cfi::x1, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::invert1DResponse().

1037  {
1038  // Find two values of x so that f(x0) <= fval <= f(x1)
1039  double x0 = xmin;
1040  double x1 = xmax;
1041  double fmin = invg(xmin) * rmin;
1042  double fmax = invg(xmax) * rmax;
1043  const double step = xmax - xmin;
1044  assert(fmin < fmax);
1045  assert(step > 0.0);
1046 
1047  unsigned stepcount = 0;
1048  const unsigned maxSteps = 1000U;
1049  for (double stepfactor = 1.0; (fval < fmin || fval > fmax) && stepcount < maxSteps; stepfactor *= 2.0, ++stepcount)
1050  if (fval < fmin) {
1051  x1 = x0;
1052  fmax = fmin;
1053  x0 -= stepfactor * step;
1054  fmin = invg(x0) * Private::lind_interpolateSimple(xmin, xmax, rmin, rmax, x0);
1055  } else {
1056  x0 = x1;
1057  fmin = fmax;
1058  x1 += stepfactor * step;
1059  fmax = invg(x1) * Private::lind_interpolateSimple(xmin, xmax, rmin, rmax, x1);
1060  }
1061  if (stepcount == maxSteps)
1063  "In LinInterpolatedTableND::solveForRatioArg: "
1064  "faled to bracket the root");
1065 
1066  assert(x1 >= x0);
1067  while ((x1 - x0) / (std::abs(x1) + std::abs(x0) + DBL_EPSILON) > 4.0 * DBL_EPSILON) {
1068  const double xhalf = (x1 + x0) / 2.0;
1069  const double fhalf = invg(xhalf) * Private::lind_interpolateSimple(xmin, xmax, rmin, rmax, xhalf);
1070  if (fval < fhalf) {
1071  x1 = xhalf;
1072  fmax = fhalf;
1073  } else {
1074  x0 = xhalf;
1075  fmin = fhalf;
1076  }
1077  }
1078  return (x1 + x0) / 2.0;
1079  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double lind_interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
step
Definition: StallMonitor.cc:94
template<class Numeric, class Axis = UniformAxis>
const ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table ( ) const
inline
template<class Numeric, class Axis = UniformAxis>
ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table ( )
inline
template<class Numeric, class Axis = UniformAxis>
static unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::version ( )
inlinestatic
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::write ( std::ostream &  of) const

Definition at line 455 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::ArrayND< Numeric, StackLen, StackDim >::classId(), npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_, mps_update::status, and npstat::ArrayND< Numeric, StackLen, StackDim >::write().

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::classId(), and npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::write().

455  {
456  const bool status = data_.classId().write(of) && data_.write(of) && gs::write_obj_vector(of, axes_);
457  if (status) {
458  gs::write_pod_array(of, leftInterpolationLinear_, dim_);
459  gs::write_pod_array(of, rightInterpolationLinear_, dim_);
460  gs::write_pod(of, functionLabel_);
461  }
462  return status && !of.fail();
463  }
bool write(std::ostream &of) const
Definition: ArrayND.h:5378
gs::ClassId classId() const
Definition: ArrayND.h:1039
char rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
char leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]

Friends And Related Function Documentation

template<class Numeric, class Axis = UniformAxis>
template<typename Num2 , typename Axis2 >
friend class LinInterpolatedTableND
friend

Definition at line 33 of file LinInterpolatedTableND.h.

Member Data Documentation

template<class Numeric, class Axis = UniformAxis>
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_
private
template<class Numeric, class Axis = UniformAxis>
std::vector<Axis> npstat::LinInterpolatedTableND< Numeric, Axis >::axes_
private
template<class Numeric, class Axis = UniformAxis>
ArrayND<Numeric> npstat::LinInterpolatedTableND< Numeric, Axis >::data_
private
template<class Numeric, class Axis = UniformAxis>
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim_
private
template<class Numeric, class Axis = UniformAxis>
std::string npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_
private
template<class Numeric, class Axis = UniformAxis>
char npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
private
template<class Numeric, class Axis = UniformAxis>
char npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)]
private