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