9#include <cdc/dataobjects/CDCRecoHit.h>
10#include <framework/utilities/MathHelpers.h>
14#include <genfit/WireTrackCandHit.h>
15#include <genfit/AbsTrackRep.h>
16#include <genfit/RKTrackRep.h>
17#include <genfit/TrackPoint.h>
18#include <genfit/AbsFitterInfo.h>
19#include <genfit/Exception.h>
20#include <genfit/HMatrixU.h>
38 bool useTrackTime,
bool cosmics)
49 : genfit::AbsMeasurement(1),
58 B2FATAL(
"Can't produce CDCRecoHits without setting of the translators.");
67 const genfit::WireTrackCandHit* aTrackCandHitPtr =
dynamic_cast<const genfit::WireTrackCandHit*
>(trackCandHit);
68 if (aTrackCandHitPtr) {
69 signed char lrInfo = aTrackCandHitPtr->getLeftRightResolution();
70 B2DEBUG(250,
"l/r: " <<
int(lrInfo));
90 genfit::StateOnPlane st(state);
96 B2Vector3D noSagWireDirection = noSagWire2 - noSagWire1;
97 noSagWireDirection.
SetMag(1.);
100 const genfit::AbsTrackRep* rep = state.getRep();
101 rep->extrapolateToLine(st, noSagWire1, noSagWireDirection);
102 const B2Vector3D& noSagPoca = rep->getPos(st);
104 double zPOCA = (noSagWire1.
Z()
105 + noSagWireDirection.
Dot(noSagPoca - noSagWire1) * noSagWireDirection.
Z());
116 rep->extrapolateToLine(st, wire1, wireDirection);
120 const B2Vector3D& pocaOnWire = wire1 + wireDirection.
Dot(poca - wire1) * wireDirection;
127 if (fabs(wireDirection.
Angle(dirInPoca)) < 0.01) {
128 genfit::Exception exc(
"CDCRecoHit::constructPlane(): Cannot construct detector plane, direction is parallel to wire", __LINE__,
136 genfit::SharedPlanePtr pl = genfit::SharedPlanePtr(
new genfit::DetPlane(pocaOnWire, U, wireDirection));
143 double z = state.getPos().Z();
153 const double wx = state.getPlane()->getO().X();
154 const double wy = state.getPlane()->getO().Y();
155 const double px = p.X();
156 const double py = p.Y();
157 const double cross = wx * py - wy * px;
158 const double dot = wx * px + wy * py;
159 double alpha = atan2(cross,
dot);
160 double theta = atan2(p.Perp(), p.Z());
178 if (atan2(py, px) > 0.) {
201 static TVectorD m(1);
202 static TMatrixDSym cov(1);
206 auto mopR =
new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
210 auto mopL =
new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
234 double rMax = 1.5 * (
m_wireID.getISuperLayer() == 0 ? 1. : 1.8);
235 double weight = 0.5 *
square(std::max(0., 1 - (mR + mL) / 2 / rMax));
236 mopL->setWeight(weight);
237 mopR->setWeight(weight);
242 if (mL < 0. || mR < 0.) {
243 B2DEBUG(150,
"Ignoring hit with negative drift time.");
254 if (!
dynamic_cast<const genfit::RKTrackRep*
>(rep)) {
255 B2FATAL(
"CDCRecoHit can only handle state vectors of type RKTrackRep!");
258 return new genfit::HMatrixU();
264 double z = state.getPos().Z();
274 const double wx = state.getPlane()->getO().X();
275 const double wy = state.getPlane()->getO().Y();
276 const double px = p.X();
277 const double py = p.Y();
278 const double cross = wx * py - wy * px;
279 const double dot = wx * px + wy * py;
280 double alpha = atan2(cross,
dot);
281 double theta = atan2(p.Perp(), p.Z());
300 auto fL = [&](
const double & t) ->
double {
304 auto fR = [&](
const double & t) ->
double {
317 double rightShort[2], rightFull[2];
318 double leftShort[2], leftFull[2];
319 const double defaultStepT = 1e-3 * trackTime;
322 double temp = trackTime + defaultStepT / 2;
336 stepT = 2 * (temp - trackTime);
338 rightShort[0] = fL(trackTime + .5 * stepT);
339 rightShort[1] = fR(trackTime + .5 * stepT);
342 leftShort[0] = fL(trackTime - .5 * stepT);
343 leftShort[1] = fR(trackTime - .5 * stepT);
346 rightFull[0] = fL(trackTime + stepT);
347 rightFull[1] = fR(trackTime + stepT);
350 leftFull[0] = fL(trackTime - stepT);
351 leftFull[1] = fR(trackTime - stepT);
357 double derivShort[2];
358 for (
size_t j = 0; j < 2; ++j) {
359 derivFull[j] = (rightFull[j] - leftFull[j]) / (2.*stepT);
360 derivShort[j] = (rightShort[j] - leftShort[j]) / stepT;
363 return { +(4.*derivShort[0] - derivFull[0]) / 3.,
364 -(4.*derivShort[1] - derivFull[1]) / 3.};
371 const genfit::AbsTrackRep* rep,
372 bool usePlaneFromFit)
374 const genfit::TrackPoint* tp = this->getTrackPoint();
376 B2ERROR(
"No genfit::TrackPoint for CDCRecoHit.");
379 const genfit::AbsFitterInfo* fi = tp->getFitterInfo(rep);
381 B2DEBUG(200,
"No genfit::AbsFitterInfo for this CDCRecoHit.");
385 const genfit::MeasuredStateOnPlane& mop = fi->getFittedState();
393 ? mop.getPlane()->getO()
397 pointingVector = fittedPoca - pocaOnWire;
399 trackDir = mop.getMom();
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
DataType Z() const
access variable Z (= .at(2) without boundary check)
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
short getTDCCount() const
Getter for TDC count.
unsigned short getID() const
Getter for encoded wire number.
unsigned short getADCCount() const
Getter for integrated charge.
signed char m_leftRight
Flag showing left/right passage.
const CDCHit * m_cdcHit
Pointer to the CDCHit used to created this CDCRecoHit.
std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
build MeasurementsOnPlane
static void setTranslators(CDC::ADCCountTranslatorBase *const adcCountTranslator, CDC::CDCGeometryTranslatorBase *const cdcGeometryTranslator, CDC::TDCCountTranslatorBase *const tdcCountTranslator, bool useTrackTime=false, bool cosmics=false)
Setter for the Translators.
static std::unique_ptr< CDC::ADCCountTranslatorBase > s_adcCountTranslator
Object for ADC Count translation.
unsigned short m_tdcCount
TDC Count as out of CDCHit.
static bool s_cosmics
Switch to use cosmic events, or physics events from IP.
unsigned short m_adcCount
ADC Count as out of CDCHit.
static bool s_useTrackTime
Whether to use the track time or not when building the measurementOnPlane.
bool getFlyByDistanceVector(B2Vector3D &pointingVector, B2Vector3D &trackDir, const genfit::AbsTrackRep *rep=nullptr, bool usePlaneFromFit=false)
Get the vector pointing from the wire to the fitted trajectory as well as the direction of the track ...
static std::unique_ptr< CDC::TDCCountTranslatorBase > s_tdcCountTranslator
Object for getting drift-length and -resolution.
std::vector< double > timeDerivativesMeasurementsOnPlane(const genfit::StateOnPlane &state) const
Get the time derivative of the MesuredStateOnPlane (derived from the track fit).
virtual const genfit::HMatrixU * constructHMatrix(const genfit::AbsTrackRep *) const override
construct error matrix
WireID m_wireID
Wire Identifier.
genfit::SharedPlanePtr constructPlane(const genfit::StateOnPlane &state) const override
Methods that actually interface to Genfit.
void setLeftRightResolution(int lr)
select how to resolve the left/right ambiguity: -1: negative (left) side on vector (wire direction) x...
CDCRecoHit()
Default Constructor for ROOT IO.
CDCRecoHit * clone() const override
Creating a copy of this hit.
static std::unique_ptr< CDC::CDCGeometryTranslatorBase > s_cdcGeometryTranslator
Object for geometry translation.
Abstract Base class for the ADC count translator.
Abstract Base class for the geometry translator.
Base class for translation of Drift Time into Drift Length.
Class to identify a wire inside the CDC.
constexpr T square(const T &x)
Calculate the square of the input.
B2Vector3< double > B2Vector3D
typedef for common usage with double
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Abstract base class for different kinds of events.