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