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/trackingUtilities/findlets/base/Findlet.h>
11#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory3D.h>
12#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
13#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
14
15#include <tracking/trackingUtilities/utilities/Algorithms.h>
16#include <tracking/trackingUtilities/utilities/Functional.h>
17#include <tracking/trackingUtilities/numerics/WeightComperator.h>
18
19#include <tracking/ckf/cdc/entities/CDCCKFState.h>
20#include <tracking/ckf/cdc/entities/CDCCKFPath.h>
21#include <tracking/ckf/cdc/filters/states/CDCStateFilterFactory.h>
22
23#include <tracking/trackingUtilities/filters/base/ChooseableFilter.dcl.h>
24
25#include <tracking/trackingUtilities/utilities/StringManipulation.h>
26#include <framework/core/ModuleParamList.h>
27
28#include <Math/Vector2D.h>
29
30namespace Belle2 {
36 class CDCCKFStateFilter : public TrackingUtilities::Findlet<const CDCCKFState, CDCCKFState> {
37 public:
46
47
49 void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
50 {
51 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "maximalHitCandidates"),
52 m_maximalHitCandidates, "Maximal hit candidates to test",
54 m_preFilter.exposeParameters(moduleParamList, TrackingUtilities::prefixed(prefix, "pre"));
55 m_basicFilter.exposeParameters(moduleParamList, TrackingUtilities::prefixed(prefix, "basic"));
56 m_extrapolationFilter.exposeParameters(moduleParamList, TrackingUtilities::prefixed(prefix, "extrapolation"));
57 m_finalSelection.exposeParameters(moduleParamList, TrackingUtilities::prefixed(prefix, "final"));
58 }
59
64 void setMaximalHitCandidates(size_t maximalHitCandidates) { m_maximalHitCandidates = maximalHitCandidates; }
65
67 void apply(const CDCCKFPath& path, std::vector<CDCCKFState>& nextStates) override
68 {
69 const CDCCKFState& lastState = path.back();
70 const TrackingUtilities::CDCTrajectory3D& trajectory = lastState.getTrajectory();
71
72 // cppcheck-suppress variableScope ; declaration kept at this scope for readability
73 TrackingUtilities::Weight weight;
74
75 B2DEBUG(29, "On layer: " << (lastState.isSeed() ? -1 : lastState.getWireHit()->getWire().getICLayer()));
76
77 for (CDCCKFState& nextState : nextStates) {
78 B2DEBUG(29, "Checking layer: " << nextState.getWireHit()->getWire().getICLayer());
79
80 weight = m_preFilter({&path, &nextState});
81 nextState.setWeight(weight);
82 if (std::isnan(weight)) {
83 B2DEBUG(29, "Fails PreFilter");
84 continue;
85 }
86
87 // Do a reconstruction based on the helix extrapolation from the last hit
88 reconstruct(nextState, trajectory, lastState.getArcLength());
89
90 weight = m_basicFilter({&path, &nextState});
91 nextState.setWeight(weight);
92 if (std::isnan(weight)) {
93 B2DEBUG(29, "Fails BasicFilter");
94 continue;
95 }
96
97 // Extrapolate and update
98 weight = m_extrapolationFilter({&path, &nextState});
99 nextState.setWeight(weight);
100 if (std::isnan(weight)) {
101 B2DEBUG(29, "Fails ExtrapolationFilter");
102 continue;
103 }
104
105 // Do a final hit selection based on the new state
106 const TrackingUtilities::CDCTrajectory3D& thisTrajectory = nextState.getTrajectory();
107 reconstruct(nextState, thisTrajectory, nextState.getArcLength());
108
109 weight = m_finalSelection({&path, &nextState});
110 nextState.setWeight(weight);
111 if (std::isnan(weight)) {
112 B2DEBUG(29, "Fails FinalFilter");
113 continue;
114 }
115 }
116
117 B2DEBUG(29, "Starting with " << nextStates.size() << " possible hits");
118
119 TrackingUtilities::erase_remove_if(nextStates,
121
122 B2DEBUG(29, "Now have " << nextStates.size());
123
124 std::sort(nextStates.begin(), nextStates.end(), TrackingUtilities::GreaterWeight());
125
126 TrackingUtilities::only_best_N(nextStates, m_maximalHitCandidates);
127 }
128
129 private:
140
142 static void reconstruct(CDCCKFState& state, const TrackingUtilities::CDCTrajectory3D& trajectory, const double lastArcLength)
143 {
144 // TODO: actually we do not need to do any trajectory creation here. We could save some computing time!
145 const TrackingUtilities::CDCTrajectory2D& trajectory2D = trajectory.getTrajectory2D();
146 const TrackingUtilities::CDCTrajectorySZ& trajectorySZ = trajectory.getTrajectorySZ();
147
148 const TrackingUtilities::CDCWireHit* wireHit = state.getWireHit();
149
150 ROOT::Math::XYVector recoPos2D;
151 if (wireHit->isAxial()) {
152 recoPos2D = wireHit->reconstruct2D(trajectory2D);
153 } else {
154 const CDC::CDCWire& wire = wireHit->getWire();
155 const ROOT::Math::XYVector& posOnXYPlane = wireHit->reconstruct2D(trajectory2D);
156
157 const double arcLength = trajectory2D.calcArcLength2D(posOnXYPlane);
158 const double z = trajectorySZ.mapSToZ(arcLength);
159
160 const ROOT::Math::XYVector& wirePos2DAtZ = wire.getWirePos2DAtZ(z);
161
162 const ROOT::Math::XYVector& recoPosOnTrajectory = trajectory2D.getClosest(wirePos2DAtZ);
163 const double driftLength = wireHit->getRefDriftLength();
164 ROOT::Math::XYVector disp2D = recoPosOnTrajectory - wirePos2DAtZ;
165 if (disp2D.R() != 0.0) {
166 disp2D *= (driftLength / disp2D.R());
167 }
168 recoPos2D = wirePos2DAtZ + disp2D;
169 }
170
171 const double arcLength = trajectory2D.calcArcLength2D(recoPos2D);
172 const double z = trajectorySZ.mapSToZ(arcLength);
173 const double distanceToHit = trajectory2D.getDist2D(recoPos2D);
174
175 state.setArcLength(lastArcLength + arcLength);
176 state.setHitDistance(distanceToHit);
177 state.setReconstructedZ(z);
178 }
179 };
180
181}
TrackingUtilities::ChooseableFilter< CDCStateFilterFactory > m_preFilter
Pre Filter.
size_t m_maximalHitCandidates
Parameter: max number of candidates.
static void reconstruct(CDCCKFState &state, const TrackingUtilities::CDCTrajectory3D &trajectory, const double lastArcLength)
Helper function to reconstruct the arc length and the hit distance of a state according to the trajec...
TrackingUtilities::ChooseableFilter< CDCStateFilterFactory > m_extrapolationFilter
Extrapolation Filter (after Kalman extrapolation)
void setMaximalHitCandidates(size_t maximalHitCandidates)
Set maximal hit candidates for state filtering.
TrackingUtilities::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.
TrackingUtilities::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.
CDCCKFStateFilter()
Add all sub findlets.
Define states for CKF algorithm, which can be seed track or CDC wire hit.
Definition CDCCKFState.h:26
void setHitDistance(double hitDistance)
Set hit distance to the trajectory.
double getArcLength() const
Return the arc-length along the tracjectory to the hit.
Definition CDCCKFState.h:95
void setReconstructedZ(double reconstructedZ)
Set state Z information.
void setArcLength(double arcLength)
Set the arc-length along the tracjectory to the hit.
Definition CDCCKFState.h:89
const TrackingUtilities::CDCWireHit * getWireHit() const
Get CDCWireHit corresponding to the state.
Definition CDCCKFState.h:36
TrackingUtilities::CDCTrajectory3D getTrajectory() const
Helper method to get trajectory from the trackState.
bool isSeed() const
Returns true if the state corresponds to the seed track.
Definition CDCCKFState.h:57
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
ROOT::Math::XYVector getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition CDCWire.h:184
The Module parameter list class.
Particle trajectory as it is seen in xy projection represented as a circle.
ROOT::Math::XYVector getClosest(const ROOT::Math::XYVector &point) const
Calculates the closest approach on the trajectory to the given point.
double calcArcLength2D(const ROOT::Math::XYVector &point) const
Calculate the travel distance from the start position of the trajectory.
double getDist2D(const ROOT::Math::XYVector &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.
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:56
Convenvience wrapper to setup a Chooseable filter from a specific factory object.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition Findlet.h:26
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 from the functional composition of two functors.
Definition Functional.h:87