UniformGenerator.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 
50 #include <momemta/ParameterSet.h>
51 #include <momemta/Module.h>
52 
53 class UniformGenerator: public Module {
54  public:
55 
56  UniformGenerator(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()),
57  m_min(parameters.get<double>("min")),
58  m_max(parameters.get<double>("max")) {
59 
60  m_ps_point = get<double>(parameters.get<InputTag>("ps_point"));
61  };
62 
63  virtual Status work() override {
64  double psPoint = *m_ps_point;
65  *output = m_min + (m_max - m_min) * psPoint;
66  *jacobian = m_max - m_min;
67 
68  return Status::OK;
69  }
70 
71  private:
72  const double m_min, m_max;
73 
74  // Inputs
75  Value<double> m_ps_point;
76 
77  // Outputs
78  std::shared_ptr<double> output = produce<double>("output");
79  std::shared_ptr<double> jacobian = produce<double>("jacobian");
80 
81 
82 };
83 
84 REGISTER_MODULE(UniformGenerator)
85  .Input("ps_point")
86  .Output("output")
87  .Output("jacobian")
88  .Attr("min:double")
89  .Attr("max:double");
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
Generate a random point uniformly in a user-set range.
virtual Status work() override
Main function.
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61