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