Belle II Software  release-05-02-19
AdvancedSegmentVarSet.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/filters/segment/AdvancedSegmentVarSet.h>
11 
12 #include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
15 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
16 
17 #include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
18 #include <tracking/trackFindingCDC/topology/ISuperLayer.h>
19 
20 #include <cdc/dataobjects/CDCHit.h>
21 
22 using namespace Belle2;
23 using namespace TrackFindingCDC;
24 
26 {
27 
28  const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
29  ISuperLayer iSuperLayer = segment->getISuperLayer();
30  if (not ISuperLayerUtil::isInCDC(iSuperLayer)) {
31  return false;
32  }
33  const CDCWireSuperLayer& superLayer = wireTopology.getWireSuperLayer(iSuperLayer);
34  double superLayerCenter = superLayer.getMiddleCylindricalR();
35  unsigned int size = segment->size();
36 
37  int totalNNeighbors = 0;
38  double totalInnerDistance = 0;
39  double totalDriftLength = 0;
40  double totalDriftLengthSquared = 0;
41  double driftVariance = 0;
42  double totalADCCount = 0;
43  double totalADCCountSquared = 0;
44  double adcCountVariance;
45  unsigned int numberOfTakenHits = 0;
46 
47  // 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.
48  std::vector<bool> layerIsHit(8, false);
49 
50  for (const CDCRecoHit2D& recoHit : *segment) {
51  const CDCWireHit& wireHit = recoHit.getWireHit();
52 
53  if (wireHit.getAutomatonCell().hasTakenFlag()) {
54  numberOfTakenHits++;
55  }
56 
57  // Layer is hit information
58  layerIsHit[wireHit.getWire().getILayer()] = true;
59 
60  // Clusterizer writes the number of neighbors into the cell weight
61  int nNeighbors = wireHit.getAutomatonCell().getCellWeight();
62  totalNNeighbors += nNeighbors;
63 
64  // hit position information
65  totalInnerDistance += wireHit.getRefPos2D().norm();
66 
67  // Drift circle information
68  double driftLength = wireHit.getRefDriftLength();
69  totalDriftLength += driftLength;
70  totalDriftLengthSquared += driftLength * driftLength;
71 
72  // ADC information
73  double adc = static_cast<double>(wireHit.getHit()->getADCCount());
74  totalADCCount += adc;
75  totalADCCountSquared += adc * adc;
76  }
77 
78  if (size > 1) {
79  double driftLengthVarianceSquared = (totalDriftLengthSquared - totalDriftLength * totalDriftLength / size) / (size - 1.0) ;
80  double adcVarianceSquared = (totalADCCountSquared - totalADCCount * totalADCCount / size) / (size - 1.0) ;
81 
82  if (driftLengthVarianceSquared > 0) {
83  driftVariance = std::sqrt(driftLengthVarianceSquared);
84  } else {
85  driftVariance = 0;
86  }
87 
88  if (adcVarianceSquared > 0) {
89  adcCountVariance = std::sqrt(adcVarianceSquared);
90  } else {
91  adcCountVariance = 0;
92  }
93 
94  } else {
95  driftVariance = -1;
96  adcCountVariance = -1;
97  }
98 
99  unsigned int numberOfHitLayers = 0;
100  for (bool hit : layerIsHit) {
101  if (hit) {
102  numberOfHitLayers++;
103  }
104  }
105 
106  // Fit information
108  CDCTrajectory2D trajectory = fitter.fit(*segment);
109 
110  var<named("is_stereo")>() = segment->getStereoKind() != EStereoKind::c_Axial;
111  var<named("size")>() = size;
112 
113  var<named("number_of_taken_hits")>() = numberOfTakenHits;
114 
115  var<named("number_of_hit_layers")>() = numberOfHitLayers;
116 
117  var<named("total_number_of_neighbors")>() = totalNNeighbors;
118  var<named("total_drift_length")>() = totalDriftLength;
119  var<named("total_adc_count")>() = totalADCCount;
120  var<named("total_inner_distance")>() = totalInnerDistance;
121 
122  var<named("variance_drift_length")>() = driftVariance;
123  var<named("variance_adc_count")>() = adcCountVariance;
124 
125  var<named("distance_to_superlayer_center")>() = superLayerCenter - totalInnerDistance / size;
126  var<named("superlayer_id")>() = iSuperLayer;
127 
128  var<named("mean_drift_length")>() = totalDriftLength / size;
129  var<named("mean_adc_count")>() = totalADCCount / size;
130  var<named("mean_inner_distance")>() = totalInnerDistance / size;
131  var<named("mean_number_of_neighbors")>() = 1.0 * totalNNeighbors / size;
132 
133  var<named("fit_prob")>() = trajectory.getPValue();
134  var<named("fitted_d0")>() = trajectory.getDist2D(Vector2D());
135  return true;
136 }
Belle2::TrackFindingCDC::CDCWireHit::getAutomatonCell
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCWireHit.h:294
Belle2::TrackFindingCDC::CDCTrajectory2D::getPValue
double getPValue() const
Getter for p-value.
Definition: CDCTrajectory2D.h:472
Belle2::TrackFindingCDC::CDCRiemannFitter
Class implementing the Riemann fit for two dimensional trajectory circle.
Definition: CDCRiemannFitter.h:34
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::CDCWireHit::getRefDriftLength
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition: CDCWireHit.h:232
Belle2::TrackFindingCDC::CDCWireHit::getRefPos2D
const Vector2D & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
Definition: CDCWireHit.cc:214
Belle2::TrackFindingCDC::CDCWireTopology::getInstance
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Definition: CDCWireTopology.cc:22
Belle2::TrackFindingCDC::CDCWireHit::getHit
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:167
Belle2::TrackFindingCDC::AutomatonCell::getCellWeight
Weight getCellWeight() const
Getter for the cell weight.
Definition: AutomatonCell.h:126
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::CDCWire::getILayer
ILayer getILayer() const
Getter for the layer id within its superlayer Gives the layer id within its superlayer ranging from ...
Definition: CDCWire.h:161
Belle2::CDCHit::getADCCount
unsigned short getADCCount() const
Getter for integrated charge.
Definition: CDCHit.h:241
Belle2::TrackFindingCDC::AdvancedSegmentVarSet::extract
bool extract(const CDCSegment2D *segment) final
Generate and assign the contained variables.
Definition: AdvancedSegmentVarSet.cc:25
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ISuperLayerUtil::isInCDC
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:45
Belle2::TrackFindingCDC::CDCWireTopology::getWireSuperLayer
const CDCWireSuperLayer & getWireSuperLayer(const WireID &wireID) const
Getter for wire superlayer getter by wireID object.
Definition: CDCWireTopology.h:181
Belle2::TrackFindingCDC::AutomatonCell::hasTakenFlag
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Definition: AutomatonCell.h:249
Belle2::TrackFindingCDC::CDCWireHit::getWire
const CDCWire & getWire() const
Getter for the CDCWire the hit is located on.
Definition: CDCWireHit.h:176
Belle2::TrackFindingCDC::CDCWireSuperLayer
Class representating a sense wire superlayer in the central drift chamber.
Definition: CDCWireSuperLayer.h:53
Belle2::TrackFindingCDC::CDCRiemannFitter::getFitter
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Definition: CDCRiemannFitter.cc:22
Belle2::TrackFindingCDC::Vector2D::norm
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:189
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::VarSet< AdvancedSegmentVarNames >::named
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:88
Belle2::TrackFindingCDC::CDCTrajectory2D::getDist2D
double getDist2D(const Vector2D &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Definition: CDCTrajectory2D.h:419
Belle2::TrackFindingCDC::VarSet< AdvancedSegmentVarNames >::var
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:103
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54