49 vdrift_4parfit(config.getParameter<
bool>(
"performT0_vdriftSegCorrection")),
50 T0_hit_resolution(config.getParameter<double>(
"hit_afterT0_resolution")),
54 string theAlgoName = config.
getParameter<
string>(
"recAlgo");
58 if (config.
exists(
"intime_cut"))
62 cout <<
"[DTSegmentUpdator] Constructor called" << endl;
79 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
81 const bool hasPhi = seg->
hasPhi();
82 const bool hasZed = seg->
hasZed();
87 int step = (hasPhi && hasZed) ? 3 : 2;
90 if(
debug)
cout <<
"Step of update is " << step << endl;
104 if(
debug)
cout <<
"[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
109 fit(seg,allow3par,
false);
113 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
201 dirZInCh*(-posZInCh.
z())/
cos(dirZInCh.
theta());
228 vector <double> dist;
237 for (DTSegmentCand::AssPointCont::const_iterator iter=seg->
hits().begin(); iter!=seg->
hits().end(); ++iter) {
238 LocalPoint pos = (*iter).first->localPosition((*iter).second);
243 else lfit.push_back(-1);
245 dist.push_back(distance);
246 sigy.push_back(
sqrt((*iter).first->localPositionError().xx()));
247 x.push_back(pos.
z());
248 y.push_back(pos.
x());
260 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par);
261 if (cminf!=0) t0_corr=-cminf/0.00543;
263 if (
debug && fitdebug)
264 cout <<
" DTcand chi2: " << chi2 <<
"/" << x.size() <<
" t0: " << t0_corr << endl;
281 if(
debug)
cout <<
"[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
287 vector <double> dist;
299 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
305 x.push_back(pos.
z());
306 y.push_back(pos.
x());
310 float distance = fabs(
hit->localPosition().
x() - xwire);
311 dist.push_back(distance);
321 sigy.push_back(
sqrt(slErr.
xx()));
332 fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par,block3par);
333 if (cminf!=0) t0_corr=-cminf/0.00543;
335 if (
debug)
cout <<
" DTSeg2d chi2: " << chi2 << endl;
336 if (
debug)
cout <<
" DTSeg2d Fit t0: " << t0_corr << endl;
349 const vector<float>&
y,
350 const vector<int>& lfit,
351 const vector<double>& dist,
352 const vector<float>& sigy,
359 const bool allow3par,
360 const bool block3par)
const {
363 float intercept = 0.;
371 int leftHits=0, rightHits=0;
372 for (
unsigned int i=0;
i<lfit.size();
i++)
373 if (lfit[
i]==1) leftHits++;
else rightHits++;
379 if (leftHits && rightHits && (leftHits+rightHits>3) && allow3par) {
380 theFitter->
fitNpar(3,x,y,lfit,dist,sigy,slope,intercept,cminf,vminf,chi2,
debug);
381 double t0_corr=-cminf/0.00543;
401 covMatrix[0][0] = covss;
402 covMatrix[1][1] = covii;
403 covMatrix[1][0] = covsi;
415 vector<DTRecHit1D> updatedRecHits;
417 for (vector<DTRecHit1D>::iterator
hit= toBeUpdatedRecHits.begin();
418 hit!=toBeUpdatedRecHits.end(); ++
hit) {
426 const float angle = atan(segDir.
x()/-segDir.
z());
437 }
else if (step == 3) {
439 LocalPoint hitPos(
hit->localPosition().
x(),+segPosAtLayer.y(),0.);
441 newHit1D.setPosition(hitPos);
444 }
else if (step == 4) {
458 const float distance = fabs(
hit->localPosition().
x() - xwire);
460 const double dy_corr = (vminf*ilc*distance-cminf*ilc );
468 newHit1D.setPositionAndError(point, error);
473 }
else throw cms::Exception(
"DTSegmentUpdator")<<
" updateHits called with wrong step " << endl;
475 if (ok) updatedRecHits.push_back(newHit1D);
477 LogError(
"DTSegmentUpdator")<<
"DTSegmentUpdator::updateHits failed update" << endl;
478 throw cms::Exception(
"DTSegmentUpdator")<<
"updateHits failed update"<<endl;
482 seg->
update(updatedRecHits);
490 if(
debug)
cout <<
" Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
493 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
500 x.push_back(pos.
z());
501 y.push_back(pos.
x());
505 cout <<
" end of segment! " << endl;
506 cout <<
" size = Number of Hits: " << x.size() <<
" " << y.size() << endl;
510 float par[2]={0.,0.};
524 for(
size_t i = 0;
i <
N;++
i){
527 Sx2 += x.at(
i)*x.at(
i);
528 Sy2 += y.at(
i)*y.at(
i);
529 Sxy += x.at(
i)*y.at(
i);
533 const float delta = N*Sx2 - Sx*Sx;
534 par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
535 par[1] = ( N*Sxy - Sx*Sy )/delta;
537 if(
debug)
cout <<
"fit 2 parameters done ----> par0: "<< par[0] <<
" par1: "<< par[1] << endl;
542 for(
size_t i = 0;
i <
N;++
i)
545 for(
size_t i = 0;
i <
N;++
i){
546 residuals[
i] = y.at(
i) - par[1]*x.at(
i) - par[0];
548 cout<<
" i: "<<
i<<
" y_i "<<y.at(
i)<<
" x_i "<<x.at(
i)<<
" res_i "<<residuals[
i];
549 if (
i==N-1)
cout<<endl;
553 if(
debug)
cout <<
" Residuals computed! "<< endl;
556 vector<DTRecHit1D> updatedRecHits;
558 float mean_residual = 0.;
560 for (
size_t i = 0;
i <
N; ++
i)
561 mean_residual += fabs(residuals[
i]);
563 mean_residual = mean_residual/(N - 2);
565 if(
debug)
cout <<
" mean_residual: "<< mean_residual << endl;
569 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
574 float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
575 if(normResidual < 1.5){
577 updatedRecHits.push_back(newHit1D);
578 if(
debug)
cout <<
" accepted "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
582 if(
debug)
cout <<
" rejected "<< i+1 <<
"th hit" <<
" Irej: " << normResidual << endl;
588 phiSeg->
update(updatedRecHits);
596 cout <<
" Check the update action: " << endl;
599 for (vector<DTRecHit1D>::const_iterator
hit=hits_upd.begin();
600 hit!=hits_upd.end(); ++
hit) {
606 x_upd.push_back(pos.
z());
607 y_upd.push_back(pos.
x());
609 cout <<
" x_upd: "<< pos.
z() <<
" y_upd: "<< pos.
x() << endl;
612 cout <<
" end of segment! " << endl;
613 cout <<
" size = Number of Hits: " << x_upd.size() <<
" " << y_upd.size() << endl;
628 if(
debug)
cout <<
"[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
630 vector<double> d_drift;
640 for (vector<DTRecHit1D>::const_iterator
hit=hits.begin();
649 float distance = fabs(
hit->localPosition().
x() - xwire);
654 x.push_back(pos.
z());
655 y.push_back(pos.
x());
657 d_drift.push_back(distance);
669 theFitter->
fit4Var(x,y,lc,d_drift,nptfit,a,b,cminf,vminf,chi2fit,
vdrift_4parfit,
debug);
671 double t0cor = -999.;
672 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)
LocalPoint localPosition() const override
Local position in Chamber frame.
Local3DVector LocalVector
Point3DBase< Scalar, LocalTag > LocalPoint
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
void calculateT0corr(DTRecSegment2D *seg) const
LocalVector localDirection() const override
Local direction in Chamber frame.
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 const AssPointCont & hits() const
the used hits
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~DTSegmentUpdator()
Destructor.
def setup(process, global_tag, zero_tesla=False)
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
AlgebraicSymMatrix parametersError() const override
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)
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
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.
double chi2() const override
the chi2 of the fit
bool hasPhi() const
Does it have the Phi projection?
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
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
Vector3DBase unit() const
bool hasZed() const
Does it have the Z projection?
virtual void sett0(double &t0)
set t0
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
LocalPoint localPosition() const override
local position in SL frame
void setT0(const double &t0)
virtual bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const =0
virtual void setDirection(LocalVector &dir)
set direction
LocalVector localDirection() const override
the local direction in SL frame
const GeomDet * idToDet(DetId) const override
void setPosition(const LocalPoint &pos)
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)
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
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
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.
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)