FlatTransferFunctionOnP.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 #include <momemta/ParameterSet.h>
20 #include <momemta/Module.h>
21 #include <momemta/Types.h>
22 #include <momemta/Math.h>
23 
64  public:
65 
66  FlatTransferFunctionOnP(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()) {
67  m_ps_point = get<double>(parameters.get<InputTag>("ps_point"));
68  m_input = get<LorentzVector>(parameters.get<InputTag>("reco_particle"));
69 
70  m_PMin = parameters.get<double>("min");
71  m_PMax = parameters.get<double>("max");
72  };
73 
74  virtual Status work() override {
75 
76  const double& ps_point = *m_ps_point;
77  const LorentzVector& reco_particle = *m_input;
78 
79  const double range = m_PMax - m_PMin;
80  const double gen_P = m_PMin + range*ps_point;
81 
82  // To change the particle's |P| without changing its direction and mass:
83  double gen_E = sqrt(SQ(gen_P) + SQ(reco_particle.M()));
84  output->SetCoordinates(
85  gen_P * std::sin(reco_particle.Theta()) * std::cos(reco_particle.Phi()),
86  gen_P * std::sin(reco_particle.Theta()) * std::sin(reco_particle.Phi()),
87  gen_P * std::cos(reco_particle.Theta()),
88  gen_E);
89 
90  // Compute TF*jacobian, ie the jacobian of the transformation of [0,1]->[range_min,range_max]
91  *TF_times_jacobian = range;
92 
93  return Status::OK;
94  }
95 
96  private:
97 
98  double m_PMin, m_PMax;
99 
100  // Inputs
101  Value<double> m_ps_point;
102  Value<LorentzVector> m_input;
103 
104  // Outputs
105  std::shared_ptr<LorentzVector> output = produce<LorentzVector>("output");
106  std::shared_ptr<double> TF_times_jacobian = produce<double>("TF_times_jacobian");
107 };
108 
109 REGISTER_MODULE(FlatTransferFunctionOnP)
110  .Input("ps_point")
111  .Input("reco_particle")
112  .Output("output")
113  .Output("TF_times_jacobian")
114  .Attr("min:double")
115  .Attr("max:double");
Mathematical functions.
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
Flat transfer function on |P| (mainly for testing purposes).
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61
virtual Status work() override
Main function.