CMS 3D CMS Logo

ReweightUserHooks.h
Go to the documentation of this file.
1 #include "Pythia8/Pythia.h"
2 #include "TF1.h"
3 
4 class PtHatReweightUserHook : public Pythia8::UserHooks {
5 public:
6  PtHatReweightUserHook(double _pt = 15, double _power = 4.5) : pt(_pt), power(_power) {}
7  ~PtHatReweightUserHook() override {}
8 
9  bool canBiasSelection() override { return true; }
10 
11  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
12  const Pythia8::PhaseSpace* phaseSpacePtr,
13  bool inEvent) override {
14  //the variable selBias of the base class should be used;
15  if ((sigmaProcessPtr->nFinal() == 2)) {
16  selBias = pow(phaseSpacePtr->pTHat() / pt, power);
17  return selBias;
18  }
19  selBias = 1.;
20  return selBias;
21  }
22 
23 private:
24  double pt, power;
25 };
26 
27 class PtHatEmpReweightUserHook : public Pythia8::UserHooks {
28 public:
29  PtHatEmpReweightUserHook(const std::string& tuneName = "") {
30  if (tuneName == "CP5")
31  p = {7377.94700788, 8.38168461349, -4.70983112392, -0.0310148108446, -0.028798537937, 925.335472326};
32  //Default reweighting - works good for tune CUEPT8M1
33  else
34  p = {5.3571961909810e+13,
35  1.0907678218282e+01,
36  -2.5898069229451e+00,
37  -5.1575514014931e-01,
38  5.5951279807561e-02,
39  3.5e+02};
40  sigma = [this](double x) -> double {
41  return (p[0] * pow(x, p[2] + p[3] * log(0.01 * x) + p[4] * pow(log(0.01 * x), 2)) *
42  pow(1 - 2 * x / (13000. + p[5]), p[1])) *
43  x;
44  };
45  }
47 
48  bool canBiasSelection() override { return true; }
49 
50  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
51  const Pythia8::PhaseSpace* phaseSpacePtr,
52  bool inEvent) override {
53  //the variable selBias of the base class should be used;
54  if ((sigmaProcessPtr->nFinal() == 2)) {
55  selBias = 1.0 / sigma(phaseSpacePtr->pTHat());
56  return selBias;
57  }
58  selBias = 1.;
59  return selBias;
60  }
61 
62 private:
63  std::vector<double> p;
64  std::function<double(double)> sigma;
65 };
66 
67 class RapReweightUserHook : public Pythia8::UserHooks {
68 public:
69  RapReweightUserHook(const std::string& _yLabsigma_func,
70  double _yLab_power,
71  const std::string& _yCMsigma_func,
72  double _yCM_power,
73  double _pTHatMin,
74  double _pTHatMax)
75  : yLabsigma_func(_yLabsigma_func),
76  yCMsigma_func(_yCMsigma_func),
77  yLab_power(_yLab_power),
78  yCM_power(_yCM_power),
79  pTHatMin(_pTHatMin),
80  pTHatMax(_pTHatMax) {
81  // empirical parametrizations defined in configuration file
82  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
83  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
84  }
85  ~RapReweightUserHook() override {}
86 
87  bool canBiasSelection() override { return true; }
88 
89  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
90  const Pythia8::PhaseSpace* phaseSpacePtr,
91  bool inEvent) override {
92  //the variable selBias of the base class should be used;
93  if ((sigmaProcessPtr->nFinal() == 2)) {
94  double x1 = phaseSpacePtr->x1();
95  double x2 = phaseSpacePtr->x2();
96  double yLab = 0.5 * log(x1 / x2);
97  double yCM = 0.5 * log(phaseSpacePtr->tHat() / phaseSpacePtr->uHat());
98  double pTHat = phaseSpacePtr->pTHat();
99  double sigmaLab = yLabsigma.Eval(pTHat);
100  double sigmaCM = yCMsigma.Eval(pTHat);
101  // empirical reweighting function
102  selBias = exp(pow(fabs(yLab), yLab_power) / (2 * sigmaLab * sigmaLab) +
103  pow(fabs(yCM), yCM_power) / (2 * sigmaCM * sigmaCM));
104  return selBias;
105  }
106  selBias = 1.;
107  return selBias;
108  }
109 
110 private:
114 };
115 
116 class PtHatRapReweightUserHook : public Pythia8::UserHooks {
117 public:
118  PtHatRapReweightUserHook(const std::string& _yLabsigma_func,
119  double _yLab_power,
120  const std::string& _yCMsigma_func,
121  double _yCM_power,
122  double _pTHatMin,
123  double _pTHatMax,
124  double _pt = 15,
125  double _power = 4.5)
126  : yLabsigma_func(_yLabsigma_func),
127  yCMsigma_func(_yCMsigma_func),
128  yLab_power(_yLab_power),
129  yCM_power(_yCM_power),
130  pTHatMin(_pTHatMin),
131  pTHatMax(_pTHatMax),
132  pt(_pt),
133  power(_power) {
134  // empirical parametrizations defined in configuration file
135  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
136  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
137  }
139 
140  bool canBiasSelection() override { return true; }
141 
142  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
143  const Pythia8::PhaseSpace* phaseSpacePtr,
144  bool inEvent) override {
145  //the variable selBias of the base class should be used;
146  if ((sigmaProcessPtr->nFinal() == 2)) {
147  double x1 = phaseSpacePtr->x1();
148  double x2 = phaseSpacePtr->x2();
149  double yLab = 0.5 * log(x1 / x2);
150  double yCM = 0.5 * log(phaseSpacePtr->tHat() / phaseSpacePtr->uHat());
151  double pTHat = phaseSpacePtr->pTHat();
152  double sigmaLab = yLabsigma.Eval(pTHat);
153  double sigmaCM = yCMsigma.Eval(pTHat);
154  // empirical reweighting function
155  selBias = pow(pTHat / pt, power) * exp(pow(fabs(yLab), yLab_power) / (2 * sigmaLab * sigmaLab) +
156  pow(fabs(yCM), yCM_power) / (2 * sigmaCM * sigmaCM));
157  return selBias;
158  }
159  selBias = 1.;
160  return selBias;
161  }
162 
163 private:
167 };
bool canBiasSelection() override
PtHatRapReweightUserHook(const std::string &_yLabsigma_func, double _yLab_power, const std::string &_yCMsigma_func, double _yCM_power, double _pTHatMin, double _pTHatMax, double _pt=15, double _power=4.5)
double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent) override
std::function< double(double)> sigma
PtHatReweightUserHook(double _pt=15, double _power=4.5)
~PtHatReweightUserHook() override
std::vector< double > p
bool canBiasSelection() override
bool canBiasSelection() override
~RapReweightUserHook() override
double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent) override
RapReweightUserHook(const std::string &_yLabsigma_func, double _yLab_power, const std::string &_yCMsigma_func, double _yCM_power, double _pTHatMin, double _pTHatMax)
double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent) override
double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent) override
bool canBiasSelection() override
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
PtHatEmpReweightUserHook(const std::string &tuneName="")