Belle II Software development
CDCCKFStateFilter.h
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#pragma once
9
10#include <tracking/trackFindingCDC/findlets/base/Findlet.h>
11#include <tracking/trackFindingCDC/geometry/Vector2D.h>
12#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
13#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
14#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
15
16#include <tracking/trackFindingCDC/utilities/Algorithms.h>
17#include <tracking/trackFindingCDC/utilities/Functional.h>
18#include <tracking/trackFindingCDC/numerics/WeightComperator.h>
19
20#include <tracking/ckf/cdc/entities/CDCCKFState.h>
21#include <tracking/ckf/cdc/entities/CDCCKFPath.h>
22#include <tracking/ckf/cdc/filters/states/CDCStateFilterFactory.h>
23
24#include <tracking/trackFindingCDC/filters/base/ChooseableFilter.h>
25
26#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
27#include <framework/core/ModuleParamList.h>
28
29namespace Belle2 {
35 class CDCCKFStateFilter : public TrackFindingCDC::Findlet<const CDCCKFState, CDCCKFState> {
36 public:
39 {
44 }
45
46
48 void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
49 {
50 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maximalHitCandidates"),
51 m_maximalHitCandidates, "Maximal hit candidates to test",
53 m_preFilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed(prefix, "pre"));
54 m_basicFilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed(prefix, "basic"));
55 m_extrapolationFilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed(prefix, "extrapolation"));
56 m_finalSelection.exposeParameters(moduleParamList, TrackFindingCDC::prefixed(prefix, "final"));
57 }
58
60 void apply(const CDCCKFPath& path, std::vector<CDCCKFState>& nextStates) override
61 {
62 const CDCCKFState& lastState = path.back();
63 const TrackFindingCDC::CDCTrajectory3D& trajectory = lastState.getTrajectory();
64
65 TrackFindingCDC::Weight weight;
66
67 B2DEBUG(29, "On layer: " << (lastState.isSeed() ? -1 : lastState.getWireHit()->getWire().getICLayer()));
68
69 for (CDCCKFState& nextState : nextStates) {
70 B2DEBUG(29, "Checking layer: " << nextState.getWireHit()->getWire().getICLayer());
71
72 weight = m_preFilter({&path, &nextState});
73 nextState.setWeight(weight);
74 if (std::isnan(weight)) {
75 B2DEBUG(29, "Fails PreFilter");
76 continue;
77 }
78
79 // Do a reconstruction based on the helix extrapolation from the last hit
80 reconstruct(nextState, trajectory, lastState.getArcLength());
81
82 weight = m_basicFilter({&path, &nextState});
83 nextState.setWeight(weight);
84 if (std::isnan(weight)) {
85 B2DEBUG(29, "Fails BasicFilter");
86 continue;
87 }
88
89 // Extrapolate and update
90 weight = m_extrapolationFilter({&path, &nextState});
91 nextState.setWeight(weight);
92 if (std::isnan(weight)) {
93 B2DEBUG(29, "Fails ExtrapolationFilter");
94 continue;
95 }
96
97 // Do a final hit selection based on the new state
98 const TrackFindingCDC::CDCTrajectory3D& thisTrajectory = nextState.getTrajectory();
99 reconstruct(nextState, thisTrajectory, nextState.getArcLength());
100
101 weight = m_finalSelection({&path, &nextState});
102 nextState.setWeight(weight);
103 if (std::isnan(weight)) {
104 B2DEBUG(29, "Fails FinalFilter");
105 continue;
106 }
107 }
108
109 B2DEBUG(29, "Starting with " << nextStates.size() << " possible hits");
110
111 TrackFindingCDC::erase_remove_if(nextStates,
113
114 B2DEBUG(29, "Now have " << nextStates.size());
115
116 std::sort(nextStates.begin(), nextStates.end(), TrackFindingCDC::GreaterWeight());
117
118 TrackFindingCDC::only_best_N(nextStates, m_maximalHitCandidates);
119 }
120
121 private:
132
134 void reconstruct(CDCCKFState& state, const TrackFindingCDC::CDCTrajectory3D& trajectory, const double lastArcLength) const
135 {
136 // TODO: actually we do not need to do any trajectory creation here. We could save some computing time!
137 const TrackFindingCDC::CDCTrajectory2D& trajectory2D = trajectory.getTrajectory2D();
138 const TrackFindingCDC::CDCTrajectorySZ& trajectorySZ = trajectory.getTrajectorySZ();
139
140 const TrackFindingCDC::CDCWireHit* wireHit = state.getWireHit();
141
143 if (wireHit->isAxial()) {
144 recoPos2D = wireHit->reconstruct2D(trajectory2D);
145 } else {
146 const TrackFindingCDC::CDCWire& wire = wireHit->getWire();
147 const TrackFindingCDC::Vector2D& posOnXYPlane = wireHit->reconstruct2D(trajectory2D);
148
149 const double arcLength = trajectory2D.calcArcLength2D(posOnXYPlane);
150 const double z = trajectorySZ.mapSToZ(arcLength);
151
152 const TrackFindingCDC::Vector2D& wirePos2DAtZ = wire.getWirePos2DAtZ(z);
153
154 const TrackFindingCDC::Vector2D& recoPosOnTrajectory = trajectory2D.getClosest(wirePos2DAtZ);
155 const double driftLength = wireHit->getRefDriftLength();
156 TrackFindingCDC::Vector2D disp2D = recoPosOnTrajectory - wirePos2DAtZ;
157 disp2D.normalizeTo(driftLength);
158 recoPos2D = wirePos2DAtZ + disp2D;
159 }
160
161 const double arcLength = trajectory2D.calcArcLength2D(recoPos2D);
162 const double z = trajectorySZ.mapSToZ(arcLength);
163 const double distanceToHit = trajectory2D.getDist2D(recoPos2D);
164
165 state.setArcLength(lastArcLength + arcLength);
166 state.setHitDistance(distanceToHit);
167 state.setReconstructedZ(z);
168 }
169 };
171}
A stack of pre-, helix-extrapolation- , Kalman-extrapolation- and Kalman-update-filters.
size_t m_maximalHitCandidates
Parameter: max number of candidates.
TrackFindingCDC::ChooseableFilter< CDCStateFilterFactory > m_basicFilter
Basic Filter (uses helix extrapolation)
void apply(const CDCCKFPath &path, std::vector< CDCCKFState > &nextStates) override
Apply the findlet and do the state selection.
TrackFindingCDC::ChooseableFilter< CDCStateFilterFactory > m_finalSelection
Final Selection Filter (after Kalman update)
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
TrackFindingCDC::ChooseableFilter< CDCStateFilterFactory > m_extrapolationFilter
Extrapolation Filter (after Kalman extrapolation)
TrackFindingCDC::ChooseableFilter< CDCStateFilterFactory > m_preFilter
Pre Filter.
CDCCKFStateFilter()
Add all sub findlets.
void reconstruct(CDCCKFState &state, const TrackFindingCDC::CDCTrajectory3D &trajectory, const double lastArcLength) const
Helper function to reconstruct the arc length and the hit distance of a state according to the trajec...
Define states for CKF algorithm, which can be seed track or CDC wire hit.
Definition: CDCCKFState.h:25
void setHitDistance(double hitDistance)
Set hit distance to the trajectory.
Definition: CDCCKFState.h:100
double getArcLength() const
Return the arc-length along the tracjectory to the hit.
Definition: CDCCKFState.h:94
void setReconstructedZ(double reconstructedZ)
Set state Z information.
Definition: CDCCKFState.h:136
void setArcLength(double arcLength)
Set the arc-length along the tracjectory to the hit.
Definition: CDCCKFState.h:88
TrackFindingCDC::CDCTrajectory3D getTrajectory() const
Helper method to get trajectory from the trackState.
Definition: CDCCKFState.h:148
const TrackFindingCDC::CDCWireHit * getWireHit() const
Get CDCWireHit corresponding to the state.
Definition: CDCCKFState.h:35
bool isSeed() const
Returns true if the state corresponds to the seed track.
Definition: CDCCKFState.h:56
The Module parameter list class.
Particle trajectory as it is seen in xy projection represented as a circle.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
Vector2D getClosest(const Vector2D &point) const
Calculates the closest approach on the trajectory to the given point.
double getDist2D(const Vector2D &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
Linear trajectory in sz space.
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
Vector2D getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition: CDCWire.h:192
Convenvience wrapper to setup a Chooseable filter from a specific factory object.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition: Vector2D.h:32
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Definition: Vector2D.h:313
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
std::vector< CDCCKFState > CDCCKFPath
Shortcut for the collection of CDC CKF-algorithm states.
Definition: CDCCKFPath.h:19
Abstract base class for different kinds of events.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127
Functor factory from the functional composition of two functors.
Definition: Functional.h:87