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 ()
 
 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 38 of file LinInterpolatedTableND.h.

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

Definition at line 37 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 566 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_.

571  axes_(axes),
572  functionLabel_(label ? label : ""),
573  dim_(axes.size())
574  {
575  if (dim_ == 0 || dim_ >= CHAR_BIT*sizeof(unsigned long))
577  "In npstat::LinInterpolatedTableND constructor: requested "
578  "table dimensionality is not supported");
579  if (dim_ != interpolationType.size())
581  "In npstat::LinInterpolatedTableND constructor: "
582  "incompatible number of interpolation specifications");
583  for (unsigned i=0; i<dim_; ++i)
584  {
585  const std::pair<bool,bool>& pair(interpolationType[i]);
586  leftInterpolationLinear_[i] = pair.first;
587  rightInterpolationLinear_[i] = pair.second;
588  }
589 
591  }
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 747 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_.

751  functionLabel_(label ? label : ""),
752  dim_(1U)
753  {
754  axes_.reserve(dim_);
755  axes_.push_back(xAxis);
756 
757  leftInterpolationLinear_[0] = leftX;
758  rightInterpolationLinear_[0] = rightX;
759 
761  }
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 724 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_.

729  functionLabel_(label ? label : ""),
730  dim_(2U)
731  {
732  axes_.reserve(dim_);
733  axes_.push_back(xAxis);
734  axes_.push_back(yAxis);
735 
736  unsigned i = 0;
737  leftInterpolationLinear_[i] = leftX;
738  rightInterpolationLinear_[i++] = rightX;
739  leftInterpolationLinear_[i] = leftY;
740  rightInterpolationLinear_[i++] = rightY;
741  assert(i == dim_);
742 
744  }
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 697 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_.

703  functionLabel_(label ? label : ""),
704  dim_(3U)
705  {
706  axes_.reserve(dim_);
707  axes_.push_back(xAxis);
708  axes_.push_back(yAxis);
709  axes_.push_back(zAxis);
710 
711  unsigned i = 0;
712  leftInterpolationLinear_[i] = leftX;
713  rightInterpolationLinear_[i++] = rightX;
714  leftInterpolationLinear_[i] = leftY;
715  rightInterpolationLinear_[i++] = rightY;
716  leftInterpolationLinear_[i] = leftZ;
717  rightInterpolationLinear_[i++] = rightZ;
718  assert(i == dim_);
719 
721  }
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 666 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_.

673  functionLabel_(label ? label : ""),
674  dim_(4U)
675  {
676  axes_.reserve(dim_);
677  axes_.push_back(xAxis);
678  axes_.push_back(yAxis);
679  axes_.push_back(zAxis);
680  axes_.push_back(tAxis);
681 
682  unsigned i = 0;
683  leftInterpolationLinear_[i] = leftX;
684  rightInterpolationLinear_[i++] = rightX;
685  leftInterpolationLinear_[i] = leftY;
686  rightInterpolationLinear_[i++] = rightY;
687  leftInterpolationLinear_[i] = leftZ;
688  rightInterpolationLinear_[i++] = rightZ;
689  leftInterpolationLinear_[i] = leftT;
690  rightInterpolationLinear_[i++] = rightT;
691  assert(i == dim_);
692 
694  }
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 631 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_.

638  : data_(Private::makeTableShape(xAxis, yAxis, zAxis, tAxis, vAxis)),
639  functionLabel_(label ? label : ""),
640  dim_(5U)
641  {
642  axes_.reserve(dim_);
643  axes_.push_back(xAxis);
644  axes_.push_back(yAxis);
645  axes_.push_back(zAxis);
646  axes_.push_back(tAxis);
647  axes_.push_back(vAxis);
648 
649  unsigned i = 0;
650  leftInterpolationLinear_[i] = leftX;
651  rightInterpolationLinear_[i++] = rightX;
652  leftInterpolationLinear_[i] = leftY;
653  rightInterpolationLinear_[i++] = rightY;
654  leftInterpolationLinear_[i] = leftZ;
655  rightInterpolationLinear_[i++] = rightZ;
656  leftInterpolationLinear_[i] = leftT;
657  rightInterpolationLinear_[i++] = rightT;
658  leftInterpolationLinear_[i] = leftV;
659  rightInterpolationLinear_[i++] = rightV;
660  assert(i == dim_);
661 
663  }
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 595 of file LinInterpolatedTableND.h.

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

