DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DetectorHelper.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/DetectorHelper.h>
16 
17 // ROOT include files
18 #include <TGeoManager.h>
19 
20 using namespace dd4hep;
21 
23 SensitiveDetector DetectorHelper::sensitiveDetector(const std::string& detector) const {
24  const std::string& det_name = detector;
25  SensitiveDetector sensitive = ptr()->sensitiveDetector(det_name);
26  return sensitive;
27 }
28 
31  for(DetElement par = detector; par.isValid(); par = par.parent()) {
32  if ( par.ptr() != ptr()->world().ptr() ) {
33  PlacedVolume pv = par.placement();
34  if ( pv.isValid() ) {
35  const auto& ids = pv.volIDs();
36  for(const auto& i : ids ) {
37  if ( i.first == "system" ) {
38  return sensitiveDetector(par.name());
39  }
40  }
41  }
42  }
43  }
44  return SensitiveDetector();
45 }
46 
50  for(const auto& det : detectors ) {
51  DetElement de(det.second);
52  if ( de.id() == id ) return de;
53  }
54  return DetElement();
55 }
56 
58 Atom DetectorHelper::element(const std::string& nam) const {
59  TGeoManager& mgr = access()->manager();
60  TGeoElementTable* tab = mgr.GetElementTable();
61  TGeoElement* elt = tab->FindElement(nam.c_str());
62  if ( !elt ) {
63  std::string n = nam;
64  transform(n.begin(), n.end(), n.begin(), ::toupper);
65  elt = tab->FindElement(n.c_str()); // Check for IRON
66  if ( !elt ) {
67  transform(n.begin(), n.end(), n.begin(), ::tolower);
68  elt = tab->FindElement(n.c_str()); // Check for iron
69  if ( !elt ) {
70  n[0] = ::toupper(n[0]);
71  elt = tab->FindElement(n.c_str()); // Check for Iron
72  }
73  }
74  }
75  return elt;
76 }
77 
79 Material DetectorHelper::material(const std::string& nam) const {
80  TGeoManager& mgr = access()->manager();
81  TGeoMedium* med = mgr.GetMedium(nam.c_str());
82  if ( !med ) {
83  std::string n = nam;
84  transform(n.begin(), n.end(), n.begin(), ::toupper);
85  med = mgr.GetMedium(n.c_str()); // Check for IRON
86  if ( !med ) {
87  transform(n.begin(), n.end(), n.begin(), ::tolower);
88  med = mgr.GetMedium(n.c_str()); // Check for iron
89  if ( !med ) {
90  n[0] = ::toupper(n[0]);
91  med = mgr.GetMedium(n.c_str()); // Check for Iron
92  }
93  }
94  }
95  return med;
96 }
dd4hep::Detector::manager
virtual TGeoManager & manager() const =0
Access the geometry manager of this instance.
dd4hep::DetectorHelper::element
Atom element(const std::string &name) const
Access an element from the element table by name.
Definition: DetectorHelper.cpp:58
dd4hep::Atom
Handle class describing an element in the periodic table.
Definition: Objects.h:242
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::Detector::detectors
virtual const HandleMap & detectors() const =0
Accessor to the map of sub-detectors.
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
DetectorHelper.h
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::DetectorHelper::detectorByID
DetElement detectorByID(int id) const
Find a detector element by its system ID.
Definition: DetectorHelper.cpp:48
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Detector::sensitiveDetector
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by its name from the detector description.
detectors
DetectorMap detectors
Definition: AlignmentsCalculator.cpp:79
dd4hep::Detector::HandleMap
std::map< std::string, Handle< NamedObject > > HandleMap
Type definition of a map of named handles.
Definition: Detector.h:93
dd4hep::DetectorHelper::sensitiveDetector
SensitiveDetector sensitiveDetector(const std::string &detector) const
Access the sensitive detector of a given subdetector (if the sub-detector is sensitive!...
Definition: DetectorHelper.cpp:23
dd4hep::Handle< Detector >::access
Detector * access() const
Checked object access. Throws invalid handle runtime exception if invalid handle.
dd4hep::Handle< Detector >::ptr
Detector * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::DetElement::id
int id() const
Get the detector identifier.
Definition: DetElement.cpp:169
dd4hep::PlacedVolume::volIDs
const PlacedVolumeExtension::VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:480
dd4hep::DetectorHelper::material
Material material(const std::string &name) const
Access a material from the material table by name.
Definition: DetectorHelper.cpp:79