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 
82  IntegrationStatus getIntegrationStatus() const;
83 
91  const Pool& getPool() const;
92 
93  private:
94  class integrands_output_error: public std::runtime_error {
95  using std::runtime_error::runtime_error;
96  };
97  class cuba_configuration_error: public std::runtime_error {
98  using std::runtime_error::runtime_error;
99  };
100  class unphysical_lorentzvector_error: public std::exception {
101  public:
102  unphysical_lorentzvector_error(const LorentzVector& p4);
103  virtual const char* what() const noexcept override;
104  private:
105  std::string _what;
106  };
107  class invalid_inputs: public std::runtime_error {
108  using std::runtime_error::runtime_error;
109  };
110  class integrands_nonfinite_error: public std::runtime_error {
111  using std::runtime_error::runtime_error;
112  };
113 
121  void checkIfPhysical(const LorentzVector& p4);
122 
126  void initPool(const Configuration& configuration);
127 
128  int integrand(const double* psPoints, double* results, const double* weights);
129 
130  static int CUBAIntegrand(const int *nDim, const double* psPoint, const int *nComp, double *value, void *inputs, const int *nVec, const int *core);
131  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);
132  static void cuba_logging(const char*);
133 
134  PoolPtr m_pool;
135  std::shared_ptr<momemta::ComputationGraph> m_computation_graph;
136 
137  using SharedLibraryPtr = std::shared_ptr<SharedLibrary>;
138  std::vector<SharedLibraryPtr> m_libraries;
139 
140  std::size_t m_n_dimensions;
141  std::size_t m_n_components;
142  ParameterSet m_cuba_configuration;
143 
144  IntegrationStatus integration_status = IntegrationStatus::NONE;
145 
146  // Pool inputs
147  std::shared_ptr<std::vector<double>> m_ps_points;
148  std::shared_ptr<double> m_ps_weight;
149 
150  std::unordered_map<std::string, std::shared_ptr<LorentzVector>> m_inputs_p4;
151  std::unordered_map<std::string, std::shared_ptr<int64_t>> m_inputs_type;
152  std::shared_ptr<LorentzVector> m_met;
153  std::vector<Value<double>> m_integrands;
154 };
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