CMS 3D CMS Logo

EndcapGeometry.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 #include <iostream>
5 #include <sstream>
6 #include <stdexcept>
7 
9 
11  dxdy_slope_.clear();
12  centroid_phis_.clear();
13 
14  std::ifstream ifile(filename, std::ios::binary);
15  if (!ifile.is_open()) {
16  throw std::runtime_error("Unable to open file: " + filename);
17  }
18 
19  while (!ifile.eof()) {
20  unsigned int detid;
21  float dxdy_slope, centroid_phi;
22 
23  // Read the detid, dxdy_slope, and centroid_phi from binary file
24  ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
25  ifile.read(reinterpret_cast<char*>(&dxdy_slope), sizeof(dxdy_slope));
26  ifile.read(reinterpret_cast<char*>(&centroid_phi), sizeof(centroid_phi));
27 
28  if (ifile) {
29  dxdy_slope_[detid] = dxdy_slope;
30  centroid_phis_[detid] = centroid_phi;
31  } else {
32  // End of file or read failed
33  if (!ifile.eof()) {
34  throw std::runtime_error("Failed to read Endcap Geometry binary data.");
35  }
36  }
37  }
38 
39  fillGeoMapArraysExplicit();
40 }
41 
43  nEndCapMap = centroid_phis_.size();
44 
45  geoMapDetId_buf.reserve(nEndCapMap);
46  geoMapPhi_buf.reserve(nEndCapMap);
47 
48  for (auto it = centroid_phis_.begin(); it != centroid_phis_.end(); ++it) {
49  unsigned int detId = it->first;
50  float Phi = it->second;
51  geoMapPhi_buf.push_back(Phi);
52  geoMapDetId_buf.push_back(detId);
53  }
54 }
55 
56 float lst::EndcapGeometry::getdxdy_slope(unsigned int detid) const {
57  auto res = dxdy_slope_.find(detid);
58  return res == dxdy_slope_.end() ? 0.f : res->second;
59 }
EndcapGeometry()=default
Definition: Electron.h:6
void load(std::string const &)
float getdxdy_slope(unsigned int detid) const