FairRoot/PandaRoot
PndLmdGeometryHelper.h
Go to the documentation of this file.
1 #ifndef LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_
2 #define LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include <boost/property_tree/json_parser.hpp>
9 #include <boost/property_tree/ptree.hpp>
10 
11 #include <TGeoManager.h>
12 #include <TVector3.h>
13 
15  // we use small data types here as they can be packed into 8 bytes
16  unsigned char detector_half;
17  unsigned char plane;
18  unsigned char module;
19  unsigned char module_side;
20  unsigned char module_sensor_id;
21 
22  friend std::ostream& operator<<(std::ostream& stream, const PndLmdHitLocationInfo& hit_info) {
23  stream << "detector half: " << (unsigned int) hit_info.detector_half << "\n";
24  stream << "detector plane: " << (unsigned int) hit_info.plane << "\n";
25  stream << "module on half plane: " << (unsigned int) hit_info.module << "\n";
26  stream << "side of module: " << (unsigned int) hit_info.module_side << "\n";
27  stream << "sensor id: " << (unsigned int) hit_info.module_sensor_id << "\n";
28 
29  return stream;
30  }
31 
34  < std::tie(o.detector_half, o.plane, o.module, o.module_side, o.module_sensor_id);
35  }
36 };
37 
39  boost::property_tree::ptree geometry_properties;
40  std::vector<std::pair<std::string, bool> > navigation_paths;
41 
42  std::map<std::string, PndLmdHitLocationInfo> volume_path_to_hit_info_mapping;
43  std::map<int, PndLmdHitLocationInfo> sensor_id_to_hit_info_mapping;
44 
45  std::string lmd_root_path;
46 
47  TGeoManager* fGeoManager;
48 
49  PndLmdGeometryHelper(const std::string& geo_params_config_file_url = "lmd-geo-params.json") :
51  // load parameters
52  read_json(geo_params_config_file_url, geometry_properties);
53  auto pt_general = geometry_properties.get_child("general");
54  for (boost::property_tree::ptree::value_type &nav_path : pt_general.get_child("navigation_paths")) {
55  navigation_paths.push_back(
56  std::make_pair(nav_path.second.get<std::string>("name"),
57  nav_path.second.get<bool>("is_alignable")));
58  }
59 
60  TString actPath = fGeoManager->GetPath();
61  std::stringstream lmd_path;
62  fGeoManager->CdTop();
63  lmd_path << fGeoManager->GetPath() << "/" << navigation_paths[0].first << "_0";
64  lmd_root_path = lmd_path.str();
65  if (actPath != "" && actPath != " ") fGeoManager->cd(actPath);
66 
67  }
68 
69  const PndLmdHitLocationInfo& createMappingEntry(int sensor_id);
70  const PndLmdHitLocationInfo& createMappingEntry(const std::string& volume_path);
71 
72  PndLmdHitLocationInfo translateVolumePathToHitLocationInfo(const std::string& volume_path) const;
73 
74 public:
76  static PndLmdGeometryHelper instance;
77  return instance;
78  }
79  virtual ~PndLmdGeometryHelper();
80 
82  void operator=(const PndLmdGeometryHelper&) = delete;
83 
84  const PndLmdHitLocationInfo& getHitLocationInfo(const std::string& volume_path);
85  // this function with the global sensor id is much faster for lookups
86  // so use that if you need speed!
87 
88  const PndLmdHitLocationInfo& getHitLocationInfo(int sensor_id);
89 
90  static std::vector<int> getAvailableOverlapIDs();
91  int getOverlapIdFromSensorIDs(int id1, int id2);
92 
93  TVector3 transformPndGlobalToLmdLocal(const TVector3 &vec);
94  TVector3 transformPndGlobalToSensor(const TVector3 &vec, int sensorId);
95 
96  bool isOverlappingArea(const int id1, const int id2);
97 
98  const std::string getPath(unsigned char...);
99 
100  const TGeoHMatrix getMatrixPndGlobalToSensor(const int sensorId);
101  const TGeoHMatrix getMatrixSensorToPndGlobal(const int sensorId);
102 
103  const TGeoHMatrix getMatrixPndGlobalToLmdLocal();
104  const TGeoHMatrix getMatrixLmdLocalToPndGlobal();
105 
106  // returns all paths to alignable objects, filtered by bools
107  std::vector<std::string> getAllAlignPaths(bool sensors=true, bool modules=false, bool planes=false,
108  bool halfs=false, bool detector=false);
109 
110  std::vector<std::string> getAllAlignableVolumePaths() const;
111 
112  };
113 
114 #endif /* LMD_LMDMC_PNDLMDGEOMETRYHELPER_H_ */
TVector3 transformPndGlobalToSensor(const TVector3 &vec, int sensorId)
PndLmdHitLocationInfo translateVolumePathToHitLocationInfo(const std::string &volume_path) const
static std::vector< int > getAvailableOverlapIDs()
const PndLmdHitLocationInfo & createMappingEntry(int sensor_id)
PndLmdGeometryHelper(const std::string &geo_params_config_file_url="lmd-geo-params.json")
static PndLmdGeometryHelper & getInstance()
bool operator<(const PndLmdHitLocationInfo &o)
TGeoManager * gGeoManager
std::vector< std::pair< std::string, bool > > navigation_paths
friend std::ostream & operator<<(std::ostream &stream, const PndLmdHitLocationInfo &hit_info)
const TGeoHMatrix getMatrixSensorToPndGlobal(const int sensorId)
std::vector< std::string > getAllAlignPaths(bool sensors=true, bool modules=false, bool planes=false, bool halfs=false, bool detector=false)
std::vector< std::string > getAllAlignableVolumePaths() const
std::map< std::string, PndLmdHitLocationInfo > volume_path_to_hit_info_mapping
const TGeoHMatrix getMatrixPndGlobalToLmdLocal()
const TGeoHMatrix getMatrixPndGlobalToSensor(const int sensorId)
const std::string getPath(unsigned char...)
const PndLmdHitLocationInfo & getHitLocationInfo(const std::string &volume_path)
std::map< int, PndLmdHitLocationInfo > sensor_id_to_hit_info_mapping
void operator=(const PndLmdGeometryHelper &)=delete
const TGeoHMatrix getMatrixLmdLocalToPndGlobal()
boost::property_tree::ptree geometry_properties
TVector3 transformPndGlobalToLmdLocal(const TVector3 &vec)
int getOverlapIdFromSensorIDs(int id1, int id2)
bool isOverlappingArea(const int id1, const int id2)
dble_vec_t vec[12]
Definition: ranlxd.cxx:380