CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
DTSegmentUpdator Class Reference

#include <DTSegmentUpdator.h>

Public Member Functions

void calculateT0corr (DTRecSegment2D *seg) const
 
void calculateT0corr (DTRecSegment4D *seg) const
 
 DTSegmentUpdator (const edm::ParameterSet &config, edm::ConsumesCollector)
 Constructor. More...
 
bool fit (DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
 
void fit (DTRecSegment2D *seg, bool allow3par, bool block3par) const
 
void fit (DTRecSegment4D *seg, bool allow3par) const
 
void setES (const edm::EventSetup &setup)
 set the setup More...
 
void update (DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
 recompute hits position and refit the segment4D More...
 
void update (DTRecSegment2D *seg, bool allow3par) const
 recompute hits position and refit the segment2D More...
 
 ~DTSegmentUpdator ()
 Destructor. More...
 

Private Member Functions

void fit (const std::vector< float > &x, const std::vector< float > &y, const std::vector< int > &lfit, const std::vector< double > &dist, const std::vector< float > &sigy, LocalPoint &pos, LocalVector &dir, float &cminf, float &vminf, AlgebraicSymMatrix &covMat, double &chi2, const bool allow3par=false, const bool block3par=false) const
 interface to LinearFit More...
 
void rejectBadHits (DTChamberRecSegment2D *) const
 
void updateHits (DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
 

Private Attributes

bool debug
 
double intime_cut
 
bool perform_delta_rejecting
 
double T0_hit_resolution
 
std::unique_ptr< DTRecHitBaseAlgotheAlgo
 
std::unique_ptr< DTLinearFittheFitter
 
edm::ESHandle< DTGeometrytheGeom
 
const edm::ESGetToken< DTGeometry, MuonGeometryRecordtheGeomToken
 
bool vdrift_4parfit
 

Detailed Description

Perform linear fit and hits update for DT segments. Update a segment by improving the hits thanks to the refined knowledge of impact angle and position (also along the wire) and perform linear fit on improved hits.

Author
Stefano Lacaprara - INFN Legnaro stefa.nosp@m.no.l.nosp@m.acapr.nosp@m.ara@.nosp@m.pd.in.nosp@m.fn.i.nosp@m.t
Riccardo Bellan - INFN TO ricca.nosp@m.rdo..nosp@m.bella.nosp@m.n@ce.nosp@m.rn.ch
M.Meneghelli - INFN BO marco.nosp@m..men.nosp@m.eghel.nosp@m.li@c.nosp@m.ern.c.nosp@m.h

Definition at line 46 of file DTSegmentUpdator.h.

Constructor & Destructor Documentation

◆ DTSegmentUpdator()

DTSegmentUpdator::DTSegmentUpdator ( const edm::ParameterSet config,
edm::ConsumesCollector  cc 
)

Constructor.

Definition at line 47 of file DTSegmentUpdator.cc.

48  : theFitter{std::make_unique<DTLinearFit>()},
50  config.getParameter<string>("recAlgo"), config.getParameter<ParameterSet>("recAlgoConfig"), cc)},
52  vdrift_4parfit(config.getParameter<bool>("performT0_vdriftSegCorrection")),
53  T0_hit_resolution(config.getParameter<double>("hit_afterT0_resolution")),
54  perform_delta_rejecting(config.getParameter<bool>("perform_delta_rejecting")),
55  debug(config.getUntrackedParameter<bool>("debug", false)) {
56  intime_cut = 20.;
57  if (config.exists("intime_cut"))
58  intime_cut = config.getParameter<double>("intime_cut");
59 
60  if (debug)
61  cout << "[DTSegmentUpdator] Constructor called" << endl;
62 }
Definition: config.py:1
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
std::unique_ptr< DTLinearFit > theFitter
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theGeomToken
#define get

◆ ~DTSegmentUpdator()

DTSegmentUpdator::~DTSegmentUpdator ( )
default

Destructor.

Member Function Documentation

◆ calculateT0corr() [1/2]

void DTSegmentUpdator::calculateT0corr ( DTRecSegment2D seg) const

Definition at line 619 of file DTSegmentUpdator.cc.

References a, b, gather_cfg::cout, debug, HLT_2022v15_cff::distance, TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, DTGeometry::idToDet(), DTGeometry::layer(), phase1PixelTopology::layer, DTEnums::Left, DTRecSegment2D::setT0(), DTRecSegment2D::setVdrift(), DTRecSegment2D::specificRecHits(), theFitter, theGeom, vdrift_4parfit, x, hit::x, and y.

Referenced by calculateT0corr(), DTMeantimerPatternReco4D::reconstruct(), DTCombinatorialPatternReco4D::reconstruct(), and update().

619  {
620  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
621  // seg->geographicalId() can be a superLayerId or a chamberId
622  if (debug)
623  cout << "[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
624 
625  vector<double> d_drift;
626  vector<float> x;
627  vector<float> y;
628  vector<int> lc;
629 
630  vector<DTRecHit1D> hits = seg->specificRecHits();
631 
632  DTWireId wireId;
633  int nptfit = 0;
634 
635  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
636  // I have to get the hits position (the hit is in the layer rf) in SL frame...
637  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
638  LocalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toLocal(glbPos);
639 
640  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
641  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
642  float distance = fabs(hit->localPosition().x() - xwire);
643 
644  int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
645 
646  nptfit++;
647  x.push_back(pos.z());
648  y.push_back(pos.x());
649  lc.push_back(ilc);
650  d_drift.push_back(distance);
651 
652  // cout << " d_drift "<<distance <<" npt= " <<npt<<endl;
653  }
654 
655  double chi2fit = 0.;
656  float cminf = 0.;
657  float vminf = 0.;
658  float a, b;
659 
660  if (nptfit > 2) {
661  //NB chi2fit is normalized
662  theFitter->fit4Var(x, y, lc, d_drift, nptfit, a, b, cminf, vminf, chi2fit, vdrift_4parfit, debug);
663 
664  double t0cor = -999.;
665  if (cminf > -998.)
666  t0cor = -cminf / 0.00543; // in ns
667 
668  //cout << "In calculateT0corr: t0 = " << t0cor << endl;
669  //cout << "In calculateT0corr: vminf = " << vminf << endl;
670  //cout << "In calculateT0corr: cminf = " << cminf << endl;
671  //cout << "In calculateT0corr: chi2 = " << chi2fit << endl;
672 
673  seg->setT0(t0cor); // time and
674  seg->setVdrift(vminf); // vdrift correction are recorded in the segment
675  }
676 }
edm::ESHandle< DTGeometry > theGeom
constexpr std::array< uint8_t, layerIndexSize > layer
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
std::unique_ptr< DTLinearFit > theFitter
DetId geographicalId() const
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
double b
Definition: hdecay.h:118
void setT0(const double &t0)
double a
Definition: hdecay.h:119
void setVdrift(const double &vdrift)
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96

