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(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  intime_cut=20.;
58  if (config.exists("intime_cut"))
59  intime_cut = config.getParameter<double>("intime_cut");
60 
61  if(debug)
62  cout << "[DTSegmentUpdator] Constructor called" << endl;
63 }
64 
67  delete theFitter;
68 }
69 
70 /* Operations */
71 
73  setup.get<MuonGeometryRecord>().get(theGeom);
74  theAlgo->setES(setup);
75 }
76 
77 void DTSegmentUpdator::update(DTRecSegment4D* seg, const bool calcT0, bool allow3par) const {
78 
79  if(debug) cout << "[DTSegmentUpdator] Starting to update the DTRecSegment4D" << endl;
80 
81  const bool hasPhi = seg->hasPhi();
82  const bool hasZed = seg->hasZed();
83 
84  //reject the bad hits (due to delta rays)
85  if(perform_delta_rejecting && hasPhi) rejectBadHits(seg->phiSegment());
86 
87  int step = (hasPhi && hasZed) ? 3 : 2;
88  if(calcT0) step = 4;
89 
90  if(debug) 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) calculateT0corr(seg);
96 
97  if(hasPhi) updateHits(seg->phiSegment(),pos,dir,step);
98  if(hasZed) updateHits(seg->zSegment() ,pos,dir,step);
99 
100  fit(seg,allow3par);
101 }
102 
103 void DTSegmentUpdator::update(DTRecSegment2D* seg, bool allow3par) const {
104  if(debug) cout << "[DTSegmentUpdator] Starting to update the DTRecSegment2D" << endl;
105  GlobalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localPosition());
106  GlobalVector dir = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localDirection());
107 
108  updateHits(seg,pos,dir);
109  fit(seg,allow3par,0);
110 }
111 
112 void DTSegmentUpdator::fit(DTRecSegment4D* seg, bool allow3par) const {
113  if(debug) cout << "[DTSegmentUpdator] Fit DTRecSegment4D:" << endl;
114  // after the update must refit the segments
115 
116  if (debug) {
117  if(seg->hasPhi()) cout << " 4D Segment contains a Phi segment. t0= " << seg->phiSegment()->t0() << " chi2= " << seg->phiSegment()->chi2() << endl;
118  if(seg->hasZed()) cout << " 4D Segment contains a Zed segment. t0= " << seg->zSegment()->t0() << " chi2= " << seg->zSegment()->chi2() << endl;
119  }
120 
121 
122  // 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
123  // segments are fit with the 2-par fit. Setting intime_cut to -1 results in the 3-par fit being used always.
124  if(seg->hasPhi()) {
125  if(seg->hasZed()) {
126  if (fabs(seg->phiSegment()->t0())<intime_cut) {
127  fit(seg->phiSegment(),allow3par,1);
128  fit(seg->zSegment(),allow3par,1);
129  } else {
130  fit(seg->phiSegment(),allow3par,0);
131  fit(seg->zSegment(),allow3par,0);
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  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 = (((*iter).first)->localPosition(DTEnums::Left).x() + ((*iter).first)->localPosition(DTEnums::Right).x()) /2.;
240  float distance = pos.x() - xwire;
241 
242  if ((*iter).second==DTEnums::Left) lfit.push_back(1);
243  else lfit.push_back(-1);
244 
245  dist.push_back(distance);
246  sigy.push_back(sqrt((*iter).first->localPositionError().xx()));
247  x.push_back(pos.z());
248  y.push_back(pos.x());
249  i++;
250  }
251 
252  LocalPoint pos;
254  AlgebraicSymMatrix covMat(2);
255  float cminf =0.;
256  float vminf =0.;
257  double chi2 = 0.;
258  double t0_corr = 0.;
259 
260  fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par);
261  if (cminf!=0) t0_corr=-cminf/0.00543; // convert drift distance to time
262 
263  if (debug && fitdebug)
264  cout << " DTcand chi2: " << chi2 << "/" << x.size() << " t0: " << t0_corr << endl;
265 
266  seg->setPosition(pos);
267  seg->setDirection(dir);
268  seg->sett0(t0_corr);
269  seg->setCovMatrix(covMat);
270  seg->setChi2(chi2);
271 
272  // cout << "pos " << pos << endl;
273  // cout << "dir " << dir << endl;
274  // cout << "Mat " << covMat << endl;
275 
276  return true;
277 }
278 
279 void DTSegmentUpdator::fit(DTRecSegment2D* seg, bool allow3par, bool block3par) const {
280 
281  if(debug) cout << "[DTSegmentUpdator] Fit DTRecSegment2D - 3par: " << allow3par << endl;
282 
283  vector<float> x;
284  vector<float> y;
285  vector<float> sigy;
286  vector <int> lfit;
287  vector <double> dist;
288  x.reserve(8);
289  y.reserve(8);
290  sigy.reserve(8);
291  lfit.reserve(8);
292  dist.reserve(8);
293 
294 // DTSuperLayerId DTid = (DTSuperLayerId)seg->geographicalId();
295 // if (DTid.superlayer()==2)
296 // allow3par = 0;
297 
298  vector<DTRecHit1D> hits=seg->specificRecHits();
299  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
300  hit!=hits.end(); ++hit) {
301 
302  // I have to get the hits position (the hit is in the layer rf) in SL frame...
303  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
304  LocalPoint pos = ( theGeom->idToDet(seg->geographicalId()) )->toLocal(glbPos);
305  x.push_back(pos.z());
306  y.push_back(pos.x());
307 
308  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
309  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
310  float distance = fabs(hit->localPosition().x() - xwire);
311  dist.push_back(distance);
312 
313  int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
314  lfit.push_back(ilc);
315 
316  // Get local error in SL frame
317  //RB: is it right in this way?
319  GlobalError glbErr = tran.transform( hit->localPositionError(),(theGeom->layer( hit->wireId().layerId() ))->surface());
320  LocalError slErr = tran.transform( glbErr, (theGeom->idToDet(seg->geographicalId()))->surface());
321  sigy.push_back(sqrt(slErr.xx()));
322  }
323 
324  LocalPoint pos;
326  AlgebraicSymMatrix covMat(2);
327  double chi2 = 0.;
328  float cminf=0.;
329  float vminf=0.;
330  double t0_corr = 0.;
331 
332  fit(x,y,lfit,dist,sigy,pos,dir,cminf,vminf,covMat,chi2,allow3par,block3par);
333  if (cminf!=0) t0_corr=-cminf/0.00543; // convert drift distance to time
334 
335  if (debug) cout << " DTSeg2d chi2: " << chi2 << endl;
336  if (debug) cout << " DTSeg2d Fit t0: " << t0_corr << endl;
337  // cout << "pos " << segPosition << endl;
338  // cout << "dir " << segDirection << endl;
339  // cout << "Mat " << mat << endl;
340 
341  seg->setPosition(pos);
342  seg->setDirection(dir);
343  seg->setCovMatrix(covMat);
344  seg->setChi2(chi2);
345  seg->setT0(t0_corr);
346 }
347 
348 void DTSegmentUpdator::fit(const vector<float>& x,
349  const vector<float>& y,
350  const vector<int>& lfit,
351  const vector<double>& dist,
352  const vector<float>& sigy,
353  LocalPoint& pos,
354  LocalVector& dir,
355  float& cminf,
356  float& vminf,
357  AlgebraicSymMatrix& covMatrix,
358  double& chi2,
359  const bool allow3par,
360  const bool block3par) const {
361 
362  float slope = 0.;
363  float intercept = 0.;
364  float covss = 0.;
365  float covii = 0.;
366  float covsi = 0.;
367 
368  cminf=0;
369  vminf=0;
370 
371  int leftHits=0, rightHits=0;
372  for (unsigned int i=0; i<lfit.size(); i++)
373  if (lfit[i]==1) leftHits++; else rightHits++;
374 
375  theFitter->fit(x,y,x.size(),sigy,slope,intercept,chi2,covss,covii,covsi);
376 
377  // If we have at least one left and one right hit we can try the 3 parameter fit (if it is switched on)
378  // FIXME: currently the covariance matrix from the 2-par fit is kept
379  if (leftHits && rightHits && (leftHits+rightHits>3) && allow3par) {
380  theFitter->fitNpar(3,x,y,lfit,dist,sigy,slope,intercept,cminf,vminf,chi2,debug);
381  double t0_corr=-cminf/0.00543;
382  if (fabs(t0_corr)<intime_cut && block3par) {
383  theFitter->fit(x,y,x.size(),sigy,slope,intercept,chi2,covss,covii,covsi);
384  cminf=0;
385  }
386  }
387 
388  // cout << "slope " << slope << endl;
389  // cout << "intercept " << intercept << endl;
390 
391  // intercept is the x() in chamber frame when the segment cross the chamber
392  // plane (at z()=0), the y() is not measured, so let's put the center of the
393  // chamber.
394  pos = LocalPoint(intercept,0.,0.);
395 
396  // slope is dx()/dz(), while dy()/dz() is by definition 0, finally I want the
397  // segment to point outward, so opposite to local z
398  dir = LocalVector(-slope,0.,-1.).unit();
399 
400  covMatrix = AlgebraicSymMatrix(2);
401  covMatrix[0][0] = covss; // this is var(dy/dz)
402  covMatrix[1][1] = covii; // this is var(y)
403  covMatrix[1][0] = covsi; // this is cov(dy/dz,y)
404 }
405 
406 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
407 // of the 2D-segment itself or the glb position and direction of the 4D segment
409  GlobalVector &gdir, const int step) const{
410 
411  // it is not necessary to have DTRecHit1D* to modify the obj in the container
412  // but I have to be carefully, since I cannot make a copy before the iteration!
413 
414  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
415  vector<DTRecHit1D> updatedRecHits;
416 
417  for (vector<DTRecHit1D>::iterator hit= toBeUpdatedRecHits.begin();
418  hit!=toBeUpdatedRecHits.end(); ++hit) {
419 
420  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
421 
422  LocalPoint segPos=layer->toLocal(gpos);
423  LocalVector segDir=layer->toLocal(gdir);
424 
425  // define impact angle needed by the step 2
426  const float angle = atan(segDir.x()/-segDir.z());
427 
428  // define the local position (extr.) of the segment. Needed by the third step
429  LocalPoint segPosAtLayer=segPos+segDir*(-segPos.z())/cos(segDir.theta());
430 
431  DTRecHit1D newHit1D = (*hit);
432  bool ok = true;
433 
434  if (step == 2) {
435  ok = theAlgo->compute(layer,*hit,angle,newHit1D);
436 
437  } else if (step == 3) {
438 
439  LocalPoint hitPos(hit->localPosition().x(),+segPosAtLayer.y(),0.);
440  GlobalPoint glbpos= theGeom->layer( hit->wireId().layerId() )->toGlobal(hitPos);
441  newHit1D.setPosition(hitPos);
442  ok = theAlgo->compute(layer,*hit,angle,glbpos,newHit1D);
443 
444  } else if (step == 4) {
445 
446  //const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
447  double vminf =0.;
448  if(vdrift_4parfit) vminf = seg->vDrift(); // use vdrift recorded in the segment only if vdrift_4parfit=True
449 
450  double cminf = 0.;
451  if(seg->ist0Valid()) cminf = - seg->t0()*0.00543;
452 
453  //cout << "In updateHits: t0 = " << seg->t0() << endl;
454  //cout << "In updateHits: vminf = " << vminf << endl;
455  //cout << "In updateHits: cminf = " << cminf << endl;
456 
457  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
458  const float distance = fabs(hit->localPosition().x() - xwire);
459  const int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
460  const double dy_corr = (vminf*ilc*distance-cminf*ilc );
461 
462  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
463 
464  //double final_hit_resol = T0_hit_resolution;
465  //if(newHit1D.wireId().layerId().superlayerId().superLayer() != 2) final_hit_resol = final_hit_resol * 0.8;
466  //LocalError error(final_hit_resol * final_hit_resol,0.,0.);
468  newHit1D.setPositionAndError(point, error);
469 
470  //FIXME: check that the hit is still inside the cell
471  ok = true;
472 
473  } else throw cms::Exception("DTSegmentUpdator")<<" updateHits called with wrong step " << endl;
474 
475  if (ok) updatedRecHits.push_back(newHit1D);
476  else {
477  LogError("DTSegmentUpdator")<<"DTSegmentUpdator::updateHits failed update" << endl;
478  throw cms::Exception("DTSegmentUpdator")<<"updateHits failed update"<<endl;
479  }
480 
481  }
482  seg->update(updatedRecHits);
483 }
484 
486 
487  vector<float> x;
488  vector<float> y;
489 
490  if(debug) cout << " Inside the segment updator, now loop on hits: ( x == z_loc , y == x_loc) " << endl;
491 
492  vector<DTRecHit1D> hits = phiSeg->specificRecHits();
493  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
494  hit!=hits.end(); ++hit) {
495 
496  // I have to get the hits position (the hit is in the layer rf) in SL frame...
497  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
498  LocalPoint pos = ( theGeom->idToDet(phiSeg->geographicalId()) )->toLocal(glbPos);
499 
500  x.push_back(pos.z());
501  y.push_back(pos.x());
502  }
503 
504  if(debug){
505  cout << " end of segment! " << endl;
506  cout << " size = Number of Hits: " << x.size() << " " << y.size() << endl;
507  }
508 
509  // Perform the 2 par fit:
510  float par[2]={0.,0.}; // q , m
511 
512  //variables to perform the fit:
513  float Sx = 0.;
514  float Sy = 0.;
515  float Sx2 = 0.;
516  float Sy2 = 0.;
517  float Sxy = 0.;
518 
519  size_t N = x.size();
520 
521  if (N == 0)
522  return;
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  Sy2 += y.at(i)*y.at(i);
529  Sxy += x.at(i)*y.at(i);
530 
531  }
532 
533  const float delta = N*Sx2 - Sx*Sx;
534  par[0] = ( Sx2*Sy - Sx*Sxy )/delta;
535  par[1] = ( N*Sxy - Sx*Sy )/delta;
536 
537  if(debug) cout << "fit 2 parameters done ----> par0: "<< par[0] << " par1: "<< par[1] << endl;
538 
539  // Calc residuals:
540  float residuals[N];
541 
542  for(size_t i = 0; i < N;++i)
543  residuals[i] = 0;
544 
545  for(size_t i = 0; i < N;++i){
546  residuals[i] = y.at(i) - par[1]*x.at(i) - par[0];
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) cout<<endl;
550  }
551  }
552 
553  if(debug) cout << " Residuals computed! "<< endl;
554 
555  // Perform bad hit rejecting -- update hits
556  vector<DTRecHit1D> updatedRecHits;
557 
558  float mean_residual = 0.; //mean of the absolute values of residuals
559 
560  for (size_t i = 0; i < N; ++i)
561  mean_residual += fabs(residuals[i]);
562 
563  mean_residual = mean_residual/(N - 2);
564 
565  if(debug) cout << " mean_residual: "<< mean_residual << endl;
566 
567  int i = 0;
568 
569  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
570  hit!=hits.end(); ++hit) {
571 
572  DTRecHit1D newHit1D = (*hit);
573 
574  float normResidual = mean_residual > 0 ? fabs(residuals[i])/mean_residual : 0;
575  if(normResidual < 1.5){
576 
577  updatedRecHits.push_back(newHit1D);
578  if(debug) cout << " accepted "<< i+1 << "th hit" <<" Irej: " << normResidual << endl;
579  ++i;
580  }
581  else {
582  if(debug) cout << " rejected "<< i+1 << "th hit" <<" Irej: " << normResidual << endl;
583  ++i;
584  continue;
585  }
586  }
587 
588  phiSeg->update(updatedRecHits);
589 
590  //final check!
591  if(debug){
592 
593  vector<float> x_upd;
594  vector<float> y_upd;
595 
596  cout << " Check the update action: " << endl;
597 
598  vector<DTRecHit1D> hits_upd = phiSeg->specificRecHits();
599  for (vector<DTRecHit1D>::const_iterator hit=hits_upd.begin();
600  hit!=hits_upd.end(); ++hit) {
601 
602  // I have to get the hits position (the hit is in the layer rf) in SL frame...
603  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
604  LocalPoint pos = ( theGeom->idToDet(phiSeg->geographicalId()) )->toLocal(glbPos);
605 
606  x_upd.push_back(pos.z());
607  y_upd.push_back(pos.x());
608 
609  cout << " x_upd: "<< pos.z() << " y_upd: "<< pos.x() << endl;
610  }
611 
612  cout << " end of segment! " << endl;
613  cout << " size = Number of Hits: " << x_upd.size() << " " << y_upd.size() << endl;
614 
615  }// end debug
616 
617  return;
618 } //end DTSegmentUpdator::rejectBadHits
619 
621  if(seg->hasPhi()) calculateT0corr(seg->phiSegment());
622  if(seg->hasZed()) calculateT0corr(seg->zSegment());
623 }
624 
626  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
627  // seg->geographicalId() can be a superLayerId or a chamberId
628  if(debug) cout << "[DTSegmentUpdator] CalculateT0corr DTRecSegment4D" << endl;
629 
630  vector<double> d_drift;
631  vector<float> x;
632  vector<float> y;
633  vector<int> lc;
634 
635  vector<DTRecHit1D> hits=seg->specificRecHits();
636 
637  DTWireId wireId;
638  int nptfit = 0;
639 
640  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
641  hit!=hits.end(); ++hit) {
642 
643  // I have to get the hits position (the hit is in the layer rf) in SL frame...
644  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
645  LocalPoint pos = ( theGeom->idToDet(seg->geographicalId()) )->toLocal(glbPos);
646 
647  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
648  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
649  float distance = fabs(hit->localPosition().x() - xwire);
650 
651  int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
652 
653  nptfit++;
654  x.push_back(pos.z());
655  y.push_back(pos.x());
656  lc.push_back(ilc);
657  d_drift.push_back(distance);
658 
659  // cout << " d_drift "<<distance <<" npt= " <<npt<<endl;
660  }
661 
662  double chi2fit = 0.;
663  float cminf = 0.;
664  float vminf = 0.;
665  float a,b;
666 
667  if ( nptfit > 2 ) {
668  //NB chi2fit is normalized
669  theFitter->fit4Var(x,y,lc,d_drift,nptfit,a,b,cminf,vminf,chi2fit,vdrift_4parfit,debug);
670 
671  double t0cor = -999.;
672  if(cminf > -998.) t0cor = - cminf/0.00543 ; // in ns
673 
674  //cout << "In calculateT0corr: t0 = " << t0cor << endl;
675  //cout << "In calculateT0corr: vminf = " << vminf << endl;
676  //cout << "In calculateT0corr: cminf = " << cminf << endl;
677  //cout << "In calculateT0corr: chi2 = " << chi2fit << endl;
678 
679  seg->setT0(t0cor); // time and
680  seg->setVdrift(vminf); // vdrift correction are recorded in the segment
681  }
682 }
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)
void rejectBadHits(DTChamberRecSegment2D *) const
float xx() const
Definition: LocalError.h:24
void setChi2(const double &chi2)
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
void calculateT0corr(DTRecSegment2D *seg) const
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 double chi2() const
the chi2 of the fit
virtual const AssPointCont & hits() const
the used hits
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
~DTSegmentUpdator()
Destructor.
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
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
void setCovMatrix(const AlgebraicSymMatrix &mat)
Set covariance matrix.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
const DTLayer * layer(DTLayerId id) const
Return a layer given its id.
Definition: DTGeometry.cc:110
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:18
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?
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return a DTSuperLayer given its id.
Definition: DTGeometry.cc:105
virtual LocalPoint localPosition() const
Local position in Chamber frame.
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.
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?
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:56
double b
Definition: hdecay.h:120
void setT0(const double &t0)
const DTChamber * chamber(DTChamberId id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:100
virtual bool compute(const DTLayer *layer, const DTDigi &digi, LocalPoint &leftPoint, LocalPoint &rightPoint, LocalError &error) const =0
HLT enums.
double a
Definition: hdecay.h:121
virtual void setDirection(LocalVector &dir)
set direction
Definition: DTSegmentCand.h:96
virtual const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:76
void setPosition(const LocalPoint &pos)
virtual LocalVector localDirection() const
the local direction in SL frame
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
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
DTRecHitBaseAlgo * theAlgo
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