597  : data_(r.data_),
598  axes_(r.axes_),
599  functionLabel_(r.functionLabel_),
600  dim_(r.dim_),
601  allConstInterpolated_(r.allConstInterpolated_)
602  {
603  for (unsigned i=0; i<dim_; ++i)
604  {
605  leftInterpolationLinear_[i] = r.leftInterpolationLinear_[i];
606  rightInterpolationLinear_[i] = r.rightInterpolationLinear_[i];
607  }
608  }
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 ( )
private
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 611 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_.

617  : data_(data),
618  axes_(axes),
620  dim_(data.rank())
621  {
622  for (unsigned i=0; i<dim_; ++i)
623  {
624  leftInterpolationLinear_[i] = leftInterpolation[i];
625  rightInterpolationLinear_[i] = rightInterpolation[i];
626  }
628  }
unsigned rank() const
Definition: ArrayND.h:240
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
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 471 of file LinInterpolatedTableND.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

472  {
473  static const std::string myClass(gs::template_class_name<Numeric,Axis>(
474  "npstat::LinInterpolatedTableND"));
475  return myClass.c_str();
476  }
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 920 of file LinInterpolatedTableND.h.

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

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

923  {
924  if (coordsBufferSize < dim_) throw npstat::NpstatInvalidArgument(
925  "In LinInterpolatedTableND::getCoords: "
926  "insufficient buffer size");
927  assert(coords);
928  unsigned index[CHAR_BIT*sizeof(unsigned long)];
929  data_.convertLinearIndex(linearIndex, index, dim_);
930  for (unsigned i=0; i<dim_; ++i)
931  coords[i] = axes_[i].coordinate(index[i]);
932  }
void convertLinearIndex(unsigned long l, unsigned *index, unsigned indexLen) const
Definition: ArrayND.h:3234
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 1168 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().

1175  {
1176  assert(toSlice);
1177  assert(fromSlice.rank() == 1U);
1178  assert(toSlice->rank() == 1U);
1179 
1180  const Numeric zero = Numeric();
1181  const Numeric* fromData = fromSlice.data();
1182  const unsigned fromLen = fromSlice.length();
1183  assert(fromLen > 1U);
1184  assert(fromLen == fromAxis.nCoords());
1185  Numeric* toD = const_cast<Numeric*>(toSlice->data());
1186  const unsigned nAxisPoints = toAxis.nCoords();
1187  assert(toSlice->length() == nAxisPoints);
1188 
1189  for (unsigned i=0; i<fromLen; ++i)
1190  {
1191  if (fromData[i] <= zero) throw npstat::NpstatDomainError(
1192  "In LinInterpolatedTableND::invert1DResponse: "
1193  "non-positive response found. This ratio "
1194  "response table is not invertible.");
1195  workspace[i] = rawx[i]*fromData[i];
1196  }
1197 
1198  const double yfirst = workspace[0];
1199  const double ylast = workspace[fromLen - 1U];
1200 
1201  bool adjustZero = false;
1202  unsigned nBelow = 0;
1203  for (unsigned ipt=0; ipt<nAxisPoints; ++ipt)
1204  {
1205  const double y = rawf[ipt];
1206  unsigned i0 = 0;
1207  bool solve = false;
1208  if (y == 0.0)
1209  {
1210  assert(ipt == 0U);
1211  if (newLeftLinear)
1212  adjustZero = true;
1213  }
1214  else if (y <= yfirst)
1215  {
1216  ++nBelow;
1217  solve = newLeftLinear;
1218  }
1219  else if (y >= ylast)
1220  {
1221  solve = newRightLinear;
1222  i0 = solve ? fromLen-2 : fromLen-1;
1223  }
1224  else
1225  {
1226  solve = true;
1227  i0 = static_cast<unsigned>(std::lower_bound(
1228  workspace,workspace+fromLen,y) - workspace) - 1U;
1229  }
1230  if (solve)
1231  {
1232  const double x = solveForRatioArg(fromAxis.coordinate(i0),
1233  fromAxis.coordinate(i0+1),
1234  fromData[i0], fromData[i0+1],
1235  y, invg);
1236  toD[ipt] = invg(x)/y;
1237  }
1238  else
1239  toD[ipt] = 1.0/fromData[i0];
1240  }
1241  if (adjustZero && nBelow)
1242  toD[0] = toD[1];
1243  }
unsigned rank() const
Definition: ArrayND.h:240
unsigned long length() const
Definition: ArrayND.h:231
static double solveForRatioArg(double xmin, double xmax, double rmin, double rmax, double fval, Functor1 invg)
const Numeric * data() const
Definition: ArrayND.h:234
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 827 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.

