326{
327
328
329 bool skipMeasurement = false;
330
331 double trkChi2 = 0.;
332
333
334 bool fitQoverP = true;
335
337 if (!(Bfield > 0.))
338 fitQoverP = false;
339
340
342
344
346
347
348 TVectorD scatResidual(2);
349 scatResidual.Zero();
350
351
353
354 #ifdef DEBUG
356
357 if (resortHits)
358 cout << "WARNING: Hits resorting in GBL interface not supported." << endl;
359
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;
365
366 #endif
367
368 std::vector<GblPoint> listOfPoints;
369
370 std::vector<double> listOfLayers;
371
372
373 unsigned int seedLabel = 0;
374
375
376
377 TMatrixDSym clSeed(dim);
378
379
380 TMatrixD jacPointToPoint(dim, dim);
381 jacPointToPoint.UnitMatrix();
382
383 int n_gbl_points = 0;
384 int n_gbl_meas_points = 0;
385 int Ndf = 0;
386 double Chi2 = 0.;
387 double lostWeight = 0.;
388
389
390 double trackMomMag = 0.;
391
392 double particleCharge = 1.;
393
394 for (int ipoint_meas = 0; ipoint_meas < npoints_meas; ipoint_meas++) {
396
398 cout << " ERROR: Measurement point does not have a fitter info. Track will be skipped." << endl;
399 return;
400 }
401
403 if (!fi) {
404 cout << " ERROR: KalmanFitterInfo (with reference state) for measurement does not exist. Track will be skipped." << endl;
405 return;
406 }
407
410 cout << " ERROR: Fitter info does not contain reference state. Track will be skipped." << endl;
411 return;
412 }
413
415
416 TVectorD state = reference->
getState();
417
418 TVector3 trackDir = rep->
getDir(*reference);
419
420 trackMomMag = rep->
getMomMag(*reference);
421
422 particleCharge = rep->
getCharge(*reference);
423
424 double particleMass = rep->
getMass(*reference);
425
426
427 double trackLen = 0.;
428 double scatTheta = 0.;
429 double scatSMean = 0.;
430 double scatDeltaS = 0.;
431
432 double theta1 = 0.;
433 double theta2 = 0.;
434 double s1 = 0.;
435 double s2 = 0.;
436
437 TMatrixDSym noise;
438 TVectorD deltaState;
439
440 TMatrixD jacMeas2Scat(dim, dim);
441 jacMeas2Scat.UnitMatrix();
442
443
444
445
446
447
448 int sensorId = 0;
450 if (measPlanar) sensorId = measPlanar->
getPlaneId();
451
452
453
454
461
462
463
464 int sensorId2 = -1;
466 if (measPlanar2) sensorId2 = measPlanar->
getPlaneId();
467
468
469
470 if (sensorId != sensorId2) {
471 skipMeasurement = true;
472 cout << " ERROR: Incompatible sensorIDs at measurement point " << ipoint_meas << ". Measurement will be skipped." << endl;
473 }
474
475
478
481
482 raw_measU = raw_meas1;
483 raw_measV = raw_meas2;
486
487 raw_measU = raw_meas2;
488 raw_measV = raw_meas1;
489 } else {
490
491 cout << " ERROR: Incompatible 1D measurements at meas. point " << ipoint_meas << ". Track will be skipped." << endl;
492 return;
493 }
494
495 TVectorD _raw_coor(2);
498
499 TMatrixDSym _raw_cov(2);
500 _raw_cov.Zero();
503
505 } else {
506
508 }
509
511 skipMeasurement = true;
512 #ifdef DEBUG
513 cout << " WARNING: Measurement " << (ipoint_meas + 1) << " is not 2D. Measurement Will be skipped. " << endl;
514 #endif
515 }
516
517
518
519 if (!skipMeasurement) {
520
522
524
525 boost::scoped_ptr<const AbsHMatrix> HitHMatrix(raw_meas->
constructHMatrix(rep));
526
527 TVectorD residual = -1. * (raw_coor - HitHMatrix->Hv(state));
528
529 trkChi2 += residual(0) * residual(0) / raw_cov(0, 0) + residual(1) * residual(1) / raw_cov(1, 1);
530
531
532 GblPoint measPoint(jacPointToPoint);
533
534
535
536 TMatrixD proL2m(2, 2);
537 proL2m.Zero();
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);
542 proL2m.Invert();
543
544
545 measPoint.addMeasurement(proL2m, residual, raw_cov.Invert());
546
547
548
549
550 int label = sensorId * 10;
551
552
553 TMatrixD derGlobal(2, 12);
554
555
556 std::vector<int> labGlobal;
557
558
559 TVector3 tDir = trackDir;
560
561 TVector3 uDir = plane->getU();
562
563 TVector3 vDir = plane->getV();
564
565 TVector3 nDir = plane->getNormal();
566
567
568
569
570
571 TVector3 tLoc = TVector3(uDir.Dot(tDir), vDir.Dot(tDir), nDir.Dot(tDir));
572
573
574 double uSlope = tLoc[0] / tLoc[2];
575
576 double vSlope = tLoc[1] / tLoc[2];
577
578
579 double uPos = raw_coor[0];
580
581 double vPos = raw_coor[1];
582
583
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;
590
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;
597
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);
604
605
606
607
608
609
610 TVector3 detPos = plane->getO();
611
612
613
614
615 TVector3 pred = detPos + uPos * uDir + vPos * vDir;
616
617
618
619 double xPred = pred[0];
620 double yPred = pred[1];
621 double zPred = pred[2];
622
623
624 double tn = tDir.Dot(nDir);
625
626
627
628
629 TMatrixD drdm(3, 3);
630 drdm.UnitMatrix();
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;
634
635
636
637
638
639 TMatrixD dmdg(3, 6);
640 dmdg.Zero();
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;
644
645
646
647
648
649 TMatrixD drldrg(3, 3);
650 drldrg.Zero();
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];
653
654
655
656
657
658
659
660
661 TMatrixD drldg(3, 6);
662 drldg = drldrg * (drdm * dmdg);
663
664
665
666
667
668
669
671
672
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);
679
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);
686
687
688
689 measPoint.addGlobals(labGlobal, derGlobal);
690 listOfPoints.push_back(measPoint);
691 listOfLayers.push_back((unsigned int) sensorId);
692 n_gbl_points++;
693 n_gbl_meas_points++;
694 } else {
695
696 GblPoint dummyPoint(jacPointToPoint);
697 listOfPoints.push_back(dummyPoint);
698 listOfLayers.push_back((unsigned int) sensorId);
699 n_gbl_points++;
700 skipMeasurement = false;
701 #ifdef DEBUG
702 cout << " Dummy point inserted. " << endl;
703 #endif
704 }
705
706
707
708 try {
709
710
711 if (ipoint_meas < npoints_meas - 1) {
712
714 cout << " ERROR: Measurement point does not have a fitter info. Track will be skipped." << endl;
715 return;
716 }
717
719 if (!fi_i_plus_1) {
720 cout << " ERROR: KalmanFitterInfo (with reference state) for measurement does not exist. Track will be skipped." << endl;
721 return;
722 }
724
727 scatTheta,
728 scatSMean,
729 scatDeltaS,
730 trackMomMag,
731 particleMass,
732 particleCharge,
734
735
736 s1 = 0.;
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)));
740
742 theta1 = scatTheta;
743 theta2 = 0;
745 theta1 = 0.;
746 theta2 = 0.;
747 }
748
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;
751 }
752
753 }
754
755 delete reference;
757
758
759 if (ipoint_meas < npoints_meas - 1) {
761
762
763
764
767
769 if (0. > nextStep) {
770 cout << " ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) << " stepped back by " << nextStep << "cm !!! Track will be skipped." << endl;
771 return;
772 }
774
775 } else {
776
778
779
781
782 }
783 }
784 } catch (...) {
785 cout << " ERROR: Extrapolation failed. Track will be skipped." << endl;
786 return;
787 }
788
789
790
791
792
793
794 if (ipoint_meas < npoints_meas - 1) {
795
797
798
799
800
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) ;
809
810
811 GblPoint& lastPoint = listOfPoints.at(n_gbl_points - 1);
813
814 }
815
817
818
819
820 TMatrixDSym scatCov(2);
821 scatCov.Zero();
822 scatCov(0, 0) = theta2 * theta2;
823 scatCov(1, 1) = theta2 * theta2;
824
826 scatPoint.addScatterer(scatResidual, scatCov.Invert());
827 listOfPoints.push_back(scatPoint);
828 listOfLayers.push_back(((unsigned int) sensorId) + 0.5);
829 n_gbl_points++;
830 }
831
832
833 }
834
835 delete reference;
836 }
837
838 if (n_gbl_meas_points > 1) {
839 int fitRes = -1;
840 double pvalue = 0.;
842 try {
843
844 traj =
new GblTrajectory(listOfPoints, seedLabel, clSeed, fitQoverP);
845
847 if (fitRes != 0) {
848
849
850
851
852
853 }
854 } catch (...) {
855
856 return;
857 }
858
859 pvalue = TMath::Prob(Chi2, Ndf);
860
861
862
863
864
865 #ifdef OUTPUT
866
867 fitResHisto->Fill(fitRes);
868 ndfHisto->Fill(Ndf);
869 #endif
870
871 #ifdef DEBUG
872 cout << " Ref. Track Chi2 : " << trkChi2 << endl;
873 cout << " Ref. end momentum : " << trackMomMag << " GeV/c ";
875 if (particleCharge < 0.)
876 cout << "(electron)";
877 else
878 cout << "(positron)";
879 }
880 cout << endl;
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;
892 cout << endl;
893 cout << "-------------------------------------------------------" << endl;
894 #endif
895
896 #ifdef OUTPUT
897 bool hittedLayers[12];
898 for (int hl = 0; hl < 12; hl++) {
899 hittedLayers[hl] = false;
900 }
901 #endif
902
903
904
905
907
908
911
912
913 for (
unsigned int p = 0;
p < listOfPoints.size();
p++) {
914 unsigned int label =
p + 1;
915 unsigned int numRes;
917 TVectorD measErrors(2);
918 TVectorD resErrors(2);
919 TVectorD downWeights(2);
920
921 if (!listOfPoints.at(p).hasMeasurement())
922 continue;
923
924 #ifdef OUTPUT
925
927 unsigned int id = listOfLayers.at(p);
928
929 id = id >> 5;
930 unsigned int sensor = id & 7;
931 id = id >> 3;
932 unsigned int ladder = id & 31;
933 id = id >> 5;
934 unsigned int layer = id & 7;
935
936 if (layer == 7 && ladder == 2) {
938 } else if (layer == 7 && ladder == 3) {
940 } else {
942 }
943
944 hittedLayers[
l - 1] =
true;
945 #endif
946 TVectorD localPar(5);
947 TMatrixDSym localCov(5);
949
950 traj->
getMeasResults(label, numRes, residuals, measErrors, resErrors, downWeights);
952 return;
953
954 #ifdef OUTPUT
955 if (!writeHistoDataForLabel(listOfLayers.at(p), residuals, measErrors, resErrors, downWeights, localPar, localCov))
956 return;
957 #endif
958
959 }
960
961
964 #ifdef DEBUG
965 cout << " GBL Track written to Millepede II binary file." << endl;
966 cout << "-------------------------------------------------------" << endl;
967 #endif
968 }
969
970 #ifdef OUTPUT
971
972 chi2OndfHisto->Fill(Chi2 / Ndf);
973 pValueHisto->Fill(TMath::Prob(Chi2, Ndf));
974
976
977 if (
978 hittedLayers[0] &&
979 hittedLayers[1] &&
980 hittedLayers[2] &&
981 hittedLayers[3] &&
982 hittedLayers[4] &&
983 hittedLayers[5] &&
984 hittedLayers[6] &&
985 hittedLayers[7] &&
986 hittedLayers[8]
987 ) {
988
990 }
991
992 if (
993 hittedLayers[0] &&
994 hittedLayers[1] &&
995 hittedLayers[2] &&
996 hittedLayers[3] &&
997 hittedLayers[4] &&
998 hittedLayers[5] &&
999 hittedLayers[6] &&
1000 hittedLayers[7] &&
1001 hittedLayers[8] &&
1002 hittedLayers[9] &&
1003 hittedLayers[10] &&
1004 hittedLayers[11]
1005 ) {
1006
1008 }
1009 if (
1010 hittedLayers[3] &&
1011 hittedLayers[4] &&
1012 hittedLayers[5] &&
1013 hittedLayers[6] &&
1014 hittedLayers[7] &&
1015 hittedLayers[8]
1016 ) {
1017
1019 }
1020 if (
1021 hittedLayers[5] &&
1022 hittedLayers[6] &&
1023 hittedLayers[7] &&
1024 hittedLayers[8]
1025 ) {
1026
1028 }
1029 if (
1030 hittedLayers[0] &&
1031 hittedLayers[1] &&
1032 hittedLayers[2] &&
1033
1034 hittedLayers[5] &&
1035 hittedLayers[6] &&
1036 hittedLayers[7] &&
1037 hittedLayers[8] &&
1038 hittedLayers[9] &&
1039 hittedLayers[10] &&
1040 hittedLayers[11]
1041 ) {
1042
1044 }
1045 if (
1046 hittedLayers[0] &&
1047 hittedLayers[1] &&
1048 hittedLayers[2] &&
1049
1050 hittedLayers[5] &&
1051 hittedLayers[6] &&
1052 hittedLayers[7] &&
1053 hittedLayers[8]
1054 ) {
1055
1057 }
1058 if (
1059 hittedLayers[9] &&
1060 hittedLayers[10] &&
1061 hittedLayers[11]
1062 ) {
1063
1065 }
1066 #endif
1067 }
1068
1069
1070 delete traj;
1071 }
1072}
void getScattererFromMatList(double &length, double &theta, double &s, double &ds, const double p, const double mass, const double charge, const std::vector< MatStep > &steps)
Evaluates moments of radiation length distribution from list of material steps and computes parameter...
void addScatterer(const TVectorD &aResiduals, const TVectorD &aPrecision)
Add a (thin) scatterer to a point.
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, std::string optionList="")
Perform fit of trajectory.
unsigned int getMeasResults(unsigned int aLabel, unsigned int &numRes, TVectorD &aResiduals, TVectorD &aMeasErrors, TVectorD &aResErrors, TVectorD &aDownWeights)
Get residuals at point from measurement.
unsigned int getResults(int aSignedLabel, TVectorD &localPar, TMatrixDSym &localCov) const
Get fit results at point.
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
bool isValid() const
Retrieve validity of trajectory.
const SharedPlanePtr & getPlane() const
virtual bool isEqual(const AbsHMatrix &other) const =0
Contains the measurement and covariance in raw detector coordinates.
virtual const AbsHMatrix * constructHMatrix(const AbsTrackRep *) const =0
const TMatrixDSym & getRawHitCov() const
const TVectorD & getRawHitCoords() const
unsigned int getDim() const
virtual double extrapolateToPlane(StateOnPlane &state, const genfit::SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to plane, and returns the extrapolation length and, via reference,...
TVector3 getDir(const StateOnPlane &state) const
Get the direction vector of a state.
virtual std::vector< genfit::MatStep > getSteps() const =0
Get stepsizes and material properties of crossed materials of the last extrapolation.
int getPDG() const
Get the pdg code.
virtual double getCharge(const StateOnPlane &state) const =0
Get the (fitted) charge of a state. This is not always equal the pdg charge (e.g. if the charge sign ...
double getMass(const StateOnPlane &state) const
Get tha particle mass in GeV/c^2.
virtual double getMomMag(const StateOnPlane &state) const =0
get the magnitude of the momentum in GeV.
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation.
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.
virtual double extrapolateBy(StateOnPlane &state, double step, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state by step (cm) and returns the extrapolation length and, via reference,...
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
static FieldManager * getInstance()
Get singleton instance.
AbsHMatrix implementation for one-dimensional MeasurementOnPlane and RKTrackRep parameterization.
AbsHMatrix implementation for one-dimensional MeasurementOnPlane and RKTrackRep parameterization.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
ReferenceStateOnPlane * getReferenceState() const
bool hasReferenceState() const
Measurement class implementing a planar hit geometry (1 or 2D).
StateOnPlane with linearized transport to that ReferenceStateOnPlane from previous and next Reference...
A state with arbitrary dimension defined in a DetPlane.
const TVectorD & getState() const
Object containing AbsMeasurement and AbsFitterInfo objects.
bool hasFitterInfo(const AbsTrackRep *rep) const
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=NULL) const
Get fitterInfo for rep. Per default, use cardinal rep.
unsigned int getNumRawMeasurements() const
AbsMeasurement * getRawMeasurement(int i=0) const
TrackPoint * getPoint(int id) const
unsigned int getNumPoints() const
TrackPoint * getPointWithMeasurement(int id) const
unsigned int getNumPointsWithMeasurement() const
AbsTrackRep * getCardinalRep() const
Get cardinal track representation.
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.