ATLAS Offline Software
Loading...
Searching...
No Matches
SamplePointUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
10
12
13#include <algorithm>
14#include <cmath>
15#include <limits>
16#include <ranges>
17
18namespace MuonCalib{
19 std::vector<SamplePoint> fetchDataPoints(const IRtRelation& rtRel, const double relUnc) {
20 assert(relUnc >0);
21 std::vector<SamplePoint> points{};
22 const double stepWidth = rtRel.tBinWidth();
23 double time = rtRel.tLower();
24 while (time <= rtRel.tUpper()){
25 const double r = rtRel.radius(time);
26 points.emplace_back(time, r, relUnc);
27 time+=stepWidth;
28 }
29 return points;
30 }
31 std::vector<SamplePoint> fetchDataPoints(const IRtRelation& rtRel, const IRtResolution& reso) {
32 std::vector<SamplePoint> points{};
33 const double stepWidth = rtRel.tBinWidth();
34 double time = rtRel.tLower();
35 while (time <= rtRel.tUpper()){
36 points.emplace_back(time,rtRel.radius(time), reso.resolution(time));
37 time+=stepWidth;
38 }
39 return points;
40 }
41 std::vector<SamplePoint> resoFromRadius(const std::vector<SamplePoint>& points,
42 const double uncert) {
43 std::vector<SamplePoint> outPoints{};
44 outPoints.reserve(points.size());
45 for (const SamplePoint& point: points) {
46 outPoints.emplace_back(point.x2(),point.error(), uncert);
47 }
48 return outPoints;
49 }
50 std::vector<SamplePoint> fetchResolution(const std::vector<SamplePoint>& points,
51 const double uncert) {
52 std::vector<SamplePoint> outPoints{};
53 outPoints.reserve(points.size());
54 for (const SamplePoint& point: points) {
55 outPoints.emplace_back(point.x1(),point.error(), uncert);
56 }
57 return outPoints;
58 }
59
60
61 std::vector<SamplePoint> swapCoordinates(const std::vector<SamplePoint>& inPoints,
62 const IRtRelation& rtRel) {
63
64 std::vector<SamplePoint> outPoints{};
65 outPoints.reserve(inPoints.size());
66 /*
67 * Let's suppose that dY = f^{\prime} dX
68 */
69 for (const SamplePoint& in : inPoints) {
70 const double fPrime = std::abs(rtRel.driftVelocity(in.x1()));
71 outPoints.emplace_back(in.x2(), in.x1(), in.error() / (fPrime > 0 ? fPrime : 1.));
72 }
73 std::ranges::sort(outPoints, [](const SamplePoint& a, const SamplePoint& b) {
74 return a.x1() < b.x1();
75 });
76 return outPoints;
77 }
78 std::vector<SamplePoint> normalizeDomain(const std::vector<SamplePoint>& dataPoints) {
79 const auto [minX, maxX] = interval(dataPoints);
80 std::vector<SamplePoint> normedPoints{dataPoints};
81 for (unsigned k = 0; k < dataPoints.size(); ++k) {
82 normedPoints[k].set_x1(mapToUnitInterval(normedPoints[k].x1(), minX, maxX));
83 }
84 return normedPoints;
85 }
86 std::pair<double, double> minMax(const std::vector<SamplePoint>& points) {
87 double min{std::numeric_limits<double>::max()}, max{-std::numeric_limits<double>::max()};
88 for (const SamplePoint& point: points) {
89 min = std::min(min, point.x2());
90 max = std::max(max, point.x2());
91 }
92 return std::make_pair(min,max);
93 }
94 std::pair<double, double> interval(const std::vector<SamplePoint>& points) {
95 double min{std::numeric_limits<double>::max()}, max{-std::numeric_limits<double>::max()};
96 for (const SamplePoint& point: points) {
97 min = std::min(min, point.x1());
98 max = std::max(max, point.x1());
99 }
100 return std::make_pair(min, max);
101 }
102 double calculateChi2(const std::vector<SamplePoint>& dataPoints,
103 const IRtRelation& rtRel){
104 double chi2{0.};
105 for (const SamplePoint& point: dataPoints){
106 chi2+=std::pow((point.x2() - rtRel.radius(point.x1())) / point.error(), 2);
107 }
108 return chi2;
109 }
110 double calculateChi2(const std::vector<SamplePoint>& dataPoints,
111 const ITrRelation& trRel) {
112 double chi2{0.};
113 for (const SamplePoint& point: dataPoints){
114 chi2+=std::pow((point.x2() - trRel.driftTime(point.x1()).value_or(2.*trRel.maxRadius()) ) / point.error(), 2);
115 }
116 return chi2;
117 }
118 double calculateChi2(const std::vector<SamplePoint>& dataPoints,
119 const IRtResolution& rtReso) {
120 double chi2{0.};
121 for (const SamplePoint& point: dataPoints){
122 chi2+=std::pow((point.x2() - rtReso.resolution(point.x1())) / point.error(), 2);
123 }
124 return chi2;
125 }
126}
static Double_t a
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
generic interface for a rt-relation
Definition IRtRelation.h:19
virtual double tLower() const =0
Returns the lower time covered by the r-t.
virtual double tBinWidth() const =0
Returns the step-size for the sampling.
virtual double radius(double t) const =0
returns drift radius for a given time
virtual double tUpper() const =0
Returns the upper time covered by the r-t.
virtual double driftVelocity(double t) const =0
Returns the drift velocity for a given time.
Generic interface to retrieve the resolution on the drift radius as a function of the drift time.
virtual double resolution(double t, double bgRate=0.0) const =0
returns resolution for a give time and background rate
virtual double maxRadius() const =0
Returns the maximum drift-radius.
virtual std::optional< double > driftTime(const double r) const =0
Interface method for fetching the drift-time from the radius Returns a nullopt if the time is out of ...
This class provides a sample point for the BaseFunctionFitter.
Definition SamplePoint.h:15
double chi2(TH1 *h0, TH1 *h1)
int r
Definition globals.cxx:22
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
std::pair< double, double > interval(const std::vector< SamplePoint > &points)
Returns the interval covered by the sample points.
std::pair< double, double > minMax(const std::vector< SamplePoint > &points)
Returns the minimum & maximum values covered by the sample points.
double mapToUnitInterval(const double x, const double lowerEdge, const double upperEdge)
Maps the number x which is in [lowEdge;upperEdge] to the interval [-1;1].
Definition UtilFunc.h:12
std::vector< SamplePoint > resoFromRadius(const std::vector< SamplePoint > &points, const double uncert)
Creates a new vector of sample points where the x2 coordinate becomes the x1 coordinate and the resol...
std::vector< SamplePoint > normalizeDomain(const std::vector< SamplePoint > &dataPoints)
Normalizes the domain of the samples points to the interval -1 to 1.
std::vector< SamplePoint > swapCoordinates(const std::vector< SamplePoint > &points, const IRtRelation &rtRel)
Creates a new vector of samples points with x1 exchanged by x2 and vice-versa.
double calculateChi2(const std::vector< SamplePoint > &dataPoints, const IRtRelation &rtRel)
Returns the chi2 of the rt-relation w.r.t.
std::vector< SamplePoint > fetchResolution(const std::vector< SamplePoint > &points, const double uncert)
Creates a new vector of sample points where the x2 is assigned to the uncertainty and the uncertainty...
std::vector< SamplePoint > fetchDataPoints(const IRtRelation &rtRel, const double relUnc)
Constructs a list of sample points from the rt-relation.