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