Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:29

0001 //-*-c++-*-
0002 //-*-Weight.h-*-
0003 //   Written by James Monk and Andrew Pilkington
0004 /////////////////////////////////////////////////////////////////////////////
0005 #ifndef WEIGHT_HH
0006 #define WEIGHT_HH
0007 
0008 #include <iostream>
0009 #include <map>
0010 #include <vector>
0011 
0012 namespace Exhume {
0013 
0014   class Weight {
0015   public:
0016     Weight() { NPoints = 1000; };
0017     virtual ~Weight(){};
0018     inline std::map<double, double> GetFuncMap() { return (FuncMap); };
0019     inline double GetTotalIntegral() { return (TotalIntegral); };
0020 
0021     inline std::map<double, double> GetLineShape() { return (LineShape); };
0022 
0023   protected:
0024     virtual double WeightFunc(const double &) = 0;
0025 
0026     void AddPoint(const double &, const double &);
0027     inline double GetFunc(const double &xx_) {
0028       if (xx_ > Max_) {
0029         return (WeightFunc(xx_));
0030       }
0031 
0032       std::map<double, double>::iterator high_, low_;
0033       high_ = FuncMap.upper_bound(xx_);
0034       low_ = high_;
0035       low_--;
0036 
0037       return (low_->second + (high_->second - low_->second) * (xx_ - low_->first) / (high_->first - low_->first));
0038     };
0039 
0040     inline double GetValue(const double &xx_) {
0041       std::map<double, double>::iterator high_, low_;
0042       high_ = LineShape.upper_bound(xx_);
0043 
0044       if (high_ == LineShape.end())
0045         high_--;
0046 
0047       low_ = high_;
0048       low_--;
0049 
0050       return (low_->second + (high_->second - low_->second) * (xx_ - low_->first) / (high_->first - low_->first));
0051     };
0052     void WeightInit(const double &, const double &);
0053 
0054     double Max_;
0055     double TotalIntegral;
0056 
0057   private:
0058     unsigned int NPoints;
0059     std::map<double, double> FuncMap;
0060     std::map<double, double> LineShape;
0061   };
0062 }  // namespace Exhume
0063 
0064 #endif