◆ calculateT0corr() [2/2]

void DTSegmentUpdator::calculateT0corr ( DTRecSegment4D seg) const

Definition at line 612 of file DTSegmentUpdator.cc.

References calculateT0corr(), DTRecSegment4D::hasPhi(), DTRecSegment4D::hasZed(), DTRecSegment4D::phiSegment(), and DTRecSegment4D::zSegment().

612  {
613  if (seg->hasPhi())
614  calculateT0corr(seg->phiSegment());
615  if (seg->hasZed())
616  calculateT0corr(seg->zSegment());
617 }
bool hasPhi() const
Does it have the Phi projection?
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
void calculateT0corr(DTRecSegment2D *seg) const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
bool hasZed() const
Does it have the Z projection?

◆ fit() [1/4]

bool DTSegmentUpdator::fit ( DTSegmentCand seg,
bool  allow3par,
const bool  fitdebug 
) const

do the linear fit on the hits of the segment candidate and update it. Returns false if the segment candidate is not good()

Definition at line 217 of file DTSegmentUpdator.cc.

References hltPixelTracks_cff::chi2, gather_cfg::cout, debug, DeadROC_duringRun::dir, HLT_2022v15_cff::distance, DTSegmentCand::hits(), mps_fire::i, DTEnums::Left, DTEnums::Right, DTSegmentCand::setChi2(), DTSegmentCand::setCovMatrix(), DTSegmentCand::setDirection(), DTSegmentCand::setPosition(), DTSegmentCand::sett0(), mathSSE::sqrt(), x, and y.

Referenced by DTCombinatorialExtendedPatternReco::buildPointsCollection(), DTCombinatorialPatternReco::buildPointsCollection(), DTCombinatorialExtendedPatternReco::extendCandidates(), fit(), DTMeantimerPatternReco::fitWithT0(), trackingPlots.Iteration::modules(), DTRefitAndCombineReco4D::refitSuperSegments(), and update().

