48 : theFitter{std::make_unique<DTLinearFit>()},
54 debug(
config.getUntrackedParameter<
bool>(
"debug",
false)) {
56 if (
config.exists(
"intime_cut"))
60 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
75 cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
77 const bool hasPhi = seg->
hasPhi();
78 const bool hasZed = seg->
hasZed();
84 int step = (hasPhi && hasZed) ? 3 : 2;
89 cout <<
"Step of update is " << step << endl;
107 cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
112 fit(seg, allow3par,
false);
117 cout <<
"[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
122 cout <<
" 4D Segment contains a Phi segment. t0= " << seg->
phiSegment()->
t0()
125 cout <<
" 4D Segment contains a Zed segment. t0= " << seg->
zSegment()->
t0()
181 }
else if (seg->
hasPhi()) {
194 }
else if (seg->
hasZed()) {
237 for (DTSegmentCand::AssPointCont::const_iterator iter = seg->
hits().begin(); iter != seg->
hits().end(); ++iter) {
238 LocalPoint pos = (*iter).first->localPosition((*iter).second);
248 dist.push_back(distance);
249 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
250 x.push_back(pos.
z());
251 y.push_back(pos.
x());
263 fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par);
265 t0_corr = -cminf / 0.00543;
267 if (
debug && fitdebug)
268 cout <<
" DTcand chi2: " << chi2 <<
"/" << x.size() <<
" t0: " << t0_corr << endl;
285 cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
303 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
307 x.push_back(pos.
z());
308 y.push_back(pos.
x());
312 float distance = fabs(
hit->localPosition().
x() - xwire);
313 dist.push_back(distance);
324 sigy.push_back(
sqrt(slErr.
xx()));
335 fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par, block3par);
337 t0_corr = -cminf / 0.00543;
340 cout <<
" DTSeg2d chi2: " << chi2 << endl;
342 cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
355 const vector<float>&
y,
356 const vector<int>& lfit,
357 const vector<double>& dist,
358 const vector<float>& sigy,
365 const bool allow3par,
366 const bool block3par)
const {
368 float intercept = 0.;
376 int leftHits = 0, rightHits = 0;
377 for (
unsigned int i = 0;
i < lfit.size();
i++)
387 if (leftHits && rightHits && (leftHits + rightHits > 3) && allow3par) {
388 theFitter->fitNpar(3, x, y, lfit, dist, sigy, slope, intercept, cminf, vminf, chi2,
debug);
389 double t0_corr = -cminf / 0.00543;
390 if (fabs(t0_corr) <
intime_cut && block3par) {
409 covMatrix[0][0] = covss;
410 covMatrix[1][1] = covii;
411 covMatrix[1][0] = covsi;
421 vector<DTRecHit1D> updatedRecHits;
423 for (vector<DTRecHit1D>::iterator
hit = toBeUpdatedRecHits.begin();
hit != toBeUpdatedRecHits.end(); ++
hit) {
430 const float angle = atan(segDir.
x() / -segDir.
z());
439 ok =
theAlgo->compute(layer, *
hit, angle, newHit1D);
441 }
else if (step == 3) {
442 LocalPoint hitPos(
hit->localPosition().
x(), +segPosAtLayer.y(), 0.);
444 newHit1D.setPosition(hitPos);
445 ok =
theAlgo->compute(layer, *
hit, angle, glbpos, newHit1D);
447 }
else if (step == 4) {
455 cminf = -seg->
t0() * 0.00543;
462 const float distance = fabs(
hit->localPosition().
x() - xwire);
464 const double dy_corr = (vminf * ilc * distance - cminf * ilc);
472 newHit1D.setPositionAndError(point, error);
478 throw cms::Exception(
"DTSegmentUpdator") <<
" updateHits called with wrong step " << endl;
481 updatedRecHits.push_back(newHit1D);
483 LogError(
"DTSegmentUpdator") <<
"DTSegmentUpdator::updateHits failed update" << endl;
484 throw cms::Exception(
"DTSegmentUpdator") <<
"updateHits failed update" << endl;
487 seg->
update(updatedRecHits);
495 cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
498 const size_t N = hits.size();
502 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
507 x.push_back(pos.
z());
508 y.push_back(pos.
x());
512 cout <<
" end of segment! " << endl;
513 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
517 float par[2] = {0., 0.};
526 for (
size_t i = 0;
i <
N; ++
i) {
529 Sx2 += x.at(
i) * x.at(
i);
530 Sy2 += y.at(
i) * y.at(
i);
531 Sxy += x.at(
i) * y.at(
i);
534 const float delta = N * Sx2 - Sx * Sx;
535 par[0] = (Sx2 * Sy - Sx * Sxy) / delta;
536 par[1] = (N * Sxy - Sx * Sy) / delta;
539 cout <<
"fit 2 parameters done ----> par0: " << par[0] <<
" par1: " << par[1] << endl;
543 float mean_residual = 0.;
544 for (
size_t i = 0;
i <
N; ++
i) {
545 residuals[
i] = y.at(
i) - par[1] * x.at(
i) - par[0];
548 cout <<
" i: " << i <<
" y_i " << y.at(i) <<
" x_i " << x.at(i) <<
" res_i " << residuals[
i];
555 cout <<
" Residuals computed! " << endl;
557 mean_residual = mean_residual / (N - 2);
559 cout <<
" mean_residual: " << mean_residual << endl;
564 vector<DTRecHit1D> updatedRecHits;
565 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
566 float normResidual = mean_residual > 0 ?
std::abs(residuals[i]) / mean_residual : 0;
568 if (normResidual < 1.5) {
570 updatedRecHits.push_back(newHit1D);
572 cout <<
" accepted " << i <<
"th hit" 573 <<
" Irej: " << normResidual << endl;
576 cout <<
" rejected " << i <<
"th hit" 577 <<
" Irej: " << normResidual << endl;
582 phiSeg->
update(updatedRecHits);
589 cout <<
" Check the update action: " << endl;
592 for (vector<DTRecHit1D>::const_iterator
hit = hits_upd.begin();
hit != hits_upd.end(); ++
hit) {
597 x_upd.push_back(pos.
z());
598 y_upd.push_back(pos.
x());
600 cout <<
" x_upd: " << pos.
z() <<
" y_upd: " << pos.
x() << endl;
603 cout <<
" end of segment! " << endl;
604 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
622 cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
624 vector<double> d_drift;
634 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
641 float distance = fabs(
hit->localPosition().
x() - xwire);
646 x.push_back(pos.
z());
647 y.push_back(pos.
x());
649 d_drift.push_back(distance);
661 theFitter->fit4Var(x, y, lc, d_drift, nptfit, a, b, cminf, vminf, chi2fit,
vdrift_4parfit,
debug);
663 double t0cor = -999.;
665 t0cor = -cminf / 0.00543;
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
void rejectBadHits(DTChamberRecSegment2D *) const
void setChi2(const double &chi2)
LocalPoint localPosition() const override
Local position in Chamber frame.
Local3DVector LocalVector
Point3DBase< Scalar, LocalTag > LocalPoint
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
void calculateT0corr(DTRecSegment2D *seg) const
LocalVector localDirection() const override
Local direction in Chamber frame.
DTChamberId chamberId() const
Return the corresponding ChamberId.
static const double slope[3]
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
virtual const AssPointCont & hits() const
the used hits
~DTSegmentUpdator()
Destructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
AlgebraicSymMatrix parametersError() const override
virtual void setChi2(double &chi2)
set chi2
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void setCovMatrix(const AlgebraicSymMatrix &cov)
void setCovMatrixForZed(const LocalPoint &posZInCh)
void update(std::vector< DTRecHit1D > &updatedRecHits)
edm::ESHandle< DTGeometry > theGeom
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
Geom::Theta< T > theta() const
const DTTopology & specificTopology() const
void setES(const edm::EventSetup &setup)
set the setup
bool perform_delta_rejecting
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
Cos< T >::type cos(const T &t)
std::unique_ptr< DTLinearFit > theFitter
Abs< T >::type abs(const T &t)
void setDirection(LocalVector dir)
Set direction.
double chi2() const override
the chi2 of the fit
bool hasPhi() const
Does it have the Phi projection?
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
Vector3DBase unit() const
bool hasZed() const
Does it have the Z projection?
virtual void sett0(double &t0)
set t0
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
LocalPoint localPosition() const override
local position in SL frame
void setT0(const double &t0)
virtual void setDirection(LocalVector &dir)
set direction
LocalVector localDirection() const override
the local direction in SL frame
const GeomDet * idToDet(DetId) const override
void setPosition(const LocalPoint &pos)
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setDirection(const LocalVector &dir)
void setPosition(LocalPoint pos)
Set position.
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
void setVdrift(const double &vdrift)
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
DetId geographicalId() const
virtual void setPosition(LocalPoint &pos)
set position
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
DTSegmentUpdator(const edm::ParameterSet &config)
Constructor.
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)