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(config.getParameter<string>("recAlgo"),
50  config.getParameter<ParameterSet>("recAlgoConfig"))},
51  vdrift_4parfit(config.getParameter<bool>("performT0_vdriftSegCorrection")),
52  T0_hit_resolution(config.getParameter<double>("hit_afterT0_resolution")),
53  perform_delta_rejecting(config.getParameter<bool>("perform_delta_rejecting")),
54  debug(config.getUntrackedParameter<bool>("debug", false)) {
55  intime_cut = 20.;
56  if (config.exists("intime_cut"))
57  intime_cut = config.getParameter<double>("intime_cut");
58 
59  if (debug)
60  cout << "[DTSegmentUpdator] Constructor called" << endl;
61 }
62 
65 
66 /* Operations */
67 
70  theAlgo->setES(setup);
71 }
72 
73 void DTSegmentUpdator::update(DTRecSegment4D* seg, const bool calcT0, bool allow3par) const {
74  if (debug)
75  cout << "[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
76 
77  const bool hasPhi = seg->hasPhi();
78  const bool hasZed = seg->hasZed();
79 
80  //reject the bad hits (due to delta rays)
81  if (perform_delta_rejecting && hasPhi)
82  rejectBadHits(seg->phiSegment());
83 
84  int step = (hasPhi && hasZed) ? 3 : 2;
85  if (calcT0)
86  step = 4;
87 
88  if (debug)
89  cout << "Step of update is " << step << endl;
90 
91  GlobalPoint pos = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localPosition());
92  GlobalVector dir = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localDirection());
93 
94  if (calcT0)
95  calculateT0corr(seg);
96 
97  if (hasPhi)
98  updateHits(seg->phiSegment(), pos, dir, step);
99  if (hasZed)
100  updateHits(seg->zSegment(), pos, dir, step);
101 
102  fit(seg, allow3par);
103 }
104 
105 void DTSegmentUpdator::update(DTRecSegment2D* seg, bool allow3par) const {
106  if (debug)
107  cout << "[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
108  GlobalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localPosition());
109  GlobalVector dir = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localDirection());
110 
111  updateHits(seg, pos, dir);
112  fit(seg, allow3par, false);
113 }
114 
115 void DTSegmentUpdator::fit(DTRecSegment4D* seg, bool allow3par) const {
116  if (debug)
117  cout << "[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
118  // after the update must refit the segments
119 
120  if (debug) {
121  if (seg->hasPhi())
122  cout << " 4D Segment contains a Phi segment. t0= " << seg->phiSegment()->t0()
123  << " chi2= " << seg->phiSegment()->chi2() << endl;
124  if (seg->hasZed())
125  cout << " 4D Segment contains a Zed segment. t0= " << seg->zSegment()->t0()
126  << " chi2= " << seg->zSegment()->chi2() << endl;
127  }
128 
129  // 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
130  // segments are fit with the 2-par fit. Setting intime_cut to -1 results in the 3-par fit being used always.
131  if (seg->hasPhi()) {
132  if (seg->hasZed()) {
133  if (fabs(seg->phiSegment()->t0()) < intime_cut) {
134  fit(seg->phiSegment(), allow3par, true);
135  fit(seg->zSegment(), allow3par, true);
136  } else {
137  fit(seg->phiSegment(), allow3par, false);
138  fit(seg->zSegment(), allow3par, false);
139  }
140  } else
141  fit(seg->phiSegment(), allow3par, false);
142  } else
143  fit(seg->zSegment(), allow3par, false);
144 
145  const DTChamber* theChamber = theGeom->chamber(seg->chamberId());
146 
147  if (seg->hasPhi() && seg->hasZed()) {
148  DTChamberRecSegment2D* segPhi = seg->phiSegment();
149  DTSLRecSegment2D* segZed = seg->zSegment();
150 
151  // NB Phi seg is already in chamber ref
152  LocalPoint posPhiInCh = segPhi->localPosition();
153  LocalVector dirPhiInCh = segPhi->localDirection();
154 
155  // Zed seg is in SL one
156  const DTSuperLayer* zSL = theChamber->superLayer(segZed->superLayerId());
157  LocalPoint zPos(segZed->localPosition().x(), (zSL->toLocal(theChamber->toGlobal(segPhi->localPosition()))).y(), 0.);
158 
159  LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
160 
161  LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(segZed->localDirection()));
162 
163  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z()) / cos(dirZInCh.theta());
164 
165  // given the actual definition of chamber refFrame, (with z poiniting to IP),
166  // the zed component of direction is negative.
167  LocalVector dir = LocalVector(dirPhiInCh.x() / fabs(dirPhiInCh.z()), dirZInCh.y() / fabs(dirZInCh.z()), -1.);
168 
169  seg->setPosition(LocalPoint(posPhiInCh.x(), posZAt0.y(), 0.));
170  seg->setDirection(dir.unit());
171 
172  AlgebraicSymMatrix mat(4);
173 
174  // set cov matrix
175  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
176  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
177  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
178 
179  seg->setCovMatrix(mat);
180  seg->setCovMatrixForZed(posZInCh);
181  } else if (seg->hasPhi()) {
182  DTChamberRecSegment2D* segPhi = seg->phiSegment();
183 
184  seg->setPosition(segPhi->localPosition());
185  seg->setDirection(segPhi->localDirection());
186 
187  AlgebraicSymMatrix mat(4);
188  // set cov matrix
189  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
190  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
191  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
192 
193  seg->setCovMatrix(mat);
194  } else if (seg->hasZed()) {
195  DTSLRecSegment2D* segZed = seg->zSegment();
196 
197  // Zed seg is in SL one
198  GlobalPoint glbPosZ = (theGeom->superLayer(segZed->superLayerId()))->toGlobal(segZed->localPosition());
199  LocalPoint posZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()))->toLocal(glbPosZ);
200 
201  GlobalVector glbDirZ = (theGeom->superLayer(segZed->superLayerId()))->toGlobal(segZed->localDirection());
202  LocalVector dirZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()))->toLocal(glbDirZ);
203 
204  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z()) / cos(dirZInCh.theta());
205 
206  seg->setPosition(posZAt0);
207  seg->setDirection(dirZInCh);
208 
209  AlgebraicSymMatrix mat(4);
210  // set cov matrix
211  seg->setCovMatrix(mat);
212  seg->setCovMatrixForZed(posZInCh);
213  }
214 }
215 
216 bool DTSegmentUpdator::fit(DTSegmentCand* seg, bool allow3par, const bool fitdebug) const {
217  // if (debug && fitdebug) cout << "[DTSegmentUpdator] Fit DTRecSegment2D" << endl;
218  // if (!seg->good()) return false;
219 
220  // DTSuperLayerId DTid = (DTSuperLayerId)seg->superLayer()->id();
221  // if (DTid.superlayer()==2)
222  // allow3par = 0;
223 
224  vector<float> x;
225  vector<float> y;
226  vector<float> sigy;
227  vector<int> lfit;
228  vector<double> dist;
229  int i = 0;
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  i++;
253  }
254 
255  LocalPoint pos;
257  AlgebraicSymMatrix covMat(2);
258  float cminf = 0.;
259  float vminf = 0.;
260  double chi2 = 0.;
261  double t0_corr = 0.;
262 
263  fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par);
264  if (cminf != 0)
265  t0_corr = -cminf / 0.00543; // convert drift distance to time
266 
267  if (debug && fitdebug)
268  cout << " DTcand chi2: " << chi2 << "/" << x.size() << " t0: " << t0_corr << endl;
269 
270  seg->setPosition(pos);
271  seg->setDirection(dir);
272  seg->sett0(t0_corr);
273  seg->setCovMatrix(covMat);
274  seg->setChi2(chi2);
275 
276  // cout << "pos " << pos << endl;
277  // cout << "dir " << dir << endl;
278  // cout << "Mat " << covMat << endl;
279 
280  return true;
281 }
282 
283 void DTSegmentUpdator::fit(DTRecSegment2D* seg, bool allow3par, bool block3par) const {
284  if (debug)
285  cout << "[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
286 
287  vector<float> x;
288  vector<float> y;
289  vector<float> sigy;
290  vector<int> lfit;
291  vector<double> dist;
292  x.reserve(8);
293  y.reserve(8);
294  sigy.reserve(8);
295  lfit.reserve(8);
296  dist.reserve(8);
297 
298  // DTSuperLayerId DTid = (DTSuperLayerId)seg->geographicalId();
299  // if (DTid.superlayer()==2)
300  // allow3par = 0;
301 
302  vector<DTRecHit1D> hits = seg->specificRecHits();
303  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
304  // I have to get the hits position (the hit is in the layer rf) in SL frame...
305  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
306  LocalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toLocal(glbPos);
307  x.push_back(pos.z());
308  y.push_back(pos.x());
309 
310  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
311  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
312  float distance = fabs(hit->localPosition().x() - xwire);
313  dist.push_back(distance);
314 
315  int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
316  lfit.push_back(ilc);
317 
318  // Get local error in SL frame
319  //RB: is it right in this way?
321  GlobalError glbErr =
322  tran.transform(hit->localPositionError(), (theGeom->layer(hit->wireId().layerId()))->surface());
323  LocalError slErr = tran.transform(glbErr, (theGeom->idToDet(seg->geographicalId()))->surface());
324  sigy.push_back(sqrt(slErr.xx()));
325  }
326 
327  LocalPoint pos;
329  AlgebraicSymMatrix covMat(2);
330  double chi2 = 0.;
331  float cminf = 0.;
332  float vminf = 0.;
333  double t0_corr = 0.;
334 
335  fit(x, y, lfit, dist, sigy, pos, dir, cminf, vminf, covMat, chi2, allow3par, block3par);
336  if (cminf != 0)
337  t0_corr = -cminf / 0.00543; // convert drift distance to time
338 
339  if (debug)
340  cout << " DTSeg2d chi2: " << chi2 << endl;
341  if (debug)
342  cout << " DTSeg2d Fit t0: " << t0_corr << endl;
343  // cout << "pos " << segPosition << endl;
344  // cout << "dir " << segDirection << endl;
345  // cout << "Mat " << mat << endl;
346 
347  seg->setPosition(pos);
348  seg->setDirection(dir);
349  seg->setCovMatrix(covMat);
350  seg->setChi2(chi2);
351  seg->setT0(t0_corr);
352 }
353 
354 void DTSegmentUpdator::fit(const vector<float>& x,
355  const vector<float>& y,
356  const vector<int>& lfit,
357  const vector<double>& dist,
358  const vector<float>& sigy,
359  LocalPoint& pos,
360  LocalVector& dir,
361  float& cminf,
362  float& vminf,
363  AlgebraicSymMatrix& covMatrix,
364  double& chi2,
365  const bool allow3par,
366  const bool block3par) const {
367  float slope = 0.;
368  float intercept = 0.;
369  float covss = 0.;
370  float covii = 0.;
371  float covsi = 0.;
372 
373  cminf = 0;
374  vminf = 0;
375 
376  int leftHits = 0, rightHits = 0;
377  for (unsigned int i = 0; i < lfit.size(); i++)
378  if (lfit[i] == 1)
379  leftHits++;
380  else
381  rightHits++;
382 
383  theFitter->fit(x, y, x.size(), sigy, slope, intercept, chi2, covss, covii, covsi);
384 
385  // If we have at least one left and one right hit we can try the 3 parameter fit (if it is switched on)
386  // FIXME: currently the covariance matrix from the 2-par fit is kept
387  if (leftHits && rightHits && (leftHits + rightHits > 3) && allow3par) {
388  theFitter->fitNpar(3, x, y, lfit, dist, sigy, slope, intercept, cminf, vminf, chi2, debug);
389  double t0_corr = -cminf / 0.00543;
390  if (fabs(t0_corr) < intime_cut && block3par) {
391  theFitter->fit(x, y, x.size(), sigy, slope, intercept, chi2, covss, covii, covsi);
392  cminf = 0;
393  }
394  }
395 
396  // cout << "slope " << slope << endl;
397  // cout << "intercept " << intercept << endl;
398 
399  // intercept is the x() in chamber frame when the segment cross the chamber
400  // plane (at z()=0), the y() is not measured, so let's put the center of the
401  // chamber.
402  pos = LocalPoint(intercept, 0., 0.);
403 
404  // slope is dx()/dz(), while dy()/dz() is by definition 0, finally I want the
405  // segment to point outward, so opposite to local z
406  dir = LocalVector(-slope, 0., -1.).unit();
407 
408  covMatrix = AlgebraicSymMatrix(2);
409  covMatrix[0][0] = covss; // this is var(dy/dz)
410  covMatrix[1][1] = covii; // this is var(y)
411  covMatrix[1][0] = covsi; // this is cov(dy/dz,y)
412 }
413 
414 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
415 // of the 2D-segment itself or the glb position and direction of the 4D segment
416 void DTSegmentUpdator::updateHits(DTRecSegment2D* seg, GlobalPoint& gpos, GlobalVector& gdir, const int step) const {
417  // it is not necessary to have DTRecHit1D* to modify the obj in the container
418  // but I have to be carefully, since I cannot make a copy before the iteration!
419 
420  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
421  vector<DTRecHit1D> updatedRecHits;
422 
423  for (vector<DTRecHit1D>::iterator hit = toBeUpdatedRecHits.begin(); hit != toBeUpdatedRecHits.end(); ++hit) {
424  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
425 
426  LocalPoint segPos = layer->toLocal(gpos);
427  LocalVector segDir = layer->toLocal(gdir);
428 
429  // define impact angle needed by the step 2
430  const float angle = atan(segDir.x() / -segDir.z());
431 
432  // define the local position (extr.) of the segment. Needed by the third step
433  LocalPoint segPosAtLayer = segPos + segDir * (-segPos.z()) / cos(segDir.theta());
434 
435  DTRecHit1D newHit1D = (*hit);
436  bool ok = true;
437 
438  if (step == 2) {
439  ok = theAlgo->compute(layer, *hit, angle, newHit1D);
440 
441  } else if (step == 3) {
442  LocalPoint hitPos(hit->localPosition().x(), +segPosAtLayer.y(), 0.);
443  GlobalPoint glbpos = theGeom->layer(hit->wireId().layerId())->toGlobal(hitPos);
444  newHit1D.setPosition(hitPos);
445  ok = theAlgo->compute(layer, *hit, angle, glbpos, newHit1D);
446 
447  } else if (step == 4) {
448  //const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
449  double vminf = 0.;
450  if (vdrift_4parfit)
451  vminf = seg->vDrift(); // use vdrift recorded in the segment only if vdrift_4parfit=True
452 
453  double cminf = 0.;
454  if (seg->ist0Valid())
455  cminf = -seg->t0() * 0.00543;
456 
457  //cout << "In updateHits: t0 = " << seg->t0() << endl;
458  //cout << "In updateHits: vminf = " << vminf << endl;
459  //cout << "In updateHits: cminf = " << cminf << endl;
460 
461  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
462  const float distance = fabs(hit->localPosition().x() - xwire);
463  const int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
464  const double dy_corr = (vminf * ilc * distance - cminf * ilc);
465 
466  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
467 
468  //double final_hit_resol = T0_hit_resolution;
469  //if(newHit1D.wireId().layerId().superlayerId().superLayer() != 2) final_hit_resol = final_hit_resol * 0.8;
470  //LocalError error(final_hit_resol * final_hit_resol,0.,0.);
472  newHit1D.setPositionAndError(point, error);
473 
474  //FIXME: check that the hit is still inside the cell
475  ok = true;
476 
477  } else
478  throw cms::Exception("DTSegmentUpdator") << " updateHits called with wrong step " << endl;
479 
480  if (ok)
481  updatedRecHits.push_back(newHit1D);
482  else {
483  LogError("DTSegmentUpdator") << "DTSegmentUpdator::updateHits failed update" << endl;
484  throw cms::Exception("DTSegmentUpdator") << "updateHits failed update" << endl;
485  }
486  }
487  seg->update(updatedRecHits);
488 }
489 
491  vector<float> x;
492  vector<float> y;
493 
494  if (debug)
495  cout << " Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
496 
497  vector<DTRecHit1D> hits = phiSeg->specificRecHits();
498  const size_t N = hits.size();
499  if (N < 3)
500  return;
501 
502  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
503  // I have to get the hits position (the hit is in the layer rf) in SL frame...
504  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
505  LocalPoint pos = (theGeom->idToDet(phiSeg->geographicalId()))->toLocal(glbPos);
506 
507  x.push_back(pos.z());
508  y.push_back(pos.x());
509  }
510 
511  if (debug) {
512  cout << " end of segment! " << endl;
513  cout << " size = Number of Hits: " << x.size() << " " << y.size() << endl;
514  }
515 
516  // Perform the 2 par fit:
517  float par[2] = {0., 0.}; // q , m
518 
519  //variables to perform the fit:
520  float Sx = 0.;
521  float Sy = 0.;
522  float Sx2 = 0.;
523  float Sy2 = 0.;
524  float Sxy = 0.;
525 
526  for (size_t i = 0; i < N; ++i) {
527  Sx += x.at(i);
528  Sy += y.at(i);
529  Sx2 += x.at(i) * x.at(i);
530  Sy2 += y.at(i) * y.at(i);
531  Sxy += x.at(i) * y.at(i);
532  }
533 
534  const float delta = N * Sx2 - Sx * Sx;
535  par[0] = (Sx2 * Sy - Sx * Sxy) / delta;
536  par[1] = (N * Sxy - Sx * Sy) / delta;
537 
538  if (debug)
539  cout << "fit 2 parameters done ----> par0: " << par[0] << " par1: " << par[1] << endl;
540 
541  // Calc residuals:
542  float residuals[N];
543  float mean_residual = 0.; //mean of the absolute values of residuals
544  for (size_t i = 0; i < N; ++i) {
545  residuals[i] = y.at(i) - par[1] * x.at(i) - par[0];
546  mean_residual += std::abs(residuals[i]);
547  if (debug) {
548  cout << " i: " << i << " y_i " << y.at(i) << " x_i " << x.at(i) << " res_i " << residuals[i];
549  if (i == N - 1)
550  cout << endl;
551  }
552  }
553 
554  if (debug)
555  cout << " Residuals computed! " << endl;
556 
557  mean_residual = mean_residual / (N - 2);
558  if (debug)
559  cout << " mean_residual: " << mean_residual << endl;
560 
561  int i = 0;
562 
563  // Perform bad hit rejecting -- update hits
564  vector<DTRecHit1D> updatedRecHits;
565  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
566  float normResidual = mean_residual > 0 ? std::abs(residuals[i]) / mean_residual : 0;
567  ++i;
568  if (normResidual < 1.5) {
569  DTRecHit1D newHit1D = (*hit);
570  updatedRecHits.push_back(newHit1D);
571  if (debug)
572  cout << " accepted " << i << "th hit"
573  << " Irej: " << normResidual << endl;
574  } else {
575  if (debug)
576  cout << " rejected " << i << "th hit"
577  << " Irej: " << normResidual << endl;
578  continue;
579  }
580  }
581 
582  phiSeg->update(updatedRecHits);
583 
584  //final check!
585  if (debug) {
586  vector<float> x_upd;
587  vector<float> y_upd;
588 
589  cout << " Check the update action: " << endl;
590 
591  vector<DTRecHit1D> hits_upd = phiSeg->specificRecHits();
592  for (vector<DTRecHit1D>::const_iterator hit = hits_upd.begin(); hit != hits_upd.end(); ++hit) {
593  // I have to get the hits position (the hit is in the layer rf) in SL frame...
594  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
595  LocalPoint pos = (theGeom->idToDet(phiSeg->geographicalId()))->toLocal(glbPos);
596 
597  x_upd.push_back(pos.z());
598  y_upd.push_back(pos.x());
599 
600  cout << " x_upd: " << pos.z() << " y_upd: " << pos.x() << endl;
601  }
602 
603  cout << " end of segment! " << endl;
604  cout << " size = Number of Hits: " << x_upd.size() << " " << y_upd.size() << endl;
605 
606  } // end debug
607 
608  return;
609 } //end DTSegmentUpdator::rejectBadHits
610 
612  if (seg->hasPhi())
613  calculateT0corr(seg->phiSegment());
614  if (seg->hasZed())
615  calculateT0corr(seg->zSegment());
616 }
617 
619  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
620  // seg->geographicalId() can be a superLayerId or a chamberId
621  if (debug)
622  cout << "[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
623 
624  vector<double> d_drift;
625  vector<float> x;
626  vector<float> y;
627  vector<int> lc;
628 
629  vector<DTRecHit1D> hits = seg->specificRecHits();
630 
631  DTWireId wireId;
632  int nptfit = 0;
633 
634  for (vector<DTRecHit1D>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
635  // I have to get the hits position (the hit is in the layer rf) in SL frame...
636  GlobalPoint glbPos = (theGeom->layer(hit->wireId().layerId()))->toGlobal(hit->localPosition());
637  LocalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toLocal(glbPos);
638 
639  const DTLayer* layer = theGeom->layer(hit->wireId().layerId());
640  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
641  float distance = fabs(hit->localPosition().x() - xwire);
642 
643  int ilc = (hit->lrSide() == DTEnums::Left) ? 1 : -1;
644 
645  nptfit++;
646  x.push_back(pos.z());
647  y.push_back(pos.x());
648  lc.push_back(ilc);
649  d_drift.push_back(distance);
650 
651  // cout << " d_drift "<<distance <<" npt= " <<npt<<endl;
652  }
653 
654  double chi2fit = 0.;
655  float cminf = 0.;
656  float vminf = 0.;
657  float a, b;
658 
659  if (nptfit > 2) {
660  //NB chi2fit is normalized
661  theFitter->fit4Var(x, y, lc, d_drift, nptfit, a, b, cminf, vminf, chi2fit, vdrift_4parfit, debug);
662 
663  double t0cor = -999.;
664  if (cminf > -998.)
665  t0cor = -cminf / 0.00543; // in ns
666 
667  //cout << "In calculateT0corr: t0 = " << t0cor << endl;
668  //cout << "In calculateT0corr: vminf = " << vminf << endl;
669  //cout << "In calculateT0corr: cminf = " << cminf << endl;
670  //cout << "In calculateT0corr: chi2 = " << chi2fit << endl;
671 
672  seg->setT0(t0cor); // time and
673  seg->setVdrift(vminf); // vdrift correction are recorded in the segment
674  }
675 }
Vector3DBase
Definition: Vector3DBase.h:8
DTRecSegment2D::ist0Valid
bool ist0Valid() const
Definition: DTRecSegment2D.h:115
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
DDAxes::y
DTRecSegment4D
Definition: DTRecSegment4D.h:23
mps_fire.i
i
Definition: mps_fire.py:428
DTRecSegment4D::localDirection
LocalVector localDirection() const override
Local direction in Chamber frame.
Definition: DTRecSegment4D.h:67
DTSegmentCand::sett0
virtual void sett0(double &t0)
set t0
Definition: DTSegmentCand.h:106
MessageLogger.h
DTSegmentUpdator::perform_delta_rejecting
bool perform_delta_rejecting
Definition: DTSegmentUpdator.h:109
DTSegmentUpdator::debug
bool debug
Definition: DTSegmentUpdator.h:110
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
DTRecSegment2D::t0
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
Definition: DTRecSegment2D.h:114
step
step
Definition: StallMonitor.cc:94
DTSegmentUpdator::DTSegmentUpdator
DTSegmentUpdator(const edm::ParameterSet &config)
Constructor.
Definition: DTSegmentUpdator.cc:47
GeomDet::setPosition
void setPosition(const Surface::PositionType &position, const Surface::RotationType &rotation)
Definition: GeomDet.cc:21
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
DTSegmentUpdator::calculateT0corr
void calculateT0corr(DTRecSegment2D *seg) const
Definition: DTSegmentUpdator.cc:618
DTRecSegment2D.h
DTSegmentCand::setPosition
virtual void setPosition(LocalPoint &pos)
set position
Definition: DTSegmentCand.h:90
DTRecHit1D.h
DTSegmentUpdator::T0_hit_resolution
double T0_hit_resolution
Definition: DTSegmentUpdator.h:108
edm
HLT enums.
Definition: AlignableModifier.h:19
DTSLRecSegment2D::superLayerId
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
Definition: DTSLRecSegment2D.cc:24
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
DTChamber
Definition: DTChamber.h:24
DTRecHit1D
Definition: DTRecHit1D.h:25
DTRecSegment2D::update
void update(std::vector< DTRecHit1D > &updatedRecHits)
Definition: DTRecSegment2D.cc:106
DTRecSegment4D::chamberId
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
Definition: DTRecSegment4D.cc:256
DTRecSegment4D::setCovMatrixForZed
void setCovMatrixForZed(const LocalPoint &posZInCh)
Definition: DTRecSegment4D.cc:188
DDAxes::x
DTSuperLayer
Definition: DTSuperLayer.h:24
DTRecSegment2D::setDirection
void setDirection(const LocalVector &dir)
Definition: DTRecSegment2D.cc:110
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
relativeConstraints.error
error
Definition: relativeConstraints.py:53
DTRecSegment4D::localPosition
LocalPoint localPosition() const override
Local position in Chamber frame.
Definition: DTRecSegment4D.h:61
DTRecSegment4D::zSegment
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
Definition: DTRecSegment4D.h:99
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTGeometry::chamber
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
hit::x
double x
Definition: SiStripHitEffFromCalibTree.cc:89
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DTSegmentUpdator::theAlgo
std::unique_ptr< DTRecHitBaseAlgo > theAlgo
Definition: DTSegmentUpdator.h:83
DTSegmentCand::setDirection
virtual void setDirection(LocalVector &dir)
set direction
Definition: DTSegmentCand.h:93
config
Definition: config.py:1
DTSegmentCand.h
HLT_FULL_cff.perform_delta_rejecting
perform_delta_rejecting
Definition: HLT_FULL_cff.py:9006
DTTopology::wirePosition
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:59
DTSegmentUpdator::rejectBadHits
void rejectBadHits(DTChamberRecSegment2D *) const
Definition: DTSegmentUpdator.cc:490
DTEnums::Left
Definition: DTEnums.h:15
debug
#define debug
Definition: HDRShower.cc:19
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
ErrorFrameTransformer
Definition: ErrorFrameTransformer.h:12
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTWireId
Definition: DTWireId.h:12
DTRecSegment4D::setDirection
void setDirection(LocalVector dir)
Set direction.
Definition: DTRecSegment4D.h:105
DTSegmentCand::setChi2
virtual void setChi2(double &chi2)
set chi2
Definition: DTSegmentCand.h:103
LocalError::xx
float xx() const
Definition: LocalError.h:22
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DTSegmentUpdator::fit
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
Definition: DTSegmentUpdator.cc:216
N
#define N
Definition: blowfish.cc:9
DTSegmentCand::hits
virtual const AssPointCont & hits() const
the used hits
Definition: DTSegmentCand.h:122
DTSegmentCand
Definition: DTSegmentCand.h:34
Point3DBase< float, GlobalTag >
DTRecSegment2D::setPosition
void setPosition(const LocalPoint &pos)
Definition: DTRecSegment2D.cc:108
DTRecSegment4D::setCovMatrix
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
Definition: DTRecSegment4D.h:108
GeomDet::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
b
double b
Definition: hdecay.h:118
DTLayer.h
DTGeometry.h
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
DTGeometry::layer
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
a
double a
Definition: hdecay.h:119
DTRecSegment2D
Definition: DTRecSegment2D.h:45
DTRecSegment2D::chi2
double chi2() const override
the chi2 of the fit
Definition: DTRecSegment2D.h:96
LocalError
Definition: LocalError.h:12
DTSuperLayerId::chamberId
DTChamberId chamberId() const
Return the corresponding ChamberId.
Definition: DTSuperLayerId.h:45
DTSegmentUpdator::theGeom
edm::ESHandle< DTGeometry > theGeom
Definition: DTSegmentUpdator.h:84
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
DTRecHitAlgoFactory.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
DTMeantimerPatternReco2DAlgo_LinearDriftFromDB_CosmicData_cfi.intime_cut
intime_cut
Definition: DTMeantimerPatternReco2DAlgo_LinearDriftFromDB_CosmicData_cfi.py:20
LocalVector
Local3DVector LocalVector
Definition: LocalVector.h:12
DTRecSegment2D::localPosition
LocalPoint localPosition() const override
local position in SL frame
Definition: DTRecSegment2D.h:84
DTChamberRecSegment2D
Definition: DTChamberRecSegment2D.h:31
DTLinearFit.h
GlobalErrorBase< double, ErrorMatrixTag >
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
edm::EventSetup
Definition: EventSetup.h:57
DTRecSegment4D.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DTSegmentUpdator::setES
void setES(const edm::EventSetup &setup)
set the setup
Definition: DTSegmentUpdator.cc:68
get
#define get
DTLayer
Definition: DTLayer.h:25
DTSegmentUpdator.h
DTChamberRecSegment2D.h
DTSegmentUpdator::intime_cut
double intime_cut
Definition: DTSegmentUpdator.h:106
DTEnums::Right
Definition: DTEnums.h:15
std
Definition: JetResolutionObject.h:76
DTRecSegment2D::setT0
void setT0(const double &t0)
Definition: DTRecSegment2D.cc:116
DTRecSegment4D::hasZed
bool hasZed() const
Does it have the Z projection?
Definition: DTRecSegment4D.h:93
ErrorFrameTransformer.h
Exception
Definition: hltDiff.cc:246
genVertex_cff.x
x
Definition: genVertex_cff.py:12
DTRecSegment2D::parametersError
AlgebraicSymMatrix parametersError() const override
Definition: DTRecSegment2D.cc:29
DTRecSegment2D::setVdrift
void setVdrift(const double &vdrift)
Definition: DTRecSegment2D.cc:118
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
DTRecSegment2D::specificRecHits
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
Definition: DTRecSegment2D.cc:104
angle
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
EventSetup.h
Exception.h
DTSLRecSegment2D.h
DTRecSegment2D::setCovMatrix
void setCovMatrix(const AlgebraicSymMatrix &cov)
Definition: DTRecSegment2D.cc:112
DTRecSegment4D::hasPhi
bool hasPhi() const
Does it have the Phi projection?
Definition: DTRecSegment4D.h:90
DTLayer::specificTopology
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
DTSegmentUpdator::theFitter
std::unique_ptr< DTLinearFit > theFitter
Definition: DTSegmentUpdator.h:82
DTSegmentUpdator::~DTSegmentUpdator
~DTSegmentUpdator()
Destructor.
DTGeometry::superLayer
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
Definition: DTGeometry.cc:92
DTRecSegment2D::localDirection
LocalVector localDirection() const override
the local direction in SL frame
Definition: DTRecSegment2D.h:90
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
DTSegmentUpdator::updateHits
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
Definition: DTSegmentUpdator.cc:416
DTRecSegment4D::setPosition
void setPosition(LocalPoint pos)
Set position.
Definition: DTRecSegment4D.h:102
MuonGeometryRecord.h
ErrorFrameTransformer::transform
static GlobalError transform(const LocalError &le, const Surface &surf)
Definition: ErrorFrameTransformer.h:16
slope
static const double slope[3]
Definition: CastorTimeSlew.cc:6
DTSegmentCand::setCovMatrix
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
Definition: DTSegmentCand.h:116
point
*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
DTSegmentUpdator::vdrift_4parfit
bool vdrift_4parfit
Definition: DTSegmentUpdator.h:107
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
DTGeometry::idToDet
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
DTRecSegment4D::phiSegment
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
Definition: DTRecSegment4D.h:96
DTRecSegment2D::vDrift
double vDrift() const
Definition: DTRecSegment2D.h:119
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTRecSegment2D::setChi2
void setChi2(const double &chi2)
Definition: DTRecSegment2D.cc:114
hit
Definition: SiStripHitEffFromCalibTree.cc:88
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
DTSegmentUpdator::update
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
Definition: DTSegmentUpdator.cc:73