329 bool skipMeasurement =
false;
334 bool fitQoverP =
true;
348 TVectorD scatResidual(2);
358 cout <<
"WARNING: Hits resorting in GBL interface not supported." << endl;
360 cout <<
"-------------------------------------------------------" << endl;
361 cout <<
" GBL processing genfit::Track " << endl;
362 cout <<
"-------------------------------------------------------" << endl;
363 cout <<
" # Ref. Track Points : " << npoints_all << endl;
364 cout <<
" # Meas. Points : " << npoints_meas << endl;
368 std::vector<GblPoint> listOfPoints;
370 std::vector<double> listOfLayers;
373 unsigned int seedLabel = 0;
377 TMatrixDSym clSeed(dim);
380 TMatrixD jacPointToPoint(dim, dim);
381 jacPointToPoint.UnitMatrix();
383 int n_gbl_points = 0;
384 int n_gbl_meas_points = 0;
387 double lostWeight = 0.;
390 double trackMomMag = 0.;
392 double particleCharge = 1.;
394 for (
int ipoint_meas = 0; ipoint_meas < npoints_meas; ipoint_meas++) {
398 cout <<
" ERROR: Measurement point does not have a fitter info. Track will be skipped." << endl;
404 cout <<
" ERROR: KalmanFitterInfo (with reference state) for measurement does not exist. Track will be skipped." << endl;
410 cout <<
" ERROR: Fitter info does not contain reference state. Track will be skipped." << endl;
416 TVectorD state = reference->
getState();
418 TVector3 trackDir = rep->
getDir(*reference);
420 trackMomMag = rep->
getMomMag(*reference);
422 particleCharge = rep->
getCharge(*reference);
424 double particleMass = rep->
getMass(*reference);
427 double trackLen = 0.;
428 double scatTheta = 0.;
429 double scatSMean = 0.;
430 double scatDeltaS = 0.;
440 TMatrixD jacMeas2Scat(dim, dim);
441 jacMeas2Scat.UnitMatrix();
450 if (measPlanar) sensorId = measPlanar->
getPlaneId();
466 if (measPlanar2) sensorId2 = measPlanar->
getPlaneId();
470 if (sensorId != sensorId2) {
471 skipMeasurement =
true;
472 cout <<
" ERROR: Incompatible sensorIDs at measurement point " << ipoint_meas <<
". Measurement will be skipped." << endl;
482 raw_measU = raw_meas1;
483 raw_measV = raw_meas2;
487 raw_measU = raw_meas2;
488 raw_measV = raw_meas1;
491 cout <<
" ERROR: Incompatible 1D measurements at meas. point " << ipoint_meas <<
". Track will be skipped." << endl;
495 TVectorD _raw_coor(2);
499 TMatrixDSym _raw_cov(2);
511 skipMeasurement =
true;
513 cout <<
" WARNING: Measurement " << (ipoint_meas + 1) <<
" is not 2D. Measurement Will be skipped. " << endl;
519 if (!skipMeasurement) {
525 boost::scoped_ptr<const AbsHMatrix> HitHMatrix(raw_meas->
constructHMatrix(rep));
527 TVectorD residual = -1. * (raw_coor - HitHMatrix->Hv(state));
529 trkChi2 += residual(0) * residual(0) / raw_cov(0, 0) + residual(1) * residual(1) / raw_cov(1, 1);
532 GblPoint measPoint(jacPointToPoint);
536 TMatrixD proL2m(2, 2);
538 proL2m(0, 0) = HitHMatrix->getMatrix()(0, 3);
539 proL2m(0, 1) = HitHMatrix->getMatrix()(0, 4);
540 proL2m(1, 1) = HitHMatrix->getMatrix()(1, 4);
541 proL2m(1, 0) = HitHMatrix->getMatrix()(1, 3);
550 int label = sensorId * 10;
553 TMatrixD derGlobal(2, 12);
556 std::vector<int> labGlobal;
559 TVector3 tDir = trackDir;
561 TVector3 uDir = plane->getU();
563 TVector3 vDir = plane->getV();
565 TVector3 nDir = plane->getNormal();
571 TVector3 tLoc = TVector3(uDir.Dot(tDir), vDir.Dot(tDir), nDir.Dot(tDir));
574 double uSlope = tLoc[0] / tLoc[2];
576 double vSlope = tLoc[1] / tLoc[2];
579 double uPos = raw_coor[0];
581 double vPos = raw_coor[1];
584 derGlobal(0, 0) = 1.0;
585 derGlobal(0, 1) = 0.0;
586 derGlobal(0, 2) = - uSlope;
587 derGlobal(0, 3) = vPos * uSlope;
588 derGlobal(0, 4) = -uPos * uSlope;
589 derGlobal(0, 5) = vPos;
591 derGlobal(1, 0) = 0.0;
592 derGlobal(1, 1) = 1.0;
593 derGlobal(1, 2) = - vSlope;
594 derGlobal(1, 3) = vPos * vSlope;
595 derGlobal(1, 4) = -uPos * vSlope;
596 derGlobal(1, 5) = -uPos;
598 labGlobal.push_back(label + 1);
599 labGlobal.push_back(label + 2);
600 labGlobal.push_back(label + 3);
601 labGlobal.push_back(label + 4);
602 labGlobal.push_back(label + 5);
603 labGlobal.push_back(label + 6);
610 TVector3 detPos = plane->getO();
615 TVector3 pred = detPos + uPos * uDir + vPos * vDir;
619 double xPred = pred[0];
620 double yPred = pred[1];
621 double zPred = pred[2];
624 double tn = tDir.Dot(nDir);
631 for (
int row = 0; row < 3; row++)
632 for (
int col = 0; col < 3; col++)
633 drdm(row, col) -= tDir[row] * nDir[col] / tn;
641 dmdg(0, 0) = 1.; dmdg(0, 4) = -zPred; dmdg(0, 5) = yPred;
642 dmdg(1, 1) = 1.; dmdg(1, 3) = zPred; dmdg(1, 5) = -xPred;
643 dmdg(2, 2) = 1.; dmdg(2, 3) = -yPred; dmdg(2, 4) = xPred;
649 TMatrixD drldrg(3, 3);
651 drldrg(0, 0) = uDir[0]; drldrg(0, 1) = uDir[1]; drldrg(0, 2) = uDir[2];
652 drldrg(1, 0) = vDir[0]; drldrg(1, 1) = vDir[1]; drldrg(1, 2) = vDir[2];
661 TMatrixD drldg(3, 6);
662 drldg = drldrg * (drdm * dmdg);
673 derGlobal(0, 6) = drldg(0, 0); labGlobal.push_back(offset + 1);
674 derGlobal(0, 7) = drldg(0, 1); labGlobal.push_back(offset + 2);
675 derGlobal(0, 8) = drldg(0, 2); labGlobal.push_back(offset + 3);
676 derGlobal(0, 9) = drldg(0, 3); labGlobal.push_back(offset + 4);
677 derGlobal(0, 10) = drldg(0, 4); labGlobal.push_back(offset + 5);
678 derGlobal(0, 11) = drldg(0, 5); labGlobal.push_back(offset + 6);
680 derGlobal(1, 6) = drldg(1, 0);
681 derGlobal(1, 7) = drldg(1, 1);
682 derGlobal(1, 8) = drldg(1, 2);
683 derGlobal(1, 9) = drldg(1, 3);
684 derGlobal(1, 10) = drldg(1, 4);
685 derGlobal(1, 11) = drldg(1, 5);
690 listOfPoints.push_back(measPoint);
691 listOfLayers.push_back((
unsigned int) sensorId);
696 GblPoint dummyPoint(jacPointToPoint);
697 listOfPoints.push_back(dummyPoint);
698 listOfLayers.push_back((
unsigned int) sensorId);
700 skipMeasurement =
false;
702 cout <<
" Dummy point inserted. " << endl;
711 if (ipoint_meas < npoints_meas - 1) {
714 cout <<
" ERROR: Measurement point does not have a fitter info. Track will be skipped." << endl;
720 cout <<
" ERROR: KalmanFitterInfo (with reference state) for measurement does not exist. Track will be skipped." << endl;
737 s2 = scatSMean + scatDeltaS * scatDeltaS / (scatSMean - s1);
738 theta1 = sqrt(scatTheta * scatTheta * scatDeltaS * scatDeltaS / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
739 theta2 = sqrt(scatTheta * scatTheta * (scatSMean - s1) * (scatSMean - s1) / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
749 if (s2 < 1.e-4 || s2 >= trackLen - 1.e-4 || s2 <= 1.e-4) {
750 cout <<
" WARNING: GBL points will be too close. GBLTrajectory construction might fail. Let's try it..." << endl;
759 if (ipoint_meas < npoints_meas - 1) {
770 cout <<
" ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) <<
" stepped back by " << nextStep <<
"cm !!! Track will be skipped." << endl;
785 cout <<
" ERROR: Extrapolation failed. Track will be skipped." << endl;
794 if (ipoint_meas < npoints_meas - 1) {
801 double c1 = trackDir.Dot(plane->getU());
802 double c2 = trackDir.Dot(plane->getV());
803 TMatrixDSym scatCov(2);
804 scatCov(0, 0) = 1. - c2 * c2;
805 scatCov(1, 1) = 1. - c1 * c1;
806 scatCov(0, 1) = c1 * c2;
807 scatCov(1, 0) = c1 * c2;
808 scatCov *= theta1 * theta1 / (1. - c1 * c1 - c2 * c2) / (1. - c1 * c1 - c2 * c2) ;
811 GblPoint& lastPoint = listOfPoints.at(n_gbl_points - 1);
820 TMatrixDSym scatCov(2);
822 scatCov(0, 0) = theta2 * theta2;
823 scatCov(1, 1) = theta2 * theta2;
827 listOfPoints.push_back(scatPoint);
828 listOfLayers.push_back(((
unsigned int) sensorId) + 0.5);
838 if (n_gbl_meas_points > 1) {
844 traj =
new GblTrajectory(listOfPoints, seedLabel, clSeed, fitQoverP);
859 pvalue = TMath::Prob(Chi2, Ndf);
867 fitResHisto->Fill(fitRes);
872 cout <<
" Ref. Track Chi2 : " << trkChi2 << endl;
873 cout <<
" Ref. end momentum : " << trackMomMag <<
" GeV/c ";
875 if (particleCharge < 0.)
876 cout <<
"(electron)";
878 cout <<
"(positron)";
881 cout <<
"------------------ GBL Fit Results --------------------" << endl;
882 cout <<
" Fit q/p parameter : " << ((fitQoverP) ? (
"True") : (
"False")) << endl;
883 cout <<
" Valid trajectory : " << ((traj->
isValid()) ? (
"True") : (
"False")) << endl;
884 cout <<
" Fit result : " << fitRes <<
" (0 for success)" << endl;
885 cout <<
" # GBL meas. points : " << n_gbl_meas_points << endl;
886 cout <<
" # GBL all points : " << n_gbl_points << endl;
887 cout <<
" GBL track NDF : " << Ndf <<
" (-1 for failure)" << endl;
888 cout <<
" GBL track Chi2 : " << Chi2 << endl;
889 cout <<
" GBL track P-value : " << pvalue;
893 cout <<
"-------------------------------------------------------" << endl;
897 bool hittedLayers[12];
898 for (
int hl = 0; hl < 12; hl++) {
899 hittedLayers[hl] =
false;
913 for (
unsigned int p = 0; p < listOfPoints.size(); p++) {
914 unsigned int label = p + 1;
916 TVectorD residuals(2);
917 TVectorD measErrors(2);
918 TVectorD resErrors(2);
919 TVectorD downWeights(2);
921 if (!listOfPoints.at(p).hasMeasurement())
927 unsigned int id = listOfLayers.at(p);
930 unsigned int sensor =
id & 7;
932 unsigned int ladder =
id & 31;
934 unsigned int layer =
id & 7;
936 if (layer == 7 && ladder == 2) {
938 }
else if (layer == 7 && ladder == 3) {
944 hittedLayers[l - 1] =
true;
946 TVectorD localPar(5);
947 TMatrixDSym localCov(5);
950 traj->
getMeasResults(label, numRes, residuals, measErrors, resErrors, downWeights);
955 if (!writeHistoDataForLabel(listOfLayers.at(p), residuals, measErrors, resErrors, downWeights, localPar, localCov))
965 cout <<
" GBL Track written to Millepede II binary file." << endl;
966 cout <<
"-------------------------------------------------------" << endl;
972 chi2OndfHisto->Fill(Chi2 / Ndf);
973 pValueHisto->Fill(TMath::Prob(Chi2, Ndf));