DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Segmentation.h
Go to the documentation of this file.
1 /*
2  * Segmentation.h
3  *
4  * Created on: Jun 27, 2013
5  * Author: Christian Grefe, CERN
6  */
7 
8 #ifndef DDSegmentation_SEGMENTATION_H_
9 #define DDSegmentation_SEGMENTATION_H_
10 
14 
15 #include <map>
16 #include <utility>
17 #include <set>
18 #include <string>
19 #include <vector>
20 
21 namespace DD4hep {
22 namespace DDSegmentation {
23 
25 typedef std::vector<Parameter> Parameters;
35 
37 typedef long long int CellID;
38 typedef long long int VolumeID;
39 
41 struct Vector3D {
43  Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
44  X(x_val), Y(y_val), Z(z_val) {
45  }
47  template<typename T> Vector3D(const T& v) {
48  X = v.x();
49  Y = v.y();
50  Z = v.Z();
51  }
53  double x() const {
54  return X;
55  }
57  double y() const {
58  return Y;
59  }
61  double z() const {
62  return Z;
63  }
64  double X, Y, Z;
65 };
66 
68 class Segmentation {
69 public:
71  virtual ~Segmentation();
72 
74  virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
76  virtual Vector3D position(const CellID& cellID) const = 0;
78  virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
79  const VolumeID& volumeID) const = 0;
81  virtual VolumeID volumeID(const CellID& cellID) const;
83  virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
85  virtual std::string fieldDescription() const {
86  return _decoder->fieldDescription();
87  }
89  virtual const std::string& name() const {
90  return _name;
91  }
93  virtual void setName(const std::string& value) {
94  _name = value;
95  }
97  virtual const std::string& type() const {
98  return _type;
99  }
101  virtual const std::string& description() const {
102  return _description;
103  }
105  virtual BitField64* decoder() const {
106  return _decoder;
107  }
109  virtual void setDecoder(BitField64* decoder);
111  virtual Parameter parameter(const std::string& parameterName) const;
113  virtual Parameters parameters() const;
115  virtual void setParameters(const Parameters& parameters);
122  virtual std::vector<double> cellDimensions(const CellID& cellID) const;
123 
124 protected:
126  Segmentation(const std::string& cellEncoding = "");
129 
131  template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
132  TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
133  bool isOpt = false) {
134  _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
135  }
137  void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
138  const std::string& defaultVal);
139 
141  static double binToPosition(CellID bin, double cellSize, double offset = 0.);
143  static int positionToBin(double position, double cellSize, double offset = 0.);
144 
146  static double binToPosition(CellID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
148  static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
149 
151  std::string _name;
153  std::string _type;
155  std::string _description;
157  std::map<std::string, Parameter> _parameters;
159  std::map<std::string, StringParameter> _indexIdentifiers;
164 private:
166  Segmentation(const Segmentation&);
167 };
168 
170 #define REGISTER_SEGMENTATION(classname) \
171  static const SegmentationCreator<classname> classname##_creator(#classname);
172 
173 } /* namespace DDSegmentation */
174 } /* namespace DD4hep */
175 #endif /* DDSegmentation_SEGMENTATION_H_ */
long long int CellID
Useful typedefs to differentiate cell IDs and volume IDs.
Definition: Primitives.h:32
Vector3D(const T &v)
Constructor using a foreign vector class. Requires methods x(), y() and z()
Definition: Segmentation.h:47
double x() const
Access to x value (required for use with ROOT GenVector)
Definition: Segmentation.h:53
void registerIdentifier(const std::string &nam, const std::string &desc, std::string &ident, const std::string &defaultVal)
Add a cell identifier to this segmentation. Used by derived classes to define their required identifi...
virtual VolumeID volumeID(const CellID &cellID) const
Determine the volume ID from the full cell ID by removing all local fields.
std::map< std::string, StringParameter > _indexIdentifiers
The indices used for the encoding.
Definition: Segmentation.h:159
virtual void neighbours(const CellID &cellID, std::set< CellID > &neighbours) const
Calculates the neighbours of the given cell ID and adds them to the list of neighbours.
virtual BitField64 * decoder() const
Access the underlying decoder.
Definition: Segmentation.h:105
TypedSegmentationParameter< std::vector< float > > * FloatVecParameter
Definition: Segmentation.h:31
TypedSegmentationParameter< double > * DoubleParameter
Definition: Segmentation.h:28
virtual Parameters parameters() const
Access to all parameters.
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:89
BitField64 * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:161
double y() const
Access to y value (required for use with ROOT GenVector)
Definition: Segmentation.h:57
UnitType
Defines the parameter unit type (useful to convert to default set of units)
TypedSegmentationParameter< std::vector< int > > * IntVecParameter
Definition: Segmentation.h:30
std::vector< Parameter > Parameters
Definition: Segmentation.h:25
TypedSegmentationParameter< std::vector< double > > * DoubleVecParameter
Definition: Segmentation.h:32
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.
virtual void setParameters(const Parameters &parameters)
Set all parameters from an existing set of parameters.
Segmentation(const std::string &cellEncoding="")
Default constructor used by derived classes passing the encoding string.
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions...
Simple container for a physics vector.
Definition: Segmentation.h:41
bool _ownsDecoder
Keeps track of the decoder ownership.
Definition: Segmentation.h:163
std::map< std::string, Parameter > _parameters
The parameters for this segmentation.
Definition: Segmentation.h:157
std::string _description
The description of the segmentation.
Definition: Segmentation.h:155
TypedSegmentationParameter< int > * IntParameter
Definition: Segmentation.h:26
Base class for all segmentations.
Definition: Segmentation.h:68
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const =0
Determine the cell ID based on the position.
double z() const
Access to z value (required for use with ROOT GenVector)
Definition: Segmentation.h:61
static int positionToBin(double position, double cellSize, double offset=0.)
Helper method to convert a 1D position to a cell ID.
Vector3D(double x_val=0., double y_val=0., double z_val=0.)
Default constructor.
Definition: Segmentation.h:43
TypedSegmentationParameter< std::vector< std::string > > * StringVecParameter
Definition: Segmentation.h:33
void registerParameter(const std::string &nam, const std::string &desc, TYPE &param, const TYPE &defaultVal, UnitType unitTyp=SegmentationParameter::NoUnit, bool isOpt=false)
Add a parameter to this segmentation. Used by derived classes to define their parameters.
Definition: Segmentation.h:131
virtual Parameter parameter(const std::string &parameterName) const
Access to parameter by name.
std::string fieldDescription() const
Definition: BitField64.cpp:155
std::string _type
The segmentation type.
Definition: Segmentation.h:153
virtual void addSubsegmentation(long key_min, long key_max, Segmentation *entry)
Add subsegmentation. Call only valid for Multi-segmentations. Default implementation throws an except...
View * v
Definition: MultiView.cpp:30
long long int VolumeID
Definition: Primitives.h:35
virtual void setDecoder(BitField64 *decoder)
Set the underlying decoder.
virtual void setName(const std::string &value)
Set the segmentation name.
Definition: Segmentation.h:93
std::string _name
The segmentation name.
Definition: Segmentation.h:151
virtual ~Segmentation()
Destructor.
virtual const std::string & type() const
Access the segmentation type.
Definition: Segmentation.h:97
Class to hold a segmentation parameter with its description.
TypedSegmentationParameter< std::string > * StringParameter
Definition: Segmentation.h:29
SegmentationParameter * Parameter
Definition: Segmentation.h:24
static double binToPosition(CellID bin, double cellSize, double offset=0.)
Helper method to convert a bin number to a 1D position.
virtual const std::string & description() const
Access the description of the segmentation.
Definition: Segmentation.h:101
TypedSegmentationParameter< float > * FloatParameter
Definition: Segmentation.h:27
virtual std::string fieldDescription() const
Access the encoding string.
Definition: Segmentation.h:85
SegmentationParameter::UnitType UnitType
Definition: Segmentation.h:34