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;
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 );
385 newHit1D.setPositionAndError(point, error);
390 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
392 if (ok) updatedRecHits.push_back(newHit1D);
394 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
395 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
399 seg->
update(updatedRecHits);
407 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
410 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
417 x.push_back(pos.
z());
418 y.push_back(pos.
x());
422 cout <<
" end of segment! " << endl;
423 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
427 float par[2]={0.,0.};
436 const int N = x.size();
438 for(
int i = 0;
i <
N;++
i){
441 Sx2 += x.at(
i)*x.at(
i);
442 Sy2 += y.at(
i)*y.at(
i);
443 Sxy += x.at(
i)*y.at(
i);
447 const float delta = N*Sx2 - Sx*Sx;
448 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
449 par[1] = ( N*Sxy - Sx*Sy )/delta;
451 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
456 for(
int i = 0;
i <
N;++
i)
459 for(
int i = 0;
i <
N;++
i)
460 residuals[
i] = y.at(
i) - par[1]*x.at(
i) - par[0];
462 if(
debug)
cout <<
" Residuals computed! "<< endl;
466 vector<DTRecHit1D> updatedRecHits;
468 float mean_residual = 0.;
470 for (
int i = 0;
i <
N; ++
i)
471 mean_residual += fabs(residuals[
i]);
473 mean_residual = mean_residual/(N - 2);
475 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
479 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
484 if(fabs(residuals[i])/mean_residual < 1.5){
486 updatedRecHits.push_back(newHit1D);
487 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << fabs(residuals[i])/mean_residual << endl;
491 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << fabs(residuals[i])/mean_residual << endl;
497 phiSeg->
update(updatedRecHits);
505 cout <<
" Check the update action: " << endl;
508 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
509 hit!=hits_upd.end(); ++
hit) {
515 x_upd.push_back(pos.
z());
516 y_upd.push_back(pos.
x());
518 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
523 cout <<
" end of segment! " << endl;
524 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
540 vector<double> d_drift;
550 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
559 float distance = fabs(
hit->localPosition().
x() - xwire);
564 x.push_back(pos.
z());
565 y.push_back(pos.
x());
567 d_drift.push_back(distance);
578 Fit4Var(x,y,lc,d_drift,nptfit,cminf,vminf,chi2fit);
580 double t0cor = -999.;
581 if(cminf > -998.) t0cor = - cminf/0.00543 ;
595 const vector<float>& yfit,
596 const vector<int>& lfit,
597 const vector<double>& tfit,
601 double& chi2fit)
const {
603 const double sigma = 0.0295;
620 double chi2fitN2 = -1. ;
621 double chi2fit3 = -1.;
622 double chi2fitN3 = -1. ;
623 double chi2fitN4 = -1.;
624 float bminf3 = bminf;
625 float aminf3 = aminf;
626 float cminf3 = cminf;
634 for (
int j=0;
j<nptfit;
j++){
637 sx2 = sx2 + xfit[
j]*xfit[
j];
638 sxy = sxy + xfit[
j]*yfit[
j];
640 sl2 = sl2 + lfit[
j]*lfit[
j];
641 sly = sly + lfit[
j]*yfit[
j];
642 slx = slx + lfit[
j]*xfit[
j];
644 st2 = st2 + tfit[
j] * tfit[
j];
645 slt = slt + lfit[
j] * tfit[
j];
646 sltx = sltx + lfit[
j] * tfit[
j]*xfit[
j];
647 slty = slty + lfit[
j] * tfit[
j]*yfit[
j];
651 const double delta = nptfit*sx2 - sx*sx;
657 a = (sx2*sy - sx*sxy)/delta;
658 b = (nptfit*sxy - sx*sy)/delta;
661 for (
int j=0;
j<nptfit;
j++){
662 const double ypred = a + b*xfit[
j];
663 const double dy = (yfit[
j] - ypred)/sigma;
664 chi2fit = chi2fit + dy*dy;
674 chi2fitN2 = chi2fit/(nptfit-2);
680 const double d1 = sy;
681 const double d2 = sxy;
682 const double d3 = sly;
683 const double c1 = sl;
684 const double c2 = slx;
685 const double c3 = sl2;
686 const double b1 = sx;
687 const double b2 = sx2;
688 const double b3 = slx;
689 const double a1 = nptfit;
690 const double a2 = sx;
691 const double a3 = sl;
694 const double b4 = b2*a1-b1*a2;
695 const double c4 = c2*a1-c1*a2;
696 const double d4 = d2*a1-d1*a2;
697 const double b5 = a1*b3-a3*b1;
698 const double c5 = a1*c3-a3*
c1;
699 const double d5 = a1*d3-d1*a3;
700 const double a6 = slt;
701 const double b6 = sltx;
702 const double c6 = st;
703 const double v6 = st2;
704 const double d6 = slty;
706 if (((c5*b4-c4*b5)*b4*a1)!=0) {
709 cminf = (d5*b4-d4*b5)/(c5*b4-c4*b5);
710 bminf = d4/b4 -cminf *c4/b4;
711 aminf = (d1/a1 -cminf*c1/a1 -bminf*b1/a1);
713 for (
int j=0;
j<nptfit;
j++){
714 const double ypred = aminf + bminf*xfit[
j];
715 const double dy = (yfit[
j]-cminf*lfit[
j] - ypred)/sigma;
716 chi2fit = chi2fit + dy*dy;
721 chi2fitN3 = chi2fit /(nptfit-3);
729 chi2fitN3 = chi2fit /(nptfit-2);
738 cout <<
"dt0= 0 : slope 2 = " << b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
739 <<
" nppar = " << nppar2 <<
" nptfit = " << nptfit << endl;
740 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
741 << chi2fitN3 <<
" nppar = " << nppar3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
747 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))
748 + a2*a2*c6*c6 + 2*a2*(a3*(b3*v6 - b6*c6) - a6*b3*c6) + a3*a3*(b6*b6 - b2*v6)
749 + a6*(2*a3*(b2*c6 - b3*b6) + a6*b3*b3));
756 aminf = (a1*(a2*(b6*d6 - v6*d2) + a6*(b6*d2 - b2*d6) + d1*(b2*v6 - b6*b6)) - a2*(b3*(c6*d6 - v6*d3)
757 + c6*(b6*d3 - c6*d2)) + a3*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2))
758 + a6*(b2*c6*d3 + b3*(b3*d6 - b6*d3 - c6*d2)) - d1*(b2*c6*c6 + b3*(b3*v6 - 2*b6*c6)))/det;
759 bminf = - (a1*a1*(b6*d6 - v6*d2) - a1*(a2*(a6*d6 - v6*d1) - a6*a6*d2 + a6*b6*d1 + b3*(c6*d6 - v6*d3)
760 + c6*(b6*d3 - c6*d2)) + a2*(a3*(c6*d6 - v6*d3) + c6*(a6*d3 - c6*d1)) + a3*a3*(v6*d2 - b6*d6)
761 + a3*(a6*(b3*d6 + b6*d3 - 2*c6*d2) - d1*(b3*v6 - b6*c6)) - a6*b3*(a6*d3 - c6*d1))/det;
762 cminf = -(a1*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2)) + a2*a2*(v6*d3 - c6*d6)
763 + a2*(a3*(b6*d6 - v6*d2) + a6*(b3*d6 - 2*b6*d3 + c6*d2) - d1*(b3*v6 - b6*c6))
764 + a3*(d1*(b2*v6 - b6*b6) - a6*(b2*d6 - b6*d2)) + a6*(a6*(b2*d3 - b3*d2) - d1*(b2*c6 - b3*b6)))/det;
765 vminf = - (a1*a1*(b2*d6 - b6*d2) - a1*(a2*a2*d6 - a2*(a6*d2 + b6*d1) + a6*b2*d1 + b2*c6*d3
766 + 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))
767 + a3*a3*(b6*d2 - b2*d6) + a3*(a6*(b2*d3 - b3*d2) + d1*(b2*c6 - b3*b6)) + a6*b3*b3*d1)/det;
770 for (
int j=0;
j<nptfit;
j++) {
771 const double ypred = aminf + bminf*xfit[
j];
772 const double dy = (yfit[
j]+vminf*lfit[
j]*tfit[
j]-cminf*lfit[
j] -ypred)/sigma;
773 chi2fit = chi2fit + dy*dy;
781 chi2fitN4= chi2fit / (nptfit-nppar);
787 if (nptfit <= nppar) chi2fitN4=-1;
788 else chi2fitN4 = chi2fit / (nptfit-nppar);
791 if (fabs(vminf) >= 0.29) {
817 cout <<
" dt0= 0 : slope 4 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
818 <<
" nppar= " << nppar4 <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
819 cout << nptfit <<
" nptfit " <<
" end chi2fit = " << chi2fit/ (nptfit-nppar ) <<
" T0_ev ns= " << cminf/0.00543 <<
" delta v = " << vminf <<endl;
822 if ( fabs(vminf) >= 0.09 &&
debug ) {
823 cout <<
"vminf gt 0.09 det= " << endl;
824 cout <<
"dt0= 0 : slope 4 = "<< bminf <<
" pos out = " << aminf <<
" chi2fitN4 = " << chi2fitN4
825 <<
" T0_ev ns = " << cminf/0.00543 <<
" delta v = "<< vminf << endl;
826 cout <<
"dt0 = 0 : slope 2 = "<< b <<
" pos in = " << a <<
" chi2fitN2 = " << chi2fitN2
827 <<
" nppar = " << nppar-1 <<
" nptfit = " << nptfit <<endl;
828 cout <<
"dt0 = 0 : slope 3 = " << bminf <<
" pos out = " << aminf <<
" chi2fitN3 = "
829 << chi2fitN3 <<
" T0_ev ns = " << cminf/0.00543 << endl;
830 cout << nptfit <<
" nptfit "<<
" end chi2fit = " << chi2fit <<
"T0_ev ns= " << cminf/0.00543 <<
"delta v = "<< vminf <<endl;
833 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)