Belle II Software development
AlignableCDCRecoHit Class Reference

This class is used to transfer CDC information to the track fit and Millepede. More...

#include <AlignableCDCRecoHit.h>

Inheritance diagram for AlignableCDCRecoHit:
CDCRecoHit

Public Member Functions

 ~AlignableCDCRecoHit ()
 Destructor.
 
AlignableCDCRecoHitclone () const override
 Creating a copy of this hit.
 
virtual std::pair< std::vector< int >, TMatrixD > globalDerivatives (const genfit::StateOnPlane *sop) override
 Labels and derivatives of residuals (local measurement coordinates) w.r.t.
 
virtual TMatrixD localDerivatives (const genfit::StateOnPlane *sop) override
 Derivatives for (local) fit parameters.
 
 CDCRecoHit ()
 Inherit constructors.
 
 CDCRecoHit (const CDCHit *cdcHit, const genfit::TrackCandHit *trackCandHit)
 Inherit constructors.
 
WireID getWireID () const
 Getter for WireID object.
 
genfit::SharedPlanePtr constructPlane (const genfit::StateOnPlane &state) const override
 Methods that actually interface to Genfit.
 
std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane (const genfit::StateOnPlane &state) const override
 build MeasurementsOnPlane
 
virtual const genfit::HMatrixU * constructHMatrix (const genfit::AbsTrackRep *) const override
 construct error matrix
 
std::vector< double > timeDerivativesMeasurementsOnPlane (const genfit::StateOnPlane &state) const
 Get the time derivative of the MesuredStateOnPlane (derived from the track fit).
 
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 in the fitted point.
 
void setLeftRightResolution (int lr)
 select how to resolve the left/right ambiguity: -1: negative (left) side on vector (wire direction) x (track direction) 0: mirrors enter with same weight, DAF will decide.
 
bool isLeftRightMeasurement () const override
 CDC RecoHits always have left-right ambiguity.
 
int getLeftRightResolution () const override
 Getter for left/right passage flag.
 
const CDCHitgetCDCHit () const
 get the pointer to the CDCHit object that was used to create this CDCRecoHit object.
 

Static Public Member Functions

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 Public Attributes

static bool s_enableTrackT0LocalDerivative = true
 Static enabling(true) or disabling(false) addition of local derivative for track T0.
 
static bool s_enableWireSaggingGlobalDerivative = false
 Static enabling(true) or disabling(false) addition of global derivative for wire sagging coefficient (per wire)
 
static bool s_enableWireByWireAlignmentGlobalDerivatives = false
 Static enabling(true) or disabling(false) addition of global derivatives for wire-by-wire alignment.
 

Protected Member Functions

 ClassDefOverride (CDCRecoHit, 10)
 ROOT Macro.
 

Protected Attributes

unsigned short m_tdcCount
 TDC Count as out of CDCHit.
 
unsigned short m_adcCount
 ADC Count as out of CDCHit.
 
WireID m_wireID
 Wire Identifier.
 
const CDCHitm_cdcHit
 Pointer to the CDCHit used to created this CDCRecoHit.
 
signed char m_leftRight
 Flag showing left/right passage.
 

Static Protected Attributes

static std::unique_ptr< CDC::ADCCountTranslatorBases_adcCountTranslator = 0
 Object for ADC Count translation.
 
static std::unique_ptr< CDC::CDCGeometryTranslatorBases_cdcGeometryTranslator = 0
 Object for geometry translation.
 
static std::unique_ptr< CDC::TDCCountTranslatorBases_tdcCountTranslator = 0
 Object for getting drift-length and -resolution.
 
static bool s_useTrackTime = false
 Whether to use the track time or not when building the measurementOnPlane.
 
static bool s_cosmics = false
 Switch to use cosmic events, or physics events from IP.
 

Private Member Functions

 ClassDefOverride (AlignableCDCRecoHit, 1)
 ROOT Macro.
 

Detailed Description

This class is used to transfer CDC information to the track fit and Millepede.

Definition at line 21 of file AlignableCDCRecoHit.h.

Constructor & Destructor Documentation

◆ ~AlignableCDCRecoHit()

~AlignableCDCRecoHit ( )
inline

Destructor.

Definition at line 35 of file AlignableCDCRecoHit.h.

35{}

Member Function Documentation

◆ CDCRecoHit() [1/2]

Inherit constructors.

Definition at line 36 of file CDCRecoHit.cc.

48 : genfit::AbsMeasurement(1),
50{
51}
signed char m_leftRight
Flag showing left/right passage.
Definition: CDCRecoHit.h:153
const CDCHit * m_cdcHit
Pointer to the CDCHit used to created this CDCRecoHit.
Definition: CDCRecoHit.h:150
unsigned short m_tdcCount
TDC Count as out of CDCHit.
Definition: CDCRecoHit.h:141
unsigned short m_adcCount
ADC Count as out of CDCHit.
Definition: CDCRecoHit.h:144
WireID m_wireID
Wire Identifier.
Definition: CDCRecoHit.h:147
Class to identify a wire inside the CDC.
Definition: WireID.h:34

◆ CDCRecoHit() [2/2]

CDCRecoHit ( const CDCHit cdcHit,
const genfit::TrackCandHit *  trackCandHit 
)

Inherit constructors.

Definition at line 40 of file CDCRecoHit.cc.

