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 
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 }
281 
282 void DTSegmentUpdator::fit(DTRecSegment2D* seg, bool allow3par, bool block3par) const {
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 }
352 
353 void DTSegmentUpdator::fit(const vector<float>& x,
354  const vector<float>& y,
355  const vector<int>& lfit,
356  const vector<double>& dist,
357  const vector<float>& sigy,
358  LocalPoint& pos,
359  LocalVector& dir,
360  float& cminf,
361  float& vminf,
362  AlgebraicSymMatrix& covMatrix,
363  double& chi2,
364  const bool allow3par,
365  const bool block3par) const {
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 }
412 
413 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
414 // of the 2D-segment itself or the glb position and direction of the 4D segment
415 void DTSegmentUpdator::updateHits(DTRecSegment2D* seg, GlobalPoint& gpos, GlobalVector& gdir, const int step) const {
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 }
488 
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
607 
609  if (seg->hasPhi())
610  calculateT0corr(seg->phiSegment());
611  if (seg->hasZed())
612  calculateT0corr(seg->zSegment());
613 }
614 
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 }
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.
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
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
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:120
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:121
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:83
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