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