21 const string metname =
"Muon|RecoMuon|SETMuonSeedFinder";
39 return (hit_1->globalPosition().mag2() < hit_2->globalPosition().mag2());
42 const sorter sortSegRadius;
46 stable_sort(cluster.begin(), cluster.end(), sortSegRadius);
50 std::vector<MuonRecHitContainer> MuonRecHitContainer_perLayer;
51 if (!cluster.empty()) {
54 hitsInThisLayer.push_back(cluster[iHit]);
55 DetId detId = cluster[iHit]->hit()->geographicalId();
57 while (iHit <
int(cluster.size()) - 1) {
58 DetId detId_2 = cluster[iHit + 1]->hit()->geographicalId();
59 const GlobalPoint gp_nextHit = cluster[iHit + 1]->globalPosition();
62 float distanceToDetector = fabs(geomDet->
surface().
localZ(gp_nextHit));
69 bool specialCase =
false;
80 if (distanceToDetector < 0.001 ||
true == specialCase) {
81 hitsInThisLayer.push_back(cluster[iHit + 1]);
84 if (((cluster[iHit]->
isDT() && cluster[iHit + 1]->
isCSC()) ||
85 (cluster[iHit]->
isCSC() && cluster[iHit + 1]->
isDT())) &&
88 fabs(cluster[iHit + 1]->globalPosition().
mag() - cluster[iHit]->globalPosition().
mag()) < 10.) {
89 hitsInThisLayer.push_back(cluster[iHit + 1]);
91 detId = cluster[iHit + 1]->hit()->geographicalId();
93 }
else if (!specialCase) {
96 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
97 hitsInThisLayer.clear();
98 hitsInThisLayer.push_back(cluster[iHit + 1]);
99 detId = cluster[iHit + 1]->hit()->geographicalId();
105 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
107 return MuonRecHitContainer_perLayer;
111 const int maximumNumberOfCombinations = 1000000;
112 unsigned nLayers = MuonRecHitContainer_perLayer.size();
118 if (MuonRecHitContainer_perLayer.size() > 15) {
119 MuonRecHitContainer_perLayer.resize(1);
123 std::vector<double> sizeOfLayer(
nLayers);
125 double nAllCombinations = 1.;
128 sizeOfLayer.at(
i) = MuonRecHitContainer_perLayer.at(
i).size();
129 nAllCombinations *= MuonRecHitContainer_perLayer.at(
i).size();
133 while (nAllCombinations >
float(maximumNumberOfCombinations)) {
134 std::vector<double>::iterator maxEl_it = max_element(sizeOfLayer.begin(), sizeOfLayer.end());
135 int maxEl = maxEl_it - sizeOfLayer.begin();
136 nAllCombinations /= MuonRecHitContainer_perLayer.at(maxEl).size();
137 MuonRecHitContainer_perLayer.erase(MuonRecHitContainer_perLayer.begin() + maxEl);
138 sizeOfLayer.erase(sizeOfLayer.begin() + maxEl);
144 const std::vector<SETSeedFinder::MuonRecHitContainer>& MuonRecHitContainer_perLayer) {
145 std::vector<MuonRecHitContainer> allValidSets;
151 unsigned nLayers = MuonRecHitContainer_perLayer.size();
156 unsigned int iPos0 = 0;
157 std::vector<unsigned int> iLayer(12);
158 std::vector<unsigned int>
size(12);
160 size.at(iPos0) = MuonRecHitContainer_perLayer.at(iPos0).size();
161 for (iLayer[iPos0] = 0; iLayer[iPos0] <
size[iPos0]; ++iLayer[iPos0]) {
163 validSet.push_back(MuonRecHitContainer_perLayer[iPos0][iLayer[iPos0]]);
164 unsigned int iPos1 = 1;
166 size.at(iPos1) = MuonRecHitContainer_perLayer.at(iPos1).size();
167 for (iLayer[iPos1] = 0; iLayer[iPos1] <
size[iPos1]; ++iLayer[iPos1]) {
168 validSet.resize(iPos1);
169 validSet.push_back(MuonRecHitContainer_perLayer[iPos1][iLayer[iPos1]]);
170 unsigned int iPos2 = 2;
172 size.at(iPos2) = MuonRecHitContainer_perLayer.at(iPos2).size();
173 for (iLayer[iPos2] = 0; iLayer[iPos2] <
size[iPos2]; ++iLayer[iPos2]) {
174 validSet.resize(iPos2);
175 validSet.push_back(MuonRecHitContainer_perLayer[iPos2][iLayer[iPos2]]);
176 unsigned int iPos3 = 3;
178 size.at(iPos3) = MuonRecHitContainer_perLayer.at(iPos3).size();
179 for (iLayer[iPos3] = 0; iLayer[iPos3] <
size[iPos3]; ++iLayer[iPos3]) {
180 validSet.resize(iPos3);
181 validSet.push_back(MuonRecHitContainer_perLayer[iPos3][iLayer[iPos3]]);
182 unsigned int iPos4 = 4;
184 size.at(iPos4) = MuonRecHitContainer_perLayer.at(iPos4).size();
185 for (iLayer[iPos4] = 0; iLayer[iPos4] <
size[iPos4]; ++iLayer[iPos4]) {
186 validSet.resize(iPos4);
187 validSet.push_back(MuonRecHitContainer_perLayer[iPos4][iLayer[iPos4]]);
188 unsigned int iPos5 = 5;
190 size.at(iPos5) = MuonRecHitContainer_perLayer.at(iPos5).size();
191 for (iLayer[iPos5] = 0; iLayer[iPos5] <
size[iPos5]; ++iLayer[iPos5]) {
192 validSet.resize(iPos5);
193 validSet.push_back(MuonRecHitContainer_perLayer[iPos5][iLayer[iPos5]]);
194 unsigned int iPos6 = 6;
196 size.at(iPos6) = MuonRecHitContainer_perLayer.at(iPos6).size();
197 for (iLayer[iPos6] = 0; iLayer[iPos6] <
size[iPos6]; ++iLayer[iPos6]) {
198 validSet.resize(iPos6);
199 validSet.push_back(MuonRecHitContainer_perLayer[iPos6][iLayer[iPos6]]);
200 unsigned int iPos7 = 7;
202 size.at(iPos7) = MuonRecHitContainer_perLayer.at(iPos7).size();
203 for (iLayer[iPos7] = 0; iLayer[iPos7] <
size[iPos7]; ++iLayer[iPos7]) {
204 validSet.resize(iPos7);
205 validSet.push_back(MuonRecHitContainer_perLayer[iPos7][iLayer[iPos7]]);
206 unsigned int iPos8 = 8;
208 size.at(iPos8) = MuonRecHitContainer_perLayer.at(iPos8).size();
209 for (iLayer[iPos8] = 0; iLayer[iPos8] <
size[iPos8]; ++iLayer[iPos8]) {
210 validSet.resize(iPos8);
211 validSet.push_back(MuonRecHitContainer_perLayer[iPos8][iLayer[iPos8]]);
212 unsigned int iPos9 = 9;
214 size.at(iPos9) = MuonRecHitContainer_perLayer.at(iPos9).size();
215 for (iLayer[iPos9] = 0; iLayer[iPos9] <
size[iPos9]; ++iLayer[iPos9]) {
216 validSet.resize(iPos9);
217 validSet.push_back(MuonRecHitContainer_perLayer[iPos9][iLayer[iPos9]]);
218 unsigned int iPos10 = 10;
220 size.at(iPos10) = MuonRecHitContainer_perLayer.at(iPos10).size();
221 for (iLayer[iPos10] = 0; iLayer[iPos10] <
size[iPos10]; ++iLayer[iPos10]) {
222 validSet.resize(iPos10);
223 validSet.push_back(MuonRecHitContainer_perLayer[iPos10][iLayer[iPos10]]);
224 unsigned int iPos11 = 11;
226 size.at(iPos11) = MuonRecHitContainer_perLayer.at(iPos11).size();
227 for (iLayer[iPos11] = 0; iLayer[iPos11] <
size[iPos11];
231 allValidSets.push_back(validSet);
235 allValidSets.push_back(validSet);
239 allValidSets.push_back(validSet);
243 allValidSets.push_back(validSet);
247 allValidSets.push_back(validSet);
251 allValidSets.push_back(validSet);
255 allValidSets.push_back(validSet);
259 allValidSets.push_back(validSet);
263 allValidSets.push_back(validSet);
267 allValidSets.push_back(validSet);
271 allValidSets.push_back(validSet);
275 allValidSets.push_back(validSet);
289 double mult = dPhi_1 * dPhi_2;
291 if (fabs(dPhi_1) < fabs(dPhi_2)) {
297 std::pair<int, int>
sign;
298 sign = make_pair(signVal, signMult);
308 for (
unsigned int iSet = 0; iSet < allValidSets.size(); ++iSet) {
314 unsigned nHits = validSet.size();
318 std::vector<double>
dPhi;
323 for (
unsigned int iHit = 1; iHit <
nHits; ++iHit) {
324 dPhi_tmp = validSet[iHit]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
325 dPhi.push_back(dPhi_tmp);
327 std::vector<int> pruneHit;
330 for (
unsigned int iHit = 0; iHit <
nHits; ++iHit) {
331 double dPHI_MIN = 0.02;
335 wildCandidate =
false;
340 fabs(validSet[iHit]->globalPosition().
phi() - validSet[iHit - 1]->globalPosition().
phi()) > dPHI_MIN) {
341 wildCandidate =
true;
349 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
352 if (1 ==
sign.first && 1 ==
sign.second) {
356 }
else if (iHit > 1 && iHit < validSet.size() - 1) {
358 4 == validSet[1]->dimension() && pruneHit.back() !=
int(iHit - 1) &&
359 pruneHit.back() != 1) {
362 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
365 if (1 ==
sign.first && 1 ==
sign.second) {
369 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit]->globalPosition().phi();
371 if (1 ==
sign.first && 1 ==
sign.second) {
372 pruneHit_tmp = iHit - 1;
378 if (pruneHit.size() > 1 && pruneHit[pruneHit.size() - 1] < 0 && pruneHit[pruneHit.size() - 2] < 0) {
380 if (-1 ==
sign.first && -1 ==
sign.second) {
386 pruneHit.push_back(pruneHit_tmp);
391 for (
unsigned int iHit = 1; iHit <
nHits; ++iHit) {
393 if (pruneHit[iHit - 1] > 0) {
394 validSet.erase(validSet.begin() + pruneHit[iHit - 1] -
count);
406 std::vector<SeedCandidate> seedCandidates_inCluster;
409 for (
unsigned int iSet = 0; iSet < allValidSets.size(); ++iSet) {
417 CLHEP::Hep3Vector momEstimate;
424 seedCandidates_inCluster_prep.
theSet = allValidSets[iSet];
425 seedCandidates_inCluster_prep.
momentum = momEstimate;
426 seedCandidates_inCluster_prep.
charge = chargeEstimate;
427 seedCandidates_inCluster.push_back(seedCandidates_inCluster_prep);
430 return seedCandidates_inCluster;
434 CLHEP::Hep3Vector& momEstimate,
436 int firstMeasurement = -1;
437 int lastMeasurement = -1;
447 for (
unsigned int iMeas = 0; iMeas < validSet.size(); ++iMeas) {
448 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())) {
449 firstMeasurement = iMeas;
455 std::vector<double> momentum_estimate;
465 for (
int iMeas = validSet.size() - 1; iMeas > -1; --iMeas) {
466 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT()) &&
469 fabs(validSet[iMeas]->globalPosition().z()) < 1000.) {
470 lastMeasurement = iMeas;
476 for (
unsigned int iMeas = 1; iMeas < validSet.size(); ++iMeas) {
477 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())) {
478 lastMeasurement = iMeas;
484 if (-1 == lastMeasurement && -1 == firstMeasurement) {
485 firstMeasurement = 0;
486 lastMeasurement = validSet.size() - 1;
489 else if (-1 == lastMeasurement) {
490 lastMeasurement = firstMeasurement;
491 }
else if (-1 == firstMeasurement) {
492 firstMeasurement = lastMeasurement;
495 firstHit = validSet[firstMeasurement];
496 secondHit = validSet[lastMeasurement];
497 if (firstHit->isRPC() && secondHit->isRPC()) {
498 momentum_estimate.push_back(300.);
499 momentum_estimate.push_back(300.);
501 if (firstHit->isRPC()) {
502 firstHit = secondHit;
503 }
else if (secondHit->isRPC()) {
504 secondHit = firstHit;
511 if (2 == firstHit->dimension() && 2 == secondHit->dimension()) {
512 momentum_estimate.push_back(999999999.);
513 momentum_estimate.push_back(999999999.);
518 pT = fabs(momentum_estimate[0]);
519 if (
true ||
pT > 40.) {
526 const float pT_min = 1.99;
529 }
else if (
pT < pT_min) {
532 }
else if (
pT > (-1) * pT_min) {
534 }
else if (
pT < -3000.) {
541 charge = momentum_estimate[0] > 0 ? 1 : -1;
546 double xHit = validSet[firstMeasurement]->globalPosition().x();
547 double yHit = validSet[firstMeasurement]->globalPosition().y();
548 double rHit = TMath::Sqrt(
pow(xHit, 2) +
pow(yHit, 2));
550 double thetaInner = validSet[firstMeasurement]->globalPosition().theta();
555 double rTrack = (
pT / (0.3 * 3.8)) * 100.;
557 double par = -1. * (2. /
charge) * (TMath::ASin(rHit / (2 * rTrack)));
558 double sinPar = TMath::Sin(par);
559 double cosPar = TMath::Cos(par);
562 double sinPhiH = 1. / (2. *
charge * rTrack) * (xHit + ((sinPar) / (cosPar - 1.)) * yHit);
563 double cosPhiH = -1. / (2. *
charge * rTrack) * (((sinPar) / (1. - cosPar)) * xHit + yHit);
569 momEstimate = CLHEP::Hep3Vector(
pT * cosPhiH,
pT * sinPhiH,
pT / TMath::Tan(thetaInner));
571 const float minMomenum = 5.;
572 if (momEstimate.mag() < minMomenum) {
573 int sign = (
pT < 0.) ? -1 : 1;
575 CLHEP::Hep3Vector momEstimate2(
pT * cosPhiH,
pT * sinPhiH,
pT / TMath::Tan(thetaInner));
576 momEstimate = momEstimate2;
577 if (momEstimate.mag() < minMomenum) {
579 CLHEP::Hep3Vector momEstimate3(
pT * cosPhiH,
pT * sinPhiH,
pT / TMath::Tan(thetaInner));
580 momEstimate = momEstimate3;
581 if (momEstimate.mag() < minMomenum) {
583 CLHEP::Hep3Vector momEstimate4(
pT * cosPhiH,
pT * sinPhiH,
pT / TMath::Tan(thetaInner));
584 momEstimate = momEstimate4;
593 for (
unsigned int iHit = 0; iHit <
hits.size(); ++iHit) {
int station() const
Return the station number.
bool operator()(TransientTrackingRecHit::ConstRecHitPointer hit_1, TransientTrackingRecHit::ConstRecHitPointer hit_2) const
T getParameter(std::string const &) const
CLHEP::Hep3Vector momentum
std::pair< int, int > checkAngleDeviation(double dPhi_1, double dPhi_2) const
bool useSegmentsInTrajectory
bool isDT(GeomDetEnumerators::SubDetector m)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
void pre_prune(MuonRecHitContainer &validSet) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonSeedPtExtractor * thePtExtractor
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
float localZ(const GlobalPoint &gp) const
std::vector< MuonRecHitContainer > sortByLayer(MuonRecHitContainer &cluster) const
const Plane & surface() const
The nominal surface of the GeomDet.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void seeds(const MuonRecHitContainer &cluster, std::vector< TrajectorySeed > &result) override
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
MuonServiceProxy * theService
void validSetsPrePruning(std::vector< MuonRecHitContainer > &allValidSets)
bool isCSC(GeomDetEnumerators::SubDetector m)
MuonTransientTrackingRecHit::MuonRecHitContainer theSet
TrajectorySeed makeSeed(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit::ConstRecHitContainer &hits) const
std::shared_ptr< MuonTransientTrackingRecHit const > ConstMuonRecHitPointer
std::vector< SeedCandidate > fillSeedCandidates(std::vector< MuonRecHitContainer > &allValidSets)
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
void estimateMomentum(const MuonRecHitContainer &validSet, CLHEP::Hep3Vector &momentum, int &charge) const
SETSeedFinder(const edm::ParameterSet &pset)