CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/GeneratorInterface/ExhumeInterface/interface/Weight.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 //-*-Weight.h-*-
00003 //   Written by James Monk and Andrew Pilkington
00005 #ifndef WEIGHT_HH
00006 #define WEIGHT_HH
00007 
00008 #include <iostream>
00009 #include <map>
00010 #include <vector>
00011 
00012 namespace Exhume{
00013 
00014   class Weight{
00015 
00016   public:
00017 
00018     Weight(){NPoints = 1000;};
00019     virtual ~Weight(){};
00020     inline std::map<double, double> GetFuncMap(){
00021       return(FuncMap);
00022     };
00023     inline double GetTotalIntegral(){
00024       return(TotalIntegral);
00025     };
00026 
00027     inline std::map<double, double> GetLineShape(){
00028       return(LineShape);
00029     };
00030 
00031   protected:
00032 
00033     virtual double WeightFunc(const double&)=0;
00034 
00035     void AddPoint(const double&, const double&);
00036     inline double GetFunc(const double &xx_){
00037       if(xx_ > Max_){
00038         return(WeightFunc(xx_) );
00039       }
00040 
00041       std::map<double, double>::iterator high_, low_;
00042       high_ = FuncMap.upper_bound(xx_);
00043       low_ = high_;
00044       low_--;
00045 
00046       return( low_->second + 
00047               (high_->second - low_->second) * (xx_ - low_->first)/
00048               (high_->first - low_->first));
00049     };
00050 
00051     inline double GetValue(const double &xx_){
00052 
00053       std::map<double, double>::iterator high_, low_;
00054       high_ = LineShape.upper_bound(xx_);
00055       
00056       if(high_==LineShape.end())high_--;
00057 
00058       low_ = high_;
00059       low_--;
00060 
00061       return( low_->second + 
00062               (high_->second - low_->second) * (xx_ - low_->first)/
00063               (high_->first - low_->first));
00064     };
00065     void WeightInit(const double&, const double&);
00066 
00067     double Max_;
00068     double TotalIntegral;
00069 
00070   private:
00071 
00072     unsigned int NPoints;
00073     std::map<double, double> FuncMap;
00074     std::map<double, double> LineShape;
00075   };
00076 }
00077 
00078 
00079 
00080 #endif