Belle II Software  release-05-01-25
RecoTrackUtil.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, Dmitrii Neverov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/eventdata/utils/RecoTrackUtil.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/hits/CDCRLWireHit.h>
15 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
16 
17 #include <tracking/trackFindingCDC/topology/ISuperLayer.h>
18 #include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
19 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
20 
21 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
22 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCBFieldUtil.h>
23 
24 #include <tracking/trackFindingCDC/numerics/TMatrixConversion.h>
25 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
26 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
27 #include <tracking/trackFindingCDC/numerics/ESign.h>
28 
29 #include <tracking/dataobjects/RecoTrack.h>
30 #include <tracking/dataobjects/RecoHitInformation.h>
31 
32 #include <framework/datastore/StoreArray.h>
33 
34 #include <TMatrixDSymfwd.h>
35 #include <TMatrixTSym.h>
36 #include <cmath>
37 
38 using namespace Belle2;
39 using namespace TrackFindingCDC;
40 
41 RecoTrack* RecoTrackUtil::storeInto(const CDCTrack& track, StoreArray<RecoTrack>& recoTracks, const double momentumSeedMagnitude)
42 {
43  CDCTrack firstHits;
44  ISuperLayer closestLayer = track.getStartISuperLayer();
45  if (ISuperLayerUtil::isAxial(closestLayer)) closestLayer = ISuperLayerUtil::getNextOutwards(closestLayer);
46 
47  for (const CDCRecoHit3D hit : track) {
48  if (hit.isAxial()) continue;
49  firstHits.push_back(hit);
50  if ((hit.getISuperLayer() != closestLayer) and (firstHits.size() > 3)) break;
51  }
52 
53  const CDCSZFitter& szFitter = CDCSZFitter::getFitter();
54  const CDCTrajectorySZ& szTrajectory = szFitter.fitWithStereoHits(firstHits);
55 
56  Vector3D position(track.getStartTrajectory3D().getSupport().x(),
57  track.getStartTrajectory3D().getSupport().y(),
58  szTrajectory.getZ0());
59 
60  Vector3D momentum(track.getStartTrajectory3D().getFlightDirection3DAtSupport());
61  const double z0 = szTrajectory.getZ0();
62  const double lambda = std::atan(szTrajectory.getTanLambda());
63  momentum.scale(std::cos(lambda));
64  momentum.setZ(std::sin(lambda));
65  momentum *= momentumSeedMagnitude;
66 
67  ESign charge;
68  double votes(0);
69  int nHits(0);
70  closestLayer = track.getEndISuperLayer();
71  if (ISuperLayerUtil::isAxial(closestLayer)) closestLayer = ISuperLayerUtil::getNextInwards(closestLayer);
72  for (auto it = track.rbegin(); it != track.rend(); it++) {
73  CDCRecoHit3D hit = *it;
74  if (hit.isAxial()) continue;
75  votes += (hit.getRecoZ() - z0 - std::tan(lambda) * hit.getArcLength2D());
76  nHits++;
77  if ((hit.getISuperLayer() != closestLayer) and (nHits > 3)) break;
78  }
79  votes > 0 ? charge = ESign::c_Plus : charge = ESign::c_Minus;
80 
81  RecoTrack* newRecoTrack = recoTracks.appendNew(position, momentum, charge);
82  RecoTrackUtil::fill(track, *newRecoTrack);
83  return newRecoTrack;
84 }
85 
87 {
88  const CDCTrajectory3D& traj3D = track.getStartTrajectory3D();
89  RecoTrack* newRecoTrack = storeInto(traj3D, recoTracks);
90  if (not newRecoTrack) return nullptr;
91 
92  RecoTrackUtil::fill(track, *newRecoTrack);
93  return newRecoTrack;
94 }
95 
96 RecoTrack*
98 {
99  Vector3D position = traj3D.getSupport();
100  return storeInto(traj3D, CDCBFieldUtil::getBFieldZ(position), recoTracks);
101 }
102 
104  const double bZ,
105  StoreArray<RecoTrack>& recoTracks)
106 {
107  // Set the start parameters
108  Vector3D position = traj3D.getSupport();
109  Vector3D momentum =
110  bZ == 0 ? traj3D.getFlightDirection3DAtSupport() : traj3D.getMom3DAtSupport(bZ);
111  ESign charge = traj3D.getChargeSign();
112 
113  // Do not propagate invalid fits, signal that the fit is invalid to the caller.
114  if (not ESignUtil::isValid(charge) or momentum.hasNAN() or position.hasNAN()) {
115  return nullptr;
116  }
117 
118  RecoTrack* newRecoTrack = recoTracks.appendNew(position, momentum, charge);
119  if (std::isfinite(traj3D.getFlightTime())) {
120  newRecoTrack->setTimeSeed(traj3D.getFlightTime());
121  }
122 
123  const CovarianceMatrix<6>& cov6 = traj3D.getCartesianCovariance(bZ);
124  TMatrixDSym covSeed = TMatrixConversion::toTMatrix(cov6);
125  newRecoTrack->setSeedCovariance(covSeed);
126  return newRecoTrack;
127 }
128 
130 template void RecoTrackUtil::fill<CDCTrack>(const CDCTrack&, RecoTrack&);
131 
133 template <class ARLHitHolderRange>
134 void RecoTrackUtil::fill(const ARLHitHolderRange& rlWireHitHolders, RecoTrack& recoTrack)
135 {
136  int sortingParameter = -1;
137  for (const auto& rlWireHitHolder : rlWireHitHolders) {
138  ++sortingParameter;
139 
140  const CDCRLWireHit rlWireHit = rlWireHitHolder.getRLWireHit();
141  const CDCWireHit& wireHit = rlWireHit.getWireHit();
142  const CDCHit* cdcHit = wireHit.getHit();
143 
144  // Right left ambiguity resolution
145  ERightLeft rlInfo = rlWireHit.getRLInfo();
146  using RightLeftInformation = RecoHitInformation::RightLeftInformation;
147  if (rlInfo == ERightLeft::c_Left) {
148  recoTrack.addCDCHit(cdcHit,
149  sortingParameter,
150  RightLeftInformation::c_left,
151  RecoHitInformation::c_CDCTrackFinder);
152  } else if (rlInfo == ERightLeft::c_Right) {
153  recoTrack.addCDCHit(cdcHit,
154  sortingParameter,
155  RightLeftInformation::c_right,
156  RecoHitInformation::c_CDCTrackFinder);
157  } else if (rlInfo == ERightLeft::c_Invalid) {
158  recoTrack.addCDCHit(cdcHit,
159  sortingParameter,
160  RightLeftInformation::c_invalidRightLeftInformation,
161  RecoHitInformation::c_CDCTrackFinder);
162  } else {
163  recoTrack.addCDCHit(cdcHit,
164  sortingParameter,
165  RightLeftInformation::c_undefinedRightLeftInformation,
166  RecoHitInformation::c_CDCTrackFinder);
167  }
168  }
169 }
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::TrackFindingCDC::Vector3D::hasNAN
bool hasNAN() const
Checks if one of the coordinates is NAN.
Definition: Vector3D.h:157
Belle2::TrackFindingCDC::CDCRecoHit3D
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:62
Belle2::RecoTrack::setTimeSeed
void setTimeSeed(const double timeSeed)
Set the time seed. ATTENTION: This is not the fitted time.
Definition: RecoTrack.h:520
Belle2::TrackFindingCDC::CDCTrack
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:51
Belle2::TrackFindingCDC::CDCSZFitter::getFitter
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
Definition: CDCSZFitter.cc:38
Belle2::RecoTrack::setSeedCovariance
void setSeedCovariance(const TMatrixDSym &seedCovariance)
Set the covariance of the seed. ATTENTION: This is not the fitted covariance.
Definition: RecoTrack.h:530
Belle2::TrackFindingCDC::CDCRLWireHit::getWireHit
const CDCWireHit & getWireHit() const
Getter for the wire hit associated with the oriented hit.
Definition: CDCRLWireHit.h:202
Belle2::CDCHit
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:51
Belle2::TrackFindingCDC::ESignUtil::ESign
ESign
Enumeration for the distinct sign values of floating point variables.
Definition: ESign.h:37
Belle2::TrackFindingCDC::ESignUtil::isValid
bool isValid(ESign s)
Returns true if sign is ESign::c_Plus, ESign::c_Minus or ESign::c_Zero.
Definition: ESign.h:56
Belle2::TrackFindingCDC::CDCWireHit::getHit
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:167
Belle2::TrackFindingCDC::CDCTrajectory3D::getMom3DAtSupport
Vector3D getMom3DAtSupport(const double bZ) const
Get the momentum at the start point of the trajectory.
Definition: CDCTrajectory3D.h:210
Belle2::TrackFindingCDC::CDCTrajectorySZ
Linear trajectory in sz space.
Definition: CDCTrajectorySZ.h:41
Belle2::TrackFindingCDC::ISuperLayerUtil::getNextOutwards
static ISuperLayer getNextOutwards(ISuperLayer iSuperLayer)
Returns the super layer that is outside of the given super layer.
Definition: ISuperLayer.cc:74
Belle2::TrackFindingCDC::RecoTrackUtil::storeInto
static RecoTrack * storeInto(const CDCTrack &track, StoreArray< RecoTrack > &recoTracks, const double momentumSeedMagnitude)
For magnetic monopoles; estimates charge sign from all stereo hits, momentum direction from hits in c...
Definition: RecoTrackUtil.cc:41
Belle2::RecoTrack::addCDCHit
bool addCDCHit(const UsedCDCHit *cdcHit, const unsigned int sortingParameter, RightLeftInformation rightLeftInformation=RightLeftInformation::c_undefinedRightLeftInformation, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a cdc hit with the given information to the reco track.
Definition: RecoTrack.h:240
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::TrackFindingCDC::CDCSZFitter::fitWithStereoHits
CDCTrajectorySZ fitWithStereoHits(const CDCTrack &track) const
Returns the fitted sz trajectory of the track with the z-information of all stereo hits of the number...
Definition: CDCSZFitter.cc:127
Belle2::TrackFindingCDC::CDCRLWireHit::getRLInfo
ERightLeft getRLInfo() const
Getter for the right left passage information.
Definition: CDCRLWireHit.h:244
Belle2::TrackFindingCDC::CDCTrajectorySZ::getZ0
double getZ0() const
Getter for the z coordinate at zero travel distance.
Definition: CDCTrajectorySZ.h:118
Belle2::TrackFindingCDC::CDCTrajectory3D::getCartesianCovariance
CovarianceMatrix< 6 > getCartesianCovariance(double bZ) const
Convert the helix parameters to the cartesian coordinates x,y,z,px,py,pz.
Definition: CDCTrajectory3D.cc:291
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ISuperLayerUtil::getNextInwards
static ISuperLayer getNextInwards(ISuperLayer iSuperLayer)
Returns the super layer that is inside of the given super layer.
Definition: ISuperLayer.cc:65
Belle2::TrackFindingCDC::CDCRLWireHit
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:51
Belle2::TrackFindingCDC::Vector3D
A three dimensional vector.
Definition: Vector3D.h:34
Belle2::TrackFindingCDC::CDCSZFitter
Class implementing the z coordinate over travel distance line fit.
Definition: CDCSZFitter.h:37
Belle2::TrackFindingCDC::NRightLeft::ERightLeft
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:35
Belle2::TrackFindingCDC::ISuperLayerUtil::isAxial
static bool isAxial(ISuperLayer iSuperLayer)
Returns if the super layer with the given id is axial.
Definition: ISuperLayer.cc:23
Belle2::TrackFindingCDC::CDCTrajectory3D::getSupport
Vector3D getSupport() const
Getter for the support point of the trajectory in global coordinates, where arcLength2D = 0.
Definition: CDCTrajectory3D.h:229
Belle2::TrackFindingCDC::CDCBFieldUtil::getBFieldZ
static double getBFieldZ()
Getter for the signed magnetic field stength in z direction at the origin ( in Tesla )
Definition: CDCBFieldUtil.cc:40
Belle2::TrackFindingCDC::CDCTrajectory3D::getFlightDirection3DAtSupport
Vector3D getFlightDirection3DAtSupport() const
Get the unit momentum at the start point of the trajectory.
Definition: CDCTrajectory3D.h:222
Belle2::TrackFindingCDC::TMatrixConversion::toTMatrix
static TMatrixDSym toTMatrix(const CovarianceMatrix< N > &cov)
Translate the covariance matrix to the TMatrix representation.
Definition: TMatrixConversion.h:69
Belle2::TrackFindingCDC::CDCTrajectory3D::getChargeSign
ESign getChargeSign() const
Gets the charge sign of the trajectory.
Definition: CDCTrajectory3D.cc:305
Belle2::TrackFindingCDC::PlainMatrix
A matrix implementation to be used as an interface typ through out the track finder.
Definition: PlainMatrix.h:50
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackFindingCDC::RecoTrackUtil::fill
static void fill(const ARLHitHolderRange &rlWireHitHolders, RecoTrack &recoTrack)
Translates a range of hits and inserts them in the reco track.
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::RecoHitInformation::RightLeftInformation
RightLeftInformation
The RightLeft information of the hit which is only valid for CDC hits.
Definition: RecoHitInformation.h:72
Belle2::TrackFindingCDC::CDCTrajectorySZ::getTanLambda
double getTanLambda() const
Getter for the slope over the travel distance coordinate.
Definition: CDCTrajectorySZ.h:114
Belle2::TrackFindingCDC::CDCTrajectory3D::getFlightTime
double getFlightTime() const
Getter for the time when the particle reached the support point position.
Definition: CDCTrajectory3D.h:366
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47