Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:53

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/DetectorHelper.h>
0016 
0017 // ROOT include files
0018 #include <TGeoManager.h>
0019 
0020 using namespace dd4hep;
0021 
0022 /// Access the sensitive detector of a given subdetector (if the sub-detector is sensitive!)
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 /// Given a detector element, access its sensitive detector (if the sub-detector is sensitive!)
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 /// Find a detector element by its system ID
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 /// Access an element from the element table by name
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());     // Check for IRON
0066     if ( !elt )    {
0067       transform(n.begin(), n.end(), n.begin(), ::tolower);
0068       elt = tab->FindElement(n.c_str());   // Check for iron
0069       if ( !elt )    {
0070         n[0] = ::toupper(n[0]);
0071         elt = tab->FindElement(n.c_str()); // Check for Iron
0072       }
0073     }
0074   }
0075   return elt;
0076 }
0077 
0078 /// Access a material from the material table by name
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());     // Check for IRON
0086     if ( !med )    {
0087       transform(n.begin(), n.end(), n.begin(), ::tolower);
0088       med = mgr.GetMedium(n.c_str());   // Check for iron
0089       if ( !med )    {
0090         n[0] = ::toupper(n[0]);
0091         med = mgr.GetMedium(n.c_str()); // Check for Iron
0092       }
0093     }
0094   }
0095   return med;
0096 }