9#include <alignment/modules/MillepedeCollector/MillepedeCollectorModule.h>
11#include <alignment/dataobjects/MilleData.h>
12#include <alignment/GblMultipleScatteringController.h>
13#include <alignment/GlobalDerivatives.h>
14#include <alignment/GlobalLabel.h>
15#include <alignment/GlobalParam.h>
16#include <alignment/GlobalTimeLine.h>
17#include <alignment/Manager.h>
18#include <alignment/reconstruction/AlignableCDCRecoHit.h>
19#include <alignment/reconstruction/AlignablePXDRecoHit.h>
20#include <alignment/reconstruction/AlignableSVDRecoHit.h>
21#include <alignment/reconstruction/AlignableSVDRecoHit2D.h>
22#include <alignment/reconstruction/AlignableBKLMRecoHit.h>
23#include <alignment/reconstruction/AlignableEKLMRecoHit.h>
24#include <analysis/dataobjects/ParticleList.h>
25#include <analysis/utility/ReferenceFrame.h>
26#include <framework/core/FileCatalog.h>
27#include <framework/database/DBObjPtr.h>
28#include <framework/dataobjects/FileMetaData.h>
29#include <framework/datastore/StoreArray.h>
30#include <framework/dbobjects/BeamParameters.h>
31#include <framework/particledb/EvtGenDatabasePDG.h>
32#include <framework/pcore/ProcHandler.h>
33#include <mdst/dbobjects/BeamSpot.h>
34#include <mdst/dataobjects/Track.h>
35#include <tracking/trackFitting/fitter/base/TrackFitter.h>
36#include <tracking/trackFitting/measurementCreator/adder/MeasurementAdder.h>
38#include <genfit/FullMeasurement.h>
39#include <genfit/GblFitter.h>
40#include <genfit/KalmanFitterInfo.h>
41#include <genfit/PlanarMeasurement.h>
42#include <genfit/Track.h>
47#include <TDecompSVD.h>
51using namespace alignment;
65 setDescription(
"Calibration data collector for Millepede Algorithm");
68 addParam(
"tracks",
m_tracks,
"Names of collections of RecoTracks (already fitted with DAF) for calibration", vector<string>({
""}));
69 addParam(
"particles",
m_particles,
"Names of particle list of single particles", vector<string>());
71 "Name of particle list of (mother) particles with daughters for calibration using vertex constraint", vector<string>());
73 "Name of particle list of (mother) particles with daughters for calibration using vertex + IP profile constraint",
76 "Name of particle list of (mother) particles with daughters for calibration using vertex + mass constraint",
79 "Name of particle list of (mother) particles with daughters for calibration using vertex + IP profile + kinematics constraint",
82 "Name of particle list of (mother) particles with daughters for calibration using vertex + mass constraint",
85 "Name of particle list of (mother) particles with daughters for calibration using vertex + IP profile + mass constraint",
89 "Width (in GeV/c/c) to use for invariant mass constraint for 'stable' particles (like K short). Temporary until proper solution is found.",
92 addParam(
"doublePrecision",
m_doublePrecision,
"Use double (=true) or single/float (=false) precision for writing binary files",
94 addParam(
"useGblTree",
m_useGblTree,
"Store GBL trajectories in a tree instead of output to binary files",
96 addParam(
"absFilePaths",
m_absFilePaths,
"Use absolute paths to remember binary files. Only applies if useGblTree=False",
101 "Specify which DB objects are calibrated, like ['BeamSpot', 'CDCTimeWalks'] or leave empty to use all components available.",
104 "For primary vertices / two body decays, beam spot vertex calibration derivatives are added",
107 "For primary two body decays, beam spot kinematics calibration derivatives are added",
115 addParam(
"recalcJacobians",
m_recalcJacobians,
"Up to which external iteration propagation Jacobians should be re-calculated",
118 addParam(
"minPValue",
m_minPValue,
"Minimum p-value to write out a (combined) trajectory. Set <0 to write out all.",
131 addParam(
"hierarchyType",
m_hierarchyType,
"Type of (VXD only now) hierarchy: 0 = None, 1 = Flat, 2 = Half-Shells, 3 = Full",
145 "List of (event, run, exp) with event numbers at which payloads can change for timedep calibration.",
149 "list{ {list{param1, param2, ...}, list{(ev1, run1, exp1), ...}}, ... }.",
154 "dict{ list_name: (mass, width), ... } with custom mass and width to use as external measurement.",
170 B2ERROR(
"You have to specify either arrays of single tracks or particle lists of single single particles or mothers with vertex constrained daughters.");
206 auto gblDataTree =
new TTree(
"GblDataTree",
"GblDataTree");
207 gblDataTree->Branch<std::vector<gbl::GblData>>(
"GblData", &
m_currentGblData, 32000, 99);
208 registerObject<TTree>(
"GblDataTree", gblDataTree);
210 registerObject<TH1I>(
"ndf",
new TH1I(
"ndf",
"ndf", 200, 0, 200));
211 registerObject<TH1F>(
"chi2_per_ndf",
new TH1F(
"chi2_per_ndf",
"chi2 divided by ndf", 200, 0., 50.));
212 registerObject<TH1F>(
"pval",
new TH1F(
"pval",
"pval", 100, 0., 1.));
214 registerObject<TH1F>(
"cdc_hit_fraction",
new TH1F(
"cdc_hit_fraction",
"cdc_hit_fraction", 100, 0., 1.));
215 registerObject<TH1F>(
"evt0",
new TH1F(
"evt0",
"evt0", 400, -100., 100.));
230 std::vector<EventMetaData> events;
232 events.push_back(
EventMetaData(std::get<0>(ev_run_exp), std::get<1>(ev_run_exp), std::get<2>(ev_run_exp)));
237 auto autoEvents = Belle2::alignment::timeline::setupTimedepGlobalLabels(
m_timedepConfig);
244 B2ERROR(
"Cannot set both, event list and timedep config.");
260 auto mille = getObjectPtr<MilleData>(
"mille");
261 if (!mille->isOpen())
265 std::shared_ptr<genfit::GblFitter> gbl(
new genfit::GblFitter());
267 double lostWeight = -1.;
276 for (
auto& recoTrack : recoTracks) {
282 if (!track.hasFitStatus())
284 genfit::GblFitStatus* fs =
dynamic_cast<genfit::GblFitStatus*
>(track.getFitStatus());
288 if (!fs->isFittedWithReferenceTrack())
292 GblTrajectory trajectory(gbl->collectGblPoints(&track, track.getCardinalRep()), fs->hasCurvature());
294 trajectory.fit(chi2, ndf, lostWeight);
295 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
296 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
297 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
300 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
314 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
316 auto gblfs =
dynamic_cast<genfit::GblFitStatus*
>(track->getFitStatus());
318 gbl::GblTrajectory trajectory(gbl->collectGblPoints(track, track->getCardinalRep()), gblfs->hasCurvature());
320 trajectory.fit(chi2, ndf, lostWeight);
321 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
322 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
323 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
326 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
340 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
341 auto mother = list->getParticle(iParticle);
342 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
345 daughters.push_back({
346 gbl->collectGblPoints(track, track->getCardinalRep()),
350 if (daughters.size() > 1) {
351 gbl::GblTrajectory combined(daughters);
353 combined.fit(chi2, ndf, lostWeight);
354 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
355 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
356 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
359 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
365 B2RESULT(
"Vertex-constrained fit NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
376 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
377 auto mother = list->getParticle(iParticle);
378 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
380 TMatrixD extProjection(5, 3);
381 TMatrixD locProjection(3, 5);
391 daughters.push_back({
392 gbl->collectGblPoints(track, track->getCardinalRep()),
397 if (daughters.size() > 1) {
400 TMatrixDSym vertexCov(get<TMatrixDSym>(beam));
401 TMatrixDSym vertexPrec(get<TMatrixDSym>(beam).Invert());
404 TVectorD extMeasurements(3);
405 extMeasurements[0] = vertexResidual[0];
406 extMeasurements[1] = vertexResidual[1];
407 extMeasurements[2] = vertexResidual[2];
409 TMatrixD extDeriv(3, 3);
417 TMatrixD derivatives(3, 3);
419 derivatives(0, 0) = 1.;
420 derivatives(1, 1) = 1.;
421 derivatives(2, 2) = 1.;
423 std::vector<int> labels;
424 GlobalLabel label = GlobalLabel::construct<BeamSpot>(0, 0);
425 labels.push_back(label.setParameterId(1));
426 labels.push_back(label.setParameterId(2));
427 labels.push_back(label.setParameterId(3));
434 std::vector<int> lab(globals); TMatrixD der(globals);
460 TMatrixD dLocal_dExt = extProjection;
461 TMatrixD dExt_dLocal = locProjection;
463 TVectorD locRes = dLocal_dExt * extMeasurements;
465 TMatrixD locCov = dLocal_dExt * vertexCov * dExt_dLocal;
467 TMatrixD locPrec = locCov.GetSub(3, 4, 3, 4).Invert();
468 TMatrixDSym locPrec2D(2); locPrec2D.Zero();
469 for (
int i = 0; i < 2; ++i)
470 for (
int j = 0; j < 2; ++j)
471 locPrec2D(i, j) = locPrec(i, j);
476 TVectorD locRes2D = locRes.GetSub(3, 4);
477 TMatrixD locDerivs2D = (extProjection * der).GetSub(3, 4, 0, 2);
481 daughters[0].first[0].addMeasurement(locRes2D, locPrec2D);
483 daughters[0].first[0].addGlobals(lab, locDerivs2D);
486 gbl::GblTrajectory combined(daughters);
490 combined.fit(chi2, ndf, lostWeight);
491 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
492 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
493 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
496 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
500 B2RESULT(
"Beam vertex constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
504 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, vertexPrec);
506 combined.fit(chi2, ndf, lostWeight);
507 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
508 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
509 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
512 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
517 B2RESULT(
"Beam vertex constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
529 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
531 auto mother = list->getParticle(iParticle);
533 if (track12.size() != 2) {
534 B2ERROR(
"Did not get 2 fitted tracks. Skipping this mother.");
539 double motherMass = mother->getPDGMass();
540 double motherWidth = pdgdb->GetParticle(mother->getPDGCode())->Width();
545 if (motherWidth == 0.) {
547 B2WARNING(
"Using artificial width for " << pdgdb->GetParticle(mother->getPDGCode())->GetName() <<
" : " << motherWidth <<
" GeV");
551 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
553 daughters.push_back({gbl->collectGblPoints(track12[0], track12[0]->getCardinalRep()), dfdextPlusMinus.first});
554 daughters.push_back({gbl->collectGblPoints(track12[1], track12[1]->getCardinalRep()), dfdextPlusMinus.second});
556 TMatrixDSym massPrec(1); massPrec(0, 0) = 1. / motherWidth / motherWidth;
557 TVectorD massResidual(1); massResidual = - (mother->getMass() - motherMass);
559 TVectorD extMeasurements(1);
560 extMeasurements[0] = massResidual[0];
562 TMatrixD extDeriv(1, 9);
566 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, massPrec);
568 combined.fit(chi2, ndf, lostWeight);
571 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
572 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
573 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
576 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
580 B2RESULT(
"Mass(PDG) + vertex constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
594 double motherMass = beam->getMass();
595 double motherWidth =
sqrt((beam->getCovHER() + beam->getCovLER())(0, 0));
599 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
601 auto mother = list->getParticle(iParticle);
603 if (track12.size() != 2) {
604 B2ERROR(
"Did not get 2 fitted tracks. Skipping this mother.");
609 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
611 daughters.push_back({gbl->collectGblPoints(track12[0], track12[0]->getCardinalRep()), dfdextPlusMinus.first});
612 daughters.push_back({gbl->collectGblPoints(track12[1], track12[1]->getCardinalRep()), dfdextPlusMinus.second});
614 TMatrixDSym massPrec(1); massPrec(0, 0) = 1. / motherWidth / motherWidth;
615 TVectorD massResidual(1); massResidual = - (mother->getMass() - motherMass);
617 TVectorD extMeasurements(1);
618 extMeasurements[0] = massResidual[0];
620 TMatrixD extDeriv(1, 9);
624 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, massPrec);
626 combined.fit(chi2, ndf, lostWeight);
627 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
628 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
629 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
632 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
636 B2RESULT(
"Mass constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
650 double motherMass = beam->getMass();
651 double motherWidth =
sqrt((beam->getCovHER() + beam->getCovLER())(0, 0));
655 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
657 auto mother = list->getParticle(iParticle);
659 if (track12.size() != 2) {
660 B2ERROR(
"Did not get 2 fitted tracks. Skipping this mother.");
665 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
667 daughters.push_back({gbl->collectGblPoints(track12[0], track12[0]->getCardinalRep()), dfdextPlusMinus.first});
668 daughters.push_back({gbl->collectGblPoints(track12[1], track12[1]->getCardinalRep()), dfdextPlusMinus.second});
673 TMatrixDSym massPrec(1); massPrec(0, 0) = 1. / motherWidth / motherWidth;
674 TVectorD massResidual(1); massResidual = - (mother->getMass() - motherMass);
676 TMatrixDSym extPrec(4); extPrec.Zero();
677 extPrec.SetSub(0, 0, vertexPrec);
678 extPrec(3, 3) = massPrec(0, 0);
680 TVectorD extMeasurements(4);
681 extMeasurements[0] = vertexResidual[0];
682 extMeasurements[1] = vertexResidual[1];
683 extMeasurements[2] = vertexResidual[2];
684 extMeasurements[3] = massResidual[0];
686 TMatrixD extDeriv(4, 9);
693 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, extPrec);
695 combined.fit(chi2, ndf, lostWeight);
696 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
697 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
698 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
701 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
707 B2RESULT(
"Mass + vertex constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
713 B2WARNING(
"This should NOT be used for production of calibration constants for the real detector (yet)!");
722 double M = beam->getMass();
723 double E_HER = beam->getHER().E();
724 double E_LER = beam->getLER().E();
726 double pz = beam->getHER().Pz() + beam->getLER().Pz();
727 double E = (beam->getHER() + beam->getLER()).
E();
729 double motherMass = beam->getMass();
730 double motherWidth =
sqrt((E_HER / M) * (E_HER / M) * beam->getCovLER()(0, 0) + (E_LER / M) * (E_LER / M) * beam->getCovHER()(0,
735 for (
unsigned int iParticle = 0; iParticle < list->getListSize(); ++iParticle) {
737 B2WARNING(
"Two body decays with full kinematic constraint not yet correct - need to resolve strange covariance provided by BeamParameters!");
739 auto mother = list->getParticle(iParticle);
742 if (track12.size() != 2) {
743 B2ERROR(
"Did not get exactly 2 fitted tracks. Skipping this mother in list " << listName);
748 std::vector<std::pair<std::vector<gbl::GblPoint>, TMatrixD> > daughters;
750 daughters.push_back({gbl->collectGblPoints(track12[0], track12[0]->getCardinalRep()), dfdextPlusMinus.first});
751 daughters.push_back({gbl->collectGblPoints(track12[1], track12[1]->getCardinalRep()), dfdextPlusMinus.second});
753 TMatrixDSym extCov(7); extCov.Zero();
762 TMatrixD dBoost_dVect(3, 3);
763 dBoost_dVect(0, 0) = 0.; dBoost_dVect(0, 1) = 1. / pz; dBoost_dVect(0, 2) = 0.;
764 dBoost_dVect(1, 0) = 0.; dBoost_dVect(1, 1) = 0.; dBoost_dVect(1, 2) = 1. / pz;
765 dBoost_dVect(2, 0) = pz /
E; dBoost_dVect(2, 1) = 0.; dBoost_dVect(2, 2) = 0.;
767 TMatrixD dVect_dBoost(3, 3);
768 dVect_dBoost(0, 0) = 0.; dVect_dBoost(0, 1) = 0.; dVect_dBoost(0, 2) =
E / pz;
769 dVect_dBoost(1, 0) = pz; dVect_dBoost(1, 1) = 0.; dVect_dBoost(1, 2) = 0.;
770 dVect_dBoost(2, 0) = 0.; dVect_dBoost(2, 1) = pz; dVect_dBoost(2, 2) = 0.;
772 TMatrixD covBoost(3, 3);
773 for (
int i = 0; i < 3; ++i) {
774 for (
int j = i; j < 3; ++j) {
775 covBoost(j, i) = covBoost(i, j) = (beam->getCovHER() + beam->getCovLER())(i, j);
781 if (covBoost(1, 1) == 0.) covBoost(1, 1) = 1.e-4;
782 if (covBoost(2, 2) == 0.) covBoost(2, 2) = 1.e-4;
784 TMatrixD covVect = dBoost_dVect * covBoost * dVect_dBoost;
786 extCov.SetSub(3, 3, covVect);
788 extCov(6, 6) = motherWidth * motherWidth;
789 auto extPrec = extCov; extPrec.Invert();
791 TVectorD extMeasurements(7);
795 extMeasurements[3] = - (
B2Vector3D(mother->getMomentum()) - (beam->getHER().Vect() + beam->getLER().Vect()))[0];
796 extMeasurements[4] = - (
B2Vector3D(mother->getMomentum()) - (beam->getHER().Vect() + beam->getLER().Vect()))[1];
797 extMeasurements[5] = - (
B2Vector3D(mother->getMomentum()) - (beam->getHER().Vect() + beam->getLER().Vect()))[2];
798 extMeasurements[6] = - (mother->getMass() - motherMass);
800 B2INFO(
"mother mass = " << mother->getMass() <<
" and beam mass = " << beam->getMass());
802 TMatrixD extDeriv(7, 9);
816 B2WARNING(
"Primary vertex+kinematics calibration not (yet?) fully implemented!");
817 B2WARNING(
"This code is highly experimental and has (un)known issues!");
820 TMatrixD derivatives(9, 6);
821 std::vector<int> labels;
825 derivatives(0, 0) = 1.;
826 derivatives(1, 1) = 1.;
827 derivatives(2, 2) = 1.;
828 GlobalLabel label = GlobalLabel::construct<BeamSpot>(0, 0);
829 labels.push_back(label.setParameterId(1));
830 labels.push_back(label.setParameterId(2));
831 labels.push_back(label.setParameterId(3));
839 derivatives(3, 3) = mother->getMomentumMagnitude();
840 derivatives(4, 4) = mother->getMomentumMagnitude();
841 derivatives(8, 5) = (beam->getLER().E() + beam->getHER().E()) / beam->getMass();
843 GlobalLabel label = GlobalLabel::construct<BeamSpot>(0, 0);
844 labels.push_back(label.setParameterId(4));
845 labels.push_back(label.setParameterId(5));
846 labels.push_back(label.setParameterId(6));
860 std::vector<int> lab(globals); TMatrixD der(globals);
863 TMatrixD dTwoBody_dExt(9, 7);
864 dTwoBody_dExt.Zero();
866 dTwoBody_dExt(0, 0) = 1.;
867 dTwoBody_dExt(1, 1) = 1.;
868 dTwoBody_dExt(2, 2) = 1.;
870 dTwoBody_dExt(3, 3) = 1.;
871 dTwoBody_dExt(4, 4) = 1.;
872 dTwoBody_dExt(5, 5) = 1.;
874 dTwoBody_dExt(8, 6) = 1.;
876 const TMatrixD dLocal_dExt = dfdextPlusMinus.first * dTwoBody_dExt;
877 TMatrixD dLocal_dExt_T = dLocal_dExt; dLocal_dExt_T.T();
886 TDecompSVD svd(dLocal_dExt_T);
887 TMatrixD dExt_dLocal = svd.Invert().T();
904 for (
int i = 0; i < 7; ++i) {
905 for (
int j = 0; j < 5; ++j) {
906 if (fabs(dExt_dLocal(i, j)) < 1.e-6)
907 dExt_dLocal(i, j) = 0.;
910 const TVectorD locRes = dLocal_dExt * extMeasurements;
911 const TMatrixD locPrec = dLocal_dExt * extPrec * dExt_dLocal;
913 TMatrixDSym locPrecSym(5); locPrecSym.Zero();
914 for (
int i = 0; i < 5; ++i) {
915 for (
int j = i; j < 5; ++j) {
917 locPrecSym(j, i) = locPrecSym(i, j) = (fabs(locPrec(i, j)) > 1.e-6) ? locPrec(i, j) : 0.;
921 daughters[0].first[0].addMeasurement(locRes, locPrecSym);
923 daughters[0].first[0].addGlobals(lab, dfdextPlusMinus.first * der);
931 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, extPrec);
935 combined.fit(chi2, ndf, lostWeight);
936 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
937 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
938 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
941 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
945 B2RESULT(
"Full kinematic-constrained fit (calibration version) results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
951 gbl::GblTrajectory combined(daughters, extDeriv, extMeasurements, extPrec);
955 combined.fit(chi2, ndf, lostWeight);
956 getObjectPtr<TH1I>(
"ndf")->Fill(ndf);
957 getObjectPtr<TH1F>(
"chi2_per_ndf")->Fill(chi2 /
double(ndf));
958 getObjectPtr<TH1F>(
"pval")->Fill(TMath::Prob(chi2, ndf));
961 getObjectPtr<TH1F>(
"evt0")->Fill(evt0);
965 B2RESULT(
"Full kinematic-constrained fit results NDF = " << ndf <<
" Chi2/NDF = " << chi2 /
double(ndf));
978 auto mille = getObjectPtr<MilleData>(
"mille");
989 B2ERROR(
"Cannot register binaries in FileCatalog.");
994 const std::vector<string> parents = {fileMetaData->getLfn()};
995 for (
auto binary : getObjectPtr<MilleData>(
"mille")->getFiles()) {
1008 if (trajectory.isValid())
1014 getObjectPtr<TTree>(
"GblDataTree")->Fill();
1016 getObjectPtr<MilleData>(
"mille")->fill(trajectory);
1044 auto relatedRecoHitInformation =
1049 if (recoHitInformation.getFlag() == RecoHitInformation::c_pruned) {
1050 B2FATAL(
"Found pruned point in RecoTrack. Pruned tracks cannot be used in MillepedeCollector.");
1053 if (recoHitInformation.getTrackingDetector() != RecoHitInformation::c_CDC)
continue;
1059 auto kalmanFitterInfo =
dynamic_cast<genfit::KalmanFitterInfo*
>(trackPoint->getFitterInfo());
1060 if (not kalmanFitterInfo) {
1063 std::vector<double> weights = kalmanFitterInfo->getWeights();
1064 if (weights.size() == 2) {
1065 if (weights.at(0) > weights.at(1))
1066 recoHitInformation.setRightLeftInformation(RecoHitInformation::c_left);
1067 else if (weights.at(0) < weights.at(1))
1068 recoHitInformation.setRightLeftInformation(RecoHitInformation::c_right);
1070 double weightLR = weights.at(0) + weights.at(1);
1072 sumCDCWeights += weightLR - 1.;
1079 getObjectPtr<TH1F>(
"cdc_hit_fraction")->Fill(usedCDCHitFraction);
1084 B2ERROR(
"Error in checking DAF weights from previous fit to resolve hit ambiguity. Why? Failed fit points in DAF? Skip track to be sure.");
1088 std::shared_ptr<genfit::GblFitter> gbl(
new genfit::GblFitter());
1102 genfit::MeasurementFactory<genfit::AbsMeasurement> genfitMeasurementFactory;
1106 genfit::MeasurementProducer <RecoHitInformation::UsedPXDHit, AlignablePXDRecoHit>* PXDProducer =
new genfit::MeasurementProducer
1108 genfitMeasurementFactory.addProducer(Const::PXD, PXDProducer);
1112 genfit::MeasurementProducer <RecoHitInformation::UsedSVDHit, AlignableSVDRecoHit>* SVDProducer =
new genfit::MeasurementProducer
1114 genfitMeasurementFactory.addProducer(Const::SVD, SVDProducer);
1118 genfit::MeasurementProducer <RecoHitInformation::UsedCDCHit, AlignableCDCRecoHit>* CDCProducer =
new genfit::MeasurementProducer
1120 genfitMeasurementFactory.addProducer(Const::CDC, CDCProducer);
1124 genfit::MeasurementProducer <RecoHitInformation::UsedBKLMHit, AlignableBKLMRecoHit>* BKLMProducer =
new genfit::MeasurementProducer
1126 genfitMeasurementFactory.addProducer(Const::BKLM, BKLMProducer);
1130 genfit::MeasurementProducer <RecoHitInformation::UsedEKLMHit, AlignableEKLMRecoHit>* EKLMProducer =
new genfit::MeasurementProducer
1132 genfitMeasurementFactory.addProducer(Const::EKLM, EKLMProducer);
1137 std::vector<std::shared_ptr<PXDBaseMeasurementCreator>> pxdMeasurementCreators = { std::shared_ptr<PXDBaseMeasurementCreator>(
new PXDCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1138 std::vector<std::shared_ptr<SVDBaseMeasurementCreator>> svdMeasurementCreators = { std::shared_ptr<SVDBaseMeasurementCreator>(
new SVDCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1141 std::vector<std::shared_ptr<CDCBaseMeasurementCreator>> cdcMeasurementCreators = { std::shared_ptr<CDCBaseMeasurementCreator>(
new CDCCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1142 std::vector<std::shared_ptr<BKLMBaseMeasurementCreator>> bklmMeasurementCreators = { std::shared_ptr<BKLMBaseMeasurementCreator>(
new BKLMCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1143 std::vector<std::shared_ptr<EKLMBaseMeasurementCreator>> eklmMeasurementCreators = { std::shared_ptr<EKLMBaseMeasurementCreator>(
new EKLMCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1146 std::vector<std::shared_ptr<BaseMeasurementCreator>> additionalMeasurementCreators = {};
1147 factory.
resetMeasurementCreators(pxdMeasurementCreators, svdMeasurementCreators, cdcMeasurementCreators, bklmMeasurementCreators,
1148 eklmMeasurementCreators, additionalMeasurementCreators);
1155 currentPdgCode = particle->getPDGCode();
1158 gfTrack.setCardinalRep(gfTrack.getIdForRep(trackRep));
1161 B2Vector3D vertexPos = particle->getVertex();
1162 B2Vector3D vertexMom = particle->getMomentum();
1163 gfTrack.setStateSeed(vertexPos, vertexMom);
1165 genfit::StateOnPlane vertexSOP(gfTrack.getCardinalRep());
1166 B2Vector3D vertexRPhiDir(vertexPos[0], vertexPos[1], 0);
1171 genfit::SharedPlanePtr vertexPlane(
new genfit::DetPlane(vertexPos, vertexMom));
1173 vertexSOP.setPlane(vertexPlane);
1174 vertexSOP.setPosMom(vertexPos, vertexMom);
1175 TMatrixDSym vertexCov(5);
1176 vertexCov.UnitMatrix();
1180 genfit::MeasuredStateOnPlane mop(vertexSOP, vertexCov);
1181 genfit::FullMeasurement* vertex =
new genfit::FullMeasurement(mop, Const::IR);
1182 gfTrack.insertMeasurement(vertex, 0);
1186 for (
unsigned int i = 0; i < gfTrack.getNumPoints() - 1; ++i) {
1189 genfit::PlanarMeasurement* planarMeas1 =
dynamic_cast<genfit::PlanarMeasurement*
>(gfTrack.getPointWithMeasurement(
1190 i)->getRawMeasurement(0));
1191 genfit::PlanarMeasurement* planarMeas2 =
dynamic_cast<genfit::PlanarMeasurement*
>(gfTrack.getPointWithMeasurement(
1192 i + 1)->getRawMeasurement(0));
1194 if (planarMeas1 != NULL && planarMeas2 != NULL &&
1195 planarMeas1->getDetId() == planarMeas2->getDetId() &&
1196 planarMeas1->getPlaneId() != -1 &&
1197 planarMeas1->getPlaneId() == planarMeas2->getPlaneId()) {
1204 if (hit1->
isU() && !hit2->
isU()) {
1207 }
else if (!hit1->
isU() && hit2->
isU()) {
1215 gfTrack.insertMeasurement(hit, i);
1217 gfTrack.deletePoint(i + 1);
1218 gfTrack.deletePoint(i + 1);
1222 }
catch (std::exception& e) {
1224 B2ERROR(
"SVD Cluster combination failed. This is symptomatic of pruned tracks. MillepedeCollector cannot process pruned tracks.");
1229 gbl->processTrackWithRep(&gfTrack, gfTrack.getCardinalRep(),
true);
1230 }
catch (genfit::Exception& e) {
1234 B2ERROR(
"GBL fit failed.");
1243 std::vector< genfit::Track* > tracks;
1244 for (
auto particle : particles) {
1245 auto belle2Track = particle->getTrack();
1247 B2WARNING(
"No Belle2::Track for particle (particle->X");
1256 auto recoTrack = belle2Track->getRelatedTo<
RecoTrack>();
1259 B2WARNING(
"No related RecoTrack for Belle2::Track (particle->Track->X)");
1264 if (!
fitRecoTrack(*recoTrack, (addVertexPoint) ? particle :
nullptr))
1269 if (!track.hasFitStatus()) {
1270 B2WARNING(
"Track has no fit status");
1273 genfit::GblFitStatus* fs =
dynamic_cast<genfit::GblFitStatus*
>(track.getFitStatus());
1275 B2WARNING(
"Track FitStatus is not GblFitStatus.");
1278 if (!fs->isFittedWithReferenceTrack()) {
1279 B2WARNING(
"Track is not fitted with reference track.");
1283 tracks.push_back(&track);
1292 std::vector<TMatrixD> result;
1294 double px = mother.
getPx();
1295 double py = mother.
getPy();
1296 double pz = mother.
getPz();
1297 double pt =
sqrt(px * px + py * py);
1299 double M = motherMass;
1303 || m != mother.
getDaughter(1)->
getPDGMass()) B2FATAL(
"Only two same-mass daughters (V0->f+f- decays) allowed.");
1306 TMatrixD mother2lab(3, 3);
1307 mother2lab(0, 0) = px * pz / pt / p; mother2lab(0, 1) = - py / pt; mother2lab(0, 2) = px / p;
1308 mother2lab(1, 0) = py * pz / pt / p; mother2lab(1, 1) = px / pt; mother2lab(1, 2) = py / p;
1309 mother2lab(2, 0) = - pt / p; mother2lab(2, 1) = 0; mother2lab(2, 2) = pz / p;
1310 ROOT::Math::Rotation3D lab2mother;
1311 lab2mother.SetRotationMatrix(mother2lab); lab2mother.Invert();
1319 auto mom1 = lab2mother * boostedFrame.
getMomentum(fourVector1).Vect();
1320 auto mom2 = lab2mother * boostedFrame.
getMomentum(fourVector2).Vect();
1323 auto avgMom = 0.5 * (mom1 - mom2);
1324 if (avgMom.Z() < 0.) {
1330 double theta = atan2(avgMom.rho(), avgMom.Z());
1331 double phi = atan2(avgMom.Y(), avgMom.X());
1332 if (phi < 0.) phi += 2. * TMath::Pi();
1334 double alpha = M / 2. / m;
1335 double c1 = m *
sqrt(alpha * alpha - 1.);
1336 double c2 = 0.5 *
sqrt((alpha * alpha - 1.) / alpha / alpha * (p * p + M * M));
1338 double p3 = p * p * p;
1339 double pt3 = pt * pt * pt;
1345 TMatrixD
R = mother2lab;
1346 B2Vector3D P(sign * c1 * sin(theta) * cos(phi),
1347 sign * c1 * sin(theta) * sin(phi),
1348 p / 2. + sign * c2 * cos(theta));
1350 TMatrixD dRdpx(3, 3);
1351 dRdpx(0, 0) = - pz * (pow(px, 4.) - pow(py, 4.) - py * py * pz * pz) / pt3 / p3;
1352 dRdpx(0, 1) = px * py / pt3;
1353 dRdpx(0, 2) = (py * py + pz * pz) / p3;
1355 dRdpx(1, 0) = - px * py * pz * (2. * px * px + 2. * py * py + pz * pz) / pt3 / p3;
1356 dRdpx(1, 1) = - py * py / pt3;
1357 dRdpx(1, 2) = px * py / p3;
1359 dRdpx(2, 0) = - px * pz * pz / pt / p3;
1361 dRdpx(2, 2) = - px * pz / p3;
1363 TMatrixD dRdpy(3, 3);
1364 dRdpy(0, 0) = - px * py * pz * (2. * px * px + 2. * py * py + pz * pz) / pt3 / p3;
1365 dRdpy(0, 1) = - px * px / pt3;
1366 dRdpy(0, 2) = px * pz / p3;
1368 dRdpy(1, 0) = - pz * (- pow(px, 4.) - px * px * pz * pz + pow(py, 4.)) / pt3 / p3;
1369 dRdpy(1, 1) = px * py / pt3;
1370 dRdpy(1, 2) = (px * px + pz * pz) / p3;
1372 dRdpy(2, 0) = - py * pz * pz / pt / p3;
1374 dRdpy(2, 2) = - py * pz / p3;
1376 TMatrixD dRdpz(3, 3);
1377 dRdpz(0, 0) = px * pt / p3;
1379 dRdpz(0, 2) = - px * pz / p3;
1381 dRdpz(1, 0) = py * pt / p3;
1383 dRdpz(1, 2) = py * pz / p3;
1385 dRdpz(2, 0) = pz * pt / p3;
1387 dRdpz(2, 2) = (px * px + py * py) / p3;
1389 auto K = 1. / 2. / p + sign * cos(theta) * m * m * (M * M / 4. / m / m - 1.) / M / M /
sqrt(m * m * (M * M / 4. / m / m - 1.) *
1390 (M * M + p * p) / M / M);
1397 sign * c1 * cos(theta) * sin(phi),
1398 sign * c2 * (- sin(theta)));
1402 sign * c1 * sin(theta) * cos(phi),
1405 double dc1dM = m * M / (2. *
sqrt(M * M - 4. * m * m));
1406 double dc2dM = M * (4. * m * m * p * p + pow(M, 4)) / (2 * M * M * M *
sqrt((M * M - 4. * m * m) * (p * p + M * M)));
1409 sign * sin(theta) * sin(phi) * dc1dM,
1410 sign * cos(theta) * dc2dM);
1412 TMatrixD dpdz(3, 6);
1413 dpdz(0, 0) = dpdpx(0); dpdz(0, 1) = dpdpy(0); dpdz(0, 2) = dpdpz(0); dpdz(0, 3) = dpdtheta(0); dpdz(0, 4) = dpdphi(0);
1414 dpdz(0, 5) = dpdM(0);
1415 dpdz(1, 0) = dpdpx(1); dpdz(1, 1) = dpdpy(1); dpdz(1, 2) = dpdpz(1); dpdz(1, 3) = dpdtheta(1); dpdz(1, 4) = dpdphi(1);
1416 dpdz(1, 5) = dpdM(1);
1417 dpdz(2, 0) = dpdpx(2); dpdz(2, 1) = dpdpy(2); dpdz(2, 2) = dpdpz(2); dpdz(2, 3) = dpdtheta(2); dpdz(2, 4) = dpdphi(2);
1418 dpdz(2, 5) = dpdM(2);
1422 TMatrixD dfdvz(5, 9);
1423 dfdvz.SetSub(0, 0, dqdv);
1424 dfdvz.SetSub(0, 3, dqdp * dpdz);
1426 result.push_back(dfdvz);
1432 return {result[0], result[1]};
1438 const B2Vector3D& U(state.getPlane()->getU());
1439 const B2Vector3D& V(state.getPlane()->getV());
1440 const B2Vector3D& O(state.getPlane()->getO());
1441 const B2Vector3D& W(state.getPlane()->getNormal());
1443 const double* state5 = state.getState().GetMatrixArray();
1447 const TVectorD& auxInfo = state.getAuxInfo();
1448 if (auxInfo.GetNrows() == 2
1449 || auxInfo.GetNrows() == 1)
1450 spu = state.getAuxInfo()(0);
1454 state7[0] = O.
X() + state5[3] * U.
X() + state5[4] * V.
X();
1455 state7[1] = O.
Y() + state5[3] * U.
Y() + state5[4] * V.
Y();
1456 state7[2] = O.
Z() + state5[3] * U.
Z() + state5[4] * V.
Z();
1458 state7[3] = spu * (W.X() + state5[1] * U.
X() + state5[2] * V.
X());
1459 state7[4] = spu * (W.Y() + state5[1] * U.
Y() + state5[2] * V.
Y());
1460 state7[5] = spu * (W.Z() + state5[1] * U.
Z() + state5[2] * V.
Z());
1463 double norm = 1. /
sqrt(state7[3] * state7[3] + state7[4] * state7[4] + state7[5] * state7[5]);
1464 for (
unsigned int i = 3; i < 6; ++i) state7[i] *= norm;
1466 state7[6] = state5[0];
1468 const double AtU = state7[3] * U.
X() + state7[4] * U.
Y() + state7[5] * U.
Z();
1469 const double AtV = state7[3] * V.
X() + state7[4] * V.
Y() + state7[5] * V.
Z();
1470 const double AtW = state7[3] * W.X() + state7[4] * W.Y() + state7[5] * W.Z();
1474 const double qop = state7[6];
1475 const double p = state.getCharge() / qop;
1477 TMatrixD J_Mp_6x5(6, 5);
1481 J_Mp_6x5(0, 3) = U.
X();
1482 J_Mp_6x5(1, 3) = U.
Y();
1483 J_Mp_6x5(2, 3) = U.
Z();
1485 J_Mp_6x5(0, 4) = V.
X();
1486 J_Mp_6x5(1, 4) = V.
Y();
1487 J_Mp_6x5(2, 4) = V.
Z();
1490 double fact = (-1.) * qop / p;
1491 J_Mp_6x5(3, 0) = fact * state7[3];
1492 J_Mp_6x5(4, 0) = fact * state7[4];
1493 J_Mp_6x5(5, 0) = fact * state7[5];
1495 fact = 1. / (p * AtW * AtW);
1496 J_Mp_6x5(3, 1) = fact * (U.
X() * AtW - W.X() * AtU);
1497 J_Mp_6x5(4, 1) = fact * (U.
Y() * AtW - W.Y() * AtU);
1498 J_Mp_6x5(5, 1) = fact * (U.
Z() * AtW - W.Z() * AtU);
1500 J_Mp_6x5(3, 2) = fact * (V.
X() * AtW - W.X() * AtV);
1501 J_Mp_6x5(4, 2) = fact * (V.
Y() * AtW - W.Y() * AtV);
1502 J_Mp_6x5(5, 2) = fact * (V.
Z() * AtW - W.Z() * AtV);
1504 return J_Mp_6x5.T();
1511 const B2Vector3D& U(state.getPlane()->getU());
1512 const B2Vector3D& V(state.getPlane()->getV());
1513 const B2Vector3D& W(state.getPlane()->getNormal());
1515 const TVectorD& state5(state.getState());
1518 const TVectorD& auxInfo = state.getAuxInfo();
1519 if (auxInfo.GetNrows() == 2
1520 || auxInfo.GetNrows() == 1)
1521 spu = state.getAuxInfo()(0);
1524 pTilde[0] = spu * (W.X() + state5(1) * U.
X() + state5(2) * V.
X());
1525 pTilde[1] = spu * (W.Y() + state5(1) * U.
Y() + state5(2) * V.
Y());
1526 pTilde[2] = spu * (W.Z() + state5(1) * U.
Z() + state5(2) * V.
Z());
1528 const double pTildeMag =
sqrt(pTilde[0] * pTilde[0] + pTilde[1] * pTilde[1] + pTilde[2] * pTilde[2]);
1529 const double pTildeMag2 = pTildeMag * pTildeMag;
1531 const double utpTildeOverpTildeMag2 = (U.
X() * pTilde[0] + U.
Y() * pTilde[1] + U.
Z() * pTilde[2]) / pTildeMag2;
1532 const double vtpTildeOverpTildeMag2 = (V.
X() * pTilde[0] + V.
Y() * pTilde[1] + V.
Z() * pTilde[2]) / pTildeMag2;
1536 const double qop = state5(0);
1537 const double p = state.getCharge() / qop;
1539 TMatrixD J_pM_5x6(5, 6);
1543 double fact = -1. * p / (pTildeMag * qop);
1544 J_pM_5x6(0, 3) = fact * pTilde[0];
1545 J_pM_5x6(0, 4) = fact * pTilde[1];
1546 J_pM_5x6(0, 5) = fact * pTilde[2];
1548 fact = p * spu / pTildeMag;
1549 J_pM_5x6(1, 3) = fact * (U.
X() - pTilde[0] * utpTildeOverpTildeMag2);
1550 J_pM_5x6(1, 4) = fact * (U.
Y() - pTilde[1] * utpTildeOverpTildeMag2);
1551 J_pM_5x6(1, 5) = fact * (U.
Z() - pTilde[2] * utpTildeOverpTildeMag2);
1553 J_pM_5x6(2, 3) = fact * (V.
X() - pTilde[0] * vtpTildeOverpTildeMag2);
1554 J_pM_5x6(2, 4) = fact * (V.
Y() - pTilde[1] * vtpTildeOverpTildeMag2);
1555 J_pM_5x6(2, 5) = fact * (V.
Z() - pTilde[2] * vtpTildeOverpTildeMag2);
1557 J_pM_5x6(3, 0) = U.
X();
1558 J_pM_5x6(3, 1) = U.
Y();
1559 J_pM_5x6(3, 2) = U.
Z();
1561 J_pM_5x6(4, 0) = V.
X();
1562 J_pM_5x6(4, 1) = V.
Y();
1563 J_pM_5x6(4, 2) = V.
Z();
1565 return J_pM_5x6.T();
1572 return {beam->getIPPosition(), beam->getSizeCovMatrix()};
1579 mass = std::get<0>(massWidth);
1580 width = std::get<1>(massWidth);
This class is used to transfer CDC information to the track fit and Millepede.
static bool s_enableWireSaggingGlobalDerivative
Static enabling(true) or disabling(false) addition of global derivative for wire sagging coefficient ...
static bool s_enableWireByWireAlignmentGlobalDerivatives
Static enabling(true) or disabling(false) addition of global derivatives for wire-by-wire alignment.
static bool s_enableTrackT0LocalDerivative
Static enabling(true) or disabling(false) addition of local derivative for track T0.
This class is used to transfer PXD information to the track fit.
This class is used to transfer SVD information to the track fit.
This class is used to transfer SVD information to the track fit.
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
Calibration collector module base class.
static const ChargedStable muon
muon particle
Class for accessing objects in the database.
@ c_Persistent
Object is available during entire execution time.
static EvtGenDatabasePDG * Instance()
Instance method that loads the EvtGen table.
static FileCatalog & Instance()
Static method to get a reference to the FileCatalog instance.
virtual bool registerFile(const std::string &fileName, FileMetaData &metaData, const std::string &oldLFN="")
Register a file in the (local) file catalog.
TrackSegmentController for use with GblFitter in Belle2.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
Algorithm class to translate the added detector hits (e.g.
void resetMeasurementCreators(const std::vector< std::shared_ptr< PXDBaseMeasurementCreator > > &pxdMeasurementCreators, const std::vector< std::shared_ptr< SVDBaseMeasurementCreator > > &svdMeasurementCreators, const std::vector< std::shared_ptr< CDCBaseMeasurementCreator > > &cdcMeasurementCreators, const std::vector< std::shared_ptr< BKLMBaseMeasurementCreator > > &bklmMeasurementCreators, const std::vector< std::shared_ptr< EKLMBaseMeasurementCreator > > &eklmMeasurementCreators, const std::vector< std::shared_ptr< BaseMeasurementCreator > > &additionalMeasurementCreators)
If you want to use non-default settings for the store arrays, you can create your own instances of th...
bool addMeasurements(RecoTrack &recoTrack) const
After you have filled the internal storage with measurement creators (either by providing your own or...
Mergeable class holding list of so far opened mille binaries and providing the binaries.
bool m_updateCDCWeights
Update L/R weights from previous DAF fit result?
std::vector< std::string > m_twoBodyDecays
Name of particle list with mothers of daughters to be used with vertex + mass constraint in calibrati...
TMatrixD getLocalToGlobalTransform(const genfit::MeasuredStateOnPlane &msop)
Compute the transformation matrix d(x,y,z,px,py,pz)/d(q/p,u',v',u,v) from state at first track point ...
std::vector< std::string > m_tracks
Names of arrays with single RecoTracks fitted by GBL.
MillepedeCollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
StoreObjPtr< EventT0 > m_eventT0
Optional input for EventT0.
std::vector< std::string > m_components
Whether to use VXD alignment hierarchy.
double m_minCDCHitWeight
Minimum CDC hit weight.
std::vector< std::string > m_primaryMassTwoBodyDecays
Name of particle list with mothers of daughters to be used with vertex + IP profile + mass constraint...
double m_minPValue
Minimum p.value for output.
std::string getUniqueMilleName()
Make a name for mille binary (encodes module name + starting exp, run and event + process id)
std::vector< std::tuple< int, int, int > > m_eventNumbers
List of event meta data entries at which payloads can change for timedep calibration.
bool m_absFilePaths
Use absolute path to locate binary files in MilleData.
std::vector< std::string > m_vertices
Name of particle list with mothers of daughters to be used with vertex constraint in calibration.
bool m_fitTrackT0
Add local parameter for track T0 fit in GBL (local derivative)
std::vector< genfit::Track * > getParticlesTracks(std::vector< Particle * > particles, bool addVertexPoint=true)
Get all useable tracks for particles.
std::vector< gbl::GblData > m_currentGblData
Current vector of GBL data from trajectory to be stored in a tree.
bool fitRecoTrack(RecoTrack &recoTrack, Particle *particle=nullptr)
Fit given RecoTrack with GBL.
bool m_enableWireSagging
Enable global derivatives for wire sagging.
TMatrixD getGlobalToLocalTransform(const genfit::MeasuredStateOnPlane &msop)
Compute the transformation matrix d(q/p,u',v',u,v)/d(x,y,z,px,py,pz) from state at first track point ...
std::tuple< B2Vector3D, TMatrixDSym > getPrimaryVertexAndCov() const
Get the primary vertex position estimation and its size from BeamSpot.
std::map< std::string, std::tuple< double, double > > m_customMassConfig
Map of list_name -> (mass, width) for custom mass and width setting.
int m_recalcJacobians
Up to which external iteration propagation Jacobians should be re-calculated.
bool m_useGblTree
Whether to use TTree to accumulate GBL data instead of binary files.
void storeTrajectory(gbl::GblTrajectory &trajectory)
Write down a GBL trajectory (to TTree or binary file)
bool m_doublePrecision
Use double (instead of single/float) precision for binary files.
virtual void collect() override
Data collection.
StoreObjPtr< EventMetaData > m_evtMetaData
Required object pointer to EventMetaData.
std::pair< TMatrixD, TMatrixD > getTwoBodyToLocalTransform(Particle &mother, double motherMass)
Compute the transformation matrices d(q/p,u'v',u,v)/d(vx,vy,vz,px,py,pz,theta,phi,...
bool m_enablePXDHierarchy
enable PXD hierarchy
virtual void closeRun() override
Only for closing mille binaries after each run.
bool m_calibrateKinematics
Add derivatives for beam spot kinematics calibration for primary vertices.
double m_minUsedCDCHitFraction
Minimum CDC used hit fraction.
void updateMassWidthIfSet(std::string listName, double &mass, double &width)
Update mass and width of the particle (mother in list) with user custom-defined values.
virtual void prepare() override
Prepration.
bool m_enableSVDHierarchy
enable SVD hierarchy
std::string m_internalIterations
String defining internal GBL iterations for outlier down-weighting.
std::vector< std::tuple< std::vector< int >, std::vector< std::tuple< int, int, int > > > > m_timedepConfig
Config for time dependence: list( tuple( list( param1, param2, ... ), list( (ev, run,...
std::vector< std::string > m_particles
Names of particle list with single particles.
virtual void finish() override
Register mille binaries in file catalog.
std::vector< std::string > m_primaryVertices
Name of particle list with mothers of daughters to be used with vertex + IP profile (+ optional calib...
int m_externalIterations
Number of external iterations of GBL fitter.
int m_hierarchyType
Type of alignment hierarchy (for VXD only for now): 0 = None, 1 = Flat (only constraints,...
bool m_enableWireByWireAlignment
Enable global derivatives for wire-by-wire alignment.
double m_stableParticleWidth
Width (in GeV/c/c) to use for invariant mass constraint for 'stable' particles (like K short).
std::vector< std::string > m_primaryTwoBodyDecays
Name of particle list with mothers of daughters to be used with vertex + IP profile (+ optional calib...
std::vector< std::string > m_primaryMassVertexTwoBodyDecays
Name of particle list with mothers of daughters to be used with vertex + IP profile + mass constraint...
bool m_calibrateVertex
Add derivatives for beam spot vertex calibration for primary vertices.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
const std::string & getName() const
Returns the name of the module.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to store reconstructed particles.
double getPx() const
Returns x component of momentum.
double getPz() const
Returns z component of momentum.
double getPy() const
Returns y component of momentum.
unsigned getNDaughters(void) const
Returns number of daughter particles.
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
double getMomentumMagnitude() const
Returns momentum magnitude.
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
static int EvtProcID()
Return ID of the current process.
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
This is the Reconstruction Event-Data Model Track.
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
const std::string & getStoreArrayNameOfRecoHitInformation() const
Name of the store array of the reco hit information.
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Rest frame of a particle.
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in rest frame System.
bool isU() const
Is the coordinate u or v?
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
bool isValid() const
Check wether the array was registered.
TClonesArray * getPtr() const
Raw access to the underlying TClonesArray.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
static int createCorrectPDGCodeForChargedStable(const Const::ChargedStable &particleType, const RecoTrack &recoTrack)
Helper function to multiply the PDG code of a charged stable with the charge of the reco track (if ne...
static const double GeV
Standard of [energy, momentum, mass].
void writeConstraints(std::string txtFilename)
Write-out complete hierarchy to a text file.
void initialize(const std::vector< std::string > &components={}, const std::vector< EventMetaData > &timeSlices={})
Initialize the manager with given configuration (from MillepedeCollector)
void preCollect(const EventMetaData &emd)
Notice manager of a comming event (from MillepedeCollector)
static GlobalCalibrationManager & getInstance()
Get instance of the Manager auto& gcm = GlobalCalibrationManager::getInstance();.
Class for easier manipulation with global derivatives (and their labels)
static bool s_enablePXD
Enable PXD in hierarchy?
static bool s_enableSVD
Enable SVD in hierarchy?
static E_VXDHierarchyType s_hierarchyType
What type of hierarchy to use for VXD?
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double sqrt(double a)
sqrt for double
CoordinateMeasurementCreator< RecoHitInformation::UsedSVDHit, Const::SVD > SVDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the SVD.
CoordinateMeasurementCreator< RecoHitInformation::UsedPXDHit, Const::PXD > PXDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the PXD.
CoordinateMeasurementCreator< RecoHitInformation::UsedBKLMHit, Const::BKLM > BKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the BKLM.
CoordinateMeasurementCreator< RecoHitInformation::UsedCDCHit, Const::CDC > CDCCoordinateMeasurementCreator
Needed for templating.
CoordinateMeasurementCreator< RecoHitInformation::UsedEKLMHit, Const::EKLM > EKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the EKLM.
Abstract base class for different kinds of events.