Belle II Software  release-05-01-25
LayerSVDRelationFilter.icc.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun, Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/ckf/svd/filters/relations/LayerSVDRelationFilter.dcl.h>
13 #include <tracking/trackFindingCDC/filters/base/RelationFilter.icc.h>
14 
15 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
16 
17 #include <tracking/spacePointCreation/SpacePoint.h>
18 #include <framework/core/ModuleParamList.templateDetails.h>
19 #include <vxd/geometry/GeoCache.h>
20 
21 namespace Belle2 {
27  template <class AFilter, class APrefilter>
29  {
32  }
33 
34  template <class AFilter, class APrefilter>
36  {
37  Super::beginRun();
38 
39  // Fill maximum number cache
40  auto& geoCache = VXD::GeoCache::getInstance();
41  const auto& layers = geoCache.getLayers(VXD::SensorInfoBase::SensorType::SVD);
42  for (const auto& layerVXDID : layers) {
43  m_maximalLadderCache[layerVXDID.getLayerNumber()] = geoCache.getLadders(layerVXDID).size();
44  }
45  }
46 
47  template <class AFilter, class APrefilter>
49 
50  template <class AFilter, class APrefilter>
51  std::vector<CKFToSVDState*>
53  const std::vector<CKFToSVDState*>& states) const
54  {
55  std::vector<CKFToSVDState*> possibleNextStates;
56  possibleNextStates.reserve(states.size());
57 
58  const CKFToSVDState::stateCache& currentStateCache = currentState->getStateCache();
59  const unsigned int currentLayer = currentStateCache.geoLayer;
60  const unsigned int nextPossibleLayer = std::max(static_cast<int>(currentLayer) - 1 - m_param_hitJumping, 0);
61 
62  for (CKFToSVDState* nextState : states) {
63  if (currentState == nextState) {
64  continue;
65  }
66 
67  const CKFToSVDState::stateCache& nextStateCache = nextState->getStateCache();
68  const unsigned int nextLayer = nextStateCache.geoLayer;
69 
70  if (std::max(currentLayer, nextPossibleLayer) >= nextLayer and nextLayer >= std::min(currentLayer, nextPossibleLayer)) {
71 
72  if (currentLayer == nextLayer) {
73  // next layer is an overlap one, so lets return all hits from the same layer, that are on a
74  // ladder which is below the last added hit.
75  const unsigned int fromLadderNumber = currentStateCache.ladder;
76  const unsigned int maximumLadderNumber = m_maximalLadderCache.find(currentLayer)->second;
77 
78  // the reason for this strange formula is the numbering scheme in the VXD.
79  // we first substract 1 from the ladder number to have a ladder counting from 0 to N - 1,
80  // then we add (PXD)/subtract(SVD) one to get to the next (overlapping) ladder and do a % N to also cope for the
81  // highest number. Then we add 1 again, to go from the counting from 0 .. N-1 to 1 .. N.
82  // The + maximumLadderNumber in between makes sure, we are not ending with negative numbers
83  const int direction = -1;
84  const unsigned int overlappingLadder =
85  ((fromLadderNumber + maximumLadderNumber - 1) + direction) % maximumLadderNumber + 1;
86 
87  if (nextStateCache.ladder != overlappingLadder) {
88  continue;
89  }
90 
91  // Next we make sure to not have any cycles in our graph: we do this by defining only the halves of the
92  // sensor as overlapping. So if the first hit is coming from sensor 1 and the second from sensor 2,
93  // they are only related if the one from sensor 1 is on the half, that is pointing towards sensor 2
94  // and the one on sensor 2 is on the half that is pointing towards sensor 1.
95  //
96  // X X X
97  // ----|---- ----|---- ----|----
98  // This is fine: X This not: X This not: X
99  // ----|---- ----|---- ----|----
100  if (currentStateCache.localNormalizedu > 0.2) {
101  continue;
102  }
103 
104  if (nextStateCache.localNormalizedu <= 0.8) {
105  continue;
106  }
107  }
108 
109  // Some loose prefiltering of possible states
110  TrackFindingCDC::Weight weight = m_prefilter(std::make_pair(currentState, nextState));
111  if (std::isnan(weight)) {
112  continue;
113  }
114 
115 
116  possibleNextStates.push_back(nextState);
117  }
118  }
119 
120  return possibleNextStates;
121  }
122 
123  template <class AFilter, class APrefilter>
124  void LayerSVDRelationFilter<AFilter, APrefilter>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
125  {
126  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "hitJumping"), m_param_hitJumping,
127  "Make it possible to jump over N layers.", m_param_hitJumping);
128 
129  m_filter.exposeParameters(moduleParamList, prefix);
130  m_prefilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed("pre", prefix));
131  }
132 
133  template <class AFilter, class APrefilter>
134  TrackFindingCDC::Weight LayerSVDRelationFilter<AFilter, APrefilter>::operator()(const CKFToSVDState& from, const CKFToSVDState& to)
135  {
136  return m_filter(std::make_pair(&from, &to));
137  }
139 }
Belle2::LayerSVDRelationFilter::beginRun
void beginRun() final
Initialize the maximal ladder cache.
Definition: LayerSVDRelationFilter.icc.h:43
Belle2::LayerSVDRelationFilter::m_prefilter
APrefilter m_prefilter
Loose pre-filter to reject possibleTos.
Definition: LayerSVDRelationFilter.dcl.h:63
Belle2::LayerSVDRelationFilter::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters of the filter.
Definition: LayerSVDRelationFilter.icc.h:132
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::addProcessingSignalListener
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Definition: CompositeProcessingSignalListener.cc:57
Belle2::LayerSVDRelationFilter::getPossibleTos
std::vector< CKFToSVDState * > getPossibleTos(CKFToSVDState *from, const std::vector< CKFToSVDState * > &states) const final
Return all states the given state is possible related to.
Definition: LayerSVDRelationFilter.icc.h:60
Belle2::LayerSVDRelationFilter::m_filter
AFilter m_filter
Filter for rejecting the states.
Definition: LayerSVDRelationFilter.dcl.h:61
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::LayerSVDRelationFilter::operator()
TrackFindingCDC::Weight operator()(const CKFToSVDState &from, const CKFToSVDState &to) final
Give a final weight to the possibilities by asking the filter.
Definition: LayerSVDRelationFilter.icc.h:142
Belle2::CKFToSVDState
Specialized CKF State for extrapolating into the SVD.
Definition: CKFToSVDState.h:29
Belle2::LayerSVDRelationFilter::LayerSVDRelationFilter
LayerSVDRelationFilter()
Add the filter as listener.
Definition: LayerSVDRelationFilter.icc.h:36
Belle2::LayerSVDRelationFilter::~LayerSVDRelationFilter
~LayerSVDRelationFilter()
Default destructor.