11 #include "trg/klm/modules/klmtrigger/klm_trig_linear_fit.h"
12 #include "trg/klm/modules/klmtrigger/group_helper.h"
13 #include "trg/klm/modules/klmtrigger/KLMAxis.h"
17 AXIS_NAME(x_pos,
int);
18 AXIS_NAME(y_pos,
int);
20 using namespace Belle2::group_helper::KLM_Coordinates_n;
21 using namespace Belle2::group_helper::KLM_Generic;
22 using namespace Belle2::group_helper;
32 template <
typename Container_T>
33 auto operator()(
const Container_T& container)
const
35 int64_t sumX = 0, sumY = 0, sumXX = 0, sumXY = 0, sumYY = 0;
36 for (
const auto& e : container) {
38 sumXX += x_pos(e) * x_pos(e);
41 sumYY += y_pos(e) * y_pos(e);
43 sumXY += x_pos(e) * y_pos(e);
45 auto nHits = Nhits_t(container.size());
46 int64_t denom = sumXX * nHits - sumX * sumX;
48 return std::tuple(slopeXY_t(1e100), interceptXY_t(1e100), ipXY_t(1e100), chisqXY_t(1e100), nHits);
50 auto slopeXY = slopeXY_t((
double)(sumXY * nHits - sumX * sumY) / (
double)denom);
51 auto interceptXY = interceptXY_t((
double)(sumXX * sumY - sumX * sumXY) / (
double)denom);
53 auto ipXY = ipXY_t(interceptXY * interceptXY * (1.0 - slopeXY * slopeXY));
55 auto chisqXY = chisqXY_t(slopeXY * slopeXY * sumXX
56 + interceptXY * interceptXY * nHits
58 + 2.0 * slopeXY * interceptXY * sumX
59 - 2.0 * slopeXY * sumXY
60 - 2.0 * interceptXY * sumY);
62 return std::tuple(slopeXY, interceptXY, ipXY, chisqXY, nHits) ;
74 std::vector<KLM_trig_linear_fit> klm_trig_linear_fit(std::vector<Belle2::group_helper::KLM_Digit_compact>& hits,
75 const std::vector<Belle2::group_helper::KLM_geo_fit_t>& geometry)
79 auto hits_w_geo_fit = vec_join(
82 comparators::on_common_args,
83 [&](
const auto & e1,
const auto & e2) {
92 x_pos(layer(e1) * geofit::slopeX(e2) + geofit::offsetX(e2)),
93 y_pos(strip(e1) * geofit::slopeY(e2) + geofit::offsetY(e2))
Abstract base class for different kinds of events.