Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:00

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       return m_buildType;
0113     }
0114 
0115     /// Read compact geometry description or alignment file
0116     virtual void fromCompact(const std::string& fname, DetectorBuildType type = BUILD_DEFAULT)   override {
0117       fromXML(fname, type);
0118     }
0119 
0120     /// Read any XML file
0121     virtual void fromXML(const std::string& fname, DetectorBuildType type = BUILD_DEFAULT)  override;
0122 
0123     /// Read any geometry description or alignment file with external XML entity resolution
0124     virtual void fromXML(const std::string& fname,
0125                          xml::UriReader* entity_resolver,
0126                          DetectorBuildType type = BUILD_DEFAULT)  override;
0127 
0128     virtual void dump() const  override;
0129 
0130     /// Manipulate geometry using facroy converter
0131     virtual long apply(const char* factory, int argc, char** argv)  const  override;
0132 
0133     /// Open the geometry at startup.
0134     virtual void init()  override;
0135 
0136     /// Close the geometry
0137     virtual void endDocument(bool close_geometry)  override;
0138 
0139     /// Add an extension object to the Detector instance
0140     virtual void* addUserExtension(unsigned long long int key, ExtensionEntry* entry)  override;
0141 
0142     /// Remove an existing extension object from the Detector instance. If not destroyed, the instance is returned
0143     virtual void* removeUserExtension(unsigned long long int key, bool destroy=true)  override;
0144 
0145     /// Access an existing extension object from the Detector instance
0146     virtual void* userExtension(unsigned long long int key, bool alert=true) const  override;
0147 
0148     virtual Handle<NamedObject> getRefChild(const HandleMap& e, const std::string& name, bool throw_if_not = true) const;
0149 
0150     /// Register new mother volume using the detector name.
0151     virtual void   declareParent(const std::string& detector_name, const DetElement& parent)  override;
0152 
0153     /// Access mother volume by detector element
0154     virtual Volume pickMotherVolume(const DetElement& sd) const  override;
0155 
0156     /// Access the geometry manager of this instance
0157     virtual TGeoManager& manager() const   override  {
0158       return *m_manager;
0159     }
0160     /// Access to properties
0161     Properties& properties() const  override {
0162       return *(Properties*)&m_properties;
0163     }
0164     /// Return handle to material describing air
0165     virtual Material air() const  override {
0166       return m_materialAir;
0167     }
0168     /// Return handle to material describing vacuum
0169     virtual Material vacuum() const  override {
0170       return m_materialVacuum;
0171     }
0172     /// Return handle to "invisible" visualization attributes
0173     virtual VisAttr invisible() const  override {
0174       return m_invisibleVis;
0175     }
0176     /// Return reference to the top-most (world) detector element
0177     virtual DetElement world() const  override {
0178       return m_world;
0179     }
0180     /// Return reference to detector element with all tracker devices.
0181     virtual DetElement trackers() const  override {
0182       return m_trackers;
0183     }
0184     /// Return handle to the world volume containing everything
0185     virtual Volume worldVolume() const  override {
0186       return m_worldVol;
0187     }
0188     /// Return handle to the world volume containing the volume with the tracking devices
0189     virtual Volume parallelWorldVolume() const override  {
0190       return m_parallelWorldVol;
0191     }
0192     /// Return handle to the world volume containing the volume with the tracking devices
0193     virtual Volume trackingVolume() const  override {
0194       return m_trackingVol;
0195     }
0196     /// Set the tracking volume of the detector
0197     virtual void setTrackingVolume(Volume vol)  override {
0198       m_trackingVol = vol;
0199     }
0200     /// Return handle to the VolumeManager
0201     virtual VolumeManager volumeManager() const  override {
0202       return m_volManager;
0203     }
0204     /// Access the optical surface manager
0205     virtual OpticalSurfaceManager surfaceManager()  const  override  {
0206       return OpticalSurfaceManager(m_surfaceManager);
0207     }
0208 
0209     /// Return handle to the combined electromagentic field description.
0210     virtual OverlayedField field() const  override {
0211       return m_field;
0212     }
0213 
0214     /// Access default conditions (temperature and pressure
0215     virtual const STD_Conditions& stdConditions()  const  override;
0216     /// Set the STD temperature and pressure
0217     virtual void setStdConditions(double temp, double pressure) override;
0218     /// Set the STD conditions according to defined types (STP or NTP)
0219     virtual void setStdConditions(const std::string& type)  override;
0220 
0221     /// Accessor to the header entry
0222     virtual Header header() const  override {
0223       return m_header;
0224     }
0225     /// Accessor to the header entry
0226     virtual void setHeader(Header h)  override {
0227       m_header = h;
0228     }
0229 
0230     /// Typed access to constants: access string values
0231     virtual std::string constantAsString(const std::string& name) const  override;
0232 
0233     /// Typed access to constants: long values
0234     virtual long constantAsLong(const std::string& name) const  override;
0235 
0236     /// Typed access to constants: double values
0237     virtual double constantAsDouble(const std::string& name) const  override;
0238 
0239     /// Retrieve a constant by its name from the detector description
0240     virtual Constant constant(const std::string& name) const  override;
0241 
0242     /// Retrieve a limitset by its name from the detector description
0243     virtual LimitSet limitSet(const std::string& name) const  override {
0244       return getRefChild(m_limits, name);
0245     }
0246     /// Retrieve a visualization attribute by its name from the detector description
0247     virtual VisAttr visAttributes(const std::string& name) const  override {
0248       return getRefChild(m_display, name, false);
0249     }
0250     /// Retrieve a matrial by its name from the detector description
0251     virtual Material material(const std::string& name) const  override;
0252 
0253     /// Retrieve a region object by its name from the detector description
0254     virtual Region region(const std::string& name) const  override {
0255       return getRefChild(m_regions, name);
0256     }
0257     /// Retrieve a id descriptor by its name from the detector description
0258     virtual IDDescriptor idSpecification(const std::string& name) const  override {
0259       return getRefChild(m_idDict, name);
0260     }
0261     /// Retrieve a readout object by its name from the detector description
0262     virtual Readout readout(const std::string& name) const  override {
0263       return getRefChild(m_readouts, name);
0264     }
0265     /// Retrieve a subdetector element by its name from the detector description
0266     virtual DetElement detector(const std::string& name) const  override;
0267     //{      return getRefChild(m_detectors, name);    }
0268     /// Retrieve a sensitive detector by its name from the detector description
0269     virtual SensitiveDetector sensitiveDetector(const std::string& name) const  override {
0270       return getRefChild(m_sensitive, name, false);
0271     }
0272     /// Retrieve a subdetector element by its name from the detector description
0273     virtual CartesianField field(const std::string& name) const  override {
0274       return getRefChild(m_fields, name, false);
0275     }
0276 
0277     /// Accessor to the map of constants
0278     virtual const HandleMap& constants() const  override {
0279       return m_define;
0280     }
0281     /// Accessor to the map of visualisation attributes
0282     virtual const HandleMap& visAttributes() const  override {
0283       return m_display;
0284     }
0285     /// Accessor to the map of limit settings
0286     virtual const HandleMap& limitsets() const  override {
0287       return m_limits;
0288     }
0289     /// Accessor to the map of region settings
0290     virtual const HandleMap& regions() const  override {
0291       return m_regions;
0292     }
0293     /// Accessor to the map of readout structures
0294     virtual const HandleMap& readouts() const  override {
0295       return m_readouts;
0296     }
0297     /// Accessor to the map of sub-detectors
0298     virtual const HandleMap& detectors() const  override {
0299       return m_detectors;
0300     }
0301     /// Retrieve a sensitive detector by its name from the detector description
0302     virtual const HandleMap& sensitiveDetectors() const  override {
0303       return m_sensitive;
0304     }
0305     /// Accessor to the map of field entries, which together form the global field
0306     virtual const HandleMap& fields() const  override {
0307       return m_fields;
0308     }
0309     /// Accessor to the map of ID specifications
0310     virtual const HandleMap& idSpecifications() const  override {
0311       return m_idDict;
0312     }
0313 
0314     /// Access a set of subdetectors according to the sensitive type.
0315     /**
0316        Please note:
0317        - The sensitive type of a detector is set in the 'detector constructor'.
0318        - Not sensitive detector structures have the name 'passive'
0319        - Compounds (ie. nested detectors) are of type 'compound'
0320        - If throw_exc is set to true, an exception is thrown if the type
0321        is not present. Otherwise an empty detector container is returned.
0322     */
0323     virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) const override;
0324 
0325     /// Access a set of subdetectors according to several sensitive types.
0326     virtual std::vector<DetElement> detectors(const std::string& type1,
0327                                               const std::string& type2,
0328                                               const std::string& type3="",
0329                                               const std::string& type4="",
0330                                               const std::string& type5="" )  override;
0331 
0332     /// Access the availible detector types
0333     virtual std::vector<std::string> detectorTypes() const  override;
0334 
0335     /** return a vector with all detectors that have all the type properties in
0336      *  includeFlag set but none of the properties given in excludeFlag
0337      */
0338     virtual std::vector<DetElement> detectors(unsigned int includeFlag, 
0339                                               unsigned int excludeFlag=0 ) const   override;
0340 
0341 
0342 #define __R  return *this
0343     /// Add a new constant to the detector description
0344     virtual Detector& add(Constant x)  override {
0345       return addConstant(x);
0346     }
0347     /// Add a new limit set to the detector description
0348     virtual Detector& add(LimitSet x)  override {
0349       return addLimitSet(x);
0350     }
0351     /// Add a new detector region to the detector description
0352     virtual Detector& add(Region x)  override {
0353       return addRegion(x);
0354     }
0355     /// Add a new visualisation attribute to the detector description
0356     virtual Detector& add(VisAttr x)  override {
0357       return addVisAttribute(x);
0358     }
0359     /// Add a new id descriptor to the detector description
0360     virtual Detector& add(IDDescriptor x)  override {
0361       return addIDSpecification(x);
0362     }
0363     /// Add a new detector readout to the detector description
0364     virtual Detector& add(Readout x)  override {
0365       return addReadout(x);
0366     }
0367     /// Add a new sensitive detector to the detector description
0368     virtual Detector& add(SensitiveDetector x)  override {
0369       return addSensitiveDetector(x);
0370     }
0371     /// Add a new subdetector to the detector description
0372     virtual Detector& add(DetElement x)  override {
0373       return addDetector(x);
0374     }
0375     /// Add a field component to the detector description
0376     virtual Detector& add(CartesianField x)  override {
0377       return addField(x);
0378     }
0379 
0380     /// Add a new constant by named reference to the detector description
0381     virtual Detector& addConstant(const Handle<NamedObject>& x)  override;
0382 
0383     /// Add a new limit set by named reference to the detector description
0384     virtual Detector& addLimitSet(const Handle<NamedObject>& x)  override {
0385       m_limits.append(x);
0386       __R;
0387     }
0388     /// Add a new detector region by named reference to the detector description
0389     virtual Detector& addRegion(const Handle<NamedObject>& x)  override {
0390       m_regions.append(x);
0391       __R;
0392     }
0393     /// Add a new id descriptor by named reference to the detector description
0394     virtual Detector& addIDSpecification(const Handle<NamedObject>& x)  override {
0395       m_idDict.append(x);
0396       __R;
0397     }
0398     /// Add a new detector readout by named reference to the detector description
0399     virtual Detector& addReadout(const Handle<NamedObject>& x)  override {
0400       m_readouts.append(x);
0401       __R;
0402     }
0403     /// Add a new visualisation attribute by named reference to the detector description
0404     virtual Detector& addVisAttribute(const Handle<NamedObject>& x)  override {
0405       m_display.append(x);
0406       __R;
0407     }
0408     /// Add a new sensitive detector by named reference to the detector description
0409     virtual Detector& addSensitiveDetector(const Handle<NamedObject>& x)  override {
0410       m_sensitive.append(x);
0411       __R;
0412     }
0413     /// Add a new subdetector by named reference to the detector description
0414     virtual Detector& addDetector(const Handle<NamedObject>& x)  override;
0415     /// Add a field component by named reference to the detector description
0416     virtual Detector& addField(const Handle<NamedObject>& x)  override;
0417 #undef __R
0418     /// TObject overload: We need to set the Volume and PlacedVolume extensions to be persistent
0419     virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0)  override  {
0420       return saveObject(name, option, bufsize);
0421     }
0422     /// TObject overload: We need to set the Volume and PlacedVolume extensions to be persistent
0423     virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const override  {
0424       return saveObject(name, option, bufsize);
0425     }
0426 
0427     ClassDefOverride(DetectorImp,100);
0428     
0429   };
0430 } /* End namespace dd4hep   */
0431 
0432 #if defined(__CINT__) || defined(__MAKECINT__) || defined(__CLING__) || defined(__ROOTCLING__)
0433 #pragma link C++ class dd4hep::DetectorImp+;
0434 #endif
0435 #endif // DD4HEP_DETECTORIMP_H