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 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,0);
110 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
201 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
218 if (!seg->
good())
return false;
228 vector <double> dist;
238 for (DTSegmentCand::AssPointCont::const_iterator
iter=hits.begin();
iter!=hits.end(); ++
iter) {
239 LocalPoint pos = (*iter).first->localPosition((*iter).second);
241 float distance = pos.
x() - xwire;
244 else lfit.push_back(-1);
246 dist.push_back(distance);
247 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
248 x.push_back(pos.
z());
249 y.push_back(pos.
x());
261 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par);
262 if (cminf!=0) t0_corr=-cminf/0.00543;
264 if (
debug && fitdebug)
cout <<
" DTcand chi2: " << chi2 << endl;
265 if (
debug && fitdebug)
cout <<
" DTcand t0: " << t0_corr << endl;
282 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
288 vector <double> dist;
300 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
306 x.push_back(pos.
z());
307 y.push_back(pos.
x());
311 float distance = fabs(
hit->localPosition().
x() - xwire);
312 dist.push_back(distance);
322 sigy.push_back(
sqrt(slErr.
xx()));
333 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par,block3par);
334 if (cminf!=0) t0_corr=-cminf/0.00543;
336 if (
debug)
cout <<
" DTSeg2d chi2: " << chi2 << endl;
337 if (
debug)
cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
350 const vector<float>&
y,
351 const vector<int>& lfit,
352 const vector<double>& dist,
353 const vector<float>& sigy,
360 const bool allow3par,
361 const bool block3par)
const {
364 float intercept = 0.;
372 int leftHits=0, rightHits=0;
373 for (
unsigned int i=0;
i<lfit.size();
i++)
374 if (lfit[
i]==1) leftHits++;
else rightHits++;
380 if (leftHits && rightHits && (leftHits+rightHits>3) && allow3par) {
381 theFitter->
fitNpar(3,x,y,lfit,dist,sigy,slope,intercept,cminf,vminf,chi2,
debug);
382 double t0_corr=-cminf/0.00543;
383 if (fabs(t0_corr)<20. && block3par) {
402 covMatrix[0][0] = covss;
403 covMatrix[1][1] = covii;
404 covMatrix[1][0] = covsi;
416 vector<DTRecHit1D> updatedRecHits;
418 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
419 hit!=toBeUpdatedRecHits.end(); ++
hit) {
427 const float angle = atan(segDir.
x()/-segDir.
z());
438 }
else if (step == 3) {
440 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
442 newHit1D.setPosition(hitPos);
445 }
else if (step == 4) {
459 const float distance = fabs(
hit->localPosition().
x() - xwire);
461 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
469 newHit1D.setPositionAndError(point, error);
474 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
476 if (ok) updatedRecHits.push_back(newHit1D);
478 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
479 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
483 seg->
update(updatedRecHits);
491 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
494 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
501 x.push_back(pos.
z());
502 y.push_back(pos.
x());
506 cout <<
" end of segment! " << endl;
507 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
511 float par[2]={0.,0.};
525 for(
size_t i = 0;
i <
N;++
i){
528 Sx2 += x.at(
i)*x.at(
i);
529 Sy2 += y.at(
i)*y.at(
i);
530 Sxy += x.at(
i)*y.at(
i);
534 const float delta = N*Sx2 - Sx*Sx;
535 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
536 par[1] = ( N*Sxy - Sx*Sy )/delta;
538 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
543 for(
size_t i = 0;
i <
N;++
i)
546 for(
size_t i = 0;
i <
N;++
i){
547 residuals[
i] = y.at(
i) - par[1]*x.at(
i) - par[0];
549 cout<<
" i: "<<
i<<
" y_i "<<y.at(
i)<<
" x_i "<<x.at(
i)<<
" res_i "<<residuals[
i];
550 if (
i==N-1)
cout<<endl;
554 if(
debug)
cout <<
" Residuals computed! "<< endl;
557 vector<DTRecHit1D> updatedRecHits;
559 float mean_residual = 0.;
561 for (
size_t i = 0;
i <
N; ++
i)
562 mean_residual += fabs(residuals[
i]);
564 mean_residual = mean_residual/(N - 2);
566 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
570 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
575 float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
576 if(normResidual < 1.5){
578 updatedRecHits.push_back(newHit1D);
579 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
583 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
589 phiSeg->
update(updatedRecHits);
597 cout <<
" Check the update action: " << endl;
600 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
601 hit!=hits_upd.end(); ++
hit) {
607 x_upd.push_back(pos.
z());
608 y_upd.push_back(pos.
x());
610 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
613 cout <<
" end of segment! " << endl;
614 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
629 if(
debug)
cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
631 vector<double> d_drift;
641 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
650 float distance = fabs(
hit->localPosition().
x() - xwire);
655 x.push_back(pos.
z());
656 y.push_back(pos.
x());
658 d_drift.push_back(distance);
670 theFitter->
fit4Var(x,y,lc,d_drift,nptfit,a,b,cminf,vminf,chi2fit,
vdrift_4parfit,
debug);
672 double t0cor = -999.;
673 if(cminf > -998.) t0cor = - cminf/0.00543 ;
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 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.
virtual double chi2() const
the chi2 of the fit
~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
void fit(const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigy, float &slope, float &intercept, double &chi2, float &covss, float &covii, float &covsi) 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
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 &aminf, float &bminf, float &cminf, float &vminf, double &chi2fit, const bool vdrift_4parfit, const bool debug) const
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)
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.
void fitNpar(const int npar, const std::vector< float > &xfit, const std::vector< float > &yfit, const std::vector< int > &lfit, const std::vector< double > &tfit, const std::vector< float > &sigy, float &aminf, float &bminf, float &cminf, float &vminf, double &chi2fit, const bool debug) const
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
virtual void sett0(double &t0)
set t0
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 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 update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
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
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
DTSegmentUpdator(const edm::ParameterSet &config)
Constructor.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)