MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
BeamFit2D.hpp
Go to the documentation of this file.
1#ifndef BEAM_FIT_2D_HPP
2#define BEAM_FIT_2D_HPP
3
4#include <Rtypes.h>
5#include <TH1F.h>
6#include <TH2F.h>
7#include <TString.h>
8#include <algorithm>
9#include <cmath>
10#include <utility>
11#include <vector>
12
19struct BeamFit2D {
20 Double_t amp = 0;
21 Double_t mu_x = 0, mu_y = 0;
22 Double_t sigma_x = 0, sigma_y = 0;
23 Double_t rho = 0;
24 Bool_t ok = kFALSE;
25};
26
33struct Moments2D {
34 Double_t mu_x = 0, mu_y = 0;
35 Double_t sigma_x = 0, sigma_y = 0;
36 Double_t rho = 0;
37 Double_t weight = 0;
39};
40
43public:
53 static Bool_t InEllipseXY(const BeamFit2D &b, Double_t x, Double_t y,
54 Double_t n);
55
67 static void DrawEllipse(const BeamFit2D &b, Double_t n, Color_t color);
68
82 static Moments2D ComputeMoments(TH2F *h, Int_t lo_bx, Int_t hi_bx,
83 Int_t lo_by, Int_t hi_by, Double_t thresh,
84 Double_t bw_x, Double_t bw_y);
85
101 static Moments2D
102 ClippedMoments(const std::vector<std::pair<Float_t, Float_t>> &pts,
103 const Moments2D &seed, Double_t clip = 3.0);
104
113 static Moments2D SeedSpotMoments(TH2F *h, Int_t seed_half_bins);
114
119 struct SpotFit {
121 Double_t chi2_ndf = -1.0;
123 Bool_t fit_used = kFALSE;
124 };
125
138 static SpotFit
139 FitSpotFromPoints(TH2F *h, std::vector<std::pair<Float_t, Float_t>> &pts,
140 const Moments2D &seed);
141
154 static BeamFit2D FitSpot(TH2F *h, const Moments2D &seed,
155 Double_t window_nsigma = 2.0,
156 Double_t *chi2_ndf = nullptr);
157
176 static Bool_t FitPeak(TH1F *h, Double_t seed_mu, Double_t seed_sigma,
177 Double_t window_nsigma, Bool_t fix_mu, Double_t &mu,
178 Double_t &sigma, Double_t *chi2_ndf = nullptr);
179};
180
181#endif
Helpers for the 2-D beam-spot description.
Definition BeamFit2D.hpp:42
static BeamFit2D FitSpot(TH2F *h, const Moments2D &seed, Double_t window_nsigma=2.0, Double_t *chi2_ndf=nullptr)
Fit a correlated 2-D Gaussian on a flat pedestal to h: ROOT's bigaus written out, Poisson likelihood,...
static SpotFit FitSpotFromPoints(TH2F *h, std::vector< std::pair< Float_t, Float_t > > &pts, const Moments2D &seed)
A beam spot from a coarse histogram and the same events unbinned: the sample's sigma-clipped moments ...
static Bool_t FitPeak(TH1F *h, Double_t seed_mu, Double_t seed_sigma, Double_t window_nsigma, Bool_t fix_mu, Double_t &mu, Double_t &sigma, Double_t *chi2_ndf=nullptr)
The 1-D counterpart: a Gaussian on a flat pedestal, fitted over window_nsigma of the seed and judged ...
static void DrawEllipse(const BeamFit2D &b, Double_t n, Color_t color)
Draw the n-sigma contour of a fitted spot on the current pad.
Definition BeamFit2D.cpp:24
static Bool_t InEllipseXY(const BeamFit2D &b, Double_t x, Double_t y, Double_t n)
Whether a point lies inside the fitted ellipse at n sigma: the correlation-aware Mahalanobis chi2 bel...
Definition BeamFit2D.cpp:9
static Moments2D ComputeMoments(TH2F *h, Int_t lo_bx, Int_t hi_bx, Int_t lo_by, Int_t hi_by, Double_t thresh, Double_t bw_x, Double_t bw_y)
Second moments of a histogram region above a threshold.
Definition BeamFit2D.cpp:42
static Moments2D SeedSpotMoments(TH2F *h, Int_t seed_half_bins)
Second moments of a coarse spot histogram's seed window: the maximum bin, ± seed_half_bins around it,...
static Moments2D ClippedMoments(const std::vector< std::pair< Float_t, Float_t > > &pts, const Moments2D &seed, Double_t clip=3.0)
Sigma-clipped centroid and covariance of a point sample, the 2-D counterpart of the strip-width clip:...
Definition BeamFit2D.cpp:94
A fitted 2-D Gaussian beam spot.
Definition BeamFit2D.hpp:19
Double_t rho
Correlation coefficient, in [-1, 1].
Definition BeamFit2D.hpp:23
Double_t sigma_y
Widths along each axis.
Definition BeamFit2D.hpp:22
Double_t mu_x
Definition BeamFit2D.hpp:21
Double_t amp
Peak amplitude.
Definition BeamFit2D.hpp:20
Double_t mu_y
Centroid.
Definition BeamFit2D.hpp:21
Bool_t ok
Whether the fit converged.
Definition BeamFit2D.hpp:24
Double_t sigma_x
Definition BeamFit2D.hpp:22
Result of a beam spot fit: the spot to use, and whether the Gaussian fit (rather than the clipped-mom...
Double_t chi2_ndf
The fit's reduced chi2; -1 when it did not run.
Bool_t fit_used
kTRUE when fit is the fit, not the fallback.
BeamFit2D fit
The spot to use; ok when usable.
Second moments of a 2-D distribution over a bin range.
Definition BeamFit2D.hpp:33
Double_t rho
Correlation coefficient, in [-1, 1].
Definition BeamFit2D.hpp:36
Double_t sigma_y
Weighted RMS widths.
Definition BeamFit2D.hpp:35
Double_t sigma_x
Definition BeamFit2D.hpp:35
Double_t mu_x
Definition BeamFit2D.hpp:34
Double_t mu_y
Weighted centroid.
Definition BeamFit2D.hpp:34
Double_t weight
Total weight included; zero means the range held nothing above threshold.
Definition BeamFit2D.hpp:37