File indexing completed on 2025-07-15 08:14:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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 <set>
0028 #include <string>
0029 #include <vector>
0030
0031 namespace dd4hep {
0032 namespace DDSegmentation {
0033
0034 typedef SegmentationParameter* Parameter;
0035 typedef std::vector<Parameter> Parameters;
0036 typedef TypedSegmentationParameter<int>* IntParameter;
0037 typedef TypedSegmentationParameter<float>* FloatParameter;
0038 typedef TypedSegmentationParameter<double>* DoubleParameter;
0039 typedef TypedSegmentationParameter<std::string>* StringParameter;
0040 typedef TypedSegmentationParameter<std::vector<int> >* IntVecParameter;
0041 typedef TypedSegmentationParameter<std::vector<float> >* FloatVecParameter;
0042 typedef TypedSegmentationParameter<std::vector<double> >* DoubleVecParameter;
0043 typedef TypedSegmentationParameter<std::vector<std::string> >* StringVecParameter;
0044 typedef SegmentationParameter::UnitType UnitType;
0045
0046
0047 struct Vector3D {
0048
0049 Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
0050 X(x_val), Y(y_val), Z(z_val) {
0051 }
0052
0053 template<typename T> Vector3D(const T& v) {
0054 X = v.x();
0055 Y = v.y();
0056 Z = v.Z();
0057 }
0058
0059 double x() const {
0060 return X;
0061 }
0062
0063 double y() const {
0064 return Y;
0065 }
0066
0067 double z() const {
0068 return Z;
0069 }
0070 double X, Y, Z;
0071 };
0072
0073
0074 class Segmentation {
0075 public:
0076
0077 virtual ~Segmentation();
0078
0079
0080 virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
0081
0082 virtual Vector3D position(const CellID& cellID) const = 0;
0083
0084 virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
0085 const VolumeID& volumeID) const = 0;
0086
0087 virtual VolumeID volumeID(const CellID& cellID) const;
0088
0089 virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
0090
0091 virtual std::string fieldDescription() const {
0092 return _decoder->fieldDescription();
0093 }
0094
0095 virtual const std::string& name() const {
0096 return _name;
0097 }
0098
0099 virtual void setName(const std::string& value) {
0100 _name = value;
0101 }
0102
0103 virtual const std::string& type() const {
0104 return _type;
0105 }
0106
0107 virtual const std::string& description() const {
0108 return _description;
0109 }
0110
0111 virtual const BitFieldCoder* decoder() const {
0112 return _decoder;
0113 }
0114
0115 virtual void setDecoder(const BitFieldCoder* decoder);
0116
0117 virtual Parameter parameter(const std::string& parameterName) const;
0118
0119 virtual Parameters parameters() const;
0120
0121 virtual void setParameters(const Parameters& parameters);
0122
0123
0124
0125
0126
0127
0128 virtual std::vector<double> cellDimensions(const CellID& cellID) const;
0129
0130
0131
0132
0133 virtual bool cellsSpanVolumes() const
0134 {
0135 return false;
0136 }
0137
0138 protected:
0139
0140 Segmentation(const std::string& cellEncoding = "");
0141
0142 Segmentation(const BitFieldCoder* decoder);
0143
0144
0145 template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
0146 TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
0147 bool isOpt = false) {
0148 _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
0149 }
0150
0151 void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
0152 const std::string& defaultVal);
0153
0154
0155 static double binToPosition(FieldID bin, double cellSize, double offset = 0.);
0156
0157 static int positionToBin(double position, double cellSize, double offset = 0.);
0158
0159
0160 static double binToPosition(FieldID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
0161
0162 static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
0163
0164
0165 std::string _name;
0166
0167 std::string _type;
0168
0169 std::string _description;
0170
0171 std::map<std::string, Parameter> _parameters;
0172
0173 std::map<std::string, StringParameter> _indexIdentifiers;
0174
0175 const BitFieldCoder* _decoder = 0;
0176
0177 bool _ownsDecoder = false;
0178 private:
0179
0180 Segmentation(const Segmentation&);
0181 };
0182
0183 }
0184 }
0185 #endif