54 : genfit::AbsMeasurement(1), m_cdcHit(cdcHit), m_leftRight(0)
55{
57 B2FATAL("Can't produce CDCRecoHits without setting of the translators.");
58 }
59
60 // get information from cdcHit into local variables.
61 m_wireID = cdcHit->getID();
62 m_tdcCount = cdcHit->getTDCCount();
63 m_adcCount = cdcHit->getADCCount();
64
65 // set l-r info
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));
71 }
72}
short getTDCCount() const
Getter for TDC count.
Definition: CDCHit.h:219
unsigned short getID() const
Getter for encoded wire number.
Definition: CDCHit.h:193
unsigned short getADCCount() const
Getter for integrated charge.
Definition: CDCHit.h:230
static std::unique_ptr< CDC::ADCCountTranslatorBase > s_adcCountTranslator
Object for ADC Count translation.
Definition: CDCRecoHit.h:120
static std::unique_ptr< CDC::TDCCountTranslatorBase > s_tdcCountTranslator
Object for getting drift-length and -resolution.
Definition: CDCRecoHit.h:126
void setLeftRightResolution(int lr)
select how to resolve the left/right ambiguity: -1: negative (left) side on vector (wire direction) x...
Definition: CDCRecoHit.h:100
static std::unique_ptr< CDC::CDCGeometryTranslatorBase > s_cdcGeometryTranslator
Object for geometry translation.
Definition: CDCRecoHit.h:123

◆ clone()

AlignableCDCRecoHit * clone ( ) const
inlineoverride

Creating a copy of this hit.

Definition at line 38 of file AlignableCDCRecoHit.h.

39 {
40 return new AlignableCDCRecoHit(*this);
41 }

◆ constructHMatrix()

const genfit::HMatrixU * constructHMatrix ( const genfit::AbsTrackRep *  rep) const
overridevirtualinherited

construct error matrix

Definition at line 251 of file CDCRecoHit.cc.

252{
253 if (!dynamic_cast<const genfit::RKTrackRep*>(rep)) {
254 B2FATAL("CDCRecoHit can only handle state vectors of type RKTrackRep!");
255 }
256
257 return new genfit::HMatrixU();
258}

◆ constructMeasurementsOnPlane()

std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane ( const genfit::StateOnPlane &  state) const
overrideinherited

build MeasurementsOnPlane

Definition at line 140 of file CDCRecoHit.cc.

141{
142 double z = state.getPos().Z();
143 const B2Vector3D& p = state.getMom();
144 // Calculate alpha and theta. A description was given in
145 // https://indico.mpp.mpg.de/getFile.py/access?contribId=5&sessionId=3&resId=0&materialId=slides&confId=3195
146
147//Comment out the following 2 lines since they introduce dependence on cdclib (or circular dependence betw. cdc_objects and cdclib).
148// double alpha = CDCGeometryPar::Instance().getAlpha(state.getPlane()->getO(), p);
149// double theta = CDCGeometryPar::Instance().getTheta(p);
150
151//N.B. The folowing 8 lines are tentative to avoid the circular dependence mentioned above ! The definitions of alpha and theta should be identical to those defined in CDCGeometryPar.
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());
160 /*
161 double alpha0 = CDCGeometryPar::Instance().getAlpha(state.getPlane()->getO(), p);
162 double theta0 = CDCGeometryPar::Instance().getTheta(p);
163 if (alpha != alpha0) {
164 std::cout <<"alpha,alpha0= " << alpha <<" "<< alpha0 << std::endl;
165 exit(-1);
166 }
167 if (theta != theta0) {;
168 std::cout <<"theta,theta0= " << theta <<" "<< theta0 << std::endl;
169 exit(-2);
170 }
171 */
172
173 double trackTime = s_useTrackTime ? state.getTime() : 0;
174 //temp4cosmics
175 // std::cout <<"phi,trackTime= " << atan2(py,px) <<" "<< trackTime << std::endl;
176 if (s_cosmics) {
177 if (atan2(py, px) > 0.) {
178 // if (atan2(wy,wx) > 0.) {
179 trackTime *= -1.;
180 }
181 }
182
183 // The meaning of the left / right flag (called
184 // 'ambiguityDiscriminator' in TDCCounTranslatorBase) is inferred
185 // from CDCGeometryPar::getNewLeftRightRaw().
186 double mL = s_tdcCountTranslator->getDriftLength(m_tdcCount, m_wireID, trackTime,
187 false, //left
188 z, alpha, theta, m_adcCount);
189 double mR = s_tdcCountTranslator->getDriftLength(m_tdcCount, m_wireID, trackTime,
190 true, //right
191 z, alpha, theta, m_adcCount);
192 double VL = s_tdcCountTranslator->getDriftLengthResolution(mL, m_wireID,
193 false, //left
194 z, alpha, theta);
195 double VR = s_tdcCountTranslator->getDriftLengthResolution(mR, m_wireID,
196 true, //right
197 z, alpha, theta);
198
199 // static to avoid constructing these over and over.
200 static TVectorD m(1);
201 static TMatrixDSym cov(1);
202
203 m(0) = mR;
204 cov(0, 0) = VR;
205 auto mopR = new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
206 constructHMatrix(state.getRep()));
207 m(0) = -mL; // Convert from unsigned drift length to signed coordinate.
208 cov(0, 0) = VL;
209 auto mopL = new genfit::MeasurementOnPlane(m, cov, state.getPlane(), state.getRep(),
210 constructHMatrix(state.getRep()));
211
212 // set left/right weights
213 if (m_leftRight < 0) {
214 mopL->setWeight(1);
215 mopR->setWeight(0);
216 } else if (m_leftRight > 0) {
217 mopL->setWeight(0);
218 mopR->setWeight(1);
219 } else {
220 // In absence of L/R information set equal weight for mirror hits.
221 // We have this weight decrease as the drift distance increases.
222 // Since the average will always be close to the wire, the bias
223 // introduced by the averaged hit would increase as the drift
224 // radius increases. Reducing the initial weight effectively
225 // counteracts this. This way the DAF can figure the ambiguities
226 // out quickly.
227 //
228 // Wire spacing in the radial direction according to TDR is 10 mm
229 // in the innermost superlayer, 18 mm otherwise. Use these values
230 // times a safety margin of 1.5 as upper bound for the drift
231 // radii. The max distance between the mirror hits is twice the
232 // maximal drift radius.
233 double rMax = 1.5 * (m_wireID.getISuperLayer() == 0 ? 1. : 1.8);
234 double weight = 0.5 * pow(std::max(0., 1 - (mR + mL) / 2 / rMax), 2);
235 mopL->setWeight(weight);
236 mopR->setWeight(weight);
237 }
238
239 // Ignore hits with negative drift times. For these, the
240 // TDCCountTranslator returns a negative drift length.
241 if (mL < 0. || mR < 0.) {
242 B2DEBUG(150, "Ignoring hit with negative drift time.");
243 mopL->setWeight(0);
244 mopR->setWeight(0);
245 }
246
247 return {mopL, mopR};
248}
static bool s_cosmics
Switch to use cosmic events, or physics events from IP.
Definition: CDCRecoHit.h:136
static bool s_useTrackTime
Whether to use the track time or not when building the measurementOnPlane.
Definition: CDCRecoHit.h:131
virtual const genfit::HMatrixU * constructHMatrix(const genfit::AbsTrackRep *) const override
construct error matrix
Definition: CDCRecoHit.cc:251
unsigned short getISuperLayer() const
Getter for Super-Layer.
Definition: WireID.h:130
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Definition: beamHelpers.h:163

