48 : theFitter{std::make_unique<DTLinearFit>()},
57 if (config.
exists(
"intime_cut"))
61 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
76 cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
78 const bool hasPhi = seg->
hasPhi();
79 const bool hasZed = seg->
hasZed();
85 int step = (hasPhi && hasZed) ? 3 : 2;
90 cout <<
"Step of update is " << step << endl;
108 cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
113 fit(seg, allow3par,
false);
118 cout <<
"[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
123 cout <<
" 4D Segment contains a Phi segment. t0= " << seg->
phiSegment()->
t0()
126 cout <<
" 4D Segment contains a Zed segment. t0= " << seg->
zSegment()->
t0()
182 }
else if (seg->
hasPhi()) {
195 }
else if (seg->
hasZed()) {
238 for (DTSegmentCand::AssPointCont::const_iterator iter = seg->
hits().begin(); iter != seg->
hits().end(); ++iter) {
239 LocalPoint pos = (*iter).first->localPosition((*iter).second);
249 dist.push_back(distance);
250 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
251 x.push_back(pos.
z());
252 y.push_back(pos.
x());
264 fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par);
266 t0_corr = -cminf / 0.00543;
268 if (
debug && fitdebug)
269 cout <<
" DTcand chi2: " << chi2 <<
"/" << x.size() <<
" t0: " << t0_corr << endl;
286 cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
304 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
308 x.push_back(pos.
z());
309 y.push_back(pos.
x());
313 float distance = fabs(
hit->localPosition().
x() - xwire);
314 dist.push_back(distance);
325 sigy.push_back(
sqrt(slErr.
xx()));
336 fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par, block3par);
338 t0_corr = -cminf / 0.00543;
341 cout <<
" DTSeg2d chi2: " << chi2 << endl;
343 cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
356 const vector<float>&
y,
357 const vector<int>& lfit,
358 const vector<double>& dist,
359 const vector<float>& sigy,
366 const bool allow3par,
367 const bool block3par)
const {
369 float intercept = 0.;
377 int leftHits = 0, rightHits = 0;
378 for (
unsigned int i = 0;
i < lfit.size();
i++)
388 if (leftHits && rightHits && (leftHits + rightHits > 3) && allow3par) {
389 theFitter->fitNpar(3, x, y, lfit, dist, sigy, slope, intercept, cminf, vminf, chi2,
debug);
390 double t0_corr = -cminf / 0.00543;
391 if (fabs(t0_corr) <
intime_cut && block3par) {
410 covMatrix[0][0] = covss;
411 covMatrix[1][1] = covii;
412 covMatrix[1][0] = covsi;
422 vector<DTRecHit1D> updatedRecHits;
424 for (vector<DTRecHit1D>::iterator
hit = toBeUpdatedRecHits.begin();
hit != toBeUpdatedRecHits.end(); ++
hit) {
431 const float angle = atan(segDir.
x() / -segDir.
z());
440 ok =
theAlgo->compute(layer, *
hit, angle, newHit1D);
442 }
else if (step == 3) {
443 LocalPoint hitPos(
hit->localPosition().
x(), +segPosAtLayer.y(), 0.);
445 newHit1D.setPosition(hitPos);
446 ok =
theAlgo->compute(layer, *
hit, angle, glbpos, newHit1D);
448 }
else if (step == 4) {
456 cminf = -seg->
t0() * 0.00543;
463 const float distance = fabs(
hit->localPosition().
x() - xwire);
465 const double dy_corr = (vminf * ilc * distance - cminf * ilc);
473 newHit1D.setPositionAndError(point, error);
479 throw cms::Exception(
"DTSegmentUpdator") <<
" updateHits called with wrong step " << endl;
482 updatedRecHits.push_back(newHit1D);
484 LogError(
"DTSegmentUpdator") <<
"DTSegmentUpdator::updateHits failed update" << endl;
485 throw cms::Exception(
"DTSegmentUpdator") <<
"updateHits failed update" << endl;
488 seg->
update(updatedRecHits);
496 cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
499 const size_t N = hits.size();
503 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
508 x.push_back(pos.
z());
509 y.push_back(pos.
x());
513 cout <<
" end of segment! " << endl;
514 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
518 float par[2] = {0., 0.};
527 for (
size_t i = 0;
i <
N; ++
i) {
530 Sx2 += x.at(
i) * x.at(
i);
531 Sy2 += y.at(
i) * y.at(
i);
532 Sxy += x.at(
i) * y.at(
i);
535 const float delta = N * Sx2 - Sx * Sx;
536 par[0] = (Sx2 * Sy - Sx * Sxy) / delta;
537 par[1] = (N * Sxy - Sx * Sy) / delta;
540 cout <<
"fit 2 parameters done ----> par0: " << par[0] <<
" par1: " << par[1] << endl;
544 float mean_residual = 0.;
545 for (
size_t i = 0;
i <
N; ++
i) {
546 residuals[
i] = y.at(
i) - par[1] * x.at(
i) - par[0];
549 cout <<
" i: " << i <<
" y_i " << y.at(i) <<
" x_i " << x.at(i) <<
" res_i " << residuals[
i];
556 cout <<
" Residuals computed! " << endl;
558 mean_residual = mean_residual / (N - 2);
560 cout <<
" mean_residual: " << mean_residual << endl;
565 vector<DTRecHit1D> updatedRecHits;
566 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
567 float normResidual = mean_residual > 0 ?
std::abs(residuals[i]) / mean_residual : 0;
569 if (normResidual < 1.5) {
571 updatedRecHits.push_back(newHit1D);
573 cout <<
" accepted " << i <<
"th hit"
574 <<
" Irej: " << normResidual << endl;
577 cout <<
" rejected " << i <<
"th hit"
578 <<
" Irej: " << normResidual << endl;
583 phiSeg->
update(updatedRecHits);
590 cout <<
" Check the update action: " << endl;
593 for (vector<DTRecHit1D>::const_iterator
hit = hits_upd.begin();
hit != hits_upd.end(); ++
hit) {
598 x_upd.push_back(pos.
z());
599 y_upd.push_back(pos.
x());
601 cout <<
" x_upd: " << pos.
z() <<
" y_upd: " << pos.
x() << endl;
604 cout <<
" end of segment! " << endl;
605 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
623 cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
625 vector<double> d_drift;
635 for (vector<DTRecHit1D>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
642 float distance = fabs(
hit->localPosition().
x() - xwire);
647 x.push_back(pos.
z());
648 y.push_back(pos.
x());
650 d_drift.push_back(distance);
662 theFitter->fit4Var(x, y, lc, d_drift, nptfit, a, b, cminf, vminf, chi2fit,
vdrift_4parfit,
debug);
664 double t0cor = -999.;
666 t0cor = -cminf / 0.00543;
T getUntrackedParameter(std::string const &, T const &) const
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)
Local3DVector LocalVector
DTSegmentUpdator(const edm::ParameterSet &config, edm::ConsumesCollector)
Constructor.
LocalPoint localPosition() const override
local position in SL frame
Point3DBase< Scalar, LocalTag > LocalPoint
LocalVector localDirection() const override
the local direction in SL frame
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
void calculateT0corr(DTRecSegment2D *seg) const
double chi2() const override
the chi2 of the fit
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
LocalVector localDirection() const override
Local direction in Chamber frame.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~DTSegmentUpdator()
Destructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
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)
Log< level::Error, false > LogError
void update(std::vector< DTRecHit1D > &updatedRecHits)
LocalPoint localPosition() const override
Local position in Chamber frame.
edm::ESHandle< DTGeometry > theGeom
constexpr std::array< uint8_t, layerIndexSize > layer
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)
AlgebraicSymMatrix parametersError() const override
void setDirection(LocalVector dir)
Set direction.
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.
T getParameter(std::string const &) const
void setT0(const double &t0)
tuple config
parse the configuration file
virtual void setDirection(LocalVector &dir)
set direction
void setPosition(const LocalPoint &pos)
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theGeomToken
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)
DetId geographicalId() const
virtual void setPosition(LocalPoint &pos)
set position
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
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
T angle(T x1, T y1, T z1, T x2, T y2, T z2)