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