Belle II Software development
AdvancedSegmentVarSet.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#include <tracking/trackFindingCDC/filters/segment/AdvancedSegmentVarSet.h>
9
10#include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
11
12#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
13#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
14
15#include <cdc/topology/CDCWireTopology.h>
16#include <cdc/topology/ISuperLayer.h>
17
18#include <cdc/dataobjects/CDCHit.h>
19
20#include <Math/Vector2D.h>
21
22using namespace Belle2;
23using namespace CDC;
24using namespace TrackFindingCDC;
25using namespace TrackingUtilities;
26
28{
29
30 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
31 ISuperLayer iSuperLayer = segment->getISuperLayer();
32 if (not ISuperLayerUtil::isInCDC(iSuperLayer)) {
33 return false;
34 }
35 const CDCWireSuperLayer& superLayer = wireTopology.getWireSuperLayer(iSuperLayer);
36 double superLayerCenter = superLayer.getMiddleCylindricalR();
37 unsigned int size = segment->size();
38
39 int totalNNeighbors = 0;
40 double totalInnerDistance = 0;
41 double totalDriftLength = 0;
42 double totalDriftLengthSquared = 0;
43 double driftVariance = 0;
44 double totalADCCount = 0;
45 double totalADCCountSquared = 0;
46 double adcCountVariance;
47 unsigned int numberOfTakenHits = 0;
48
49 // We have at most 8 layers per super layer. As one segment is only in one superlayer, we can assume 8 layers to save memory.
50 std::vector<bool> layerIsHit(8, false);
51
52 for (const CDCRecoHit2D& recoHit : *segment) {
53 const CDCWireHit& wireHit = recoHit.getWireHit();
54
55 if (wireHit.getAutomatonCell().hasTakenFlag()) {
56 numberOfTakenHits++;
57 }
58
59 // Layer is hit information
60 layerIsHit[wireHit.getWire().getILayer()] = true;
61
62 // Clusterizer writes the number of neighbors into the cell weight
63 int nNeighbors = wireHit.getAutomatonCell().getCellWeight();
64 totalNNeighbors += nNeighbors;
65
66 // hit position information
67 totalInnerDistance += wireHit.getRefPos2D().R();
68
69 // Drift circle information
70 double driftLength = wireHit.getRefDriftLength();
71 totalDriftLength += driftLength;
72 totalDriftLengthSquared += driftLength * driftLength;
73
74 // ADC information
75 double adc = static_cast<double>(wireHit.getHit()->getADCCount());
76 totalADCCount += adc;
77 totalADCCountSquared += adc * adc;
78 }
79
80 if (size > 1) {
81 double driftLengthVarianceSquared = (totalDriftLengthSquared - totalDriftLength * totalDriftLength / size) / (size - 1.0) ;
82 double adcVarianceSquared = (totalADCCountSquared - totalADCCount * totalADCCount / size) / (size - 1.0) ;
83
84 if (driftLengthVarianceSquared > 0) {
85 driftVariance = std::sqrt(driftLengthVarianceSquared);
86 } else {
87 driftVariance = 0;
88 }
89
90 if (adcVarianceSquared > 0) {
91 adcCountVariance = std::sqrt(adcVarianceSquared);
92 } else {
93 adcCountVariance = 0;
94 }
95
96 } else {
97 driftVariance = -1;
98 adcCountVariance = -1;
99 }
100
101 unsigned int numberOfHitLayers = 0;
102 for (bool hit : layerIsHit) {
103 if (hit) {
104 numberOfHitLayers++;
105 }
106 }
107
108 // Fit information
110 CDCTrajectory2D trajectory = fitter.fit(*segment);
111
112 var<named("is_stereo")>() = segment->getStereoKind() != EStereoKind::c_Axial;
113 var<named("size")>() = size;
114
115 var<named("number_of_taken_hits")>() = numberOfTakenHits;
116
117 var<named("number_of_hit_layers")>() = numberOfHitLayers;
118
119 var<named("total_number_of_neighbors")>() = totalNNeighbors;
120 var<named("total_drift_length")>() = totalDriftLength;
121 var<named("total_adc_count")>() = totalADCCount;
122 var<named("total_inner_distance")>() = totalInnerDistance;
123
124 var<named("variance_drift_length")>() = driftVariance;
125 var<named("variance_adc_count")>() = adcCountVariance;
126
127 var<named("distance_to_superlayer_center")>() = superLayerCenter - totalInnerDistance / size;
128 var<named("superlayer_id")>() = iSuperLayer;
129
130 var<named("mean_drift_length")>() = totalDriftLength / size;
131 var<named("mean_adc_count")>() = totalADCCount / size;
132 var<named("mean_inner_distance")>() = totalInnerDistance / size;
133 var<named("mean_number_of_neighbors")>() = 1.0 * totalNNeighbors / size;
134
135 var<named("fit_prob")>() = trajectory.getPValue();
136 var<named("fitted_d0")>() = trajectory.getDist2D(ROOT::Math::XYVector());
137 return true;
138}
Class representing a sense wire superlayer in the central drift chamber.
double getMiddleCylindricalR() const
Getter for the radius in the middle of the layer.
Class representing the sense wire arrangement in the whole of the central drift chamber.
const CDCWireSuperLayer & getWireSuperLayer(const WireID &wireID) const
Getter for wire superlayer getter by wireID object.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
ILayer getILayer() const
Getter for the layer id within its superlayer Gives the layer id within its superlayer ranging from ...
Definition CDCWire.h:151
bool extract(const TrackingUtilities::CDCSegment2D *segment) final
Generate and assign the contained variables.
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Weight getCellWeight() const
Getter for the cell weight.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Class representing a two dimensional reconstructed hit in the central drift chamber.
A reconstructed sequence of two dimensional hits in one super layer.
Particle trajectory as it is seen in xy projection represented as a circle.
double getPValue() const
Getter for p-value.
double getDist2D(const ROOT::Math::XYVector &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:56
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition CDCWireHit.h:160
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition CDCWireHit.h:225
const ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
const CDC::CDCWire & getWire() const
Getter for the CDCWire the hit is located on.
Definition CDCWireHit.h:169
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition CDCWireHit.h:287
static constexpr int named(const char *name)
Definition VarSet.h:78
signed short ISuperLayer
The type of the layer and superlayer ids.
Definition ISuperLayer.h:24
Abstract base class for different kinds of events.
static bool isInCDC(ISuperLayer iSuperLayer)
Indicates if the given number corresponds to a true cdc superlayer - excludes the logic ids for inner...