File indexing completed on 2024-04-06 12:28:50
0001 #include "RecoTracker/TkHitPairs/interface/RecHitsSortedInPhi.h"
0002 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0003
0004 #include <algorithm>
0005 #include <cassert>
0006
0007 RecHitsSortedInPhi::RecHitsSortedInPhi(const std::vector<Hit>& hits, GlobalPoint const& origin, DetLayer const* il)
0008 : layer(il),
0009 isBarrel(il->isBarrel()),
0010 x(hits.size()),
0011 y(hits.size()),
0012 z(hits.size()),
0013 drphi(hits.size()),
0014 u(hits.size()),
0015 v(hits.size()),
0016 du(hits.size()),
0017 dv(hits.size()),
0018 lphi(hits.size()) {
0019
0020
0021
0022
0023 theHits.reserve(hits.size());
0024 for (auto const& hp : hits)
0025 theHits.emplace_back(hp);
0026
0027 std::sort(theHits.begin(), theHits.end(), HitLessPhi());
0028
0029 for (unsigned int i = 0; i != theHits.size(); ++i) {
0030 auto const& h = *theHits[i].hit();
0031 auto const& gs = static_cast<BaseTrackerRecHit const&>(h).globalState();
0032 auto loc = gs.position - origin.basicVector();
0033 float lr = loc.perp();
0034
0035 float lz = gs.position.z();
0036 float dr = gs.errorR;
0037 float dz = gs.errorZ;
0038
0039
0040 x[i] = gs.position.x();
0041 y[i] = gs.position.y();
0042 z[i] = lz;
0043 drphi[i] = gs.errorRPhi;
0044 u[i] = isBarrel ? lr : lz;
0045 v[i] = isBarrel ? lz : lr;
0046 du[i] = isBarrel ? dr : dz;
0047 dv[i] = isBarrel ? dz : dr;
0048 lphi[i] = loc.barePhi();
0049 }
0050 }
0051
0052 RecHitsSortedInPhi::DoubleRange RecHitsSortedInPhi::doubleRange(float phiMin, float phiMax) const {
0053 Range r1, r2;
0054 if (phiMin < phiMax) {
0055 if (phiMin < -Geom::fpi()) {
0056 r1 = unsafeRange(phiMin + Geom::ftwoPi(), Geom::fpi());
0057 r2 = unsafeRange(-Geom::fpi(), phiMax);
0058 } else if (phiMax > Geom::pi()) {
0059 r1 = unsafeRange(phiMin, Geom::fpi());
0060 r2 = unsafeRange(-Geom::fpi(), phiMax - Geom::ftwoPi());
0061 } else {
0062 r1 = unsafeRange(phiMin, phiMax);
0063 r2 = Range(theHits.begin(), theHits.begin());
0064 }
0065 } else {
0066 r1 = unsafeRange(phiMin, Geom::fpi());
0067 r2 = unsafeRange(-Geom::fpi(), phiMax);
0068 }
0069
0070 return (DoubleRange){{int(r1.first - theHits.begin()),
0071 int(r1.second - theHits.begin()),
0072 int(r2.first - theHits.begin()),
0073 int(r2.second - theHits.begin())}};
0074 }
0075
0076 void RecHitsSortedInPhi::hits(float phiMin, float phiMax, std::vector<Hit>& result) const {
0077 if (phiMin < phiMax) {
0078 if (phiMin < -Geom::fpi()) {
0079 copyResult(unsafeRange(phiMin + Geom::ftwoPi(), Geom::fpi()), result);
0080 copyResult(unsafeRange(-Geom::fpi(), phiMax), result);
0081 } else if (phiMax > Geom::pi()) {
0082 copyResult(unsafeRange(phiMin, Geom::fpi()), result);
0083 copyResult(unsafeRange(-Geom::fpi(), phiMax - Geom::ftwoPi()), result);
0084 } else {
0085 copyResult(unsafeRange(phiMin, phiMax), result);
0086 }
0087 } else {
0088 copyResult(unsafeRange(phiMin, Geom::fpi()), result);
0089 copyResult(unsafeRange(-Geom::fpi(), phiMax), result);
0090 }
0091 }
0092
0093 std::vector<RecHitsSortedInPhi::Hit> RecHitsSortedInPhi::hits(float phiMin, float phiMax) const {
0094 std::vector<Hit> result;
0095 hits(phiMin, phiMax, result);
0096 return result;
0097 }
0098
0099 RecHitsSortedInPhi::Range RecHitsSortedInPhi::unsafeRange(float phiMin, float phiMax) const {
0100 auto low = std::lower_bound(theHits.begin(), theHits.end(), HitWithPhi(phiMin), HitLessPhi());
0101 return Range(low, std::upper_bound(low, theHits.end(), HitWithPhi(phiMax), HitLessPhi()));
0102 }