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