51 vdrift_4parfit(config.getParameter<bool>(
"performT0_vdriftSegCorrection")),
52 T0_hit_resolution(config.getParameter<double>(
"hit_afterT0_resolution")),
53 perform_delta_rejecting(config.getParameter<bool>(
"perform_delta_rejecting")),
54 debug(config.getUntrackedParameter<bool>(
"debug",
false))
56 string theAlgoName = config.
getParameter<
string>(
"recAlgo");
61 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
78 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the segment" << endl;
80 const bool hasPhi = seg->
hasPhi();
81 const bool hasZed = seg->
hasZed();
86 int step = (hasPhi && hasZed) ? 3 : 2;
89 if(
debug)
cout <<
"Step of update is " << step << endl;
183 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
196 if (!seg->
good())
return false;
203 for (DTSegmentCand::AssPointCont::const_iterator iter=hits.begin();
204 iter!=hits.end(); ++iter) {
205 LocalPoint pos = (*iter).first->localPosition((*iter).second);
206 x.push_back(pos.
z());
207 y.push_back(pos.
x());
208 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
216 fit(x,y,sigy,pos,dir,covMat,chi2);
240 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
247 x.push_back(pos.
z());
248 y.push_back(pos.
x());
258 sigy.push_back(
sqrt(slErr.
xx()));
266 fit(x,y,sigy,pos,dir,covMat,chi2);
281 const vector<float>&
y,
282 const vector<float>& sigy,
286 double& chi2)
const {
289 float intercept = 0.;
309 covMatrix[0][0] = covss;
310 covMatrix[1][1] = covii;
311 covMatrix[1][0] = covsi;
315 for(
unsigned int i=0;
i<x.size() ; ++
i) {
316 double resid= y[
i] - (intercept + slope*x[
i]);
317 chi2 += (resid/sigy[
i])*(resid/sigy[
i]);
330 vector<DTRecHit1D> updatedRecHits;
332 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
333 hit!=toBeUpdatedRecHits.end(); ++
hit) {
341 const float angle = atan(segDir.
x()/-segDir.
z());
353 }
else if (step == 3) {
355 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
359 newHit1D.setPosition(hitPos);
363 }
else if (step == 4) {
377 const float distance = fabs(
hit->localPosition().
x() - xwire);
381 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
391 newHit1D.setPositionAndError(point, error);
396 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
398 if (ok) updatedRecHits.push_back(newHit1D);
400 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
401 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
405 seg->
update(updatedRecHits);
413 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
416 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
423 x.push_back(pos.
z());
424 y.push_back(pos.
x());
428 cout <<
" end of segment! " << endl;
429 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
433 float par[2]={0.,0.};
444 for(
size_t i = 0;
i <
N;++
i){
447 Sx2 += x.at(
i)*x.at(
i);
448 Sy2 += y.at(
i)*y.at(
i);
449 Sxy += x.at(
i)*y.at(
i);
453 const float delta = N*Sx2 - Sx*Sx;
454 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
455 par[1] = ( N*Sxy - Sx*Sy )/delta;
457 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
462 for(
size_t i = 0;
i <
N;++
i)
465 for(
size_t i = 0;
i <
N;++
i){
466 residuals[
i] = y.at(
i) - par[1]*x.at(
i) - par[0];
468 cout<<
" i: "<<
i<<
" y_i "<<y.at(
i)<<
" x_i "<<x.at(
i)<<
" res_i "<<residuals[
i];
469 if (
i==N-1)
cout<<endl;
473 if(
debug)
cout <<
" Residuals computed! "<< endl;
477 vector<DTRecHit1D> updatedRecHits;
479 float mean_residual = 0.;
481 for (
size_t i = 0;
i <
N; ++
i)
482 mean_residual += fabs(residuals[
i]);
484 mean_residual = mean_residual/(N - 2);
486 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
490 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
495 float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
496 if(normResidual < 1.5){
498 updatedRecHits.push_back(newHit1D);
499 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
503 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
509 phiSeg->
update(updatedRecHits);
517 cout <<
" Check the update action: " << endl;
520 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
521 hit!=hits_upd.end(); ++
hit) {
527 x_upd.push_back(pos.
z());
528 y_upd.push_back(pos.
x());
530 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
535 cout <<
" end of segment! " << endl;
536 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
552 vector<double> d_drift;
562 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
571 float distance = fabs(
hit->localPosition().
x() - xwire);
576 x.push_back(pos.
z());
577 y.push_back(pos.
x());
579 d_drift.push_back(distance);
590 Fit4Var(x,y,lc,d_drift,nptfit,cminf,vminf,chi2fit);
592 double t0cor = -999.;
593 if(cminf > -998.) t0cor = - cminf/0.00543 ;
607 const vector<float>& yfit,
608 const vector<int>& lfit,
609 const vector<double>& tfit,
613 double& chi2fit)
const {
615 const double sigma = 0.0295;
632 double chi2fitN2 = -1. ;
633 double chi2fit3 = -1.;
634 double chi2fitN3 = -1. ;
635 double chi2fitN4 = -1.;
636 float bminf3 = bminf;
637 float aminf3 = aminf;
638 float cminf3 = cminf;
646 for (
int j=0;
j<nptfit;
j++){
649 sx2 = sx2 + xfit[
j]*xfit[
j];
650 sxy = sxy + xfit[
j]*yfit[
j];
652 sl2 = sl2 + lfit[
j]*lfit[
j];
653 sly = sly + lfit[
j]*yfit[
j];
654 slx = slx + lfit[
j]*xfit[
j];
656 st2 = st2 + tfit[
j] * tfit[
j];
657 slt = slt + lfit[
j] * tfit[
j];
658 sltx = sltx + lfit[
j] * tfit[
j]*xfit[
j];
659 slty = slty + lfit[
j] * tfit[
j]*yfit[
j];
663 const double delta = nptfit*sx2 - sx*sx;
669 a = (sx2*sy - sx*sxy)/delta;
670 b = (nptfit*sxy - sx*sy)/delta;
673 for (
int j=0;
j<nptfit;
j++){
674 const double ypred = a + b*xfit[
j];
675 const double dy = (yfit[
j] - ypred)/sigma;
676 chi2fit = chi2fit + dy*dy;
686 chi2fitN2 = chi2fit/(nptfit-2);
692 const double d1 = sy;
693 const double d2 = sxy;
694 const double d3 = sly;
695 const double c1 = sl;
696 const double c2 = slx;
697 const double c3 = sl2;
698 const double b1 = sx;
699 const double b2 = sx2;
700 const double b3 = slx;
701 const double a1 = nptfit;
702 const double a2 = sx;
703 const double a3 = sl;
706 const double b4 = b2*a1-b1*a2;
707 const double c4 = c2*a1-c1*a2;
708 const double d4 = d2*a1-d1*a2;
709 const double b5 = a1*b3-a3*b1;
710 const double c5 = a1*c3-a3*
c1;
711 const double d5 = a1*d3-d1*a3;
712 const double a6 = slt;
713 const double b6 = sltx;
714 const double c6 = st;
715 const double v6 = st2;
716 const double d6 = slty;
718 if (((c5*b4-c4*b5)*b4*a1)!=0) {
721 cminf = (d5*b4-d4*b5)/(c5*b4-c4*b5);
722 bminf = d4/b4 -cminf *c4/b4;
723 aminf = (d1/a1 -cminf*c1/a1 -bminf*b1/a1);
725 for (
int j=0;
j<nptfit;
j++){
726 const double ypred = aminf + bminf*xfit[
j];
727 const double dy = (yfit[
j]-cminf*lfit[
j] - ypred)/sigma;
728 chi2fit = chi2fit + dy*dy;
733 chi2fitN3 = chi2fit /(nptfit-3);
741 chi2fitN3 = chi2fit /(nptfit-2);
750 cout <<
"dt0= 0 : slope 2 = " << b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
751 <<
" nppar = " << nppar2 <<
" nptfit = " << nptfit << endl;
752 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
753 << chi2fitN3 <<
" nppar = " << nppar3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
759 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))
760 + a2*a2*c6*c6 + 2*a2*(a3*(b3*v6 - b6*c6) - a6*b3*c6) + a3*a3*(b6*b6 - b2*v6)
761 + a6*(2*a3*(b2*c6 - b3*b6) + a6*b3*b3));
768 aminf = (a1*(a2*(b6*d6 - v6*d2) + a6*(b6*d2 - b2*d6) + d1*(b2*v6 - b6*b6)) - a2*(b3*(c6*d6 - v6*d3)
769 + c6*(b6*d3 - c6*d2)) + a3*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2))
770 + a6*(b2*c6*d3 + b3*(b3*d6 - b6*d3 - c6*d2)) - d1*(b2*c6*c6 + b3*(b3*v6 - 2*b6*c6)))/det;
771 bminf = - (a1*a1*(b6*d6 - v6*d2) - a1*(a2*(a6*d6 - v6*d1) - a6*a6*d2 + a6*b6*d1 + b3*(c6*d6 - v6*d3)
772 + c6*(b6*d3 - c6*d2)) + a2*(a3*(c6*d6 - v6*d3) + c6*(a6*d3 - c6*d1)) + a3*a3*(v6*d2 - b6*d6)
773 + a3*(a6*(b3*d6 + b6*d3 - 2*c6*d2) - d1*(b3*v6 - b6*c6)) - a6*b3*(a6*d3 - c6*d1))/det;
774 cminf = -(a1*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2)) + a2*a2*(v6*d3 - c6*d6)
775 + a2*(a3*(b6*d6 - v6*d2) + a6*(b3*d6 - 2*b6*d3 + c6*d2) - d1*(b3*v6 - b6*c6))
776 + a3*(d1*(b2*v6 - b6*b6) - a6*(b2*d6 - b6*d2)) + a6*(a6*(b2*d3 - b3*d2) - d1*(b2*c6 - b3*b6)))/det;
777 vminf = - (a1*a1*(b2*d6 - b6*d2) - a1*(a2*a2*d6 - a2*(a6*d2 + b6*d1) + a6*b2*d1 + b2*c6*d3
778 + 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))
779 + a3*a3*(b6*d2 - b2*d6) + a3*(a6*(b2*d3 - b3*d2) + d1*(b2*c6 - b3*b6)) + a6*b3*b3*d1)/det;
782 for (
int j=0;
j<nptfit;
j++) {
783 const double ypred = aminf + bminf*xfit[
j];
784 const double dy = (yfit[
j]+vminf*lfit[
j]*tfit[
j]-cminf*lfit[
j] -ypred)/sigma;
785 chi2fit = chi2fit + dy*dy;
793 chi2fitN4= chi2fit / (nptfit-nppar);
799 if (nptfit <= nppar) chi2fitN4=-1;
800 else chi2fitN4 = chi2fit / (nptfit-nppar);
803 if (fabs(vminf) >= 0.29) {
829 cout <<
" dt0= 0 : slope 4 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
830 <<
" nppar= " << nppar4 <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
831 cout << nptfit <<
" nptfit " <<
" end chi2fit = " << chi2fit/ (nptfit-nppar ) <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
834 if ( fabs(vminf) >= 0.09 &&
debug ) {
835 cout <<
"vminf gt 0.09 det= " << endl;
836 cout <<
"dt0= 0 : slope 4 = "<< bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
837 <<
" T0_ev ns = " << cminf/0.00543 <<
" delta v = "<< vminf << endl;
838 cout <<
"dt0 = 0 : slope 2 = "<< b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
839 <<
" nppar = " << nppar-1 <<
" nptfit = " << nptfit <<endl;
840 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
841 << chi2fitN3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
842 cout << nptfit <<
" nptfit "<<
" end chi2fit = " << chi2fit <<
"T0_ev ns= " << cminf/0.00543 <<
"delta v = "<< vminf <<endl;
845 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
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
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.
void setCovMatrix(AlgebraicSymMatrix mat)
Set covariance matrix.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)