CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
Quantile Struct Reference

#include <Quantile.h>

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)
 

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
 

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 class-composition::H, head, i, N, and tail.

15  :
16  N( 1 + h->GetNbinsX()),
17  Total(h->Integral(0,N))
18  { for(int i=0;i<N; i++) {
19  const double H = h->GetBinContent(i) + (head.size()?head.back().second:0);
20  const double T = h->GetBinContent(N-i) + (tail.size()?tail.back().second:0);
21  if(H) head.push_back( pair( h->GetBinWidth(i) + h->GetBinLowEdge(i) , H));
22  if(T) tail.push_back( pair( h->GetBinLowEdge(N-i),T));
23  }
24  }
int i
Definition: DBlmapReader.cc:9
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::pair< double, double > pair
Definition: Quantile.h:9
array head
Definition: Quantile.h:82
const double Total
Definition: Quantile.h:81
array tail
Definition: Quantile.h:82
const int N
Definition: Quantile.h:80
long double T

Member Function Documentation

pair Quantile::calculateQ ( const double  frac,
const bool  fromHead 
) const
inlineprivate

Definition at line 31 of file Quantile.h.

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

Referenced by fromHead(), and fromTail().

31  {
32  const double f = frac<0.5 ? frac : 1-frac ;
33  array::const_iterator
34  begin( ( (frac<0.5) == fromHead ) ? head.begin() : tail.begin()),
35  end( ( (frac<0.5) == fromHead ) ? head.end() : tail.end()),
36  bin(begin);
37 
38  while( bin->second < f*Total ) bin++;
39 //dk if( bin==begin ) return pair(sqrt(-1),0);
40  if( bin==begin ) return pair(-1,0);
41 
42  array::const_iterator
43  binNext( next(bin,end)),
44  binPrev( prev(bin,begin)),
45  binPPrev( prev(binPrev,begin));
46 
47  const double
48  DX( binNext->first - binPPrev->first ),
49  DY( (binNext->second - binPPrev->second)/Total ),
50 
51  dX( bin->first - binPrev->first ),
52  dY( (bin->second - binPrev->second)/Total ),
53 
54  avgX( ( bin->first + binPrev->first) /2 ),
55  avgY( ( bin->second + binPrev->second) /(2*Total) ),
56 
57  x_q( avgX + dX/dY * ( f - avgY ) ),
58  xerr_q( std::max(fabs(DX/DY),fabs(dX/dY)) * sqrt(f*(1-f)/Total) );
59 
60  return pair(x_q,xerr_q);
61  }
T next(T bin, T end) const
Definition: Quantile.h:72
std::pair< double, double > pair
Definition: Quantile.h:9
T sqrt(T t)
Definition: SSEVec.h:18
array head
Definition: Quantile.h:82
double f[11][100]
#define end
Definition: vmac.h:37
const double Total
Definition: Quantile.h:81
pair fromHead(const double frac) const
Definition: Quantile.h:26
#define begin
Definition: vmac.h:30
array tail
Definition: Quantile.h:82
T prev(T bin, T begin) const
Definition: Quantile.h:64
pair Quantile::fromHead ( const double  frac) const
inline

Definition at line 26 of file Quantile.h.

References calculateQ().

Referenced by operator()().

26 {return calculateQ(frac,true);}
pair calculateQ(const double frac, const bool fromHead) const
Definition: Quantile.h:31
pair Quantile::fromTail ( const double  frac) const
inline

Definition at line 27 of file Quantile.h.

References calculateQ().

Referenced by operator[]().

27 {return calculateQ(frac,false);}
pair calculateQ(const double frac, const bool fromHead) const
Definition: Quantile.h:31
template<class T >
T Quantile::next ( T  bin,
T  end 
) const
inlineprivate

Definition at line 72 of file Quantile.h.

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

Referenced by BeautifulSoup.PageElement::_invert(), and calculateQ().

72  {
73  T binNext = bin;
74  while( binNext<end-1 &&
75  (++binNext)->second == bin->second)
76  ;
77  return binNext;
78  }
U second(std::pair< T, U > const &p)
#define end
Definition: vmac.h:37
long double T
pair Quantile::operator() ( const double  frac) const
inline

Definition at line 12 of file Quantile.h.

References fromHead().

12 {return fromHead(frac);}
pair fromHead(const double frac) const
Definition: Quantile.h:26
pair Quantile::operator[] ( const double  frac) const
inline

Definition at line 13 of file Quantile.h.

References fromTail().

13 {return fromTail(frac);}
pair fromTail(const double frac) const
Definition: Quantile.h:27
template<class T >
T Quantile::prev ( T  bin,
T  begin 
) const
inlineprivate

Definition at line 64 of file Quantile.h.

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

Referenced by calculateQ().

64  {
65  T binPrev = bin;
66  while( binPrev > begin &&
67  (binPrev-1)->second == (bin-1)->second )
68  binPrev--;
69  return binPrev;
70  }
U second(std::pair< T, U > const &p)
#define begin
Definition: vmac.h:30
long double T

Member Data Documentation

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().