CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(new DTLinearFit()) ,
49  vdrift_4parfit(config.getParameter<bool>("performT0_vdriftSegCorrection")),
50  T0_hit_resolution(config.getParameter<double>("hit_afterT0_resolution")),
51  perform_delta_rejecting(config.getParameter<bool>("perform_delta_rejecting")),
52  debug(config.getUntrackedParameter<bool>("debug",false))
53 {
54  string theAlgoName = config.getParameter<string>("recAlgo");
55  theAlgo = DTRecHitAlgoFactory::get()->create(theAlgoName,
56  config.getParameter<ParameterSet>("recAlgoConfig"));
57 
58  if(debug)
59  cout << "[DTSegmentUpdator] Constructor called" << endl;
60 }
61 
64  delete theFitter;
65 }
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,0);
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  // use the 2-par fit UNLESS the 4D segment only has the Phi projection or is out of time by more than 20ns
120  // - in these cases use the 3-par fit
121  if(seg->hasPhi()) {
122  if(seg->hasZed()) {
123 
124  // fit in-time Phi segments with the 2par fit and out-of-time segments with the 3par fit
125  if (fabs(seg->phiSegment()->t0())<40.) {
126  fit(seg->phiSegment(),allow3par,1);
127  fit(seg->zSegment(),allow3par,1);
128  } else {
129  fit(seg->phiSegment(),allow3par,0);
130  fit(seg->zSegment(),allow3par,0);
131  }
132 
133  } else fit(seg->phiSegment(),allow3par,0);
134  } else fit(seg->zSegment(),allow3par,0);
135 
136  const DTChamber* theChamber = theGeom->chamber(seg->chamberId());
137 
138  if(seg->hasPhi() && seg->hasZed() ) {
139 
140  DTChamberRecSegment2D *segPhi=seg->phiSegment();
141  DTSLRecSegment2D *segZed=seg->zSegment();
142 
143  // NB Phi seg is already in chamber ref
144  LocalPoint posPhiInCh = segPhi->localPosition();
145  LocalVector dirPhiInCh= segPhi->localDirection();
146 
147  // Zed seg is in SL one
148  const DTSuperLayer* zSL = theChamber->superLayer(segZed->superLayerId());
149  LocalPoint zPos(segZed->localPosition().x(),
150  (zSL->toLocal(theChamber->toGlobal(segPhi->localPosition()))).y(),
151  0.);
152 
153  LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
154 
155  LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(segZed->localDirection()));
156 
157  LocalPoint posZAt0 = posZInCh + dirZInCh*(-posZInCh.z())/cos(dirZInCh.theta());
158 
159  // given the actual definition of chamber refFrame, (with z poiniting to IP),
160  // the zed component of direction is negative.
161  LocalVector dir=LocalVector(dirPhiInCh.x()/fabs(dirPhiInCh.z()),dirZInCh.y()/fabs(dirZInCh.z()),-1.);
162 
163  seg->setPosition(LocalPoint(posPhiInCh.x(),posZAt0.y(),0.));
164  seg->setDirection(dir.unit());
165 
166  AlgebraicSymMatrix mat(4);
167 
168  // set cov matrix
169  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
170  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
171  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
172 
173  seg->setCovMatrix(mat);
174  seg->setCovMatrixForZed(posZInCh);
175  }
176  else if (seg->hasPhi()) {
177  DTChamberRecSegment2D *segPhi=seg->phiSegment();
178 
179  seg->setPosition(segPhi->localPosition());
180  seg->setDirection(segPhi->localDirection());
181 
182  AlgebraicSymMatrix mat(4);
183  // set cov matrix
184  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
185  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
186  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
187 
188  seg->setCovMatrix(mat);
189  }
190  else if (seg->hasZed()) {
191  DTSLRecSegment2D *segZed = seg->zSegment();
192 
193  // Zed seg is in SL one
194  GlobalPoint glbPosZ = ( theGeom->superLayer(segZed->superLayerId()) )->toGlobal(segZed->localPosition());
195  LocalPoint posZInCh = ( theGeom->chamber(segZed->superLayerId().chamberId()) )->toLocal(glbPosZ);
196 
197  GlobalVector glbDirZ = (theGeom->superLayer(segZed->superLayerId()) )->toGlobal(segZed->localDirection());
198  LocalVector dirZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()) )->toLocal(glbDirZ);
199 
200  LocalPoint posZAt0 = posZInCh+
201  dirZInCh*(-posZInCh.z())/cos(dirZInCh.theta());
202 
203  seg->setPosition(posZAt0);
204  seg->setDirection(dirZInCh);
205 
206  AlgebraicSymMatrix mat(4);
207  // set cov matrix
208  seg->setCovMatrix(mat);
209  seg->setCovMatrixForZed(posZInCh);
210  }
211 }
212 
213 
214 
215 bool DTSegmentUpdator::fit(DTSegmentCand* seg, bool allow3par, const bool fitdebug) const {
216 
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  DTSegmentCand::AssPointCont hits=seg->hits();
238  for (DTSegmentCand::AssPointCont::const_iterator iter=hits.begin(); iter!=hits.end(); ++iter) {
239  LocalPoint pos = (*iter).first->localPosition((*iter).second);
240  float xwire = (((*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) lfit.push_back(1);
244  else lfit.push_back(-1);
245 
246  dist.push_back(distance);
247  sigy.push_back(sqrt((*iter).first->localPositionError().xx()));
248  x.push_back(pos.z());
249  y.push_back(pos.x());
250  i++;
251  }
252 
253  LocalPoint pos;
255  AlgebraicSymMatrix covMat(2);
256  float cminf =0.;
257  float vminf =0.;
258  double chi2 = 0.;
259  double t0_corr = 0.;
260 
261  fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par);
262  if (cminf!=0) t0_corr=-cminf/0.00543; // convert drift distance to time
263 
264  if (debug && fitdebug) cout << " DTcand chi2: " << chi2 << endl;
265  if (debug && fitdebug) cout << " DTcand t0: " << t0_corr << endl;
266 
267  seg->setPosition(pos);
268  seg->setDirection(dir);
269  seg->sett0(t0_corr);
270  seg->setCovMatrix(covMat);
271  seg->setChi2(chi2);
272 
273  // cout << "pos " << pos << endl;
274  // cout << "dir " << dir << endl;
275  // cout << "Mat " << covMat << endl;
276 
277  return true;
278 }
279 
280 void DTSegmentUpdator::fit(DTRecSegment2D* seg, bool allow3par, bool block3par) const {
281 
282  if(debug) cout << "[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
283 
284  vector<float> x;
285  vector<float> y;
286  vector<float> sigy;
287  vector <int> lfit;
288  vector <double> dist;
289  x.reserve(8);
290  y.reserve(8);
291  sigy.reserve(8);
292  lfit.reserve(8);
293  dist.reserve(8);
294 
295 // DTSuperLayerId DTid = (DTSuperLayerId)seg->geographicalId();
296 // if (DTid.superlayer()==2)
297 // allow3par = 0;
298 
299  vector<DTRecHit1D> hits=seg->specificRecHits();
300  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
301  hit!=hits.end(); ++hit) {
302 
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 = tran.transform( hit->localPositionError(),(theGeom->layer( hit->wireId().layerId() ))->surface());
321  LocalError slErr = tran.transform( glbErr, (theGeom->idToDet(seg->geographicalId()))->surface());
322  sigy.push_back(sqrt(slErr.xx()));
323  }
324 
325  LocalPoint pos;
327  AlgebraicSymMatrix covMat(2);
328  double chi2 = 0.;
329  float cminf=0.;
330  float vminf=0.;
331  double t0_corr = 0.;
332 
333  fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par,block3par);
334  if (cminf!=0) t0_corr=-cminf/0.00543; // convert drift distance to time
335 
336  if (debug) cout << " DTSeg2d chi2: " << chi2 << endl;
337  if (debug) cout << " DTSeg2d Fit t0: " << t0_corr << endl;
338  // cout << "pos " << segPosition << endl;
339  // cout << "dir " << segDirection << endl;
340  // cout << "Mat " << mat << endl;
341 
342  seg->setPosition(pos);
343  seg->setDirection(dir);
344  seg->setCovMatrix(covMat);
345  seg->setChi2(chi2);
346  seg->setT0(t0_corr);
347 }
348 
349 void DTSegmentUpdator::fit(const vector<float>& x,
350  const vector<float>& y,
351  const vector<int>& lfit,
352  const vector<double>& dist,
353  const vector<float>& sigy,
354  LocalPoint& pos,
355  LocalVector& dir,
356  float& cminf,
357  float& vminf,
358  AlgebraicSymMatrix& covMatrix,
359  double& chi2,
360  const bool allow3par,
361  const bool block3par) const {
362 
363  float slope = 0.;
364  float intercept = 0.;
365  float covss = 0.;
366  float covii = 0.;
367  float covsi = 0.;
368 
369  cminf=0;
370  vminf=0;
371 
372  int leftHits=0, rightHits=0;
373  for (unsigned int i=0; i<lfit.size(); i++)
374  if (lfit[i]==1) leftHits++; else rightHits++;
375 
376  theFitter->fit(x,y,x.size(),sigy,slope,intercept,chi2,covss,covii,covsi);
377 
378  // If we have at least one left and one right hit we can try the 3 parameter fit (if it is switched on)
379  // FIXME: currently the covariance matrix from the 2-par fit is kept
380  if (leftHits && rightHits && (leftHits+rightHits>3) && allow3par) {
381  theFitter->fitNpar(3,x,y,lfit,dist,sigy,slope,intercept,cminf,vminf,chi2,debug);
382  double t0_corr=-cminf/0.00543;
383  if (fabs(t0_corr)<20. && block3par) {
384  theFitter->fit(x,y,x.size(),sigy,slope,intercept,chi2,covss,covii,covsi);
385  cminf=0;
386  }
387  }
388 
389  // cout << "slope " << slope << endl;
390  // cout << "intercept " << intercept << endl;
391 
392  // intercept is the x() in chamber frame when the segment cross the chamber
393  // plane (at z()=0), the y() is not measured, so let's put the center of the
394  // chamber.
395  pos = LocalPoint(intercept,0.,0.);
396 
397  // slope is dx()/dz(), while dy()/dz() is by definition 0, finally I want the
398  // segment to point outward, so opposite to local z
399  dir = LocalVector(-slope,0.,-1.).unit();
400 
401  covMatrix = AlgebraicSymMatrix(2);
402  covMatrix[0][0] = covss; // this is var(dy/dz)
403  covMatrix[1][1] = covii; // this is var(y)
404  covMatrix[1][0] = covsi; // this is cov(dy/dz,y)
405 }
406 
407 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
408 // of the 2D-segment itself or the glb position and direction of the 4D segment
410  GlobalVector &gdir, const int step) const{
411 
412  // it is not necessary to have DTRecHit1D* to modify the obj in the container
413  // but I have to be carefully, since I cannot make a copy before the iteration!
414 
415  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
416  vector<DTRecHit1D> updatedRecHits;
417 
418  for (vector<DTRecHit1D>::iterator hit= toBeUpdatedRecHits.begin();
419  hit!=toBeUpdatedRecHits.end(); ++hit) {
420 
421  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
422 
423  LocalPoint segPos=layer->toLocal(gpos);
424  LocalVector segDir=layer->toLocal(gdir);
425 
426  // define impact angle needed by the step 2
427  const float angle = atan(segDir.x()/-segDir.z());
428 
429  // define the local position (extr.) of the segment. Needed by the third step
430  LocalPoint segPosAtLayer=segPos+segDir*(-segPos.z())/cos(segDir.theta());
431 
432  DTRecHit1D newHit1D = (*hit);
433  bool ok = true;
434 
435  if (step == 2) {
436  ok = theAlgo->compute(layer,*hit,angle,newHit1D);
437 
438  } else if (step == 3) {
439 
440  LocalPoint hitPos(hit->localPosition().x(),+segPosAtLayer.y(),0.);
441  GlobalPoint glbpos= theGeom->layer( hit->wireId().layerId() )->toGlobal(hitPos);
442  newHit1D.setPosition(hitPos);
443  ok = theAlgo->compute(layer,*hit,angle,glbpos,newHit1D);
444 
445  } else if (step == 4) {
446 
447  //const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
448  double vminf =0.;
449  if(vdrift_4parfit) vminf = seg->vDrift(); // use vdrift recorded in the segment only if vdrift_4parfit=True
450 
451  double cminf = 0.;
452  if(seg->ist0Valid()) cminf = - seg->t0()*0.00543;
453 
454  //cout << "In updateHits: t0 = " << seg->t0() << endl;
455  //cout << "In updateHits: vminf = " << vminf << endl;
456  //cout << "In updateHits: cminf = " << cminf << endl;
457 
458  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
459  const float distance = fabs(hit->localPosition().x() - xwire);
460  const int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
461  const double dy_corr = (vminf*ilc*distance-cminf*ilc );
462 
463  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
464 
465  //double final_hit_resol = T0_hit_resolution;
466  //if(newHit1D.wireId().layerId().superlayerId().superLayer() != 2) final_hit_resol = final_hit_resol * 0.8;
467  //LocalError error(final_hit_resol * final_hit_resol,0.,0.);
469  newHit1D.setPositionAndError(point, error);
470 
471  //FIXME: check that the hit is still inside the cell
472  ok = true;
473 
474  } else throw cms::Exception("DTSegmentUpdator")<<" updateHits called with wrong step " << endl;
475 
476  if (ok) updatedRecHits.push_back(newHit1D);
477  else {
478  LogError("DTSegmentUpdator")<<"DTSegmentUpdator::updateHits failed update" << endl;
479  throw cms::Exception("DTSegmentUpdator")<<"updateHits failed update"<<endl;
480  }
481 
482  }
483  seg->update(updatedRecHits);
484 }
485 
487 
488  vector<float> x;
489  vector<float> y;
490 
491  if(debug) cout << " Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
492 
493  vector<DTRecHit1D> hits = phiSeg->specificRecHits();
494  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
495  hit!=hits.end(); ++hit) {
496 
497  // I have to get the hits position (the hit is in the layer rf) in SL frame...
498  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
499  LocalPoint pos = ( theGeom->idToDet(phiSeg->geographicalId()) )->toLocal(glbPos);
500 
501  x.push_back(pos.z());
502  y.push_back(pos.x());
503  }
504 
505  if(debug){
506  cout << " end of segment! " << endl;
507  cout << " size = Number of Hits: " << x.size() << " " << y.size() << endl;
508  }
509 
510  // Perform the 2 par fit:
511  float par[2]={0.,0.}; // q , m
512 
513  //variables to perform the fit:
514  float Sx = 0.;
515  float Sy = 0.;
516  float Sx2 = 0.;
517  float Sy2 = 0.;
518  float Sxy = 0.;
519 
520  size_t N = x.size();
521 
522  if (N == 0)
523  return;
524 
525  for(size_t i = 0; i < N;++i){
526  Sx += x.at(i);
527  Sy += y.at(i);
528  Sx2 += x.at(i)*x.at(i);
529  Sy2 += y.at(i)*y.at(i);
530  Sxy += x.at(i)*y.at(i);
531 
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) cout << "fit 2 parameters done ----> par0: "<< par[0] << " par1: "<< par[1] << endl;
539 
540  // Calc residuals:
541  float residuals[N];
542 
543  for(size_t i = 0; i < N;++i)
544  residuals[i] = 0;
545 
546  for(size_t i = 0; i < N;++i){
547  residuals[i] = y.at(i) - par[1]*x.at(i) - par[0];
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) cout<<endl;
551  }
552  }
553 
554  if(debug) cout << " Residuals computed! "<< endl;
555 
556  // Perform bad hit rejecting -- update hits
557  vector<DTRecHit1D> updatedRecHits;
558 
559  float mean_residual = 0.; //mean of the absolute values of residuals
560 
561  for (size_t i = 0; i < N; ++i)
562  mean_residual += fabs(residuals[i]);
563 
564  mean_residual = mean_residual/(N - 2);
565 
566  if(debug) cout << " mean_residual: "<< mean_residual << endl;
567 
568  int i = 0;
569 
570  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
571  hit!=hits.end(); ++hit) {
572 
573  DTRecHit1D newHit1D = (*hit);
574 
575  float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
576  if(normResidual < 1.5){
577 
578  updatedRecHits.push_back(newHit1D);
579  if(debug) cout << " accepted "<< i+1 << "th hit" <<" Irej: " << normResidual << endl;
580  ++i;
581  }
582  else {
583  if(debug) cout << " rejected "<< i+1 << "th hit" <<" Irej: " << normResidual << endl;
584  ++i;
585  continue;
586  }
587  }
588 
589  phiSeg->update(updatedRecHits);
590 
591  //final check!
592  if(debug){
593 
594  vector<float> x_upd;
595  vector<float> y_upd;
596 
597  cout << " Check the update action: " << endl;
598 
599  vector<DTRecHit1D> hits_upd = phiSeg->specificRecHits();
600  for (vector<DTRecHit1D>::const_iterator hit=hits_upd.begin();
601  hit!=hits_upd.end(); ++hit) {
602 
603  // I have to get the hits position (the hit is in the layer rf) in SL frame...
604  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
605  LocalPoint pos = ( theGeom->idToDet(phiSeg->geographicalId()) )->toLocal(glbPos);
606 
607  x_upd.push_back(pos.z());
608  y_upd.push_back(pos.x());
609 
610  cout << " x_upd: "<< pos.z() << " y_upd: "<< pos.x() << endl;
611  }
612 
613  cout << " end of segment! " << endl;
614  cout << " size = Number of Hits: " << x_upd.size() << " " << y_upd.size() << endl;
615 
616  }// end debug
617 
618  return;
619 } //end DTSegmentUpdator::rejectBadHits
620 
622  if(seg->hasPhi()) calculateT0corr(seg->phiSegment());
623  if(seg->hasZed()) calculateT0corr(seg->zSegment());
624 }
625 
627  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
628  // seg->geographicalId() can be a superLayerId or a chamberId
629  if(debug) cout << "[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
630 
631  vector<double> d_drift;
632  vector<float> x;
633  vector<float> y;
634  vector<int> lc;
635 
636  vector<DTRecHit1D> hits=seg->specificRecHits();
637 
638  DTWireId wireId;
639  int nptfit = 0;
640 
641  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
642  hit!=hits.end(); ++hit) {
643 
644  // I have to get the hits position (the hit is in the layer rf) in SL frame...
645  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
646  LocalPoint pos = ( theGeom->idToDet(seg->geographicalId()) )->toLocal(glbPos);
647 
648  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
649  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
650  float distance = fabs(hit->localPosition().x() - xwire);
651 
652  int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
653 
654  nptfit++;
655  x.push_back(pos.z());
656  y.push_back(pos.x());
657  lc.push_back(ilc);
658  d_drift.push_back(distance);
659 
660  // cout << " d_drift "<<distance <<" npt= " <<npt<<endl;
661  }
662 
663  double chi2fit = 0.;
664  float cminf = 0.;
665  float vminf = 0.;
666  float a,b;
667 
668  if ( nptfit > 2 ) {
669  //NB chi2fit is normalized
670  theFitter->fit4Var(x,y,lc,d_drift,nptfit,a,b,cminf,vminf,chi2fit,vdrift_4parfit,debug);
671 
672  double t0cor = -999.;
673  if(cminf > -998.) t0cor = - cminf/0.00543 ; // in ns
674 
675  //cout << "In calculateT0corr: t0 = " << t0cor << endl;
676  //cout << "In calculateT0corr: vminf = " << vminf << endl;
677  //cout << "In calculateT0corr: cminf = " << cminf << endl;
678  //cout << "In calculateT0corr: chi2 = " << chi2fit << endl;
679 
680  seg->setT0(t0cor); // time and
681  seg->setVdrift(vminf); // vdrift correction are recorded in the segment
682  }
683 }
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
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)
int i
Definition: DBlmapReader.cc:9
void rejectBadHits(DTChamberRecSegment2D *) const
float xx() const
Definition: LocalError.h:24
void setChi2(const double &chi2)
Local3DVector LocalVector
Definition: LocalVector.h:12
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
void calculateT0corr(DTRecSegment2D *seg) const
double zPos
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:47
virtual double chi2() const
the chi2 of the fit
T y() const
Definition: PV3DBase.h:63
~DTSegmentUpdator()
Destructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
virtual void setChi2(double &chi2)
set chi2
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void setCovMatrix(const AlgebraicSymMatrix &cov)
void setCovMatrixForZed(const LocalPoint &posZInCh)
void update(std::vector< DTRecHit1D > &updatedRecHits)
virtual bool good() const
edm::ESHandle< DTGeometry > theGeom
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
void fit(const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigy, float &slope, float &intercept, double &chi2, float &covss, float &covii, float &covsi) const
Definition: DTLinearFit.cc:27
virtual LocalVector localDirection() const
Local direction in Chamber frame.
const DTTopology & specificTopology() const
Definition: DTLayer.cc:42
DTLinearFit * theFitter
void setES(const edm::EventSetup &setup)
set the setup
double vDrift() const
void fit4Var(const std::vector< float > &xfit, const std::vector< float > &yfit, const std::vector< int > &lfit, const std::vector< double > &tfit, const int nptfit, float &aminf, float &bminf, float &cminf, float &vminf, double &chi2fit, const bool vdrift_4parfit, const bool debug) const
Definition: DTLinearFit.cc:238
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
virtual void setES(const edm::EventSetup &setup)=0
Pass the Event Setup to the algo at each event.
virtual void setCovMatrix(AlgebraicSymMatrix &cov)
set the cov matrix
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void setDirection(LocalVector dir)
Set direction.
bool hasPhi() const
Does it have the Phi projection?
virtual bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const =0
virtual LocalPoint localPosition() const
Local position in Chamber frame.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
bool ist0Valid() const
virtual AssPointCont hits() const
the used hits
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
void fitNpar(const int npar, const std::vector< float > &xfit, const std::vector< float > &yfit, const std::vector< int > &lfit, const std::vector< double > &tfit, const std::vector< float > &sigy, float &aminf, float &bminf, float &cminf, float &vminf, double &chi2fit, const bool debug) const
Definition: DTLinearFit.cc:70
virtual LocalPoint localPosition() const
local position in SL frame
Vector3DBase unit() const
Definition: Vector3DBase.h:57
bool hasZed() const
Does it have the Z projection?
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:40
virtual void sett0(double &t0)
set t0
#define debug
Definition: HDRShower.cc:19
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
#define N
Definition: blowfish.cc:9
virtual AlgebraicSymMatrix parametersError() const
const T & get() const
Definition: EventSetup.h:55
double b
Definition: hdecay.h:120
void setT0(const double &t0)
double a
Definition: hdecay.h:121
virtual void setDirection(LocalVector &dir)
set direction
Definition: DTSegmentCand.h:96
void setPosition(const LocalPoint &pos)
virtual LocalVector localDirection() const
the local direction in SL frame
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setDirection(const LocalVector &dir)
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
void setPosition(LocalPoint pos)
Set position.
tuple cout
Definition: gather_cfg.py:121
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
void setVdrift(const double &vdrift)
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
volatile std::atomic< bool > shutdown_flag false
virtual void setPosition(LocalPoint &pos)
set position
Definition: DTSegmentCand.h:93
Definition: DDAxes.h:10
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
T x() const
Definition: PV3DBase.h:62
DTRecHitBaseAlgo * theAlgo
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11