Belle II Software development
SegmentFitter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/trackFindingCDC/findlets/minimal/SegmentFitter.h>
9
10#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
11
12#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
13
14#include <tracking/trackingUtilities/utilities/StringManipulation.h>
15
16#include <framework/core/ModuleParamList.templateDetails.h>
17#include <framework/logging/Logger.h>
18
19#include <Math/Vector2D.h>
20
21using namespace Belle2;
22using namespace TrackFindingCDC;
23using namespace TrackingUtilities;
24
26{
27 return "Fits each segment with a selectable method";
28}
29
30void SegmentFitter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
31{
32 moduleParamList->addParameter(prefixed(prefix, "karimakiFit"),
34 "Switch to select Karimaki method for fitting instead of Riemann fit",
36
37 moduleParamList->addParameter(prefixed(prefix, "fitPos"),
39 "Positional information of the hits to be used in the fit. "
40 "Options are 'recoPos', 'rlDriftCircle', 'wirePos'.",
42
43 moduleParamList->addParameter(prefixed(prefix, "fitVariance"),
45 "Positional information of the hits to be used in the fit. "
46 "Options are 'unit', 'driftLength', 'pseudo', 'proper'.",
48
49 moduleParamList->addParameter(prefixed(prefix, "updateDriftLength"),
51 "Switch to reestimate the drift length",
53
54 moduleParamList->addParameter(prefixed(prefix, "updateRecoPos"),
56 "Switch to reestimate the position and right left passage information",
58
59 m_driftLengthEstimator.exposeParameters(moduleParamList, prefix);
60}
61
62
64{
66 if (m_param_fitPosString != std::string("")) {
67 try {
68 m_fitPos = getFitPos(m_param_fitPosString);
69 } catch (std::invalid_argument& e) {
70 B2ERROR("Unexpected fitPos parameter : '" << m_param_fitPosString);
71 }
72 }
73
74 if (m_param_fitVarianceString != std::string("")) {
75 try {
77 } catch (std::invalid_argument& e) {
78 B2ERROR("Unexpected fitVariance parameter : '" << m_param_fitVarianceString);
79 }
80 }
81
83 if (m_fitPos != EFitPos::c_RecoPos) {
84 B2WARNING("Karimaki fitter only works with the reconstructed position as input.");
85 }
86 m_fitPos = EFitPos::c_RecoPos;
87 }
88}
89
90void SegmentFitter::apply(std::vector<CDCSegment2D>& outputSegments)
91{
92 // Update the drift length
94 for (CDCSegment2D& segment : outputSegments) {
95 m_driftLengthEstimator.updateDriftLength(segment);
96 }
97 }
98
99 for (const CDCSegment2D& segment : outputSegments) {
101 observations2D.appendRange(segment);
102
103 if (m_param_karimakiFit or observations2D.size() < 4) {
104 // Karimaki only works with the reconstructed position
105 if (m_fitPos != EFitPos::c_RecoPos) {
106 observations2D.clear();
107 observations2D.setFitPos(EFitPos::c_RecoPos);
108 observations2D.appendRange(segment);
109 }
110 CDCTrajectory2D trajectory2D = m_karimakiFitter.fit(observations2D);
111 segment.setTrajectory2D(trajectory2D);
112 } else {
113
114 CDCTrajectory2D trajectory2D = m_riemannFitter.fit(observations2D);
115 segment.setTrajectory2D(trajectory2D);
116 }
117 }
118
120 for (CDCSegment2D& segment : outputSegments) {
121 const CDCTrajectory2D& trajectory2D = segment.getTrajectory2D();
122 if (not trajectory2D.isFitted()) continue;
123 int nRLChanges = 0;
124 for (CDCRecoHit2D& recoHit2D : segment) {
125 ERightLeft rlInfo = trajectory2D.isRightOrLeft(recoHit2D.getRefPos2D());
126 if (rlInfo != recoHit2D.getRLInfo()) ++nRLChanges;
127 recoHit2D.setRLInfo(rlInfo);
128 const TrackingUtilities::CDCRLWireHit& rlWireHit = recoHit2D.getRLWireHit();
129 ROOT::Math::XYVector recoPos2D = rlWireHit.reconstruct2D(trajectory2D);
130 recoHit2D.setRecoPos2D(recoPos2D);
131 }
132 if (nRLChanges > 0) B2DEBUG(25, "RL changes " << nRLChanges);
133 }
134 }
135}
The Module parameter list class.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t appendRange(const TrackingUtilities::CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
void clear()
Removes all observations stored.
std::size_t size() const
Returns the number of observations stored.
void setFitPos(EFitPos fitPos)
Setter for the indicator that the reconstructed position should be favoured.
EFitPos m_fitPos
Option which positional information from the hits should be used.
DriftLengthEstimator m_driftLengthEstimator
Instance of the drift length estimator to be used.
void initialize() override
Signals the beginning of the event processing.
bool m_param_karimakiFit
Parameter : Switch to use Karimaki fit.
std::string getDescription() override
Short description of the findlet.
CDCKarimakiFitter m_karimakiFitter
Instance of the karimaki fitter to be used.
void apply(std::vector< TrackingUtilities::CDCSegment2D > &outputSegments) override
Main algorithm applying the fit to each segment.
bool m_param_updateDriftLength
Parameter : Switch to reestimate the drift length before the fit.
CDCRiemannFitter m_riemannFitter
Instance of the riemann fitter to be used.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to a module.
EFitVariance m_fitVariance
Option which variance information from the hits should be used.
std::string m_param_fitVarianceString
Parameter : Option string which variance information from the hits should be used.
bool m_param_updateRecoPos
Parameter : Switch to reevaluate the position and right left passage information based in the fit.
std::string m_param_fitPosString
Parameter : Option string which positional information from the hits should be used.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
ROOT::Math::XYVector reconstruct2D(const CDCTrajectory2D &trajectory2D) const
Reconstructs a position of primary ionisation on the drift circle.
Class representing a two dimensional reconstructed hit in the central drift chamber.
A reconstructed sequence of two dimensional hits in one super layer.
Particle trajectory as it is seen in xy projection represented as a circle.
bool isFitted() const
Checks if the circle is already set to a valid value.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Checks if the given point is to the right or to the left of the trajectory.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.