217  {
218  // if (debug && fitdebug) cout << "[DTSegmentUpdator] Fit DTRecSegment2D" << endl;
219  // if (!seg->good()) return false;
220 
221  // DTSuperLayerId DTid = (DTSuperLayerId)seg->superLayer()->id();
222  // if (DTid.superlayer()==2)
223  // allow3par = 0;
224 
225  vector<float> x;
226  vector<float> y;
227  vector<float> sigy;
228  vector<int> lfit;
229  vector<double> dist;
230  int i = 0;
231 
232  x.reserve(8);
233  y.reserve(8);
234  sigy.reserve(8);
235  lfit.reserve(8);
236  dist.reserve(8);
237 
238  for (DTSegmentCand::AssPointCont::const_iterator iter = seg->hits().begin(); iter != seg->hits().end(); ++iter) {
239  LocalPoint pos = (*iter).first->localPosition((*iter).second);
240  float xwire =
241  (((*iter).first)->localPosition(DTEnums::Left).x() + ((*iter).first)->localPosition(DTEnums::Right).x()) / 2.;
242  float distance = pos.x() - xwire;
243 
244  if ((*iter).second == DTEnums::Left)
245  lfit.push_back(1);
246  else
247  lfit.push_back(-1);
248 
249  dist.push_back(distance);
250  sigy.push_back(sqrt((*iter).first->localPositionError().xx()));
251  x.push_back(pos.z());
252  y.push_back(pos.x());
253  i++;
254  }
255 
256  LocalPoint pos;
258  AlgebraicSymMatrix covMat(2);
259  float cminf = 0.;
260  float vminf = 0.;
261  double chi2 = 0.;
262  double t0_corr = 0.;
263 
264  fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par);
265  if (cminf != 0)
266  t0_corr = -cminf / 0.00543; // convert drift distance to time
267 
268  if (debug && fitdebug)
269  cout << " DTcand chi2: " << chi2 << "/" << x.size() << " t0: " << t0_corr << endl;
270 
271  seg->setPosition(pos);
272  seg->setDirection(dir);
273  seg->sett0(t0_corr);
274  seg->setCovMatrix(covMat);
275  seg->setChi2(chi2);
276 
277  // cout << "pos " << pos << endl;
278  // cout << "dir " << dir << endl;
279  // cout << "Mat " << covMat << endl;
280 
281  return true;
282 }
virtual void setChi2(double &chi2)
set chi2
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
T sqrt(T t)
Definition: SSEVec.h:19
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
virtual const AssPointCont & hits() const
the used hits
virtual void sett0(double &t0)
set t0
virtual void setDirection(LocalVector &dir)
set direction
Definition: DTSegmentCand.h:93
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual void setPosition(LocalPoint &pos)
set position
Definition: DTSegmentCand.h:90

◆ fit() [2/4]

void DTSegmentUpdator::fit ( DTRecSegment2D seg,
bool  allow3par,
bool  block3par 
) const

ditto for true segment: since the fit is applied on a true segment, by definition the segment is "good", while it's not the case for just candidates

Definition at line 284 of file DTSegmentUpdator.cc.

References hltPixelTracks_cff::chi2, gather_cfg::cout, debug, DeadROC_duringRun::dir, HLT_2022v15_cff::distance, fit(), TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, DTGeometry::idToDet(), DTGeometry::layer(), phase1PixelTopology::layer, DTEnums::Left, DTRecSegment2D::setChi2(), DTRecSegment2D::setCovMatrix(), DTRecSegment2D::setDirection(), DTRecSegment2D::setPosition(), DTRecSegment2D::setT0(), DTRecSegment2D::specificRecHits(), mathSSE::sqrt(), theGeom, ErrorFrameTransformer::transform(), x, hit::x, LocalError::xx(), and y.

Referenced by trackingPlots.Iteration::modules().

284  {
285  if (debug)
286  cout << "[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
287 
288  vector<float> x;
289  vector<float> y;
290  vector<float> sigy;
291  vector<int> lfit;
292  vector<double> dist;
293  x.reserve(8);
294  y.reserve(8);
295  sigy.reserve(8);
296  lfit.reserve(8);
297  dist.reserve(8);
298 
299  // DTSuperLayerId DTid = (DTSuperLayerId)seg->geographicalId();
300  // if (DTid.superlayer()==2)
301  // allow3par = 0;
302 
303  vector<DTRecHit1D> hits = seg->specificRecHits();
304  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
305  // I have to get the hits position (the hit is in the layer rf) in SL frame...
306  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
307  LocalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toLocal(glbPos);
308  x.push_back(pos.z());
309  y.push_back(pos.x());
310 
311  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
312  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
313  float distance = fabs(hit->localPosition().x() - xwire);
314  dist.push_back(distance);
315 
316  int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
317  lfit.push_back(ilc);
318 
319  // Get local error in SL frame
320  //RB: is it right in this way?
322  GlobalError glbErr =
323  tran.transform(hit->localPositionError(), (theGeom->layer(hit->wireId().layerId()))->surface());
324  LocalError slErr = tran.transform(glbErr, (theGeom->idToDet(seg->geographicalId()))->surface());
325  sigy.push_back(sqrt(slErr.xx()));
326  }
327 
328  LocalPoint pos;
330  AlgebraicSymMatrix covMat(2);
331  double chi2 = 0.;
332  float cminf = 0.;
333  float vminf = 0.;
334  double t0_corr = 0.;
335 
336  fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par, block3par);
337  if (cminf != 0)
338  t0_corr = -cminf / 0.00543; // convert drift distance to time
339 
340  if (debug)
341  cout << " DTSeg2d chi2: " << chi2 << endl;
342  if (debug)
343  cout << " DTSeg2d Fit t0: " << t0_corr << endl;
344  // cout << "pos " << segPosition << endl;
345  // cout << "dir " << segDirection << endl;
346  // cout << "Mat " << mat << endl;
347 
348  seg->setPosition(pos);
349  seg->setDirection(dir);
350  seg->setCovMatrix(covMat);
351  seg->setChi2(chi2);
352  seg->setT0(t0_corr);
353 }
static GlobalError transform(const LocalError &le, const Surface &surf)
void setChi2(const double &chi2)
void setCovMatrix(const AlgebraicSymMatrix &cov)
edm::ESHandle< DTGeometry > theGeom
constexpr std::array< uint8_t, layerIndexSize > layer
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
T sqrt(T t)
Definition: SSEVec.h:19
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
DetId geographicalId() const
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
void setT0(const double &t0)
void setPosition(const LocalPoint &pos)
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setDirection(const LocalVector &dir)
float xx() const
Definition: LocalError.h:22
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96

