DAS  3.0
Das Analysis System
resolution.h File Reference
#include "Core/CommonTools/interface/binnings.h"
#include "Core/CommonTools/interface/toolbox.h"
#include <TH1.h>
#include <iostream>
#include <cmath>
+ Include dependency graph for resolution.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double safelog (double x)
 
double id (double x)
 
TH1 * Derivative (TH1 *h, double(*f)(double)=id)
 
unique_ptr< TH1 > DerivativeFivePointStencil (const unique_ptr< TH1 > &h, double(*f)(double)=id)
 
TH1 * SecondDerivative (TH1 *h, double(*f)(double)=id)
 
double mNSC (double *x, double *p)
 
double GausExp (double *x, double *p)
 
double Novosibirsk (double *x, double *p)
 
double CrystalBall (double *x, double *p)
 
double ModifiedGaussianCore (double *x, double *p)
 

Variables

static const size_t nN = 8
 
static const size_t nmu = 3
 
static const size_t nkL = 2
 
static const size_t nnL = 5
 
static const size_t nkR = 2
 
static const size_t nnR = 5
 

Function Documentation

◆ CrystalBall()

double CrystalBall ( double *  x,
double *  p 
)

Resolution with modified Gaussian with simple power-law tail

Note: not very stable because of n**n behaviour -> the trick when fitting is to find the k by looking at the derivative of the log of the function, since the Gaussian should be a straight line...

NB: code should be carefully checked ...

https://en.wikipedia.org/wiki/Crystal_Ball_function

NOTE: prefer the more general implementation

172 {
173  double N = p[0],
174  mu = p[1],
175  sigma = p[2],
176  k = p[3],
177  n = p[4];
178 
179  double z = (*x - mu)/sigma,
180  a = abs( k - mu)/sigma;
181 
182  double expa2 = exp(-pow(a,2)/2.);
183 
184  double C = n * expa2 / (a*(n-1)),
185  D = sqrt(M_PI/2.)*(1 + erf(a/sqrt(2)));
186 
187  N /= sigma * (C + D);
188 
189  if (*x > k) {
190  return N*exp(-pow(z,2)/2.);
191  }
192  else {
193  double A = pow(n/a, n) * expa2,
194  B = n/a - a;
195  return N*A*pow(B-z,-n);
196  }
197 }

◆ Derivative()

TH1* Derivative ( TH1 *  h,
double(*)(double)  f = id 
)

Calculate numerical derivative of a histogram

https://en.wikipedia.org/wiki/Numerical_differentiation

28 {
29  const char * name = Form("derivative_%s", h->GetName());
30  TH1 * d = dynamic_cast<TH1*>(h->Clone(name));
31  d->Reset();
32  for (int i = 2; i < d->GetNbinsX(); ++i) {
33  auto x1 = h->GetBinCenter(i-1),
34  x2 = h->GetBinCenter(i+1),
35  f1 = f(h->GetBinContent(i-1)),
36  f2 = f(h->GetBinContent(i+1));
37  auto dx = x2-x1;
38  if (abs(dx) < 1e-20) continue;
39  auto df = f2-f1;
40  d->SetBinContent(i, df/dx);
41  }
42  return d;
43 }

◆ DerivativeFivePointStencil()

unique_ptr<TH1> DerivativeFivePointStencil ( const unique_ptr< TH1 > &  h,
double(*)(double)  f = id 
)

Calculate numerical derivative of a histogram

https://en.wikipedia.org/wiki/Numerical_differentiation

50 {
51  const char * name = Form("derivative_%s", h->GetName());
52  auto d = unique_ptr<TH1>( dynamic_cast<TH1*>(h->Clone(name)) );
53  d->Reset();
54  for (int i = 3; i < d->GetNbinsX()-1; ++i) {
55  auto w = d->GetBinWidth(i);
56  //assert(abs(w - d->GetBinWidth(i)) < 1e-4); /// \todo not necessary met in the tails, where bins are merged....
57  auto f1 = f(h->GetBinContent(i-2)),
58  f2 = f(h->GetBinContent(i-1)),
59  f3 = f(h->GetBinContent(i+1)),
60  f4 = f(h->GetBinContent(i+2));
61  auto dx = 12*w;
62  if (abs(dx) < 1e-20) continue;
63  auto df = -f4 + 8*f3 - 8*f2 + f1;
64  d->SetBinContent(i, df/dx);
65  }
66  return d;
67 }

◆ GausExp()

double GausExp ( double *  x,
double *  p 
)

Resolution with modified Gaussian with simple exponentional tail

Note: more stable than Crystal-Ball, but only one parameter

