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  virtual ~PtHatReweightUserHook() {}
10 
11  virtual bool canBiasSelection() { return true; }
12 
13  virtual double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
14  const Pythia8::PhaseSpace* phaseSpacePtr, bool inEvent)
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:
33  {
34  p = {5.3571961909810e+13,1.0907678218282e+01,-2.5898069229451e+00,-5.1575514014931e-01,5.5951279807561e-02,3.5e+02};
35  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; };
36  }
38 
39  virtual bool canBiasSelection() { return true; }
40 
41  virtual double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
42  const Pythia8::PhaseSpace* phaseSpacePtr, bool inEvent)
43  {
44  //the variable selBias of the base class should be used;
45  if ((sigmaProcessPtr->nFinal() == 2)) {
46  selBias = 1.0/sigma(phaseSpacePtr->pTHat());
47  return selBias;
48  }
49  selBias = 1.;
50  return selBias;
51  }
52 
53  private:
54  std::vector<double> p;
55  std::function<double(double)> sigma;
56 };
57 
58 class RapReweightUserHook : public Pythia8::UserHooks
59 {
60  public:
61  RapReweightUserHook(const std::string& _yLabsigma_func, double _yLab_power,
62  const std::string& _yCMsigma_func, double _yCM_power,
63  double _pTHatMin, double _pTHatMax) :
64  yLabsigma_func(_yLabsigma_func), yCMsigma_func(_yCMsigma_func),
65  yLab_power(_yLab_power), yCM_power(_yCM_power),
66  pTHatMin(_pTHatMin), pTHatMax(_pTHatMax)
67  {
68  // empirical parametrizations defined in configuration file
69  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
70  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
71  }
72  virtual ~RapReweightUserHook() {}
73 
74  virtual bool canBiasSelection() { return true; }
75 
76  virtual double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
77  const Pythia8::PhaseSpace* phaseSpacePtr, bool inEvent)
78  {
79  //the variable selBias of the base class should be used;
80  if ((sigmaProcessPtr->nFinal() == 2)) {
81  double x1 = phaseSpacePtr->x1();
82  double x2 = phaseSpacePtr->x2();
83  double yLab = 0.5*log(x1/x2);
84  double yCM = 0.5*log( phaseSpacePtr->tHat() / phaseSpacePtr->uHat() );
85  double pTHat = phaseSpacePtr->pTHat();
86  double sigmaLab = yLabsigma.Eval(pTHat);
87  double sigmaCM = yCMsigma.Eval(pTHat);
88  // empirical reweighting function
89  selBias = exp( pow(fabs(yLab),yLab_power)/(2*sigmaLab*sigmaLab) +
90  pow(fabs(yCM),yCM_power)/(2*sigmaCM*sigmaCM) );
91  return selBias;
92  }
93  selBias = 1.;
94  return selBias;
95  }
96 
97  private:
98  std::string yLabsigma_func, yCMsigma_func;
99  double yLab_power, yCM_power, pTHatMin, pTHatMax;
100  TF1 yLabsigma, yCMsigma;
101 };
102 
103 
104 class PtHatRapReweightUserHook : public Pythia8::UserHooks
105 {
106  public:
107  PtHatRapReweightUserHook(const std::string& _yLabsigma_func, double _yLab_power,
108  const std::string& _yCMsigma_func, double _yCM_power,
109  double _pTHatMin, double _pTHatMax,
110  double _pt = 15, double _power = 4.5) :
111  yLabsigma_func(_yLabsigma_func), yCMsigma_func(_yCMsigma_func),
112  yLab_power(_yLab_power), yCM_power(_yCM_power),
113  pTHatMin(_pTHatMin), pTHatMax(_pTHatMax), pt(_pt), power(_power)
114  {
115  // empirical parametrizations defined in configuration file
116  yLabsigma = TF1("yLabsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
117  yCMsigma = TF1("yCMsigma", yLabsigma_func.c_str(), pTHatMin, pTHatMax);
118  }
120 
121  virtual bool canBiasSelection() { return true; }
122 
123  virtual double biasSelectionBy(const Pythia8::SigmaProcess* sigmaProcessPtr,
124  const Pythia8::PhaseSpace* phaseSpacePtr, bool inEvent)
125  {
126  //the variable selBias of the base class should be used;
127  if ((sigmaProcessPtr->nFinal() == 2)) {
128  double x1 = phaseSpacePtr->x1();
129  double x2 = phaseSpacePtr->x2();
130  double yLab = 0.5*log(x1/x2);
131  double yCM = 0.5*log( phaseSpacePtr->tHat() / phaseSpacePtr->uHat() );
132  double pTHat = phaseSpacePtr->pTHat();
133  double sigmaLab = yLabsigma.Eval(pTHat);
134  double sigmaCM = yCMsigma.Eval(pTHat);
135  // empirical reweighting function
136  selBias = pow(pTHat / pt, power) * exp( pow(fabs(yLab),yLab_power)/(2*sigmaLab*sigmaLab) +
137  pow(fabs(yCM),yCM_power)/(2*sigmaCM*sigmaCM) );
138  return selBias;
139  }
140  selBias = 1.;
141  return selBias;
142  }
143 
144  private:
145  std::string yLabsigma_func, yCMsigma_func;
146  double yLab_power, yCM_power, pTHatMin, pTHatMax, pt, power;
147  TF1 yLabsigma, yCMsigma;
148 };
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)
virtual double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent)
virtual ~PtHatReweightUserHook()
std::function< double(double)> sigma
virtual bool canBiasSelection()
PtHatReweightUserHook(double _pt=15, double _power=4.5)
virtual double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent)
std::vector< double > p
std::string yLabsigma_func
virtual ~RapReweightUserHook()
virtual bool canBiasSelection()
RapReweightUserHook(const std::string &_yLabsigma_func, double _yLab_power, const std::string &_yCMsigma_func, double _yCM_power, double _pTHatMin, double _pTHatMax)
virtual double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent)
virtual bool canBiasSelection()
virtual double biasSelectionBy(const Pythia8::SigmaProcess *sigmaProcessPtr, const Pythia8::PhaseSpace *phaseSpacePtr, bool inEvent)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40