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 
11 /* This Class Header */
13 
14 /* Collaborating Class Header */
15 
22 
26 
30 
35 
36 /* C++ Headers */
37 #include <string>
38 
39 using namespace std;
40 using namespace edm;
41 
42 /* ====================================================================== */
43 
46  theFitter(new DTLinearFit()) ,
47  vdrift_4parfit(config.getParameter<bool>("performT0_vdriftSegCorrection")),
48  T0_hit_resolution(config.getParameter<double>("hit_afterT0_resolution")),
49  debug(config.getUntrackedParameter<bool>("debug",false))
50 {
51  string theAlgoName = config.getParameter<string>("recAlgo");
52  theAlgo = DTRecHitAlgoFactory::get()->create(theAlgoName,
53  config.getParameter<ParameterSet>("recAlgoConfig"));
54 
55  if(debug)
56  cout << "[DTSegmentUpdator] Constructor called" << endl;
57 }
58 
61  delete theFitter;
62 }
63 
64 /* Operations */
65 
67  setup.get<MuonGeometryRecord>().get(theGeom);
68  theAlgo->setES(setup);
69 }
70 
71 void DTSegmentUpdator::update(DTRecSegment4D* seg, const bool calcT0) const {
72 
73  if(debug) cout << "[DTSegmentUpdator] Starting to update the segment" << endl;
74 
75  const bool hasPhi = seg->hasPhi();
76  const bool hasZed = seg->hasZed();
77 
78  int step = (hasPhi && hasZed) ? 3 : 2;
79  if(calcT0) step = 4;
80 
81  GlobalPoint pos = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localPosition());
82  GlobalVector dir = theGeom->idToDet(seg->geographicalId())->toGlobal(seg->localDirection());
83 
84  if(calcT0) calculateT0corr(seg);
85 
86  if(hasPhi) updateHits(seg->phiSegment(),pos,dir,step);
87  if(hasZed) updateHits(seg->zSegment() ,pos,dir,step);
88 
89  fit(seg);
90 }
91 
93  GlobalPoint pos = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localPosition());
94  GlobalVector dir = (theGeom->idToDet(seg->geographicalId()))->toGlobal(seg->localDirection());
95 
96  updateHits(seg,pos,dir);
97  fit(seg);
98 }
99 
101  // after the update must refit the segments
102  if(seg->hasPhi()) fit(seg->phiSegment());
103  if(seg->hasZed()) fit(seg->zSegment());
104 
105  const DTChamber* theChamber = theGeom->chamber(seg->chamberId());
106 
107  if(seg->hasPhi() && seg->hasZed() ) {
108 
109  DTChamberRecSegment2D *segPhi=seg->phiSegment();
110  DTSLRecSegment2D *segZed=seg->zSegment();
111 
112  // NB Phi seg is already in chamber ref
113  LocalPoint posPhiInCh = segPhi->localPosition();
114  LocalVector dirPhiInCh= segPhi->localDirection();
115 
116  // Zed seg is in SL one
117  const DTSuperLayer* zSL = theChamber->superLayer(segZed->superLayerId());
118  LocalPoint zPos(segZed->localPosition().x(),
119  (zSL->toLocal(theChamber->toGlobal(segPhi->localPosition()))).y(),
120  0.);
121 
122  LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
123 
124  LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(segZed->localDirection()));
125 
126  LocalPoint posZAt0 = posZInCh + dirZInCh*(-posZInCh.z())/cos(dirZInCh.theta());
127 
128  // given the actual definition of chamber refFrame, (with z poiniting to IP),
129  // the zed component of direction is negative.
130  LocalVector dir=LocalVector(dirPhiInCh.x()/fabs(dirPhiInCh.z()),dirZInCh.y()/fabs(dirZInCh.z()),-1.);
131 
132  seg->setPosition(LocalPoint(posPhiInCh.x(),posZAt0.y(),0.));
133  seg->setDirection(dir.unit());
134 
135  AlgebraicSymMatrix mat(4);
136 
137  // set cov matrix
138  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
139  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
140  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
141 
142  seg->setCovMatrix(mat);
143  seg->setCovMatrixForZed(posZInCh);
144 
145  }
146 
147  else if (seg->hasPhi()) {
148  DTChamberRecSegment2D *segPhi=seg->phiSegment();
149 
150  seg->setPosition(segPhi->localPosition());
151  seg->setDirection(segPhi->localDirection());
152 
153  AlgebraicSymMatrix mat(4);
154  // set cov matrix
155  mat[0][0] = segPhi->parametersError()[0][0]; //sigma (dx/dz)
156  mat[0][2] = segPhi->parametersError()[0][1]; //cov(dx/dz,x)
157  mat[2][2] = segPhi->parametersError()[1][1]; //sigma (x)
158 
159  seg->setCovMatrix(mat);
160  }
161 
162  else if (seg->hasZed()) {
163  DTSLRecSegment2D *segZed = seg->zSegment();
164 
165  // Zed seg is in SL one
166  GlobalPoint glbPosZ = ( theGeom->superLayer(segZed->superLayerId()) )->toGlobal(segZed->localPosition());
167  LocalPoint posZInCh = ( theGeom->chamber(segZed->superLayerId().chamberId()) )->toLocal(glbPosZ);
168 
169  GlobalVector glbDirZ = (theGeom->superLayer(segZed->superLayerId()) )->toGlobal(segZed->localDirection());
170  LocalVector dirZInCh = (theGeom->chamber(segZed->superLayerId().chamberId()) )->toLocal(glbDirZ);
171 
172  LocalPoint posZAt0 = posZInCh+
173  dirZInCh*(-posZInCh.z())/cos(dirZInCh.theta());
174 
175  seg->setPosition(posZAt0);
176  seg->setDirection(dirZInCh);
177 
178  AlgebraicSymMatrix mat(4);
179  // set cov matrix
180  seg->setCovMatrix(mat);
181  seg->setCovMatrixForZed(posZInCh);
182  }
183 }
184 
186  if (!seg->good()) return false;
187 
188  vector<float> x;
189  vector<float> y;
190  vector<float> sigy;
191 
192  DTSegmentCand::AssPointCont hits=seg->hits();
193  for (DTSegmentCand::AssPointCont::const_iterator iter=hits.begin();
194  iter!=hits.end(); ++iter) {
195  LocalPoint pos = (*iter).first->localPosition((*iter).second);
196  x.push_back(pos.z());
197  y.push_back(pos.x());
198  sigy.push_back(sqrt((*iter).first->localPositionError().xx()));
199  }
200 
201  LocalPoint pos;
203  AlgebraicSymMatrix covMat(2);
204 
205  double chi2 = 0.;
206  fit(x,y,sigy,pos,dir,covMat,chi2);
207 
208  seg->setPosition(pos);
209  seg->setDirection(dir);
210 
211  //cout << "pos " << segPosition<< endl;
212  //cout << "dir " << segDirection<< endl;
213 
214  seg->setCovMatrix(covMat);
215  // cout << "Mat " << covMat << endl;
216 
217  seg->setChi2(chi2);
218  return true;
219 }
220 
222  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
223  // seg->geographicalId() can be a superLayerId or a chamberId
224 
225  vector<float> x;
226  vector<float> y;
227  vector<float> sigy;
228 
229  vector<DTRecHit1D> hits=seg->specificRecHits();
230  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
231  hit!=hits.end(); ++hit) {
232 
233  // I have to get the hits position (the hit is in the layer rf) in SL frame...
234  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
235  LocalPoint pos = ( theGeom->idToDet(seg->geographicalId()) )->toLocal(glbPos);
236 
237  x.push_back(pos.z());
238  y.push_back(pos.x());
239 
240  // Get local error in SL frame
241  //RB: is it right in this way?
243  GlobalError glbErr =
244  tran.transform( hit->localPositionError(),(theGeom->layer( hit->wireId().layerId() ))->surface());
245  LocalError slErr =
246  tran.transform( glbErr, (theGeom->idToDet(seg->geographicalId()))->surface());
247 
248  sigy.push_back(sqrt(slErr.xx()));
249  }
250 
251  LocalPoint pos;
253  AlgebraicSymMatrix covMat(2);
254  double chi2 = 0.;
255 
256  fit(x,y,sigy,pos,dir,covMat,chi2);
257 
258  seg->setPosition(pos);
259  seg->setDirection(dir);
260 
261  //cout << "pos " << segPosition << endl;
262  //cout << "dir " << segDirection << endl;
263 
264  seg->setCovMatrix(covMat);
265  // cout << "Mat " << mat << endl;
266 
267  seg->setChi2(chi2);
268 }
269 
270 void DTSegmentUpdator::fit(const vector<float>& x,
271  const vector<float>& y,
272  const vector<float>& sigy,
273  LocalPoint& pos,
274  LocalVector& dir,
275  AlgebraicSymMatrix& covMatrix,
276  double& chi2) const {
277 
278  float slope = 0.;
279  float intercept = 0.;
280  float covss = 0.;
281  float covii = 0.;
282  float covsi = 0.;
283 
284  // do the fit
285  theFitter->fit(x,y,x.size(),sigy,slope,intercept,covss,covii,covsi);
286  // cout << "slope " << slope << endl;
287  // cout << "intercept " << intercept << endl;
288 
289  // intercept is the x() in chamber frame when the segment cross the chamber
290  // plane (at z()=0), the y() is not measured, so let's put the center of the
291  // chamber.
292  pos = LocalPoint(intercept,0.,0.);
293 
294  // slope is dx()/dz(), while dy()/dz() is by definition 0, finally I want the
295  // segment to point outward, so opposite to local z
296  dir = LocalVector(-slope,0.,-1.).unit();
297 
298  covMatrix = AlgebraicSymMatrix(2);
299  covMatrix[0][0] = covss; // this is var(dy/dz)
300  covMatrix[1][1] = covii; // this is var(y)
301  covMatrix[1][0] = covsi; // this is cov(dy/dz,y)
302 
303  /* Calculate chi2. */
304  chi2 = 0.;
305  for(unsigned int i=0; i<x.size() ; ++i) {
306  double resid= y[i] - (intercept + slope*x[i]);
307  chi2 += (resid/sigy[i])*(resid/sigy[i]);
308  }
309 }
310 
311 // The GlobalPoint and the GlobalVector can be either the glb position and the direction
312 // of the 2D-segment itself or the glb position and direction of the 4D segment
314  GlobalVector &gdir, const int step) const{
315 
316  // it is not necessary to have DTRecHit1D* to modify the obj in the container
317  // but I have to be carefully, since I cannot make a copy before the iteration!
318 
319  vector<DTRecHit1D> toBeUpdatedRecHits = seg->specificRecHits();
320  vector<DTRecHit1D> updatedRecHits;
321 
322  for (vector<DTRecHit1D>::iterator hit= toBeUpdatedRecHits.begin();
323  hit!=toBeUpdatedRecHits.end(); ++hit) {
324 
325  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
326 
327  LocalPoint segPos=layer->toLocal(gpos);
328  LocalVector segDir=layer->toLocal(gdir);
329 
330  // define impact angle needed by the step 2
331  const float angle = atan(segDir.x()/-segDir.z());
332 
333  // define the local position (extr.) of the segment. Needed by the third step
334  LocalPoint segPosAtLayer=segPos+segDir*(-segPos.z())/cos(segDir.theta());
335 
336  DTRecHit1D newHit1D = (*hit);
337 
338  bool ok = true;
339 
340  if (step == 2) {
341  ok = theAlgo->compute(layer,*hit,angle,newHit1D);
342 
343  } else if (step == 3) {
344 
345  LocalPoint hitPos(hit->localPosition().x(),+segPosAtLayer.y(),0.);
346 
347  GlobalPoint glbpos= theGeom->layer( hit->wireId().layerId() )->toGlobal(hitPos);
348 
349  newHit1D.setPosition(hitPos);
350 
351  ok = theAlgo->compute(layer,*hit,angle,glbpos,newHit1D);
352 
353  } else if (step == 4) {
354 
355  const double vminf = seg->vDrift(); // vdrift correction are recorded in the segment
356  double cminf = 0.;
357  if(seg->ist0Valid()) cminf = - seg->t0()*0.00543;
358 
359  //cout << "In updateHits: t0 = " << seg->t0() << endl;
360  //cout << "In updateHits: vminf = " << vminf << endl;
361  //cout << "In updateHits: cminf = " << cminf << endl;
362 
363  const float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
364  const float distance = fabs(hit->localPosition().x() - xwire);
365 
366  const int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
367 
368  const double dy_corr = (vminf*ilc*distance-cminf*ilc );
369 
370  LocalPoint point(hit->localPosition().x() + dy_corr, +segPosAtLayer.y(), 0.);
371 
373 
374  newHit1D.setPositionAndError(point, error);
375 
376  //FIXME: check that the hit is still inside the cell
377  ok = true;
378 
379  } else throw cms::Exception("DTSegmentUpdator")<<" updateHits called with wrong step " << endl;
380 
381  if (ok) updatedRecHits.push_back(newHit1D);
382  else {
383  LogError("DTSegmentUpdator")<<"DTSegmentUpdator::updateHits failed update" << endl;
384  throw cms::Exception("DTSegmentUpdator")<<"updateHits failed update"<<endl;
385  }
386 
387  }
388  seg->update(updatedRecHits);
389 }
390 
392  if(seg->hasPhi()) calculateT0corr(seg->phiSegment());
393  if(seg->hasZed()) calculateT0corr(seg->zSegment());
394 }
395 
397  // WARNING: since this method is called both with a 2D and a 2DPhi as argument
398  // seg->geographicalId() can be a superLayerId or a chamberId
399 
400  vector<double> d_drift;
401  vector<float> x;
402  vector<float> y;
403  vector<int> lc;
404 
405  vector<DTRecHit1D> hits=seg->specificRecHits();
406 
407  DTWireId wireId;
408  int nptfit = 0;
409 
410  for (vector<DTRecHit1D>::const_iterator hit=hits.begin();
411  hit!=hits.end(); ++hit) {
412 
413  // I have to get the hits position (the hit is in the layer rf) in SL frame...
414  GlobalPoint glbPos = ( theGeom->layer( hit->wireId().layerId() ) )->toGlobal(hit->localPosition());
415  LocalPoint pos = ( theGeom->idToDet(seg->geographicalId()) )->toLocal(glbPos);
416 
417  const DTLayer* layer = theGeom->layer( hit->wireId().layerId() );
418  float xwire = layer->specificTopology().wirePosition(hit->wireId().wire());
419  float distance = fabs(hit->localPosition().x() - xwire);
420 
421  int ilc = ( hit->lrSide() == DTEnums::Left ) ? 1 : -1;
422 
423  nptfit++;
424  x.push_back(pos.z());
425  y.push_back(pos.x());
426  lc.push_back(ilc);
427  d_drift.push_back(distance);
428 
429  // cout << " d_drift "<<distance <<" npt= " <<npt<<endl;
430  }
431 
432  double chi2fit = 0.;
433  float cminf = 0.;
434  double vminf = 0.;
435 
436  if ( nptfit > 2 ) {
437  //NB chi2fit is normalized
438  Fit4Var(x,y,lc,d_drift,nptfit,cminf,vminf,chi2fit);
439 
440  double t0cor = -999.;
441  if(cminf > -998.) t0cor = - cminf/0.00543 ; // in ns
442 
443  //cout << "In calculateT0corr: t0 = " << t0cor << endl;
444  //cout << "In calculateT0corr: vminf = " << vminf << endl;
445  //cout << "In calculateT0corr: cminf = " << cminf << endl;
446  //cout << "In calculateT0corr: chi2 = " << chi2fit << endl;
447 
448  seg->setT0(t0cor); // time and
449  seg->setVdrift(vminf); // vdrift correction are recorded in the segment
450  }
451 }
452 
453 
454 void DTSegmentUpdator::Fit4Var(const vector<float>& xfit,
455  const vector<float>& yfit,
456  const vector<int>& lfit,
457  const vector<double>& tfit,
458  const int nptfit,
459  float& cminf,
460  double& vminf,
461  double& chi2fit) const {
462 
463  const double sigma = 0.0295;// errors can be inserted .just load them/that is the usual TB resolution value for DT chambers
464  double aminf = 0.;
465  double bminf = 0.;
466  int nppar = 0;
467  double sx = 0.;
468  double sx2 = 0.;
469  double sy = 0.;
470  double sxy = 0.;
471  double sl = 0.;
472  double sl2 = 0.;
473  double sly = 0.;
474  double slx = 0.;
475  double st = 0.;
476  double st2 = 0.;
477  double slt = 0.;
478  double sltx = 0.;
479  double slty = 0.;
480  double chi2fit2 = -1.;
481  double chi2fitN2 = -1. ;
482  double chi2fit3 = -1.;
483  double chi2fitN3 = -1. ;
484  double chi2fit4 = -1.;
485  double chi2fitN4 = -1.;
486  float bminf3 = bminf;
487  float aminf3 = aminf;
488  float cminf3 = cminf;
489  int nppar2 = 0;
490  int nppar3 = 0;
491  int nppar4 = 0;
492 
493  cminf = -999.;
494  vminf = 0.;
495 
496  for (int j=0; j<nptfit; j++){
497  sx = sx + xfit[j];
498  sy = sy + yfit[j];
499  sx2 = sx2 + xfit[j]*xfit[j];
500  sxy = sxy + xfit[j]*yfit[j];
501  sl = sl + lfit[j];
502  sl2 = sl2 + lfit[j]*lfit[j];
503  sly = sly + lfit[j]*yfit[j];
504  slx = slx + lfit[j]*xfit[j];
505  st = st + tfit[j];
506  st2 = st2 + tfit[j] * tfit[j];
507  slt = slt + lfit[j] * tfit[j];
508  sltx = sltx + lfit[j] * tfit[j]*xfit[j];
509  slty = slty + lfit[j] * tfit[j]*yfit[j];
510 
511  } //end loop
512 
513  const double delta = nptfit*sx2 - sx*sx;
514 
515  double a = 0.;
516  double b = 0.;
517 
518  if (delta!=0){ //
519  a = (sx2*sy - sx*sxy)/delta;
520  b = (nptfit*sxy - sx*sy)/delta;
521 
522  // cout << " NPAR=2 : slope = "<<b<< " intercept = "<<a <<endl;
523  for (int j=0; j<nptfit; j++){
524  const double ypred = a + b*xfit[j];
525  const double dy = (yfit[j] - ypred)/sigma;
526  chi2fit = chi2fit + dy*dy;
527  } //end loop chi2
528  }
529 
530  bminf = b;
531  aminf = a;
532 
533  nppar = 2;
534  nppar2 = nppar;
535 
536  chi2fit2 = chi2fit;
537  chi2fitN2 = chi2fit/(nptfit-2);
538 
539  // cout << "dt0 = 0chi2fit = " << chi2fit << " slope = "<<b<<endl;
540 
541  if (nptfit >= 3) {
542 
543  const double d1 = sy;
544  const double d2 = sxy;
545  const double d3 = sly;
546  const double c1 = sl;
547  const double c2 = slx;
548  const double c3 = sl2;
549  const double b1 = sx;
550  const double b2 = sx2;
551  const double b3 = slx;
552  const double a1 = nptfit;
553  const double a2 = sx;
554  const double a3 = sl;
555 
556  //these parameters are not used in the 4-variables fit
557  const double b4 = b2*a1-b1*a2;
558  const double c4 = c2*a1-c1*a2;
559  const double d4 = d2*a1-d1*a2;
560  const double b5 = a1*b3-a3*b1;
561  const double c5 = a1*c3-a3*c1;
562  const double d5 = a1*d3-d1*a3;
563  const double a6 = slt;
564  const double b6 = sltx;
565  const double c6 = st;
566  const double v6 = st2;
567  const double d6 = slty;
568 
569  if (((c5*b4-c4*b5)*b4*a1)!=0) {
570  nppar = 3;
571  chi2fit = 0.;
572  cminf = (d5*b4-d4*b5)/(c5*b4-c4*b5);
573  bminf = d4/b4 -cminf *c4/b4;
574  aminf = (d1/a1 -cminf*c1/a1 -bminf*b1/a1);
575 
576  for (int j=0; j<nptfit; j++){
577  const double ypred = aminf + bminf*xfit[j];
578  const double dy = (yfit[j]-cminf*lfit[j] - ypred)/sigma;
579  chi2fit = chi2fit + dy*dy;
580 
581  } //end loop chi2
582  chi2fit3 = chi2fit;
583  if (nptfit>3)
584  chi2fitN3 = chi2fit /(nptfit-3);
585 
586  }
587  else {
588  cminf = -999.;
589  bminf = b;
590  aminf = a;
591  chi2fit3 = chi2fit;
592  chi2fitN3 = chi2fit /(nptfit-2);
593  }
594 
595  bminf3 = bminf;
596  aminf3 = aminf;
597  cminf3 = cminf;
598  nppar3 = nppar;
599 
600  if (debug) {
601  cout << "dt0= 0 : slope 2 = " << b << " pos in = " << a << " chi2fitN2 = " << chi2fitN2
602  << " nppar = " << nppar2 << " nptfit = " << nptfit << endl;
603  cout << "dt0 = 0 : slope 3 = " << bminf << " pos out = " << aminf << " chi2fitN3 = "
604  << chi2fitN3 << " nppar = " << nppar3 << " T0_ev ns = " << cminf/0.00543 << endl;
605  }
606 
607  //***********************************
608  // cout << " vdrift_4parfit "<< vdrift_4parfit<<endl;
609  if( nptfit>=5 && vdrift_4parfit) {
610  const double det = (a1*a1*(b2*v6 - b6*b6) - a1*(a2*a2*v6 - 2*a2*a6*b6 + a6*a6*b2 + b2*c6*c6 + b3*(b3*v6 - 2*b6*c6))
611  + a2*a2*c6*c6 + 2*a2*(a3*(b3*v6 - b6*c6) - a6*b3*c6) + a3*a3*(b6*b6 - b2*v6)
612  + a6*(2*a3*(b2*c6 - b3*b6) + a6*b3*b3));
613 
614  // the dv/vdrift correction may be computed under vdrift_4parfit request;
615  if (det != 0) {
616  nppar = 4;
617  chi2fit = 0.;
618  // computation of a, b, c e v
619  aminf = (a1*(a2*(b6*d6 - v6*d2) + a6*(b6*d2 - b2*d6) + d1*(b2*v6 - b6*b6)) - a2*(b3*(c6*d6 - v6*d3)
620  + c6*(b6*d3 - c6*d2)) + a3*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2))
621  + a6*(b2*c6*d3 + b3*(b3*d6 - b6*d3 - c6*d2)) - d1*(b2*c6*c6 + b3*(b3*v6 - 2*b6*c6)))/det;
622  bminf = - (a1*a1*(b6*d6 - v6*d2) - a1*(a2*(a6*d6 - v6*d1) - a6*a6*d2 + a6*b6*d1 + b3*(c6*d6 - v6*d3)
623  + c6*(b6*d3 - c6*d2)) + a2*(a3*(c6*d6 - v6*d3) + c6*(a6*d3 - c6*d1)) + a3*a3*(v6*d2 - b6*d6)
624  + a3*(a6*(b3*d6 + b6*d3 - 2*c6*d2) - d1*(b3*v6 - b6*c6)) - a6*b3*(a6*d3 - c6*d1))/det;
625  cminf = -(a1*(b2*(c6*d6 - v6*d3) + b3*(v6*d2 - b6*d6) + b6*(b6*d3 - c6*d2)) + a2*a2*(v6*d3 - c6*d6)
626  + a2*(a3*(b6*d6 - v6*d2) + a6*(b3*d6 - 2*b6*d3 + c6*d2) - d1*(b3*v6 - b6*c6))
627  + a3*(d1*(b2*v6 - b6*b6) - a6*(b2*d6 - b6*d2)) + a6*(a6*(b2*d3 - b3*d2) - d1*(b2*c6 - b3*b6)))/det;
628  vminf = - (a1*a1*(b2*d6 - b6*d2) - a1*(a2*a2*d6 - a2*(a6*d2 + b6*d1) + a6*b2*d1 + b2*c6*d3
629  + b3*(b3*d6 - b6*d3 - c6*d2)) + a2*a2*c6*d3 + a2*(a3*(2*b3*d6 - b6*d3 - c6*d2) - b3*(a6*d3 + c6*d1))
630  + a3*a3*(b6*d2 - b2*d6) + a3*(a6*(b2*d3 - b3*d2) + d1*(b2*c6 - b3*b6)) + a6*b3*b3*d1)/det;
631 
632  // chi 2
633  for (int j=0; j<nptfit; j++) {
634  const double ypred = aminf + bminf*xfit[j];
635  const double dy = (yfit[j]+vminf*lfit[j]*tfit[j]-cminf*lfit[j] -ypred)/sigma;
636  chi2fit = chi2fit + dy*dy;
637 
638  } //end loop chi2
639  if (nptfit<=nppar){
640  chi2fit4=chi2fit; //set negative Chi2 if not a fit...;
641  chi2fitN4=-1;
642  // cout << "nptfit " << nptfit << " nppar " << nppar << endl;
643  }
644  else{
645  chi2fit4 = chi2fit ;
646  chi2fitN4= chi2fit / (nptfit-nppar);
647  }
648  }
649  else {
650  chi2fit4 = chi2fit;
651  vminf = 0.;
652 
653  if (nptfit <= nppar) chi2fitN4=-1;
654  else chi2fitN4 = chi2fit / (nptfit-nppar);
655  }
656 
657  if (fabs(vminf) >= 0.09) {
658  // for safety and for code construction..dont accept correction on dv/vdrift greater then 0.09
659  vminf = 0.;
660  cminf = cminf3;
661  aminf = aminf3;
662  bminf = bminf3;
663  nppar = 3;
664  chi2fit = chi2fit3;
665  }
666 
667  } //end if vdrift
668  nppar4 = nppar;
669 
670  } //end nptfit >=3
671 
672  if (debug) {
673  cout << " dt0= 0 : slope 4 = " << bminf << " pos out = " << aminf <<" chi2fitN4 = " << chi2fitN4
674  << " nppar= " << nppar4 << " T0_ev ns= " << cminf/0.00543 <<" delta v = " << vminf <<endl;
675  cout << nptfit << " nptfit " << " end chi2fit = " << chi2fit/ (nptfit-nppar ) << " T0_ev ns= " << cminf/0.00543 << " delta v = " << vminf <<endl;
676  }
677 
678  if ( fabs(vminf) >= 0.09 && debug ) { //checks only vdrift less then 10 % accepted
679  cout << "vminf gt 0.09 det= " << endl;
680  cout << "dt0= 0 : slope 4 = "<< bminf << " pos out = " << aminf << " chi2fitN4 = " << chi2fitN4
681  << " T0_ev ns = " << cminf/0.00543 << " delta v = "<< vminf << endl;
682  cout << "dt0 = 0 : slope 2 = "<< b << " pos in = " << a <<" chi2fitN2 = " << chi2fitN2
683  << " nppar = " << nppar-1 << " nptfit = " << nptfit <<endl;
684  cout << "dt0 = 0 : slope 3 = " << bminf << " pos out = " << aminf << " chi2fitN3 = "
685  << chi2fitN3 << " T0_ev ns = " << cminf/0.00543 << endl;
686  cout << nptfit <<" nptfit "<< " end chi2fit = " << chi2fit << "T0_ev ns= " << cminf/0.00543 << "delta v = "<< vminf <<endl;
687  }
688 
689  if (nptfit != nppar) chi2fit = chi2fit / (nptfit-nppar);
690 }
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:73
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:19
void setChi2(const double &chi2)
Local3DVector LocalVector
Definition: LocalVector.h:12
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 &cminf, double &vminf, double &chi2fit) const
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
GlobalError transform(const LocalError &le, const Surface &surf) const
void updateHits(DTRecSegment2D *seg, GlobalPoint &gpos, GlobalVector &gdir, const int step=2) const
list step
Definition: launcher.py:15
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:49
T y() const
Definition: PV3DBase.h:57
~DTSegmentUpdator()
Destructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:64
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
tuple d1
Definition: debug_cff.py:7
edm::ESHandle< DTGeometry > theGeom
Geom::Theta< T > theta() const
Definition: PV3DBase.h:69
virtual LocalVector localDirection() const
Local direction in Chamber frame.
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
DTLinearFit * theFitter
void setES(const edm::EventSetup &setup)
set the setup
double vDrift() const
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
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
int j
Definition: DBlmapReader.cc:9
bool fit(DTSegmentCand *seg) const
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.
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:41
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
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:94
void fit(const std::vector< float > &x, const std::vector< float > &y, int ndat, const std::vector< float > &sigy, float &slope, float &intercept, float &covss, float &covii, float &covsi) const
Definition: DTLinearFit.cc:28
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:41
void setVdrift(const double &vdrift)
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
virtual void setPosition(LocalPoint &pos)
set position
Definition: DTSegmentCand.h:91
Definition: DDAxes.h:10
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:56
DTRecHitBaseAlgo * theAlgo
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)
Definition: component.h:56
*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(const edm::ParameterSet &config)
Constructor.
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:67
void setCovMatrix(AlgebraicSymMatrix mat)
Set covariance matrix.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11