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