MoMEMta.h
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 #pragma once
21 
22 #include <memory>
23 #include <vector>
24 
25 #include <momemta/Module.h>
26 #include <momemta/ParameterSet.h>
27 #include <momemta/Particle.h>
28 #include <momemta/Pool.h>
29 #include <momemta/Types.h>
30 
31 class Configuration;
32 class SharedLibrary;
33 
34 namespace momemta {
35 class ComputationGraph;
36 }
37 
44 class MoMEMta {
45  public:
47  enum class IntegrationStatus {
48  SUCCESS,
49  ACCURACY_NOT_REACHED,
50  FAILED,
51  ABORTED,
52  DIM_OUT_OF_RANGE,
53  NONE
54  };
55 
62  MoMEMta(const Configuration& configuration);
64  virtual ~MoMEMta();
65 
75  std::vector<std::pair<double, double>> computeWeights(const std::vector<momemta::Particle>& particles,
76  const LorentzVector& met=LorentzVector());
77 
85  void setEvent(const std::vector<momemta::Particle>& particles, const LorentzVector& met=LorentzVector());
86 
97  std::vector<double> evaluateIntegrand(const std::vector<double>& psPoints);
98 
103  IntegrationStatus getIntegrationStatus() const;
104 
112  const Pool& getPool() const;
113 
114  private:
115  class integrands_output_error: public std::runtime_error {
116  using std::runtime_error::runtime_error;
117  };
118  class cuba_configuration_error: public std::runtime_error {
119  using std::runtime_error::runtime_error;
120  };
121  class unphysical_lorentzvector_error: public std::exception {
122  public:
123  unphysical_lorentzvector_error(const LorentzVector& p4);
124  virtual const char* what() const noexcept override;
125  private:
126  std::string _what;
127  };
128  class invalid_inputs: public std::runtime_error {
129  using std::runtime_error::runtime_error;
130  };
131  class integrands_nonfinite_error: public std::runtime_error {
132  using std::runtime_error::runtime_error;
133  };
134 
142  void checkIfPhysical(const LorentzVector& p4);
143 
147  void initPool(const Configuration& configuration);
148 
149  int integrand(const double* psPoints, double* results, const double* weights=nullptr);
150 
151  static int CUBAIntegrand(const int *nDim, const double* psPoint, const int *nComp, double *value, void *inputs, const int *nVec, const int *core);
152  static int CUBAIntegrandWeighted(const int *nDim, const double* psPoint, const int *nComp, double *value, void *inputs, const int *nVec, const int *core, const double *weight);
153  static void cuba_logging(const char*);
154 
155  PoolPtr m_pool;
156  std::shared_ptr<momemta::ComputationGraph> m_computation_graph;
157 
158  using SharedLibraryPtr = std::shared_ptr<SharedLibrary>;
159  std::vector<SharedLibraryPtr> m_libraries;
160 
161  std::size_t m_n_dimensions;
162  std::size_t m_n_components;
163  ParameterSet m_cuba_configuration;
164 
165  IntegrationStatus integration_status = IntegrationStatus::NONE;
166 
167  // Pool inputs
168  std::shared_ptr<std::vector<double>> m_ps_points;
169  std::shared_ptr<double> m_ps_weight;
170 
171  std::unordered_map<std::string, std::shared_ptr<LorentzVector>> m_inputs_p4;
172  std::unordered_map<std::string, std::shared_ptr<int64_t>> m_inputs_type;
173  std::shared_ptr<LorentzVector> m_met;
174  std::vector<Value<double>> m_integrands;
175 };
A MoMEMta instance.
Definition: MoMEMta.h:44
Definition: Graph.h:21
A class encapsulating a lua table.
Definition: ParameterSet.h:82
Definition: Pool.h:40
A frozen snapshot of the configuration file.
Definition: Configuration.h:36
IntegrationStatus
Status of the integration.
Definition: MoMEMta.h:47