CMS 3D CMS Logo

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

◆ array

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

Definition at line 10 of file Quantile.h.

◆ pair

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

Definition at line 9 of file Quantile.h.

Constructor & Destructor Documentation

◆ Quantile()

Quantile::Quantile ( const TH1 *  h)
inline

Definition at line 15 of file Quantile.h.

References h, data-class-funcs::H, head, mps_fire::i, N, and tail.

15  : N(1 + h->GetNbinsX()), Total(h->Integral(0, N)) {
16  for (int i = 0; i < N; i++) {
17  const double H = h->GetBinContent(i) + (!head.empty() ? head.back().second : 0);
18  const double T = h->GetBinContent(N - i) + (!tail.empty() ? tail.back().second : 0);
19  if (H)
20  head.push_back(pair(h->GetBinWidth(i) + h->GetBinLowEdge(i), H));
21  if (T)
22  tail.push_back(pair(h->GetBinLowEdge(N - i), T));
23  }
24  }
array head
Definition: Quantile.h:72
const double Total
Definition: Quantile.h:71
array tail
Definition: Quantile.h:72
const int N
Definition: Quantile.h:70
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
std::pair< double, double > pair
Definition: Quantile.h:9

Member Function Documentation

◆ calculateQ()

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

Definition at line 30 of file Quantile.h.

References newFWLiteAna::bin, mps_fire::end, f, DivergingColor::frac, fromHead(), head, SiStripPI::max, next(), prev(), mathSSE::sqrt(), tail, and Total.

Referenced by fromHead(), and fromTail().

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

◆ fromHead()

pair Quantile::fromHead ( const double  frac) const
inline

Definition at line 26 of file Quantile.h.

References calculateQ(), and DivergingColor::frac.

Referenced by calculateQ(), and operator()().

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

◆ fromTail()

pair Quantile::fromTail ( const double  frac) const
inline

Definition at line 27 of file Quantile.h.

References calculateQ(), and DivergingColor::frac.

Referenced by operator[]().

27 { return calculateQ(frac, false); }
pair calculateQ(const double frac, const bool fromHead) const
Definition: Quantile.h:30

◆ next()

template<class T >
T Quantile::next ( T  bin,
T  end 
) const
inlineprivate

Definition at line 63 of file Quantile.h.

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

Referenced by calculateQ().

63  {
64  T binNext = bin;
65  while (binNext < end - 1 && (++binNext)->second == bin->second)
66  ;
67  return binNext;
68  }
U second(std::pair< T, U > const &p)
long double T

◆ operator()()

pair Quantile::operator() ( const double  frac) const
inline

Definition at line 12 of file Quantile.h.

References DivergingColor::frac, and fromHead().

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

◆ operator[]()

pair Quantile::operator[] ( const double  frac) const
inline

Definition at line 13 of file Quantile.h.

References DivergingColor::frac, and fromTail().

13 { return fromTail(frac); }
pair fromTail(const double frac) const
Definition: Quantile.h:27

◆ prev()

template<class T >
T Quantile::prev ( T  bin,
T  begin 
) const
inlineprivate

Definition at line 55 of file Quantile.h.

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

Referenced by calculateQ().

55  {
56  T binPrev = bin;
57  while (binPrev > begin && (binPrev - 1)->second == (bin - 1)->second)
58  binPrev--;
59  return binPrev;
60  }
U second(std::pair< T, U > const &p)
long double T

Member Data Documentation

◆ head

array Quantile::head
private

Definition at line 72 of file Quantile.h.

Referenced by calculateQ(), and Quantile().

◆ N

const int Quantile::N
private

Definition at line 70 of file Quantile.h.

Referenced by Quantile().

◆ tail

array Quantile::tail
private

Definition at line 72 of file Quantile.h.

Referenced by calculateQ(), and Quantile().

◆ Total

const double Quantile::Total
private

Definition at line 71 of file Quantile.h.

Referenced by calculateQ().