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