EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
materialPlotHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file materialPlotHelper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include "materialPlotHelper.hpp"
10 
11 #include <iomanip>
12 #include <ostream>
13 #include <string>
14 
15 #include "../../../thirdparty/nlohmann_json/single_include/nlohmann/json.hpp"
16 
18 
20 
21 struct sinfo {
22  std::string name;
23  std::string idname;
24  std::string id;
25  int type;
26  float pos;
27  float range_min;
28  float range_max;
29 };
30 
31 std::ostream& Acts::operator<<(std::ostream& os, Acts::GeometryIdentifier id) {
32  os << "[ " << std::setw(3) << id.volume();
33  os << " | " << std::setw(3) << id.boundary();
34  os << " | " << std::setw(3) << id.layer();
35  os << " | " << std::setw(3) << id.approach();
36  os << " | " << std::setw(4) << id.sensitive() << " ]";
37  return os;
38 }
39 
41 
42 void Parse_Json(const json& Det,
43  std::map<std::string, std::string>& surface_name) {
44  std::string name;
45  for (auto& [key, value] : Det.items()) {
46  // Check if this the volume key
47  if (key == "volumes") {
48  // Get the volume json
49  auto volj = value;
50  for (auto& [vkey, vvalue] : volj.items()) {
51  // Get the volume name
52  name = vvalue["Name"];
53  // If boundaries associate the vol name to their id
54  if (!vvalue["boundaries"].empty()) {
55  for (auto& [bkey, bvalue] : vvalue["boundaries"].items()) {
56  surface_name[bvalue["SGeoid"]] = name;
57  }
58  }
59  // If layer associate the vol name to their id
60  if (!vvalue["layers"].empty()) {
61  for (auto& [lkey, lvalue] : vvalue["layers"].items()) {
62  surface_name[lvalue["Geoid"]] = name;
63  // Finally loop over layer components
64  for (auto& [lckey, lcvalue] : lvalue.items()) {
65  if (lckey == "representing" && !lcvalue.empty()) {
66  surface_name[lcvalue["SGeoid"]] = name;
67  } else if (lckey == "approach" && !lcvalue.empty()) {
68  // Loop over approach surfaces
69  for (auto& [askey, asvalue] : lcvalue.items()) {
70  surface_name[asvalue["SGeoid"]] = name;
71  }
72  } else if (lckey == "sensitive" && !lcvalue.empty()) {
73  // Loop over sensitive surfaces
74  for (auto& [sskey, ssvalue] : lcvalue.items()) {
75  surface_name[ssvalue["SGeoid"]] = name;
76  }
77  }
78  }
79  }
80  }
81  }
82  }
83  }
84  return;
85 }
86 
88 
89 void Initialise_info(sinfo& surface_info,
90  const std::map<std::string, std::string>& surface_name,
91  const uint64_t& id, const int& type, const float& pos,
92  const float& range_min, const float& range_max) {
94  std::ostringstream layerID;
95  layerID << ID;
96  std::string surface_id = layerID.str();
97 
98  std::string Id_temp = surface_id;
99  std::string delimiter = " | ";
100  size_t del_pos = 0;
101  std::vector<std::string> Ids;
102  while ((del_pos = Id_temp.find(delimiter)) != std::string::npos) {
103  Ids.push_back(Id_temp.substr(0, del_pos));
104  Id_temp.erase(0, del_pos + delimiter.length());
105  }
106  Ids.push_back(Id_temp);
107 
108  for (int tag = 0; tag < 5; tag++) {
109  Ids[tag].erase(std::remove(Ids[tag].begin(), Ids[tag].end(), ' '),
110  Ids[tag].end());
111  Ids[tag].erase(std::remove(Ids[tag].begin(), Ids[tag].end(), '['),
112  Ids[tag].end());
113  Ids[tag].erase(std::remove(Ids[tag].begin(), Ids[tag].end(), ']'),
114  Ids[tag].end());
115  }
116 
117  surface_info.idname =
118  "v" + Ids[0] + "_b" + Ids[1] + "_l" + Ids[2] + "_a" + Ids[3];
119  surface_info.type = type;
120 
121  if (surface_name.find(surface_id) != surface_name.end()) {
122  surface_info.name = surface_name.at(surface_id);
123  } else
124  surface_info.name = "";
125 
126  surface_info.id = surface_id;
127  surface_info.pos = pos;
128  surface_info.range_min = range_min;
129  surface_info.range_max = range_max;
130 }