CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

Quantile Class Reference

#include <Quantile.h>

List of all members.

Public Types

typedef std::vector< pairarray
typedef std::pair< double, double > pair

Public Member Functions

pair fromHead (const double frac) const
pair fromTail (const double frac) const
pair operator() (const double frac) const
pair operator[] (const double frac) const
 Quantile (const TH1 *h)
 Quantile (double central, double err)
double spread (TH1F &hist)
double spreadError (TH1F &hist)
double value (TH1F &hist)
double valueError (TH1F &hist)
 ~Quantile ()

Private Member Functions

pair calculateQ (const double frac, const bool fromHead) const
double distance (TH1F &hist)
void evaluate (double &err)
template<class T >
T next (T bin, T end) const
template<class T >
T prev (T bin, T begin) const
void quantiles (TH1F &hist, double err)

Private Attributes

double central_
double err_
array head
const int N
double qnt_ [3]
array tail
const double Total
double val_ [3]

Detailed Description

Definition at line 8 of file Quantile.h.


Member Typedef Documentation

typedef std::vector<pair> Quantile::array

Definition at line 10 of file Quantile.h.

typedef std::pair<double,double> Quantile::pair

Definition at line 9 of file Quantile.h.


Constructor & Destructor Documentation

Quantile::Quantile ( const TH1 *  h) [inline]

Definition at line 15 of file Quantile.h.

References head, i, N, and tail.

                         : 
    N( 1 + h->GetNbinsX()),
    Total(h->Integral(0,N))
  { for(int i=0;i<N; i++) {
      const double H = h->GetBinContent(i)   + (head.size()?head.back().second:0);
      const double T = h->GetBinContent(N-i) + (tail.size()?tail.back().second:0);  
      if(H) head.push_back( pair( h->GetBinWidth(i) + h->GetBinLowEdge(i) , H));
      if(T) tail.push_back( pair(                     h->GetBinLowEdge(N-i),T)); 
    }
  }
Quantile::Quantile ( double  central,
double  err 
) [inline]

Definition at line 42 of file CompMethods.h.

:central_(central), err_(err){};
Quantile::~Quantile ( ) [inline]

Definition at line 43 of file CompMethods.h.

{};

Member Function Documentation

pair Quantile::calculateQ ( const double  frac,
const bool  fromHead 
) const [inline, private]

Definition at line 31 of file Quantile.h.

References begin, newFWLiteAna::bin, end, f, cropTnPTrees::frac, head, max(), next(), prev(), mathSSE::sqrt(), tail, and Total.

Referenced by fromHead(), and fromTail().

                                                                {
    const double f = frac<0.5 ? frac : 1-frac ;
    array::const_iterator 
      begin( ( (frac<0.5) == fromHead ) ?  head.begin() : tail.begin()), 
      end(   ( (frac<0.5) == fromHead ) ?  head.end()   : tail.end()), 
      bin(begin);

    while( bin->second < f*Total ) bin++;
//dk    if( bin==begin ) return pair(sqrt(-1),0);
    if( bin==begin ) return pair(-1,0);
  
    array::const_iterator 
      binNext( next(bin,end)),
      binPrev( prev(bin,begin)),
      binPPrev( prev(binPrev,begin));

    const double
      DX( binNext->first - binPPrev->first ),
      DY( (binNext->second - binPPrev->second)/Total ),

      dX( bin->first - binPrev->first ),
      dY( (bin->second - binPrev->second)/Total ),

      avgX( ( bin->first + binPrev->first) /2 ),
      avgY( ( bin->second + binPrev->second) /(2*Total) ),

      x_q( avgX + dX/dY * ( f - avgY ) ),
      xerr_q( std::max(fabs(DX/DY),fabs(dX/dY)) * sqrt(f*(1-f)/Total) );
    
    return pair(x_q,xerr_q);
  }
double Quantile::distance ( TH1F &  hist) [inline, private]

Definition at line 53 of file CompMethods.h.

References qnt_.

Referenced by spread(), spreadError(), and valueError().

{ return std::fabs(qnt_[2]-qnt_[0]); };
void Quantile::evaluate ( double &  err) [inline, private]

Definition at line 51 of file CompMethods.h.

