69 : theService(nullptr),
70 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
71 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
72 theCSCSegmentsLabel(par.getParameter<
InputTag>(
"CSCSegmentLabel")),
73 theDT4DRecSegmentLabel(par.getParameter<
InputTag>(
"DT4DRecSegmentLabel")) {
88 category_ =
"MuonShowerInformationFiller";
90 for (
int istat = 0; istat < 4; istat++) {
143 for (
int istat = 0; istat < 4; istat++) {
186 for (chamberIdIt = dtSegments->id_begin(); chamberIdIt != dtSegments->id_end(); ++chamberIdIt) {
187 if (*chamberIdIt != chamberId)
194 if (iseg->dimension() != 4)
204 if ((*chamberId).chamber() != did.chamber())
211 if (iseg->dimension() != 3)
222 if (segments.empty())
223 return allhitscorrelated;
228 if (segments.size() == 1)
229 return allhitscorrelated;
231 for (MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator iseg = segments.begin() + 1;
232 iseg != segments.end();
238 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit1 = hits1.begin(); ihit1 != hits1.end();
240 bool usedbefore =
false;
243 GlobalPoint gp1dinsegHit = (*ihit1)->globalPosition();
245 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit2 = allhitscorrelated.begin();
246 ihit2 != allhitscorrelated.end();
250 GlobalPoint gp1dinsegHit2 = (*ihit2)->globalPosition();
252 if ((gp1dinsegHit2 - gp1dinsegHit).
mag() < 1.0)
256 allhitscorrelated.push_back(*ihit1);
260 return allhitscorrelated;
269 if (muonRecHits.empty())
276 stable_sort(muonRecHits.begin(), muonRecHits.end(),
AbsLessDTheta(refpoint));
278 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit = muonRecHits.begin();
279 ihit != muonRecHits.end() - 1;
281 if (fabs((*(ihit + 1))->globalPosition().
theta() - (*ihit)->globalPosition().theta()) <
step) {
296 if (muonRecHits.empty())
299 stable_sort(muonRecHits.begin(), muonRecHits.end(),
LessPerp());
301 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator seedhit =
302 min_element(muonRecHits.begin(), muonRecHits.end(),
LessPerp());
304 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator ihigh = seedhit;
305 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator ilow = seedhit;
308 while (ihigh != muonRecHits.end() - 1 &&
309 (fabs((*(ihigh + 1))->globalPosition().
perp() - (*ihigh)->globalPosition().perp()) <
step)) {
312 while (ilow != muonRecHits.begin() &&
313 (fabs((*ilow)->globalPosition().perp() - (*(ilow - 1))->globalPosition().perp()) <
step)) {
326 vector<const GeomDet*>
total;
339 vector<GlobalPoint> allCrossingPoints;
341 const vector<const DetLayer*>& dtlayers =
theService->detLayerGeometry()->allDTLayers();
343 for (
auto iLayer = dtlayers.begin(); iLayer != dtlayers.end(); ++iLayer) {
348 if ((fabs(xPoint.
y()) < 1000.0) && (fabs(xPoint.
z()) < 1500) &&
349 (!(xPoint.
y() == 0 && xPoint.
x() == 0 && xPoint.
z() == 0)))
350 allCrossingPoints.push_back(xPoint);
353 stable_sort(allCrossingPoints.begin(), allCrossingPoints.end(),
LessMag(innerPos));
355 vector<const GeomDet*> tempDT;
357 for (vector<GlobalPoint>::const_iterator ipos = allCrossingPoints.begin(); ipos != allCrossingPoints.end(); ++ipos) {
359 vector<const GeomDet*>::const_iterator
begin = tempDT.begin();
360 vector<const GeomDet*>::const_iterator
end = tempDT.end();
366 allCrossingPoints.clear();
368 const vector<const DetLayer*>& csclayers =
theService->detLayerGeometry()->allCSCLayers();
369 for (
auto iLayer = csclayers.begin(); iLayer != csclayers.end(); ++iLayer) {
373 if ((fabs(xPoint.
y()) < 1000.0) && (fabs(xPoint.
z()) < 1500.0) &&
374 (!(xPoint.
y() == 0 && xPoint.
x() == 0 && xPoint.
z() == 0)))
375 allCrossingPoints.push_back(xPoint);
377 stable_sort(allCrossingPoints.begin(), allCrossingPoints.end(),
LessMag(innerPos));
379 vector<const GeomDet*> tempCSC;
380 for (vector<GlobalPoint>::const_iterator ipos = allCrossingPoints.begin(); ipos != allCrossingPoints.end(); ++ipos) {
382 vector<const GeomDet*>::const_iterator
begin = tempCSC.begin();
383 vector<const GeomDet*>::const_iterator
end = tempCSC.end();
418 if (n1 * n1 - 4 * n2 *
n0 > 0) {
419 y1 = (-n1 +
sqrt(n1 * n1 - 4 * n2 *
n0)) / (2 * n2);
420 y2 = (-n1 -
sqrt(n1 * n1 - 4 * n2 *
n0)) / (2 * n2);
426 float slopeZ =
dp.z() /
dp.y();
428 float z1 =
p1.z() + slopeZ * (
y1 -
p1.y());
429 float z2 =
p1.z() + slopeZ * (
y2 -
p1.y());
432 if ((
p2.x() *
x1 > 0) && (
y1 *
p2.y() > 0) && (z1 *
p2.z() > 0)) {
452 float diskZ = disk.position().z();
453 int endcap = diskZ > 0 ? 1 : (diskZ < 0 ? -1 : 0);
454 diskZ = diskZ +
endcap * dynamic_cast<const SimpleDiskBounds&>(disk.bounds()).
thickness() / 2.;
458 float slopeZ =
dp.z() /
dp.y();
459 float y1 = diskZ / slopeZ;
466 if (
p2.z() * z1 > 0) {
479 if (
gp.z() < -680.0) {
482 }
else if (
gp.z() < -396.0) {
485 }
else if (
gp.z() < -126.8) {
488 }
else if (
gp.z() < 126.8) {
491 }
else if (
gp.z() < 396.0) {
494 }
else if (
gp.z() < 680.0) {
503 if (
gp.perp() > 680.0 &&
gp.perp() < 755.0)
505 else if (
gp.perp() > 580.0)
507 else if (
gp.perp() > 480.0)
509 else if (
gp.perp() > 380.0)
516 float phistep =
M_PI / 6;
518 float phigp = (
float)
gp.barePhi();
520 if (fabs(
deltaPhi(phigp, 0 * phistep)) < phistep)
522 if (fabs(
deltaPhi(phigp, phistep)) < phistep)
524 if (fabs(
deltaPhi(phigp, 2 * phistep)) < phistep)
526 if (fabs(
deltaPhi(phigp, 3 * phistep)) < phistep) {
531 if (fabs(
deltaPhi(phigp, 4 * phistep)) < phistep)
533 if (fabs(
deltaPhi(phigp, 5 * phistep)) < phistep)
535 if (fabs(
deltaPhi(phigp, 6 * phistep)) < phistep)
537 if (fabs(
deltaPhi(phigp, 7 * phistep)) < phistep)
539 if (fabs(
deltaPhi(phigp, 8 * phistep)) < phistep)
541 if (fabs(
deltaPhi(phigp, 9 * phistep)) < phistep) {
546 if (fabs(
deltaPhi(phigp, 10 * phistep)) < phistep)
548 if (fabs(
deltaPhi(phigp, 11 * phistep)) < phistep)
555 vector<const GeomDet*>
result;
558 if (minwheel > 2 || maxwheel < -2)
561 for (vector<int>::const_iterator isector =
sectors.begin(); isector !=
sectors.end(); ++isector) {
562 for (
int iwheel = minwheel; iwheel != maxwheel + 1; ++iwheel) {
589 if (fabs(
gp.z()) > 1000. && fabs(
gp.z()) < 1055.0) {
591 }
else if (fabs(
gp.z()) > 910.0 && fabs(
gp.z()) < 965.0) {
593 }
else if (fabs(
gp.z()) > 800.0 && fabs(
gp.z()) < 860.0) {
595 }
else if (fabs(
gp.z()) > 570.0 && fabs(
gp.z()) < 730.0) {
601 float phistep1 =
M_PI / 18.;
602 float phistep2 =
M_PI / 9.;
603 float phigp = (
float)
gp.barePhi();
610 if (
gp.perp() > 100 &&
gp.perp() < 270)
612 else if (
gp.perp() > 270 &&
gp.perp() < 450)
614 else if (
gp.perp() > 450 &&
gp.perp() < 695)
616 else if (
gp.perp() > 100 &&
gp.perp() < 270)
620 if (
gp.perp() > 140 &&
gp.perp() < 350)
622 else if (
gp.perp() > 350 &&
gp.perp() < 700)
626 if (
gp.perp() > 160 &&
gp.perp() < 350)
628 else if (
gp.perp() > 350 &&
gp.perp() < 700)
632 if (
gp.perp() > 175 &&
gp.perp() < 350)
634 else if (
gp.perp() > 350 &&
gp.perp() < 700)
640 for (
int i = 0;
i < 18;
i++) {
641 if (fabs(
deltaPhi(phigp,
i * phistep2)) < phistep2)
647 for (
int i = 0;
i < 36;
i++) {
648 if (fabs(
deltaPhi(phigp,
i * phistep1)) < phistep1)
660 vector<const GeomDet*>
result;
671 for (vector<int>::const_iterator isector =
sectors.begin(); isector !=
sectors.end(); ++isector) {
672 for (
int ilayer = minlayer; ilayer != maxlayer + 1; ++ilayer) {
686 if (
muon.isGlobalMuon())
688 else if (
muon.isStandAloneMuon())
694 vector<MuonRecHitContainer> muonRecHits(4);
697 vector<TransientTrackingRecHit::ConstRecHitContainer> muonCorrelatedHits(4);
704 bool dtOverlapToCheck =
false;
705 bool cscOverlapToCheck =
false;
707 for (vector<const GeomDet*>::const_iterator igd = compatibleLayers.begin(); igd != compatibleLayers.end(); igd++) {
709 DetId geoId = (*igd)->geographicalId();
720 int wheel = detid.wheel();
725 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_begin = muonCorrelatedHitsTmp.begin();
726 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_end = muonCorrelatedHitsTmp.end();
728 for (; hits_begin != hits_end; ++hits_begin) {
729 muonCorrelatedHits.at(
station - 1).push_back(*hits_begin);
734 dtOverlapToCheck =
true;
741 DTLayerId lid(detid, isuperlayer, ilayer);
744 vector<const TrackingRecHit*> subrechits = (*rechit).recHits();
745 for (vector<const TrackingRecHit*>::iterator irechit = subrechits.begin(); irechit != subrechits.end();
756 int ring = did.ring();
761 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_begin = muonCorrelatedHitsTmp.begin();
762 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_end = muonCorrelatedHitsTmp.end();
764 for (; hits_begin != hits_end; ++hits_begin) {
765 muonCorrelatedHits.at(
station - 1).push_back(*hits_begin);
768 if ((
station == 1 &&
ring == 3) && dtOverlapToCheck)
769 cscOverlapToCheck =
true;
774 if (!cscOverlapToCheck) {
785 if (
temp.size() > 1) {
786 center = (
temp.front()->globalPosition().perp() +
temp.back()->globalPosition().perp()) / 2.;
788 center =
temp.front()->globalPosition().perp();
793 muonRecHits.at(2).insert(muonRecHits.at(2).end(), tmpCSC1.begin(), tmpCSC1.end());
795 muonRecHits.at(1).insert(muonRecHits.at(1).end(), tmpCSC1.begin(), tmpCSC1.end());
823 const size_t nhit = muonRecHits[
stat].size();
826 muonRecHitsPhiBest.clear();
827 muonRecHitsPhiBest.reserve(nhit);
834 std::vector<size_t> clUppers;
835 for (
size_t ihit = 0; ihit < nhit; ++ihit) {
836 const size_t jhit = (ihit + 1) % nhit;
837 const double phi1 = muonRecHits[
stat].at(ihit)->globalPosition().barePhi();
838 const double phi2 = muonRecHits[
stat].at(jhit)->globalPosition().barePhi();
842 clUppers.push_back(ihit);
847 if (clUppers.empty()) {
849 const double refPhi = muonRecHits[
stat].at(0)->globalPosition().barePhi();
850 double dphilo = 0, dphihi = 0;
851 for (
auto&
hit : muonRecHits[
stat]) {
852 muonRecHitsPhiBest.push_back(
hit);
853 const double phi =
hit->globalPosition().barePhi();
857 dphimax =
std::abs(dphihi + dphilo);
861 size_t bestUpper = 0, bestLower = 0;
862 for (
auto icl = clUppers.begin(); icl != clUppers.end(); ++icl) {
864 const size_t upper = *icl;
866 const auto prevCl = (icl == clUppers.begin()) ? clUppers.end() : icl;
867 const size_t lower = (*(prevCl - 1) + 1) % nhit;
873 const double phi1 = muonRecHits[
stat].at(
upper)->globalPosition().barePhi();
874 const double phi2 = muonRecHits[
stat].at(lower)->globalPosition().barePhi();
877 if (dphimax < dphi) {
884 if (bestUpper > bestLower) {
885 muonRecHitsPhiBest.reserve(bestUpper - bestLower + 1);
887 muonRecHits[
stat].
begin() + bestUpper + 1,
888 std::back_inserter(muonRecHitsPhiBest));
889 }
else if (bestUpper < bestLower) {
890 muonRecHitsPhiBest.reserve(bestUpper + (nhit - bestLower) + 1);
892 muonRecHits[
stat].
begin() + bestUpper + 1,
893 std::back_inserter(muonRecHitsPhiBest));
895 muonRecHits[
stat].
begin() + bestLower, muonRecHits[
stat].
end(), std::back_inserter(muonRecHitsPhiBest));
900 if (!muonRecHitsPhiBest.empty()) {
901 muonRecHits[
stat] = muonRecHitsPhiBest;
903 muonRecHits[
stat].front();
909 if (!muonCorrelatedHits.at(
stat).empty()) {
911 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator
iseed = muonCorrelatedHits.at(
stat).begin();
912 iseed != muonCorrelatedHits.at(
stat).end();
914 if (!(*iseed)->isValid())
917 muonRecHitsThetaTemp.clear();
919 if (muonRecHitsThetaTemp.size() > 1) {
920 float dtheta = fabs((
float)muonRecHitsThetaTemp.back()->globalPosition().theta() -
921 (
float)muonRecHitsThetaTemp.front()->globalPosition().theta());
922 if (dtheta > dthetamax) {
924 muonRecHitsThetaBest = muonRecHitsThetaTemp;
931 if (muonRecHitsThetaBest.size() > 1 && muonRecHitsPhiBest.size() > 1)
933 muonRecHitsPhiBest.back()->globalPosition().barePhi()),
935 pow(muonRecHitsThetaBest.front()->globalPosition().theta() -
936 muonRecHitsThetaBest.back()->globalPosition().theta(),
941 LogTrace(
category_) <<
"deltaR around a track containing all the station hits, by station "