21 constexpr
double c_BIL = 28.4366;
22 constexpr
double c_BMS = 53.1259;
23 constexpr
double c_BML = 62.8267;
24 constexpr
double c_BOL = 29.7554;
29 declareInterface<IMSVertexTrackletTool>(
this);
39 return StatusCode::SUCCESS;
47 ATH_CHECK(container.
record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()));
50 std::vector<std::vector<const Muon::MdtPrepData*> > SortedMdt;
54 if (nMDT <= 0) {
return StatusCode::SUCCESS; }
68 std::vector<TrackletSegment> segs[6][2][16];
69 std::vector<std::vector<const Muon::MdtPrepData*> >::const_iterator ChamberItr = SortedMdt.begin();
70 for (; ChamberItr != SortedMdt.end(); ++ChamberItr) {
71 std::vector<TrackletSegment> mlsegments;
72 std::vector<const Muon::MdtPrepData*>::const_iterator mdt1 = ChamberItr->begin();
73 std::vector<const Muon::MdtPrepData*>::const_iterator mdtEnd = ChamberItr->end();
78 bool mdt1_isBarrel =
m_idHelperSvc->mdtIdHelper().isBarrel(mdt1_ID);
79 bool mdt1_isEndcap =
m_idHelperSvc->mdtIdHelper().isEndcap(mdt1_ID);
81 int maxLayer =
m_idHelperSvc->mdtIdHelper().tubeLayerMax(mdt1_ID);
85 for (; mdt1 != mdtEnd; ++mdt1) {
93 if (tl1 == maxLayer)
break;
96 std::vector<const Muon::MdtPrepData*>::const_iterator mdt2 = (mdt1 + 1);
97 if (mdt2 == mdtEnd)
continue;
99 for (; mdt2 != mdtEnd; ++mdt2) {
108 if (mdt1 == mdt2 || (tl2 - tl1) > 1 || (tl2 - tl1) < 0)
continue;
109 if ((tl2 - tl1) == 0 && (
m_idHelperSvc->mdtIdHelper().tube(mdt2_ID) -
112 if (mdt1_isBarrel && std::abs((*mdt1)->globalPosition().z() - (*mdt2)->globalPosition().z()) >
m_d12_max)
continue;
113 if (mdt1_isEndcap && std::abs((*mdt1)->globalPosition().perp() - (*mdt2)->globalPosition().perp()) >
m_d12_max)
continue;
116 std::vector<const Muon::MdtPrepData*>::const_iterator mdt3 = (mdt2 + 1);
117 if (mdt3 == mdtEnd)
continue;
119 for (; mdt3 != mdtEnd; ++mdt3) {
127 if (mdt1 == mdt3 || mdt2 == mdt3)
continue;
129 if ((tl3 - tl2) > 1 || (tl3 - tl2) < 0 || (tl3 - tl1) <= 0)
continue;
130 if ((tl3 - tl2) == 0 && (
m_idHelperSvc->mdtIdHelper().tube(mdt3_ID) -
133 if (mdt1_isBarrel && std::abs((*mdt1)->globalPosition().z() - (*mdt3)->globalPosition().z()) >
m_d13_max)
continue;
134 if (mdt1_isEndcap && std::abs((*mdt1)->globalPosition().perp() - (*mdt3)->globalPosition().perp()) >
m_d13_max)
continue;
137 std::vector<const Muon::MdtPrepData*> mdts;
138 mdts.push_back((*mdt1));
139 mdts.push_back((*mdt2));
140 mdts.push_back((*mdt3));
142 for (
const TrackletSegment &tmpSeg : tmpSegs) mlsegments.push_back(tmpSeg);
149 int stationRegion =
m_idHelperSvc->mdtIdHelper().stationRegion(mdt1_ID);
151 if (stationRegion == 0)
152 for (
const TrackletSegment &mlsegment : mlsegments) segs[0][ML - 1][sector - 1].push_back(mlsegment);
153 else if (stationRegion == 2)
154 for (
const TrackletSegment &mlsegment : mlsegments) segs[1][ML - 1][sector - 1].push_back(mlsegment);
155 else if (stationRegion == 3)
156 for (
const TrackletSegment &mlsegment : mlsegments) segs[2][ML - 1][sector - 1].push_back(mlsegment);
158 else if (mdt1_isEndcap){
159 if (stationRegion == 0)
160 for (
const TrackletSegment &mlsegment : mlsegments) segs[3][ML - 1][sector - 1].push_back(mlsegment);
161 else if (stationRegion == 2)
162 for (
const TrackletSegment &mlsegment : mlsegments) segs[4][ML - 1][sector - 1].push_back(mlsegment);
163 else if (stationRegion == 3)
164 for (
const TrackletSegment &mlsegment : mlsegments) segs[5][ML - 1][sector - 1].push_back(mlsegment);
171 std::vector<TrackletSegment> CleanSegs[6][2][16];
172 for (
int st = 0; st < 6; ++st) {
173 for (
int ml = 0; ml < 2; ++ml) {
174 for (
int sector = 0; sector < 16; ++sector) {
175 if (!segs[st][ml][sector].
empty()) {
176 CleanSegs[st][ml][sector] =
CleanSegments(segs[st][ml][sector]);
183 for (
int st = 0; st < 6; ++st) {
185 for (
int sector = 0; sector < 16; ++sector) {
188 const Identifier trkID = ML1seg.getIdentifier();
191 int stationRegion =
m_idHelperSvc->mdtIdHelper().stationRegion(trkID);
194 if (stationRegion == 0){
196 else DeltaAlphaCut =
c_BIL / 750.0;
198 else if (stationRegion == 2){
199 if (isSmall) DeltaAlphaCut =
c_BMS / 750.0;
200 else DeltaAlphaCut =
c_BML / 750.0;
202 else if (stationRegion == 3){
204 else DeltaAlphaCut =
c_BOL / 750.0;
213 if (ML1seg.mdtChamber() != ML2seg.mdtChamber() || ML1seg.mdtChEta() != ML2seg.mdtChEta())
continue;
215 double deltaAlpha = ML1seg.alpha() - ML2seg.alpha();
218 if (std::abs(deltaAlpha) < DeltaAlphaCut && goodDeltab) {
221 double charge_discriminant = deltaAlpha * ML1seg.globalPosition().z() *
std::tan(ML1seg.alpha());
222 double charge = charge_discriminant < 0 ? -1 : 1;
224 double pTot =
TrackMomentum(ML1seg.getIdentifier(), deltaAlpha);
229 std::vector<const Muon::MdtPrepData*> mdts = ML1seg.mdtHitsOnTrack();
230 std::vector<const Muon::MdtPrepData*> mdts2 = ML2seg.mdtHitsOnTrack();
234 if (!CombinedSeg.empty()) {
240 pT *
std::sin(CombinedSeg[0].globalPosition().phi()),
254 <<
") and |p| = " << tmpTrk.
momentum().mag() <<
" MeV");
255 tracklets.push_back(tmpTrk);
277 <<
") and |p| = " << tmpTrk.
momentum().mag() <<
" MeV");
278 tracklets.push_back(tmpTrk);
284 std::vector<const Muon::MdtPrepData*> mdts = ML1seg.mdtHitsOnTrack();
285 std::vector<const Muon::MdtPrepData*> mdts2 = ML2seg.mdtHitsOnTrack();
289 if (!CombinedSeg.empty()) {
295 pT *
std::sin(CombinedSeg[0].globalPosition().phi()),
308 tracklets.push_back(tmpTrk);
325 return StatusCode::SUCCESS;
333 for (
Tracklet &tracklet : tracklets) {
335 tracklet.setTrackParticle(trackparticle);
345 trackparticle->
setFitQuality(1., (
float)tracklet.mdtHitsOnTrack().size());
347 std::vector<float> covMatrixVec;
364 if (stName ==
m_idHelperSvc->mdtIdHelper().stationNameIndex(
"BEE") ||
365 stName ==
m_idHelperSvc->mdtIdHelper().stationNameIndex(
"EEL") ||
369 if (stName ==
m_idHelperSvc->mdtIdHelper().stationNameIndex(
"BIS") && std::abs(stEta) >= 7)
ignore =
true;
372 if (stName ==
m_idHelperSvc->mdtIdHelper().stationNameIndex(
"BME") ||
394 if (MDTch->empty())
continue;
398 std::vector<const Muon::MdtPrepData*> hitsML1;
399 std::vector<const Muon::MdtPrepData*> hitsML2;
404 if (mdt->adc() < 50)
continue;
408 if (mdt->localPosition()[
Trk::locR] == 0.)
continue;
417 if (
m_idHelperSvc->mdtIdHelper().multilayer(mdt->identify()) == 1)
418 hitsML1.push_back(mdt);
420 hitsML2.push_back(mdt);
433 std::vector<std::vector<const Muon::MdtPrepData*> >& SortedMdt)
const {
434 if (
hits.empty())
return;
437 int ntubes =
hits.front()->detectorElement()->getNLayers() *
hits.front()->detectorElement()->getNtubesperlayer();
438 if (
hits.size() > 0.75 * ntubes)
return;
440 if (m_idHelperSvc->mdtIdHelper().tubeLayer(mprd1->identify()) > m_idHelperSvc->mdtIdHelper().tubeLayer(mprd2->identify()))
442 if (m_idHelperSvc->mdtIdHelper().tubeLayer(mprd1->identify()) < m_idHelperSvc->mdtIdHelper().tubeLayer(mprd2->identify()))
444 if (m_idHelperSvc->mdtIdHelper().tube(mprd1->identify()) < m_idHelperSvc->mdtIdHelper().tube(mprd2->identify())) return true;
448 SortedMdt.push_back(
hits);
456 std::vector<std::pair<double, double> > SeedParams =
SegSeeds(mdts);
466 std::vector<std::pair<double, double> > SeedParams;
472 double x1 = mdts.front()->globalPosition().z();
473 double y1 = mdts.front()->globalPosition().perp();
474 double r1 = std::abs(mdts.front()->localPosition()[
Trk::locR]);
476 double x2 = mdts.back()->globalPosition().z();
477 double y2 = mdts.back()->globalPosition().perp();
478 double r2 = std::abs(mdts.back()->localPosition()[
Trk::locR]);
480 double DeltaX =
x2 -
x1;
481 double DeltaY =
y2 -
y1;
482 double DistanceOfCenters = std::hypot(DeltaX, DeltaY);
483 if (DistanceOfCenters < 30)
return SeedParams;
484 double Alpha0 = std::acos(DeltaX / DistanceOfCenters);
487 double phi = mdts.front()->globalPosition().phi();
488 double RSum = r1 + r2;
489 if (RSum > DistanceOfCenters)
return SeedParams;
490 double Alpha1 = std::asin(RSum / DistanceOfCenters);
491 double line_theta = Alpha0 + Alpha1;
492 double z_line =
x1 + r1 *
std::sin(line_theta);
493 double rho_line =
y1 - r1 *
std::cos(line_theta);
498 double gSlope1 = (globalDir1.perp() / globalDir1.z());
499 double gInter1 = gPos1.perp() - gSlope1 * gPos1.z();
501 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope1, gInter1);
503 line_theta = Alpha0 - Alpha1;
508 double gSlope2 = (globalDir2.perp() / globalDir2.z());
509 double gInter2 = gPos2.perp() - gSlope2 * gPos2.z();
511 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope2, gInter2);
513 double Alpha2 = std::asin(std::abs(r2 - r1) / DistanceOfCenters);
516 line_theta = Alpha0 + Alpha2;
522 double gSlope3 = (globalDir3.perp() / globalDir3.z());
523 double gInter3 = gPos3.perp() - gSlope3 * gPos3.z();
525 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope3, gInter3);
528 line_theta = Alpha0 - Alpha2;
534 double gSlope4 = (globalDir4.perp() / globalDir4.z());
535 double gInter4 = gPos4.perp() - gSlope4 * gPos4.z();
537 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope4, gInter4);
540 line_theta = Alpha0 + Alpha2;
546 double gSlope3 = (globalDir3.perp() / globalDir3.z());
547 double gInter3 = gPos3.perp() - gSlope3 * gPos3.z();
549 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope3, gInter3);
552 line_theta = Alpha0 - Alpha2;
558 double gSlope4 = (globalDir4.perp() / globalDir4.z());
559 double gInter4 = gPos4.perp() - gSlope4 * gPos4.z();
561 if (resid <
m_SeedResidual) SeedParams.emplace_back(gSlope4, gInter4);
573 double mdtR = mdt->globalPosition().perp();
574 double mdtZ = mdt->globalPosition().z();
575 double res = std::abs((mdt->localPosition()[
Trk::locR] - std::abs((mdtR - inter - slope * mdtZ) / std::hypot(slope, 1))) /
577 if (
res > resid) resid =
res;
585 const std::vector<std::pair<double, double> >& SeedParams)
const {
586 std::vector<TrackletSegment> segs;
589 for (
const std::pair<double,double> &SeedParam : SeedParams) {
593 double s(0),
sz(0),
sy(0);
600 const double mdt_y = std::hypot(prd->globalPosition().x(), prd->globalPosition().y());
601 const double mdt_z = prd->globalPosition().z();
604 sz += mdt_z / sigma2;
605 sy += mdt_y / sigma2;
607 const double yc =
sy /
s;
608 const double zc =
sz /
s;
611 double alpha = std::atan2(SeedParam.first, 1.0);
614 double d = (SeedParam.second - yc + zc * SeedParam.first) *
std::cos(
alpha);
622 double sPyy(0), sPyz(0), sPyyzz(0);
624 double mdt_y = std::hypot(prd->globalPosition().x(), prd->globalPosition().y());
625 double mdt_z = prd->globalPosition().z();
627 sPyy +=
std::pow(mdt_y-yc,2) / sigma2;
628 sPyz += (mdt_y - yc) * (mdt_z - zc) / sigma2;
629 sPyyzz += ((mdt_y - yc) - (mdt_z - zc)) * ((mdt_y - yc) + (mdt_z - zc)) / sigma2;
634 double deltaAlpha = 0;
637 double sumRyi(0), sumRzi(0), sumRi(0);
643 double mdt_y = prd->globalPosition().perp();
644 double mdt_z = prd->globalPosition().z();
645 double yPi = -(mdt_z - zc) * sin_a + (mdt_y - yc) * cos_a -
d;
646 double signR = yPi >= 0 ? -1. : 1;
648 double ri = signR * prd->localPosition()[
Trk::locR];
649 sumRyi += ri * (mdt_y - yc) / sigma2;
650 sumRzi += ri * (mdt_z - zc) / sigma2;
651 sumRi += ri / sigma2;
654 double bAlpha = -1 * sPyz + cos_a * (sin_a * sPyyzz + 2 * cos_a * sPyz + sumRzi) + sin_a * sumRyi;
655 double AThTh = sPyy + cos_a * (2 * sin_a * sPyz - cos_a * sPyyzz);
659 if (std::abs(AThTh) < 1.e-7)
break;
661 double alphaNew =
alpha + bAlpha / AThTh;
662 double dNew = sumRi /
s;
664 dalpha = std::sqrt(1 / std::abs(AThTh));
665 dd = std::sqrt(1 /
s);
666 deltaAlpha = std::abs(alphaNew -
alpha);
667 deltad = std::abs(
d - dNew);
669 if (deltaAlpha < 5.
e-7 && deltad < 5.
e-6)
break;
673 if (Nitr > 10)
break;
677 double chi2Prob = TMath::Prob(
chi2, mdts.size() - 2);
694 for (
unsigned int k = 0;
k < mdts.size(); ++
k) {
696 double mdtR = std::hypot(mdts.at(
k)->globalPosition().x(), mdts.at(
k)->globalPosition().y());
697 double mdtZ = mdts.at(
k)->globalPosition().z();
707 double mdtPhi = mdts.at(0)->globalPosition().phi();
711 segs.push_back(MyTrackletSegment);
717 if (segs.size() > 1) {
718 std::vector<TrackletSegment> tmpSegs;
719 for (
unsigned int i1 = 0; i1 < segs.size(); ++i1) {
720 bool isUnique =
true;
721 int pattern1 = segs.at(i1).getHitPattern();
722 for (
unsigned int i2 = (i1 + 1); i2 < segs.size(); ++i2) {
723 if (pattern1 == -1)
break;
724 int pattern2 = segs.at(i2).getHitPattern();
725 if (pattern1 == pattern2) isUnique =
false;
727 if (isUnique) tmpSegs.push_back(segs.at(i1));
739 std::vector<TrackletSegment> CleanSegs;
740 std::vector<TrackletSegment> segs = Segs;
741 bool keepCleaning(
true);
744 while (keepCleaning) {
746 keepCleaning =
false;
749 if (
it->isCombined())
continue;
750 std::vector<TrackletSegment> segsToCombine;
752 double r1 =
it->globalPosition().perp();
753 double zi1 =
it->globalPosition().z() - r1 / tanTh1;
756 if (sit->isCombined())
continue;
757 if (
it->mdtChamber() != sit->mdtChamber())
continue;
758 if ((
it->mdtChEta()) * (sit->mdtChEta()) < 0)
continue;
759 if (
it->mdtChPhi() != sit->mdtChPhi())
continue;
760 if (std::abs(
it->alpha() - sit->alpha()) > 0.005)
continue;
761 double tanTh2 =
std::tan(sit->alpha());
762 double r2 = sit->globalPosition().perp();
763 double zi2 = sit->globalPosition().z() - r2 / tanTh2;
765 double rmid = (r1 + r2) / 2.;
766 double z1 = rmid / tanTh1 + zi1;
767 double z2 = rmid / tanTh2 + zi2;
768 double zdist = std::abs(z1 - z2);
770 segsToCombine.push_back(*sit);
771 sit->isCombined(
true);
776 if (segsToCombine.empty()) {
777 CleanSegs.push_back(*
it);
780 else if (!segsToCombine.empty()) {
782 std::vector<const Muon::MdtPrepData*> mdts =
it->mdtHitsOnTrack();
784 std::vector<const Muon::MdtPrepData*> tmpmdts = seg.mdtHitsOnTrack();
788 if (tmpprd->identify() == tmpprd2->identify()) {
798 if (mdts.size() >
it->mdtHitsOnTrack().size()) {
801 if (refitsegs.empty()) {
802 if (segsToCombine.size() == 1) {
803 segsToCombine[0].isCombined(
false);
804 CleanSegs.push_back(*
it);
805 CleanSegs.push_back(segsToCombine[0]);
808 std::vector<int> nSeg;
809 for (
unsigned int i = 0;
i < mdts.size(); ++
i) {
812 for (
unsigned int k = 0;
k <
it->mdtHitsOnTrack().
size(); ++
k) {
813 if (
it->mdtHitsOnTrack()[
k]->identify() == mdts[
i]->identify()) {
819 for (
unsigned int k = 0;
k < segsToCombine.size(); ++
k) {
820 for (
unsigned int m = 0;
m < segsToCombine[
k].mdtHitsOnTrack().
size(); ++
m) {
830 bool keeprefitting(
true);
832 while (keeprefitting) {
834 int nMinSeg(nSeg[0]);
836 std::vector<int> nrfsegs;
837 std::vector<const Muon::MdtPrepData*> refitmdts;
839 for (
unsigned int i = 1;
i < mdts.size(); ++
i) {
840 if (nSeg[
i] < nMinSeg) {
841 refitmdts.push_back(minmdt);
842 nrfsegs.push_back(nMinSeg);
846 refitmdts.push_back(mdts[
i]);
847 nrfsegs.push_back(nSeg[
i]);
855 if (!refitsegs.empty()) {
856 for (
const TrackletSegment &refitseg : refitsegs) CleanSegs.push_back(refitseg);
857 keeprefitting =
false;
858 }
else if (mdts.size() <= 3) {
859 CleanSegs.push_back(*
it);
860 keeprefitting =
false;
862 if (nItr2 > 10)
break;
867 for (
const TrackletSegment &refitseg : refitsegs) CleanSegs.push_back(refitseg);
872 CleanSegs.push_back(*
it);
879 if (nItr > 10)
break;
890 double mid1(100), mid2(1000);
900 if (std::abs(deltab2) < std::abs(deltab)) deltab = deltab2;
909 if (std::abs(deltab2) < std::abs(deltab)) deltab = deltab2;
915 return std::abs(deltab) < dbmax;
924 int stationRegion =
m_idHelperSvc->mdtIdHelper().stationRegion(trkID);
926 double dalpha = std::abs(deltaAlpha);
929 if (stationRegion == 0){
931 else pTot =
c_BIL / dalpha;
933 else if (stationRegion == 2){
934 if (isSmall) pTot =
c_BMS / dalpha;
935 else pTot =
c_BML / dalpha;
937 else if (stationRegion == 3){
939 else pTot =
c_BOL / dalpha;
955 int stationRegion =
m_idHelperSvc->mdtIdHelper().stationRegion(trkID);
958 double pErr = dalpha /
c_BML;
960 if (stationRegion == 0){
961 if (isSmall) pErr = dalpha /
c_BML;
962 else pErr = dalpha /
c_BIL;
964 else if (stationRegion == 2){
965 if (isSmall) pErr = dalpha /
c_BMS;
966 else pErr = dalpha /
c_BML;
968 else if (stationRegion == 3){
969 if (isSmall) pErr = dalpha /
c_BML;
970 else pErr = dalpha /
c_BOL;
984 int stationRegion =
m_idHelperSvc->mdtIdHelper().stationRegion(trkID);
987 double pErr = dalpha /
c_BML;
989 if (stationRegion == 0){
990 if (isSmall) pErr = dalpha /
c_BML;
991 else pErr = dalpha /
c_BIL;
993 else if (stationRegion == 2){
994 if (isSmall) pErr = dalpha /
c_BMS;
995 else pErr = dalpha /
c_BML;
997 else if (stationRegion == 3){
998 if (isSmall) pErr = dalpha /
c_BML;
999 else pErr = dalpha /
c_BOL;
1014 std::vector<Tracklet> myTracks = tracks;
1017 Identifier id1 =
track.getML1seg().mdtHitsOnTrack().at(0)->identify();
1019 int nLayerML1 =
m_idHelperSvc->mdtIdHelper().tubeLayerMax(id1);
1021 double ratio = (
double)(
track.mdtHitsOnTrack().size()) / (nLayerML1 + nLayerML2);
1026 std::vector<Tracklet> UniqueTracks;
1027 std::vector<unsigned int> AmbigTrks;
1028 for (
unsigned int tk1 = 0; tk1 < tracks.size(); ++tk1) {
1031 bool isResolved =
false;
1032 for (
unsigned int AmbigTrksIdx : AmbigTrks) {
1033 if (tk1 == AmbigTrksIdx) {
1038 if (isResolved)
continue;
1039 std::vector<Tracklet> AmbigTracks;
1040 AmbigTracks.push_back(tracks.at(tk1));
1042 double Trk1ML1R = tracks.at(tk1).getML1seg().globalPosition().perp();
1043 double Trk1ML1Z = tracks.at(tk1).getML1seg().globalPosition().z();
1044 double Trk1ML2R = tracks.at(tk1).getML2seg().globalPosition().perp();
1045 double Trk1ML2Z = tracks.at(tk1).getML2seg().globalPosition().z();
1047 Identifier tk1ID = tracks.at(tk1).muonIdentifier();
1048 bool tk1_isBarrel =
m_idHelperSvc->mdtIdHelper().isBarrel(tk1ID);
1049 bool tk1_isEndcap =
m_idHelperSvc->mdtIdHelper().isEndcap(tk1ID);
1052 for (
unsigned int tk2 = (tk1 + 1); tk2 < tracks.size(); ++tk2) {
1053 if (tracks.at(tk1).mdtChamber() == tracks.at(tk2).mdtChamber() && tracks.at(tk1).mdtChPhi() == tracks.at(tk2).mdtChPhi() &&
1054 (tracks.at(tk1).mdtChEta()) * (tracks.at(tk2).mdtChEta()) > 0) {
1056 for (
unsigned int AmbigTrksIdx : AmbigTrks) {
1057 if (tk2 == AmbigTrksIdx) {
1062 if (isResolved)
continue;
1064 double Trk2ML1R = tracks.at(tk2).getML1seg().globalPosition().perp();
1065 double Trk2ML1Z = tracks.at(tk2).getML1seg().globalPosition().z();
1066 double Trk2ML2R = tracks.at(tk2).getML2seg().globalPosition().perp();
1067 double Trk2ML2Z = tracks.at(tk2).getML2seg().globalPosition().z();
1070 double DistML1(1000), DistML2(1000);
1072 DistML1 = std::abs(Trk1ML1Z - Trk2ML1Z);
1073 DistML2 = std::abs(Trk1ML2Z - Trk2ML2Z);
1074 }
else if (tk1_isEndcap) {
1075 DistML1 = std::abs(Trk1ML1R - Trk2ML1R);
1076 DistML2 = std::abs(Trk1ML2R - Trk2ML2R);
1078 if (DistML1 < 40 || DistML2 < 40) {
1080 std::vector<const Muon::MdtPrepData*> mdts1 = tracks.at(tk1).mdtHitsOnTrack();
1081 std::vector<const Muon::MdtPrepData*> mdts2 = tracks.at(tk2).mdtHitsOnTrack();
1085 if (mdt1->identify() == mdt2->identify()) {
1092 if (nShared <= 1)
continue;
1094 AmbigTracks.push_back(tracks.at(tk2));
1095 AmbigTrks.push_back(tk2);
1100 if (AmbigTracks.size() == 1) {
1101 UniqueTracks.push_back(tracks.at(tk1));
1107 bool hasMomentum = tracks.at(tk1).charge() != 0;
1108 double aveX(0), aveY(0), aveZ(0), aveAlpha(0);
1109 double aveP(0), nAmbigP(0), TrkCharge(tracks.at(tk1).charge());
1110 bool allSameSign(
true);
1112 for (
const Tracklet &AmbigTrack : AmbigTracks) {
1114 aveX += AmbigTrack.globalPosition().x();
1115 aveY += AmbigTrack.globalPosition().y();
1116 aveZ += AmbigTrack.globalPosition().z();
1117 aveAlpha += AmbigTrack.getML1seg().alpha();
1120 if (std::abs(AmbigTrack.charge() - TrkCharge) > 0.1) allSameSign =
false;
1122 aveP += AmbigTrack.momentum().mag();
1124 aveAlpha += AmbigTrack.alpha();
1125 aveX += AmbigTrack.globalPosition().x();
1126 aveY += AmbigTrack.globalPosition().y();
1127 aveZ += AmbigTrack.globalPosition().z();
1131 aveX = aveX / (
double)AmbigTracks.size();
1132 aveY = aveY / (
double)AmbigTracks.size();
1133 aveZ = aveZ / (
double)AmbigTracks.size();
1135 aveAlpha = aveAlpha / (
double)AmbigTracks.size();
1136 double alphaErr = tracks.at(tk1).getML1seg().alphaError();
1137 double rErr = tracks.at(tk1).getML1seg().rError();
1138 double zErr = tracks.at(tk1).getML1seg().zError();
1151 matrix(3, 3) =
std::pow(tracks.at(tk1).getML1seg().alphaError(),2);
1154 UniqueTracks.push_back(aveTrack);
1155 }
else if (allSameSign) {
1156 aveP = aveP / nAmbigP;
1157 double pT = aveP *
std::sin(tracks.at(tk1).getML1seg().alpha());
1158 double pz = aveP *
std::cos(tracks.at(tk1).getML1seg().alpha());
1160 pT *
std::sin(tracks.at(tk1).globalPosition().phi()),
1164 MyTrack.
charge(tracks.at(tk1).charge());
1165 UniqueTracks.push_back(MyTrack);
1167 aveX = aveX / (
double)AmbigTracks.size();
1168 aveY = aveY / (
double)AmbigTracks.size();
1169 aveZ = aveZ / (
double)AmbigTracks.size();
1171 aveAlpha = aveAlpha / (
double)AmbigTracks.size();
1172 double alphaErr = tracks.at(tk1).getML1seg().alphaError();
1173 double rErr = tracks.at(tk1).getML1seg().rError();
1174 double zErr = tracks.at(tk1).getML1seg().zError();
1187 matrix(3, 3) =
std::pow(tracks.at(tk1).getML1seg().alphaError(),2);
1190 UniqueTracks.push_back(aveTrack);
1195 else if (tk1_isEndcap) {
1196 std::vector<const Muon::MdtPrepData*> AllMdts;
1197 for (
Tracklet const &AmbigTrack : AmbigTracks) {
1198 std::vector<const Muon::MdtPrepData*> mdts = AmbigTrack.mdtHitsOnTrack();
1199 std::vector<const Muon::MdtPrepData*> tmpAllMdt = AllMdts;
1201 bool isNewHit =
true;
1203 if (mdt->identify() == tmpmdt->identify()) {
1208 if (isNewHit) AllMdts.push_back(mdt);
1213 if (!MyECsegs.empty()) {
1229 UniqueTracks.push_back(MyCombTrack);
1231 UniqueTracks.push_back(tracks.at(tk1));
1236 return UniqueTracks;