◆ fit() [3/4]

void DTSegmentUpdator::fit ( DTRecSegment4D seg,
bool  allow3par 
) const

ditto for true segment 4D, the fit is done on either projection and then the 4D direction and position is built. Since the fit is applied on a true segment, by definition the segment is "good", while it's not the case for just candidates

Definition at line 116 of file DTSegmentUpdator.cc.

References DTGeometry::chamber(), DTSuperLayerId::chamberId(), DTRecSegment4D::chamberId(), DTRecSegment2D::chi2(), funct::cos(), gather_cfg::cout, debug, DeadROC_duringRun::dir, fit(), DTRecSegment4D::hasPhi(), DTRecSegment4D::hasZed(), intime_cut, DTRecSegment2D::localDirection(), DTRecSegment2D::localPosition(), DTRecSegment2D::parametersError(), DTRecSegment4D::phiSegment(), DTRecSegment4D::setCovMatrix(), DTRecSegment4D::setCovMatrixForZed(), DTRecSegment4D::setDirection(), DTRecSegment4D::setPosition(), DTGeometry::superLayer(), DTSLRecSegment2D::superLayerId(), DTRecSegment2D::t0(), theGeom, PV3DBase< T, PVType, FrameType >::theta(), GeomDet::toGlobal(), GeomDet::toLocal(), PV3DBase< T, PVType, FrameType >::x(), y, PV3DBase< T, PVType, FrameType >::y(), PV3DBase< T, PVType, FrameType >::z(), and DTRecSegment4D::zSegment().

Referenced by trackingPlots.Iteration::modules().

116  {
117  if (debug)
118  cout << "[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
119  // after the update must refit the segments
120 
121  if (debug) {
122  if (seg->hasPhi())
123  cout << " 4D Segment contains a Phi segment. t0= " << seg->phiSegment()->t0()
124  << " chi2= " << seg->phiSegment()->chi2() << endl;
125  if (seg->hasZed())
126  cout << " 4D Segment contains a Zed segment. t0= " << seg->zSegment()->t0()
127  << " chi2= " << seg->zSegment()->chi2() << endl;
128  }
129 
130  // If both phi and zed projections are present and the phi segment is in time (segment t0<intime_cut) the 3-par fit is blocked and
131  // segments are fit with the 2-par fit. Setting intime_cut to -1 results in the 3-par fit being used always.
132  if (seg->hasPhi()) {
133  if (seg->hasZed()) {
134  if (fabs(seg->phiSegment()->t0()) < intime_cut) {
135  fit(seg->phiSegment(), allow3par, true);
136  fit(seg->zSegment(), allow3par, true);
137  } else {
138  fit(seg->phiSegment(), allow3par, false);
139  fit(seg->zSegment(), allow3par, false);
140  }
141  } else
142  fit(seg->phiSegment(), allow3par, false);
143  } else
144  fit(seg->zSegment(), allow3par, false);
145 
146  const DTChamber* theChamber = theGeom->chamber(seg->chamberId());
147 
148  if (seg->hasPhi() && seg->hasZed()) {
149  DTChamberRecSegment2D* segPhi = seg->phiSegment();
150  DTSLRecSegment2D* segZed = seg->zSegment();
151 
152  // NB Phi seg is already in chamber ref
153  LocalPoint posPhiInCh = segPhi->localPosition();
154  LocalVector dirPhiInCh = segPhi->localDirection();
155 
156  // Zed seg is in SL one
157  const DTSuperLayer* zSL = theChamber->superLayer(segZed->superLayerId());
158  LocalPoint zPos(segZed->localPosition().x(), (zSL->toLocal(theChamber->toGlobal(segPhi->localPosition()))).y(), 0.);
159 
160  LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
161 
162  LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(segZed->localDirection()));
163 
164  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z()) / cos(dirZInCh.theta());
165 
166  // given the actual definition of chamber refFrame, (with z poiniting to IP),
167  // the zed component of direction is negative.
168  LocalVector dir = LocalVector(dirPhiInCh.x() / fabs(dirPhiInCh.z()), dirZInCh.y() / fabs(dirZInCh.z()), -1.);
169 
170  seg->setPosition(LocalPoint(posPhiInCh.x(), posZAt0.y(), 0.));
171  seg->setDirection(dir.unit());
172 
173  AlgebraicSymMatrix mat(4);
174 
175  // set cov matrix
176  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
177  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
178  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
179 
180  seg->setCovMatrix(mat);
181  seg->setCovMatrixForZed(posZInCh);
182  } else if (seg->hasPhi()) {
183  DTChamberRecSegment2D* segPhi = seg->phiSegment();
184 
185  seg->setPosition(segPhi->localPosition());
186  seg->setDirection(segPhi->localDirection());
187 
188  AlgebraicSymMatrix mat(4);
189  // set cov matrix
190  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
191  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
192  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
193 
194  seg->setCovMatrix(mat);
195  } else if (seg->hasZed()) {
196  DTSLRecSegment2D* segZed = seg->zSegment();
197 
198  // Zed seg is in SL one
199  GlobalPoint glbPosZ = (theGeom->superLayer(segZed->superLayerId()))->toGlobal(segZed->localPosition());
200  LocalPoint posZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()))->toLocal(glbPosZ);
201 
202  GlobalVector glbDirZ = (theGeom->superLayer(segZed->superLayerId()))->toGlobal(segZed->localDirection());
203  LocalVector dirZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()))->toLocal(glbDirZ);
204 
205  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z()) / cos(dirZInCh.theta());
206 
207  seg->setPosition(posZAt0);
208  seg->setDirection(dirZInCh);
209 
210  AlgebraicSymMatrix mat(4);
211  // set cov matrix
212  seg->setCovMatrix(mat);
213  seg->setCovMatrixForZed(posZInCh);
214  }
215 }
Local3DVector LocalVector
Definition: LocalVector.h:12
LocalPoint localPosition() const override
local position in SL frame
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
LocalVector localDirection() const override
the local direction in SL frame
bool hasPhi() const
Does it have the Phi projection?
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
T z() const
Definition: PV3DBase.h:61
double chi2() const override
the chi2 of the fit
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void setCovMatrixForZed(const LocalPoint &posZInCh)
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
edm::ESHandle< DTGeometry > theGeom
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
DTChamberId chamberId() const
Return the corresponding ChamberId.
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
Definition: DTGeometry.cc:92
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
AlgebraicSymMatrix parametersError() const override
void setDirection(LocalVector dir)
Set direction.
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setPosition(LocalPoint pos)
Set position.
bool hasZed() const
Does it have the Z projection?
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72

