48 : theFitter{std::make_unique<DTLinearFit>()},
51 theGeomToken(
cc.esConsumes()),
52 vdrift_4parfit(
config.getParameter<
bool>(
"performT0_vdriftSegCorrection")),
55 debug(
config.getUntrackedParameter<
bool>(
"debug",
false)) {
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()) {
237 for (DTSegmentCand::AssPointCont::const_iterator iter = seg->
hits().begin(); iter != seg->
hits().end(); ++iter) {
238 LocalPoint pos = (*iter).first->localPosition((*iter).second);
249 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
250 x.push_back(
pos.z());
251 y.push_back(
pos.x());
262 fit(
x,
y, lfit, dist, sigy,
pos,
dir, cminf, vminf, covMat,
chi2, allow3par);
264 t0_corr = -cminf / 0.00543;
266 if (
debug && fitdebug)
267 cout <<
" DTcand chi2: " <<
chi2 <<
"/" <<
x.size() <<
" t0: " << t0_corr << endl;
284 cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
302 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
306 x.push_back(
pos.z());
307 y.push_back(
pos.x());
310 float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
311 float distance = fabs(
hit->localPosition().
x() - xwire);
323 sigy.push_back(
sqrt(slErr.
xx()));
334 fit(
x,
y, lfit, dist, sigy,
pos,
dir, cminf, vminf, covMat,
chi2, allow3par, block3par);
336 t0_corr = -cminf / 0.00543;
339 cout <<
" DTSeg2d chi2: " <<
chi2 << endl;
341 cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
354 const vector<float>&
y,
355 const vector<int>& lfit,
356 const vector<double>& dist,
357 const vector<float>& sigy,
364 const bool allow3par,
365 const bool block3par)
const {
367 float intercept = 0.;
375 int leftHits = 0, rightHits = 0;
376 for (
unsigned int i = 0;
i < lfit.size();
i++)
386 if (leftHits && rightHits && (leftHits + rightHits > 3) && allow3par) {
387 theFitter->fitNpar(3,
x,
y, lfit, dist, sigy,
slope, intercept, cminf, vminf,
chi2,
debug);
388 double t0_corr = -cminf / 0.00543;
389 if (fabs(t0_corr) <
intime_cut && block3par) {
408 covMatrix[0][0] = covss;
409 covMatrix[1][1] = covii;
410 covMatrix[1][0] = covsi;
420 vector<DTRecHit1D> updatedRecHits;
422 for (vector<DTRecHit1D>::iterator
hit = toBeUpdatedRecHits.begin();
hit != toBeUpdatedRecHits.end(); ++
hit) {
429 const float angle = atan(segDir.
x() / -segDir.
z());
440 }
else if (
step == 3) {
441 LocalPoint hitPos(
hit->localPosition().
x(), +segPosAtLayer.y(), 0.);
443 newHit1D.setPosition(hitPos);
446 }
else if (
step == 4) {
454 cminf = -seg->
t0() * 0.00543;
460 const float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
461 const float distance = fabs(
hit->localPosition().
x() - xwire);
463 const double dy_corr = (vminf * ilc *
distance - cminf * ilc);
477 throw cms::Exception(
"DTSegmentUpdator") <<
" updateHits called with wrong step " << endl;
480 updatedRecHits.push_back(newHit1D);
482 LogError(
"DTSegmentUpdator") <<
"DTSegmentUpdator::updateHits failed update" << endl;
483 throw cms::Exception(
"DTSegmentUpdator") <<
"updateHits failed update" << endl;
486 seg->
update(updatedRecHits);
494 cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
497 const size_t N =
hits.size();
501 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
506 x.push_back(
pos.z());
507 y.push_back(
pos.x());
511 cout <<
" end of segment! " << endl;
512 cout <<
" size = Number of Hits: " <<
x.size() <<
" " <<
y.size() << endl;
516 float par[2] = {0., 0.};
524 for (
size_t i = 0;
i <
N; ++
i) {
527 Sx2 +=
x.at(
i) *
x.at(
i);
528 Sxy +=
x.at(
i) *
y.at(
i);
531 const float delta =
N * Sx2 - Sx * Sx;
532 par[0] = (Sx2 * Sy - Sx * Sxy) /
delta;
533 par[1] = (
N * Sxy - Sx * Sy) /
delta;
536 cout <<
"fit 2 parameters done ----> par0: " << par[0] <<
" par1: " << par[1] << endl;
540 float mean_residual = 0.;
541 for (
size_t i = 0;
i <
N; ++
i) {
542 residuals[
i] =
y.at(
i) - par[1] *
x.at(
i) - par[0];
545 cout <<
" i: " <<
i <<
" y_i " <<
y.at(
i) <<
" x_i " <<
x.at(
i) <<
" res_i " << residuals[
i];
552 cout <<
" Residuals computed! " << endl;
554 mean_residual = mean_residual / (
N - 2);
556 cout <<
" mean_residual: " << mean_residual << endl;
561 vector<DTRecHit1D> updatedRecHits;
562 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
563 float normResidual = mean_residual > 0 ?
std::abs(residuals[
i]) / mean_residual : 0;
565 if (normResidual < 1.5) {
567 updatedRecHits.push_back(newHit1D);
569 cout <<
" accepted " <<
i <<
"th hit" 570 <<
" Irej: " << normResidual << endl;
573 cout <<
" rejected " <<
i <<
"th hit" 574 <<
" Irej: " << normResidual << endl;
579 phiSeg->
update(updatedRecHits);
586 cout <<
" Check the update action: " << endl;
589 for (vector<DTRecHit1D>::const_iterator
hit = hits_upd.begin();
hit != hits_upd.end(); ++
hit) {
594 x_upd.push_back(
pos.z());
595 y_upd.push_back(
pos.x());
597 cout <<
" x_upd: " <<
pos.z() <<
" y_upd: " <<
pos.x() << endl;
600 cout <<
" end of segment! " << endl;
601 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
619 cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
621 vector<double> d_drift;
631 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
637 float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
638 float distance = fabs(
hit->localPosition().
x() - xwire);
643 x.push_back(
pos.z());
644 y.push_back(
pos.x());
658 theFitter->fit4Var(
x,
y, lc, d_drift, nptfit,
a,
b, cminf, vminf, chi2fit,
vdrift_4parfit,
debug);
660 double t0cor = -999.;
662 t0cor = -cminf / 0.00543;
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
bool hasPhi() const
Does it have the Phi projection?
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
double chi2() const override
the chi2 of the fit
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
uint32_t cc[maxCellsPerHit]
static const double slope[3]
LocalVector localDirection() const override
Local direction in Chamber frame.
~DTSegmentUpdator()
Destructor.
virtual void setChi2(double &chi2)
set chi2
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.
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
edm::ESHandle< DTGeometry > theGeom
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
void calculateT0corr(DTRecSegment2D *seg) const
DTChamberId chamberId() const
Return the corresponding ChamberId.
void setES(const edm::EventSetup &setup)
set the setup
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
bool perform_delta_rejecting
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
void rejectBadHits(DTChamberRecSegment2D *) const
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
const GeomDet * idToDet(DetId) const override
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.
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
virtual const AssPointCont & hits() const
the used hits
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
virtual void sett0(double &t0)
set t0
DetId geographicalId() const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
void setT0(const double &t0)
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
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 setVdrift(const double &vdrift)
Vector3DBase unit() const
virtual void setPosition(LocalPoint &pos)
set position
bool hasZed() const
Does it have the Z projection?
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
*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
Geom::Theta< T > theta() const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.