48 : theFitter{std::make_unique<DTLinearFit>()},
51 theGeomToken(
cc.esConsumes()),
52 vdrift_4parfit(
config.getParameter<
bool>(
"performT0_vdriftSegCorrection")),
53 T0_hit_resolution(
config.getParameter<
double>(
"hit_afterT0_resolution")),
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()) {
238 for (DTSegmentCand::AssPointCont::const_iterator iter = seg->
hits().begin(); iter != seg->
hits().end(); ++iter) {
239 LocalPoint pos = (*iter).first->localPosition((*iter).second);
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());
312 float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
313 float distance = fabs(
hit->localPosition().
x() - xwire);
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());
442 }
else if (
step == 3) {
443 LocalPoint hitPos(
hit->localPosition().
x(), +segPosAtLayer.y(), 0.);
445 newHit1D.setPosition(hitPos);
448 }
else if (
step == 4) {
456 cminf = -seg->
t0() * 0.00543;
462 const float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
463 const float distance = fabs(
hit->localPosition().
x() - xwire);
465 const double dy_corr = (vminf * ilc *
distance - cminf * ilc);
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.};
526 for (
size_t i = 0;
i <
N; ++
i) {
529 Sx2 +=
x.at(
i) *
x.at(
i);
530 Sxy +=
x.at(
i) *
y.at(
i);
533 const float delta =
N * Sx2 - Sx * Sx;
534 par[0] = (Sx2 * Sy - Sx * Sxy) /
delta;
535 par[1] = (
N * Sxy - Sx * Sy) /
delta;
538 cout <<
"fit 2 parameters done ----> par0: " << par[0] <<
" par1: " << par[1] << endl;
542 float mean_residual = 0.;
543 for (
size_t i = 0;
i <
N; ++
i) {
544 residuals[
i] =
y.at(
i) - par[1] *
x.at(
i) - par[0];
547 cout <<
" i: " <<
i <<
" y_i " <<
y.at(
i) <<
" x_i " <<
x.at(
i) <<
" res_i " << residuals[
i];
554 cout <<
" Residuals computed! " << endl;
556 mean_residual = mean_residual / (
N - 2);
558 cout <<
" mean_residual: " << mean_residual << endl;
563 vector<DTRecHit1D> updatedRecHits;
564 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
565 float normResidual = mean_residual > 0 ?
std::abs(residuals[
i]) / mean_residual : 0;
567 if (normResidual < 1.5) {
569 updatedRecHits.push_back(newHit1D);
571 cout <<
" accepted " <<
i <<
"th hit" 572 <<
" Irej: " << normResidual << endl;
575 cout <<
" rejected " <<
i <<
"th hit" 576 <<
" Irej: " << normResidual << endl;
581 phiSeg->
update(updatedRecHits);
588 cout <<
" Check the update action: " << endl;
591 for (vector<DTRecHit1D>::const_iterator
hit = hits_upd.begin();
hit != hits_upd.end(); ++
hit) {
596 x_upd.push_back(
pos.z());
597 y_upd.push_back(
pos.x());
599 cout <<
" x_upd: " <<
pos.z() <<
" y_upd: " <<
pos.x() << endl;
602 cout <<
" end of segment! " << endl;
603 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
621 cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
623 vector<double> d_drift;
633 for (vector<DTRecHit1D>::const_iterator
hit =
hits.begin();
hit !=
hits.end(); ++
hit) {
639 float xwire =
layer->specificTopology().wirePosition(
hit->wireId().wire());
640 float distance = fabs(
hit->localPosition().
x() - xwire);
645 x.push_back(
pos.z());
646 y.push_back(
pos.x());
660 theFitter->fit4Var(
x,
y, lc, d_drift, nptfit,
a,
b, cminf, vminf, chi2fit,
vdrift_4parfit,
debug);
662 double t0cor = -999.;
664 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.
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
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.