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