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/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
13#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
14
15#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
16#include <tracking/trackFindingCDC/topology/ISuperLayer.h>
17
18#include <cdc/dataobjects/CDCHit.h>
19
20using namespace Belle2;
21using namespace TrackFindingCDC;
22
24{
25
26 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
27 ISuperLayer iSuperLayer = segment->getISuperLayer();
28 if (not ISuperLayerUtil::isInCDC(iSuperLayer)) {
29 return false;
30 }
31 const CDCWireSuperLayer& superLayer = wireTopology.getWireSuperLayer(iSuperLayer);
32 double superLayerCenter = superLayer.getMiddleCylindricalR();
33 unsigned int size = segment->size();
34
35 int totalNNeighbors = 0;
36 double totalInnerDistance = 0;
37 double totalDriftLength = 0;
38 double totalDriftLengthSquared = 0;
39 double driftVariance = 0;
40 double totalADCCount = 0;
41 double totalADCCountSquared = 0;
42 double adcCountVariance;
43 unsigned int numberOfTakenHits = 0;
44
45 // 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.
46 std::vector<bool> layerIsHit(8, false);
47
48 for (const CDCRecoHit2D& recoHit : *segment) {
49 const CDCWireHit& wireHit = recoHit.getWireHit();
50
51 if (wireHit.getAutomatonCell().hasTakenFlag()) {
52 numberOfTakenHits++;
53 }
54
55 // Layer is hit information
56 layerIsHit[wireHit.getWire().getILayer()] = true;
57
58 // Clusterizer writes the number of neighbors into the cell weight
59 int nNeighbors = wireHit.getAutomatonCell().getCellWeight();
60 totalNNeighbors += nNeighbors;
61
62 // hit position information
63 totalInnerDistance += wireHit.getRefPos2D().norm();
64
65 // Drift circle information
66 double driftLength = wireHit.getRefDriftLength();
67 totalDriftLength += driftLength;
68 totalDriftLengthSquared += driftLength * driftLength;
69
70 // ADC information
71 double adc = static_cast<double>(wireHit.getHit()->getADCCount());
72 totalADCCount += adc;
73 totalADCCountSquared += adc * adc;
74 }
75
76 if (size > 1) {
77 double driftLengthVarianceSquared = (totalDriftLengthSquared - totalDriftLength * totalDriftLength / size) / (size - 1.0) ;
78 double adcVarianceSquared = (totalADCCountSquared - totalADCCount * totalADCCount / size) / (size - 1.0) ;
79
80 if (driftLengthVarianceSquared > 0) {
81 driftVariance = std::sqrt(driftLengthVarianceSquared);
82 } else {
83 driftVariance = 0;
84 }
85
86 if (adcVarianceSquared > 0) {
87 adcCountVariance = std::sqrt(adcVarianceSquared);
88 } else {
89 adcCountVariance = 0;
90 }
91
92 } else {
93 driftVariance = -1;
94 adcCountVariance = -1;
95 }
96
97 unsigned int numberOfHitLayers = 0;
98 for (bool hit : layerIsHit) {
99 if (hit) {
100 numberOfHitLayers++;
101 }
102 }
103
104 // Fit information
106 CDCTrajectory2D trajectory = fitter.fit(*segment);
107
108 var<named("is_stereo")>() = segment->getStereoKind() != EStereoKind::c_Axial;
109 var<named("size")>() = size;
110
111 var<named("number_of_taken_hits")>() = numberOfTakenHits;
112
113 var<named("number_of_hit_layers")>() = numberOfHitLayers;
114
115 var<named("total_number_of_neighbors")>() = totalNNeighbors;
116 var<named("total_drift_length")>() = totalDriftLength;
117 var<named("total_adc_count")>() = totalADCCount;
118 var<named("total_inner_distance")>() = totalInnerDistance;
119
120 var<named("variance_drift_length")>() = driftVariance;
121 var<named("variance_adc_count")>() = adcCountVariance;
122
123 var<named("distance_to_superlayer_center")>() = superLayerCenter - totalInnerDistance / size;
124 var<named("superlayer_id")>() = iSuperLayer;
125
126 var<named("mean_drift_length")>() = totalDriftLength / size;
127 var<named("mean_adc_count")>() = totalADCCount / size;
128 var<named("mean_inner_distance")>() = totalInnerDistance / size;
129 var<named("mean_number_of_neighbors")>() = 1.0 * totalNNeighbors / size;
130
131 var<named("fit_prob")>() = trajectory.getPValue();
132 var<named("fitted_d0")>() = trajectory.getDist2D(Vector2D());
133 return true;
134}
unsigned short getADCCount() const
Getter for integrated charge.
Definition: CDCHit.h:230
bool extract(const CDCSegment2D *segment) final
Generate and assign the contained variables.
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.
Definition: CDCRecoHit2D.h:47
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
Particle trajectory as it is seen in xy projection represented as a circle.
double getPValue() const
Getter for p-value.
double getDist2D(const Vector2D &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:55
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:159
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition: CDCWireHit.h:224
const CDCWire & getWire() const
Getter for the CDCWire the hit is located on.
Definition: CDCWireHit.h:168
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCWireHit.h:286
const Vector2D & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
Definition: CDCWireHit.cc:212
Class representing a sense wire superlayer in the central drift chamber.
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:159
static constexpr int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:78
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:93
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition: Vector2D.h:32
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175
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...
Definition: ISuperLayer.cc:43