◆ fit() [4/4]

void DTSegmentUpdator::fit ( const std::vector< float > &  x,
const std::vector< float > &  y,
const std::vector< int > &  lfit,
const std::vector< double > &  dist,
const std::vector< float > &  sigy,
LocalPoint pos,
LocalVector dir,
float &  cminf,
float &  vminf,
AlgebraicSymMatrix covMat,
double &  chi2,
const bool  allow3par = false,
const bool  block3par = false 
) const
private

interface to LinearFit

Definition at line 355 of file DTSegmentUpdator.cc.

References hltPixelTracks_cff::chi2, debug, DeadROC_duringRun::dir, mps_fire::i, intime_cut, slope, theFitter, Vector3DBase< T, FrameTag >::unit(), x, and y.

Referenced by trackingPlots.Iteration::modules().

367  {
368  float slope = 0.;
369  float intercept = 0.;
370  float covss = 0.;
371  float covii = 0.;
372  float covsi = 0.;
373 
374  cminf = 0;
375  vminf = 0;
376 
377  int leftHits = 0, rightHits = 0;
378  for (unsigned int i = 0; i < lfit.size(); i++)
379  if (lfit[i] == 1)
380  leftHits++;
381  else
382  rightHits++;
383 
384  theFitter->fit(x, y, x.size(), sigy, slope, intercept, chi2, covss, covii, covsi);
385 
386  // If we have at least one left and one right hit we can try the 3 parameter fit (if it is switched on)
387  // FIXME: currently the covariance matrix from the 2-par fit is kept
388  if (leftHits && rightHits && (leftHits + rightHits > 3) && allow3par) {
389  theFitter->fitNpar(3, x, y, lfit, dist, sigy, slope, intercept, cminf, vminf, chi2, debug);
390  double t0_corr = -cminf / 0.00543;
391  if (fabs(t0_corr) < intime_cut && block3par) {
392  theFitter->fit(x, y, x.size(), sigy, slope, intercept, chi2, covss, covii, covsi);
393  cminf = 0;
394  }
395  }
396 
397  // cout << "slope " << slope << endl;
398  // cout << "intercept " << intercept << endl;
399 
400  // intercept is the x() in chamber frame when the segment cross the chamber
401  // plane (at z()=0), the y() is not measured, so let's put the center of the
402  // chamber.
403  pos = LocalPoint(intercept, 0., 0.);
404 
405  // slope is dx()/dz(), while dy()/dz() is by definition 0, finally I want the
406  // segment to point outward, so opposite to local z
407  dir = LocalVector(-slope, 0., -1.).unit();
408 
409  covMatrix = AlgebraicSymMatrix(2);
410  covMatrix[0][0] = covss; // this is var(dy/dz)
411  covMatrix[1][1] = covii; // this is var(y)
412  covMatrix[1][0] = covsi; // this is cov(dy/dz,y)
413 }
Local3DVector LocalVector
Definition: LocalVector.h:12
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
static const double slope[3]
std::unique_ptr< DTLinearFit > theFitter
CLHEP::HepSymMatrix AlgebraicSymMatrix
Vector3DBase unit() const
Definition: Vector3DBase.h:54

◆ rejectBadHits()

void DTSegmentUpdator::rejectBadHits ( DTChamberRecSegment2D phiSeg) const
private

Definition at line 491 of file DTSegmentUpdator.cc.

