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.

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  }

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

Member Function Documentation

◆ calculateQ()

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

Definition at line 30 of file Quantile.h.

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  }

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

◆ fromHead()

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

Definition at line 26 of file Quantile.h.

26 { return calculateQ(frac, true); }

References calculateQ(), and DivergingColor::frac.

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

◆ fromTail()

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

Definition at line 27 of file Quantile.h.

27 { return calculateQ(frac, false); }

References calculateQ(), and DivergingColor::frac.

Referenced by operator[]().

◆ next()

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

Definition at line 63 of file Quantile.h.

63  {
64  T binNext = bin;
65  while (binNext < end - 1 && (++binNext)->second == bin->second)
66  ;
67  return binNext;
68  }

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

Referenced by calculateQ().

◆ operator()()

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

Definition at line 12 of file Quantile.h.

12 { return fromHead(frac); }

References DivergingColor::frac, and fromHead().

◆ operator[]()

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

Definition at line 13 of file Quantile.h.

13 { return fromTail(frac); }

References DivergingColor::frac, and fromTail().

◆ prev()

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

Definition at line 55 of file Quantile.h.

55  {
56  T binPrev = bin;
57  while (binPrev > begin && (binPrev - 1)->second == (bin - 1)->second)
58  binPrev--;
59  return binPrev;
60  }

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

Referenced by calculateQ().

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

mps_fire.i
i
Definition: mps_fire.py:428
Quantile::fromHead
pair fromHead(const double frac) const
Definition: Quantile.h:26
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
Quantile::fromTail
pair fromTail(const double frac) const
Definition: Quantile.h:27
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
DivergingColor.frac
float frac
Definition: DivergingColor.py:175
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
mps_fire.end
end
Definition: mps_fire.py:242
Quantile::tail
array tail
Definition: Quantile.h:72
h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Quantile::head
array head
Definition: Quantile.h:72
Quantile::N
const int N
Definition: Quantile.h:70
Quantile::pair
std::pair< double, double > pair
Definition: Quantile.h:9
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
T
long double T
Definition: Basic3DVectorLD.h:48
Quantile::Total
const double Total
Definition: Quantile.h:71
Quantile::next
T next(T bin, T end) const
Definition: Quantile.h:63
Quantile::prev
T prev(T bin, T begin) const
Definition: Quantile.h:55
data-class-funcs.H
H
Definition: data-class-funcs.py:33
Quantile::calculateQ
pair calculateQ(const double frac, const bool fromHead) const
Definition: Quantile.h:30