Belle II Software  release-05-01-25
PXDStateBasicVarSet.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/pxd/filters/states/PXDStateBasicVarSet.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 PXDStateBasicVarSet::extract(const BasePXDStateFilter::Object* pair)
26 {
27  const std::vector<TrackFindingCDC::WithWeight<const CKFToPXDState*>>& previousStates = pair->first;
28  CKFToPXDState* state = pair->second;
29 
30  const RecoTrack* seedTrack = previousStates.front()->getSeed();
31  B2ASSERT("Path without seed?", seedTrack);
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  firstMeasurement = previousStates.back()->getMeasuredStateOnPlane();
41  }
42 
43  Vector3D position = Vector3D(firstMeasurement.getPos());
44  Vector3D momentum = Vector3D(firstMeasurement.getMom());
45 
46  const CDCTrajectory3D trajectory(position, 0, momentum, seedTrack->getChargeSeed());
47 
48  const Vector3D& hitPosition = static_cast<Vector3D>(spacePoint->getPosition());
49 
50  const double arcLength = trajectory.calcArcLength2D(hitPosition);
51  const Vector2D& trackPositionAtHit2D = trajectory.getTrajectory2D().getPos2DAtArcLength2D(arcLength);
52  double trackPositionAtHitZ = trajectory.getTrajectorySZ().mapSToZ(arcLength);
53 
54  Vector3D trackPositionAtHit(trackPositionAtHit2D, trackPositionAtHitZ);
55  Vector3D distance = trackPositionAtHit - hitPosition;
56 
57  var<named("distance")>() = static_cast<Float_t>(distance.norm());
58  var<named("xy_distance")>() = static_cast<Float_t>(distance.xy().norm());
59  var<named("z_distance")>() = static_cast<Float_t>(distance.z());
60 
61  Vector3D mSoP_distance = position - hitPosition;
62 
63  var<named("mSoP_distance")>() = static_cast<Float_t>(mSoP_distance.norm());
64  var<named("mSoP_xy_distance")>() = static_cast<Float_t>(mSoP_distance.xy().norm());
65  var<named("mSoP_z_distance")>() = static_cast<Float_t>(mSoP_distance.z());
66 
67  var<named("same_hemisphere")>() = fabs(position.phi() - hitPosition.phi()) < TMath::PiOver2();
68 
69  var<named("arcLengthOfHitPosition")>() = static_cast<Float_t>(trajectory.calcArcLength2D(hitPosition));
70  var<named("arcLengthOfCenterPosition")>() = static_cast<Float_t>(trajectory.calcArcLength2D(Vector3D(0, 0, 0)));
71 
72  var<named("layer")>() = spacePoint->getVxdID().getLayerNumber();
73  var<named("number")>() = previousStates.size();
74 
75  var<named("pt")>() = static_cast<Float_t>(momentum.xy().norm());
76  var<named("tan_lambda")>() = static_cast<Float_t>(trajectory.getTanLambda());
77  var<named("phi")>() = static_cast<Float_t>(momentum.phi());
78 
79  const VxdID& sensorInfo = spacePoint->getVxdID();
80 
81  var<named("ladder")>() = sensorInfo.getLadderNumber();
82  var<named("sensor")>() = sensorInfo.getSensorNumber();
83  var<named("segment")>() = sensorInfo.getSegmentNumber();
84  var<named("id")>() = sensorInfo.getID();
85 
86  var<named("last_layer")>() = 0;
87  var<named("last_ladder")>() = 0;
88  var<named("last_sensor")>() = 0;
89  var<named("last_segment")>() = 0;
90  var<named("last_id")>() = 0;
91 
92  const CKFToPXDState* parent = previousStates.back();
93  const SpacePoint* parentSpacePoint = parent->getHit();
94  if (parentSpacePoint) {
95  const VxdID& parentSensorInfo = parentSpacePoint->getVxdID();
96 
97  var<named("last_layer")>() = parentSensorInfo.getLayerNumber();
98  var<named("last_ladder")>() = parentSensorInfo.getLadderNumber();
99  var<named("last_sensor")>() = parentSensorInfo.getSensorNumber();
100  var<named("last_segment")>() = parentSensorInfo.getSegmentNumber();
101  var<named("last_id")>() = parentSensorInfo.getID();
102  }
103 
104  const double residual = m_kalmanStepper.calculateResidual(firstMeasurement, *state);
105  var<named("residual")>() = residual;
106 
107  if (state->isFitted()) {
108  var<named("chi2")>() = static_cast<Float_t>(state->getChi2());
109  } else {
110  var<named("chi2")>() = -999;
111  }
112 
113  const TMatrixDSym& cov5 = firstMeasurement.getCov();
114  const Float_t sigmaUV = std::sqrt(std::max(cov5(4, 4), cov5(3, 3)));
115  var<named("sigma_uv")>() = sigmaUV;
116  var<named("residual_over_sigma")>() = residual / sigmaUV;
117 
118  return true;
119 }
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::CKFToPXDState
Specialized CKF State for extrapolating into the PXD.
Definition: CKFToPXDState.h:29
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::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