49 vdrift_4parfit(config.getParameter<bool>(
"performT0_vdriftSegCorrection")),
50 T0_hit_resolution(config.getParameter<double>(
"hit_afterT0_resolution")),
51 perform_delta_rejecting(config.getParameter<bool>(
"perform_delta_rejecting")),
52 debug(config.getUntrackedParameter<bool>(
"debug",
false))
54 string theAlgoName = config.
getParameter<
string>(
"recAlgo");
59 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
76 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the segment" << 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;
181 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
194 if (!seg->
good())
return false;
201 for (DTSegmentCand::AssPointCont::const_iterator iter=hits.begin();
202 iter!=hits.end(); ++iter) {
203 LocalPoint pos = (*iter).first->localPosition((*iter).second);
204 x.push_back(pos.
z());
205 y.push_back(pos.
x());
206 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
214 fit(x,y,sigy,pos,dir,covMat,chi2);
238 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
245 x.push_back(pos.
z());
246 y.push_back(pos.
x());
256 sigy.push_back(
sqrt(slErr.
xx()));
264 fit(x,y,sigy,pos,dir,covMat,chi2);
279 const vector<float>&
y,
280 const vector<float>& sigy,
284 double& chi2)
const {
287 float intercept = 0.;
307 covMatrix[0][0] = covss;
308 covMatrix[1][1] = covii;
309 covMatrix[1][0] = covsi;
313 for(
unsigned int i=0;
i<x.size() ; ++
i) {
314 double resid= y[
i] - (intercept + slope*x[
i]);
315 chi2 += (resid/sigy[
i])*(resid/sigy[
i]);
328 vector<DTRecHit1D> updatedRecHits;
330 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
331 hit!=toBeUpdatedRecHits.end(); ++
hit) {
339 const float angle = atan(segDir.
x()/-segDir.
z());
351 }
else if (step == 3) {
353 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
357 newHit1D.setPosition(hitPos);
361 }
else if (step == 4) {
375 const float distance = fabs(
hit->localPosition().
x() - xwire);
379 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
389 newHit1D.setPositionAndError(point, error);
394 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
396 if (ok) updatedRecHits.push_back(newHit1D);
398 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
399 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
403 seg->
update(updatedRecHits);
411 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
414 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
421 x.push_back(pos.
z());
422 y.push_back(pos.
x());
426 cout <<
" end of segment! " << endl;
427 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
431 float par[2]={0.,0.};
445 for(
size_t i = 0;
i <
N;++
i){
448 Sx2 += x.at(
i)*x.at(
i);
449 Sy2 += y.at(
i)*y.at(
i);
450 Sxy += x.at(
i)*y.at(
i);
454 const float delta = N*Sx2 - Sx*Sx;
455 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
456 par[1] = ( N*Sxy - Sx*Sy )/delta;
458 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
463 for(
size_t i = 0;
i <
N;++
i)
466 for(
size_t i = 0;
i <
N;++
i){
467 residuals[
i] = y.at(
i) - par[1]*x.at(
i) - par[0];
469 cout<<
" i: "<<
i<<
" y_i "<<y.at(
i)<<
" x_i "<<x.at(
i)<<
" res_i "<<residuals[
i];
470 if (
i==N-1)
cout<<endl;
474 if(
debug)
cout <<
" Residuals computed! "<< endl;
478 vector<DTRecHit1D> updatedRecHits;
480 float mean_residual = 0.;
482 for (
size_t i = 0;
i <
N; ++
i)
483 mean_residual += fabs(residuals[
i]);
485 mean_residual = mean_residual/(N - 2);
487 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
491 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
496 float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
497 if(normResidual < 1.5){
499 updatedRecHits.push_back(newHit1D);
500 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
504 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
510 phiSeg->
update(updatedRecHits);
518 cout <<
" Check the update action: " << endl;
521 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
522 hit!=hits_upd.end(); ++
hit) {
528 x_upd.push_back(pos.
z());
529 y_upd.push_back(pos.
x());
531 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
536 cout <<
" end of segment! " << endl;
537 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
553 vector<double> d_drift;
563 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
572 float distance = fabs(
hit->localPosition().
x() - xwire);
577 x.push_back(pos.
z());
578 y.push_back(pos.
x());
580 d_drift.push_back(distance);
591 Fit4Var(x,y,lc,d_drift,nptfit,cminf,vminf,chi2fit);
593 double t0cor = -999.;
594 if(cminf > -998.) t0cor = - cminf/0.00543 ;
608 const vector<float>& yfit,
609 const vector<int>& lfit,
610 const vector<double>& tfit,
614 double& chi2fit)
const {
616 const double sigma = 0.0295;
633 double chi2fitN2 = -1. ;
634 double chi2fit3 = -1.;
635 double chi2fitN3 = -1. ;
636 double chi2fitN4 = -1.;
637 float bminf3 = bminf;
638 float aminf3 = aminf;
639 float cminf3 = cminf;
647 for (
int j=0;
j<nptfit;
j++){
650 sx2 = sx2 + xfit[
j]*xfit[
j];
651 sxy = sxy + xfit[
j]*yfit[
j];
653 sl2 = sl2 + lfit[
j]*lfit[
j];
654 sly = sly + lfit[
j]*yfit[
j];
655 slx = slx + lfit[
j]*xfit[
j];
657 st2 = st2 + tfit[
j] * tfit[
j];
658 slt = slt + lfit[
j] * tfit[
j];
659 sltx = sltx + lfit[
j] * tfit[
j]*xfit[
j];
660 slty = slty + lfit[
j] * tfit[
j]*yfit[
j];
664 const double delta = nptfit*sx2 - sx*sx;
670 a = (sx2*sy - sx*sxy)/delta;
671 b = (nptfit*sxy - sx*sy)/delta;
674 for (
int j=0;
j<nptfit;
j++){
675 const double ypred = a + b*xfit[
j];
676 const double dy = (yfit[
j] - ypred)/sigma;
677 chi2fit = chi2fit + dy*dy;
687 chi2fitN2 = chi2fit/(nptfit-2);
693 const double d1 = sy;
694 const double d2 = sxy;
695 const double d3 = sly;
696 const double c1 = sl;
697 const double c2 = slx;
698 const double c3 = sl2;
699 const double b1 = sx;
700 const double b2 = sx2;
701 const double b3 = slx;
702 const double a1 = nptfit;
703 const double a2 = sx;
704 const double a3 = sl;
707 const double b4 = b2*a1-b1*a2;
708 const double c4 = c2*a1-c1*a2;
709 const double d4 = d2*a1-d1*a2;
710 const double b5 = a1*b3-a3*b1;
711 const double c5 = a1*c3-a3*
c1;
712 const double d5 = a1*d3-d1*a3;
713 const double a6 = slt;
714 const double b6 = sltx;
715 const double c6 = st;
716 const double v6 = st2;
717 const double d6 = slty;
719 if (((c5*b4-c4*b5)*b4*a1)!=0) {
722 cminf = (d5*b4-d4*b5)/(c5*b4-c4*b5);
723 bminf = d4/b4 -cminf *c4/b4;
724 aminf = (d1/a1 -cminf*c1/a1 -bminf*b1/a1);
726 for (
int j=0;
j<nptfit;
j++){
727 const double ypred = aminf + bminf*xfit[
j];
728 const double dy = (yfit[
j]-cminf*lfit[
j] - ypred)/sigma;
729 chi2fit = chi2fit + dy*dy;
734 chi2fitN3 = chi2fit /(nptfit-3);
742 chi2fitN3 = chi2fit /(nptfit-2);
751 cout <<
"dt0= 0 : slope 2 = " << b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
752 <<
" nppar = " << nppar2 <<
" nptfit = " << nptfit << endl;
753 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
754 << chi2fitN3 <<
" nppar = " << nppar3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
760 const double det = (a1*a1*(b2*v6 - b6*b6) - a1*(a2*a2*v6 - 2*a2*a6*b6 + a6*a6*b2 + b2*c6*c6 + b3*(b3*v6 - 2*b6*c6))
761 + a2*a2*c6*c6 + 2*a2*(a3*(b3*v6 - b6*c6) - a6*b3*c6) + a3*a3*(b6*b6 - b2*v6)
762 + a6*(2*a3*(b2*c6 - b3*b6) + a6*b3*b3));
769 aminf = (a1*(a2*(b6*d6 - v6*d2) + a6*(b6*d2 - b2*d6) + d1*(b2*v6 - b6*b6)) - a2*(b3*(c6*d6 - v6*d3)
770 + c6*(b6*d3 - c6*d2)) + a3*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2))
771 + a6*(b2*c6*d3 + b3*(b3*d6 - b6*d3 - c6*d2)) - d1*(b2*c6*c6 + b3*(b3*v6 - 2*b6*c6)))/det;
772 bminf = - (a1*a1*(b6*d6 - v6*d2) - a1*(a2*(a6*d6 - v6*d1) - a6*a6*d2 + a6*b6*d1 + b3*(c6*d6 - v6*d3)
773 + c6*(b6*d3 - c6*d2)) + a2*(a3*(c6*d6 - v6*d3) + c6*(a6*d3 - c6*d1)) + a3*a3*(v6*d2 - b6*d6)
774 + a3*(a6*(b3*d6 + b6*d3 - 2*c6*d2) - d1*(b3*v6 - b6*c6)) - a6*b3*(a6*d3 - c6*d1))/det;
775 cminf = -(a1*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2)) + a2*a2*(v6*d3 - c6*d6)
776 + a2*(a3*(b6*d6 - v6*d2) + a6*(b3*d6 - 2*b6*d3 + c6*d2) - d1*(b3*v6 - b6*c6))
777 + a3*(d1*(b2*v6 - b6*b6) - a6*(b2*d6 - b6*d2)) + a6*(a6*(b2*d3 - b3*d2) - d1*(b2*c6 - b3*b6)))/det;
778 vminf = - (a1*a1*(b2*d6 - b6*d2) - a1*(a2*a2*d6 - a2*(a6*d2 + b6*d1) + a6*b2*d1 + b2*c6*d3
779 + b3*(b3*d6 - b6*d3 - c6*d2)) + a2*a2*c6*d3 + a2*(a3*(2*b3*d6 - b6*d3 - c6*d2) - b3*(a6*d3 + c6*d1))
780 + a3*a3*(b6*d2 - b2*d6) + a3*(a6*(b2*d3 - b3*d2) + d1*(b2*c6 - b3*b6)) + a6*b3*b3*d1)/det;
783 for (
int j=0;
j<nptfit;
j++) {
784 const double ypred = aminf + bminf*xfit[
j];
785 const double dy = (yfit[
j]+vminf*lfit[
j]*tfit[
j]-cminf*lfit[
j] -ypred)/sigma;
786 chi2fit = chi2fit + dy*dy;
794 chi2fitN4= chi2fit / (nptfit-nppar);
800 if (nptfit <= nppar) chi2fitN4=-1;
801 else chi2fitN4 = chi2fit / (nptfit-nppar);
804 if (fabs(vminf) >= 0.29) {
830 cout <<
" dt0= 0 : slope 4 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
831 <<
" nppar= " << nppar4 <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
832 cout << nptfit <<
" nptfit " <<
" end chi2fit = " << chi2fit/ (nptfit-nppar ) <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
835 if ( fabs(vminf) >= 0.09 &&
debug ) {
836 cout <<
"vminf gt 0.09 det= " << endl;
837 cout <<
"dt0= 0 : slope 4 = "<< bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
838 <<
" T0_ev ns = " << cminf/0.00543 <<
" delta v = "<< vminf << endl;
839 cout <<
"dt0 = 0 : slope 2 = "<< b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
840 <<
" nppar = " << nppar-1 <<
" nptfit = " << nptfit <<endl;
841 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
842 << chi2fitN3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
843 cout << nptfit <<
" nptfit "<<
" end chi2fit = " << chi2fit <<
"T0_ev ns= " << cminf/0.00543 <<
"delta v = "<< vminf <<endl;
846 if (nptfit != nppar) chi2fit = chi2fit / (nptfit-nppar);
T getParameter(std::string 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
void Fit4Var(const std::vector< float > &xfit, const std::vector< float > &yfit, const std::vector< int > &lfit, const std::vector< double > &tfit, const int nptfit, float &cminf, double &vminf, double &chi2fit) const
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
void calculateT0corr(DTRecSegment2D *seg) const
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.
~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)
void update(std::vector< DTRecHit1D > &updatedRecHits)
virtual bool good() const
edm::ESHandle< DTGeometry > theGeom
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
Geom::Theta< T > theta() const
virtual LocalVector localDirection() const
Local direction in Chamber frame.
const DTTopology & specificTopology() const
void setES(const edm::EventSetup &setup)
set the setup
bool perform_delta_rejecting
virtual void setES(const edm::EventSetup &setup)=0
Pass the Event Setup to the algo at each event.
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
Cos< T >::type cos(const T &t)
bool fit(DTSegmentCand *seg) const
void setDirection(LocalVector dir)
Set direction.
bool hasPhi() const
Does it have the Phi projection?
virtual bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const =0
virtual LocalPoint localPosition() const
Local position in Chamber frame.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
virtual AssPointCont hits() const
the used hits
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
virtual LocalPoint localPosition() const
local position in SL frame
Vector3DBase unit() const
bool hasZed() const
Does it have the Z projection?
std::set< AssPoint, AssPointLessZ > AssPointCont
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
virtual AlgebraicSymMatrix parametersError() const
void setT0(const double &t0)
virtual void setDirection(LocalVector &dir)
set direction
void fit(const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigy, float &slope, float &intercept, float &covss, float &covii, float &covsi) const
void setPosition(const LocalPoint &pos)
virtual LocalVector localDirection() const
the local direction in SL frame
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setDirection(const LocalVector &dir)
void setPosition(LocalPoint pos)
Set position.
void setVdrift(const double &vdrift)
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
virtual void setPosition(LocalPoint &pos)
set position
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
DTRecHitBaseAlgo * theAlgo
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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
DTSegmentUpdator(const edm::ParameterSet &config)
Constructor.
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)