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" || tuneName == "CP5Run3")
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  const double ecms = (tuneName == "CP5Run3" ? 13600. : 13000.);
41  sigma = [this, ecms](double x) -> double {
42  return (p[0] * pow(x, p[2] + p[3] * log(0.01 * x) + p[4] * pow(log(0.01 * x), 2)) *
43  pow(1 - 2 * x / (ecms + p[5]), p[1])) *
44  x;
45  };
46  }
48 
49  bool canBiasSelection() override { return true; }
50 
51  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
52  const Pythia8::PhaseSpace* phaseSpacePtr,
53  bool inEvent) override {
54  //the variable selBias of the base class should be used;
55  if ((sigmaProcessPtr->nFinal() == 2)) {
56  selBias = 1.0 / sigma(phaseSpacePtr->pTHat());
57  return selBias;
58  }
59  selBias = 1.;
60  return selBias;
61  }
62 
63 private:
64  std::vector<double> p;
65  std::function<double(double)> sigma;
66 };
67 
68 class RapReweightUserHook : public Pythia8::UserHooks {
69 public:
70  RapReweightUserHook(const std::string& _yLabsigma_func,
71  double _yLab_power,
72  const std::string& _yCMsigma_func,
73  double _yCM_power,
74  double _pTHatMin,
75  double _pTHatMax)
76  : yLabsigma_func(_yLabsigma_func),
77  yCMsigma_func(_yCMsigma_func),
78  yLab_power(_yLab_power),
79  yCM_power(_yCM_power),
80  pTHatMin(_pTHatMin),
81  pTHatMax(_pTHatMax) {
82  // empirical parametrizations defined in configuration file
83  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
84  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
85  }
86  ~RapReweightUserHook() override {}
87 
88  bool canBiasSelection() override { return true; }
89 
90  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
91  const Pythia8::PhaseSpace* phaseSpacePtr,
92  bool inEvent) override {
93  //the variable selBias of the base class should be used;
94  if ((sigmaProcessPtr->nFinal() == 2)) {
95  double x1 = phaseSpacePtr->x1();
96  double x2 = phaseSpacePtr->x2();
97  double yLab = 0.5 * log(x1 / x2);
98  double yCM = 0.5 * log(phaseSpacePtr->tHat() / phaseSpacePtr->uHat());
99  double pTHat = phaseSpacePtr->pTHat();
100  double sigmaLab = yLabsigma.Eval(pTHat);
101  double sigmaCM = yCMsigma.Eval(pTHat);
102  // empirical reweighting function
103  selBias = exp(pow(fabs(yLab), yLab_power) / (2 * sigmaLab * sigmaLab) +
104  pow(fabs(yCM), yCM_power) / (2 * sigmaCM * sigmaCM));
105  return selBias;
106  }
107  selBias = 1.;
108  return selBias;
109  }
110 
111 private:
115 };
116 
117 class PtHatRapReweightUserHook : public Pythia8::UserHooks {
118 public:
119  PtHatRapReweightUserHook(const std::string& _yLabsigma_func,
120  double _yLab_power,
121  const std::string& _yCMsigma_func,
122  double _yCM_power,
123  double _pTHatMin,
124  double _pTHatMax,
125  double _pt = 15,
126  double _power = 4.5)
127  : yLabsigma_func(_yLabsigma_func),
128  yCMsigma_func(_yCMsigma_func),
129  yLab_power(_yLab_power),
130  yCM_power(_yCM_power),
131  pTHatMin(_pTHatMin),
132  pTHatMax(_pTHatMax),
133  pt(_pt),
134  power(_power) {
135  // empirical parametrizations defined in configuration file
136  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
137  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
138  }
140 
141  bool canBiasSelection() override { return true; }
142 
143  double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
144  const Pythia8::PhaseSpace* phaseSpacePtr,
145  bool inEvent) override {
146  //the variable selBias of the base class should be used;
147  if ((sigmaProcessPtr->nFinal() == 2)) {
148  double x1 = phaseSpacePtr->x1();
149  double x2 = phaseSpacePtr->x2();
150  double yLab = 0.5 * log(x1 / x2);
151  double yCM = 0.5 * log(phaseSpacePtr->tHat() / phaseSpacePtr->uHat());
152  double pTHat = phaseSpacePtr->pTHat();
153  double sigmaLab = yLabsigma.Eval(pTHat);
154  double sigmaCM = yCMsigma.Eval(pTHat);
155  // empirical reweighting function
156  selBias = pow(pTHat / pt, power) * exp(pow(fabs(yLab), yLab_power) / (2 * sigmaLab * sigmaLab) +
157  pow(fabs(yCM), yCM_power) / (2 * sigmaCM * sigmaCM));
158  return selBias;
159  }
160  selBias = 1.;
161  return selBias;
162  }
163 
164 private:
168 };
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="")