84 template <
typename RandomAccessSequence,
typename Predicate,
typename Transform>
85 RandomAccessSequence sort_all_indexed(
const RandomAccessSequence&
s, Predicate
p, Transform
t) {
86 std::vector<size_t>
idx(
s.size());
87 std::iota(
idx.begin(),
idx.end(), 0);
90 using valueCacheType = std::invoke_result_t<decltype(t), typename RandomAccessSequence::value_type>;
91 std::vector<valueCacheType> valcache(
s.size());
95 auto idxComp = [&valcache,
p](
auto i1,
auto i2) {
return p(valcache[
i1], valcache[
i2]); };
96 std::stable_sort(
idx.begin(),
idx.end(), idxComp);
99 RandomAccessSequence
r(
s.size());
100 for (
size_t i = 0;
i <
s.size(); ++
i) {
111 : theService(nullptr),
112 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
113 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
114 theCSCSegmentsLabel(par.getParameter<
InputTag>(
"CSCSegmentLabel")),
115 theDT4DRecSegmentLabel(par.getParameter<
InputTag>(
"DT4DRecSegmentLabel")) {
130 auto trackerRecHitBuilderName = par.
getParameter<
string>(
"TrackerRecHitBuilder");
132 auto muonRecHitBuilderName = par.
getParameter<
string>(
"MuonRecHitBuilder");
138 category_ =
"MuonShowerInformationFiller";
140 for (
int istat = 0; istat < 4; istat++) {
193 for (
int istat = 0; istat < 4; istat++) {
236 for (chamberIdIt = dtSegments->id_begin(); chamberIdIt != dtSegments->id_end(); ++chamberIdIt) {
237 if (*chamberIdIt != chamberId)
244 if (iseg->dimension() != 4)
254 if ((*chamberId).chamber() != did.chamber())
261 if (iseg->dimension() != 3)
272 if (segments.empty())
273 return allhitscorrelated;
278 if (segments.size() == 1)
279 return allhitscorrelated;
281 for (MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator iseg = segments.begin() + 1;
282 iseg != segments.end();
288 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit1 = hits1.begin(); ihit1 != hits1.end();
290 bool usedbefore =
false;
293 GlobalPoint gp1dinsegHit = (*ihit1)->globalPosition();
295 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit2 = allhitscorrelated.begin();
296 ihit2 != allhitscorrelated.end();
300 GlobalPoint gp1dinsegHit2 = (*ihit2)->globalPosition();
302 if ((gp1dinsegHit2 - gp1dinsegHit).
mag() < 1.0)
306 allhitscorrelated.push_back(*ihit1);
310 return allhitscorrelated;
319 if (muonRecHitsIn.empty())
320 return muonRecHitsIn;
326 auto muonRecHitsTmp = sort_all_indexed(muonRecHitsIn, std::less(),
AbsDThetaTransform(refpoint));
328 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit = muonRecHitsTmp.begin();
329 ihit != muonRecHitsTmp.end() - 1;
331 if (fabs((*(ihit + 1))->globalPosition().
theta() - (*ihit)->globalPosition().theta()) <
step) {
346 if (muonRecHitsIn.empty())
347 return muonRecHitsIn;
349 auto muonRecHitsTmp = sort_all_indexed(muonRecHitsIn, std::less(),
PerpTransform());
351 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator seedhit =
352 min_element(muonRecHitsTmp.begin(), muonRecHitsTmp.end(),
LessPerp());
354 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator ihigh = seedhit;
355 MuonTransientTrackingRecHit::MuonRecHitContainer::const_iterator ilow = seedhit;
358 while (ihigh != muonRecHitsTmp.end() - 1 &&
359 (fabs((*(ihigh + 1))->globalPosition().
perp() - (*ihigh)->globalPosition().perp()) <
step)) {
362 while (ilow != muonRecHitsTmp.begin() &&
363 (fabs((*ilow)->globalPosition().perp() - (*(ilow - 1))->globalPosition().perp()) <
step)) {
376 vector<const GeomDet*>
total;
389 vector<GlobalPoint> allCrossingPoints;
391 const vector<const DetLayer*>& dtlayers =
theService->detLayerGeometry()->allDTLayers();
393 for (
auto iLayer = dtlayers.begin(); iLayer != dtlayers.end(); ++iLayer) {
398 if ((fabs(xPoint.
y()) < 1000.0) && (fabs(xPoint.
z()) < 1500) &&
399 (!(xPoint.
y() == 0 && xPoint.
x() == 0 && xPoint.
z() == 0)))
400 allCrossingPoints.push_back(xPoint);
403 allCrossingPoints = sort_all_indexed(allCrossingPoints, std::less(),
MagTransform(innerPos));
405 vector<const GeomDet*> tempDT;
407 for (vector<GlobalPoint>::const_iterator ipos = allCrossingPoints.begin(); ipos != allCrossingPoints.end(); ++ipos) {
409 vector<const GeomDet*>::const_iterator begin = tempDT.begin();
410 vector<const GeomDet*>::const_iterator
end = tempDT.end();
412 for (; begin !=
end; ++begin) {
413 total.push_back(*begin);
416 allCrossingPoints.clear();
418 const vector<const DetLayer*>& csclayers =
theService->detLayerGeometry()->allCSCLayers();
419 for (
auto iLayer = csclayers.begin(); iLayer != csclayers.end(); ++iLayer) {
423 if ((fabs(xPoint.
y()) < 1000.0) && (fabs(xPoint.
z()) < 1500.0) &&
424 (!(xPoint.
y() == 0 && xPoint.
x() == 0 && xPoint.
z() == 0)))
425 allCrossingPoints.push_back(xPoint);
427 allCrossingPoints = sort_all_indexed(allCrossingPoints, std::less(),
MagTransform(innerPos));
429 vector<const GeomDet*> tempCSC;
430 for (vector<GlobalPoint>::const_iterator ipos = allCrossingPoints.begin(); ipos != allCrossingPoints.end(); ++ipos) {
432 vector<const GeomDet*>::const_iterator begin = tempCSC.begin();
433 vector<const GeomDet*>::const_iterator
end = tempCSC.end();
435 for (; begin !=
end; ++begin) {
436 total.push_back(*begin);
468 if (n1 * n1 - 4 * n2 *
n0 > 0) {
469 y1 = (-n1 +
sqrt(n1 * n1 - 4 * n2 *
n0)) / (2 * n2);
470 y2 = (-n1 -
sqrt(n1 * n1 - 4 * n2 *
n0)) / (2 * n2);
476 float slopeZ =
dp.z() /
dp.y();
478 float z1 =
p1.z() + slopeZ * (
y1 -
p1.y());
479 float z2 =
p1.z() + slopeZ * (
y2 -
p1.y());
482 if ((
p2.x() *
x1 > 0) && (
y1 *
p2.y() > 0) && (z1 *
p2.z() > 0)) {
502 float diskZ = disk.position().z();
503 int endcap = diskZ > 0 ? 1 : (diskZ < 0 ? -1 : 0);
508 float slopeZ =
dp.z() /
dp.y();
509 float y1 = diskZ / slopeZ;
516 if (
p2.z() * z1 > 0) {
529 if (
gp.z() < -680.0) {
532 }
else if (
gp.z() < -396.0) {
535 }
else if (
gp.z() < -126.8) {
538 }
else if (
gp.z() < 126.8) {
541 }
else if (
gp.z() < 396.0) {
544 }
else if (
gp.z() < 680.0) {
553 if (
gp.perp() > 680.0 &&
gp.perp() < 755.0)
555 else if (
gp.perp() > 580.0)
557 else if (
gp.perp() > 480.0)
559 else if (
gp.perp() > 380.0)
566 float phistep =
M_PI / 6;
568 float phigp = (
float)
gp.barePhi();
570 if (fabs(
deltaPhi(phigp, 0 * phistep)) < phistep)
572 if (fabs(
deltaPhi(phigp, phistep)) < phistep)
574 if (fabs(
deltaPhi(phigp, 2 * phistep)) < phistep)
576 if (fabs(
deltaPhi(phigp, 3 * phistep)) < phistep) {
581 if (fabs(
deltaPhi(phigp, 4 * phistep)) < phistep)
583 if (fabs(
deltaPhi(phigp, 5 * phistep)) < phistep)
585 if (fabs(
deltaPhi(phigp, 6 * phistep)) < phistep)
587 if (fabs(
deltaPhi(phigp, 7 * phistep)) < phistep)
589 if (fabs(
deltaPhi(phigp, 8 * phistep)) < phistep)
591 if (fabs(
deltaPhi(phigp, 9 * phistep)) < phistep) {
596 if (fabs(
deltaPhi(phigp, 10 * phistep)) < phistep)
598 if (fabs(
deltaPhi(phigp, 11 * phistep)) < phistep)
605 vector<const GeomDet*>
result;
608 if (minwheel > 2 || maxwheel < -2)
611 for (vector<int>::const_iterator isector =
sectors.begin(); isector !=
sectors.end(); ++isector) {
612 for (
int iwheel = minwheel; iwheel != maxwheel + 1; ++iwheel) {
639 if (fabs(
gp.z()) > 1000. && fabs(
gp.z()) < 1055.0) {
641 }
else if (fabs(
gp.z()) > 910.0 && fabs(
gp.z()) < 965.0) {
643 }
else if (fabs(
gp.z()) > 800.0 && fabs(
gp.z()) < 860.0) {
645 }
else if (fabs(
gp.z()) > 570.0 && fabs(
gp.z()) < 730.0) {
651 float phistep1 =
M_PI / 18.;
652 float phistep2 =
M_PI / 9.;
653 float phigp = (
float)
gp.barePhi();
660 if (
gp.perp() > 100 &&
gp.perp() < 270)
662 else if (
gp.perp() > 270 &&
gp.perp() < 450)
664 else if (
gp.perp() > 450 &&
gp.perp() < 695)
666 else if (
gp.perp() > 100 &&
gp.perp() < 270)
670 if (
gp.perp() > 140 &&
gp.perp() < 350)
672 else if (
gp.perp() > 350 &&
gp.perp() < 700)
676 if (
gp.perp() > 160 &&
gp.perp() < 350)
678 else if (
gp.perp() > 350 &&
gp.perp() < 700)
682 if (
gp.perp() > 175 &&
gp.perp() < 350)
684 else if (
gp.perp() > 350 &&
gp.perp() < 700)
690 for (
int i = 0;
i < 18;
i++) {
691 if (fabs(
deltaPhi(phigp,
i * phistep2)) < phistep2)
697 for (
int i = 0;
i < 36;
i++) {
698 if (fabs(
deltaPhi(phigp,
i * phistep1)) < phistep1)
710 vector<const GeomDet*>
result;
721 for (vector<int>::const_iterator isector =
sectors.begin(); isector !=
sectors.end(); ++isector) {
722 for (
int ilayer = minlayer; ilayer != maxlayer + 1; ++ilayer) {
736 if (
muon.isGlobalMuon())
738 else if (
muon.isStandAloneMuon())
744 vector<MuonRecHitContainer> muonRecHits(4);
747 vector<TransientTrackingRecHit::ConstRecHitContainer> muonCorrelatedHits(4);
754 bool dtOverlapToCheck =
false;
755 bool cscOverlapToCheck =
false;
757 for (vector<const GeomDet*>::const_iterator igd = compatibleLayers.begin(); igd != compatibleLayers.end(); igd++) {
759 DetId geoId = (*igd)->geographicalId();
770 int wheel = detid.wheel();
775 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_begin = muonCorrelatedHitsTmp.begin();
776 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_end = muonCorrelatedHitsTmp.end();
778 for (; hits_begin != hits_end; ++hits_begin) {
779 muonCorrelatedHits.at(
station - 1).push_back(*hits_begin);
784 dtOverlapToCheck =
true;
791 DTLayerId lid(detid, isuperlayer, ilayer);
794 vector<const TrackingRecHit*> subrechits = (*rechit).recHits();
795 for (vector<const TrackingRecHit*>::iterator irechit = subrechits.begin(); irechit != subrechits.end();
806 int ring = did.ring();
811 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_begin = muonCorrelatedHitsTmp.begin();
812 TransientTrackingRecHit::ConstRecHitContainer::const_iterator hits_end = muonCorrelatedHitsTmp.end();
814 for (; hits_begin != hits_end; ++hits_begin) {
815 muonCorrelatedHits.at(
station - 1).push_back(*hits_begin);
818 if ((
station == 1 &&
ring == 3) && dtOverlapToCheck)
819 cscOverlapToCheck =
true;
824 if (!cscOverlapToCheck) {
835 if (
temp.size() > 1) {
836 center = (
temp.front()->globalPosition().perp() +
temp.back()->globalPosition().perp()) / 2.;
838 center =
temp.front()->globalPosition().perp();
843 muonRecHits.at(2).insert(muonRecHits.at(2).end(), tmpCSC1.begin(), tmpCSC1.end());
845 muonRecHits.at(1).insert(muonRecHits.at(1).end(), tmpCSC1.begin(), tmpCSC1.end());
873 const size_t nhit = muonRecHits[
stat].size();
876 muonRecHitsPhiBest.clear();
877 muonRecHitsPhiBest.reserve(nhit);
884 std::vector<size_t> clUppers;
885 for (
size_t ihit = 0; ihit < nhit; ++ihit) {
886 const size_t jhit = (ihit + 1) % nhit;
887 const double phi1 = muonRecHits[
stat].at(ihit)->globalPosition().barePhi();
888 const double phi2 = muonRecHits[
stat].at(jhit)->globalPosition().barePhi();
892 clUppers.push_back(ihit);
897 if (clUppers.empty()) {
899 const double refPhi = muonRecHits[
stat].at(0)->globalPosition().barePhi();
900 double dphilo = 0, dphihi = 0;
901 for (
auto&
hit : muonRecHits[
stat]) {
902 muonRecHitsPhiBest.push_back(
hit);
903 const double phi =
hit->globalPosition().barePhi();
907 dphimax =
std::abs(dphihi + dphilo);
911 size_t bestUpper = 0, bestLower = 0;
912 for (
auto icl = clUppers.begin(); icl != clUppers.end(); ++icl) {
914 const size_t upper = *icl;
916 const auto prevCl = (icl == clUppers.begin()) ? clUppers.end() : icl;
917 const size_t lower = (*(prevCl - 1) + 1) % nhit;
923 const double phi1 = muonRecHits[
stat].at(upper)->globalPosition().barePhi();
924 const double phi2 = muonRecHits[
stat].at(lower)->globalPosition().barePhi();
927 if (dphimax < dphi) {
934 if (bestUpper > bestLower) {
935 muonRecHitsPhiBest.reserve(bestUpper - bestLower + 1);
937 muonRecHits[
stat].begin() + bestUpper + 1,
938 std::back_inserter(muonRecHitsPhiBest));
939 }
else if (bestUpper < bestLower) {
940 muonRecHitsPhiBest.reserve(bestUpper + (nhit - bestLower) + 1);
942 muonRecHits[
stat].begin() + bestUpper + 1,
943 std::back_inserter(muonRecHitsPhiBest));
945 muonRecHits[
stat].begin() + bestLower, muonRecHits[
stat].
end(), std::back_inserter(muonRecHitsPhiBest));
950 if (!muonRecHitsPhiBest.empty()) {
957 if (!muonCorrelatedHits.at(
stat).empty()) {
959 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator
iseed = muonCorrelatedHits.at(
stat).begin();
960 iseed != muonCorrelatedHits.at(
stat).end();
962 if (!(*iseed)->isValid())
965 muonRecHitsThetaTemp.clear();
967 if (muonRecHitsThetaTemp.size() > 1) {
968 float dtheta = fabs((
float)muonRecHitsThetaTemp.back()->globalPosition().theta() -
969 (
float)muonRecHitsThetaTemp.front()->globalPosition().theta());
970 if (dtheta > dthetamax) {
972 muonRecHitsThetaBest = muonRecHitsThetaTemp;
979 if (muonRecHitsThetaBest.size() > 1 && muonRecHitsPhiBest.size() > 1)
981 muonRecHitsPhiBest.back()->globalPosition().barePhi()),
983 pow(muonRecHitsThetaBest.front()->globalPosition().theta() -
984 muonRecHitsThetaBest.back()->globalPosition().theta(),
989 LogTrace(
category_) <<
"deltaR around a track containing all the station hits, by station "
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::pair< const_iterator, const_iterator > range
iterator range
static const double slope[3]
Global3DPoint GlobalPoint
std::vector< int > nStationHits
number of all the muon RecHits per chamber crossed by a track (1D hits)
constexpr Detector det() const
get the detector field from this detid
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
C::const_iterator const_iterator
constant access iterator type
std::vector< int > nStationCorrelatedHits
number of the muon RecHits used by segments per chamber crossed by a track
GlobalPoint globalPosition() const
static const int maxLayerId
highest layer id
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Abs< T >::type abs(const T &t)
static const int minLayerId
lowest layer id. 0 indicates a full SL
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static const int maxSuperLayerId
highest superlayer id
DetId geographicalId() const
The label of this GeomDet.
T perp() const
Magnitude of transverse component.
std::vector< ConstRecHitPointer > ConstRecHitContainer
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
constexpr uint32_t rawId() const
get the raw id
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
static const int minSuperLayerId
loweset super layer id. 0 indicates a full chamber
Scalar radius() const
Radius of the cylinder.
std::vector< float > stationShowerSizeT
the transverse size of the hit cluster
virtual const BoundDisk & specificSurface() const final
Geom::Theta< T > theta() const
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
Power< A, B >::type pow(const A &a, const B &b)
std::vector< float > stationShowerDeltaR
the radius of the cone containing the all the hits around the track