GaussianTransferFunctionOnEnergy.cc
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #include <momemta/Logging.h>
21 #include <momemta/Module.h>
22 #include <momemta/ParameterSet.h>
23 #include <momemta/Types.h>
24 #include <momemta/Math.h>
25 
26 #include <Math/DistFunc.h>
27 
36  public:
37 
38  GaussianTransferFunctionOnEnergyBase(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()) {
39  m_reco_input = get<LorentzVector>(parameters.get<InputTag>("reco_particle"));
40 
41  m_sigma = parameters.get<double>("sigma", 0.10);
42  m_sigma_range = parameters.get<double>("sigma_range", 5);
43  m_min_E = parameters.get<double>("min_E", 0.);
44  }
45 
46  protected:
47  double m_min_E;
48  double m_sigma;
49  double m_sigma_range;
50 
51  // Input
52  Value<LorentzVector> m_reco_input;
53 };
54 
96  public:
97  GaussianTransferFunctionOnEnergy(PoolPtr pool, const ParameterSet& parameters): GaussianTransferFunctionOnEnergyBase(pool, parameters) {
98  m_ps_point = get<double>(parameters.get<InputTag>("ps_point"));
99  }
100 
101  virtual Status work() override {
102  // Estimate the width over which to integrate using the width of the TF at E_rec ...
103  const double sigma_E_rec = m_reco_input->E() * m_sigma;
104 
105  double range_min = std::max( { m_min_E, m_reco_input->M(), m_reco_input->E() - (m_sigma_range * sigma_E_rec) } );
106  double range_max = m_reco_input->E() + (m_sigma_range * sigma_E_rec);
107  double range = (range_max - range_min);
108 
109  double gen_E = range_min + range * (*m_ps_point);
110  double gen_pt = std::sqrt(SQ(gen_E) - SQ(m_reco_input->M())) / std::cosh(m_reco_input->Eta());
111 
112  output->SetCoordinates(
113  gen_pt * std::cos(m_reco_input->Phi()),
114  gen_pt * std::sin(m_reco_input->Phi()),
115  gen_pt * std::sinh(m_reco_input->Eta()),
116  gen_E);
117 
118  // ... but compute the width of the TF at E_gen!
119  const double sigma_E_gen = gen_E * m_sigma;
120 
121  // Compute TF*jacobian, where the jacobian includes the transformation of [0,1]->[range_min,range_max] and d|P|/dE
122  *TF_times_jacobian = ROOT::Math::normal_pdf(gen_E, sigma_E_gen, m_reco_input->E()) * range * dP_over_dE(*output);
123 
124  return Status::OK;
125  }
126 
127  private:
128  // Input
129  Value<double> m_ps_point;
130 
131  // Outputs
132  std::shared_ptr<LorentzVector> output = produce<LorentzVector>("output");
133  std::shared_ptr<double> TF_times_jacobian = produce<double>("TF_times_jacobian");
134 
135 };
136 
171  public:
172  GaussianTransferFunctionOnEnergyEvaluator(PoolPtr pool, const ParameterSet& parameters): GaussianTransferFunctionOnEnergyBase(pool, parameters) {
173  m_gen_input = get<LorentzVector>(parameters.get<InputTag>("gen_particle"));
174  }
175 
176  virtual Status work() override {
177  // Compute TF value
178  *TF_value = ROOT::Math::normal_pdf(m_gen_input->E(), m_gen_input->E() * m_sigma, m_reco_input->E());
179 
180  return Status::OK;
181  }
182 
183  private:
184  // Input
185  Value<LorentzVector> m_gen_input;
186 
187  // Outputs
188  std::shared_ptr<double> TF_value = produce<double>("TF");
189 
190 };
191 
192 REGISTER_MODULE(GaussianTransferFunctionOnEnergy)
193  .Input("ps_point")
194  .Input("reco_particle")
195  .Output("output")
196  .Output("TF_times_jacobian")
197  .Attr("sigma:double=0.10")
198  .Attr("sigma_range:double=5")
199  .Attr("min_E:double=0");
200 
202  .Input("gen_particle")
203  .Input("reco_particle")
204  .Output("TF")
205  .Attr("sigma:double=0.10")
206  .Attr("sigma_range:double=5")
207  .Attr("min_E:double=0");
Mathematical functions.
Helper class for Gaussian transfer function modules.
virtual Status work() override
Main function.
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
Parent class for all the modules.
Definition: Module.h:37
A class encapsulating a lua table.
Definition: ParameterSet.h:82
#define SQ(x)
Compute .
Definition: Math.h:25
double dP_over_dE(const T &v)
Compute .
Definition: Math.h:53
Evaluate a transfer function on energy described by a Gaussian distribution.
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61
Integrate over a transfer function on energy described by a Gaussian distribution.