Belle II Software  release-08-01-10
DriftLengthEstimator.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/eventdata/utils/DriftLengthEstimator.h>
9 
10 #include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
15 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
16 
17 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
18 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
19 #include <tracking/trackFindingCDC/eventdata/hits/CDCFacet.h>
20 #include <tracking/trackFindingCDC/eventdata/hits/CDCRLWireHit.h>
21 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
22 
23 #include <tracking/trackFindingCDC/topology/CDCWire.h>
24 
25 #include <tracking/trackFindingCDC/geometry/UncertainParameterLine2D.h>
26 #include <tracking/trackFindingCDC/geometry/ParameterLine2D.h>
27 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
28 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
29 
30 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
31 #include <tracking/trackFindingCDC/numerics/Quadratic.h>
32 
33 #include <framework/core/ModuleParamList.templateDetails.h>
34 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
35 
36 #include <cdc/translators/RealisticTDCCountTranslator.h>
37 #include <cdc/dataobjects/CDCHit.h>
38 
39 using namespace Belle2;
40 using namespace TrackFindingCDC;
41 
42 
43 void DriftLengthEstimator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
44 {
45  moduleParamList->addParameter(prefixed(prefix, "useAlphaInDriftLength"),
47  "Switch to serve the alpha angle to the drift length translator",
49 
50  moduleParamList->addParameter(prefixed(prefix, "tofMassScale"),
52  "Mass to estimate the velocity in the flight time to the hit",
54 }
55 
57 {
58  CDC::RealisticTDCCountTranslator tdcCountTranslator;
59  const FlightTimeEstimator& flightTimeEstimator = FlightTimeEstimator::instance();
60 
61  Vector2D flightDirection = recoHit2D.getFlightDirection2D();
62  Vector2D recoPos2D = recoHit2D.getRecoPos2D();
63  double alpha = recoPos2D.angleWith(flightDirection);
64  const double beta = 1;
65  double flightTimeEstimate = flightTimeEstimator.getFlightTime2D(recoPos2D, alpha, beta);
66 
67  const CDCWire& wire = recoHit2D.getWire();
68  const CDCHit* hit = recoHit2D.getWireHit().getHit();
69  const bool rl = recoHit2D.getRLInfo() == ERightLeft::c_Right;
70 
72  alpha = 0;
73  }
74 
75  double driftLength = tdcCountTranslator.getDriftLength(hit->getTDCCount(),
76  wire.getWireID(),
77  flightTimeEstimate,
78  rl,
79  wire.getRefZ(),
80  alpha);
81  if (driftLength > -2 and driftLength < 16) {
82  bool snapRecoPos = true;
83  recoHit2D.setRefDriftLength(driftLength, snapRecoPos);
84  }
85  return driftLength;
86 }
87 
89 {
90  CDC::RealisticTDCCountTranslator tdcCountTranslator;
91  const FlightTimeEstimator& flightTimeEstimator = FlightTimeEstimator::instance();
92 
93  const UncertainParameterLine2D& line = facet.getFitLine();
94  Vector2D flightDirection = line->tangential();
95  Vector2D centralPos2D = line->closest(facet.getMiddleWire().getRefPos2D());
96  double alpha = centralPos2D.angleWith(flightDirection);
98  alpha = 0;
99  }
100 
101  auto doUpdate = [&](CDCRLWireHit & rlWireHit, Vector2D recoPos2D) {
102  const CDCWire& wire = rlWireHit.getWire();
103  const CDCHit* hit = rlWireHit.getWireHit().getHit();
104  const bool rl = rlWireHit.getRLInfo() == ERightLeft::c_Right;
105  const double beta = 1;
106  double flightTimeEstimate = flightTimeEstimator.getFlightTime2D(recoPos2D, alpha, beta);
107  double driftLength = tdcCountTranslator.getDriftLength(hit->getTDCCount(),
108  wire.getWireID(),
109  flightTimeEstimate,
110  rl,
111  wire.getRefZ(),
112  alpha);
113  rlWireHit.setRefDriftLength(driftLength);
114  };
115 
116  doUpdate(facet.getStartRLWireHit(), facet.getStartRecoPos2D());
117  doUpdate(facet.getMiddleRLWireHit(), facet.getMiddleRecoPos2D());
118  doUpdate(facet.getEndRLWireHit(), facet.getEndRecoPos2D());
119 
120  // More accurate implementation
121  // double startDriftLength = updateDriftLength(facet.getStartRecoHit2D());
122  // facet.getStartRLWireHit().setRefDriftLength(startDriftLength);
123 
124  // double middleDriftLength = updateDriftLength(facet.getMiddleRecoHit2D());
125  // facet.getMiddleRLWireHit().setRefDriftLength(middleDriftLength);
126 
127  // double endDriftLength = updateDriftLength(facet.getEndRecoHit2D());
128  // facet.getEndRLWireHit().setRefDriftLength(endDriftLength);
129 }
130 
132 {
133  for (CDCRecoHit2D& recoHit2D : segment) {
134  updateDriftLength(recoHit2D);
135  }
136 }
137 
139  double tanLambda)
140 {
141  CDC::RealisticTDCCountTranslator tdcCountTranslator;
142  const FlightTimeEstimator& flightTimeEstimator = FlightTimeEstimator::instance();
143 
144  Vector2D flightDirection = recoHit3D.getFlightDirection2D();
145  const Vector3D& recoPos3D = recoHit3D.getRecoPos3D();
146  const Vector2D& recoPos2D = recoPos3D.xy();
147  double alpha = recoPos2D.angleWith(flightDirection);
148  const double beta = 1;
149  double flightTimeEstimate = flightTimeEstimator.getFlightTime2D(recoPos2D, alpha, beta);
150 
151  if (std::isnan(tanLambda)) {
152  tanLambda = recoPos3D.z() / recoPos3D.cylindricalR();
153  }
154  const double theta = M_PI / 2 - std::atan(tanLambda);
155  flightTimeEstimate *= hypot2(1, tanLambda);
156 
157  const CDCWire& wire = recoHit3D.getWire();
158  const CDCHit* hit = recoHit3D.getWireHit().getHit();
159  const bool rl = recoHit3D.getRLInfo() == ERightLeft::c_Right;
160  double driftLength =
161  tdcCountTranslator.getDriftLength(hit->getTDCCount(),
162  wire.getWireID(),
163  flightTimeEstimate,
164  rl,
165  recoPos3D.z(),
166  alpha,
167  theta,
168  hit->getADCCount());
169  if (driftLength > -2 and driftLength < 16) {
170  bool snapRecoPos = true;
171  recoHit3D.setRecoDriftLength(driftLength, snapRecoPos);
172  }
173  return driftLength;
174 }
175 
176 
178  const double tanLambda)
179 {
180  for (CDCRecoHit3D& recoHit3D : segment3D) {
181  updateDriftLength(recoHit3D, tanLambda);
182  }
183 }
184 
186  const double tanLambda)
187 {
188  for (CDCRecoHit3D& recoHit3D : track) {
189  updateDriftLength(recoHit3D, tanLambda);
190  }
191 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Translator mirroring the realistic Digitization.
double getDriftLength(unsigned short tdcCount, const WireID &wireID=WireID(), double timeOfFlightEstimator=0, bool leftRight=false, double z=0, double alpha=0, double theta=static_cast< double >(TMath::Pi()/2.), unsigned short adcCount=0) override
Get Drift length.
The Module parameter list class.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition: CDCFacet.h:32
const UncertainParameterLine2D & getFitLine() const
Getter for the contained line fit information.
Definition: CDCFacet.h:61
Vector2D getEndRecoPos2D() const
Getter for the reconstructed position at the third hit on the fit line.
Definition: CDCFacet.cc:81
Vector2D getMiddleRecoPos2D() const
Getter for the reconstructed position at the second hit on the fit line.
Definition: CDCFacet.cc:76
Vector2D getStartRecoPos2D() const
Getter for the reconstructed position at the first hit on the fit line.
Definition: CDCFacet.cc:71
CDCRLWireHit & getEndRLWireHit()
Getter for the third oriented wire hit.
const CDCWire & getMiddleWire() const
Getter for the wire the second oriented wire hit is based on.
CDCRLWireHit & getMiddleRLWireHit()
Getter for the second oriented wire hit.
CDCRLWireHit & getStartRLWireHit()
Getter for the first oriented wire hit.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:41
void setRefDriftLength(double driftLength)
Setter for the drift length at the reference position of the wire.
Definition: CDCRLWireHit.h:210
const CDCWire & getWire() const
Getter for the wire the oriented hit associated to.
const CDCWireHit & getWireHit() const
Getter for the wire hit associated with the oriented hit.
Definition: CDCRLWireHit.h:192
ERightLeft getRLInfo() const
Getter for the right left passage information.
Definition: CDCRLWireHit.h:234
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
void setRefDriftLength(double driftLength, bool snapRecoPos)
Setter for the drift length at the wire reference position.
Vector2D getFlightDirection2D() const
Getter for the direction of flight.
Definition: CDCRecoHit2D.h:256
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:238
const CDCWireHit & getWireHit() const
Getter for the wire hit assoziated with the reconstructed hit.
Definition: CDCRecoHit2D.h:193
const CDCWire & getWire() const
Getter for the wire the reconstructed hit assoziated to.
Definition: CDCRecoHit2D.h:175
ERightLeft getRLInfo() const
Getter for the right left passage information.
Definition: CDCRecoHit2D.h:205
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
Vector2D getFlightDirection2D() const
Getter for the direction of flight.
Definition: CDCRecoHit3D.h:312
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
Definition: CDCRecoHit3D.h:285
const CDCWireHit & getWireHit() const
Getter for the wire hit.
Definition: CDCRecoHit3D.h:238
void setRecoDriftLength(double driftLength, bool snapRecoPos)
Setter to update the drift length of the hit.
const CDCWire & getWire() const
Getter for the wire.
Definition: CDCRecoHit3D.h:226
ERightLeft getRLInfo() const
Getter for the right left passage information.
Definition: CDCRecoHit3D.h:267
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:26
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:159
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
const Vector2D & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
Definition: CDCWire.h:229
const WireID & getWireID() const
Getter for the wire id.
Definition: CDCWire.h:122
double getRefZ() const
Getter for the wire reference z coordinate Gives the wire's reference z coordinate.
Definition: CDCWire.h:236
Helper struct to provide consistent flight time estimation throughout the CDC track finding.
static const FlightTimeEstimator & instance(std::unique_ptr< FlightTimeEstimator > replacement=nullptr)
Getter for the instance.
virtual double getFlightTime2D(const Vector2D &, double, double=1) const
Default estimator for the flight time.
A parameter line including including an line covariance matrix which is interpreted as located in the...
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:35
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition: Vector2D.h:209
A three dimensional vector.
Definition: Vector3D.h:33
double cylindricalR() const
Getter for the cylindrical radius ( xy projected norm )
Definition: Vector3D.h:534
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:508
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:496
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double atan(double a)
atan for double
Definition: beamHelpers.h:34
Abstract base class for different kinds of events.
double m_param_tofMassScale
Parameter : Mass to estimate the velocity in the flight time to the hit.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Add the parameters of the estimator to the module.
bool m_param_useAlphaInDriftLength
Parameter : Switch to serve the alpha angle to the drift length translator.
double updateDriftLength(CDCRecoHit2D &recoHit2D)
Update the drift length of the reconstructed hit in place.