Belle II Software  release-08-01-10
SegmentPairCreator.cc
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 #include <tracking/trackFindingCDC/findlets/minimal/SegmentPairCreator.h>
9 
10 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
11 #include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
12 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
13 
14 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
15 
16 #include <framework/core/ModuleParamList.templateDetails.h>
17 
18 #include <vector>
19 #include <array>
20 #include <string>
21 #include <algorithm>
22 
23 using namespace Belle2;
24 using namespace TrackFindingCDC;
25 
27 {
30 }
31 
33 {
34  return "Creates axial stereo segment pairs from a set of segments filtered by some acceptance criterion";
35 }
36 
37 void SegmentPairCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
38 {
39  m_segmentPairFilter.exposeParameters(moduleParamList, prefix);
40  m_axialSegmentPairCreator.exposeParameters(moduleParamList, prefixed("Axial", prefix));
41 
42  moduleParamList->addParameter(prefixed(prefix, "axialBridging"),
44  "Switch to enable the search for axial to axial pairs "
45  "to enable more stable reconstruction of the middle stereo",
47 }
48 
49 void SegmentPairCreator::apply(const std::vector<CDCSegment2D>& inputSegments,
50  std::vector<CDCSegmentPair>& segmentPairs)
51 {
52  segmentPairs.reserve(500);
53 
54  // Group the segments by their super layer id
55  for (std::vector<const CDCSegment2D*>& segmentsInSuperLayer : m_segmentsBySuperLayer) {
56  segmentsInSuperLayer.clear();
57  }
58 
59  for (const CDCSegment2D& segment : inputSegments) {
60  if (segment.empty()) continue;
61  ISuperLayer iSuperLayer = segment.front().getISuperLayer();
62  if (not ISuperLayerUtil::isInvalid(iSuperLayer)) {
63  const CDCSegment2D* ptrSegment = &segment;
64  m_segmentsBySuperLayer[iSuperLayer].push_back(ptrSegment);
65  }
66  }
67 
68  // Make pairs of closeby superlayers
69  for (ISuperLayer iSuperLayer = 0; iSuperLayer < ISuperLayerUtil::c_N; ++iSuperLayer) {
70  const std::vector<const CDCSegment2D*>& fromSegments = m_segmentsBySuperLayer[iSuperLayer];
71 
72  // Make pairs of this superlayer and the superlayer more to the inside
73  ISuperLayer iSuperLayerIn = ISuperLayerUtil::getNextInwards(iSuperLayer);
74  if (ISuperLayerUtil::isInCDC(iSuperLayerIn)) {
75  const std::vector<const CDCSegment2D*>& toSegments = m_segmentsBySuperLayer[iSuperLayerIn];
76  create(fromSegments, toSegments, segmentPairs);
77  }
78 
79  // Make pairs of this superlayer and the superlayer more to the outside
80  ISuperLayer iSuperLayerOut = ISuperLayerUtil::getNextOutwards(iSuperLayer);
81  if (ISuperLayerUtil::isInCDC(iSuperLayerOut)) {
82  const std::vector<const CDCSegment2D*>& toSegments = m_segmentsBySuperLayer[iSuperLayerOut];
83  create(fromSegments, toSegments, segmentPairs);
84  }
85  }
86 
87  std::sort(segmentPairs.begin(), segmentPairs.end());
88 
89  if (not m_param_axialBridging) return;
90 
91  // Memory for the axial axial segment pairs.
92  std::vector<CDCAxialSegmentPair> axialSegmentPairs;
93 
94  // Create the axial to axial bridges
95  m_axialSegmentPairCreator.apply(inputSegments, axialSegmentPairs);
96 
97  // Make pairs by splitting the axial segment pairs and using the *common* fit as the 3d reconstruction bases
98  for (const CDCAxialSegmentPair& axialSegmentPair : axialSegmentPairs) {
99  const CDCSegment2D* startSegment = axialSegmentPair.getStartSegment();
100  const CDCSegment2D* endSegment = axialSegmentPair.getEndSegment();
101 
102  CDCTrajectory2D startCommonTrajectory = axialSegmentPair.getTrajectory2D();
103  if (not startCommonTrajectory.isFitted()) continue;
104 
105  CDCTrajectory2D startTrajectory2D = startSegment->getTrajectory2D();
106  startCommonTrajectory.setLocalOrigin(startTrajectory2D.getLocalOrigin());
107  startSegment->setTrajectory2D(startCommonTrajectory);
108  std::vector<const CDCSegment2D*> startSegments{startSegment};
109 
110  CDCTrajectory2D endCommonTrajectory = axialSegmentPair.getTrajectory2D();
111  CDCTrajectory2D endTrajectory2D = endSegment->getTrajectory2D();
112  endCommonTrajectory.setLocalOrigin(endTrajectory2D.getLocalOrigin());
113  endSegment->setTrajectory2D(endCommonTrajectory);
114  std::vector<const CDCSegment2D*> endSegments{endSegment};
115 
116  if (startSegment->getISuperLayer() == endSegment->getISuperLayer()) {
117  ISuperLayer iSuperLayerCommon = startSegment->getISuperLayer();
118 
119  ISuperLayer iSuperLayerIn = ISuperLayerUtil::getNextInwards(iSuperLayerCommon);
120  if (ISuperLayerUtil::isInCDC(iSuperLayerIn)) {
121  const std::vector<const CDCSegment2D*>& middleSegments = m_segmentsBySuperLayer[iSuperLayerIn];
122  create(startSegments, middleSegments, segmentPairs);
123  create(middleSegments, endSegments, segmentPairs);
124  }
125 
126  ISuperLayer iSuperLayerOut = ISuperLayerUtil::getNextOutwards(iSuperLayerCommon);
127  if (ISuperLayerUtil::isInCDC(iSuperLayerOut)) {
128  const std::vector<const CDCSegment2D*>& middleSegments = m_segmentsBySuperLayer[iSuperLayerOut];
129  create(startSegments, middleSegments, segmentPairs);
130  create(middleSegments, endSegments, segmentPairs);
131  }
132 
133  } else {
134  ISuperLayer iSuperLayerMiddle =
135  (startSegment->getISuperLayer() + endSegment->getISuperLayer()) / 2;
136  const std::vector<const CDCSegment2D*>& middleSegments = m_segmentsBySuperLayer[iSuperLayerMiddle];
137  create(startSegments, middleSegments, segmentPairs);
138  create(middleSegments, endSegments, segmentPairs);
139  }
140  startSegment->setTrajectory2D(startTrajectory2D);
141  endSegment->setTrajectory2D(endTrajectory2D);
142  }
143 
144  auto lessPairAndgreaterWeight = [](const CDCSegmentPair & lhs, const CDCSegmentPair & rhs) {
145  if (lhs < rhs) return true;
146  if (rhs < lhs) return false;
147  return lhs.getAutomatonCell().getCellWeight() > rhs.getAutomatonCell().getCellWeight();
148  };
149 
150  std::sort(segmentPairs.begin(), segmentPairs.end(), lessPairAndgreaterWeight);
151 
152  // auto samePair = [](const CDCSegmentPair& lhs, const CDCSegmentPair& rhs) {
153  // if (lhs < rhs) return false;
154  // if (rhs < lhs) return false;
155  // return true;
156  // };
157  // erase_unique(segmentPairs, samePair);
158 }
159 
160 void SegmentPairCreator::create(const std::vector<const CDCSegment2D*>& fromSegments,
161  const std::vector<const CDCSegment2D*>& toSegments,
162  std::vector<CDCSegmentPair>& segmentPairs)
163 {
164  CDCSegmentPair segmentPair;
165  for (const CDCSegment2D* ptrFromSegment : fromSegments) {
166  for (const CDCSegment2D* ptrToSegment : toSegments) {
167 
168  if (ptrFromSegment == ptrToSegment) continue;
169  segmentPair.setSegments(ptrFromSegment, ptrToSegment);
170  segmentPair.clearTrajectory3D();
171 
172  Weight pairWeight = m_segmentPairFilter(segmentPair);
173  if (not std::isnan(pairWeight)) {
174  segmentPair.getAutomatonCell().setCellWeight(pairWeight);
175  segmentPairs.push_back(segmentPair);
176  }
177  }
178  }
179 }
The Module parameter list class.
Weight getCellWeight() const
Getter for the cell weight.
void setCellWeight(Weight weight)
Setter for the cell weight.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
void apply(const std::vector< CDCSegment2D > &inputSegments, std::vector< CDCAxialSegmentPair > &axialSegmentPairs) final
Main method constructing pairs in adjacent super layers.
Class representing a pair of reconstructed axial segements in adjacent superlayer.
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
void setSegments(const CDCSegment2D *fromSegment, const CDCSegment2D *toSegment)
Setter for both segments simultaniously.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
void clearTrajectory3D() const
Invalides the currently stored trajectory information.
Particle trajectory as it is seen in xy projection represented as a circle.
double setLocalOrigin(const Vector2D &localOrigin)
Setter for the origin of the local coordinate system.
const Vector2D & getLocalOrigin() const
Getter for the origin of the local coordinate system.
bool isFitted() const
Checks if the circle is already set to a valid value.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the set of parameters of the filter to the module parameter list.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
ChooseableSegmentPairFilter m_segmentPairFilter
The filter to be used for the segment pair generation.
AxialSegmentPairCreator m_axialSegmentPairCreator
Findlet responsible for the creation of axial axial segment pairs.
void create(const std::vector< const CDCSegment2D * > &fromSegments, const std::vector< const CDCSegment2D * > &toSegments, std::vector< CDCSegmentPair > &segmentPairs)
Creates segment pairs from a combination of from segments and to segments.
std::string getDescription() final
Short description of the findlet.
SegmentPairCreator()
Constructor adding the filter as a subordinary processing signal listener.
bool m_param_axialBridging
Parameter : Switch to enable the search for axial to axial pairs to enable more stable reconstruction...
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
std::array< std::vector< const CDCSegment2D * >, ISuperLayerUtil::c_N > m_segmentsBySuperLayer
Structure for the segments grouped by super layer id.
void apply(const std::vector< CDCSegment2D > &inputSegments, std::vector< CDCSegmentPair > &segmentPairs) final
Main method constructing pairs in adjacent super layers.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.
static const ISuperLayer c_N
Constant representing the total number of cdc superlayers.
Definition: ISuperLayer.h:56
static ISuperLayer getNextInwards(ISuperLayer iSuperLayer)
Returns the super layer that is inside of the given super layer.
Definition: ISuperLayer.cc:63
static bool isInvalid(ISuperLayer iSuperLayer)
Indicates if the given number corresponds to a true cdc superlayer - excludes the logic ids for inner...
Definition: ISuperLayer.cc:38
static ISuperLayer getNextOutwards(ISuperLayer iSuperLayer)
Returns the super layer that is outside of the given super layer.
Definition: ISuperLayer.cc:72
static bool isInCDC(ISuperLayer iSuperLayer)
Indicates if the given number corresponds to a true cdc superlayer - excludes the logic ids for inner...
Definition: ISuperLayer.cc:43