47 vdrift_4parfit(config.getParameter<bool>(
"performT0_vdriftSegCorrection")),
48 T0_hit_resolution(config.getParameter<double>(
"hit_afterT0_resolution")),
49 debug(config.getUntrackedParameter<bool>(
"debug",
false))
51 string theAlgoName = config.
getParameter<
string>(
"recAlgo");
56 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
73 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the segment" << endl;
75 const bool hasPhi = seg->
hasPhi();
76 const bool hasZed = seg->
hasZed();
78 int step = (hasPhi && hasZed) ? 3 : 2;
173 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
186 if (!seg->
good())
return false;
193 for (DTSegmentCand::AssPointCont::const_iterator iter=hits.begin();
194 iter!=hits.end(); ++iter) {
195 LocalPoint pos = (*iter).first->localPosition((*iter).second);
196 x.push_back(pos.
z());
197 y.push_back(pos.
x());
198 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
206 fit(x,y,sigy,pos,dir,covMat,chi2);
230 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
237 x.push_back(pos.
z());
238 y.push_back(pos.
x());
248 sigy.push_back(
sqrt(slErr.
xx()));
256 fit(x,y,sigy,pos,dir,covMat,chi2);
271 const vector<float>&
y,
272 const vector<float>& sigy,
276 double& chi2)
const {
279 float intercept = 0.;
299 covMatrix[0][0] = covss;
300 covMatrix[1][1] = covii;
301 covMatrix[1][0] = covsi;
305 for(
unsigned int i=0;
i<x.size() ; ++
i) {
306 double resid= y[
i] - (intercept + slope*x[
i]);
307 chi2 += (resid/sigy[
i])*(resid/sigy[
i]);
320 vector<DTRecHit1D> updatedRecHits;
322 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
323 hit!=toBeUpdatedRecHits.end(); ++
hit) {
331 const float angle = atan(segDir.
x()/-segDir.
z());
343 }
else if (step == 3) {
345 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
349 newHit1D.setPosition(hitPos);
353 }
else if (step == 4) {
355 const double vminf = seg->
vDrift();
364 const float distance = fabs(
hit->localPosition().
x() - xwire);
368 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
374 newHit1D.setPositionAndError(point, error);
379 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
381 if (ok) updatedRecHits.push_back(newHit1D);
383 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
384 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
388 seg->
update(updatedRecHits);
400 vector<double> d_drift;
410 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
419 float distance = fabs(
hit->localPosition().
x() - xwire);
424 x.push_back(pos.
z());
425 y.push_back(pos.
x());
427 d_drift.push_back(distance);
438 Fit4Var(x,y,lc,d_drift,nptfit,cminf,vminf,chi2fit);
440 double t0cor = -999.;
441 if(cminf > -998.) t0cor = - cminf/0.00543 ;
455 const vector<float>& yfit,
456 const vector<int>& lfit,
457 const vector<double>& tfit,
461 double& chi2fit)
const {
463 const double sigma = 0.0295;
480 double chi2fit2 = -1.;
481 double chi2fitN2 = -1. ;
482 double chi2fit3 = -1.;
483 double chi2fitN3 = -1. ;
484 double chi2fit4 = -1.;
485 double chi2fitN4 = -1.;
486 float bminf3 = bminf;
487 float aminf3 = aminf;
488 float cminf3 = cminf;
496 for (
int j=0;
j<nptfit;
j++){
499 sx2 = sx2 + xfit[
j]*xfit[
j];
500 sxy = sxy + xfit[
j]*yfit[
j];
502 sl2 = sl2 + lfit[
j]*lfit[
j];
503 sly = sly + lfit[
j]*yfit[
j];
504 slx = slx + lfit[
j]*xfit[
j];
506 st2 = st2 + tfit[
j] * tfit[
j];
507 slt = slt + lfit[
j] * tfit[
j];
508 sltx = sltx + lfit[
j] * tfit[
j]*xfit[
j];
509 slty = slty + lfit[
j] * tfit[
j]*yfit[
j];
513 const double delta = nptfit*sx2 - sx*sx;
519 a = (sx2*sy - sx*sxy)/delta;
520 b = (nptfit*sxy - sx*sy)/delta;
523 for (
int j=0;
j<nptfit;
j++){
524 const double ypred = a + b*xfit[
j];
525 const double dy = (yfit[
j] - ypred)/sigma;
526 chi2fit = chi2fit + dy*dy;
537 chi2fitN2 = chi2fit/(nptfit-2);
543 const double d1 = sy;
544 const double d2 = sxy;
545 const double d3 = sly;
546 const double c1 = sl;
547 const double c2 = slx;
548 const double c3 = sl2;
549 const double b1 = sx;
550 const double b2 = sx2;
551 const double b3 = slx;
552 const double a1 = nptfit;
553 const double a2 = sx;
554 const double a3 = sl;
557 const double b4 = b2*a1-b1*a2;
558 const double c4 = c2*a1-c1*a2;
559 const double d4 = d2*a1-d1*a2;
560 const double b5 = a1*b3-a3*b1;
561 const double c5 = a1*c3-a3*
c1;
562 const double d5 = a1*d3-d1*a3;
563 const double a6 = slt;
564 const double b6 = sltx;
565 const double c6 = st;
566 const double v6 = st2;
567 const double d6 = slty;
569 if (((c5*b4-c4*b5)*b4*a1)!=0) {
572 cminf = (d5*b4-d4*b5)/(c5*b4-c4*b5);
573 bminf = d4/b4 -cminf *c4/b4;
574 aminf = (d1/a1 -cminf*c1/a1 -bminf*b1/a1);
576 for (
int j=0;
j<nptfit;
j++){
577 const double ypred = aminf + bminf*xfit[
j];
578 const double dy = (yfit[
j]-cminf*lfit[
j] - ypred)/sigma;
579 chi2fit = chi2fit + dy*dy;
584 chi2fitN3 = chi2fit /(nptfit-3);
592 chi2fitN3 = chi2fit /(nptfit-2);
601 cout <<
"dt0= 0 : slope 2 = " << b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
602 <<
" nppar = " << nppar2 <<
" nptfit = " << nptfit << endl;
603 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
604 << chi2fitN3 <<
" nppar = " << nppar3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
610 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))
611 + a2*a2*c6*c6 + 2*a2*(a3*(b3*v6 - b6*c6) - a6*b3*c6) + a3*a3*(b6*b6 - b2*v6)
612 + a6*(2*a3*(b2*c6 - b3*b6) + a6*b3*b3));
619 aminf = (a1*(a2*(b6*d6 - v6*d2) + a6*(b6*d2 - b2*d6) + d1*(b2*v6 - b6*b6)) - a2*(b3*(c6*d6 - v6*d3)
620 + c6*(b6*d3 - c6*d2)) + a3*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2))
621 + a6*(b2*c6*d3 + b3*(b3*d6 - b6*d3 - c6*d2)) - d1*(b2*c6*c6 + b3*(b3*v6 - 2*b6*c6)))/det;
622 bminf = - (a1*a1*(b6*d6 - v6*d2) - a1*(a2*(a6*d6 - v6*d1) - a6*a6*d2 + a6*b6*d1 + b3*(c6*d6 - v6*d3)
623 + c6*(b6*d3 - c6*d2)) + a2*(a3*(c6*d6 - v6*d3) + c6*(a6*d3 - c6*
d1)) + a3*a3*(v6*d2 - b6*d6)
624 + a3*(a6*(b3*d6 + b6*d3 - 2*c6*d2) - d1*(b3*v6 - b6*c6)) - a6*b3*(a6*d3 - c6*
d1))/det;
625 cminf = -(a1*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2)) + a2*a2*(v6*d3 - c6*d6)
626 + a2*(a3*(b6*d6 - v6*d2) + a6*(b3*d6 - 2*b6*d3 + c6*d2) - d1*(b3*v6 - b6*c6))
627 + a3*(d1*(b2*v6 - b6*b6) - a6*(b2*d6 - b6*d2)) + a6*(a6*(b2*d3 - b3*d2) - d1*(b2*c6 - b3*b6)))/det;
628 vminf = - (a1*a1*(b2*d6 - b6*d2) - a1*(a2*a2*d6 - a2*(a6*d2 + b6*d1) + a6*b2*d1 + b2*c6*d3
629 + 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))
630 + a3*a3*(b6*d2 - b2*d6) + a3*(a6*(b2*d3 - b3*d2) + d1*(b2*c6 - b3*b6)) + a6*b3*b3*d1)/det;
633 for (
int j=0;
j<nptfit;
j++) {
634 const double ypred = aminf + bminf*xfit[
j];
635 const double dy = (yfit[
j]+vminf*lfit[
j]*tfit[
j]-cminf*lfit[
j] -ypred)/sigma;
636 chi2fit = chi2fit + dy*dy;
646 chi2fitN4= chi2fit / (nptfit-nppar);
653 if (nptfit <= nppar) chi2fitN4=-1;
654 else chi2fitN4 = chi2fit / (nptfit-nppar);
657 if (fabs(vminf) >= 0.09) {
673 cout <<
" dt0= 0 : slope 4 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
674 <<
" nppar= " << nppar4 <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
675 cout << nptfit <<
" nptfit " <<
" end chi2fit = " << chi2fit/ (nptfit-nppar ) <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
678 if ( fabs(vminf) >= 0.09 &&
debug ) {
679 cout <<
"vminf gt 0.09 det= " << endl;
680 cout <<
"dt0= 0 : slope 4 = "<< bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
681 <<
" T0_ev ns = " << cminf/0.00543 <<
" delta v = "<< vminf << endl;
682 cout <<
"dt0 = 0 : slope 2 = "<< b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
683 <<
" nppar = " << nppar-1 <<
" nptfit = " << nptfit <<endl;
684 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
685 << chi2fitN3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
686 cout << nptfit <<
" nptfit "<<
" end chi2fit = " << chi2fit <<
"T0_ev ns= " << cminf/0.00543 <<
"delta v = "<< vminf <<endl;
689 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 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
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)