gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
ImageLimit.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
14 
15 
17 
18 
19 
20 namespace Gambit {
21  namespace ColliderBit {
22 
23  data_type ImageLimit::get_image(std::string name) {
24  std::fstream in(name);
25  std::string line;
27  int line_number = 0;
28 
29  while (std::getline(in, line)) {
30  double value;
31  std::stringstream ss(line);
32 
33  data.push_back(std::vector<double>());
34 
35  while (ss >> value) {
36  data[line_number].push_back(value);
37  }
38  ++line_number;
39  }
40  return data;
41  }
42 
43  double ImageLimit::get_limit(double x, double y) {
44  // Look-up nearest neighbour by index. The conversion factors
45  // originate from the size of the grid divided by the
46  // masses that the grid spans
47 
48  const double unit_x = (x - extent[0]) / (extent[1] - extent[0]);
49  const int index_x = std::round((image_data[0].size() - 1) * unit_x);
50 
51  const double unit_y = (y - extent[2]) / (extent[3] - extent[2]);
52  const int index_y = std::round((image_data.size() - 1) * unit_y);
53 
54  // Retrive limit from data
55 
56  try {
57  return image_data.at(index_y).at(index_x);
58  } catch (const std::out_of_range& e) {
59  return limit_outside_grid;
60  }
61  }
62 
63  ImageLimit::ImageLimit(std::string name,
64  double x_min, double x_max,
65  double y_min, double y_max) {
66  image_data = get_image(name);
67  extent = {x_min, x_max, y_min, y_max};
68  }
69 
70  } // namespace ColliderBit
71 } // namespace Gambit
Read a limit from an image, represented by a grid of values at every pixel.
greatScanData data
Definition: great.cpp:38
std::vector< std::vector< double > > data_type
Definition: ImageLimit.hpp:33
data_type get_image(std::string name)
Definition: ImageLimit.cpp:23
double get_limit(double x, double y)
Definition: ImageLimit.cpp:43
ImageLimit(std::string name, double x_min, double x_max, double y_min, double y_max)
Definition: ImageLimit.cpp:63
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::vector< double > extent
Definition: ImageLimit.hpp:47