Fit kink with cardinal hypothesis and store it if the fit was successful.
Fit and store kink.
If the corresponding flag is set, try to reassign hits between mother and daughter tracks. If the corresponding flag is set, try to flip and refit daughter track. If the corresponding flag is set, try to combine mother and daughter track and fit the resulting track. If the corresponding flag is set, try to split the track candidate selected by KinkFinderModule.
If the fitterMode requires, tries to reassign hits between daughter and mother tracks. If the fitterMode requires, tries to flip and refit the tracks.
829{
830
831
834
835
836 if (filterFlag >= 7 && filterFlag <= 9) {
837 short recoTrackIndexMother = -1;
838 short recoTrackIndexDaughter = -1;
839 if (!
splitRecoTrack(recoTrackMother, recoTrackIndexMother, recoTrackIndexDaughter))
840 return false;
843 }
844
845
846
847
848
849
850
851 bool refitBadFlag = false;
852 if (filterFlag == 4 || filterFlag == 6) {
853 B2DEBUG(29, "Try to do initial refit of daughter track for filterFlag " << filterFlag);
854
855
856
858
861
862 ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
863
864
865
866 bool blockInnerStereoHits = false;
867 if (filterFlag == 4) blockInnerStereoHits = true;
868
869 bool anotherFitter = false;
870 if (filterFlag == 6) anotherFitter = true;
871
872
874 motherPosLast, timeSeedDaughterRefit,
875 blockInnerStereoHits, anotherFitter);
876
877
878
879
881 if (filterFlag == 4 ||
883 recoTrackDaughter = recoTrackDaughterRefit;
884 B2DEBUG(29, "Initial refit successful");
885 refitBadFlag = true;
886 }
887 }
888
889
891 B2DEBUG(29, "Try to do initial flip and refit of daughter track for filterFlag " << filterFlag);
892
893
894
896
899
900 ROOT::Math::XYZVector momSeedDaughterFlipAndRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromLastHit().getMom());
901
902
904 motherPosLast, momSeedDaughterFlipAndRefit,
905 timeSeedDaughterFlipAndRefit);
906
907
909 recoTrackDaughter = recoTrackDaughterFlipAndRefit;
910 B2DEBUG(29, "Initial flip and refit successful");
911 }
912 }
913
914
916
917
918 unsigned int reassignHitStatus = 0;
919 int finalHitPositionForReassignment = 0;
920 double distanceAtVertex = std::numeric_limits<double>::max();
921
922
923
924
925 bool failedFitFlag = !
vertexFitWithRecoTracks(recoTrackMother, recoTrackDaughter, reassignHitStatus, vertexPos, distanceAtVertex,
927 if (failedFitFlag && (filterFlag != 1 && filterFlag != 3))
928 return false;
929
930
931
932 if (failedFitFlag && filterFlag == 1) {
933 B2DEBUG(29, "Try to do postVertexFit refit of daughter track for filterFlag " << filterFlag);
934
935
936
938
941
942 const ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
943
944
945
946 const bool blockInnerStereoHits = true;
947
948 const bool anotherFitter = false;
949
950
952 motherPosLast, timeSeedDaughterRefit,
953 blockInnerStereoHits, anotherFitter);
954
955
956
958 vertexFitWithRecoTracks(recoTrackMother, recoTrackDaughterRefit, reassignHitStatus, vertexPos, distanceAtVertex,
959 motherPosLast)) {
960 recoTrackDaughter = recoTrackDaughterRefit;
961 B2DEBUG(29, "postVertexFit refit successful");
962 refitBadFlag = true;
963 } else return false;
964 }
965
966
967
968
969
970 if ((filterFlag == 4 || (failedFitFlag && filterFlag == 1)) && (refitBadFlag) && (reassignHitStatus == 0))
971 reassignHitStatus |= 0x1;
972
973
974
977
980
981
982
983
985 (filterFlag == 1 || filterFlag == 4 ||
987 (reassignHitStatus != 0)) {
988 B2DEBUG(29, "Start of the hits reassignment for filterFlag " << filterFlag);
989
990
991 unsigned short countReassignTries = 0;
992
993
994 int finalHitPositionForReassignmentTmp = 0;
995 double distanceAtVertexTmp = std::numeric_limits<double>::max();
996 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
997 RecoTrack* recoTrackMotherRefit = nullptr;
998 RecoTrack* recoTrackDaughterRefit = nullptr;
999 const RecoTrack* recoTrackMotherBuffer = recoTrackMother;
1000 const RecoTrack* recoTrackDaughterBuffer = recoTrackDaughter;
1001
1002
1003 while (reassignHitStatus != 0 && countReassignTries < 3) {
1004 ++countReassignTries;
1005 B2DEBUG(29, "Try number " << countReassignTries);
1006
1007
1008 unsigned short countBadReassignTries = 0;
1009
1010
1011
1012
1013 int hitPositionForReassignment = 0;
1014 if (reassignHitStatus & 0x1) {
1015
1016
1018
1019
1020
1021 if (static_cast<unsigned int>(-hitPositionForReassignment + 5) >
1023 break;
1024
1025 } else if (reassignHitStatus & 0x2) {
1026
1027
1029
1030
1031
1032 if (
static_cast<unsigned int>(hitPositionForReassignment + 5) > recoTrackMotherBuffer->
getNumberOfCDCHits()) {
1033
1034
1037 else
1038 break;
1039
1040 }
1041 }
1042 B2DEBUG(29, "Found hit index, starting from which hits are reassigned: " << hitPositionForReassignment);
1043
1044
1045
1046 while (hitPositionForReassignment != 0) {
1047
1048
1050 recoTrackDaughterBuffer,
1051 true, hitPositionForReassignment);
1053 recoTrackDaughterBuffer,
1054 false, hitPositionForReassignment);
1055
1056
1057
1058
1060 recoTrackMother, recoTrackDaughter)) {
1061 if (hitPositionForReassignment > 0) {
1062 --hitPositionForReassignment;
1063 } else {
1064 ++hitPositionForReassignment;
1065 }
1066 ++countBadReassignTries;
1067
1068 if (countBadReassignTries > 5) hitPositionForReassignment = 0;
1069 } else
1070 break;
1071 B2DEBUG(29, "Refit of the tracks failed, try with smaller hit index: " << hitPositionForReassignment);
1072 }
1073
1074
1075 if (hitPositionForReassignment == 0) {
1076 B2DEBUG(29, "Reassigning of hits and refitting failed");
1077 break;
1078 }
1079
1080
1082 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp))
1083 break;
1084 recoTrackMotherBuffer = recoTrackMotherRefit;
1085 recoTrackDaughterBuffer = recoTrackDaughterRefit;
1086 finalHitPositionForReassignmentTmp += hitPositionForReassignment;
1087
1088
1090 distanceAtVertex = distanceAtVertexTmp;
1091 vertexPos = vertexPosTmp;
1094
1097 finalHitPositionForReassignment = finalHitPositionForReassignmentTmp;
1098 }
1099 }
1100 }
1101
1102
1103
1105 B2DEBUG(29, "Try to do postVertexFit flip and refit of daughter track for filterFlag " << filterFlag);
1106
1107
1108 double distanceAtVertexTmp = std::numeric_limits<double>::max();
1109 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
1110
1111
1114
1115
1116 const ROOT::Math::XYZVector momSeedDaughterFlipAndRefit(stDaughter.getMom());
1117
1118
1120 vertexPos, momSeedDaughterFlipAndRefit,
1121 timeSeedDaughterFlipAndRefit);
1122
1123
1126 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp))
1127 if (distanceAtVertexTmp < distanceAtVertex) {
1128 distanceAtVertex = distanceAtVertexTmp;
1129 vertexPos = vertexPosTmp;
1133
1134 B2DEBUG(29, "postVertexFit flip and refit successful");
1135 }
1136 }
1137
1138
1139
1140 if (filterFlag == 3) {
1141 B2DEBUG(29, "Try to do postVertexFit refit of daughter track for filterFlag " << filterFlag);
1142
1143
1144
1146
1149
1150 const ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
1151
1152
1153 double distanceAtVertexTmp = std::numeric_limits<double>::max();
1154 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
1155
1156
1157
1158 const bool blockInnerStereoHits = false;
1159
1160 const bool anotherFitter = true;
1161
1162
1164 motherPosLast, timeSeedDaughterRefit,
1165 blockInnerStereoHits, anotherFitter);
1166
1167
1170 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp)) {
1171 if ((distanceAtVertexTmp < distanceAtVertex) || failedFitFlag) {
1172 distanceAtVertex = distanceAtVertexTmp;
1173 vertexPos = vertexPosTmp;
1177
1178 B2DEBUG(29, "postVertexFit refit successful");
1179 }
1180 } else if (failedFitFlag) return false;
1181 }
1182
1183 B2DEBUG(29, "Distance between tracks at fitted kink vertex " << distanceAtVertex);
1184 B2DEBUG(29, "Radius of the kink vertex " << vertexPos.Rho());
1185 B2DEBUG(29, "Number of reassigned hits " << finalHitPositionForReassignment);
1186
1187
1188
1189
1190
1191
1192
1193
1194 short filterFlagToStore = 0;
1195 switch (filterFlag) {
1196 case 1:
1197 case 2:
1198 case 4:
1199 case 5:
1200 filterFlagToStore = 1;
1201 break;
1202 case 3:
1203 case 6:
1204 filterFlagToStore = 2;
1205 break;
1206 case 7:
1207 filterFlagToStore = 3;
1208 break;
1209 case 8:
1210 filterFlagToStore = 4;
1211 break;
1212 case 9:
1213 filterFlagToStore = 5;
1214 }
1215
1216
1217
1219 if (filterFlag < 7)
1220 return false;
1221 else
1222 filterFlagToStore += 10;
1223 }
1224
1225
1226 if (vertexPos.Rho() < 14)
1227 return false;
1228
1229
1231 try {
1233 } catch (...) {
1234 B2DEBUG(29, "Could not extrapolate mother track to IP.");
1235 }
1236
1237
1240
1241
1245
1246
1247
1250 filterFlagToStore += combinedFitFlag * 10;
1251 }
1252
1253
1254
1255
1256
1257 if (abs(finalHitPositionForReassignment) < 32) {
1258 if (finalHitPositionForReassignment >= 0)
1259 filterFlagToStore += finalHitPositionForReassignment * 1000;
1260 else {
1261 filterFlagToStore *= -1;
1262 filterFlagToStore += finalHitPositionForReassignment * 1000;
1263 }
1264 } else {
1265 filterFlagToStore += 32 * 1000;
1266 }
1267
1268
1269 m_kinks.appendNew(std::make_pair(trackMother, std::make_pair(tfrMotherIP, tfrMotherVtx)),
1270 std::make_pair(trackDaughter, tfrDaughterVtx),
1271 vertexPos.X(), vertexPos.Y(), vertexPos.Z(), filterFlagToStore);
1272
1273
1274 return true;
1275}
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
static const ChargedStable pion
charged pion particle
static bool refitRecoTrackAfterReassign(RecoTrack *recoTrackMotherRefit, RecoTrack *recoTrackDaughterRefit, const RecoTrack *recoTrackMother, const RecoTrack *recoTrackDaughter)
Try to fit new RecoTracks after hit reassignment.
genfit::MeasuredStateOnPlane m_stMotherBuffer
buffer for the MeasuredStateOnPlane of mother obtained in the vertex fit
bool m_kinkFitterModeCombineAndFit
fitter mode 3rd bit
RecoTrack * m_motherKinkRecoTrackCache
cache for the RecoTrack of mother used to find the best vertex
double m_vertexDistanceCut
cut on the distance at the found vertex.
RecoTrack * copyRecoTrackForRefit(const RecoTrack *recoTrack, const ROOT::Math::XYZVector &momentumSeed, const ROOT::Math::XYZVector &positionSeed, const double &timeSeed, const bool blockInnerStereoHits=false, const bool useAnotherFitter=false)
Refit the daughter track blocking hits if required.
static int findHitPositionForReassignment(const RecoTrack *recoTrack, const ROOT::Math::XYZVector &vertexPos, int direction)
Find hit position closest to the vertex.
TrackFitResult * buildTrackFitResult(const RecoTrack *recoTrack, const genfit::MeasuredStateOnPlane &msop, const double Bz, const Const::ParticleType &trackHypothesis)
Build TrackFitResult of the Kink Track.
RecoTrack * m_daughterKinkRecoTrackCache
cache for the RecoTrack of daughter used to find the best vertex
bool vertexFitWithRecoTracks(const RecoTrack *recoTrackMother, RecoTrack *recoTrackDaughter, unsigned int &reassignHitStatus, ROOT::Math::XYZVector &vertexPos, double &distance, ROOT::Math::XYZVector vertexPosSeed=ROOT::Math::XYZVector(0, 0, 0))
Fit kink vertex using RecoTrack's as inputs.
bool m_kinkFitterModeHitsReassignment
fitter mode 1st bit
bool isRefitImproveFilter6(const RecoTrack *recoTrackDaughterRefit, const ROOT::Math::XYZVector &motherPosLast)
check if the refit of filter 6 daughter tracks improves the distance between mother and daughter
RecoTrack * copyRecoTrackForFlipAndRefit(const RecoTrack *recoTrack, const ROOT::Math::XYZVector &momentumSeed, const ROOT::Math::XYZVector &positionSeed, const double &timeSeed)
Flip and refit the daughter track.
bool m_kinkFitterModeFlipAndRefit
fitter mode 2nd bit
genfit::MeasuredStateOnPlane m_stDaughterBuffer
buffer for the MeasuredStateOnPlane of daughter obtained in the vertex fit
unsigned int combineTracksAndFit(const Track *trackMother, const Track *trackDaughter)
Combine daughter and mother tracks in one and fit.
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
unsigned int getNumberOfSVDHits() const
Return the number of svd hits.
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromLastHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the last hit in a fit useful for extrapolation of measuremen...
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
B2Vector3< double > B2Vector3D
typedef for common usage with double