48 theFitter{std::make_unique<DTLinearFit>()},
54 debug(
config.getUntrackedParameter<
bool>(
"debug",
false))
57 if (
config.exists(
"intime_cut"))
61 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
76 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
78 const bool hasPhi = seg->
hasPhi();
79 const bool hasZed = seg->
hasZed();
84 int step = (hasPhi && hasZed) ? 3 : 2;
87 if(
debug)
cout <<
"Step of update is " << step << endl;
101 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
106 fit(seg,allow3par,
false);
110 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
198 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
225 vector <double> dist;
234 for (DTSegmentCand::AssPointCont::const_iterator iter=seg->
hits().begin(); iter!=seg->
hits().end(); ++iter) {
235 LocalPoint pos = (*iter).first->localPosition((*iter).second);
240 else lfit.push_back(-1);
242 dist.push_back(distance);
243 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
244 x.push_back(pos.
z());
245 y.push_back(pos.
x());
257 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par);
258 if (cminf!=0) t0_corr=-cminf/0.00543;
260 if (
debug && fitdebug)
261 cout <<
" DTcand chi2: " << chi2 <<
"/" << x.size() <<
" t0: " << t0_corr << endl;
278 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
284 vector <double> dist;
296 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
302 x.push_back(pos.
z());
303 y.push_back(pos.
x());
307 float distance = fabs(
hit->localPosition().
x() - xwire);
308 dist.push_back(distance);
318 sigy.push_back(
sqrt(slErr.
xx()));
329 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par,block3par);
330 if (cminf!=0) t0_corr=-cminf/0.00543;
332 if (
debug)
cout <<
" DTSeg2d chi2: " << chi2 << endl;
333 if (
debug)
cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
346 const vector<float>&
y,
347 const vector<int>& lfit,
348 const vector<double>& dist,
349 const vector<float>& sigy,
356 const bool allow3par,
357 const bool block3par)
const {
360 float intercept = 0.;
368 int leftHits=0, rightHits=0;
369 for (
unsigned int i=0;
i<lfit.size();
i++)
370 if (lfit[
i]==1) leftHits++;
else rightHits++;
376 if (leftHits && rightHits && (leftHits+rightHits>3) && allow3par) {
377 theFitter->fitNpar(3,x,y,lfit,dist,sigy,slope,intercept,cminf,vminf,chi2,
debug);
378 double t0_corr=-cminf/0.00543;
398 covMatrix[0][0] = covss;
399 covMatrix[1][1] = covii;
400 covMatrix[1][0] = covsi;
412 vector<DTRecHit1D> updatedRecHits;
414 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
415 hit!=toBeUpdatedRecHits.end(); ++
hit) {
423 const float angle = atan(segDir.
x()/-segDir.
z());
432 ok =
theAlgo->compute(layer,*
hit,angle,newHit1D);
434 }
else if (step == 3) {
436 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
438 newHit1D.setPosition(hitPos);
439 ok =
theAlgo->compute(layer,*
hit,angle,glbpos,newHit1D);
441 }
else if (step == 4) {
455 const float distance = fabs(
hit->localPosition().
x() - xwire);
457 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
465 newHit1D.setPositionAndError(point, error);
470 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
472 if (ok) updatedRecHits.push_back(newHit1D);
474 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
475 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
479 seg->
update(updatedRecHits);
487 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
490 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
497 x.push_back(pos.
z());
498 y.push_back(pos.
x());
502 cout <<
" end of segment! " << endl;
503 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
507 float par[2]={0.,0.};
521 for(
size_t i = 0;
i <
N;++
i){
524 Sx2 += x.at(
i)*x.at(
i);
525 Sy2 += y.at(
i)*y.at(
i);
526 Sxy += x.at(
i)*y.at(
i);
530 const float delta = N*Sx2 - Sx*Sx;
531 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
532 par[1] = ( N*Sxy - Sx*Sy )/delta;
534 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
539 for(
size_t i = 0;
i <
N;++
i)
542 for(
size_t i = 0;
i <
N;++
i){
543 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];
546 if (
i==N-1)
cout<<endl;
550 if(
debug)
cout <<
" Residuals computed! "<< endl;
553 vector<DTRecHit1D> updatedRecHits;
555 float mean_residual = 0.;
557 for (
size_t i = 0;
i <
N; ++
i)
558 mean_residual += fabs(residuals[
i]);
560 mean_residual = mean_residual/(N - 2);
562 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
566 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
571 float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
572 if(normResidual < 1.5){
574 updatedRecHits.push_back(newHit1D);
575 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
579 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
585 phiSeg->
update(updatedRecHits);
593 cout <<
" Check the update action: " << endl;
596 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
597 hit!=hits_upd.end(); ++
hit) {
603 x_upd.push_back(pos.
z());
604 y_upd.push_back(pos.
x());
606 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
609 cout <<
" end of segment! " << endl;
610 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
625 if(
debug)
cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
627 vector<double> d_drift;
637 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
646 float distance = fabs(
hit->localPosition().
x() - xwire);
651 x.push_back(pos.
z());
652 y.push_back(pos.
x());
654 d_drift.push_back(distance);
666 theFitter->fit4Var(x,y,lc,d_drift,nptfit,a,b,cminf,vminf,chi2fit,
vdrift_4parfit,
debug);
668 double t0cor = -999.;
669 if(cminf > -998.) 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.
def setup(process, global_tag, zero_tesla=False)
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
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)
T get(const Candidate &c)
*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)