Weight

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//-*-c++-*-
//-*-Weight.h-*-
//   Written by James Monk and Andrew Pilkington
/////////////////////////////////////////////////////////////////////////////
#ifndef WEIGHT_HH
#define WEIGHT_HH

#include <iostream>
#include <map>
#include <vector>

namespace Exhume {

  class Weight {
  public:
    Weight() { NPoints = 1000; };
    virtual ~Weight() {}
    inline std::map<double, double> GetFuncMap() { return (FuncMap); };
    inline double GetTotalIntegral() { return (TotalIntegral); };

    inline std::map<double, double> GetLineShape() { return (LineShape); };

  protected:
    virtual double WeightFunc(const double &) = 0;

    void AddPoint(const double &, const double &);
    inline double GetFunc(const double &xx_) {
      if (xx_ > Max_) {
        return (WeightFunc(xx_));
      }

      std::map<double, double>::iterator high_, low_;
      high_ = FuncMap.upper_bound(xx_);
      low_ = high_;
      low_--;

      return (low_->second + (high_->second - low_->second) * (xx_ - low_->first) / (high_->first - low_->first));
    };

    inline double GetValue(const double &xx_) {
      std::map<double, double>::iterator high_, low_;
      high_ = LineShape.upper_bound(xx_);

      if (high_ == LineShape.end())
        high_--;

      low_ = high_;
      low_--;

      return (low_->second + (high_->second - low_->second) * (xx_ - low_->first) / (high_->first - low_->first));
    };
    void WeightInit(const double &, const double &);

    double Max_;
    double TotalIntegral;

  private:
    unsigned int NPoints;
    std::map<double, double> FuncMap;
    std::map<double, double> LineShape;
  };
}  // namespace Exhume

#endif