References funct::abs(), gather_cfg::cout, debug, dumpMFGeometry_cfg::delta, TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, mps_fire::i, DTGeometry::idToDet(), DTGeometry::layer(), N, DTRecSegment2D::specificRecHits(), theGeom, DTRecSegment2D::update(), x, and y.

Referenced by update().

491  {
492  vector<float> x;
493  vector<float> y;
494 
495  if (debug)
496  cout << " Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
497 
498  vector<DTRecHit1D> hits = phiSeg->specificRecHits();
499  const size_t N = hits.size();
500  if (N < 3)
501  return;
502 
503  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
504  // I have to get the hits position (the hit is in the layer rf) in SL frame...
505  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
506  LocalPoint pos = (theGeom->idToDet(phiSeg->geographicalId()))->toLocal(glbPos);
507 
508  x.push_back(pos.z());
509  y.push_back(pos.x());
510  }
511 
512  if (debug) {
513  cout << " end of segment! " << endl;
514  cout << " size = Number of Hits: " << x.size() << " " << y.size() << endl;
515  }
516 
517  // Perform the 2 par fit:
518  float par[2] = {0., 0.}; // q , m
519 
520  //variables to perform the fit:
521  float Sx = 0.;
522  float Sy = 0.;
523  float Sx2 = 0.;
524  float Sy2 = 0.;
525  float Sxy = 0.;
526 
527  for (size_t i = 0; i < N; ++i) {
528  Sx += x.at(i);
529  Sy += y.at(i);
530  Sx2 += x.at(i) * x.at(i);
531  Sy2 += y.at(i) * y.at(i);
532  Sxy += x.at(i) * y.at(i);
533  }
534 
535  const float delta = N * Sx2 - Sx * Sx;
536  par[0] = (Sx2 * Sy - Sx * Sxy) / delta;
537  par[1] = (N * Sxy - Sx * Sy) / delta;
538 
539  if (debug)
540  cout << "fit 2 parameters done ----> par0: " << par[0] << " par1: " << par[1] << endl;
541 
542  // Calc residuals:
543  float residuals[N];
544  float mean_residual = 0.; //mean of the absolute values of residuals
545  for (size_t i = 0; i < N; ++i) {
546  residuals[i] = y.at(i) - par[1] * x.at(i) - par[0];
547  mean_residual += std::abs(residuals[i]);
548  if (debug) {
549  cout << " i: " << i << " y_i " << y.at(i) << " x_i " << x.at(i) << " res_i " << residuals[i];
550  if (i == N - 1)
551  cout << endl;
552  }
553  }
554 
555  if (debug)
556  cout << " Residuals computed! " << endl;
557 
558  mean_residual = mean_residual / (N - 2);
559  if (debug)
560  cout << " mean_residual: " << mean_residual << endl;
561 
562  int i = 0;
563 
564  // Perform bad hit rejecting -- update hits
565  vector<DTRecHit1D> updatedRecHits;
566  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
567  float normResidual = mean_residual > 0 ? std::abs(residuals[i]) / mean_residual : 0;
568  ++i;
569  if (normResidual < 1.5) {
570  DTRecHit1D newHit1D = (*hit);
571  updatedRecHits.push_back(newHit1D);
572  if (debug)
573  cout << " accepted " << i << "th hit"
574  << " Irej: " << normResidual << endl;
575  } else {
576  if (debug)
577  cout << " rejected " << i << "th hit"
578  << " Irej: " << normResidual << endl;
579  continue;
580  }
581  }
582 
583  phiSeg->update(updatedRecHits);
584 
585  //final check!
586  if (debug) {
587  vector<float> x_upd;
588  vector<float> y_upd;
589 
590  cout << " Check the update action: " << endl;
591 
592  vector<DTRecHit1D> hits_upd = phiSeg->specificRecHits();
593  for (vector<DTRecHit1D>::const_iterator hit = hits_upd.begin(); hit != hits_upd.end(); ++hit) {
594  // I have to get the hits position (the hit is in the layer rf) in SL frame...
595  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
596  LocalPoint pos = (theGeom->idToDet(phiSeg->geographicalId()))->toLocal(glbPos);
597 
598  x_upd.push_back(pos.z());
599  y_upd.push_back(pos.x());
600 
601  cout << " x_upd: " << pos.z() << " y_upd: " << pos.x() << endl;
602  }
603 
604  cout << " end of segment! " << endl;
605  cout << " size = Number of Hits: " << x_upd.size() << " " << y_upd.size() << endl;
606 
607  } // end debug
608 
609  return;
610 } //end DTSegmentUpdator::rejectBadHits
void update(std::vector< DTRecHit1D > &updatedRecHits)
edm::ESHandle< DTGeometry > theGeom
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define N
Definition: blowfish.cc:9
DetId geographicalId() const
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96

◆ setES()

void DTSegmentUpdator::setES ( const edm::EventSetup setup)

set the setup

Definition at line 69 of file DTSegmentUpdator.cc.

References singleTopDQM_cfi::setup, theAlgo, theGeom, and theGeomToken.

