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