Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResidualOutlierFinder.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ResidualOutlierFinder.h
1 #ifndef TRACKBASE_RESIDUALOUTLIERFINDER_H
2 #define TRACKBASE_RESIDUALOUTLIERFINDER_H
3 
9 
11 {
12  int verbosity = 0;
13  std::map<long unsigned int, float> chi2Cuts;
14 
16  {
17  // can't determine an outlier w/o a measurement or predicted parameters
18  if (!state.hasCalibrated() || !state.hasPredicted())
19  {
20  return false;
21  }
22 
23  const auto predicted = state.predicted();
24  const auto predictedCovariance = state.predictedCovariance();
25  double chi2 = std::numeric_limits<float>::max();
26 
27  auto fullCalibrated = state
28  .template calibrated<Acts::MultiTrajectoryTraits::MeasurementSizeMax>().data();
29  auto fullCalibratedCovariance = state
30  .template calibratedCovariance<Acts::MultiTrajectoryTraits::MeasurementSizeMax>().data();
31 
32  chi2 = Acts::visit_measurement(state.calibratedSize(), [&](auto N) -> double {
33  constexpr size_t kMeasurementSize = decltype(N)::value;
35  fullCalibrated};
36 
38  calibratedCovariance{fullCalibratedCovariance};
39 
40  using ParametersVector = Acts::ActsVector<kMeasurementSize>;
41  const auto H = state.projector().template topLeftCorner<kMeasurementSize, Acts::eBoundSize>().eval();
42  ParametersVector res;
43  res = calibrated - H * predicted;
44  chi2 = (res.transpose() * ((calibratedCovariance + H * predictedCovariance * H.transpose())).inverse() * res).eval()(0, 0);
45 
46  return chi2;
47  });
48 
49  if (verbosity > 2)
50  {
51  auto distance = Acts::visit_measurement(state.calibratedSize(), [&](auto N) {
52  constexpr size_t kMeasurementSize = decltype(N)::value;
53  auto residuals =
54  state.template calibrated<kMeasurementSize>() -
55  state.projector()
56  .template topLeftCorner<kMeasurementSize, Acts::eBoundSize>() *
57  state.predicted();
58  auto cdistance = residuals.norm();
59  return cdistance;
60  });
61  std::cout << "Measurement has distance, chi2 "
62  << distance << ", " << chi2
63  << std::endl;
64  }
65 
66  auto volume = state.referenceSurface().geometryId().volume();
67  auto layer = state.referenceSurface().geometryId().layer();
68 
69  bool outlier = false;
70  float chi2cut = chi2Cuts.find(volume)->second;
71  if (chi2 > chi2cut)
72  {
73  outlier = true;
74  }
75 
76  if (verbosity > 2)
77  {
78  std::cout << "Meas vol id and layer " << volume << ", " << layer
79  << " and chi2cut "
80  << chi2cut << " so returning outlier : " << outlier
81  << std::endl;
82  }
83 
84  return outlier;
85  }
86 };
87 
88 #endif