PandaRoot
PndLmdGeometryHelper.h
Go to the documentation of this file.
1 // @author S. Pflueger
2 // @author R. Klasen, roklasen@uni-mainz.de or r.klasen@gsi.de or r.klasen@ep1.rub.de
3 
4 #ifndef LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_
5 #define LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_
6 
7 #include <exception>
8 #include <iostream>
9 #include <map>
10 #include <mutex>
11 #include <string>
12 #include <vector>
13 
14 #include <boost/property_tree/json_parser.hpp>
15 #include <boost/property_tree/ptree.hpp>
16 
17 #include <TGeoManager.h>
18 #include <TVector3.h>
19 
21  // we use small data types here as they can be packed into 8 bytes
22  unsigned char detector_half;
23  unsigned char plane;
24  unsigned char module;
25  unsigned char module_side;
26  unsigned char module_sensor_id;
27 
28  friend std::ostream &operator<<(std::ostream &stream, const PndLmdHitLocationInfo &hit_info)
29  {
30  stream << "detector half: " << (unsigned int)hit_info.detector_half << "\n";
31  stream << "detector plane: " << (unsigned int)hit_info.plane << "\n";
32  stream << "module on half plane: " << (unsigned int)hit_info.module << "\n";
33  stream << "side of module: " << (unsigned int)hit_info.module_side << "\n";
34  stream << "sensor id: " << (unsigned int)hit_info.module_sensor_id << "\n";
35 
36  return stream;
37  }
38 
40  {
41  return std::tie(detector_half, plane, module, module_side, module_sensor_id) < std::tie(o.detector_half, o.plane, o.module, o.module_side, o.module_sensor_id);
42  }
43 };
44 
46  std::string path1;
47  std::string path2;
48  std::string pathModule;
49  int moduleID;
50  int overlapID;
51  int sectorID;
52  int id1;
53  int id2;
54 
55  TGeoHMatrix mat1;
56  TGeoHMatrix mat2;
57 
58  // two dummy HitLocationInfo objects for the sensors
61 
62  friend std::ostream &operator<<(std::ostream &stream, const PndLmdOverlapInfo &overlap_info)
63  {
64  stream << "path 1: " << overlap_info.path1 << "\n";
65  stream << "path 2: " << overlap_info.path2 << "\n";
66  stream << "module path: " << overlap_info.pathModule << "\n";
67  stream << "id 1: " << overlap_info.id1 << "\n";
68  stream << "id 2: " << overlap_info.id2 << "\n";
69  stream << "overlapID: " << overlap_info.overlapID << "\n";
70  return stream;
71  }
72 };
73 
75  boost::property_tree::ptree geometry_properties;
76  std::vector<std::pair<std::string, bool>> navigation_paths;
77 
78  std::map<std::string, PndLmdHitLocationInfo> volume_path_to_hit_info_mapping;
79  std::map<int, PndLmdHitLocationInfo> sensor_id_to_hit_info_mapping;
80 
81  std::string lmd_root_path;
82 
83  TGeoManager *fGeoManager;
84 
85  std::mutex accessMutex;
86 
87  PndLmdGeometryHelper(const std::string &geo_params_config_file_url = "") : fGeoManager(gGeoManager)
88  {
89  std::string file_url(geo_params_config_file_url);
90  if (geo_params_config_file_url == "") {
91  file_url = std::getenv("VMCWORKDIR");
92  file_url += "/macro/detectors/lmd/lmd-geo-params.json"; // FIXME: Put to input/ or params/
93  }
94  // load parameters
95  try {
96  read_json(file_url, geometry_properties);
97  } catch (std::exception &e) {
98  std::cerr << "PndLmdGeometryHelper::PndLmdGeometryHelper(): ERROR! Parameter file not present!\n";
99  std::cerr << "Was looking for file: " << file_url << "\n";
100  exit(1);
101  }
102 
103  if (!fGeoManager) {
104  std::cerr << "ERROR! gGeoManager is unitialized! Please populate the gGeoManager or initialize a run!\n";
105  exit(2);
106  }
107 
108  auto pt_general = geometry_properties.get_child("general");
109  for (boost::property_tree::ptree::value_type &nav_path : pt_general.get_child("navigation_paths")) {
110  navigation_paths.push_back(std::make_pair(nav_path.second.get<std::string>("name"), nav_path.second.get<bool>("is_alignable")));
111  }
112 
113  TString actPath = fGeoManager->GetPath();
114  std::stringstream lmd_path;
115  fGeoManager->CdTop();
116  lmd_path << fGeoManager->GetPath() << "/" << navigation_paths[0].first << "_0";
117  lmd_root_path = lmd_path.str();
118  if (actPath != "" && actPath != " ")
119  fGeoManager->cd(actPath);
120  }
121 
122  const PndLmdHitLocationInfo &createMappingEntry(int sensor_id);
123  const PndLmdHitLocationInfo &createMappingEntry(const std::string &volume_path);
124 
125  PndLmdHitLocationInfo translateVolumePathToHitLocationInfo(const std::string &volume_path) const;
126 
127  public:
129  {
130  static PndLmdGeometryHelper instance;
131  return instance;
132  }
133 
134  virtual ~PndLmdGeometryHelper();
135 
136  PndLmdGeometryHelper(const PndLmdGeometryHelper &) = delete;
137  void operator=(const PndLmdGeometryHelper &) = delete;
138 
139  const PndLmdHitLocationInfo &getHitLocationInfo(const std::string &volume_path);
140  // this function with the global sensor id is much faster for lookups
141  // so use that if you need speed!
142 
143  const PndLmdHitLocationInfo &getHitLocationInfo(int sensor_id);
144 
145  std::vector<int> getAvailableOverlapIDs();
146  int getOverlapIdFromSensorIDs(int id1, int id2);
147  int getModuleIDFromSensorIDs(int id1, int id2);
148  int getSectorIDfromSensorID(int sensorID);
149  std::string getModulePathFromModuleID(int moduleID);
150  int getSensorOneFromOverlapID(int overlapID);
151  int getSensorTwoFromOverlapID(int overlapID);
152 
153  TVector3 transformPndGlobalToLmdLocal(const TVector3 &vec);
154  TVector3 transformPndGlobalToSensor(const TVector3 &vec, int sensorId);
155 
156  bool isOverlappingArea(const int id1, const int id2);
157 
158  const std::string getPath(unsigned char...);
159 
160  const TGeoHMatrix getMatrixPndGlobalToSensor(const int sensorId);
161  const TGeoHMatrix getMatrixSensorToPndGlobal(const int sensorId);
162 
163  const TGeoHMatrix getMatrixPndGlobalToLmdLocal();
164  const TGeoHMatrix getMatrixLmdLocalToPndGlobal();
165 
166  std::vector<std::string> getAllAlignPaths(bool sensors = true, bool modules = false, bool planes = false, bool halfs = false, bool detector = false);
167 
168  // can be restriced by half, plane and module
169  std::vector<PndLmdOverlapInfo> getOverlapInfos(int iHalf = -1, int iPlane = -1, int iModule = -1);
170 
171  std::vector<std::string> getAllAlignableVolumePaths() const;
172 };
173 
174 #endif /* LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_ */
friend std::ostream & operator<<(std::ostream &stream, const PndLmdOverlapInfo &overlap_info)
static PndLmdGeometryHelper & getInstance()
bool operator<(const PndLmdHitLocationInfo &o)
friend std::ostream & operator<<(std::ostream &stream, const PndLmdHitLocationInfo &hit_info)
PndLmdHitLocationInfo hit1
PndLmdHitLocationInfo hit2