◆ constructPlane()

genfit::SharedPlanePtr constructPlane ( const genfit::StateOnPlane &  state) const
overrideinherited

Methods that actually interface to Genfit.

Definition at line 80 of file CDCRecoHit.cc.

81{
82 // We find the plane in two steps: first we neglect wire sag to get
83 // a good estimate of the z coordinate of the crossing. Then we use
84 // this z coordinate to find the point of closest approach to the
85 // sagging wire and its local direction.
86
87 // Don't use clone: we don't want to extrapolate covariances if
88 // state is a genfit::MeasuredStateOnPlane.
89 genfit::StateOnPlane st(state);
90
91 const B2Vector3D& noSagWire1(s_cdcGeometryTranslator->getWireBackwardPosition(m_wireID));
92 const B2Vector3D& noSagWire2(s_cdcGeometryTranslator->getWireForwardPosition(m_wireID));
93
94 // unit vector along the wire
95 B2Vector3D noSagWireDirection = noSagWire2 - noSagWire1;
96 noSagWireDirection.SetMag(1.);
97
98 // point of closest approach
99 const genfit::AbsTrackRep* rep = state.getRep();
100 rep->extrapolateToLine(st, noSagWire1, noSagWireDirection);
101 const B2Vector3D& noSagPoca = rep->getPos(st);
102
103 double zPOCA = (noSagWire1.Z()
104 + noSagWireDirection.Dot(noSagPoca - noSagWire1) * noSagWireDirection.Z());
105
106 // Now re-extrapolate taking Z of trajectory into account.
107 const B2Vector3D& wire1(s_cdcGeometryTranslator->getWireBackwardPosition(m_wireID, zPOCA));
108 const B2Vector3D& wire2(s_cdcGeometryTranslator->getWireForwardPosition(m_wireID, zPOCA));
109
110 // unit vector along the wire (will become V of plane)
111 B2Vector3D wireDirection = wire2 - wire1;
112 wireDirection.SetMag(1.);
113
114 // point of closest approach
115 rep->extrapolateToLine(st, wire1, wireDirection);
116 const B2Vector3D& poca = rep->getPos(st);
117 B2Vector3D dirInPoca = rep->getMom(st);
118 dirInPoca.SetMag(1.);
119 const B2Vector3D& pocaOnWire = wire1 + wireDirection.Dot(poca - wire1) * wireDirection;
120 //temp
121 // std::cout << (noSagWire1 + noSagWireDirection.Dot(noSagPoca - noSagWire1) * noSagWireDirection).Y() <<" "<< pocaOnWire.Y() <<" " << (noSagWire1 + noSagWireDirection.Dot(noSagPoca - noSagWire1) * noSagWireDirection - pocaOnWire).Y() << std::endl;
122 // std::cout << (noSagWire1 + noSagWireDirection.Dot(noSagPoca - noSagWire1) * noSagWireDirection).Perp() <<" "<< pocaOnWire.Perp() << std::endl;
123 // std::cout << (noSagWire1 + noSagWireDirection.Dot(noSagPoca - noSagWire1) * noSagWireDirection).Z() <<" "<< pocaOnWire.Z() << std::endl;
124
125 // check if direction is parallel to wire
126 if (fabs(wireDirection.Angle(dirInPoca)) < 0.01) {
127 genfit::Exception exc("CDCRecoHit::constructPlane(): Cannot construct detector plane, direction is parallel to wire", __LINE__,
128 __FILE__);
129 throw exc;
130 }
131
132 // construct orthogonal (unit) vector
133 const B2Vector3D& U = wireDirection.Cross(dirInPoca);
134
135 genfit::SharedPlanePtr pl = genfit::SharedPlanePtr(new genfit::DetPlane(pocaOnWire, U, wireDirection));
136 //pl->Print();
137 return pl;
138}
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
Definition: B2Vector3.h:182
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Definition: B2Vector3.h:296
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
Definition: B2Vector3.h:290
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Definition: B2Vector3.h:302
ROOT::Math::XYZVector poca(ROOT::Math::XYZVector const &trackPos, ROOT::Math::XYZVector const &trackP, ROOT::Math::XYZVector const &vtxPos)
Returns the Point Of Closest Approach of a track to a vertex.

