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)},
51  theGeomToken(cc.esConsumes()),
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 }
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
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 615 of file DTSegmentUpdator.cc.

References a, b, gather_cfg::cout, debug, HLT_2024v10_cff::distance, TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, DTGeometry::idToDet(), nano_mu_digi_cff::layer, DTGeometry::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().

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

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

608  {
609  if (seg->hasPhi())
610  calculateT0corr(seg->phiSegment());
611  if (seg->hasZed())
612  calculateT0corr(seg->zSegment());
613 }
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 nano_mu_local_reco_cff::chi2, gather_cfg::cout, debug, DeadROC_duringRun::dir, HLT_2024v10_cff::distance, DTSegmentCand::hits(), 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 
231  x.reserve(8);
232  y.reserve(8);
233  sigy.reserve(8);
234  lfit.reserve(8);
235  dist.reserve(8);
236 
237  for (DTSegmentCand::AssPointCont::const_iterator iter = seg->hits().begin(); iter != seg->hits().end(); ++iter) {
238  LocalPoint pos = (*iter).first->localPosition((*iter).second);
239  float xwire =
240  (((*iter).first)->localPosition(DTEnums::Left).x() + ((*iter).first)->localPosition(DTEnums::Right).x()) / 2.;
241  float distance = pos.x() - xwire;
242 
243  if ((*iter).second == DTEnums::Left)
244  lfit.push_back(1);
245  else
246  lfit.push_back(-1);
247 
248  dist.push_back(distance);
249  sigy.push_back(sqrt((*iter).first->localPositionError().xx()));
250  x.push_back(pos.z());
251  y.push_back(pos.x());
252  }
253 
254  LocalPoint pos;
256  AlgebraicSymMatrix covMat(2);
257  float cminf = 0.;
258  float vminf = 0.;
259  double chi2 = 0.;
260  double t0_corr = 0.;
261 
262  fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par);
263  if (cminf != 0)
264  t0_corr = -cminf / 0.00543; // convert drift distance to time
265 
266  if (debug && fitdebug)
267  cout << " DTcand chi2: " << chi2 << "/" << x.size() << " t0: " << t0_corr << endl;
268 
269  seg->setPosition(pos);
270  seg->setDirection(dir);
271  seg->sett0(t0_corr);
272  seg->setCovMatrix(covMat);
273  seg->setChi2(chi2);
274 
275  // cout << "pos " << pos << endl;
276  // cout << "dir " << dir << endl;
277  // cout << "Mat " << covMat << endl;
278 
279  return true;
280 }
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 282 of file DTSegmentUpdator.cc.

References nano_mu_local_reco_cff::chi2, gather_cfg::cout, debug, DeadROC_duringRun::dir, HLT_2024v10_cff::distance, fit(), TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, DTGeometry::idToDet(), nano_mu_digi_cff::layer, DTGeometry::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().

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

References nano_mu_local_reco_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().

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

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

References angle(), funct::cos(), HLT_2024v10_cff::distance, relativeConstraints::error, Exception, DTRecSegment2D::ist0Valid(), nano_mu_digi_cff::layer, DTGeometry::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().

415  {
416  // it is not necessary to have DTRecHit1D* to modify the obj in the container
417  // but I have to be carefully, since I cannot make a copy before the iteration!
418 
419  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
420  vector<DTRecHit1D> updatedRecHits;
421 
422  for (vector<DTRecHit1D>::iterator hit = toBeUpdatedRecHits.begin(); hit != toBeUpdatedRecHits.end(); ++hit) {
423  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
424 
425  LocalPoint segPos = layer->toLocal(gpos);
426  LocalVector segDir = layer->toLocal(gdir);
427 
428  // define impact angle needed by the step 2
429  const float angle = atan(segDir.x() / -segDir.z());
430 
431  // define the local position (extr.) of the segment. Needed by the third step
432  LocalPoint segPosAtLayer = segPos + segDir * (-segPos.z()) / cos(segDir.theta());
433 
434  DTRecHit1D newHit1D = (*hit);
435  bool ok = true;
436 
437  if (step == 2) {
438  ok = theAlgo->compute(layer, *hit, angle, newHit1D);
439 
440  } else if (step == 3) {
441  LocalPoint hitPos(hit->localPosition().x(), +segPosAtLayer.y(), 0.);
442  GlobalPoint glbpos = theGeom->layer(hit->wireId().layerId())->toGlobal(hitPos);
443  newHit1D.setPosition(hitPos);
444  ok = theAlgo->compute(layer, *hit, angle, glbpos, newHit1D);
445 
446  } else if (step == 4) {
447  //const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
448  double vminf = 0.;
449  if (vdrift_4parfit)
450  vminf = seg->vDrift(); // use vdrift recorded in the segment only if vdrift_4parfit=True
451 
452  double cminf = 0.;
453  if (seg->ist0Valid())
454  cminf = -seg->t0() * 0.00543;
455 
456  //cout << "In updateHits: t0 = " << seg->t0() << endl;
457  //cout << "In updateHits: vminf = " << vminf << endl;
458  //cout << "In updateHits: cminf = " << cminf << endl;
459 
460  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
461  const float distance = fabs(hit->localPosition().x() - xwire);
462  const int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
463  const double dy_corr = (vminf * ilc * distance - cminf * ilc);
464 
465  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
466 
467  //double final_hit_resol = T0_hit_resolution;
468  //if(newHit1D.wireId().layerId().superlayerId().superLayer() != 2) final_hit_resol = final_hit_resol * 0.8;
469  //LocalError error(final_hit_resol * final_hit_resol,0.,0.);
471  newHit1D.setPositionAndError(point, error);
472 
473  //FIXME: check that the hit is still inside the cell
474  ok = true;
475 
476  } else
477  throw cms::Exception("DTSegmentUpdator") << " updateHits called with wrong step " << endl;
478 
479  if (ok)
480  updatedRecHits.push_back(newHit1D);
481  else {
482  LogError("DTSegmentUpdator") << "DTSegmentUpdator::updateHits failed update" << endl;
483  throw cms::Exception("DTSegmentUpdator") << "updateHits failed update" << endl;
484  }
485  }
486  seg->update(updatedRecHits);
487 }
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
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:83
*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().