Referenced by DTRefitAndCombineReco4D::setES(), DTMeantimerPatternReco4D::setES(), DTCombinatorialPatternReco4D::setES(), DTCombinatorialPatternReco::setES(), DTCombinatorialExtendedPatternReco::setES(), and DTMeantimerPatternReco::setES().

69  {
70  theGeom = setup.getHandle(theGeomToken);
71  theAlgo->setES(setup);
72 }
edm::ESHandle< DTGeometry > theGeom
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theGeomToken

◆ update() [1/2]

void DTSegmentUpdator::update ( DTRecSegment4D seg,
const bool  calcT0,
bool  allow3par 
) const

recompute hits position and refit the segment4D

Definition at line 74 of file DTSegmentUpdator.cc.

References calculateT0corr(), gather_cfg::cout, debug, DeadROC_duringRun::dir, fit(), TrackingRecHit::geographicalId(), DTRecSegment4D::hasPhi(), DTRecSegment4D::hasZed(), DTGeometry::idToDet(), DTRecSegment4D::localDirection(), DTRecSegment4D::localPosition(), perform_delta_rejecting, DTRecSegment4D::phiSegment(), rejectBadHits(), theGeom, updateHits(), and DTRecSegment4D::zSegment().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), MatrixUtil.Steps::overwrite(), DTRefitAndCombineReco4D::reconstruct(), DTMeantimerPatternReco4D::reconstruct(), DTCombinatorialPatternReco4D::reconstruct(), DTCombinatorialPatternReco::reconstruct(), DTCombinatorialExtendedPatternReco::reconstruct(), and DTMeantimerPatternReco::reconstruct().

74  {
75  if (debug)
76  cout << "[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
77 
78  const bool hasPhi = seg->hasPhi();
79  const bool hasZed = seg->hasZed();
80 
81  //reject the bad hits (due to delta rays)
82  if (perform_delta_rejecting && hasPhi)
83  rejectBadHits(seg->phiSegment());
84 
85  int step = (hasPhi && hasZed) ? 3 : 2;
86  if (calcT0)
87  step = 4;
88 
89  if (debug)
90  cout << "Step of update is " << step << endl;
91 
92  GlobalPoint pos = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localPosition());
93  GlobalVector dir = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localDirection());
94 
95  if (calcT0)
96  calculateT0corr(seg);
97 
98  if (hasPhi)
99  updateHits(seg->phiSegment(), pos, dir, step);
100  if (hasZed)
101  updateHits(seg->zSegment(), pos, dir, step);
102 
103  fit(seg, allow3par);
104 }
bool hasPhi() const
Does it have the Phi projection?
LocalVector localDirection() const override
Local direction in Chamber frame.
LocalPoint localPosition() const override
Local position in Chamber frame.
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
edm::ESHandle< DTGeometry > theGeom
void calculateT0corr(DTRecSegment2D *seg) const
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
void rejectBadHits(DTChamberRecSegment2D *) const
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
DetId geographicalId() const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
step
Definition: StallMonitor.cc:98
bool hasZed() const
Does it have the Z projection?

◆ update() [2/2]

void DTSegmentUpdator::update ( DTRecSegment2D seg,
bool  allow3par 
) const

recompute hits position and refit the segment2D

Definition at line 106 of file DTSegmentUpdator.cc.

References gather_cfg::cout, debug, DeadROC_duringRun::dir, fit(), TrackingRecHit::geographicalId(), DTGeometry::idToDet(), DTRecSegment2D::localDirection(), DTRecSegment2D::localPosition(), theGeom, and updateHits().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

106  {
107  if (debug)
108  cout << "[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
109  GlobalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localPosition());
110  GlobalVector dir = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localDirection());
111 
112  updateHits(seg, pos, dir);
113  fit(seg, allow3par, false);
114 }
LocalPoint localPosition() const override
local position in SL frame
LocalVector localDirection() const override
the local direction in SL frame
edm::ESHandle< DTGeometry > theGeom
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
DetId geographicalId() const
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const

◆ updateHits()

void DTSegmentUpdator::updateHits ( DTRecSegment2D seg,
GlobalPoint gpos,
GlobalVector gdir,
const int  step = 2 
) const
private

Definition at line 417 of file DTSegmentUpdator.cc.

References angle(), funct::cos(), HLT_2022v15_cff::distance, relativeConstraints::error, Exception, DTRecSegment2D::ist0Valid(), DTGeometry::layer(), phase1PixelTopology::layer, DTEnums::Left, convertSQLiteXML::ok, point, DTRecSegment2D::specificRecHits(), DTRecSegment2D::t0(), T0_hit_resolution, theAlgo, theGeom, PV3DBase< T, PVType, FrameType >::theta(), DTRecSegment2D::update(), DTRecSegment2D::vDrift(), vdrift_4parfit, PV3DBase< T, PVType, FrameType >::x(), hit::x, and PV3DBase< T, PVType, FrameType >::z().

Referenced by update().