◆ getCDCHit()

const CDCHit * getCDCHit ( ) const
inlineinherited

get the pointer to the CDCHit object that was used to create this CDCRecoHit object.

Can be NULL if CDCRecoHit was not created with the CDCRecoHit(const CDCHit* cdcHit) constructor

Definition at line 112 of file CDCRecoHit.h.

113 {
114 return m_cdcHit;
115 }

◆ getFlyByDistanceVector()

bool getFlyByDistanceVector ( B2Vector3D pointingVector,
B2Vector3D trackDir,
const genfit::AbsTrackRep *  rep = nullptr,
bool  usePlaneFromFit = false 
)
inherited

Get the vector pointing from the wire to the fitted trajectory as well as the direction of the track in the fitted point.

Uses the cardinal TrackRep if rep == NULL. Returns false if the track is not fitted in this point for the requested TrackRep. If the hit does not belong to a track, an error is issued and false returned. If usePlaneFromFit is used, constructPlane is not called to evaluate the closest point on the wire to the track. Instead the origin of the plane of the fitted state is used (which will be the same point if the wire is not bent).

Definition at line 368 of file CDCRecoHit.cc.

372{
373 const genfit::TrackPoint* tp = this->getTrackPoint();
374 if (!tp) {
375 B2ERROR("No genfit::TrackPoint for CDCRecoHit.");
376 return false;
377 }
378 const genfit::AbsFitterInfo* fi = tp->getFitterInfo(rep);
379 if (!fi) {
380 B2DEBUG(200, "No genfit::AbsFitterInfo for this CDCRecoHit.");
381 return false;
382 }
383
384 const genfit::MeasuredStateOnPlane& mop = fi->getFittedState();
385 B2Vector3D fittedPoca = mop.getPos();
386 // constructPlane places the coordinate center in the POCA to the
387 // wire. Using this is the default behavior. If this should be too
388 // slow, as it has to re-evaluate the POCA, alternatively the user
389 // can set usePlaneFromFit which uses the plane determined by the
390 // track fit.
391 B2Vector3D pocaOnWire = (usePlaneFromFit
392 ? mop.getPlane()->getO()
393 : this->constructPlane(mop)->getO());
394
395 // The vector from the wire to the track.
396 pointingVector = fittedPoca - pocaOnWire;
397
398 trackDir = mop.getMom();
399 trackDir.SetMag(1.);
400 return true;
401}
genfit::SharedPlanePtr constructPlane(const genfit::StateOnPlane &state) const override
Methods that actually interface to Genfit.
Definition: CDCRecoHit.cc:80

◆ getLeftRightResolution()

int getLeftRightResolution ( ) const
inlineoverrideinherited

Getter for left/right passage flag.

Definition at line 106 of file CDCRecoHit.h.

106{ return m_leftRight; }

◆ getWireID()

WireID getWireID ( ) const
inlineinherited

Getter for WireID object.

Definition at line 49 of file CDCRecoHit.h.

50 {
51 return m_wireID;
52 }

◆ globalDerivatives()

std::pair< std::vector< int >, TMatrixD > globalDerivatives ( const genfit::StateOnPlane *  sop)
overridevirtual

Labels and derivatives of residuals (local measurement coordinates) w.r.t.

alignment/calibration parameters Matrix "G" of derivatives valid for given prediction of track state:

G(i, j) = d_residual_i/d_parameter_j

For 2D measurement (u,v):

G = ( du/da du/db du/dc ... ) ( dv/da dv/db dv/dc ... )

for calibration parameters a, b, c.

For 1D measurement:

G = ( 0 0 0 ... ) ( dv/da dv/db dv/dc ... ) for V-strip,

G = ( du/da du/db du/dc ... ) ( 0 0 0 ... ) for U-strip,

Measurements with more dimesions (slopes, curvature) should provide full 4-5Dx(n params) matrix (state as (q/p, u', v', u, v) or (u', v', u, v))

Parameters
sopPredicted state of the track as linearization point around which derivatives of alignment/calibration parameters shall be computed
Returns
pair<vector<int>, TMatrixD> With matrix with number of rows = dimension of residual, number of columns = number of parameters. number of columns must match vector<int>.size().

Definition at line 28 of file AlignableCDCRecoHit.cc.

