Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
AMSContourExtractor.cpp
Go to the documentation of this file.
2
3#include <cmath>
4#include <exception>
5#include <iostream>
6
8 Contour c;
9 c.level = cr.level;
10 c.success = false;
11
12 try {
13 const std::size_t safe_resolution = std::max<std::size_t>(2, cr.resolution);
14 std::size_t depth = static_cast<std::size_t>(
15 std::ceil(std::log2(static_cast<double>(safe_resolution)))
16 );
17
18 depth = std::min<std::size_t>(depth, 8);
19
20 MarchingSquaresExtractor mse(field, cr.bounds, depth);
21 c.paths = mse.find_iso_contour(cr.level);
22
23 // Empty paths mean AMS did not find a contour. Let WithFallback try MINUIT.
24 c.success = !c.paths.empty();
25 } catch (const std::exception& e) {
26 std::cout << "[AMS] extraction failed: " << e.what() << std::endl;
27 c.paths.clear();
28 c.success = false;
29 return c;
30 } catch (...) {
31 std::cout << "[AMS] extraction failed with unknown exception" << std::endl;
32 c.paths.clear();
33 c.success = false;
34 return c;
35 }
36
37 if (on_progress_) {
38 std::size_t path_id = 0;
39 for (const auto& path : c.paths) {
40 std::size_t point_id = 0;
41
42 for (const auto& pt : path) {
45 ev.level = c.level;
46 ev.path_id = path_id;
47 ev.point_id = point_id++;
48 ev.x = pt.first;
49 ev.y = pt.second;
50 on_progress_(ev);
51 }
52
55 ev.level = c.level;
56 ev.path_id = path_id;
57 ev.n_points = path.size();
58 on_progress_(ev);
59
60 ++path_id;
61 }
62 }
63
64 return c;
65}
Adaptive marching-squares contour extractor.
@ PathPoint
A new point on a contour path is available.
@ PathFinished
A contour path has been completed.
Contour extract(const ScalarField2D &field, const ContourRequest &cr) override
Extracts contour paths from a scalar field.
std::set< Path > find_iso_contour(double lvl)
Definition contour.cpp:14
std::function< double(double, double)> ScalarField2D
Definition contour.h:17
Payload passed to contour progress callbacks.
std::size_t n_points
Number of points produced so far or in total.
double level
Contour level associated with the event.
std::size_t path_id
Index of the contour path being reported.
ContourProgressEventType type
Event category.
double x
X coordinate of a reported contour point.
double y
Y coordinate of a reported contour point.
std::size_t point_id
Index of the point within the current path.
Input configuration for a two-dimensional contour extraction.
std::size_t resolution
Requested grid or sampling resolution.
std::array< double, 4 > bounds
Extraction domain as {xmin, xmax, ymin, ymax}.
double level
Target scalar-field level to extract.
Output of a contour extraction algorithm.
bool success
Whether extraction produced a valid contour.
std::set< Path > paths
Extracted contour paths.
double level
Level actually targeted by the extraction.