Belle II Software  release-05-01-25
TrackCreatorSegmentPairAutomaton.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - 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/TrackCreatorSegmentPairAutomaton.h>
11 
12 #include <tracking/trackFindingCDC/fitting/CDCAxialStereoFusion.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
15 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
16 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
17 
18 #include <tracking/trackFindingCDC/ca/Path.h>
19 
20 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
21 
22 using namespace Belle2;
23 using namespace TrackFindingCDC;
24 
26 {
27  return "Constructs tracks by extraction of segment pair paths in a cellular automaton.";
28 }
29 
30 void TrackCreatorSegmentPairAutomaton::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
31 {
32  m_cellularPathFinder.exposeParameters(moduleParamList, prefix);
33 }
34 
36  const std::vector<CDCSegmentPair>& inputSegmentPairs,
37  const std::vector<WeightedRelation<const CDCSegmentPair>>& inputSegmentPairRelations,
38  std::vector<CDCTrack>& outputTracks)
39 {
40  // Obtain the segment pairs as pointers
41  std::vector<const CDCSegmentPair*> segmentPairPtrs =
42  as_pointers<const CDCSegmentPair>(inputSegmentPairs);
43 
44  m_segmentPairPaths.clear();
45  m_cellularPathFinder.apply(segmentPairPtrs, inputSegmentPairRelations, m_segmentPairPaths);
46 
47  // Reduce to plain tracks
48  CDCAxialStereoFusion fusionFitter;
49  for (const Path<const CDCSegmentPair>& segmentPairPath : m_segmentPairPaths) {
50  CDCTrajectory3D startTrajectory3D = segmentPairPath.front()->getTrajectory3D();
51  CDCTrajectory3D endTrajectory3D = segmentPairPath.back()->getTrajectory3D();
52 
53  // Work around for in stable fusion fits that reach over the apogee
54  auto saverStereoApogeePositions = [&fusionFitter](const CDCSegmentPair * lhs,
55  const CDCSegmentPair * rhs) {
56  // Segment pairs are at a turning point
57  if (lhs->getFromSegment()->getISuperLayer() != rhs->getToSegment()->getISuperLayer()) return false;
58 
59  // Only apply workaround if apogee is in a stereo superlayer
60  if (lhs->getToSegment()->isAxial()) return false;
61 
62  // Reset critical situation to simpler fit
63  fusionFitter.fusePreliminary(*lhs);
64  fusionFitter.fusePreliminary(*rhs);
65 
66  // Return false to continue looking
67  return false;
68  };
69  // return value is not needed here
70  // cppcheck-suppress ignoredReturnValue
71  std::adjacent_find(segmentPairPath.begin(), segmentPairPath.end(), saverStereoApogeePositions);
72 
73  // Compute the average recohits with the preliminary fits
74  outputTracks.push_back(CDCTrack::condense(segmentPairPath));
75  CDCTrack& track = outputTracks.back();
76 
77  // Set the start and end trajectory from the original fits
78  // Only necessary for the work around
79  {
80  Vector3D startPos = track.getStartTrajectory3D().getLocalOrigin();
81  startTrajectory3D.setLocalOrigin(startPos);
82  track.setStartTrajectory3D(startTrajectory3D);
83 
84  Vector3D endPos = track.getEndTrajectory3D().getLocalOrigin();
85  endTrajectory3D.setLocalOrigin(endPos);
86  track.setEndTrajectory3D(endTrajectory3D);
87  }
88  for (const CDCSegmentPair* segmentPair : segmentPairPath) {
89  segmentPair->getFromSegment()->getAutomatonCell().setTakenFlag();
90  segmentPair->getToSegment()->getAutomatonCell().setTakenFlag();
91  }
92  }
93 }
Belle2::TrackFindingCDC::CDCTrack
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:51
Belle2::TrackFindingCDC::CDCSegmentPair
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
Definition: CDCSegmentPair.h:44
Belle2::TrackFindingCDC::CDCTrajectory3D::setLocalOrigin
double setLocalOrigin(const Vector3D &localOrigin)
Setter for the origin of the local coordinate system.
Definition: CDCTrajectory3D.cc:369
Belle2::TrackFindingCDC::CDCSegmentPair::getToSegment
const CDCSegment2D * getToSegment() const
Getter for the to segment.
Definition: CDCSegmentPair.h:132
Belle2::TrackFindingCDC::TrackCreatorSegmentPairAutomaton::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: TrackCreatorSegmentPairAutomaton.cc:25
Belle2::TrackFindingCDC::CDCTrack::condense
static CDCTrack condense(const Path< const CDCTrack > &trackPath)
Concats several tracks from a path.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::Vector3D
A three dimensional vector.
Definition: Vector3D.h:34
Belle2::TrackFindingCDC::TrackCreatorSegmentPairAutomaton::apply
void apply(const std::vector< CDCSegmentPair > &inputSegmentPairs, const std::vector< WeightedRelation< const CDCSegmentPair >> &inputSegmentPairRelations, std::vector< CDCTrack > &outputTracks) final
Main function of the segment finding by the cellular automaton.
Definition: TrackCreatorSegmentPairAutomaton.cc:35
Belle2::TrackFindingCDC::TrackCreatorSegmentPairAutomaton::m_segmentPairPaths
std::vector< Path< const CDCSegmentPair > > m_segmentPairPaths
Memory for the segment pair paths generated from the graph.
Definition: TrackCreatorSegmentPairAutomaton.h:69
Belle2::TrackFindingCDC::CDCAxialStereoFusion
Utility class implementing the Kalmanesk combination of to two dimensional trajectories to one three ...
Definition: CDCAxialStereoFusion.h:40
Belle2::TrackFindingCDC::CDCAxialStereoFusion::fusePreliminary
void fusePreliminary(const CDCSegmentPair &segmentPair)
Fit the given segment pair using the preliminary helix fit without proper covariance matrix.
Definition: CDCAxialStereoFusion.cc:65
Belle2::TrackFindingCDC::WeightedRelation
Type for two related objects with a weight.
Definition: CDCSegment2D.h:36
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::CDCSegmentPair::getFromSegment
const CDCSegment2D * getFromSegment() const
Getter for the from segment.
Definition: CDCSegmentPair.h:120
Belle2::TrackFindingCDC::TrackCreatorSegmentPairAutomaton::m_cellularPathFinder
MultipassCellularPathFinder< const CDCSegmentPair > m_cellularPathFinder
Instance of the cellular automaton path finder.
Definition: TrackCreatorSegmentPairAutomaton.h:65
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47
Belle2::TrackFindingCDC::TrackCreatorSegmentPairAutomaton::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: TrackCreatorSegmentPairAutomaton.cc:30