832  {
833  if (axisNumber >= dim_)
835  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
836  "axis number is out of range");
837 
838  // Generate the new set of axes
839  std::vector<Axis> newAxes(axes_);
840  newAxes[axisNumber] = replacementAxis;
841 
842  std::vector<std::pair<bool,bool> > iType(interpolationType());
843  iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear);
844 
845  // Transform the original axis to the raw x values
846  const Axis& oldAxis(axes_[axisNumber]);
847  std::vector<double> rawx;
848  const unsigned nCoords = oldAxis.nCoords();
849  rawx.reserve(nCoords);
850  for (unsigned i=0; i<nCoords; ++i)
851  {
852  const double x = invg(oldAxis.coordinate(i));
853  if (x < 0.0)
855  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
856  "invalid original axis definition (negative transformed "
857  "coordinate)");
858  rawx.push_back(x);
859  }
860 
861  // Transform the new axis to the raw f(x) values
862  std::vector<double> rawf;
863  const unsigned nFuncs = replacementAxis.nCoords();
864  rawf.reserve(nFuncs);
865  for (unsigned i=0; i<nFuncs; ++i)
866  {
867  const double f = invh(replacementAxis.coordinate(i));
868  if (f < 0.0)
870  "In npstat::LinInterpolatedTableND::invertRatioResponse: "
871  "invalid new axis definition (negative transformed "
872  "coordinate)");
873  rawf.push_back(f);
874  }
875 
876  // Workspace needed for the inversion code
877  std::vector<double> workspace(nCoords);
878 
879  // Create the new table
880  CPP11_auto_ptr<LinInterpolatedTableND> pTable(
881  new LinInterpolatedTableND(newAxes, iType, functionLabel));
882 
883  if (dim_ > 1U)
884  {
885  // Prepare array slices
886  unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)];
887  unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)];
888  unsigned count = 0;
889  for (unsigned i=0; i<dim_; ++i)
890  if (i != axisNumber)
891  {
892  sliceIndex[count] = data_.span(i);
893  fixedIndices[count++] = i;
894  }
895  ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
896  ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);
897 
898  // Cycle over the slices
899  for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan)
900  {
901  scan.getIndex(sliceIndex, count);
902  data_.exportSlice(&parentSlice, fixedIndices,
903  sliceIndex, count);
904  invert1DResponse(parentSlice, oldAxis,
905  replacementAxis, leftLinear, rightLinear,
906  invg, &rawx[0], &rawf[0], &workspace[0],
907  &dauSlice);
908  pTable->data_.importSlice(dauSlice, fixedIndices,
909  sliceIndex, count);
910  }
911  }
912  else
913  invert1DResponse(data_, oldAxis, replacementAxis, leftLinear,
914  rightLinear, invg, &rawx[0], &rawf[0],
915  &workspace[0], &pTable->data_);
916  return pTable;
917  }
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:5622
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:700
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 766 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.

