Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:32:43

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_DETAIL_SEGMENTATIONSINTERNA_H
0014 #define DD4HEP_DETAIL_SEGMENTATIONSINTERNA_H
0015 
0016 // Framework include files
0017 #include <DD4hep/Handle.h>
0018 #include <DD4hep/Objects.h>
0019 #include <DD4hep/BitFieldCoder.h>
0020 
0021 // C/C++ include files
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   // Forward declarations
0027   class DetElementObject;
0028   class SegmentationObject;
0029   class SensitiveDetectorObject;
0030 
0031   namespace DDSegmentation {
0032     class Segmentation;
0033     class SegmentationParameter;
0034     typedef SegmentationParameter* Parameter;
0035     typedef std::vector<Parameter> Parameters;
0036   }
0037 
0038   /// Implementation class supporting generic Segmentation of sensitive detectors
0039   /**
0040    *  The SegmentationObject wraps the functionality of the DDSegmentation base class.
0041    *
0042    *  \author  M.Frank
0043    *  \version 1.0
0044    *  \ingroup DD4HEP_CORE
0045    */
0046   class SegmentationObject {
0047   public:
0048     /// Standard constructor
0049     SegmentationObject(DDSegmentation::Segmentation* seg = 0);
0050     /// Default destructor
0051     virtual ~SegmentationObject();
0052     /// Access the encoding string
0053     std::string fieldDescription() const;
0054     /// Access the segmentation name
0055     const std::string& name() const;
0056     /// Set the segmentation name
0057     void setName(const std::string& value);
0058 
0059     /// Access the segmentation type
0060     const std::string& type() const;
0061     /// Access the description of the segmentation
0062     const std::string& description() const;
0063     /// Access the underlying decoder
0064     const BitFieldCoder* decoder() const;
0065     /// Set the underlying decoder
0066     void setDecoder(const BitFieldCoder* decoder) const;
0067     /// Access to parameter by name
0068     DDSegmentation::Parameter  parameter(const std::string& parameterName) const;
0069     /// Access to all parameters
0070     DDSegmentation::Parameters parameters() const;
0071     /// Set all parameters from an existing set of parameters
0072     void setParameters(const DDSegmentation::Parameters& parameters);
0073 
0074     /** Segmentation interface  */
0075     /// Determine the local position based on the cell ID
0076     Position position(const CellID& cellID) const;
0077     /// Determine the cell ID based on the position
0078     CellID cellID(const Position& localPosition,
0079                   const Position& globalPosition,
0080                   const VolumeID& volumeID) const;
0081     /// Determine the volume ID from the full cell ID by removing all local fields
0082     VolumeID volumeID(const CellID& cellID) const;
0083     /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours
0084     void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
0085 
0086     /** Data members.                                          */
0087     /// Magic word to check object integrity
0088     unsigned long magic;
0089     /// Flag to use segmentation for hit positioning
0090     unsigned char useForHitPosition;
0091     /// Reference to hosting top level DetElement structure
0092     Handle<DetElementObject> detector;      
0093     /// Reference to hosting top level sensitve detector structure
0094     Handle<SensitiveDetectorObject> sensitive;
0095     /// Reference to base segmentation
0096     DDSegmentation::Segmentation* segmentation = 0;
0097   };
0098 
0099   /// Concrete wrapper class for segmentation implementation based on DDSegmentation objects
0100   /**
0101    * \author  M.Frank
0102    * \version 1.0
0103    * \ingroup DD4HEP_CORE
0104    */
0105   template <typename IMP> class SegmentationWrapper : public SegmentationObject {
0106   public:
0107     /// DDSegmentation aggregate
0108     IMP* implementation;
0109   public:
0110 #if defined(G__ROOT) || defined(__CLANG__) || defined(__ROOTCLING__)
0111     /// Empty constructor for ROOT persistency
0112     SegmentationWrapper() : SegmentationObject(implementation=new IMP(0)) { }
0113 #endif
0114     /// Standard constructor
0115     SegmentationWrapper(const BitFieldCoder* decoder);
0116     /// Default destructor
0117     virtual ~SegmentationWrapper();
0118   };
0119   
0120   /// Standard constructor
0121   template <typename IMP> inline
0122   SegmentationWrapper<IMP>::SegmentationWrapper(const BitFieldCoder* decode)
0123     :  SegmentationObject(implementation=new IMP(decode))
0124   {
0125   }
0126 
0127   /// Default destructor
0128   template <typename IMP> inline SegmentationWrapper<IMP>::~SegmentationWrapper()  {
0129   }
0130 
0131   namespace {
0132     template<typename T> SegmentationObject*
0133     create_segmentation(const BitFieldCoder* decoder)  {
0134       return new SegmentationWrapper<T>(decoder);
0135     }
0136   }
0137 
0138 }         /* End namespace dd4hep                       */
0139 #endif // DD4HEP_DETAIL_SEGMENTATIONSINTERNA_H