#include <Quantile.h>
Public Types | |
typedef std::vector< pair > | array |
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) | |
Private Member Functions | |
pair | calculateQ (const double frac, const bool fromHead) const |
template<class T > | |
T | next (T bin, T end) const |
template<class T > | |
T | prev (T bin, T begin) const |
Private Attributes | |
array | head |
const int | N |
array | tail |
const double | Total |
Definition at line 8 of file Quantile.h.
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.
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)); } }
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); }
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);}
Definition at line 72 of file Quantile.h.
References newFWLiteAna::bin, and edm::second().
Referenced by calculateQ().
pair Quantile::operator() | ( | const double | frac | ) | const [inline] |
pair Quantile::operator[] | ( | const double | frac | ) | const [inline] |
Definition at line 64 of file Quantile.h.
References newFWLiteAna::bin, and edm::second().
Referenced by calculateQ().
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().
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().