-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathEndcapGeometry.cc
More file actions
78 lines (62 loc) · 2.4 KB
/
Copy pathEndcapGeometry.cc
File metadata and controls
78 lines (62 loc) · 2.4 KB
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
#include "RecoTracker/LSTCore/interface/EndcapGeometry.h"
#include <fstream>
#include <iostream>
#include <limits>
#include <sstream>
#include <stdexcept>
lst::EndcapGeometry::EndcapGeometry(std::string const& filename) { load(filename); }
lst::EndcapGeometry::EndcapGeometry(lstgeometry::Slopes const& slopes, lstgeometry::Sensors const& sensors) {
load(slopes, sensors);
}
void lst::EndcapGeometry::load(std::string const& filename) {
dxdy_slope_.clear();
centroid_phis_.clear();
std::ifstream ifile(filename, std::ios::binary);
if (!ifile.is_open()) {
throw std::runtime_error("Unable to open file: " + filename);
}
while (!ifile.eof()) {
unsigned int detid;
float dxdy_slope, centroid_phi;
// Read the detid, dxdy_slope, and centroid_phi from binary file
ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
ifile.read(reinterpret_cast<char*>(&dxdy_slope), sizeof(dxdy_slope));
ifile.read(reinterpret_cast<char*>(¢roid_phi), sizeof(centroid_phi));
if (ifile) {
// TODO: This is needed for now in case old geometry files are used. Remove once deemed unnecessary.
constexpr float kLegacyVerticalSlope = 123456789.0f;
dxdy_slope_[detid] = (dxdy_slope == kLegacyVerticalSlope) ? std::numeric_limits<float>::infinity() : dxdy_slope;
centroid_phis_[detid] = centroid_phi;
} else {
// End of file or read failed
if (!ifile.eof()) {
throw std::runtime_error("Failed to read Endcap Geometry binary data.");
}
}
}
fillGeoMapArraysExplicit();
}
void lst::EndcapGeometry::load(lstgeometry::Slopes const& slopes, lstgeometry::Sensors const& sensors) {
dxdy_slope_.clear();
centroid_phis_.clear();
for (const auto& [detId, slope] : slopes) {
dxdy_slope_[detId] = slope.dxdy;
centroid_phis_[detId] = sensors.at(detId).centerPhi;
}
fillGeoMapArraysExplicit();
}
void lst::EndcapGeometry::fillGeoMapArraysExplicit() {
nEndCapMap = centroid_phis_.size();
geoMapDetId_buf.reserve(nEndCapMap);
geoMapPhi_buf.reserve(nEndCapMap);
for (auto it = centroid_phis_.begin(); it != centroid_phis_.end(); ++it) {
unsigned int detId = it->first;
float Phi = it->second;
geoMapPhi_buf.push_back(Phi);
geoMapDetId_buf.push_back(detId);
}
}
float lst::EndcapGeometry::getdxdy_slope(unsigned int detid) const {
auto res = dxdy_slope_.find(detid);
return res == dxdy_slope_.end() ? 0.f : res->second;
}