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