Belle II Software development
TrackOrienter.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/TrackOrienter.h>
9
10#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
11#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
12
13#include <tracking/trackingUtilities/utilities/StringManipulation.h>
14
15#include <framework/core/ModuleParamList.templateDetails.h>
16#include <framework/logging/Logger.h>
17
18using namespace Belle2;
19using namespace TrackFindingCDC;
20using namespace TrackingUtilities;
21
23{
24 return "Fixes the flight direction of tracks to a preferred orientation by simple heuristics.";
25}
26
27void TrackOrienter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
28{
29 moduleParamList->addParameter(prefixed(prefix, "TrackOrientation"),
31 "Option which orientation of tracks 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_trackOrientationString != std::string("")) {
45 try {
47 } catch (std::invalid_argument& e) {
48 B2ERROR("Unexpected 'TrackOrientation' parameter : '" << m_param_trackOrientationString);
49 }
50 }
51}
52
53void TrackOrienter::apply(const std::vector<CDCTrack>& inputTracks,
54 std::vector<CDCTrack>& outputTracks)
55{
57 if (m_trackOrientation == EPreferredDirection::c_None) {
58 // Copy the tracks unchanged.
59 outputTracks = inputTracks;
60
61 } else if (m_trackOrientation == EPreferredDirection::c_Symmetric) {
62 outputTracks.reserve(2 * inputTracks.size());
63 for (const CDCTrack& track : inputTracks) {
64 outputTracks.push_back(track.reversed());
65 outputTracks.push_back(track);
66 }
67
68 } else if (m_trackOrientation == EPreferredDirection::c_Curling) {
69 // Only make a copy for tracks that are curling inside the CDC
70 // Others fix to flighing outwards
71 outputTracks.reserve(1.5 * inputTracks.size());
72 for (const CDCTrack& track : inputTracks) {
73 const CDCTrajectory3D& startTrajectory3D = track.getStartTrajectory3D();
74 const CDCTrajectory2D startTrajectory2D = startTrajectory3D.getTrajectory2D();
75
76 const CDCTrajectory3D& endTrajectory3D = track.getEndTrajectory3D();
77 const CDCTrajectory2D endTrajectory2D = endTrajectory3D.getTrajectory2D();
78 bool isFitted = startTrajectory2D.isFitted() and endTrajectory2D.isFitted();
79 bool isStartLeaver = (not endTrajectory2D.isCurler(1.1)) and startTrajectory2D.isOriginer();
80 bool isEndLeaver = (not startTrajectory2D.isCurler(1.1)) and endTrajectory2D.isOriginer();
81 // Trajectory is leaving the CDC starting in the inner volume
82 bool isLeaver = isFitted and (isStartLeaver or isEndLeaver);
83 if (isLeaver) {
84 // Fix to outwards flying
85 const CDCRecoHit3D& firstHit = track.front();
86 const CDCRecoHit3D& lastHit = track.back();
87 if (lastHit.getRecoPos2D().cylindricalR() < firstHit.getRecoPos2D().cylindricalR()) {
88 outputTracks.push_back(track.reversed());
89 } else {
90 outputTracks.push_back(track);
91 }
92 } else {
93 // Ambiguous keep both options
94 outputTracks.push_back(track);
95 outputTracks.push_back(track.reversed());
96 }
97 }
98
99 } else if (m_trackOrientation == EPreferredDirection::c_Outwards) {
100 outputTracks.reserve(inputTracks.size());
101 for (const CDCTrack& track : inputTracks) {
102 const CDCRecoHit3D& firstHit = track.front();
103 const CDCRecoHit3D& lastHit = track.back();
104 if (lastHit.getRecoPos2D().cylindricalR() < firstHit.getRecoPos2D().cylindricalR()) {
105 outputTracks.push_back(track.reversed());
106 } else {
107 outputTracks.push_back(track);
108 }
109 }
110
111 } else if (m_trackOrientation == EPreferredDirection::c_Downwards) {
112 outputTracks.reserve(inputTracks.size());
113 for (const CDCTrack& track : inputTracks) {
114 const CDCRecoHit3D& firstHit = track.front();
115 const CDCRecoHit3D& lastHit = track.back();
116 if (lastHit.getRecoPos2D().y() > firstHit.getRecoPos2D().y()) {
117 outputTracks.push_back(track.reversed());
118 } else {
119 outputTracks.push_back(track);
120 }
121 }
122
123 } else {
124 B2WARNING("Unexpected 'TrackOrientation' parameter of track finder module : '" <<
126 "'. No tracks are put out.");
127 }
128}
The Module parameter list class.
EPreferredDirection m_trackOrientation
Encoded desired track orientation.
void initialize() final
Signals the beginning of the event processing.
std::string m_param_trackOrientationString
Parameter: String that states the desired track orientation.
std::string getDescription() final
Short description of the findlet.
void apply(const std::vector< TrackingUtilities::CDCTrack > &inputTracks, std::vector< TrackingUtilities::CDCTrack > &outputTracks) 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 three dimensional reconstructed hit.
const Vector2D & getRecoPos2D() const
Getter for the 2d position of the hit.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.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.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
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.