DAS  3.0
Das Analysis System
RoccoR.h
Go to the documentation of this file.
1 #ifndef ElectroWeakAnalysis_RoccoR_H
2 #define ElectroWeakAnalysis_RoccoR_H
3 
4 #include <boost/math/special_functions/erf.hpp>
5 
6 struct CrystalBall{
7  static const double pi;
8  static const double sqrtPiOver2;
9  static const double sqrt2;
10 
11  double m;
12  double s;
13  double a;
14  double n;
15 
16  double B;
17  double C;
18  double D;
19  double N;
20 
21  double NA;
22  double Ns;
23  double NC;
24  double F;
25  double G;
26  double k;
27 
28  double cdfMa;
29  double cdfPa;
30 
31  CrystalBall():m(0),s(1),a(10),n(10){
32  init();
33  }
34 
35  void init(){
36  double fa = fabs(a);
37  double ex = exp(-fa*fa/2);
38  double A = pow(n/fa, n) * ex;
39  double C1 = n/fa/(n-1) * ex;
40  double D1 = 2 * sqrtPiOver2 * erf(fa/sqrt2);
41 
42  B = n/fa-fa;
43  C = (D1+2*C1)/C1;
44  D = (D1+2*C1)/2;
45 
46  N = 1.0/s/(D1+2*C1);
47  k = 1.0/(n-1);
48 
49  NA = N*A;
50  Ns = N*s;
51  NC = Ns*C1;
52  F = 1-fa*fa/n;
53  G = s*n/fa;
54 
55  cdfMa = cdf(m-a*s);
56  cdfPa = cdf(m+a*s);
57  }
58 
59  double pdf(double x) const{
60  double d=(x-m)/s;
61  if(d<-a) return NA*pow(B-d, -n);
62  if(d>a) return NA*pow(B+d, -n);
63  return N*exp(-d*d/2);
64  }
65 
66  double pdf(double x, double ks, double dm) const{
67  double d=(x-m-dm)/(s*ks);
68  if(d<-a) return NA/ks*pow(B-d, -n);
69  if(d>a) return NA/ks*pow(B+d, -n);
70  return N/ks*exp(-d*d/2);
71  }
72 
73  double cdf(double x) const{
74  double d = (x-m)/s;
75  if(d<-a) return NC / pow(F-s*d/G, n-1);
76  if(d>a) return NC * (C - pow(F+s*d/G, 1-n) );
77  return Ns * (D - sqrtPiOver2 * erf(-d/sqrt2));
78  }
79 
80  double invcdf(double u) const{
81  if(u<cdfMa) return m + G*(F - pow(NC/u, k));
82  if(u>cdfPa) return m - G*(F - pow(C-u/NC, -k) );
83  return m - sqrt2 * s * boost::math::erf_inv((D - u/Ns )/sqrtPiOver2);
84  }
85 };
86 
87 
88 struct RocRes{
89  enum TYPE {MC, Data, Extra};
90 
91  struct ResParams{
92  double eta;
93  double kRes[2];
94  std::vector<double> nTrk[2];
95  std::vector<double> rsPar[3];
96  std::vector<CrystalBall> cb;
97  ResParams():eta(0){for(auto& k: kRes) k=1;}
98  };
99 
100  int NETA;
101  int NTRK;
102  int NMIN;
103 
104  std::vector<ResParams> resol;
105 
106  RocRes();
107 
108  int etaBin(double x) const;
109  int trkBin(double x, int h, TYPE T=MC) const;
110  void reset();
111 
112  double rndm(int H, int F, double v) const;
113  double Sigma(double pt, int H, int F) const;
114  double kSpread(double gpt, double rpt, double eta, int nlayers, double w) const;
115  double kSpread(double gpt, double rpt, double eta) const;
116  double kSmear(double pt, double eta, TYPE type, double v, double u) const;
117  double kSmear(double pt, double eta, TYPE type, double v, double u, int n) const;
118  double kExtra(double pt, double eta, int nlayers, double u, double w) const;
119  double kExtra(double pt, double eta, int nlayers, double u) const;
120 };
121 
122 class RoccoR{
123 
124  private:
126 
127  static const double MPHI;
128 
129  int NETA;
130  int NPHI;
131  double DPHI;
132  std::vector<double> etabin;
133 
134  struct CorParams{double M; double A;};
135 
136  struct RocOne{
138  std::vector<std::vector<CorParams>> CP[2];
139  };
140 
141  int nset;
142  std::vector<int> nmem;
143  std::vector<int> tvar;
144  std::vector<std::vector<RocOne>> RC;
145  template <typename T> double error(T f) const;
146 
147  protected:
148  int etaBin(double eta) const;
149  int phiBin(double phi) const;
150 
151  public:
152  enum TYPE{MC, DT};
153 
154  RoccoR();
155  RoccoR(std::string filename);
156 
157  void init(std::string filename);
158  void reset();
159  bool empty() const {return RC.empty();}
160  const RocRes& getRes(int s=0, int m=0) const {return RC[s][m].RR;}
161  double getM(int T, int H, int F, int s=0, int m=0) const{return RC[s][m].CP[T][H][F].M;}
162  double getA(int T, int H, int F, int s=0, int m=0) const{return RC[s][m].CP[T][H][F].A;}
163  double getK(int T, int H, int s=0, int m=0) const{return RC[s][m].RR.resol[H].kRes[T];}
164  double kGenSmear(double pt, double eta, double v, double u, RocRes::TYPE TT=RocRes::Data, int s=0, int m=0) const;
165  double kScaleMC(int Q, double pt, double eta, double phi, int s=0, int m=0) const;
166 
167  double kScaleDT(int Q, double pt, double eta, double phi, int s=0, int m=0) const;
168  double kSpreadMC(int Q, double pt, double eta, double phi, double gt, int s=0, int m=0) const;
169  double kSmearMC(int Q, double pt, double eta, double phi, int n, double u, int s=0, int m=0) const;
170 
171  double kScaleDTerror(int Q, double pt, double eta, double phi) const;
172  double kSpreadMCerror(int Q, double pt, double eta, double phi, double gt) const;
173  double kSmearMCerror(int Q, double pt, double eta, double phi, int n, double u) const;
174 
175  //old, should only be used with 2017v0
176  double kScaleFromGenMC(int Q, double pt, double eta, double phi, int n, double gt, double w, int s=0, int m=0) const;
177  double kScaleAndSmearMC(int Q, double pt, double eta, double phi, int n, double u, double w, int s=0, int m=0) const;
178  double kScaleFromGenMCerror(int Q, double pt, double eta, double phi, int n, double gt, double w) const;
179  double kScaleAndSmearMCerror(int Q, double pt, double eta, double phi, int n, double u, double w) const;
180 };
181 
182 #endif
RoccoR::nset
int nset
Definition: RoccoR.h:141
CrystalBall::NA
double NA
Definition: RoccoR.h:21
RoccoR::kScaleAndSmearMC
double kScaleAndSmearMC(int Q, double pt, double eta, double phi, int n, double u, double w, int s=0, int m=0) const
Definition: RoccoR.cc:299
RoccoR::kScaleAndSmearMCerror
double kScaleAndSmearMCerror(int Q, double pt, double eta, double phi, int n, double u, double w) const
Definition: RoccoR.cc:340
RoccoR::kSmearMC
double kSmearMC(int Q, double pt, double eta, double phi, int n, double u, int s=0, int m=0) const
Definition: RoccoR.cc:282
RoccoR::RC
std::vector< std::vector< RocOne > > RC
Definition: RoccoR.h:144
RoccoR::RocOne::RR
RocRes RR
Definition: RoccoR.h:137
jmarExample.pt
pt
Definition: jmarExample.py:19
CrystalBall::cdf
double cdf(double x) const
Definition: RoccoR.h:73
CrystalBall::D
double D
Definition: RoccoR.h:18
RoccoR::getA
double getA(int T, int H, int F, int s=0, int m=0) const
Definition: RoccoR.h:162
RoccoR::error
double error(T f) const
Definition: RoccoR.cc:313
RoccoR::getK
double getK(int T, int H, int s=0, int m=0) const
Definition: RoccoR.h:163
RoccoR::tvar
std::vector< int > tvar
Definition: RoccoR.h:143
CrystalBall::F
double F
Definition: RoccoR.h:24
RocRes::ResParams::cb
std::vector< CrystalBall > cb
Definition: RoccoR.h:96
RoccoR::NPHI
int NPHI
Definition: RoccoR.h:130
CrystalBall::Ns
double Ns
Definition: RoccoR.h:22
RocRes::ResParams::eta
double eta
Definition: RoccoR.h:92
RocRes::Data
@ Data
Definition: RoccoR.h:89
RoccoR::CorParams
Definition: RoccoR.h:134
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
RoccoR::Symhes
@ Symhes
Definition: RoccoR.h:125
RoccoR::CorParams::M
double M
Definition: RoccoR.h:134
RocRes::ResParams::rsPar
std::vector< double > rsPar[3]
Definition: RoccoR.h:95
RocRes::kSmear
double kSmear(double pt, double eta, TYPE type, double v, double u) const
Definition: RoccoR.cc:70
DAS::JetEnergy::w
static const float w
Definition: common.h:51
RoccoR::getRes
const RocRes & getRes(int s=0, int m=0) const
Definition: RoccoR.h:160
RoccoR::nmem
std::vector< int > nmem
Definition: RoccoR.h:142
CrystalBall::a
double a
Definition: RoccoR.h:13
RoccoR::phiBin
int phiBin(double phi) const
Definition: RoccoR.cc:255
RoccoR::kScaleFromGenMCerror
double kScaleFromGenMCerror(int Q, double pt, double eta, double phi, int n, double gt, double w) const
Definition: RoccoR.cc:336
CrystalBall::B
double B
Definition: RoccoR.h:16
CrystalBall::cdfMa
double cdfMa
Definition: RoccoR.h:28
RocRes::ResParams::kRes
double kRes[2]
Definition: RoccoR.h:93
RoccoR::init
void init(std::string filename)
Definition: RoccoR.cc:129
RocRes::resol
std::vector< ResParams > resol
Definition: RoccoR.h:104
RocRes::Extra
@ Extra
Definition: RoccoR.h:89
RocRes::ResParams::ResParams
ResParams()
Definition: RoccoR.h:97
RoccoR::CorParams::A
double A
Definition: RoccoR.h:134
RoccoR::TYPE
TYPE
Definition: RoccoR.h:152
RoccoR::TVAR
TVAR
Definition: RoccoR.h:125
RoccoR::getM
double getM(int T, int H, int F, int s=0, int m=0) const
Definition: RoccoR.h:161
CrystalBall::pi
static const double pi
Definition: RoccoR.h:7
RocRes::trkBin
int trkBin(double x, int h, TYPE T=MC) const
Definition: RoccoR.cc:32
RoccoR
Definition: RoccoR.h:122
tauExample.dm
dm
Definition: tauExample.py:24
RoccoR::DPHI
double DPHI
Definition: RoccoR.h:131
RoccoR::kSpreadMCerror
double kSpreadMCerror(int Q, double pt, double eta, double phi, double gt) const
Definition: RoccoR.cc:328
RoccoR::empty
bool empty() const
Definition: RoccoR.h:159
RocRes::TYPE
TYPE
Definition: RoccoR.h:89
CrystalBall::cdfPa
double cdfPa
Definition: RoccoR.h:29
CrystalBall::sqrt2
static const double sqrt2
Definition: RoccoR.h:9
CrystalBall::pdf
double pdf(double x) const
Definition: RoccoR.h:59
RoccoR::MPHI
static const double MPHI
Definition: RoccoR.h:127
RocRes::NMIN
int NMIN
Definition: RoccoR.h:102
RocRes::kSpread
double kSpread(double gpt, double rpt, double eta, int nlayers, double w) const
Definition: RoccoR.cc:48
CrystalBall::k
double k
Definition: RoccoR.h:26
RoccoR::etaBin
int etaBin(double eta) const
Definition: RoccoR.cc:250
RocRes::kExtra
double kExtra(double pt, double eta, int nlayers, double u, double w) const
Definition: RoccoR.cc:87
RocRes::NTRK
int NTRK
Definition: RoccoR.h:101
RoccoR::kScaleFromGenMC
double kScaleFromGenMC(int Q, double pt, double eta, double phi, int n, double gt, double w, int s=0, int m=0) const
Definition: RoccoR.cc:291
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
RoccoR::NETA
int NETA
Definition: RoccoR.h:129
RoccoR::reset
void reset()
Definition: RoccoR.cc:118
CrystalBall::init
void init()
Definition: RoccoR.h:35
RoccoR::RocOne
Definition: RoccoR.h:136
RocRes::Sigma
double Sigma(double pt, int H, int F) const
Definition: RoccoR.cc:37
CrystalBall::NC
double NC
Definition: RoccoR.h:23
CrystalBall::invcdf
double invcdf(double u) const
Definition: RoccoR.h:80
RocRes::MC
@ MC
Definition: RoccoR.h:89
RocRes::RocRes
RocRes()
Definition: RoccoR.cc:15
CrystalBall::s
double s
Definition: RoccoR.h:12
RoccoR::kScaleDT
double kScaleDT(int Q, double pt, double eta, double phi, int s=0, int m=0) const
Definition: RoccoR.cc:262
CrystalBall
Definition: RoccoR.h:6
CrystalBall::CrystalBall
CrystalBall()
Definition: RoccoR.h:31
CrystalBall::sqrtPiOver2
static const double sqrtPiOver2
Definition: RoccoR.h:8
CrystalBall::m
double m
Definition: RoccoR.h:11
CrystalBall::n
double n
Definition: RoccoR.h:14
RoccoR::kSmearMCerror
double kSmearMCerror(int Q, double pt, double eta, double phi, int n, double u) const
Definition: RoccoR.cc:332
RoccoR::kScaleDTerror
double kScaleDTerror(int Q, double pt, double eta, double phi) const
Definition: RoccoR.cc:324
RoccoR::Default
@ Default
Definition: RoccoR.h:125
CrystalBall::N
double N
Definition: RoccoR.h:19
RocRes
Definition: RoccoR.h:88
RoccoR::kScaleMC
double kScaleMC(int Q, double pt, double eta, double phi, int s=0, int m=0) const
Definition: RoccoR.cc:268
RoccoR::etabin
std::vector< double > etabin
Definition: RoccoR.h:132
RocRes::etaBin
int etaBin(double x) const
Definition: RoccoR.cc:26
RoccoR::RocOne::CP
std::vector< std::vector< CorParams > > CP[2]
Definition: RoccoR.h:138
RoccoR::RoccoR
RoccoR()
Definition: RoccoR.cc:112
RoccoR::kGenSmear
double kGenSmear(double pt, double eta, double v, double u, RocRes::TYPE TT=RocRes::Data, int s=0, int m=0) const
Definition: RoccoR.cc:307
RocRes::ResParams
Definition: RoccoR.h:91
CrystalBall::G
double G
Definition: RoccoR.h:25
jmarExample.eta
eta
DeepAK8/ParticleNet tagging.
Definition: jmarExample.py:19
RocRes::reset
void reset()
Definition: RoccoR.cc:19
RoccoR::kSpreadMC
double kSpreadMC(int Q, double pt, double eta, double phi, double gt, int s=0, int m=0) const
Definition: RoccoR.cc:274
RocRes::NETA
int NETA
Definition: RoccoR.h:100
RoccoR::Replica
@ Replica
Definition: RoccoR.h:125
CrystalBall::pdf
double pdf(double x, double ks, double dm) const
Definition: RoccoR.h:66
CrystalBall::C
double C
Definition: RoccoR.h:17
RocRes::ResParams::nTrk
std::vector< double > nTrk[2]
Definition: RoccoR.h:94
RoccoR::MC
@ MC
Definition: RoccoR.h:152
RocRes::rndm
double rndm(int H, int F, double v) const
Definition: RoccoR.cc:43