Belle II Software  release-05-01-25
SegmentOrienter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - 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/SegmentOrienter.h>
11 
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 #include <framework/logging/Logger.h>
18 
19 using namespace Belle2;
20 using namespace TrackFindingCDC;
21 
23 {
24  return "Fixes the flight direction of segments to a preferred orientation by simple heuristics.";
25 }
26 
27 
28 void SegmentOrienter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
29 {
30  moduleParamList->addParameter(prefixed(prefix, "SegmentOrientation"),
32  "Option which orientation of segments shall be generate. "
33  "Valid options are '' (default of the finder), "
34  "'none' (one orientation, algorithm dependent), "
35  "'symmetric', "
36  "'curling', "
37  "'outwards', "
38  "'downwards'.",
40 }
41 
43 {
45  if (m_param_segmentOrientationString != std::string("")) {
46  try {
48  } catch (std::invalid_argument& e) {
49  B2ERROR("Unexpected 'SegmentOrientation' parameter : '" << m_param_segmentOrientationString);
50  }
51  }
52 }
53 
54 void SegmentOrienter::apply(const std::vector<CDCSegment2D>& inputSegments,
55  std::vector<CDCSegment2D>& outputSegments)
56 {
58  if (m_segmentOrientation == EPreferredDirection::c_None) {
59  // Copy the segments unchanged.
60  outputSegments = inputSegments;
61 
62  } else if (m_segmentOrientation == EPreferredDirection::c_Symmetric) {
63  outputSegments.reserve(2 * inputSegments.size());
64  for (const CDCSegment2D& segment : inputSegments) {
65  outputSegments.push_back(segment);
66  if (segment->hasReverseFlag()) continue; // Already a reverse found in the facet ca
67  outputSegments.back()->setReverseFlag();
68  outputSegments.push_back(segment.reversed());
69  outputSegments.back()->setReverseFlag();
70  }
71 
72  } else if (m_segmentOrientation == EPreferredDirection::c_Curling) {
73  // Only make a copy for segments that are curling inside the CDC
74  // Others fix to flighing outwards
75  outputSegments.reserve(1.5 * inputSegments.size());
76  for (const CDCSegment2D& segment : inputSegments) {
77  if (segment->hasReverseFlag()) {
78  outputSegments.push_back(segment);
79  continue; // Already a reverse found in the facet ca
80  }
81  const CDCTrajectory2D& trajectory2D = segment.getTrajectory2D();
82  bool isFitted = trajectory2D.isFitted();
83  bool isCurler = trajectory2D.isCurler(1.1);
84  bool isOriginer = trajectory2D.isOriginer();
85  // Trajectory is leaving the CDC starting in the inner volume
86  bool isLeaver = isFitted and (not isCurler) and isOriginer;
87  if (isLeaver) {
88  // Fix to outwards flying
89  const CDCRecoHit2D& firstHit = segment.front();
90  const CDCRecoHit2D& lastHit = segment.back();
91  if (lastHit.getRecoPos2D().cylindricalR() < firstHit.getRecoPos2D().cylindricalR()) {
92  outputSegments.push_back(segment.reversed());
93  } else {
94  outputSegments.push_back(segment);
95  }
96  } else {
97  // Ambigious keep both options
98  outputSegments.push_back(segment);
99  outputSegments.back()->setReverseFlag();
100  outputSegments.push_back(segment.reversed());
101  outputSegments.back()->setReverseFlag();
102  }
103  }
104 
105  } else if (m_segmentOrientation == EPreferredDirection::c_Outwards) {
106  outputSegments.reserve(inputSegments.size());
107  for (const CDCSegment2D& segment : inputSegments) {
108  const CDCRecoHit2D& firstHit = segment.front();
109  const CDCRecoHit2D& lastHit = segment.back();
110  if (lastHit.getRecoPos2D().cylindricalR() < firstHit.getRecoPos2D().cylindricalR()) {
111  outputSegments.push_back(segment.reversed());
112  } else {
113  outputSegments.push_back(segment);
114  }
115  }
116  } else if (m_segmentOrientation == EPreferredDirection::c_Downwards) {
117  outputSegments.reserve(inputSegments.size());
118  for (const CDCSegment2D& segment : inputSegments) {
119  const CDCRecoHit2D& firstHit = segment.front();
120  const CDCRecoHit2D& lastHit = segment.back();
121  if (lastHit.getRecoPos2D().y() > firstHit.getRecoPos2D().y()) {
122  outputSegments.push_back(segment.reversed());
123  } else {
124  outputSegments.push_back(segment);
125  }
126  }
127 
128  } else {
129  B2WARNING("Unexpected 'SegmentOrientation' parameter of segment finder module : '" <<
131  "'. No segments are put out.");
132  }
133 }
Belle2::TrackFindingCDC::CDCTrajectory2D::isOriginer
bool isOriginer(double factor=1) const
Checks if the trajectory intersects with the inner radius of the CDC time the given tolerance factor.
Definition: CDCTrajectory2D.cc:273
Belle2::TrackFindingCDC::SegmentOrienter::m_segmentOrientation
EPreferredDirection m_segmentOrientation
Encoded desired segment orientation.
Definition: SegmentOrienter.h:68
Belle2::TrackFindingCDC::CDCRecoHit2D::getRecoPos2D
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:248
Belle2::TrackFindingCDC::Vector2D::y
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:619
Belle2::TrackFindingCDC::SegmentOrienter::m_param_segmentOrientationString
std::string m_param_segmentOrientationString
Parameter: String that states the desired segment orientation.
Definition: SegmentOrienter.h:62
Belle2::TrackFindingCDC::CDCTrajectory2D::isCurler
bool isCurler(double factor=1) const
Checks if the trajectory leaves the outer radius of the CDC times the given tolerance factor.
Definition: CDCTrajectory2D.cc:267
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
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::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::Vector2D::cylindricalR
double cylindricalR() const
Gives the cylindrical radius of the vector. Same as norm()
Definition: Vector2D.h:571
Belle2::TrackFindingCDC::SegmentOrienter::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: SegmentOrienter.cc:22
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::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::SegmentOrienter::apply
void apply(const std::vector< CDCSegment2D > &inputSegments, std::vector< CDCSegment2D > &outputSegments) final
Main algorithm applying the adjustment of the orientation.
Definition: SegmentOrienter.cc:54
Belle2::TrackFindingCDC::SegmentOrienter::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: SegmentOrienter.cc:28
Belle2::TrackFindingCDC::SegmentOrienter::initialize
void initialize() final
Signals the beginning of the event processing.
Definition: SegmentOrienter.cc:42