BmnRoot
26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnWeightedLine.h
Go to the documentation of this file.
1
/*
2
BM@N alignment routine
3
BM@N experiment at NICA complex, JINR, 2026
4
5
Department: Math & Soft Group of HEP lab
6
Author: Claude (Opus 5)
7
Supervisor: Igor Polev, polev@jinr.int
8
9
BmnWeightedLine header-only implementation
10
Weighted least squares straight line in one projection
11
*/
12
13
#ifndef BMNWEIGHTEDLINE_H
14
#define BMNWEIGHTEDLINE_H
15
16
#include <
RtypesCore.h
>
17
#include <
TMath.h
>
18
#include <algorithm>
19
#include <cmath>
20
21
// v = At0() + Slope() * z. Raw sums lose digits when the points lie far from z = 0 compared with
22
// their z spread; for the BM@N detectors they keep 12 digits or more.
23
// A point of zero weight adds nothing, but still counts in n.
24
class
BmnWeightedLine
25
{
26
private
:
27
Double_t
s
{0.0},
sz
{0.0},
szz
{0.0},
sv
{0.0},
szv
{0.0},
svv
{0.0};
28
Int_t
n
{0};
29
// det value is heavily reused -- it needs to be cached
30
mutable
Double_t
det
{
TMath::QuietNaN
()};
31
32
public
:
33
void
Add
(
Double_t
z,
Double_t
v
,
Double_t
w = 1.0) noexcept
34
{
35
s
+= w;
36
sz
+= w * z;
37
szz
+= w * z * z;
38
sv
+= w *
v
;
39
szv
+= w * z *
v
;
40
svv
+= w *
v
*
v
;
41
n
++;
42
det
=
TMath::QuietNaN
();
43
}
44
// the inverse of Add(): the line through the other points
45
void
Remove
(
Double_t
z,
Double_t
v
,
Double_t
w = 1.0) noexcept
46
{
47
s
-= w;
48
sz
-= w * z;
49
szz
-= w * z * z;
50
sv
-= w *
v
;
51
szv
-= w * z *
v
;
52
svv
-= w *
v
*
v
;
53
n
--;
54
det
=
TMath::QuietNaN
();
55
}
56
Int_t
N
() const noexcept {
return
n
; }
57
Double_t
Mean
() const noexcept {
return
sv
/
s
; }
58
Double_t
At
(
Double_t
z)
const
noexcept
{
return
At0
() +
Slope
() * z; }
59
Double_t
At0
() const noexcept {
return
(
szz
*
sv
-
sz
*
szv
) /
Det
(); }
60
Double_t
Slope
() const noexcept {
return
(
s
*
szv
-
sz
*
sv
) /
Det
(); }
61
Double_t
Chi2
() const noexcept {
return
svv
-
At0
() *
sv
-
Slope
() *
szv
; }
62
Double_t
Rms
() const noexcept {
return
std::sqrt(std::max(
svv
/
s
-
Mean
() *
Mean
(), 0.0)); }
63
// Var(At0) + 2 z Cov(At0, Slope) + z^2 Var(Slope), from the weights alone
64
Double_t
Var
(
Double_t
z)
const
noexcept
{
return
(
szz
- 2.0 * z *
sz
+ z * z *
s
) /
Det
(); }
65
Double_t
SlopeVar
() const noexcept {
return
s
/
Det
(); }
66
Double_t
Cov
() const noexcept {
return
-
sz
/
Det
(); }
// Cov(At0, Slope)
67
// cached functions used in hot code or heavily reused
68
Double_t
Det
() const noexcept
69
{
70
if
(
TMath::IsNaN
(
det
))
71
det
=
s
*
szz
-
sz
*
sz
;
72
return
det
;
73
}
74
};
75
76
#endif
// BMNWEIGHTEDLINE_H
v
__m128 v
Definition
P4_F32vec4.h:1
RtypesCore.h
Int_t
int Int_t
Double_t
double Double_t
TMath.h
BmnWeightedLine
Definition
BmnWeightedLine.h:25
BmnWeightedLine::Det
Double_t Det() const noexcept
Definition
BmnWeightedLine.h:68
BmnWeightedLine::At0
Double_t At0() const noexcept
Definition
BmnWeightedLine.h:59
BmnWeightedLine::Chi2
Double_t Chi2() const noexcept
Definition
BmnWeightedLine.h:61
BmnWeightedLine::n
Int_t n
Definition
BmnWeightedLine.h:28
BmnWeightedLine::sv
Double_t sv
Definition
BmnWeightedLine.h:27
BmnWeightedLine::sz
Double_t sz
Definition
BmnWeightedLine.h:27
BmnWeightedLine::Cov
Double_t Cov() const noexcept
Definition
BmnWeightedLine.h:66
BmnWeightedLine::Var
Double_t Var(Double_t z) const noexcept
Definition
BmnWeightedLine.h:64
BmnWeightedLine::N
Int_t N() const noexcept
Definition
BmnWeightedLine.h:56
BmnWeightedLine::At
Double_t At(Double_t z) const noexcept
Definition
BmnWeightedLine.h:58
BmnWeightedLine::Mean
Double_t Mean() const noexcept
Definition
BmnWeightedLine.h:57
BmnWeightedLine::Rms
Double_t Rms() const noexcept
Definition
BmnWeightedLine.h:62
BmnWeightedLine::Add
void Add(Double_t z, Double_t v, Double_t w=1.0) noexcept
Definition
BmnWeightedLine.h:33
BmnWeightedLine::det
Double_t det
Definition
BmnWeightedLine.h:30
BmnWeightedLine::Slope
Double_t Slope() const noexcept
Definition
BmnWeightedLine.h:60
BmnWeightedLine::szv
Double_t szv
Definition
BmnWeightedLine.h:27
BmnWeightedLine::SlopeVar
Double_t SlopeVar() const noexcept
Definition
BmnWeightedLine.h:65
BmnWeightedLine::s
Double_t s
Definition
BmnWeightedLine.h:27
BmnWeightedLine::Remove
void Remove(Double_t z, Double_t v, Double_t w=1.0) noexcept
Definition
BmnWeightedLine.h:45
BmnWeightedLine::svv
Double_t svv
Definition
BmnWeightedLine.h:27
BmnWeightedLine::szz
Double_t szz
Definition
BmnWeightedLine.h:27
TMath::IsNaN
Bool_t IsNaN(Double_t x)
TMath::QuietNaN
Double_t QuietNaN()
align_new
src
BmnWeightedLine.h
Generated on
for BmnRoot by
1.17.0