https://home.fnal.gov/~souvik/GaussExp/GaussExp.pdf

117 {
118  double N = p[0],
119  mu = p[1],
120  sigma = p[2],
121  kR = p[3];
122 
123  auto z = [&](double x) { return (x - mu)/sigma; };
124 
125  double zx = z(*x);
126 
127  if (*x > kR) {
128  double zk = z(kR);
129  return N*exp(0.5*pow(zk,2)-zk*zx);
130  }
131  else {
132  return N*exp(-0.5*pow(zx,2));
133  }
134 }

◆ id()

double id ( double  x)
inline
21 { return x; };

◆ mNSC()

double mNSC ( double *  x,
double *  p 
)

Resolution width as a function of gen pt

  • p[0] = Noise
  • p[1] = Stochastic
  • p[2] = Constant
  • p[3] = modification parameter

Note that the freedom for the sign of the first term is also a modification of the original NSC function.

106 {
107  return sqrt( p[0]*abs(p[0])/(x[0]*x[0]) + p[1]*p[1]/pow(x[0],p[3]) + p[2]*p[2]);
108 }

◆ ModifiedGaussianCore()

double ModifiedGaussianCore ( double *  x,
double *  p 
)

Advanced function to fit resolution including non-Gaussian deviations and pile-up jets.

202 {
203  double N = p[0], // Gaussian core
204  mu = p[1],
205  sigma = max(1e-8,abs(p[2])),
206  B = p[3],
207  C = p[4];
208 
209  return N*exp(- pow((*x-mu)/sigma,2)/2
210  -B*pow((*x-mu) ,3)/3
211  -C*pow((*x-mu) ,4)/4);
212 }

◆ Novosibirsk()

double Novosibirsk ( double *  x,
double *  p 
)

Asymmetric Gaussian, a.k.a. Novosibirsk

Todo:
find reference
141 {
142  double N = p[0],
143  mu = p[1],
144  sigma = p[2],
145  tau = p[3];
146 
147  if (sigma <= 0) return 0;
148 
149  double y = (*x-mu)/sigma;
150 
151  static const double C = sqrt(log(4.));
152  double coeff = sinh(C*tau) / C;
153 
154  double z2 = pow( log(1.+coeff*y)/tau, 2) + pow(tau,2);
155  return N*exp(-0.5*z2);
156 }

◆ safelog()

double safelog ( double  x)
inline
19 { return x > 0 ? log(x) : 0; };

◆ SecondDerivative()

TH1* SecondDerivative ( TH1 *  h,
double(*)(double)  f = id 
)

Calculate numerical second derivative of a histogram

Note: seems to work less good that just applying twice Derivative()...

https://en.wikipedia.org/wiki/Numerical_differentiation

76 {
77  const char * name = Form("secondderivative_%s", h->GetName());
78  TH1 * d2 = dynamic_cast<TH1*>(h->Clone(name));
79  d2->Reset();
80  for (int i = 2; i < d2->GetNbinsX(); ++i) {
81  auto x0 = h->GetBinCenter(i-1),
82  x1 = h->GetBinCenter(i ),
83  x2 = h->GetBinCenter(i+1),
84  f0 = f(h->GetBinContent(i-1)),
85  f1 = f(h->GetBinContent(i )),
86  f2 = f(h->GetBinContent(i+1));
87  auto dx2 = (x2-x1)*(x1-x0);
88  if (abs(dx2) < 1e-20) continue;
89  auto d2f = f2-2*f1+f0;
90  d2->SetBinContent(i, d2f/dx2);
91  }
92  return d2;
93 }

Variable Documentation

◆ nkL

const size_t nkL = 2
static

order of Chebyshev polynomial for global LHS tail transition of DCB

◆ nkR

const size_t nkR = 2
static

order of Chebyshev polynomial for global RHS tail transition of DCB

◆ nmu

const size_t nmu = 3
static

order of Chebyshev polynomial for global mean of DCB

◆ nN

const size_t nN = 8
static

order of Chebyshev polynomial for global normalisation of DCB

◆ nnL

const size_t nnL = 5
static

order of Chebyshev polynomial for global LHS tail steepness of DCB

◆ nnR

const size_t nnR = 5
static

order of Chebyshev polynomial for global RHS tail steepness of DCB

DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Ntupliser_cfg.p
p
Definition: Ntupliser_cfg.py:358
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:252
B
< SOURCE_DIR >< SOURCE_SUBDIR > B
Definition: Core-cfgcmd.txt:1
DAS::JetEnergy::w
static const float w
Definition: common.h:51