CMS 3D CMS Logo

DTSegmentUpdator.cc
Go to the documentation of this file.
1 
10 /* This Class Header */
12 
13 /* Collaborating Class Header */
14 
15 //mene
17 
24 
28 
32 
37 
38 /* C++ Headers */
39 #include <string>
40 
41 using namespace std;
42 using namespace edm;
43 
44 /* ====================================================================== */
45 
48  : theFitter{std::make_unique<DTLinearFit>()},
49  theAlgo{DTRecHitAlgoFactory::get()->create(
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 }
63 
66 
67 /* Operations */
68 
70  theGeom = setup.getHandle(theGeomToken);
71  theAlgo->setES(setup);
72 }
73 
74 void DTSegmentUpdator::update(DTRecSegment4D* seg, const bool calcT0, bool allow3par) const {
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 }
105 
106 void DTSegmentUpdator::update(DTRecSegment2D* seg, bool allow3par) const {
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 }
115 
116 void DTSegmentUpdator::fit(DTRecSegment4D* seg, bool allow3par) const {
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 }
216 
217 bool DTSegmentUpdator::fit(DTSegmentCand* seg, bool allow3par, const bool fitdebug) const {
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 }
283 
284 void DTSegmentUpdator::fit(DTRecSegment2D* seg, bool allow3par, bool block3par) const {
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 }
354 
355 void DTSegmentUpdator::fit(const vector<float>& x,
356  const vector<float>& y,
357  const vector<int>& lfit,
358  const vector<double>& dist,
359  const vector<float>& sigy,
360  LocalPoint& pos,
361  LocalVector& dir,
362  float& cminf,
363  float& vminf,
364  AlgebraicSymMatrix& covMatrix,
365  double& chi2,
366  const bool allow3par,
367  const bool block3par) const {
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 }
414 
415 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
416 // of the 2D-segment itself or the glb position and direction of the 4D segment
417 void DTSegmentUpdator::updateHits(DTRecSegment2D* seg, GlobalPoint& gpos, GlobalVector& gdir, const int step) const {
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 }
490 
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
611 
613  if (seg->hasPhi())
614  calculateT0corr(seg->phiSegment());
615  if (seg->hasZed())
616  calculateT0corr(seg->zSegment());
617 }
618 
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 }
static GlobalError transform(const LocalError &le, const Surface &surf)
void setChi2(const double &chi2)
bool ist0Valid() const
Local3DVector LocalVector
Definition: LocalVector.h:12
DTSegmentUpdator(const edm::ParameterSet &config, edm::ConsumesCollector)
Constructor.
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.
static const double slope[3]
LocalVector localDirection() const override
Local direction in Chamber frame.
double vDrift() const
~DTSegmentUpdator()
Destructor.
virtual void setChi2(double &chi2)
set chi2
Definition: config.py:1
void setCovMatrix(const AlgebraicSymMatrix &cov)
void setCovMatrixForZed(const LocalPoint &posZInCh)
Log< level::Error, false > LogError
void update(std::vector< DTRecHit1D > &updatedRecHits)
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
constexpr std::array< uint8_t, layerIndexSize > layer
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
void calculateT0corr(DTRecSegment2D *seg) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
DTChamberId chamberId() const
Return the corresponding ChamberId.
void setES(const edm::EventSetup &setup)
set the setup
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
T sqrt(T t)
Definition: SSEVec.h:19
void rejectBadHits(DTChamberRecSegment2D *) const
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::unique_ptr< DTLinearFit > theFitter
Abs< T >::type abs(const T &t)
Definition: Abs.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.
virtual const AssPointCont & hits() const
the used hits
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
virtual void sett0(double &t0)
set t0
#define debug
Definition: HDRShower.cc:19
#define N
Definition: blowfish.cc:9
DetId geographicalId() const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
double b
Definition: hdecay.h:118
void setT0(const double &t0)
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
HLT enums.
double a
Definition: hdecay.h:119
virtual void setDirection(LocalVector &dir)
set direction
Definition: DTSegmentCand.h:93
void setPosition(const LocalPoint &pos)
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theGeomToken
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setDirection(const LocalVector &dir)
float x
void setPosition(LocalPoint pos)
Set position.
void setVdrift(const double &vdrift)
step
Definition: StallMonitor.cc:98
Vector3DBase unit() const
Definition: Vector3DBase.h:54
virtual void setPosition(LocalPoint &pos)
set position
Definition: DTSegmentCand.h:90
#define get
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
float xx() const
Definition: LocalError.h:22
*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