417  {
418  // it is not necessary to have DTRecHit1D* to modify the obj in the container
419  // but I have to be carefully, since I cannot make a copy before the iteration!
420 
421  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
422  vector<DTRecHit1D> updatedRecHits;
423 
424  for (vector<DTRecHit1D>::iterator hit = toBeUpdatedRecHits.begin(); hit != toBeUpdatedRecHits.end(); ++hit) {
425  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
426 
427  LocalPoint segPos = layer->toLocal(gpos);
428  LocalVector segDir = layer->toLocal(gdir);
429 
430  // define impact angle needed by the step 2
431  const float angle = atan(segDir.x() / -segDir.z());
432 
433  // define the local position (extr.) of the segment. Needed by the third step
434  LocalPoint segPosAtLayer = segPos + segDir * (-segPos.z()) / cos(segDir.theta());
435 
436  DTRecHit1D newHit1D = (*hit);
437  bool ok = true;
438 
439  if (step == 2) {
440  ok = theAlgo->compute(layer, *hit, angle, newHit1D);
441 
442  } else if (step == 3) {
443  LocalPoint hitPos(hit->localPosition().x(), +segPosAtLayer.y(), 0.);
444  GlobalPoint glbpos = theGeom->layer(hit->wireId().layerId())->toGlobal(hitPos);
445  newHit1D.setPosition(hitPos);
446  ok = theAlgo->compute(layer, *hit, angle, glbpos, newHit1D);
447 
448  } else if (step == 4) {
449  //const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
450  double vminf = 0.;
451  if (vdrift_4parfit)
452  vminf = seg->vDrift(); // use vdrift recorded in the segment only if vdrift_4parfit=True
453 
454  double cminf = 0.;
455  if (seg->ist0Valid())
456  cminf = -seg->t0() * 0.00543;
457 
458  //cout << "In updateHits: t0 = " << seg->t0() << endl;
459  //cout << "In updateHits: vminf = " << vminf << endl;
460  //cout << "In updateHits: cminf = " << cminf << endl;
461 
462  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
463  const float distance = fabs(hit->localPosition().x() - xwire);
464  const int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
465  const double dy_corr = (vminf * ilc * distance - cminf * ilc);
466 
467  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
468 
469  //double final_hit_resol = T0_hit_resolution;
470  //if(newHit1D.wireId().layerId().superlayerId().superLayer() != 2) final_hit_resol = final_hit_resol * 0.8;
471  //LocalError error(final_hit_resol * final_hit_resol,0.,0.);
473  newHit1D.setPositionAndError(point, error);
474 
475  //FIXME: check that the hit is still inside the cell
476  ok = true;
477 
478  } else
479  throw cms::Exception("DTSegmentUpdator") << " updateHits called with wrong step " << endl;
480 
481  if (ok)
482  updatedRecHits.push_back(newHit1D);
483  else {
484  LogError("DTSegmentUpdator") << "DTSegmentUpdator::updateHits failed update" << endl;
485  throw cms::Exception("DTSegmentUpdator") << "updateHits failed update" << endl;
486  }
487  }
488  seg->update(updatedRecHits);
489 }
bool ist0Valid() const
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
T z() const
Definition: PV3DBase.h:61
double vDrift() const
Log< level::Error, false > LogError
void update(std::vector< DTRecHit1D > &updatedRecHits)
edm::ESHandle< DTGeometry > theGeom
constexpr std::array< uint8_t, layerIndexSize > layer
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
T x() const
Definition: PV3DBase.h:59
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
step
Definition: StallMonitor.cc:98
*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
Definition: invegas.h:5
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96

Member Data Documentation

◆ debug

bool DTSegmentUpdator::debug
private

◆ intime_cut

double DTSegmentUpdator::intime_cut
private

Definition at line 110 of file DTSegmentUpdator.h.

Referenced by fit().

◆ perform_delta_rejecting

bool DTSegmentUpdator::perform_delta_rejecting
private

Definition at line 113 of file DTSegmentUpdator.h.

Referenced by update().

◆ T0_hit_resolution

double DTSegmentUpdator::T0_hit_resolution
private

Definition at line 112 of file DTSegmentUpdator.h.

Referenced by updateHits().

◆ theAlgo

std::unique_ptr<DTRecHitBaseAlgo> DTSegmentUpdator::theAlgo
private

Definition at line 86 of file DTSegmentUpdator.h.

Referenced by setES(), and updateHits().

◆ theFitter

std::unique_ptr<DTLinearFit> DTSegmentUpdator::theFitter
private

Definition at line 85 of file DTSegmentUpdator.h.

Referenced by calculateT0corr(), and fit().

◆ theGeom

edm::ESHandle<DTGeometry> DTSegmentUpdator::theGeom
private

Definition at line 87 of file DTSegmentUpdator.h.

Referenced by calculateT0corr(), fit(), rejectBadHits(), setES(), update(), and updateHits().

◆ theGeomToken

const edm::ESGetToken<DTGeometry, MuonGeometryRecord> DTSegmentUpdator::theGeomToken
private

Definition at line 88 of file DTSegmentUpdator.h.

Referenced by setES().

◆ vdrift_4parfit

bool DTSegmentUpdator::vdrift_4parfit
private

Definition at line 111 of file DTSegmentUpdator.h.

Referenced by calculateT0corr(), and updateHits().