770  {
771  const unsigned axisNumber = static_cast<unsigned>(axisNumC);
772 
773  if (axisNumber >= dim_)
775  "In npstat::LinInterpolatedTableND::invertAxis: "
776  "axis number is out of range");
777 
778  // Generate the new set of axes
779  std::vector<Axis> newAxes(axes_);
780  newAxes[axisNumber] = replacementAxis;
781 
782  std::vector<std::pair<bool,bool> > iType(interpolationType());
783  iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear);
784 
785  // Create the new table
786  CPP11_auto_ptr<LinInterpolatedTableND> pTable(
787  new LinInterpolatedTableND(newAxes, iType, functionLabel));
788 
789  if (dim_ > 1U)
790  {
791  // Prepare array slices
792  unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)];
793  unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)];
794  unsigned count = 0;
795  for (unsigned i=0; i<dim_; ++i)
796  if (i != axisNumber)
797  {
798  sliceIndex[count] = data_.span(i);
799  fixedIndices[count++] = i;
800  }
801  ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
802  ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);
803 
804  // Cycle over the slices
805  for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan)
806  {
807  scan.getIndex(sliceIndex, count);
808  data_.exportSlice(&parentSlice, fixedIndices,
809  sliceIndex, count);
811  parentSlice, axes_[axisNumber], replacementAxis,
812  leftLinear, rightLinear, &dauSlice);
813  pTable->data_.importSlice(dauSlice, fixedIndices,
814  sliceIndex, count);
815  }
816  }
817  else
819  data_, axes_[0], replacementAxis,
820  leftLinear, rightLinear, &pTable->data_);
821  return pTable;
822  }
unsigned span(unsigned dim) const
Definition: ArrayND.h:5622
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:700
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 545 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().

546  {
547  for (unsigned i=0; i<dim_; ++i)
548  if (!axes_[i].isUniform())
549  return false;
550  return true;
551  }
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 935 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().

937  {
938  if (len != dim_)
940  "In npstat::LinInterpolatedTableND::isWithinLimits: "
941  "incompatible point dimensionality");
942  assert(point);
943 
944  for (unsigned i=0; i<dim_; ++i)
945  if (point[i] < axes_[i].min() || point[i] > axes_[i].max())
946  return false;
947  return true;
948  }
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 525 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().

527  {
528  if (i >= dim_) throw npstat::NpstatOutOfRange(
529  "In npstat::LinInterpolatedTableND::leftInterpolationLinear: "
530  "index out of range");
531  return leftInterpolationLinear_[i];
532  }
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 200 of file LinInterpolatedTableND.h.

References alignCSCRings::r.

201  {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 951 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()().

953  {
954  typedef typename ProperDblFromCmpl<Numeric>::type proper_double;
955 
956  if (len != dim_)
958  "In npstat::LinInterpolatedTableND::operator(): "
959  "incompatible point dimensionality");
960  assert(point);
961 
962  bool interpolateArray = true;
964  for (unsigned i=0; i<dim_; ++i)
965  if ((leftInterpolationLinear_[i] && point[i] < axes_[i].min()) ||
967  {
968  interpolateArray = false;
969  break;
970  }
971 
972  if (interpolateArray)
973  {
974  // Translate coordinates into the array system and
975  // simply use the ArrayND interpolation facilities
976  double buf[CHAR_BIT*sizeof(unsigned long)];
977  for (unsigned i=0; i<dim_; ++i)
978  {
979  const std::pair<unsigned,double>& pair =
980  axes_[i].getInterval(point[i]);
981  buf[i] = pair.first + 1U - pair.second;
982  }
983  return data_.interpolate1(buf, dim_);
984  }
985  else
986  {
987  unsigned ix[CHAR_BIT*sizeof(unsigned long)];
988  double weight[CHAR_BIT*sizeof(unsigned long)];
989  for (unsigned i=0; i<dim_; ++i)
990  {
991  const bool linear = (leftInterpolationLinear_[i] &&
992  point[i] < axes_[i].min()) ||
994  point[i] > axes_[i].max());
995  const std::pair<unsigned,double>& pair = linear ?
996  axes_[i].linearInterval(point[i]) :
997  axes_[i].getInterval(point[i]);
998  ix[i] = pair.first;
999  weight[i] = pair.second;
1000  }
1001 
1002  Numeric sum = Numeric();
1003  const unsigned long maxcycle = 1UL << dim_;
1004  const unsigned long* strides = data_.strides();
1005  const Numeric* dat = data_.data();
1006  for (unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
1007  {
1008  double w = 1.0;
1009  unsigned long icell = 0UL;
1010  for (unsigned i=0; i<dim_; ++i)
1011  {
1012  if (icycle & (1UL << i))
1013  {
1014  w *= (1.0 - weight[i]);
1015  icell += strides[i]*(ix[i] + 1U);
1016  }
1017  else
1018  {
1019  w *= weight[i];
1020  icell += strides[i]*ix[i];
1021  }
1022  }
1023  sum += dat[icell]*static_cast<proper_double>(w);
1024  }
1025  return sum;
1026  }
1027  }
const double w
Definition: UKUtility.cc:23
Definition: weight.py:1
Numeric interpolate1(const double *x, unsigned xDim) const
Definition: ArrayND.h:4610
const Numeric * data() const
Definition: ArrayND.h:234
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:261
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 1030 of file LinInterpolatedTableND.h.

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

1032  {
1033  const unsigned nArgs = 1U;
1034  if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
1035  "In npstat::LinInterpolatedTableND::operator(): number of "
1036  "arguments, 1, is incompatible with the interpolator dimensionality");
1037  double tmp[nArgs];
1038  tmp[0] = x0;
1039  return operator()(tmp, nArgs);
1040  }
Numeric operator()(const double *point, unsigned dim) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1 
) const

