Back to home page

EIC code displayed by LXR

 
 

    


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

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 //==========================================================================
0011 
0012 /*
0013  * Segmentation.h
0014  *
0015  *  Created on: Jun 27, 2013
0016  *      Author: Christian Grefe, CERN
0017  */
0018 
0019 #ifndef DDSEGMENTATION_SEGMENTATION_H
0020 #define DDSEGMENTATION_SEGMENTATION_H
0021 
0022 #include <DD4hep/detail/SegmentationsInterna.h>
0023 #include <DDSegmentation/BitFieldCoder.h>
0024 #include <DDSegmentation/SegmentationParameter.h>
0025 
0026 #include <map>
0027 #include <utility>
0028 #include <set>
0029 #include <string>
0030 #include <vector>
0031 
0032 namespace dd4hep {
0033   namespace DDSegmentation {
0034 
0035     typedef SegmentationParameter* Parameter;
0036     typedef std::vector<Parameter> Parameters;
0037     typedef TypedSegmentationParameter<int>* IntParameter;
0038     typedef TypedSegmentationParameter<float>* FloatParameter;
0039     typedef TypedSegmentationParameter<double>* DoubleParameter;
0040     typedef TypedSegmentationParameter<std::string>* StringParameter;
0041     typedef TypedSegmentationParameter<std::vector<int> >* IntVecParameter;
0042     typedef TypedSegmentationParameter<std::vector<float> >* FloatVecParameter;
0043     typedef TypedSegmentationParameter<std::vector<double> >* DoubleVecParameter;
0044     typedef TypedSegmentationParameter<std::vector<std::string> >* StringVecParameter;
0045     typedef SegmentationParameter::UnitType UnitType;
0046 
0047     /// Simple container for a physics vector
0048     struct Vector3D {
0049       /// Default constructor
0050       Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
0051         X(x_val), Y(y_val), Z(z_val) {
0052       }
0053       /// Constructor using a foreign vector class. Requires methods x(), y() and z()
0054       template<typename T> Vector3D(const T& v) {
0055         X = v.x();
0056         Y = v.y();
0057         Z = v.Z();
0058       }
0059       /// Access to x value (required for use with ROOT GenVector)
0060       double x() const {
0061         return X;
0062       }
0063       /// Access to y value (required for use with ROOT GenVector)
0064       double y() const {
0065         return Y;
0066       }
0067       /// Access to z value (required for use with ROOT GenVector)
0068       double z() const {
0069         return Z;
0070       }
0071       double X, Y, Z;
0072     };
0073 
0074     /// Base class for all segmentations
0075     class Segmentation {
0076     public:
0077       /// Destructor
0078       virtual ~Segmentation();
0079 
0080       /// Add subsegmentation. Call only valid for Multi-segmentations. Default implementation throws an exception
0081       virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
0082       /// Determine the local position based on the cell ID
0083       virtual Vector3D position(const CellID& cellID) const = 0;
0084       /// Determine the cell ID based on the position
0085       virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
0086                             const VolumeID& volumeID) const = 0;
0087       /// Determine the volume ID from the full cell ID by removing all local fields
0088       virtual VolumeID volumeID(const CellID& cellID) const;
0089       /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours
0090       virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
0091       /// Access the encoding string
0092       virtual std::string fieldDescription() const {
0093         return _decoder->fieldDescription();
0094       }
0095       /// Access the segmentation name
0096       virtual const std::string& name() const {
0097         return _name;
0098       }
0099       /// Set the segmentation name
0100       virtual void setName(const std::string& value) {
0101         _name = value;
0102       }
0103       /// Access the segmentation type
0104       virtual const std::string& type() const {
0105         return _type;
0106       }
0107       /// Access the description of the segmentation
0108       virtual const std::string& description() const {
0109         return _description;
0110       }
0111       /// Access the underlying decoder
0112       virtual const BitFieldCoder* decoder()  const {
0113         return _decoder;
0114       }
0115       /// Set the underlying decoder
0116       virtual void setDecoder(const BitFieldCoder* decoder);
0117       /// Access to parameter by name
0118       virtual Parameter parameter(const std::string& parameterName) const;
0119       /// Access to all parameters
0120       virtual Parameters parameters() const;
0121       /// Set all parameters from an existing set of parameters
0122       virtual void setParameters(const Parameters& parameters);
0123       /** \brief Returns a vector<double> of the cellDimensions of the given cell ID
0124           in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi
0125 
0126           \param cellID cellID of the cell for which parameters are returned
0127           \return vector<double> in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi
0128       */
0129       virtual std::vector<double> cellDimensions(const CellID& cellID) const;
0130 
0131     protected:
0132       /// Default constructor used by derived classes passing the encoding string
0133       Segmentation(const std::string& cellEncoding = "");
0134       /// Default constructor used by derived classes passing an existing decoder
0135       Segmentation(const BitFieldCoder* decoder);
0136 
0137       /// Add a parameter to this segmentation. Used by derived classes to define their parameters
0138       template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
0139                                                      TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
0140                                                      bool isOpt = false) {
0141         _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
0142       }
0143       /// Add a cell identifier to this segmentation. Used by derived classes to define their required identifiers
0144       void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
0145                               const std::string& defaultVal);
0146 
0147       /// Helper method to convert a bin number to a 1D position
0148       static double binToPosition(FieldID bin, double cellSize, double offset = 0.);
0149       /// Helper method to convert a 1D position to a cell ID
0150       static int positionToBin(double position, double cellSize, double offset = 0.);
0151 
0152       /// Helper method to convert a bin number to a 1D position given a vector of binBoundaries
0153       static double binToPosition(FieldID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
0154       /// Helper method to convert a 1D position to a cell ID given a vector of binBoundaries
0155       static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
0156 
0157       /// The segmentation name
0158       std::string _name;
0159       /// The segmentation type
0160       std::string _type;
0161       /// The description of the segmentation
0162       std::string _description;
0163       /// The parameters for this segmentation
0164       std::map<std::string, Parameter> _parameters;   //! No ROOT persistency
0165       /// The indices used for the encoding
0166       std::map<std::string, StringParameter> _indexIdentifiers;   //! No ROOT persistency
0167       /// The cell ID encoder and decoder
0168       const BitFieldCoder* _decoder = 0;
0169       /// Keeps track of the decoder ownership
0170       bool _ownsDecoder = false;
0171     private:
0172       /// No copy constructor allowed
0173       Segmentation(const Segmentation&);
0174     };
0175 
0176   } /* namespace DDSegmentation */
0177 } /* namespace dd4hep */
0178 #endif // DDSEGMENTATION_SEGMENTATION_H