29{
30 GlobalDerivatives globals;
31 unsigned short LR = (int(m_leftRight) > 0.) ? 1 : 0;
32
33 const B2Vector3D& mom = sop->getMom();
34 const B2Vector3D& wirePositon = sop->getPlane()->getO();
35 const unsigned short layer = getWireID().getICLayer();
36
38 double alpha = cdcgeo.getAlpha(wirePositon, mom);
39 double theta = cdcgeo.getTheta(mom);
40 const TVectorD& stateOnPlane = sop->getState();
41 const double driftLengthEstimate = std::abs(stateOnPlane(3));
42 const double driftTime = cdcgeo.getDriftTime(driftLengthEstimate, layer, LR, alpha, theta);
43 const double driftVelocity = cdcgeo.getDriftV(driftTime, layer, LR, alpha, theta);
44
45 // CDC Calibration -------------------------------------------------
46
47 // Time zero calibration (per wire)
48 if (driftTime > 20 && driftTime < 200 && fabs(driftVelocity) < 1.0e-2) {
49 globals.add(
50 GlobalLabel::construct<CDCTimeZeros>(getWireID(), 0),
51 driftVelocity * double(int(m_leftRight))
52 );
53 }
54
55 // Time walk calibration (per board)
56 if (driftTime > 20 && driftTime < 200 && fabs(driftVelocity) < 1.0e-2 && m_adcCount < 400 && m_adcCount > 2) {
58 unsigned short board = CDCGeometryPar::Instance().getBoardID(getWireID());
59 const std::vector<float> param = tws->getTimeWalkParams(board);
60 globals.add(
61 GlobalLabel::construct<CDCTimeWalks>(board, 0),
62 -driftVelocity * exp(-param[1]* m_adcCount) * double(int(m_leftRight))
63 );
64 globals.add(
65 GlobalLabel::construct<CDCTimeWalks>(board, 1),
66 driftVelocity * m_adcCount * param[0]*exp(-param[1]* m_adcCount) * double(int(m_leftRight))
67 );
68 }
69
70 // Space time relations calibration
71 if (driftTime > 20 && driftTime < 500 && fabs(driftVelocity) < 1.0e-2) {
72 // TODO: ugly to need to ask XTRelations for something here...
73 // Can't I get this CDCGeometryPar or sth. like this?
74
75 theta = cdcgeo.getOutgoingTheta(alpha, theta);
76 alpha = cdcgeo.getOutgoingAlpha(alpha);
78 auto xtid = xts->getXtID(getWireID().getICLayer(), LR, (float)alpha, (float)theta);
79 const auto& par = xts->getXtParams(xtid);
80 auto boundary = par.at(6);
81 if (driftTime < boundary) {
82 globals.add(
83 GlobalLabel::construct<CDCXtRelations>(xtid, 0),
84 ROOT::Math::Chebyshev5(driftTime, 1, 0, 0, 0, 0, 0) * double(int(m_leftRight))
85 );
86 globals.add(
87 GlobalLabel::construct<CDCXtRelations>(xtid, 1),
88 ROOT::Math::Chebyshev5(driftTime, 0, 1, 0, 0, 0, 0) * double(int(m_leftRight))
89 );
90 globals.add(
91 GlobalLabel::construct<CDCXtRelations>(xtid, 2),
92 ROOT::Math::Chebyshev5(driftTime, 0, 0, 1, 0, 0, 0) * double(int(m_leftRight))
93 );
94 globals.add(
95 GlobalLabel::construct<CDCXtRelations>(xtid, 3),
96 ROOT::Math::Chebyshev5(driftTime, 0, 0, 0, 1, 0, 0) * double(int(m_leftRight))
97 );
98 globals.add(
99 GlobalLabel::construct<CDCXtRelations>(xtid, 4),
100 ROOT::Math::Chebyshev5(driftTime, 0, 0, 0, 0, 1, 0) * double(int(m_leftRight))
101 );
102 globals.add(
103 GlobalLabel::construct<CDCXtRelations>(xtid, 5),
104 ROOT::Math::Chebyshev5(driftTime, 0, 0, 0, 0, 0, 1) * double(int(m_leftRight))
105 );
106 } else {
107 globals.add(
108 GlobalLabel::construct<CDCXtRelations>(xtid, 7),
109 double(int(m_leftRight))
110 );
111 globals.add(
112 GlobalLabel::construct<CDCXtRelations>(xtid, 8),
113 (driftTime - boundary) * double(int(m_leftRight))
114 );
115 }
116 }
117
118
119 // CDC Alignment ---------------------------------------------------
120
121 auto tdir = sop->getDir();
122 auto ndir = sop->getPlane()->getNormal();
123 auto udir = sop->getPlane()->getU();
124 auto vdir = sop->getPlane()->getV();
125 auto pos = sop->getPos();
126
127 auto tn = tdir[0] * ndir[0] + tdir[1] * ndir[1] + tdir[2] * ndir [2];
128 // d residual / d measurement
129 auto drdm = TMatrixD(3, 3);
130 drdm.UnitMatrix();
131 for (int i = 0; i < 3; ++i) {
132 for (int j = 0; j < 3; ++j) {
133 drdm(i, j) -= tdir[i] * ndir[j] / tn;
134 }
135 }
136 // d measurement / d global rigid body param
137 auto dmdg = TMatrixD(3, 6);
138 dmdg.Zero();
139 dmdg[0][0] = 1.; dmdg[0][4] = -pos[2]; dmdg[0][5] = pos[1];
140 dmdg[1][1] = 1.; dmdg[1][3] = pos[2]; dmdg[1][5] = -pos[0];
141 dmdg[2][2] = 1.; dmdg[2][3] = -pos[1]; dmdg[2][4] = pos[0];
142 // d local residual / d global residual
143 auto drldrg = TMatrixD(3, 3);
144 for (int i = 0; i < 3; ++i) {
145 drldrg(0, i) = udir[i];
146 drldrg(1, i) = vdir[i];
147 drldrg(2, i) = ndir[i];
148 }
149 // d local residual / d global rigid body param
150 auto drldg = drldrg * (drdm * dmdg);
151
152 // wire ends
153 const double zWireM = s_cdcGeometryTranslator->getWireBackwardPosition(getWireID(), CDCGeometryPar::c_Aligned)[2];
154 const double zWireP = s_cdcGeometryTranslator->getWireForwardPosition(getWireID(), CDCGeometryPar::c_Aligned)[2];
155 // relative Z position [0..1]
156 const double zRel = std::max(0., std::min(1., (pos[2] - zWireM) / (zWireP - zWireM)));
157
158 // Layer alignment
159 // wire 511 = no wire (0 is reserved for existing wires) - this has to be compatible with code in CDCGeometryPar::setWirPosAlignParams
160 auto layerID = WireID(getWireID().getICLayer(), 511);
161
162 // Alignment of layer X (bwd)
163 globals.add(
164 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerX),
165 drldg(0, 0)
166 );
167
168 // Alignment of layer Y (bwd)
169 globals.add(
170 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerY),
171 drldg(0, 1)
172 );
173
174 // Alignment of layer rotation (gamma) (bwd)
175 globals.add(
176 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerPhi),
177 drldg(0, 5)
178 );
179
180 // Difference between wire ends (end plates)
181 // Alignment of layer dX, dX = foward - backward endplate
182 globals.add(
183 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerDx),
184 drldg(0, 0) * zRel
185 );
186
187 // Alignment of layer dY, dY = foward - backward endplate
188 globals.add(
189 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerDy),
190 drldg(0, 1) * zRel
191 );
192
193 // Alignment of layer rotation difference d(gamma or phi), dPhi = foward - backward endplate
194 globals.add(
195 GlobalLabel::construct<CDCAlignment>(layerID, CDCAlignment::layerDPhi),
196 drldg(0, 5) * zRel
197 );
198
199 //WARNING: experimental (disabled by default)
200 // Wire-by-wire alignment
202 // How much shift (in X or Y) on BWD wire-end will change the residual at estimated track crossing
203 // with the wire (at relative z-position on wire = zRel)
204 double zRelM = fabs(1. - zRel);
205 // Same as above but for FWD wire-end (residual at zRel = zRel * delta(X or Y at FWD wire-end)
206 double zRelP = fabs(zRel - 0.);
207
208 // Alignment of wires X in global coords at BWD wire-end
209 globals.add(
210 GlobalLabel::construct<CDCAlignment>(getWireID().getEWire(), CDCAlignment::wireBwdX),
211 drldg(0, 0) * zRelM
212 );
213 // Alignment of wires X in global coords at FWD wire-end
214 globals.add(
215 GlobalLabel::construct<CDCAlignment>(getWireID().getEWire(), CDCAlignment::wireFwdX),
216 drldg(0, 0) * zRelP
217 );
218
219 // Alignment of wires Y in global coords at BWD wire-end
220 globals.add(
221 GlobalLabel::construct<CDCAlignment>(getWireID().getEWire(), CDCAlignment::wireBwdY),
222 drldg(0, 1) * zRelM
223 );
224 // Alignment of wires Y in global coords at FWD wire-end
225 globals.add(
226 GlobalLabel::construct<CDCAlignment>(getWireID().getEWire(), CDCAlignment::wireFwdY),
227 drldg(0, 1) * zRelP
228 );
229 }
230
231 //WARNING: experimental (disabled by default)
232 //TODO: missing some factors (we do not align directly the wire-sag coefficient, but
233 // wire tension ... coef = pi * ro * r * r / 8 / tension
234 //TODO: need to get these numbers from CDCGeometryPar!
236 globals.add(
237 GlobalLabel::construct<CDCAlignment>(getWireID().getEWire(), CDCAlignment::wireTension),
238 drldg(0, 1) * 4.0 * zRel * (1.0 - zRel)
239 );
240 }
241
242
243
244 return globals;
245}
static bool s_enableWireSaggingGlobalDerivative
Static enabling(true) or disabling(false) addition of global derivative for wire sagging coefficient ...
static bool s_enableWireByWireAlignmentGlobalDerivatives
Static enabling(true) or disabling(false) addition of global derivatives for wire-by-wire alignment.
static const baseType layerDPhi
Layer rotation in global X-Y plane (gamma) dPhi = foward - backward endplate.
Definition: CDCAlignment.h:61
static const baseType layerDy
Layer shift in global Y dY = foward - backward endplate.
Definition: CDCAlignment.h:59
static const baseType layerDx
Layer shift in global X dX = foward - backward endplate.
Definition: CDCAlignment.h:57
static const baseType wireBwdY
Wire Y position w.r.t. nominal on backward endplate.
Definition: CDCAlignment.h:31
static const baseType wireFwdY
Wire Y position w.r.t. nominal on forward endplate.
Definition: CDCAlignment.h:37
static const baseType wireFwdX
Wire X position w.r.t. nominal on forward endplate.
Definition: CDCAlignment.h:35
static const baseType wireBwdX
Wire X position w.r.t. nominal on backward endplate.
Definition: CDCAlignment.h:29
static const baseType layerY
Layer shift in global Y at backward endplate.
Definition: CDCAlignment.h:52
static const baseType layerX
Layer shift in global X at backward endplate.
Definition: CDCAlignment.h:50
static const baseType layerPhi
Layer rotation in global X-Y plane (gamma) at backward endplate.
Definition: CDCAlignment.h:54
static const baseType wireTension
Wire tension w.r.t. nominal (=50. ?)
Definition: CDCAlignment.h:43
WireID getWireID() const
Getter for WireID object.
Definition: CDCRecoHit.h:49
The Class for CDC Geometry Parameters.
double getTheta(const B2Vector3D &momentum) const
Returns track incident angle (theta in rad.).
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
double getAlpha(const B2Vector3D &posOnWire, const B2Vector3D &momentum) const
Returns track incident angle in rphi plane (alpha in rad.).
double getDriftV(double dt, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Get the realistic drift velocity.
double getOutgoingAlpha(const double alpha) const
Converts incoming- to outgoing-alpha.
double getOutgoingTheta(const double alpha, const double theta) const
Converts incoming- to outgoing-theta.
double getDriftTime(double dist, unsigned short layer, unsigned short lr, double alpha, double theta) const
Return the drift time to the sense wire.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:24

◆ isLeftRightMeasurement()

bool isLeftRightMeasurement ( ) const
inlineoverrideinherited

CDC RecoHits always have left-right ambiguity.

Definition at line 103 of file CDCRecoHit.h.

103{ return true; }

◆ localDerivatives()

TMatrixD localDerivatives ( const genfit::StateOnPlane *  sop)
overridevirtual

Derivatives for (local) fit parameters.

Parameters
sopState on virtual plane to calculate derivatives
Returns
TMatrixD of local derivatives, number of columns = number of params, number of rows = 2 (or measurement dimension if > 2)

Definition at line 248 of file AlignableCDCRecoHit.cc.

249{
251 return TMatrixD();
252
253 unsigned short LR = (int(m_leftRight) > 0.) ? 1 : 0;
254
255 const B2Vector3D& mom = sop->getMom();
256 const B2Vector3D& wirePositon = sop->getPlane()->getO();
257 const unsigned short layer = getWireID().getICLayer();
258
260 const double alpha = cdcgeo.getAlpha(wirePositon, mom);
261 const double theta = cdcgeo.getTheta(mom);
262 const TVectorD& stateOnPlane = sop->getState();
263 const double driftLengthEstimate = std::abs(stateOnPlane(3));
264 const double driftTime = cdcgeo.getDriftTime(driftLengthEstimate, layer, LR, alpha, theta);
265 const double driftVelocity = cdcgeo.getDriftV(driftTime, layer, LR, alpha, theta);
266
267 TMatrixD locals(2, 1);
268 if (driftTime > 20 && driftTime < 200 && fabs(driftVelocity) < 1.0e-2) {
269 locals(0, 0) = - double(int(m_leftRight)) * driftVelocity;
270 locals(1, 0) = 0.; // insesitive coordinate along wire
271 }
272
273 return locals;
274}
static bool s_enableTrackT0LocalDerivative
Static enabling(true) or disabling(false) addition of local derivative for track T0.

◆ setLeftRightResolution()

void setLeftRightResolution ( int  lr)
inlineinherited

select how to resolve the left/right ambiguity: -1: negative (left) side on vector (wire direction) x (track direction) 0: mirrors enter with same weight, DAF will decide.

1: positive (right) side on vector (wire direction) x (track direction) where the wire direction is pointing towards +z except for small corrections such as stereo angle, sagging

Definition at line 100 of file CDCRecoHit.h.

100{ m_leftRight = lr; }

◆ setTranslators()

void setTranslators ( CDC::ADCCountTranslatorBase *const  adcCountTranslator,
CDC::CDCGeometryTranslatorBase *const  cdcGeometryTranslator,
CDC::TDCCountTranslatorBase *const  tdcCountTranslator,
bool  useTrackTime = false,
bool  cosmics = false 
)
staticinherited

Setter for the Translators.

Definition at line 33 of file CDCRecoHit.cc.

38{
39 s_adcCountTranslator.reset(adcCountTranslator);
40 s_cdcGeometryTranslator.reset(cdcGeometryTranslator);
41 s_tdcCountTranslator.reset(tdcCountTranslator);
42 s_useTrackTime = useTrackTime;
43 //temp4cosmics
44 s_cosmics = cosmics;
45}

◆ timeDerivativesMeasurementsOnPlane()

std::vector< double > timeDerivativesMeasurementsOnPlane ( const genfit::StateOnPlane &  state) const
inherited

Get the time derivative of the MesuredStateOnPlane (derived from the track fit).


Definition at line 261 of file CDCRecoHit.cc.

262{
263 double z = state.getPos().Z();
264 const B2Vector3D& p = state.getMom();
265 // Calculate alpha and theta. A description was given by in
266 // https://indico.mpp.mpg.de/getFile.py/access?contribId=5&sessionId=3&resId=0&materialId=slides&confId=3195
267
268//Comment out the following 2 lines since they introduce dependence on cdclib (or circular dependence betw. cdc_objects and cdclib).
269// double alpha = CDCGeometryPar::Instance().getAlpha(state.getPlane()->getO(), p);
270// double theta = CDCGeometryPar::Instance().getTheta(p);
271
272//N.B. The folowing 8 lines are tentative to avoid the circular dependence mentioned above ! The definitions of alpha and theta should be identical to those defined in CDCGeometryPar.
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());
281 /*
282 double alpha0 = CDCGeometryPar::Instance().getAlpha(state.getPlane()->getO(), p);
283 double theta0 = CDCGeometryPar::Instance().getTheta(p);
284 if (alpha != alpha0) {
285 std::cout <<"alpha,alpha0= " << alpha <<" "<< alpha0 << std::endl;
286 exit(-1);
287 }
288 if (theta != theta0) {;
289 std::cout <<"theta,theta0= " << theta <<" "<< theta0 << std::endl;
290 exit(-2);
291 }
292 */
293
294 double trackTime = s_useTrackTime ? state.getTime() : 0;
295
296 // The meaning of the left / right flag (called
297 // 'ambiguityDiscriminator' in TDCCounTranslatorBase) is inferred
298 // from CDCGeometryPar::getNewLeftRightRaw().
299 auto fL = [&](const double & t) -> double {
300 return s_tdcCountTranslator->getDriftLength(m_tdcCount, m_wireID, t,
301 false, //left
302 z, alpha, theta, m_adcCount); };
303 auto fR = [&](const double & t) -> double {
304 return s_tdcCountTranslator->getDriftLength(m_tdcCount, m_wireID, t,
305 true, //right
306 z, alpha, theta, m_adcCount); };
307
308 // Calculate derivative for all left and right mirror hit.
309 //
310 // It's a polynomial, but let's not meddle with the innard of the
311 // CDC code for now.
312 //
313 // The algorithm follows the one in TF1::Derivative() :
314 // df(x) = (4 D(h/2) - D(h)) / 3
315 // with D(h) = (f(x + h) - f(x - h)) / (2 h).
316 double rightShort[2], rightFull[2];
317 double leftShort[2], leftFull[2];
318 const double defaultStepT = 1e-3 * trackTime;
319 double stepT;
320 {
321 double temp = trackTime + defaultStepT / 2;
322 // Find the actual size of the step, which will differ from
323 // defaultStepX due to roundoff. This is the step-size we will
324 // use for this direction. Idea taken from Numerical Recipes,
325 // 3rd ed., section 5.7.
326 //
327 // Note that if a number is exactly representable, it's double
328 // will also be exact. Outside denormals, this also holds for
329 // halving. Unless the exponent changes (which it only will in
330 // the vicinity of zero) adding or subtracing doesn't make a
331 // difference.
332 //
333 // We determine the roundoff error for the half-step. If this
334 // is exactly representable, the full step will also be.
335 stepT = 2 * (temp - trackTime);
336
337 rightShort[0] = fL(trackTime + .5 * stepT);
338 rightShort[1] = fR(trackTime + .5 * stepT);
339 }
340 {
341 leftShort[0] = fL(trackTime - .5 * stepT);
342 leftShort[1] = fR(trackTime - .5 * stepT);
343 }
344 {
345 rightFull[0] = fL(trackTime + stepT);
346 rightFull[1] = fR(trackTime + stepT);
347 }
348 {
349 leftFull[0] = fL(trackTime - stepT);
350 leftFull[1] = fR(trackTime - stepT);
351 }
352
353 // Calculate the derivatives for the individual components of
354 // the track parameters.
355 double derivFull[2];
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;
360 }
361 //std::cout << rightShort[0] << " " << derivShort[0] << " " << trackTime << std::endl;
362 return { +(4.*derivShort[0] - derivFull[0]) / 3.,
363 -(4.*derivShort[1] - derivFull[1]) / 3.};
364}

