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