CMS 3D CMS Logo

TiltedGeometry.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 #include <iostream>
5 #include <sstream>
6 #include <stdexcept>
7 
9 
11  drdzs_.clear();
12  dxdys_.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 drdz, dxdy;
22 
23  // Read the detid, drdz, and dxdy from binary file
24  ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
25  ifile.read(reinterpret_cast<char*>(&drdz), sizeof(drdz));
26  ifile.read(reinterpret_cast<char*>(&dxdy), sizeof(dxdy));
27 
28  if (ifile) {
29  drdzs_[detid] = drdz;
30  dxdys_[detid] = dxdy;
31  } else {
32  // End of file or read failed
33  if (!ifile.eof()) {
34  throw std::runtime_error("Failed to read Tilted Geometry binary data.");
35  }
36  }
37  }
38 }
39 
40 float lst::TiltedGeometry::getDrDz(unsigned int detid) const {
41  auto res = drdzs_.find(detid);
42  return res == drdzs_.end() ? 0.f : res->second;
43 }
44 
45 float lst::TiltedGeometry::getDxDy(unsigned int detid) const {
46  auto res = dxdys_.find(detid);
47  return res == dxdys_.end() ? 0.f : res->second;
48 }
Definition: Electron.h:6
void load(std::string const &)
TiltedGeometry()=default
float getDrDz(unsigned int detid) const
float getDxDy(unsigned int detid) const