DAS  3.0
Das Analysis System
resolution.h
Go to the documentation of this file.
3 
4 #include <TH1.h>
5 
6 #include <iostream>
7 #include <cmath>
8 
9 using namespace DAS;
10 using namespace std;
11 
12 static const size_t nN = 8;
13 static const size_t nmu = 3;
14 static const size_t nkL = 2;
15 static const size_t nnL = 5;
16 static const size_t nkR = 2;
17 static const size_t nnR = 5;
18 
19 inline double safelog (double x) { return x > 0 ? log(x) : 0; };
20 
21 inline double id (double x) { return x; };
22 
27 TH1 * Derivative (TH1 * h, double (*f)(double) = id)
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 }
44 
49 unique_ptr<TH1> DerivativeFivePointStencil (const unique_ptr<TH1>& h, double (*f)(double) = id)
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 }
68 
75 TH1 * SecondDerivative (TH1 * h, double (*f)(double) = id)
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 }
94 
105 double mNSC (double * x, double * p)
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 }
109 
116 double GausExp (double * x, double * p)
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 }
135 
140 double Novosibirsk (double * x, double * p)
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 }
157 
170 [[ deprecated ]]
171 double CrystalBall (double * x, double * p)
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 }
198 
201 double ModifiedGaussianCore (double * x, double * p)
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 }
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
DAS
Definition: applyBTagSF.cc:31
Novosibirsk
double Novosibirsk(double *x, double *p)
Definition: resolution.h:140
SecondDerivative
TH1 * SecondDerivative(TH1 *h, double(*f)(double)=id)
Definition: resolution.h:75
Derivative
TH1 * Derivative(TH1 *h, double(*f)(double)=id)
Definition: resolution.h:27
nmu
static const size_t nmu
order of Chebyshev polynomial for global mean of DCB
Definition: resolution.h:13
DerivativeFivePointStencil
unique_ptr< TH1 > DerivativeFivePointStencil(const unique_ptr< TH1 > &h, double(*f)(double)=id)
Definition: resolution.h:49
GausExp
double GausExp(double *x, double *p)
Definition: resolution.h:116
Ntupliser_cfg.p
p
Definition: Ntupliser_cfg.py:362
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
B
< SOURCE_DIR >< SOURCE_SUBDIR > B
Definition: Core-cfgcmd.txt:1
DAS::JetEnergy::w
static const float w
Definition: common.h:51
id
double id(double x)
Definition: resolution.h:21
nN
static const size_t nN
order of Chebyshev polynomial for global normalisation of DCB
Definition: resolution.h:12
nkR
static const size_t nkR
order of Chebyshev polynomial for global RHS tail transition of DCB
Definition: resolution.h:16
CrystalBall
double CrystalBall(double *x, double *p)
Definition: resolution.h:171
nnL
static const size_t nnL
order of Chebyshev polynomial for global LHS tail steepness of DCB
Definition: resolution.h:15
binnings.h
nnR
static const size_t nnR
order of Chebyshev polynomial for global RHS tail steepness of DCB
Definition: resolution.h:17
mNSC
double mNSC(double *x, double *p)
Definition: resolution.h:105
toolbox.h
ModifiedGaussianCore
double ModifiedGaussianCore(double *x, double *p)
Advanced function to fit resolution including non-Gaussian deviations and pile-up jets.
Definition: resolution.h:201
nkL
static const size_t nkL
order of Chebyshev polynomial for global LHS tail transition of DCB
Definition: resolution.h:14
safelog
double safelog(double x)
Definition: resolution.h:19