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();
92 geomDet =
theService->trackingGeometry()->idToDet(detId);
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();
100 geomDet =
theService->trackingGeometry()->idToDet(detId);
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.;
126 for (
unsigned int i = 0;
i < nLayers; ++
i) {
128 sizeOfLayer.at(
i) = MuonRecHitContainer_perLayer.at(
i).size();
129 nAllCombinations *= MuonRecHitContainer_perLayer.at(
i).size();
134 while (nAllCombinations >
float(maximumNumberOfCombinations)) {
136 std::vector<double>::iterator maxEl_it = max_element(sizeOfLayer.begin(), sizeOfLayer.end());
137 int maxEl = maxEl_it - sizeOfLayer.begin();
138 nAllCombinations /= MuonRecHitContainer_perLayer.at(maxEl).size();
140 MuonRecHitContainer_perLayer.erase(MuonRecHitContainer_perLayer.begin() + maxEl);
141 sizeOfLayer.erase(sizeOfLayer.begin() + maxEl);
147 const std::vector<SETSeedFinder::MuonRecHitContainer>& MuonRecHitContainer_perLayer) {
148 std::vector<MuonRecHitContainer> allValidSets;
154 unsigned nLayers = MuonRecHitContainer_perLayer.size();
159 unsigned int iPos0 = 0;
160 std::vector<unsigned int> iLayer(12);
161 std::vector<unsigned int>
size(12);
162 if (iPos0 < nLayers) {
163 size.at(iPos0) = MuonRecHitContainer_perLayer.at(iPos0).size();
164 for (iLayer[iPos0] = 0; iLayer[iPos0] < size[iPos0]; ++iLayer[iPos0]) {
166 validSet.push_back(MuonRecHitContainer_perLayer[iPos0][iLayer[iPos0]]);
167 unsigned int iPos1 = 1;
168 if (iPos1 < nLayers) {
169 size.at(iPos1) = MuonRecHitContainer_perLayer.at(iPos1).size();
170 for (iLayer[iPos1] = 0; iLayer[iPos1] < size[iPos1]; ++iLayer[iPos1]) {
171 validSet.resize(iPos1);
172 validSet.push_back(MuonRecHitContainer_perLayer[iPos1][iLayer[iPos1]]);
173 unsigned int iPos2 = 2;
174 if (iPos2 < nLayers) {
175 size.at(iPos2) = MuonRecHitContainer_perLayer.at(iPos2).size();
176 for (iLayer[iPos2] = 0; iLayer[iPos2] < size[iPos2]; ++iLayer[iPos2]) {
177 validSet.resize(iPos2);
178 validSet.push_back(MuonRecHitContainer_perLayer[iPos2][iLayer[iPos2]]);
179 unsigned int iPos3 = 3;
180 if (iPos3 < nLayers) {
181 size.at(iPos3) = MuonRecHitContainer_perLayer.at(iPos3).size();
182 for (iLayer[iPos3] = 0; iLayer[iPos3] < size[iPos3]; ++iLayer[iPos3]) {
183 validSet.resize(iPos3);
184 validSet.push_back(MuonRecHitContainer_perLayer[iPos3][iLayer[iPos3]]);
185 unsigned int iPos4 = 4;
186 if (iPos4 < nLayers) {
187 size.at(iPos4) = MuonRecHitContainer_perLayer.at(iPos4).size();
188 for (iLayer[iPos4] = 0; iLayer[iPos4] < size[iPos4]; ++iLayer[iPos4]) {
189 validSet.resize(iPos4);
190 validSet.push_back(MuonRecHitContainer_perLayer[iPos4][iLayer[iPos4]]);
191 unsigned int iPos5 = 5;
192 if (iPos5 < nLayers) {
193 size.at(iPos5) = MuonRecHitContainer_perLayer.at(iPos5).size();
194 for (iLayer[iPos5] = 0; iLayer[iPos5] < size[iPos5]; ++iLayer[iPos5]) {
195 validSet.resize(iPos5);
196 validSet.push_back(MuonRecHitContainer_perLayer[iPos5][iLayer[iPos5]]);
197 unsigned int iPos6 = 6;
198 if (iPos6 < nLayers) {
199 size.at(iPos6) = MuonRecHitContainer_perLayer.at(iPos6).size();
200 for (iLayer[iPos6] = 0; iLayer[iPos6] < size[iPos6]; ++iLayer[iPos6]) {
201 validSet.resize(iPos6);
202 validSet.push_back(MuonRecHitContainer_perLayer[iPos6][iLayer[iPos6]]);
203 unsigned int iPos7 = 7;
204 if (iPos7 < nLayers) {
205 size.at(iPos7) = MuonRecHitContainer_perLayer.at(iPos7).size();
206 for (iLayer[iPos7] = 0; iLayer[iPos7] < size[iPos7]; ++iLayer[iPos7]) {
207 validSet.resize(iPos7);
208 validSet.push_back(MuonRecHitContainer_perLayer[iPos7][iLayer[iPos7]]);
209 unsigned int iPos8 = 8;
210 if (iPos8 < nLayers) {
211 size.at(iPos8) = MuonRecHitContainer_perLayer.at(iPos8).size();
212 for (iLayer[iPos8] = 0; iLayer[iPos8] < size[iPos8]; ++iLayer[iPos8]) {
213 validSet.resize(iPos8);
214 validSet.push_back(MuonRecHitContainer_perLayer[iPos8][iLayer[iPos8]]);
215 unsigned int iPos9 = 9;
216 if (iPos9 < nLayers) {
217 size.at(iPos9) = MuonRecHitContainer_perLayer.at(iPos9).size();
218 for (iLayer[iPos9] = 0; iLayer[iPos9] < size[iPos9]; ++iLayer[iPos9]) {
219 validSet.resize(iPos9);
220 validSet.push_back(MuonRecHitContainer_perLayer[iPos9][iLayer[iPos9]]);
221 unsigned int iPos10 = 10;
222 if (iPos10 < nLayers) {
223 size.at(iPos10) = MuonRecHitContainer_perLayer.at(iPos10).size();
224 for (iLayer[iPos10] = 0; iLayer[iPos10] < size[iPos10]; ++iLayer[iPos10]) {
225 validSet.resize(iPos10);
226 validSet.push_back(MuonRecHitContainer_perLayer[iPos10][iLayer[iPos10]]);
227 unsigned int iPos11 = 11;
228 if (iPos11 < nLayers) {
229 size.at(iPos11) = MuonRecHitContainer_perLayer.at(iPos11).size();
230 for (iLayer[iPos11] = 0; iLayer[iPos11] < size[iPos11];
234 allValidSets.push_back(validSet);
238 allValidSets.push_back(validSet);
242 allValidSets.push_back(validSet);
246 allValidSets.push_back(validSet);
250 allValidSets.push_back(validSet);
254 allValidSets.push_back(validSet);
258 allValidSets.push_back(validSet);
262 allValidSets.push_back(validSet);
266 allValidSets.push_back(validSet);
270 allValidSets.push_back(validSet);
274 allValidSets.push_back(validSet);
278 allValidSets.push_back(validSet);
292 double mult = dPhi_1 * dPhi_2;
294 if (fabs(dPhi_1) < fabs(dPhi_2)) {
300 std::pair<int, int>
sign;
301 sign = make_pair(signVal, signMult);
311 for (
unsigned int iSet = 0; iSet < allValidSets.size(); ++iSet) {
317 unsigned nHits = validSet.size();
321 std::vector<double> dPhi;
326 for (
unsigned int iHit = 1; iHit <
nHits; ++iHit) {
327 dPhi_tmp = validSet[iHit]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
328 dPhi.push_back(dPhi_tmp);
330 std::vector<int> pruneHit;
333 for (
unsigned int iHit = 0; iHit <
nHits; ++iHit) {
334 double dPHI_MIN = 0.02;
338 wildCandidate =
false;
343 fabs(validSet[iHit]->globalPosition().
phi() - validSet[iHit - 1]->globalPosition().
phi()) > dPHI_MIN) {
344 wildCandidate =
true;
352 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
355 if (1 == sign.first && 1 == sign.second) {
359 }
else if (iHit > 1 && iHit < validSet.size() - 1) {
361 4 == validSet[1]->dimension() && pruneHit.back() != int(iHit - 1) &&
362 pruneHit.back() != 1) {
365 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit - 1]->globalPosition().phi();
368 if (1 == sign.first && 1 == sign.second) {
372 dPhi_tmp = validSet[iHit + 1]->globalPosition().phi() - validSet[iHit]->globalPosition().phi();
374 if (1 == sign.first && 1 == sign.second) {
375 pruneHit_tmp = iHit - 1;
381 if (pruneHit.size() > 1 && pruneHit[pruneHit.size() - 1] < 0 && pruneHit[pruneHit.size() - 2] < 0) {
383 if (-1 == sign.first && -1 == sign.second) {
389 pruneHit.push_back(pruneHit_tmp);
394 for (
unsigned int iHit = 1; iHit <
nHits; ++iHit) {
396 if (pruneHit[iHit - 1] > 0) {
397 validSet.erase(validSet.begin() + pruneHit[iHit - 1] -
count);
409 std::vector<SeedCandidate> seedCandidates_inCluster;
412 for (
unsigned int iSet = 0; iSet < allValidSets.size(); ++iSet) {
420 CLHEP::Hep3Vector momEstimate;
427 seedCandidates_inCluster_prep.
theSet = allValidSets[iSet];
428 seedCandidates_inCluster_prep.
momentum = momEstimate;
429 seedCandidates_inCluster_prep.
charge = chargeEstimate;
430 seedCandidates_inCluster.push_back(seedCandidates_inCluster_prep);
433 return seedCandidates_inCluster;
437 CLHEP::Hep3Vector& momEstimate,
439 int firstMeasurement = -1;
440 int lastMeasurement = -1;
450 for (
unsigned int iMeas = 0; iMeas < validSet.size(); ++iMeas) {
451 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())) {
452 firstMeasurement = iMeas;
458 std::vector<double> momentum_estimate;
468 for (
int iMeas = validSet.size() - 1; iMeas > -1; --iMeas) {
469 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT()) &&
472 fabs(validSet[iMeas]->globalPosition().z()) < 1000.) {
473 lastMeasurement = iMeas;
479 for (
unsigned int iMeas = 1; iMeas < validSet.size(); ++iMeas) {
480 if (4 == validSet[iMeas]->
dimension() && (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())) {
481 lastMeasurement = iMeas;
487 if (-1 == lastMeasurement && -1 == firstMeasurement) {
488 firstMeasurement = 0;
489 lastMeasurement = validSet.size() - 1;
492 else if (-1 == lastMeasurement) {
493 lastMeasurement = firstMeasurement;
494 }
else if (-1 == firstMeasurement) {
495 firstMeasurement = lastMeasurement;
498 firstHit = validSet[firstMeasurement];
499 secondHit = validSet[lastMeasurement];
500 if (firstHit->isRPC() && secondHit->isRPC()) {
501 momentum_estimate.push_back(300.);
502 momentum_estimate.push_back(300.);
504 if (firstHit->isRPC()) {
505 firstHit = secondHit;
506 }
else if (secondHit->isRPC()) {
507 secondHit = firstHit;
514 if (2 == firstHit->dimension() && 2 == secondHit->dimension()) {
515 momentum_estimate.push_back(999999999.);
516 momentum_estimate.push_back(999999999.);
521 pT = fabs(momentum_estimate[0]);
522 if (
true || pT > 40.) {
529 const float pT_min = 1.99;
532 }
else if (pT < pT_min) {
535 }
else if (pT > (-1) * pT_min) {
537 }
else if (pT < -3000.) {
544 charge = momentum_estimate[0] > 0 ? 1 : -1;
549 double xHit = validSet[firstMeasurement]->globalPosition().x();
550 double yHit = validSet[firstMeasurement]->globalPosition().y();
551 double rHit = TMath::Sqrt(
pow(xHit, 2) +
pow(yHit, 2));
553 double thetaInner = validSet[firstMeasurement]->globalPosition().theta();
558 double rTrack = (pT / (0.3 * 3.8)) * 100.;
560 double par = -1. * (2. /
charge) * (TMath::ASin(rHit / (2 * rTrack)));
561 double sinPar = TMath::Sin(par);
562 double cosPar = TMath::Cos(par);
565 double sinPhiH = 1. / (2. * charge * rTrack) * (xHit + ((sinPar) / (cosPar - 1.)) * yHit);
566 double cosPhiH = -1. / (2. * charge * rTrack) * (((sinPar) / (1. - cosPar)) * xHit + yHit);
572 momEstimate = CLHEP::Hep3Vector(pT * cosPhiH, pT * sinPhiH, pT / TMath::Tan(thetaInner));
574 const float minMomenum = 5.;
575 if (momEstimate.mag() < minMomenum) {
576 int sign = (pT < 0.) ? -1 : 1;
577 pT = sign * (fabs(pT) + 1);
578 CLHEP::Hep3Vector momEstimate2(pT * cosPhiH, pT * sinPhiH, pT / TMath::Tan(thetaInner));
579 momEstimate = momEstimate2;
580 if (momEstimate.mag() < minMomenum) {
581 pT = sign * (fabs(pT) + 1);
582 CLHEP::Hep3Vector momEstimate3(pT * cosPhiH, pT * sinPhiH, pT / TMath::Tan(thetaInner));
583 momEstimate = momEstimate3;
584 if (momEstimate.mag() < minMomenum) {
585 pT = sign * (fabs(pT) + 1);
586 CLHEP::Hep3Vector momEstimate4(pT * cosPhiH, pT * sinPhiH, pT / TMath::Tan(thetaInner));
587 momEstimate = momEstimate4;
596 for (
unsigned int iHit = 0; iHit < hits.size(); ++iHit) {
597 recHitsContainer.
push_back(hits.at(iHit)->hit()->clone());
const std::string metname
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
CLHEP::Hep3Vector momentum
std::pair< int, int > checkAngleDeviation(double dPhi_1, double dPhi_2) const
float localZ(const GlobalPoint &gp) const
void pre_prune(MuonRecHitContainer &validSet) const
bool useSegmentsInTrajectory
TrajectorySeed makeSeed(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit::ConstRecHitContainer &hits) const
bool isDT(GeomDetEnumerators::SubDetector m)
const Plane & surface() const
The nominal surface of the GeomDet.
std::vector< MuonRecHitContainer > sortByLayer(MuonRecHitContainer &cluster) const
void estimateMomentum(const MuonRecHitContainer &validSet, CLHEP::Hep3Vector &momentum, int &charge) const
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool operator()(TransientTrackingRecHit::ConstRecHitPointer hit_1, TransientTrackingRecHit::ConstRecHitPointer hit_2) const
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonSeedPtExtractor * thePtExtractor
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
void seeds(const MuonRecHitContainer &cluster, std::vector< TrajectorySeed > &result) override
T getParameter(std::string const &) const
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
MuonServiceProxy * theService
void validSetsPrePruning(std::vector< MuonRecHitContainer > &allValidSets)
bool isCSC(GeomDetEnumerators::SubDetector m)
MuonTransientTrackingRecHit::MuonRecHitContainer theSet
std::shared_ptr< MuonTransientTrackingRecHit const > ConstMuonRecHitPointer
std::vector< SeedCandidate > fillSeedCandidates(std::vector< MuonRecHitContainer > &allValidSets)
int station() const
Return the station number.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
SETSeedFinder(const edm::ParameterSet &pset)
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)