Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-06 08:34:41

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 #ifndef DDCORE_SRC_PLUGINS_LCDDCONVERTER_H
0015 #define DDCORE_SRC_PLUGINS_LCDDCONVERTER_H
0016 
0017 // Framework include files
0018 #include <DD4hep/Detector.h>
0019 #include <DD4hep/GeoHandler.h>
0020 #include <DD4hep/DetFactoryHelper.h>
0021 
0022 // C/C++ include files
0023 #include <set>
0024 #include <map>
0025 
0026 // Forward declarations
0027 class TGeoVolume;
0028 class TGeoElement;
0029 class TGeoShape;
0030 class TGeoMedium;
0031 class TGeoNode;
0032 class TGeoMatrix;
0033 
0034 /// Namespace for the AIDA detector description toolkit
0035 namespace dd4hep {
0036 
0037   /// Namespace for implementation details of the AIDA detector description toolkit
0038   namespace detail {
0039 
0040     // Forward declarations
0041     class SensitiveDetectorObject;
0042 
0043     /// Geometry converter from dd4hep to Geant 4 in Detector format.
0044     /**
0045      *  \author  M.Frank
0046      *  \version 1.0
0047      *  \ingroup DD4HEP_CORE
0048      */
0049     class LCDDConverter: public GeoHandler {
0050     public:
0051       typedef xml::XmlElement XmlElement;
0052       typedef std::map<Atom,              XmlElement*> ElementMap;
0053       typedef std::map<Material,          XmlElement*> MaterialMap;
0054       typedef std::map<LimitSet,          XmlElement*> LimitMap;
0055       typedef std::map<PlacedVolume,      XmlElement*> PlacementMap;
0056       typedef std::map<Region,            XmlElement*> RegionMap;
0057       typedef std::map<SensitiveDetector, XmlElement*> SensDetMap;
0058       typedef std::map<Volume,            XmlElement*> VolumeMap;
0059       typedef std::map<IDDescriptor,      XmlElement*> IdSpecMap;
0060       typedef std::map<VisAttr,           XmlElement*> VisMap;
0061       typedef std::map<const TGeoShape*,  XmlElement*> SolidMap;
0062       typedef std::map<OverlayedField,    XmlElement*> FieldMap;
0063       typedef std::map<const TGeoMatrix*, XmlElement*> TrafoMap;
0064       /// Data structure of the geometry converter from dd4hep to Geant 4 in Detector format.
0065       /**
0066        *  \author  M.Frank
0067        *  \version 1.0
0068        *  \ingroup DD4HEP_CORE
0069        */
0070       class GeometryInfo: public GeoHandler::GeometryInfo {
0071       public:
0072         ElementMap   xmlElements;
0073         MaterialMap  xmlMaterials;
0074         SolidMap     xmlSolids;
0075         VolumeMap    xmlVolumes;
0076         PlacementMap xmlPlacements;
0077         RegionMap    xmlRegions;
0078         VisMap       xmlVis;
0079         LimitMap     xmlLimits;
0080         IdSpecMap    xmlIdSpecs;
0081         SensDetMap   xmlSensDets;
0082         TrafoMap     xmlPositions;
0083         TrafoMap     xmlRotations;
0084         FieldMap     xmlFields;
0085         std::set<SensitiveDetector> sensitives;
0086         std::set<Region> regions;
0087         std::set<LimitSet> limits;
0088         // These we need for redundancy and checking the data integrity
0089         typedef std::map<std::string, const TNamed*> CheckIter;
0090         struct _checks {
0091           std::map<std::string, const TNamed*> positions, rotations, volumes, solids, materials;
0092         };
0093         mutable _checks checks;
0094         void check(const std::string& name, const TNamed* n, std::map<std::string, const TNamed*>& array) const;
0095         void checkPosition(const std::string& name, const TNamed* n) const {
0096           check(name, n, checks.positions);
0097         }
0098         void checkRotation(const std::string& name, const TNamed* n) const {
0099           check(name, n, checks.rotations);
0100         }
0101         void checkVolume(const std::string& name, const TNamed* n) const {
0102           check(name, n, checks.volumes);
0103         }
0104         void checkShape(const std::string& name, const TNamed* n) const {
0105           check(name, n, checks.solids);
0106         }
0107         void checkMaterial(const std::string& name, Material n) const {
0108           check(name, n.ptr(), checks.materials);
0109         }
0110 
0111         xml_doc_t doc;
0112         xml_h identity_rot, identity_pos;
0113         xml_elt_t doc_root, doc_header, doc_idDict, doc_detectors, doc_limits, doc_regions, doc_display, doc_gdml, doc_fields,
0114           doc_define, doc_materials, doc_solids, doc_structure, doc_setup;
0115         GeometryInfo();
0116       };
0117       typedef std::set<std::string> NameSet;
0118 
0119       /// Reference to detector description
0120       Detector& m_detDesc;
0121       mutable NameSet m_checkNames;
0122       GeometryInfo* m_dataPtr;
0123 
0124       GeometryInfo& data() const {
0125         return *m_dataPtr;
0126       }
0127 
0128       /// Data integrity checker
0129       void checkVolumes(const std::string& name, Volume volume) const;
0130 
0131       /// Initializing Constructor
0132       LCDDConverter(Detector& description);
0133 
0134       /// Standard destructor
0135       virtual ~LCDDConverter();
0136 
0137       /// Create geometry conversion in GDML format
0138       xml_doc_t createGDML(DetElement top);
0139 
0140       /// Create geometry conversion in Detector format
0141       xml_doc_t createDetector(DetElement top);
0142 
0143       /// Create geometry conversion in Vis format
0144       xml_doc_t createVis(DetElement top);
0145 
0146       /// Add header information in Detector format
0147       virtual void handleHeader() const;
0148 
0149       /// Convert the geometry type material into the corresponding Xml object(s).
0150       virtual xml_h handleMaterial(const std::string& name, Material medium) const;
0151 
0152       /// Convert the geometry type element into the corresponding Xml object(s).
0153       virtual xml_h handleElement(const std::string& name, Atom element) const;
0154 
0155       /// Convert the geometry type solid into the corresponding Xml object(s).
0156       virtual xml_h handleSolid(const std::string& name, const TGeoShape* volume) const;
0157 
0158       /// Convert the geometry type logical volume into the corresponding Xml object(s).
0159       virtual xml_h handleVolume(const std::string& name, Volume volume) const;
0160       virtual xml_h handleVolumeVis(const std::string& name, const TGeoVolume* volume) const;
0161       virtual void collectVolume(const std::string& name, const TGeoVolume* volume) const;
0162 
0163       /// Convert the geometry type volume placement into the corresponding Xml object(s).
0164       virtual xml_h handlePlacement(const std::string& name, PlacedVolume node) const;
0165 
0166       /// Convert the geometry type field into the corresponding Xml object(s).
0167       ///virtual xml_h handleField(const std::string& name, Ref_t field) const;
0168 
0169       /// Convert the geometry type region into the corresponding Xml object(s).
0170       virtual xml_h handleRegion(const std::string& name, Region region) const;
0171 
0172       /// Convert the geometry visualisation attributes to the corresponding Xml object(s).
0173       virtual xml_h handleVis(const std::string& name, VisAttr vis) const;
0174 
0175       /// Convert the geometry id dictionary entry to the corresponding Xml object(s).
0176       virtual xml_h handleIdSpec(const std::string& name, IDDescriptor idspec) const;
0177 
0178       /// Convert the geometry type LimitSet into the corresponding Xml object(s).
0179       virtual xml_h handleLimitSet(const std::string& name, LimitSet limitset) const;
0180 
0181       /// Convert the geometry type SensitiveDetector into the corresponding Xml object(s).
0182       virtual xml_h handleSensitive(const std::string& name, SensitiveDetector sens_det) const;
0183 
0184       /// Convert the segmentation of a SensitiveDetector into the corresponding Detector object
0185       virtual xml_h handleSegmentation(Segmentation seg) const;
0186 
0187       /// Convert the Position into the corresponding Xml object(s).
0188       virtual xml_h handlePosition(const std::string& name, const TGeoMatrix* trafo) const;
0189 
0190       /// Convert the Rotation into the corresponding Xml object(s).
0191       virtual xml_h handleRotation(const std::string& name, const TGeoMatrix* trafo) const;
0192 
0193       /// Convert the electric or magnetic fields into the corresponding Xml object(s).
0194       virtual xml_h handleField(const std::string& name, OverlayedField field) const;
0195 
0196       /// Handle the geant 4 specific properties
0197       void handleProperties(Detector::Properties& prp) const;
0198     };
0199   }    // End namespace xml
0200 }      // End namespace dd4hep
0201 #endif // DDCORE_SRC_PLUGINS_LCDDCONVERTER_H