Belle II Software development
SVDStateVarSet.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
9#include <tracking/ckf/svd/filters/states/SVDStateVarSet.h>
10#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory3D.h>
11#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
12#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
13#include <tracking/dataobjects/RecoTrack.h>
14
15#include <Math/Vector3D.h>
16#include <Math/Vector2D.h>
17
18using namespace Belle2;
19using namespace TrackingUtilities;
20
21namespace {
23 template<class APredicate>
24 double meanOver(const std::vector<TrackingUtilities::WithWeight<const CKFToSVDState*>>& states, const APredicate& t)
25 {
26 double sum = 0;
27 unsigned int numberOfHits = 0;
28
29 for (const CKFToSVDState* walkState : states) {
30 const SpacePoint* spacePoint = walkState->getHit();
31 if (not spacePoint) {
32 continue;
33 }
34 for (auto& cluster : spacePoint->getRelationsTo<SVDCluster>()) {
35 numberOfHits++;
36 sum += t(cluster);
37 }
38 }
39
40 return sum / numberOfHits;
41 }
42
44 template<class APredicate>
45 double minOver(const std::vector<TrackingUtilities::WithWeight<const CKFToSVDState*>>& states, const APredicate& t)
46 {
47 double minimalValue = NAN;
48
49 for (const CKFToSVDState* walkState : states) {
50 const SpacePoint* spacePoint = walkState->getHit();
51 if (not spacePoint) {
52 continue;
53 }
54 for (auto& cluster : spacePoint->getRelationsTo<SVDCluster>()) {
55 double currentValue = t(cluster);
56 if (std::isnan(minimalValue)) {
57 minimalValue = currentValue;
58 } else {
59 minimalValue = std::min(currentValue, minimalValue);
60 }
61 }
62 }
63
64 return minimalValue;
65 }
66
68 template<class APredicate>
69 double stdOver(const std::vector<TrackingUtilities::WithWeight<const CKFToSVDState*>>& states, const APredicate& t)
70 {
71 double sum = 0;
72 double sumSquared = 0;
73 unsigned int numberOfHits = 0;
74
75 for (const CKFToSVDState* walkState : states) {
76 const SpacePoint* spacePoint = walkState->getHit();
77 if (not spacePoint) {
78 continue;
79 }
80 for (auto& cluster : spacePoint->getRelationsTo<SVDCluster>()) {
81 numberOfHits++;
82 const auto& currentValue = t(cluster);
83 sum += currentValue;
84 sumSquared += currentValue * currentValue;
85 }
86 }
87
88 return std::sqrt((sumSquared - sum * sum / numberOfHits) / (numberOfHits - 1));
89 }
90}
91
93{
94 const std::vector<TrackingUtilities::WithWeight<const CKFToSVDState*>>& previousStates = pair->first;
95 CKFToSVDState* state = pair->second;
96
97 const RecoTrack* cdcTrack = previousStates.front()->getSeed();
98 B2ASSERT("Path without seed?", cdcTrack);
99
100 const SpacePoint* spacePoint = state->getHit();
101 B2ASSERT("Path without hit?", spacePoint);
102
103 std::vector<TrackingUtilities::WithWeight<const CKFToSVDState*>> allStates = previousStates;
104 allStates.emplace_back(state, 0);
105
106 const std::vector<CDCHit*>& cdcHits = cdcTrack->getSortedCDCHitList();
107
108 var<named("seed_cdc_hits")>() = cdcHits.size();
109 var<named("seed_lowest_cdc_layer")>() = cdcHits.front()->getICLayer();
110
111 genfit::MeasuredStateOnPlane firstMeasurement;
112 if (state->mSoPSet()) {
113 firstMeasurement = state->getMeasuredStateOnPlane();
114 } else {
115 B2ASSERT("Previous state was not fitted?", previousStates.back()->mSoPSet());
116 firstMeasurement = previousStates.back()->getMeasuredStateOnPlane();
117 }
118
119 const ROOT::Math::XYZVector position = ROOT::Math::XYZVector(firstMeasurement.getPos());
120 const ROOT::Math::XYZVector momentum = ROOT::Math::XYZVector(firstMeasurement.getMom());
121
122 const CDCTrajectory3D trajectory(position, 0, momentum, cdcTrack->getChargeSeed());
123
124 const ROOT::Math::XYZVector& hitPosition = spacePoint->getPosition();
125
126 const double arcLength = trajectory.calcArcLength2D(hitPosition);
127 const ROOT::Math::XYVector& trackPositionAtHit2D = trajectory.getTrajectory2D().getPos2DAtArcLength2D(arcLength);
128 const double trackPositionAtHitZ = trajectory.getTrajectorySZ().mapSToZ(arcLength);
129
130 ROOT::Math::XYZVector trackPositionAtHit(trackPositionAtHit2D.X(), trackPositionAtHit2D.Y(), trackPositionAtHitZ);
131
132 const auto calculateCharge = [](const auto & s) {
133 return s.getCharge();
134 };
135 const auto calculateSeedCharge = [](const auto & s) {
136 return s.getSeedCharge();
137 };
138 const auto calculateSize = [](const auto & s) {
139 return s.getSize();
140 };
141 const auto calculateSNR = [](const auto & s) {
142 return s.getSNR();
143 };
144 const auto calculateChargeSizeRatio = [](const auto & s) {
145 return s.getCharge() / s.getSize();
146 };
147
148 if (spacePoint->getType() == VXD::SensorInfoBase::SensorType::SVD) {
149 const auto& clusters = spacePoint->getRelationsTo<SVDCluster>();
150
151 B2ASSERT("Must be related to exactly 2 clusters", clusters.size() == 2);
152 const SVDCluster* firstCluster = clusters[0];
153 const SVDCluster* secondCluster = clusters[1];
154
155 var<named("cluster_1_charge")>() = calculateCharge(*firstCluster);
156 var<named("cluster_2_charge")>() = calculateCharge(*secondCluster);
157 var<named("mean_rest_cluster_charge")>() = meanOver(allStates, calculateCharge);
158 var<named("min_rest_cluster_charge")>() = minOver(allStates, calculateCharge);
159 var<named("std_rest_cluster_charge")>() = stdOver(allStates, calculateCharge);
160
161 var<named("cluster_1_seed_charge")>() = calculateSeedCharge(*firstCluster);
162 var<named("cluster_2_seed_charge")>() = calculateSeedCharge(*secondCluster);
163 var<named("mean_rest_cluster_seed_charge")>() = meanOver(allStates, calculateSeedCharge);
164 var<named("min_rest_cluster_seed_charge")>() = minOver(allStates, calculateSeedCharge);
165 var<named("std_rest_cluster_seed_charge")>() = stdOver(allStates, calculateSeedCharge);
166
167 var<named("cluster_1_size")>() = calculateSize(*firstCluster);
168 var<named("cluster_2_size")>() = calculateSize(*secondCluster);
169 var<named("mean_rest_cluster_size")>() = meanOver(allStates, calculateSize);
170 var<named("min_rest_cluster_size")>() = minOver(allStates, calculateSize);
171 var<named("std_rest_cluster_size")>() = stdOver(allStates, calculateSize);
172
173 var<named("cluster_1_snr")>() = calculateSNR(*firstCluster);
174 var<named("cluster_2_snr")>() = calculateSNR(*secondCluster);
175 var<named("mean_rest_cluster_snr")>() = meanOver(allStates, calculateSNR);
176 var<named("min_rest_cluster_snr")>() = minOver(allStates, calculateSNR);
177 var<named("std_rest_cluster_snr")>() = stdOver(allStates, calculateSNR);
178
179 var<named("cluster_1_charge_over_size")>() = calculateChargeSizeRatio(*firstCluster);
180 var<named("cluster_2_charge_over_size")>() = calculateChargeSizeRatio(*secondCluster);
181 var<named("mean_rest_cluster_charge_over_size")>() = meanOver(allStates, calculateChargeSizeRatio);
182 var<named("min_rest_cluster_charge_over_size")>() = minOver(allStates, calculateChargeSizeRatio);
183 var<named("std_rest_cluster_charge_over_size")>() = stdOver(allStates, calculateChargeSizeRatio);
184 }
185
186 std::vector<const SpacePoint*> spacePoints;
187 for (const CKFToSVDState* walkState : allStates) {
188 const SpacePoint* sp = walkState->getHit();
189 if (sp) {
190 spacePoints.push_back(sp);
191 }
192 }
193
194 if (spacePoints.size() >= 3) {
195 var<named("quality_index_triplet")>() = m_qualityTriplet.estimateQuality(spacePoints);
196 var<named("quality_index_circle")>() = m_qualityCircle.estimateQuality(spacePoints);
197 var<named("quality_index_helix")>() = m_qualityHelix.estimateQuality(spacePoints);
198 } else {
199 var<named("quality_index_triplet")>() = 0;
200 var<named("quality_index_circle")>() = 0;
201 var<named("quality_index_helix")>() = 0;
202 }
203
204 return true;
205}
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlane() const
Get the mSoP if already set during extrapolation (or fitting)
Definition CKFState.h:93
const Hit * getHit() const
Return the SP this state is related to. May be nullptr.
Definition CKFState.h:66
bool mSoPSet() const
Is the mSoP already set? (= state was already extrapolated)
Definition CKFState.h:106
Specialized CKF State for extrapolating into the SVD.
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
std::vector< Belle2::RecoTrack::UsedCDCHit * > getSortedCDCHitList() const
Return a sorted list of cdc hits. Sorted by the sortingParameter.
Definition RecoTrack.h:470
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition RecoTrack.h:508
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition SVDCluster.h:29
QualityEstimatorRiemannHelixFit m_qualityHelix
Instance of the Riemann helix-fit class.
QualityEstimatorTripletFit m_qualityTriplet
Instance of the triplet-fit class.
QualityEstimatorCircleFit m_qualityCircle
Instance of the circle-fit class.
virtual bool extract(const BaseSVDStateFilter::Object *object) override
Generate and assign the variables from the VXD-CDC object.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition SpacePoint.h:42
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
Definition SpacePoint.h:145
const B2Vector3D & getPosition() const
return the position vector in global coordinates
Definition SpacePoint.h:138
ROOT::Math::XYVector getPos2DAtArcLength2D(double arcLength2D)
Getter for the position at a given two dimensional arc length.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
double calcArcLength2D(const ROOT::Math::XYZVector &point) const
Calculate the travel distance from the start position of the trajectory.
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
std::pair< const std::vector< TrackingUtilities::WithWeight< const CKFToSVDState * > >, CKFToSVDState * > Object
Definition Filter.dcl.h:35
static constexpr int named(const char *name)
Definition VarSet.h:78
A mixin class to attach a weight to an object.
Definition WithWeight.h:24
Abstract base class for different kinds of events.