Belle II Software  release-05-01-25
SegmentPairCreator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/findlets/minimal/SegmentPairCreator.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
13 #include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
14 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
15 
16 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17 
18 #include <framework/core/ModuleParamList.templateDetails.h>
19 
20 #include <vector>
21 #include <array>
22 #include <string>
23 #include <algorithm>
24 
25 using namespace Belle2;
26 using namespace TrackFindingCDC;
27 
29 {
32 }
33 
35 {
36  return "Creates axial stereo segment pairs from a set of segments filtered by some acceptance criterion";
37 }
38 
39 void 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 
51 void 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 
162 void 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 }
Belle2::TrackFindingCDC::ISuperLayerUtil::c_N
static const ISuperLayer c_N
Constant representing the total number of cdc superlayers.
Definition: ISuperLayer.h:66
Belle2::TrackFindingCDC::CDCSegmentPair
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
Definition: CDCSegmentPair.h:44
Belle2::TrackFindingCDC::SegmentPairCreator::m_axialSegmentPairCreator
AxialSegmentPairCreator m_axialSegmentPairCreator
Findlet responsible for the creation of axial axial segment pairs.
Definition: SegmentPairCreator.h:76
Belle2::TrackFindingCDC::CDCTrajectory2D::setLocalOrigin
double setLocalOrigin(const Vector2D &localOrigin)
Setter for the origin of the local coordinate system.
Definition: CDCTrajectory2D.cc:357
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::addProcessingSignalListener
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Definition: CompositeProcessingSignalListener.cc:57
Belle2::TrackFindingCDC::SegmentPairCreator::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: SegmentPairCreator.cc:39
Belle2::TrackFindingCDC::CDCSegmentPair::getAutomatonCell
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCSegmentPair.h:243
Belle2::TrackFindingCDC::AutomatonCell::getCellWeight
Weight getCellWeight() const
Getter for the cell weight.
Definition: AutomatonCell.h:126
Belle2::TrackFindingCDC::SegmentPairCreator::apply
void apply(const std::vector< CDCSegment2D > &inputSegments, std::vector< CDCSegmentPair > &segmentPairs) final
Main method constructing pairs in adjacent super layers.
Definition: SegmentPairCreator.cc:51
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::ISuperLayerUtil::getNextOutwards
static ISuperLayer getNextOutwards(ISuperLayer iSuperLayer)
Returns the super layer that is outside of the given super layer.
Definition: ISuperLayer.cc:74
Belle2::TrackFindingCDC::SegmentPairCreator::m_param_axialBridging
bool m_param_axialBridging
Parameter : Switch to enable the search for axial to axial pairs to enable more stable reconstruction...
Definition: SegmentPairCreator.h:72
Belle2::TrackFindingCDC::CDCTrajectory2D::getLocalOrigin
const Vector2D & getLocalOrigin() const
Getter for the origin of the local coordinate system.
Definition: CDCTrajectory2D.h:508
Belle2::TrackFindingCDC::SegmentPairCreator::m_segmentPairFilter
ChooseableSegmentPairFilter m_segmentPairFilter
The filter to be used for the segment pair generation.
Definition: SegmentPairCreator.h:79
Belle2::TrackFindingCDC::CDCSegmentPair::clearTrajectory3D
void clearTrajectory3D() const
Invalides the currently stored trajectory information.
Definition: CDCSegmentPair.h:225
Belle2::TrackFindingCDC::ISuperLayerUtil::isInvalid
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:40
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::TrackFindingCDC::CDCAxialSegmentPair
Class representing a pair of reconstructed axial segements in adjacent superlayer.
Definition: CDCAxialSegmentPair.h:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ISuperLayerUtil::getNextInwards
static ISuperLayer getNextInwards(ISuperLayer iSuperLayer)
Returns the super layer that is inside of the given super layer.
Definition: ISuperLayer.cc:65
Belle2::TrackFindingCDC::ISuperLayerUtil::isInCDC
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:45
Belle2::TrackFindingCDC::SegmentPairCreator::SegmentPairCreator
SegmentPairCreator()
Constructor adding the filter as a subordinary processing signal listener.
Definition: SegmentPairCreator.cc:28
Belle2::TrackFindingCDC::SegmentPairCreator::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: SegmentPairCreator.cc:34
Belle2::TrackFindingCDC::CDCTrajectory2D::isFitted
bool isFitted() const
Checks if the circle is already set to a valid value.
Definition: CDCTrajectory2D.cc:85
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::AxialSegmentPairCreator::apply
void apply(const std::vector< CDCSegment2D > &inputSegments, std::vector< CDCAxialSegmentPair > &axialSegmentPairs) final
Main method constructing pairs in adjacent super layers.
Definition: AxialSegmentPairCreator.cc:36
Belle2::TrackFindingCDC::Chooseable::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the set of parameters of the filter to the module parameter list.
Definition: ChooseableFilter.icc.h:58
Belle2::TrackFindingCDC::SegmentPairCreator::create
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.
Definition: SegmentPairCreator.cc:162
Belle2::TrackFindingCDC::AxialSegmentPairCreator::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: AxialSegmentPairCreator.cc:31
Belle2::TrackFindingCDC::SegmentPairCreator::m_segmentsBySuperLayer
std::array< std::vector< const CDCSegment2D * >, ISuperLayerUtil::c_N > m_segmentsBySuperLayer
Structure for the segments grouped by super layer id.
Definition: SegmentPairCreator.h:83
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::CDCSegmentPair::setSegments
void setSegments(const CDCSegment2D *fromSegment, const CDCSegment2D *toSegment)
Setter for both segments simultaniously.
Definition: CDCSegmentPair.h:156
Belle2::TrackFindingCDC::AutomatonCell::setCellWeight
void setCellWeight(Weight weight)
Setter for the cell weight.
Definition: AutomatonCell.h:132