References central_, and val_.

Referenced by quantiles().

{val_[0]=central_-err; val_[1]=central_; val_[2]=central_+err;};
pair Quantile::fromHead ( const double  frac) const [inline]

Definition at line 26 of file Quantile.h.

References calculateQ().

Referenced by operator()().

{return calculateQ(frac,true);}
pair Quantile::fromTail ( const double  frac) const [inline]

Definition at line 27 of file Quantile.h.

References calculateQ().

Referenced by operator[]().

{return calculateQ(frac,false);}
template<class T >
T Quantile::next ( T  bin,
T  end 
) const [inline, private]

Definition at line 72 of file Quantile.h.

References newFWLiteAna::bin, and edm::second().

Referenced by calculateQ().

                                               {
    T binNext = bin;
    while( binNext<end-1 &&
           (++binNext)->second == bin->second) 
      ;
    return binNext;
  }
pair Quantile::operator() ( const double  frac) const [inline]

Definition at line 12 of file Quantile.h.

References fromHead().

{return fromHead(frac);}
pair Quantile::operator[] ( const double  frac) const [inline]

Definition at line 13 of file Quantile.h.

References fromTail().

{return fromTail(frac);}
template<class T >
T Quantile::prev ( T  bin,
T  begin 
) const [inline, private]

Definition at line 64 of file Quantile.h.

References newFWLiteAna::bin, and edm::second().

Referenced by calculateQ().

                                                 {
    T binPrev = bin;
    while( binPrev > begin && 
           (binPrev-1)->second == (bin-1)->second ) 
      binPrev--;
    return binPrev;
  }
void Quantile::quantiles ( TH1F &  hist,
double  err 
) [inline, private]

Definition at line 52 of file CompMethods.h.

References evaluate(), qnt_, and val_.

Referenced by spread(), spreadError(), value(), and valueError().

{ evaluate(err); hist.GetQuantiles(3, qnt_, val_); };
double Quantile::spread ( TH1F &  hist) [inline]

Definition at line 46 of file CompMethods.h.

References distance(), and quantiles().

Referenced by FitHist::fillTargetHistogramBin().

{ quantiles(hist, 0.25); return distance(hist); };
double Quantile::spreadError ( TH1F &  hist)

Definition at line 92 of file CompMethods.cc.

References distance(), err_, SurfaceOrientation::inner, SurfaceOrientation::outer, and quantiles().

Referenced by FitHist::fillTargetHistogramBin().

{
  quantiles(hist, 0.25+err_); double outer=distance(hist);
  quantiles(hist, 0.25-err_); double inner=distance(hist);
  return std::fabs(outer-inner)/2;
}
double Quantile::value ( TH1F &  hist) [inline]

Definition at line 44 of file CompMethods.h.

References err_, qnt_, and quantiles().

Referenced by FitHist::fillTargetHistogramBin().

{ quantiles(hist, err_); return qnt_[1]; };
double Quantile::valueError ( TH1F &  hist) [inline]

Definition at line 45 of file CompMethods.h.

References distance(), err_, and quantiles().

Referenced by FitHist::fillTargetHistogramBin().

{ quantiles(hist, err_); return distance(hist); };

Member Data Documentation

double Quantile::central_ [private]

Definition at line 53 of file CompMethods.h.

Referenced by evaluate().

double Quantile::err_ [private]

Definition at line 58 of file CompMethods.h.

Referenced by spreadError(), value(), and valueError().

array Quantile::head [private]

Definition at line 82 of file Quantile.h.

Referenced by calculateQ(), and Quantile().

const int Quantile::N [private]

Definition at line 80 of file Quantile.h.

Referenced by Quantile().

double Quantile::qnt_[3] [private]

Definition at line 60 of file CompMethods.h.

Referenced by distance(), quantiles(), and value().

array Quantile::tail [private]

Definition at line 82 of file Quantile.h.

Referenced by calculateQ(), and Quantile().

const double Quantile::Total [private]

Definition at line 81 of file Quantile.h.

Referenced by calculateQ().

double Quantile::val_[3] [private]

Definition at line 59 of file CompMethods.h.

Referenced by evaluate(), and quantiles().