50 return (Ref_L1A->pt() > Ref_L1B->pt());
58 if (Ref_L1A->hwQual() > Ref_L1B->hwQual())
60 if (Ref_L1A->hwQual() < Ref_L1B->hwQual())
64 return (Ref_L1A->pt() > Ref_L1B->pt());
70 theL1GMTReadoutCollection(iConfig.getParameter<
InputTag>(
"GMTReadoutCollection")),
72 theL1MinPt(iConfig.getParameter<double>(
"L1MinPt")),
73 theL1MaxEta(iConfig.getParameter<double>(
"L1MaxEta")),
74 theL1MinQuality(iConfig.getParameter<unsigned
int>(
"L1MinQuality")),
75 theMinPtBarrel(iConfig.getParameter<double>(
"SetMinPtBarrelTo")),
76 theMinPtEndcap(iConfig.getParameter<double>(
"SetMinPtEndcapTo")),
77 useOfflineSeed(iConfig.getUntrackedParameter<
bool>(
"UseOfflineSeed",
false)),
78 useUnassociatedL1(iConfig.getParameter<
bool>(
"UseUnassociatedL1")),
79 matchingDR(iConfig.getParameter<
std::vector<double>>(
"MatchDR")),
80 etaBins(iConfig.getParameter<
std::vector<double>>(
"EtaMatchingBins")),
81 centralBxOnly_(iConfig.getParameter<
bool>(
"CentralBxOnly")),
82 matchType(iConfig.getParameter<unsigned
int>(
"MatchType")),
83 sortType(iConfig.getParameter<unsigned
int>(
"SortType")) {
93 <<
"does not match number of eta bins." << endl;
98 throw cms::Exception(
"Configuration") <<
"Wrong MatchType or SortType" << endl;
110 produces<L2MuonTrajectorySeedCollection>();
125 desc.
add<
string>(
"Propagator",
"");
126 desc.
add<
double>(
"L1MinPt", -1.);
127 desc.
add<
double>(
"L1MaxEta", 5.0);
128 desc.
add<
unsigned int>(
"L1MinQuality", 0);
129 desc.
add<
double>(
"SetMinPtBarrelTo", 3.5);
130 desc.
add<
double>(
"SetMinPtEndcapTo", 1.0);
132 desc.
add<
bool>(
"UseUnassociatedL1",
true);
133 desc.
add<std::vector<double>>(
"MatchDR", {0.3});
134 desc.
add<std::vector<double>>(
"EtaMatchingBins", {0., 2.5});
135 desc.
add<
bool>(
"CentralBxOnly",
true);
136 desc.
add<
unsigned int>(
"MatchType", 0)
138 "MatchType : 0 Old matching, 1 L1 Order(1to1), 2 Min dR(1to1), 3 Higher Q(1to1), 4 All matched L1");
139 desc.
add<
unsigned int>(
"SortType", 0)->setComment(
"SortType : 0 not sort, 1 Pt, 2 Q and Pt");
143 psd0.
addUntracked<std::vector<std::string>>(
"Propagators", {
"SteppingHelixPropagatorAny"});
144 psd0.add<
bool>(
"RPCLayers",
true);
145 psd0.addUntracked<
bool>(
"UseMuonNavigation",
true);
147 descriptions.
add(
"L2MuonSeedGeneratorFromL1T", desc);
154 auto output = std::make_unique<L2MuonTrajectorySeedCollection>();
163 vector<int> offlineSeedMap;
166 LogDebug(
metname) <<
"Number of offline seeds " << offlineSeedHandle->size() << endl;
167 offlineSeedMap = vector<int>(offlineSeedHandle->size(), 0);
173 for (
auto it = muColl->
begin(ibx); it != muColl->
end(ibx); it++) {
174 unsigned int quality = it->hwQual();
175 int valid_charge = it->hwChargeValid();
178 float eta = it->eta();
180 float phi = it->phi();
181 int charge = it->charge();
188 int link = 36 + (
int)(it->tfMuonIndex() / 3.);
214 CLHEP::Hep3Vector vec(0., 1., 0.);
225 detLayer =
theService->detLayerGeometry()->idToLayer(theid);
229 const BoundCylinder *bc = dynamic_cast<const BoundCylinder *>(sur);
243 detLayer =
theService->detLayerGeometry()->idToLayer(theid);
261 mat[0][0] = (0.25 /
pt) * (0.25 /
pt);
263 mat[0][0] = (0.4 /
pt) * (0.4 /
pt);
267 mat[0][0] = (1. /
pt) * (1. /
pt);
269 mat[1][1] = 0.05 * 0.05;
270 mat[2][2] = 0.2 * 0.2;
271 mat[3][3] = 20. * 20.;
272 mat[4][4] = 20. * 20.;
302 if (assoOffseed !=
nullptr) {
305 for (; tsci != tscie; ++tsci) {
326 std::vector<pair<const GeomDet *, TrajectoryStateOnSurface>> detsWithStates =
329 if (detsWithStates.empty() &&
barrel) {
340 if (!detsWithStates.empty()) {
342 const GeomDet *newTSOSDet = detsWithStates.front().first;
358 if (assoOffseed !=
nullptr) {
361 tscie = assoOffseed->
recHits().second;
362 for (; tsci != tscie; ++tsci) {
398 unsigned int nMuColl = muColl->
size();
400 vector<vector<double>> dRmtx;
401 vector<vector<const TrajectorySeed *>> selOffseeds;
406 unsigned int nOfflineSeed = offlineSeedHandle->size();
407 LogDebug(
metname) <<
"Number of offline seeds " << nOfflineSeed << endl;
410 dRmtx = vector<vector<double>>(nMuColl, vector<double>(nOfflineSeed, 999.0));
412 vector<vector<const TrajectorySeed *>>(nMuColl, vector<const TrajectorySeed *>(nOfflineSeed,
nullptr));
422 for (
auto it = muColl->
begin(ibx); it != muColl->
end(ibx); it++) {
426 unsigned int quality = it->hwQual();
427 int valid_charge = it->hwChargeValid();
430 float eta = it->eta();
432 float phi = it->phi();
433 int charge = it->charge();
440 int link = 36 + (
int)(it->tfMuonIndex() / 3.);
466 CLHEP::Hep3Vector vec(0., 1., 0.);
477 detLayer =
theService->detLayerGeometry()->idToLayer(theid);
481 const BoundCylinder *bc = dynamic_cast<const BoundCylinder *>(sur);
495 detLayer =
theService->detLayerGeometry()->idToLayer(theid);
513 mat[0][0] = (0.25 /
pt) * (0.25 /
pt);
515 mat[0][0] = (0.4 /
pt) * (0.4 /
pt);
519 mat[0][0] = (1. /
pt) * (1. /
pt);
521 mat[1][1] = 0.05 * 0.05;
522 mat[2][2] = 0.2 * 0.2;
523 mat[3][3] = 20. * 20.;
524 mat[4][4] = 20. * 20.;
551 if ((!valid_charge ||
charge == 0)) {
574 else if (valid_charge) {
576 std::vector<pair<const GeomDet *, TrajectoryStateOnSurface>> detsWithStates =
579 if (detsWithStates.empty() &&
barrel) {
590 if (!detsWithStates.empty()) {
592 const GeomDet *newTSOSDet = detsWithStates.front().first;
642 unsigned int nOfflineSeed1 = offlineSeedHandle->size();
647 vector<bool> removed_col = vector<bool>(nOfflineSeed1,
false);
649 for (nL1 = 0; nL1 < nMuColl; ++nL1) {
651 unsigned int theOffs = 0;
653 for (
j = 0;
j < nOfflineSeed1; ++
j) {
656 if (tempDR > dRmtx[nL1][
j]) {
657 tempDR = dRmtx[nL1][
j];
665 if (fabs(it->eta()) <
etaBins.back()) {
670 if (!(tempDR < newDRcone))
674 removed_col[theOffs] =
true;
676 if (selOffseeds[nL1][theOffs] !=
nullptr) {
682 tscie = selOffseeds[nL1][theOffs]->recHits().second;
683 for (; tsci != tscie; ++tsci) {
695 vector<bool> removed_row = vector<bool>(nMuColl,
false);
696 vector<bool> removed_col = vector<bool>(nOfflineSeed1,
false);
698 for (nL1 = 0; nL1 < nMuColl; ++nL1) {
700 unsigned int theL1 = 0;
701 unsigned int theOffs = 0;
703 for (
i = 0;
i < nMuColl; ++
i) {
706 for (
j = 0;
j < nOfflineSeed1; ++
j) {
709 if (tempDR > dRmtx[
i][
j]) {
710 tempDR = dRmtx[
i][
j];
720 if (fabs(it->eta()) <
etaBins.back()) {
725 if (!(tempDR < newDRcone))
729 removed_col[theOffs] =
true;
730 removed_row[theL1] =
true;
732 if (selOffseeds[theL1][theOffs] !=
nullptr) {
738 tscie = selOffseeds[theL1][theOffs]->recHits().second;
739 for (; tsci != tscie; ++tsci) {
751 vector<bool> removed_row = vector<bool>(nMuColl,
false);
752 vector<bool> removed_col = vector<bool>(nOfflineSeed1,
false);
754 for (nL1 = 0; nL1 < nMuColl; ++nL1) {
756 unsigned int theL1 = 0;
757 unsigned int theOffs = 0;
761 for (
i = 0;
i < nMuColl; ++
i) {
765 if (theit->hwQual() > 10) {
766 for (
j = 0;
j < nOfflineSeed1; ++
j) {
769 if (tempDR > dRmtx[
i][
j]) {
770 tempDR = dRmtx[
i][
j];
780 for (
i = 0;
i < nMuColl; ++
i) {
784 if ((theit->hwQual() <= 10) && (theit->hwQual() > 6)) {
785 for (
j = 0;
j < nOfflineSeed1; ++
j) {
788 if (tempDR > dRmtx[
i][
j]) {
789 tempDR = dRmtx[
i][
j];
800 for (
i = 0;
i < nMuColl; ++
i) {
804 if (theit->hwQual() <= 6) {
805 for (
j = 0;
j < nOfflineSeed1; ++
j) {
808 if (tempDR > dRmtx[
i][
j]) {
809 tempDR = dRmtx[
i][
j];
821 if (fabs(it->eta()) <
etaBins.back()) {
826 if (!(tempDR < newDRcone))
830 removed_col[theOffs] =
true;
831 removed_row[theL1] =
true;
833 if (selOffseeds[theL1][theOffs] !=
nullptr) {
839 tscie = selOffseeds[theL1][theOffs]->recHits().second;
840 for (; tsci != tscie; ++tsci) {
852 for (
i = 0;
i < nMuColl; ++
i) {
856 unsigned int theOffs = 0;
859 if (fabs(it->eta()) <
etaBins.back()) {
864 for (
j = 0;
j < nOfflineSeed1; ++
j) {
865 if (tempDR > dRmtx[
i][
j]) {
866 tempDR = dRmtx[
i][
j];
871 if (!(tempDR < newDRcone))
874 if (selOffseeds[
i][theOffs] !=
nullptr) {
880 tscie = selOffseeds[
i][theOffs]->recHits().second;
881 for (; tsci != tscie; ++tsci) {
912 std::vector<int> &offseedMap,
915 const std::string metlabel =
"Muon|RecoMuon|L2MuonSeedGeneratorFromL1T";
920 double bestDr = 99999.;
921 unsigned int nOffseed(0);
924 for (offseed = offseeds->
begin(); offseed != endOffseed; ++offseed, ++nOffseed) {
925 if (offseedMap[nOffseed] != 0)
928 ->idToDet(offseed->startingState().detId())
930 .toGlobal(offseed->startingState().parameters().position());
932 ->idToDet(offseed->startingState().detId())
934 .toGlobal(offseed->startingState().parameters().momentum());
942 glbPos, glbMom, offseed->startingState().parameters().charge(), &*
theService->magneticField());
945 LogDebug(metlabel) <<
"Offline seed info: Det and State" << std::endl;
946 LogDebug(metlabel) << debugtmp.
dumpMuonId(offseed->startingState().detId()) << std::endl;
947 LogDebug(metlabel) <<
"pos: (r=" << offseedFTS.position().mag() <<
", phi=" << offseedFTS.position().phi()
948 <<
", eta=" << offseedFTS.position().eta() <<
")" << std::endl;
949 LogDebug(metlabel) <<
"mom: (q*pt=" << offseedFTS.charge() * offseedFTS.momentum().perp()
950 <<
", phi=" << offseedFTS.momentum().phi() <<
", eta=" << offseedFTS.momentum().eta() <<
")"
954 if (offseedTsos.isValid()) {
955 LogDebug(metlabel) <<
"Offline seed info after propagation to L1 layer:" << std::endl;
956 LogDebug(metlabel) <<
"pos: (r=" << offseedTsos.globalPosition().mag()
957 <<
", phi=" << offseedTsos.globalPosition().phi()
958 <<
", eta=" << offseedTsos.globalPosition().eta() <<
")" << std::endl;
959 LogDebug(metlabel) <<
"mom: (q*pt=" << offseedTsos.charge() * offseedTsos.globalMomentum().perp()
960 <<
", phi=" << offseedTsos.globalMomentum().phi()
961 <<
", eta=" << offseedTsos.globalMomentum().eta() <<
")" << std::endl
965 offseedTsos.globalPosition().eta(),
966 offseedTsos.globalPosition().
phi());
967 LogDebug(metlabel) <<
" -- DR = " << newDr << std::endl;
968 if (newDr <
dRcone && newDr < bestDr) {
969 LogDebug(metlabel) <<
" --> OK! " << newDr << std::endl << std::endl;
970 selOffseed = &*offseed;
972 offseedMap[nOffseed] = 1;
973 if (lastOffseed > -1)
974 offseedMap[lastOffseed] = 0;
975 lastOffseed = nOffseed;
977 LogDebug(metlabel) <<
" --> Rejected. " << newDr << std::endl << std::endl;
980 LogDebug(metlabel) <<
"Invalid offline seed TSOS after propagation!" << std::endl << std::endl;
989 std::vector<std::vector<double>> &dRmtx,
992 std::vector<std::vector<const TrajectorySeed *>> &selOffseeds,
994 const std::string metlabel =
"Muon|RecoMuon|L2MuonSeedGeneratorFromL1T";
995 bool isAssociated =
false;
999 unsigned int nOffseed(0);
1001 for (offseed = offseeds->
begin(); offseed != endOffseed; ++offseed, ++nOffseed) {
1003 ->idToDet(offseed->startingState().detId())
1005 .toGlobal(offseed->startingState().parameters().position());
1007 ->idToDet(offseed->startingState().detId())
1009 .toGlobal(offseed->startingState().parameters().momentum());
1017 glbPos, glbMom, offseed->startingState().parameters().charge(), &*
theService->magneticField());
1020 LogDebug(metlabel) <<
"Offline seed info: Det and State" << std::endl;
1021 LogDebug(metlabel) << debugtmp.
dumpMuonId(offseed->startingState().detId()) << std::endl;
1022 LogDebug(metlabel) <<
"pos: (r=" << offseedFTS.position().mag() <<
", phi=" << offseedFTS.position().phi()
1023 <<
", eta=" << offseedFTS.position().eta() <<
")" << std::endl;
1024 LogDebug(metlabel) <<
"mom: (q*pt=" << offseedFTS.charge() * offseedFTS.momentum().perp()
1025 <<
", phi=" << offseedFTS.momentum().phi() <<
", eta=" << offseedFTS.momentum().eta() <<
")"
1029 if (offseedTsos.isValid()) {
1030 LogDebug(metlabel) <<
"Offline seed info after propagation to L1 layer:" << std::endl;
1031 LogDebug(metlabel) <<
"pos: (r=" << offseedTsos.globalPosition().mag()
1032 <<
", phi=" << offseedTsos.globalPosition().phi()
1033 <<
", eta=" << offseedTsos.globalPosition().eta() <<
")" << std::endl;
1034 LogDebug(metlabel) <<
"mom: (q*pt=" << offseedTsos.charge() * offseedTsos.globalMomentum().perp()
1035 <<
", phi=" << offseedTsos.globalMomentum().phi()
1036 <<
", eta=" << offseedTsos.globalMomentum().eta() <<
")" << std::endl
1040 offseedTsos.globalPosition().eta(),
1041 offseedTsos.globalPosition().
phi());
1043 LogDebug(metlabel) <<
" -- DR = " << newDr << std::endl;
1045 LogDebug(metlabel) <<
" --> OK! " << newDr << std::endl << std::endl;
1047 dRmtx[imu][nOffseed] = newDr;
1048 selOffseeds[imu][nOffseed] = &*offseed;
1050 isAssociated =
true;
1052 LogDebug(metlabel) <<
" --> Rejected. " << newDr << std::endl << std::endl;
1055 LogDebug(metlabel) <<
"Invalid offline seed TSOS after propagation!" << std::endl << std::endl;
1059 return isAssociated;