Definition at line 1043 of file LinInterpolatedTableND.h.

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

1045  {
1046  const unsigned nArgs = 2U;
1047  if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
1048  "In npstat::LinInterpolatedTableND::operator(): number of "
1049  "arguments, 2, is incompatible with the interpolator dimensionality");
1050  double tmp[nArgs];
1051  tmp[0] = x0;
1052  tmp[1] = x1;
1053  return operator()(tmp, nArgs);
1054  }
Numeric operator()(const double *point, unsigned dim) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2 
) const

Definition at line 1057 of file LinInterpolatedTableND.h.

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

1059  {
1060  const unsigned nArgs = 3U;
1061  if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
1062  "In npstat::LinInterpolatedTableND::operator(): number of "
1063  "arguments, 3, is incompatible with the interpolator dimensionality");
1064  double tmp[nArgs];
1065  tmp[0] = x0;
1066  tmp[1] = x1;
1067  tmp[2] = x2;
1068  return operator()(tmp, nArgs);
1069  }
Numeric operator()(const double *point, unsigned dim) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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 1072 of file LinInterpolatedTableND.h.

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

1075  {
1076  const unsigned nArgs = 4U;
1077  if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
1078  "In npstat::LinInterpolatedTableND::operator(): number of "
1079  "arguments, 4, is incompatible with the interpolator dimensionality");
1080  double tmp[nArgs];
1081  tmp[0] = x0;
1082  tmp[1] = x1;
1083  tmp[2] = x2;
1084  tmp[3] = x3;
1085  return operator()(tmp, nArgs);
1086  }
Numeric operator()(const double *point, unsigned dim) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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 1089 of file LinInterpolatedTableND.h.

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

1092  {
1093  const unsigned nArgs = 5U;
1094  if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
1095  "In npstat::LinInterpolatedTableND::operator(): number of "
1096  "arguments, 5, is incompatible with the interpolator dimensionality");
1097  double tmp[nArgs];
1098  tmp[0] = x0;
1099  tmp[1] = x1;
1100  tmp[2] = x2;
1101  tmp[3] = x3;
1102  tmp[4] = x4;
1103  return operator()(tmp, nArgs);
1104  }
Numeric operator()(const double *point, unsigned dim) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
template<class Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator== ( const LinInterpolatedTableND< Numeric, Axis > &  r) const

Comparison for equality

Definition at line 453 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().

455  {
456  if (dim_ != r.dim_)
457  return false;
458  for (unsigned i=0; i<dim_; ++i)
459  {
460  if (leftInterpolationLinear_[i] != r.leftInterpolationLinear_[i])
461  return false;
462  if (rightInterpolationLinear_[i] != r.rightInterpolationLinear_[i])
463  return false;
464  }
465  return data_ == r.data_ &&
466  axes_ == r.axes_ &&
467  functionLabel_ == r.functionLabel_;
468  }
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 495 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes(), data, npstat::LinInterpolatedTableND< Numeric, Axis >::dim(), diffTwoXMLs::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().