Member Data Documentation

◆ m_adcCount

unsigned short m_adcCount
protectedinherited

ADC Count as out of CDCHit.

Definition at line 144 of file CDCRecoHit.h.

◆ m_cdcHit

const CDCHit* m_cdcHit
protectedinherited

Pointer to the CDCHit used to created this CDCRecoHit.

Definition at line 150 of file CDCRecoHit.h.

◆ m_leftRight

signed char m_leftRight
protectedinherited

Flag showing left/right passage.

Definition at line 153 of file CDCRecoHit.h.

◆ m_tdcCount

unsigned short m_tdcCount
protectedinherited

TDC Count as out of CDCHit.

Definition at line 141 of file CDCRecoHit.h.

◆ m_wireID

WireID m_wireID
protectedinherited

Wire Identifier.

Definition at line 147 of file CDCRecoHit.h.

◆ s_adcCountTranslator

std::unique_ptr< ADCCountTranslatorBase > s_adcCountTranslator = 0
staticprotectedinherited

Object for ADC Count translation.

Definition at line 120 of file CDCRecoHit.h.

◆ s_cdcGeometryTranslator

std::unique_ptr< CDCGeometryTranslatorBase > s_cdcGeometryTranslator = 0
staticprotectedinherited

Object for geometry translation.

