9#include <cdc/dataobjects/CDCRecoHit.h>
13#include <genfit/WireTrackCandHit.h>
14#include <genfit/AbsTrackRep.h>
15#include <genfit/RKTrackRep.h>
16#include <genfit/TrackPoint.h>
17#include <genfit/AbsFitterInfo.h>
18#include <genfit/Exception.h>
19#include <genfit/HMatrixU.h>
37 bool useTrackTime,
bool cosmics)
48 : genfit::AbsMeasurement(1),
49 m_tdcCount(0), m_adcCount(0), m_wireID(
WireID()), m_cdcHit(nullptr), m_leftRight(0)
54 : genfit::AbsMeasurement(1), m_cdcHit(cdcHit), m_leftRight(0)
57 B2FATAL(
"Can't produce CDCRecoHits without setting of the translators.");
66 const genfit::WireTrackCandHit* aTrackCandHitPtr =
dynamic_cast<const genfit::WireTrackCandHit*
>(trackCandHit);
67 if (aTrackCandHitPtr) {
68 signed char lrInfo = aTrackCandHitPtr->getLeftRightResolution();
69 B2DEBUG(250,
"l/r: " <<
int(lrInfo));
89 genfit::StateOnPlane st(state);
95 B2Vector3D noSagWireDirection = noSagWire2 - noSagWire1;
96 noSagWireDirection.
SetMag(1.);
99 const genfit::AbsTrackRep* rep = state.getRep();
100 rep->extrapolateToLine(st, noSagWire1, noSagWireDirection);
101 const B2Vector3D& noSagPoca = rep->getPos(st);
103 double zPOCA = (noSagWire1.
Z()
104 + noSagWireDirection.
Dot(noSagPoca - noSagWire1) * noSagWireDirection.
Z());
115 rep->extrapolateToLine(st, wire1, wireDirection);
119 const B2Vector3D& pocaOnWire = wire1 + wireDirection.
Dot(poca - wire1) * wireDirection;
126 if (fabs(wireDirection.
Angle(dirInPoca)) < 0.01) {
127 genfit::Exception exc(
"CDCRecoHit::constructPlane(): Cannot construct detector plane, direction is parallel to wire", __LINE__,
135 genfit::SharedPlanePtr pl = genfit::SharedPlanePtr(
new genfit::DetPlane(pocaOnWire, U, wireDirection));
142 double z = state.getPos().Z();
152 const double wx = state.getPlane()->getO().X();
153 const double wy = state.getPlane()->getO().Y();
154 const double px = p.X();
155 const double py = p.Y();
156 const double cross = wx * py - wy * px;
157 const double dot = wx * px + wy * py;
158 double alpha = atan2(cross,
dot);
159 double theta = atan2(p.Perp(), p.Z());
177 if (atan2(py, px) > 0.) {
200 static TVectorD m(1);
201 static TMatrixDSym cov(1);
205 auto mopR =
new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
209 auto mopL =
new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
234 double weight = 0.5 * pow(std::max(0., 1 - (mR + mL) / 2 / rMax), 2);
235 mopL->setWeight(weight);
236 mopR->setWeight(weight);
241 if (mL < 0. || mR < 0.) {
242 B2DEBUG(150,
"Ignoring hit with negative drift time.");
253 if (!
dynamic_cast<const genfit::RKTrackRep*
>(rep)) {
254 B2FATAL(
"CDCRecoHit can only handle state vectors of type RKTrackRep!");
257 return new genfit::HMatrixU();
263 double z = state.getPos().Z();
273 const double wx = state.getPlane()->getO().X();
274 const double wy = state.getPlane()->getO().Y();
275 const double px = p.X();
276 const double py = p.Y();
277 const double cross = wx * py - wy * px;
278 const double dot = wx * px + wy * py;
279 double alpha = atan2(cross,
dot);
280 double theta = atan2(p.Perp(), p.Z());
299 auto fL = [&](
const double & t) ->
double {
303 auto fR = [&](
const double & t) ->
double {
316 double rightShort[2], rightFull[2];
317 double leftShort[2], leftFull[2];
318 const double defaultStepT = 1e-3 * trackTime;
321 double temp = trackTime + defaultStepT / 2;
335 stepT = 2 * (temp - trackTime);
337 rightShort[0] = fL(trackTime + .5 * stepT);
338 rightShort[1] = fR(trackTime + .5 * stepT);
341 leftShort[0] = fL(trackTime - .5 * stepT);
342 leftShort[1] = fR(trackTime - .5 * stepT);
345 rightFull[0] = fL(trackTime + stepT);
346 rightFull[1] = fR(trackTime + stepT);
349 leftFull[0] = fL(trackTime - stepT);
350 leftFull[1] = fR(trackTime - stepT);
356 double derivShort[2];
357 for (
size_t j = 0; j < 2; ++j) {
358 derivFull[j] = (rightFull[j] - leftFull[j]) / (2.*stepT);
359 derivShort[j] = (rightShort[j] - leftShort[j]) / stepT;
362 return { +(4.*derivShort[0] - derivFull[0]) / 3.,
363 -(4.*derivShort[1] - derivFull[1]) / 3.};
370 const genfit::AbsTrackRep* rep,
371 bool usePlaneFromFit)
373 const genfit::TrackPoint* tp = this->getTrackPoint();
375 B2ERROR(
"No genfit::TrackPoint for CDCRecoHit.");
378 const genfit::AbsFitterInfo* fi = tp->getFitterInfo(rep);
380 B2DEBUG(200,
"No genfit::AbsFitterInfo for this CDCRecoHit.");
384 const genfit::MeasuredStateOnPlane& mop = fi->getFittedState();
392 ? mop.getPlane()->getO()
396 pointingVector = fittedPoca - pocaOnWire;
398 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.
This class is used to transfer CDC information to the track fit.
signed char m_leftRight
Flag showing left/right passage.
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.
unsigned short getISuperLayer() const
Getter for Super-Layer.
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Abstract base class for different kinds of events.