Belle II Software  release-05-01-25
SVDStateBasicVarSet.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/ckf/svd/filters/states/SVDStateBasicVarSet.h>
12 
13 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
14 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
15 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
16 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
17 
18 #include <tracking/spacePointCreation/SpacePoint.h>
19 #include <tracking/dataobjects/RecoTrack.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 using namespace TrackFindingCDC;
24 
25 bool SVDStateBasicVarSet::extract(const BaseSVDStateFilter::Object* pair)
26 {
27  const std::vector<TrackFindingCDC::WithWeight<const CKFToSVDState*>>& previousStates = pair->first;
28  CKFToSVDState* state = pair->second;
29 
30  const RecoTrack* cdcTrack = previousStates.front()->getSeed();
31  B2ASSERT("Path without seed?", cdcTrack);
32 
33  const SpacePoint* spacePoint = state->getHit();
34  B2ASSERT("Path without hit?", spacePoint);
35 
36  genfit::MeasuredStateOnPlane firstMeasurement;
37  if (state->mSoPSet()) {
38  firstMeasurement = state->getMeasuredStateOnPlane();
39  } else {
40  B2ASSERT("Previous state was not fitted?", previousStates.back()->mSoPSet());
41  firstMeasurement = previousStates.back()->getMeasuredStateOnPlane();
42  }
43 
44  Vector3D position = Vector3D(firstMeasurement.getPos());
45  Vector3D momentum = Vector3D(firstMeasurement.getMom());
46 
47  const CDCTrajectory3D trajectory(position, 0, momentum, cdcTrack->getChargeSeed());
48 
49  const Vector3D& hitPosition = static_cast<Vector3D>(spacePoint->getPosition());
50 
51  const double arcLength = trajectory.calcArcLength2D(hitPosition);
52  const Vector2D& trackPositionAtHit2D = trajectory.getTrajectory2D().getPos2DAtArcLength2D(arcLength);
53  double trackPositionAtHitZ = trajectory.getTrajectorySZ().mapSToZ(arcLength);
54 
55  Vector3D trackPositionAtHit(trackPositionAtHit2D, trackPositionAtHitZ);
56  Vector3D distance = trackPositionAtHit - hitPosition;
57 
58  var<named("distance")>() = static_cast<Float_t>(distance.norm());
59  var<named("xy_distance")>() = static_cast<Float_t>(distance.xy().norm());
60  var<named("z_distance")>() = static_cast<Float_t>(distance.z());
61 
62  Vector3D mSoP_distance = position - hitPosition;
63 
64  var<named("mSoP_distance")>() = static_cast<Float_t>(mSoP_distance.norm());
65  var<named("mSoP_xy_distance")>() = static_cast<Float_t>(mSoP_distance.xy().norm());
66  var<named("mSoP_z_distance")>() = static_cast<Float_t>(mSoP_distance.z());
67 
68  var<named("same_hemisphere")>() = fabs(position.phi() - hitPosition.phi()) < TMath::PiOver2();
69 
70  var<named("arcLengthOfHitPosition")>() = static_cast<Float_t>(trajectory.calcArcLength2D(hitPosition));
71  var<named("arcLengthOfCenterPosition")>() = static_cast<Float_t>(trajectory.calcArcLength2D(Vector3D(0, 0, 0)));
72 
73  var<named("layer")>() = spacePoint->getVxdID().getLayerNumber();
74  var<named("number")>() = previousStates.size();
75 
76  var<named("pt")>() = static_cast<Float_t>(momentum.xy().norm());
77  var<named("tan_lambda")>() = static_cast<Float_t>(trajectory.getTanLambda());
78  var<named("phi")>() = static_cast<Float_t>(momentum.phi());
79 
80  const VxdID& sensorInfo = spacePoint->getVxdID();
81 
82  var<named("ladder")>() = sensorInfo.getLadderNumber();
83  var<named("sensor")>() = sensorInfo.getSensorNumber();
84  var<named("segment")>() = sensorInfo.getSegmentNumber();
85  var<named("id")>() = sensorInfo.getID();
86 
87  var<named("last_layer")>() = 0;
88  var<named("last_ladder")>() = 0;
89  var<named("last_sensor")>() = 0;
90  var<named("last_segment")>() = 0;
91  var<named("last_id")>() = 0;
92 
93  const CKFToSVDState* parent = previousStates.back();
94  const SpacePoint* parentSpacePoint = parent->getHit();
95  if (parentSpacePoint) {
96  const VxdID& parentSensorInfo = parentSpacePoint->getVxdID();
97 
98  var<named("last_layer")>() = parentSensorInfo.getLayerNumber();
99  var<named("last_ladder")>() = parentSensorInfo.getLadderNumber();
100  var<named("last_sensor")>() = parentSensorInfo.getSensorNumber();
101  var<named("last_segment")>() = parentSensorInfo.getSegmentNumber();
102  var<named("last_id")>() = parentSensorInfo.getID();
103  }
104 
105  const double residual = m_kalmanStepper.calculateResidual(firstMeasurement, *state);
106  var<named("residual")>() = residual;
107 
108  if (state->isFitted()) {
109  var<named("chi2")>() = static_cast<Float_t>(state->getChi2());
110  } else {
111  var<named("chi2")>() = -999;
112  }
113 
114  const TMatrixDSym& cov5 = firstMeasurement.getCov();
115  const Float_t sigmaUV = std::sqrt(std::max(cov5(4, 4), cov5(3, 3)));
116  var<named("sigma_uv")>() = sigmaUV;
117  var<named("residual_over_sigma")>() = residual / sigmaUV;
118 
119  return true;
120 }
Belle2::Vector3D
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:35
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::VxdID::getID
baseType getID() const
Get the unique id.
Definition: VxdID.h:104
Belle2::CKFState::getMeasuredStateOnPlane
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlane() const
Get the mSoP if already set during extrapolation (or fitting)
Definition: CKFState.h:103
Belle2::CKFState::mSoPSet
bool mSoPSet() const
Is the mSoP already set? (= state was already extrapolated)
Definition: CKFState.h:116
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::SpacePoint::getPosition
const B2Vector3< double > & getPosition() const
return the position vector in global coordinates
Definition: SpacePoint.h:148
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CKFState::getChi2
double getChi2() const
Return the chi2 set during fitting. Is only valid after fitting.
Definition: CKFState.h:82
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::CKFState::getHit
const Hit * getHit() const
Return the SP this state is related to. May be nullptr.
Definition: CKFState.h:76
Belle2::CKFState::isFitted
bool isFitted() const
Check if state was already fitted.
Definition: CKFState.h:110
Belle2::RecoTrack::getChargeSeed
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:497
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::CKFToSVDState
Specialized CKF State for extrapolating into the SVD.
Definition: CKFToSVDState.h:29
Belle2::SpacePoint::getVxdID
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:158
Belle2::TrackFindingCDC::Filter::Object
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:43
Belle2::VxdID::getSegmentNumber
baseType getSegmentNumber() const
Get the sensor segment.
Definition: VxdID.h:112