Definition at line 123 of file CDCRecoHit.h.

◆ s_cosmics

bool s_cosmics = false
staticprotectedinherited

Switch to use cosmic events, or physics events from IP.

Default value is 0, which means "physics event" mode.

Definition at line 136 of file CDCRecoHit.h.

◆ s_enableTrackT0LocalDerivative

bool s_enableTrackT0LocalDerivative = true
static

Static enabling(true) or disabling(false) addition of local derivative for track T0.

Definition at line 25 of file AlignableCDCRecoHit.h.

◆ s_enableWireByWireAlignmentGlobalDerivatives

bool s_enableWireByWireAlignmentGlobalDerivatives = false
static

Static enabling(true) or disabling(false) addition of global derivatives for wire-by-wire alignment.

Definition at line 29 of file AlignableCDCRecoHit.h.

◆ s_enableWireSaggingGlobalDerivative

bool s_enableWireSaggingGlobalDerivative = false
static

Static enabling(true) or disabling(false) addition of global derivative for wire sagging coefficient (per wire)

Definition at line 27 of file AlignableCDCRecoHit.h.

◆ s_tdcCountTranslator

std::unique_ptr< TDCCountTranslatorBase > s_tdcCountTranslator = 0
staticprotectedinherited

Object for getting drift-length and -resolution.

Definition at line 126 of file CDCRecoHit.h.

◆ s_useTrackTime

bool s_useTrackTime = false
staticprotectedinherited

Whether to use the track time or not when building the measurementOnPlane.

This needs to be in sync with the TDCCountTranslator.

Definition at line 131 of file CDCRecoHit.h.


The documentation for this class was generated from the following files: