-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathRecHitsSortedInPhi.cc
102 lines (92 loc) · 3.48 KB
/
RecHitsSortedInPhi.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "RecoTracker/TkHitPairs/interface/RecHitsSortedInPhi.h"
#include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
#include <algorithm>
#include <cassert>
RecHitsSortedInPhi::RecHitsSortedInPhi(const std::vector<Hit>& hits, GlobalPoint const& origin, DetLayer const* il)
: layer(il),
isBarrel(il->isBarrel()),
x(hits.size()),
y(hits.size()),
z(hits.size()),
drphi(hits.size()),
u(hits.size()),
v(hits.size()),
du(hits.size()),
dv(hits.size()),
lphi(hits.size()) {
// standard region have origin as 0,0,z (not true!!!!0
// cosmic region never used here
// assert(origin.x()==0 && origin.y()==0);
theHits.reserve(hits.size());
for (auto const& hp : hits)
theHits.emplace_back(hp);
std::sort(theHits.begin(), theHits.end(), HitLessPhi());
for (unsigned int i = 0; i != theHits.size(); ++i) {
auto const& h = *theHits[i].hit();
auto const& gs = static_cast<BaseTrackerRecHit const&>(h).globalState();
auto loc = gs.position - origin.basicVector();
float lr = loc.perp();
// float lr = gs.position.perp();
float lz = gs.position.z();
float dr = gs.errorR;
float dz = gs.errorZ;
// r[i] = gs.position.perp();
// phi[i] = gs.position.barePhi();
x[i] = gs.position.x();
y[i] = gs.position.y();
z[i] = lz;
drphi[i] = gs.errorRPhi;
u[i] = isBarrel ? lr : lz;
v[i] = isBarrel ? lz : lr;
du[i] = isBarrel ? dr : dz;
dv[i] = isBarrel ? dz : dr;
lphi[i] = loc.barePhi();
}
}
RecHitsSortedInPhi::DoubleRange RecHitsSortedInPhi::doubleRange(float phiMin, float phiMax) const {
Range r1, r2;
if (phiMin < phiMax) {
if (phiMin < -Geom::fpi()) {
r1 = unsafeRange(phiMin + Geom::ftwoPi(), Geom::fpi());
r2 = unsafeRange(-Geom::fpi(), phiMax);
} else if (phiMax > Geom::pi()) {
r1 = unsafeRange(phiMin, Geom::fpi());
r2 = unsafeRange(-Geom::fpi(), phiMax - Geom::ftwoPi());
} else {
r1 = unsafeRange(phiMin, phiMax);
r2 = Range(theHits.begin(), theHits.begin());
}
} else {
r1 = unsafeRange(phiMin, Geom::fpi());
r2 = unsafeRange(-Geom::fpi(), phiMax);
}
return (DoubleRange){{int(r1.first - theHits.begin()),
int(r1.second - theHits.begin()),
int(r2.first - theHits.begin()),
int(r2.second - theHits.begin())}};
}
void RecHitsSortedInPhi::hits(float phiMin, float phiMax, std::vector<Hit>& result) const {
if (phiMin < phiMax) {
if (phiMin < -Geom::fpi()) {
copyResult(unsafeRange(phiMin + Geom::ftwoPi(), Geom::fpi()), result);
copyResult(unsafeRange(-Geom::fpi(), phiMax), result);
} else if (phiMax > Geom::pi()) {
copyResult(unsafeRange(phiMin, Geom::fpi()), result);
copyResult(unsafeRange(-Geom::fpi(), phiMax - Geom::ftwoPi()), result);
} else {
copyResult(unsafeRange(phiMin, phiMax), result);
}
} else {
copyResult(unsafeRange(phiMin, Geom::fpi()), result);
copyResult(unsafeRange(-Geom::fpi(), phiMax), result);
}
}
std::vector<RecHitsSortedInPhi::Hit> RecHitsSortedInPhi::hits(float phiMin, float phiMax) const {
std::vector<Hit> result;
hits(phiMin, phiMax, result);
return result;
}
RecHitsSortedInPhi::Range RecHitsSortedInPhi::unsafeRange(float phiMin, float phiMax) const {
auto low = std::lower_bound(theHits.begin(), theHits.end(), HitWithPhi(phiMin), HitLessPhi());
return Range(low, std::upper_bound(low, theHits.end(), HitWithPhi(phiMax), HitLessPhi()));
}