497  {
498  static const gs::ClassId current(
499  gs::ClassId::makeId<LinInterpolatedTableND<Numeric,Axis> >());
500  current.ensureSameId(id);
501 
502  gs::ClassId ida(in, 1);
503  ArrayND<Numeric> data;
504  ArrayND<Numeric>::restore(ida, in, &data);
505  std::vector<Axis> axes;
506  gs::read_heap_obj_vector_as_placed(in, &axes);
507  const unsigned dim = axes.size();
508  if (dim > CHAR_BIT*sizeof(unsigned long) || data.rank() != dim)
509  throw gs::IOInvalidData(
510  "In npstat::LinInterpolatedTableND::read: "
511  "read back invalid dimensionality");
512  char leftInterpolation[CHAR_BIT*sizeof(unsigned long)];
513  gs::read_pod_array(in, leftInterpolation, dim);
514  char rightInterpolation[CHAR_BIT*sizeof(unsigned long)];
515  gs::read_pod_array(in, rightInterpolation, dim);
517  gs::read_pod(in, &label);
518  if (in.fail()) throw gs::IOReadFailure(
519  "In npstat::LinInterpolatedTableND::read: input stream failure");
520  return new LinInterpolatedTableND(
521  data, axes, leftInterpolation, rightInterpolation, label);
522  }
const std::vector< Axis > & axes() const
static void restore(const gs::ClassId &id, std::istream &in, ArrayND *array)
Definition: ArrayND.h:6052
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear ( unsigned  i) const

Definition at line 535 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().

537  {
538  if (i >= dim_) throw npstat::NpstatOutOfRange(
539  "In npstat::LinInterpolatedTableND::rightInterpolationLinear: "
540  "index out of range");
542  }
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 1108 of file LinInterpolatedTableND.h.

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

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

1112  {
1113  // Find two values of x so that f(x0) <= fval <= f(x1)
1114  double x0 = xmin;
1115  double x1 = xmax;
1116  double fmin = invg(xmin)*rmin;
1117  double fmax = invg(xmax)*rmax;
1118  const double step = xmax - xmin;
1119  assert(fmin < fmax);
1120  assert(step > 0.0);
1121 
1122  unsigned stepcount = 0;
1123  const unsigned maxSteps = 1000U;
1124  for (double stepfactor = 1.0; (fval < fmin || fval > fmax) &&
1125  stepcount < maxSteps; stepfactor *= 2.0, ++stepcount)
1126  if (fval < fmin)
1127  {
1128  x1 = x0;
1129  fmax = fmin;
1130  x0 -= stepfactor*step;
1131  fmin = invg(x0)*Private::lind_interpolateSimple(
1132  xmin, xmax, rmin, rmax, x0);
1133  }
1134  else
1135  {
1136  x0 = x1;
1137  fmin = fmax;
1138  x1 += stepfactor*step;
1139  fmax = invg(x1)*Private::lind_interpolateSimple(
1140  xmin, xmax, rmin, rmax, x1);
1141  }
1142  if (stepcount == maxSteps) throw npstat::NpstatRuntimeError(
1143  "In LinInterpolatedTableND::solveForRatioArg: "
1144  "faled to bracket the root");
1145 
1146  assert(x1 >= x0);
1147  while ((x1 - x0)/(std::abs(x1) + std::abs(x0) + DBL_EPSILON) > 4.0*DBL_EPSILON)
1148  {
1149  const double xhalf = (x1 + x0)/2.0;
1150  const double fhalf = invg(xhalf)*Private::lind_interpolateSimple(
1151  xmin, xmax, rmin, rmax, xhalf);
1152  if (fval < fhalf)
1153  {
1154  x1 = xhalf;
1155  fmax = fhalf;
1156  }
1157  else
1158  {
1159  x0 = xhalf;
1160  fmin = fhalf;
1161  }
1162  }
1163  return (x1 + x0)/2.0;
1164  }
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
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 479 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().

480  {
481  const bool status = data_.classId().write(of) &&
482  data_.write(of) &&
483  gs::write_obj_vector(of, axes_);
484  if (status)
485  {
486  gs::write_pod_array(of, leftInterpolationLinear_, dim_);
487  gs::write_pod_array(of, rightInterpolationLinear_, dim_);
488  gs::write_pod(of, functionLabel_);
489  }
490  return status && !of.fail();
491  }
bool write(std::ostream &of) const
Definition: ArrayND.h:6041
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 34 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