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/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
13
14#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
15
16#include <framework/core/ModuleParamList.templateDetails.h>
17#include <framework/logging/Logger.h>
18
19using namespace Belle2;
20using namespace TrackFindingCDC;
21
23{
24 return "Fits each segment with a selectable method";
25}
26
27void SegmentFitter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
28{
29 moduleParamList->addParameter(prefixed(prefix, "karimakiFit"),
31 "Switch to select Karimaki method for fitting instead of Riemann fit",
33
34 moduleParamList->addParameter(prefixed(prefix, "fitPos"),
36 "Positional information of the hits to be used in the fit. "
37 "Options are 'recoPos', 'rlDriftCircle', 'wirePos'.",
39
40 moduleParamList->addParameter(prefixed(prefix, "fitVariance"),
42 "Positional information of the hits to be used in the fit. "
43 "Options are 'unit', 'driftLength', 'pseudo', 'proper'.",
45
46 moduleParamList->addParameter(prefixed(prefix, "updateDriftLength"),
48 "Switch to reestimate the drift length",
50
51 moduleParamList->addParameter(prefixed(prefix, "updateRecoPos"),
53 "Switch to reestimate the position and right left passage information",
55
56 m_driftLengthEstimator.exposeParameters(moduleParamList, prefix);
57}
58
59
61{
63 if (m_param_fitPosString != std::string("")) {
64 try {
65 m_fitPos = getFitPos(m_param_fitPosString);
66 } catch (std::invalid_argument& e) {
67 B2ERROR("Unexpected fitPos parameter : '" << m_param_fitPosString);
68 }
69 }
70
71 if (m_param_fitVarianceString != std::string("")) {
72 try {
74 } catch (std::invalid_argument& e) {
75 B2ERROR("Unexpected fitVariance parameter : '" << m_param_fitVarianceString);
76 }
77 }
78
80 if (m_fitPos != EFitPos::c_RecoPos) {
81 B2WARNING("Karimaki fitter only works with the reconstructed position as input.");
82 }
83 m_fitPos = EFitPos::c_RecoPos;
84 }
85}
86
87void SegmentFitter::apply(std::vector<CDCSegment2D>& outputSegments)
88{
89 // Update the drift length
91 for (CDCSegment2D& segment : outputSegments) {
92 m_driftLengthEstimator.updateDriftLength(segment);
93 }
94 }
95
96 for (const CDCSegment2D& segment : outputSegments) {
98 observations2D.appendRange(segment);
99
100 if (m_param_karimakiFit or observations2D.size() < 4) {
101 // Karimaki only works with the reconstructed position
102 if (m_fitPos != EFitPos::c_RecoPos) {
103 observations2D.clear();
104 observations2D.setFitPos(EFitPos::c_RecoPos);
105 observations2D.appendRange(segment);
106 }
107 CDCTrajectory2D trajectory2D = m_karimakiFitter.fit(observations2D);
108 segment.setTrajectory2D(trajectory2D);
109 } else {
110
111 CDCTrajectory2D trajectory2D = m_riemannFitter.fit(observations2D);
112 segment.setTrajectory2D(trajectory2D);
113 }
114 }
115
117 for (CDCSegment2D& segment : outputSegments) {
118 const CDCTrajectory2D& trajectory2D = segment.getTrajectory2D();
119 if (not trajectory2D.isFitted()) continue;
120 int nRLChanges = 0;
121 for (CDCRecoHit2D& recoHit2D : segment) {
122 ERightLeft rlInfo = trajectory2D.isRightOrLeft(recoHit2D.getRefPos2D());
123 if (rlInfo != recoHit2D.getRLInfo()) ++nRLChanges;
124 recoHit2D.setRLInfo(rlInfo);
125 const CDCRLWireHit& rlWireHit = recoHit2D.getRLWireHit();
126 Vector2D recoPos2D = rlWireHit.reconstruct2D(trajectory2D);
127 recoHit2D.setRecoPos2D(recoPos2D);
128 }
129 if (nRLChanges > 0) B2DEBUG(25, "RL changes " << nRLChanges);
130 }
131 }
132}
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 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.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Vector2D 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 Vector2D &point) const
Checks if the given point is to the right or to the left of the trajectory.
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.
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 apply(std::vector< CDCSegment2D > &outputSegments) override
Main algorithm applying the fit to each segment.
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.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition Vector2D.h:32
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.