Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 08:34:01

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 #ifndef DD4HEP_DETECTORIMP_H
0014 #define DD4HEP_DETECTORIMP_H
0015 
0016 //==========================================================================
0017 //
0018 // Please note:
0019 //
0020 // This header file is purely DD4hep internal. It should never be used
0021 // independently outside DetectorImp.cpp and certain DD4hep specific plugins.
0022 // This header files is only publicly present to satisfy the ROOT interpreter
0023 // when loading precompiled dictionary libraries.
0024 //
0025 //==========================================================================
0026 #if !defined(DD4HEP_MUST_USE_DETECTORIMP_H) && !defined(G__ROOT)
0027 #error "DetectorImp.h is a dd4hep internal header. Never use it in a depending compilation unit!"
0028 #endif
0029 
0030 // Framework include files
0031 #include <DD4hep/DetectorData.h>
0032 #include <DD4hep/DetectorLoad.h>
0033 #include <TNamed.h>
0034 
0035 // Forward declarations
0036 class TGeoManager;
0037 
0038 // C/C++ include files
0039 #include <map>
0040 
0041 /// Namespace for the AIDA detector description toolkit
0042 namespace dd4hep {
0043 
0044   /// Namespace for implementation details of the AIDA detector description toolkit
0045   namespace detail  {
0046     class OpticalSurfaceManagerObject;
0047   }
0048   
0049   /// Concrete implementation class of the Detector interface
0050   /** The main entry point to the DD4hep detector description
0051    *
0052    *  Please note:
0053    *  The inheritance of the TNamed is necessary to properly access the 
0054    *  object when loaded from ROOT.
0055    *
0056    * @author  M.Frank
0057    * @version 1.0
0058    */
0059   class DetectorImp: public TNamed, public Detector, public DetectorData, public DetectorLoad  {
0060   protected:
0061     /// Cached map with detector types:
0062     typedef std::map<std::string, std::vector<DetElement> > DetectorTypeMap;
0063 
0064     /// Standard conditions
0065     mutable STD_Conditions m_std_conditions;
0066     
0067     /// Inventory of detector types
0068     DetectorTypeMap   m_detectorTypes;
0069 
0070     /// VolumeManager m_volManager;
0071     DetectorBuildType m_buildType;
0072 
0073     /// Optical surface manager
0074     detail::OpticalSurfaceManagerObject* m_surfaceManager {nullptr};   //! not persistent
0075 
0076   private:
0077     /// Disable move constructor
0078     DetectorImp(DetectorImp&& copy) = delete;
0079 
0080     /// Disable copy constructor
0081     DetectorImp(const DetectorImp& copy) = delete;
0082 
0083     /// Disable assignment operator
0084     DetectorImp& operator=(const DetectorImp& copy) = delete;
0085 
0086     /// Internal helper to map detector types once the geometry is closed
0087     void mapDetectorTypes();
0088 
0089     /// ROOT I/O call
0090     Int_t saveObject(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
0091   public:
0092 
0093     /// Local method (no interface): Load volume manager.
0094     void imp_loadVolumeManager();
0095     
0096     /// Default constructor used by ROOT I/O
0097     DetectorImp();
0098 
0099     /// Initializing constructor
0100     DetectorImp(const std::string& name);
0101 
0102     /// Standard destructor
0103     virtual ~DetectorImp();
0104 
0105     /// Access the state of the geometry
0106     virtual State state()  const  override   {
0107       return m_state;
0108     }
0109 
0110     /// Access flag to steer the detail of building of the geometry/detector description
0111     virtual DetectorBuildType buildType() const   override;
0112 
0113     /// Read compact geometry description or alignment file
0114     virtual void fromCompact(const std::string& fname, DetectorBuildType type = BUILD_DEFAULT)   override {
0115       fromXML(fname, type);
0116     }
0117 
0118     /// Read any XML file
0119     virtual void fromXML(const std::string& fname, DetectorBuildType type = BUILD_DEFAULT)  override;
0120 
0121     /// Read any geometry description or alignment file with external XML entity resolution
0122     virtual void fromXML(const std::string& fname,
0123                          xml::UriReader* entity_resolver,
0124                          DetectorBuildType type = BUILD_DEFAULT)  override;
0125 
0126     virtual void dump() const  override;
0127 
0128     /// Manipulate geometry using facroy converter
0129     virtual long apply(const char* factory, int argc, char** argv)  const  override;
0130 
0131     /// Open the geometry at startup.
0132     virtual void init()  override;
0133 
0134     /// Close the geometry
0135     virtual void endDocument(bool close_geometry)  override;
0136 
0137     /// Add an extension object to the Detector instance
0138     virtual void* addUserExtension(unsigned long long int key, ExtensionEntry* entry)  override;
0139 
0140     /// Remove an existing extension object from the Detector instance. If not destroyed, the instance is returned
0141     virtual void* removeUserExtension(unsigned long long int key, bool destroy=true)  override;
0142 
0143     /// Access an existing extension object from the Detector instance
0144     virtual void* userExtension(unsigned long long int key, bool alert=true) const  override;
0145 
0146     virtual Handle<NamedObject> getRefChild(const HandleMap& e, const std::string& name, bool throw_if_not = true) const;
0147 
0148     /// Register new mother volume using the detector name.
0149     virtual void   declareParent(const std::string& detector_name, const DetElement& parent)  override;
0150 
0151     /// Access mother volume by detector element
0152     virtual Volume pickMotherVolume(const DetElement& sd) const  override;
0153 
0154     /// Access the geometry manager of this instance
0155     virtual TGeoManager& manager() const   override  {
0156       return *m_manager;
0157     }
0158     /// Access to properties
0159     Properties& properties() const  override {
0160       return *(Properties*)&m_properties;
0161     }
0162     /// Return handle to material describing air
0163     virtual Material air() const  override {
0164       return m_materialAir;
0165     }
0166     /// Return handle to material describing vacuum
0167     virtual Material vacuum() const  override {
0168       return m_materialVacuum;
0169     }
0170     /// Return handle to "invisible" visualization attributes
0171     virtual VisAttr invisible() const  override {
0172       return m_invisibleVis;
0173     }
0174     /// Return reference to the top-most (world) detector element
0175     virtual DetElement world() const  override {
0176       return m_world;
0177     }
0178     /// Return reference to detector element with all tracker devices.
0179     virtual DetElement trackers() const  override {
0180       return m_trackers;
0181     }
0182     /// Return handle to the world volume containing everything
0183     virtual Volume worldVolume() const  override {
0184       return m_worldVol;
0185     }
0186     /// Return handle to the world volume containing the volume with the tracking devices
0187     virtual Volume parallelWorldVolume() const override  {
0188       return m_parallelWorldVol;
0189     }
0190     /// Return handle to the world volume containing the volume with the tracking devices
0191     virtual Volume trackingVolume() const  override {
0192       return m_trackingVol;
0193     }
0194     /// Set the tracking volume of the detector
0195     virtual void setTrackingVolume(Volume vol)  override {
0196       m_trackingVol = vol;
0197     }
0198     /// Return handle to the VolumeManager
0199     virtual VolumeManager volumeManager() const  override {
0200       return m_volManager;
0201     }
0202     /// Access the optical surface manager
0203     virtual OpticalSurfaceManager surfaceManager()  const  override  {
0204       return OpticalSurfaceManager(m_surfaceManager);
0205     }
0206 
0207     /// Return handle to the combined electromagentic field description.
0208     virtual OverlayedField field() const  override {
0209       return m_field;
0210     }
0211 
0212     /// Access default conditions (temperature and pressure
0213     virtual const STD_Conditions& stdConditions()  const  override;
0214     /// Set the STD temperature and pressure
0215     virtual void setStdConditions(double temp, double pressure) override;
0216     /// Set the STD conditions according to defined types (STP or NTP)
0217     virtual void setStdConditions(const std::string& type)  override;
0218 
0219     /// Accessor to the header entry
0220     virtual Header header() const  override {
0221       return m_header;
0222     }
0223     /// Accessor to the header entry
0224     virtual void setHeader(Header h)  override {
0225       m_header = h;
0226     }
0227 
0228     /// Typed access to constants: access string values
0229     virtual std::string constantAsString(const std::string& name) const  override;
0230 
0231     /// Typed access to constants: long values
0232     virtual long constantAsLong(const std::string& name) const  override;
0233 
0234     /// Typed access to constants: double values
0235     virtual double constantAsDouble(const std::string& name) const  override;
0236 
0237     /// Retrieve a constant by its name from the detector description
0238     virtual Constant constant(const std::string& name) const  override;
0239 
0240     /// Retrieve a limitset by its name from the detector description
0241     virtual LimitSet limitSet(const std::string& name) const  override {
0242       return getRefChild(m_limits, name);
0243     }
0244     /// Retrieve a visualization attribute by its name from the detector description
0245     virtual VisAttr visAttributes(const std::string& name) const  override {
0246       return getRefChild(m_display, name, false);
0247     }
0248     /// Retrieve a matrial by its name from the detector description
0249     virtual Material material(const std::string& name) const  override;
0250 
0251     /// Retrieve a region object by its name from the detector description
0252     virtual Region region(const std::string& name) const  override {
0253       return getRefChild(m_regions, name);
0254     }
0255     /// Retrieve a id descriptor by its name from the detector description
0256     virtual IDDescriptor idSpecification(const std::string& name) const  override {
0257       return getRefChild(m_idDict, name);
0258     }
0259     /// Retrieve a readout object by its name from the detector description
0260     virtual Readout readout(const std::string& name) const  override {
0261       return getRefChild(m_readouts, name);
0262     }
0263     /// Retrieve a subdetector element by its name from the detector description
0264     virtual DetElement detector(const std::string& name) const  override;
0265     //{      return getRefChild(m_detectors, name);    }
0266     /// Retrieve a sensitive detector by its name from the detector description
0267     virtual SensitiveDetector sensitiveDetector(const std::string& name) const  override {
0268       return getRefChild(m_sensitive, name, false);
0269     }
0270     /// Retrieve a subdetector element by its name from the detector description
0271     virtual CartesianField field(const std::string& name) const  override {
0272       return getRefChild(m_fields, name, false);
0273     }
0274 
0275     /// Accessor to the map of constants
0276     virtual const HandleMap& constants() const  override {
0277       return m_define;
0278     }
0279     /// Accessor to the map of visualisation attributes
0280     virtual const HandleMap& visAttributes() const  override {
0281       return m_display;
0282     }
0283     /// Accessor to the map of limit settings
0284     virtual const HandleMap& limitsets() const  override {
0285       return m_limits;
0286     }
0287     /// Accessor to the map of region settings
0288     virtual const HandleMap& regions() const  override {
0289       return m_regions;
0290     }
0291     /// Accessor to the map of readout structures
0292     virtual const HandleMap& readouts() const  override {
0293       return m_readouts;
0294     }
0295     /// Accessor to the map of sub-detectors
0296     virtual const HandleMap& detectors() const  override {
0297       return m_detectors;
0298     }
0299     /// Retrieve a sensitive detector by its name from the detector description
0300     virtual const HandleMap& sensitiveDetectors() const  override {
0301       return m_sensitive;
0302     }
0303     /// Accessor to the map of field entries, which together form the global field
0304     virtual const HandleMap& fields() const  override {
0305       return m_fields;
0306     }
0307     /// Accessor to the map of ID specifications
0308     virtual const HandleMap& idSpecifications() const  override {
0309       return m_idDict;
0310     }
0311 
0312     /// Access a set of subdetectors according to the sensitive type.
0313     /**
0314        Please note:
0315        - The sensitive type of a detector is set in the 'detector constructor'.
0316        - Not sensitive detector structures have the name 'passive'
0317        - Compounds (ie. nested detectors) are of type 'compound'
0318        - If throw_exc is set to true, an exception is thrown if the type
0319        is not present. Otherwise an empty detector container is returned.
0320     */
0321     virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) const override;
0322 
0323     /// Access a set of subdetectors according to several sensitive types.
0324     virtual std::vector<DetElement> detectors(const std::string& type1,
0325                                               const std::string& type2,
0326                                               const std::string& type3="",
0327                                               const std::string& type4="",
0328                                               const std::string& type5="" )  override;
0329 
0330     /// Access the availible detector types
0331     virtual std::vector<std::string> detectorTypes() const  override;
0332 
0333     /** return a vector with all detectors that have all the type properties in
0334      *  includeFlag set but none of the properties given in excludeFlag
0335      */
0336     virtual std::vector<DetElement> detectors(unsigned int includeFlag, 
0337                                               unsigned int excludeFlag=0 ) const   override;
0338 
0339 
0340 #define __R  return *this
0341     /// Add a new constant to the detector description
0342     virtual Detector& add(Constant x)  override {
0343       return addConstant(x);
0344     }
0345     /// Add a new limit set to the detector description
0346     virtual Detector& add(LimitSet x)  override {
0347       return addLimitSet(x);
0348     }
0349     /// Add a new detector region to the detector description
0350     virtual Detector& add(Region x)  override {
0351       return addRegion(x);
0352     }
0353     /// Add a new visualisation attribute to the detector description
0354     virtual Detector& add(VisAttr x)  override {
0355       return addVisAttribute(x);
0356     }
0357     /// Add a new id descriptor to the detector description
0358     virtual Detector& add(IDDescriptor x)  override {
0359       return addIDSpecification(x);
0360     }
0361     /// Add a new detector readout to the detector description
0362     virtual Detector& add(Readout x)  override {
0363       return addReadout(x);
0364     }
0365     /// Add a new sensitive detector to the detector description
0366     virtual Detector& add(SensitiveDetector x)  override {
0367       return addSensitiveDetector(x);
0368     }
0369     /// Add a new subdetector to the detector description
0370     virtual Detector& add(DetElement x)  override {
0371       return addDetector(x);
0372     }
0373     /// Add a field component to the detector description
0374     virtual Detector& add(CartesianField x)  override {
0375       return addField(x);
0376     }
0377 
0378     /// Add a new constant by named reference to the detector description
0379     virtual Detector& addConstant(const Handle<NamedObject>& x)  override;
0380 
0381     /// Add a new limit set by named reference to the detector description
0382     virtual Detector& addLimitSet(const Handle<NamedObject>& x)  override {
0383       m_limits.append(x);
0384       __R;
0385     }
0386     /// Add a new detector region by named reference to the detector description
0387     virtual Detector& addRegion(const Handle<NamedObject>& x)  override {
0388       m_regions.append(x);
0389       __R;
0390     }
0391     /// Add a new id descriptor by named reference to the detector description
0392     virtual Detector& addIDSpecification(const Handle<NamedObject>& x)  override {
0393       m_idDict.append(x);
0394       __R;
0395     }
0396     /// Add a new detector readout by named reference to the detector description
0397     virtual Detector& addReadout(const Handle<NamedObject>& x)  override {
0398       m_readouts.append(x);
0399       __R;
0400     }
0401     /// Add a new visualisation attribute by named reference to the detector description
0402     virtual Detector& addVisAttribute(const Handle<NamedObject>& x)  override {
0403       m_display.append(x);
0404       __R;
0405     }
0406     /// Add a new sensitive detector by named reference to the detector description
0407     virtual Detector& addSensitiveDetector(const Handle<NamedObject>& x)  override {
0408       m_sensitive.append(x);
0409       __R;
0410     }
0411     /// Add a new subdetector by named reference to the detector description
0412     virtual Detector& addDetector(const Handle<NamedObject>& x)  override;
0413     /// Add a field component by named reference to the detector description
0414     virtual Detector& addField(const Handle<NamedObject>& x)  override;
0415 #undef __R
0416     /// TObject overload: We need to set the Volume and PlacedVolume extensions to be persistent
0417     virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0)  override  {
0418       return saveObject(name, option, bufsize);
0419     }
0420     /// TObject overload: We need to set the Volume and PlacedVolume extensions to be persistent
0421     virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const override  {
0422       return saveObject(name, option, bufsize);
0423     }
0424 
0425     ClassDefOverride(DetectorImp,100);
0426     
0427   };
0428 } /* End namespace dd4hep   */
0429 
0430 #if defined(__CINT__) || defined(__MAKECINT__) || defined(__CLING__) || defined(__ROOTCLING__)
0431 #pragma link C++ class dd4hep::DetectorImp+;
0432 #endif
0433 #endif // DD4HEP_DETECTORIMP_H