File indexing completed on 2025-01-18 09:13:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/DetectorHelper.h>
0016
0017
0018 #include <TGeoManager.h>
0019
0020 using namespace dd4hep;
0021
0022
0023 SensitiveDetector DetectorHelper::sensitiveDetector(const std::string& detector) const {
0024 const std::string& det_name = detector;
0025 SensitiveDetector sensitive = ptr()->sensitiveDetector(det_name);
0026 return sensitive;
0027 }
0028
0029
0030 SensitiveDetector DetectorHelper::sensitiveDetector(DetElement detector) const {
0031 for(DetElement par = detector; par.isValid(); par = par.parent()) {
0032 if ( par.ptr() != ptr()->world().ptr() ) {
0033 PlacedVolume pv = par.placement();
0034 if ( pv.isValid() ) {
0035 const auto& ids = pv.volIDs();
0036 for(const auto& i : ids ) {
0037 if ( i.first == "system" ) {
0038 return sensitiveDetector(par.name());
0039 }
0040 }
0041 }
0042 }
0043 }
0044 return SensitiveDetector();
0045 }
0046
0047
0048 DetElement DetectorHelper::detectorByID(int id) const {
0049 const Detector::HandleMap& detectors = ptr()->detectors();
0050 for(const auto& det : detectors ) {
0051 DetElement de(det.second);
0052 if ( de.id() == id ) return de;
0053 }
0054 return DetElement();
0055 }
0056
0057
0058 Atom DetectorHelper::element(const std::string& nam) const {
0059 TGeoManager& mgr = access()->manager();
0060 TGeoElementTable* tab = mgr.GetElementTable();
0061 TGeoElement* elt = tab->FindElement(nam.c_str());
0062 if ( !elt ) {
0063 std::string n = nam;
0064 transform(n.begin(), n.end(), n.begin(), ::toupper);
0065 elt = tab->FindElement(n.c_str());
0066 if ( !elt ) {
0067 transform(n.begin(), n.end(), n.begin(), ::tolower);
0068 elt = tab->FindElement(n.c_str());
0069 if ( !elt ) {
0070 n[0] = ::toupper(n[0]);
0071 elt = tab->FindElement(n.c_str());
0072 }
0073 }
0074 }
0075 return elt;
0076 }
0077
0078
0079 Material DetectorHelper::material(const std::string& nam) const {
0080 TGeoManager& mgr = access()->manager();
0081 TGeoMedium* med = mgr.GetMedium(nam.c_str());
0082 if ( !med ) {
0083 std::string n = nam;
0084 transform(n.begin(), n.end(), n.begin(), ::toupper);
0085 med = mgr.GetMedium(n.c_str());
0086 if ( !med ) {
0087 transform(n.begin(), n.end(), n.begin(), ::tolower);
0088 med = mgr.GetMedium(n.c_str());
0089 if ( !med ) {
0090 n[0] = ::toupper(n[0]);
0091 med = mgr.GetMedium(n.c_str());
0092 }
0093 }
0094 }
0095 return med;
0096 }