DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Segmentation.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 
12 /*
13  * Segmentation.h
14  *
15  * Created on: Jun 27, 2013
16  * Author: Christian Grefe, CERN
17  */
18 
19 #ifndef DDSEGMENTATION_SEGMENTATION_H
20 #define DDSEGMENTATION_SEGMENTATION_H
21 
25 
26 #include <map>
27 #include <utility>
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 namespace dd4hep {
33  namespace DDSegmentation {
34 
35  typedef SegmentationParameter* Parameter;
36  typedef std::vector<Parameter> Parameters;
46 
48  struct Vector3D {
50  Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
51  X(x_val), Y(y_val), Z(z_val) {
52  }
54  template<typename T> Vector3D(const T& v) {
55  X = v.x();
56  Y = v.y();
57  Z = v.Z();
58  }
60  double x() const {
61  return X;
62  }
64  double y() const {
65  return Y;
66  }
68  double z() const {
69  return Z;
70  }
71  double X, Y, Z;
72  };
73 
75  class Segmentation {
76  public:
78  virtual ~Segmentation();
79 
81  virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
83  virtual Vector3D position(const CellID& cellID) const = 0;
85  virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
86  const VolumeID& volumeID) const = 0;
88  virtual VolumeID volumeID(const CellID& cellID) const;
90  virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
92  virtual std::string fieldDescription() const {
93  return _decoder->fieldDescription();
94  }
96  virtual const std::string& name() const {
97  return _name;
98  }
100  virtual void setName(const std::string& value) {
101  _name = value;
102  }
104  virtual const std::string& type() const {
105  return _type;
106  }
108  virtual const std::string& description() const {
109  return _description;
110  }
112  virtual const BitFieldCoder* decoder() const {
113  return _decoder;
114  }
116  virtual void setDecoder(const BitFieldCoder* decoder);
118  virtual Parameter parameter(const std::string& parameterName) const;
120  virtual Parameters parameters() const;
122  virtual void setParameters(const Parameters& parameters);
129  virtual std::vector<double> cellDimensions(const CellID& cellID) const;
130 
131  protected:
133  Segmentation(const std::string& cellEncoding = "");
136 
138  template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
139  TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
140  bool isOpt = false) {
141  _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
142  }
144  void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
145  const std::string& defaultVal);
146 
148  static double binToPosition(FieldID bin, double cellSize, double offset = 0.);
150  static int positionToBin(double position, double cellSize, double offset = 0.);
151 
153  static double binToPosition(FieldID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
155  static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
156 
158  std::string _name;
160  std::string _type;
162  std::string _description;
164  std::map<std::string, Parameter> _parameters;
165  std::map<std::string, StringParameter> _indexIdentifiers;
167  const BitFieldCoder* _decoder = 0;
170  bool _ownsDecoder = false;
171  private:
174  };
175 
176  } /* namespace DDSegmentation */
177 } /* namespace dd4hep */
178 #endif // DDSEGMENTATION_SEGMENTATION_H
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::Segmentation::_name
std::string _name
The segmentation name.
Definition: Segmentation.h:158
dd4hep::DDSegmentation::Segmentation::_parameters
std::map< std::string, Parameter > _parameters
The parameters for this segmentation.
Definition: Segmentation.h:164
SegmentationParameter.h
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:168
dd4hep::DDSegmentation::Parameter
SegmentationParameter * Parameter
Definition: SegmentationsInterna.h:33
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
v
View * v
Definition: MultiView.cpp:28
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::DDSegmentation::Segmentation::~Segmentation
virtual ~Segmentation()
Destructor.
Definition: Segmentation.cpp:50
dd4hep::DDSegmentation::StringParameter
TypedSegmentationParameter< std::string > * StringParameter
Definition: Segmentation.h:40
dd4hep::DDSegmentation::IntVecParameter
TypedSegmentationParameter< std::vector< int > > * IntVecParameter
Definition: Segmentation.h:41
dd4hep::DDSegmentation::StringVecParameter
TypedSegmentationParameter< std::vector< std::string > > * StringVecParameter
Definition: Segmentation.h:44
dd4hep::DDSegmentation::DoubleParameter
TypedSegmentationParameter< double > * DoubleParameter
Definition: Segmentation.h:39
dd4hep::DDSegmentation::SegmentationParameter
Class to hold a segmentation parameter with its description.
Definition: SegmentationParameter.h:107
dd4hep::DDSegmentation::FieldID
int64_t FieldID
Definition: BitFieldCoder.h:25
dd4hep::DDSegmentation::Segmentation::_ownsDecoder
bool _ownsDecoder
Keeps track of the decoder ownership.
Definition: Segmentation.h:170
dd4hep::DDSegmentation::Segmentation::name
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:96
dd4hep::DDSegmentation::Vector3D::Vector3D
Vector3D(double x_val=0., double y_val=0., double z_val=0.)
Default constructor.
Definition: Segmentation.h:50
dd4hep::DDSegmentation::FloatParameter
TypedSegmentationParameter< float > * FloatParameter
Definition: Segmentation.h:38
dd4hep::DDSegmentation::SegmentationParameter::NoUnit
@ NoUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::Segmentation::parameters
virtual Parameters parameters() const
Access to all parameters.
Definition: Segmentation.cpp:121
dd4hep::DDSegmentation::Vector3D::Vector3D
Vector3D(const T &v)
Constructor using a foreign vector class. Requires methods x(), y() and z()
Definition: Segmentation.h:54
dd4hep::DDSegmentation::Segmentation::registerParameter
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:138
dd4hep::DDSegmentation::Segmentation::parameter
virtual Parameter parameter(const std::string &parameterName) const
Access to parameter by name.
Definition: Segmentation.cpp:110
dd4hep::DDSegmentation::Parameters
std::vector< Parameter > Parameters
Definition: SegmentationsInterna.h:35
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Segmentation::decoder
virtual const BitFieldCoder * decoder() const
Access the underlying decoder.
Definition: Segmentation.h:112
dd4hep::DDSegmentation::FloatVecParameter
TypedSegmentationParameter< std::vector< float > > * FloatVecParameter
Definition: Segmentation.h:42
BitFieldCoder.h
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::DoubleVecParameter
TypedSegmentationParameter< std::vector< double > > * DoubleVecParameter
Definition: Segmentation.h:43
dd4hep::DDSegmentation::Segmentation::registerIdentifier
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...
Definition: Segmentation.cpp:135
dd4hep::DDSegmentation::Segmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: Segmentation.cpp:100
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::Segmentation::description
virtual const std::string & description() const
Access the description of the segmentation.
Definition: Segmentation.h:108
dd4hep::DDSegmentation::Segmentation::volumeID
virtual VolumeID volumeID(const CellID &cellID) const
Determine the volume ID from the full cell ID by removing all local fields.
Definition: Segmentation.cpp:66
dd4hep::DDSegmentation::Segmentation::positionToBin
static int positionToBin(double position, double cellSize, double offset=0.)
Helper method to convert a 1D position to a cell ID.
Definition: Segmentation.cpp:150
SegmentationsInterna.h
dd4hep::DDSegmentation::Segmentation::Segmentation
Segmentation(const std::string &cellEncoding="")
Default constructor used by derived classes passing the encoding string.
Definition: Segmentation.cpp:39
dd4hep::DDSegmentation::Segmentation::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const =0
Determine the cell ID based on the position.
dd4hep::DDSegmentation::IntParameter
TypedSegmentationParameter< int > * IntParameter
Definition: Segmentation.h:37
dd4hep::DDSegmentation::UnitType
SegmentationParameter::UnitType UnitType
Definition: Segmentation.h:45
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Segmentation::binToPosition
static double binToPosition(FieldID bin, double cellSize, double offset=0.)
Helper method to convert a bin number to a 1D position.
Definition: Segmentation.cpp:145
dd4hep::DDSegmentation::Vector3D::z
double z() const
Access to z value (required for use with ROOT GenVector)
Definition: Segmentation.h:68
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::TypedSegmentationParameter
Concrete class to hold a segmentation parameter of a given type with its description.
Definition: SegmentationParameter.h:166
dd4hep::DDSegmentation::Segmentation::cellDimensions
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,...
Definition: Segmentation.cpp:195
dd4hep::DDSegmentation::BitFieldCoder::fieldDescription
std::string fieldDescription() const
Definition: BitFieldCoder.cpp:123
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::Segmentation::neighbours
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.
Definition: Segmentation.cpp:77
dd4hep::DDSegmentation::Segmentation::fieldDescription
virtual std::string fieldDescription() const
Access the encoding string.
Definition: Segmentation.h:92
dd4hep::DDSegmentation::Segmentation::setName
virtual void setName(const std::string &value)
Set the segmentation name.
Definition: Segmentation.h:100
dd4hep::DDSegmentation::Vector3D::y
double y() const
Access to y value (required for use with ROOT GenVector)
Definition: Segmentation.h:64
dd4hep::DDSegmentation::Segmentation::Segmentation
Segmentation(const Segmentation &)
No copy constructor allowed.
dd4hep::DDSegmentation::Segmentation::_indexIdentifiers
std::map< std::string, StringParameter > _indexIdentifiers
The indices used for the encoding.
Definition: Segmentation.h:166
dd4hep::DDSegmentation::Segmentation::addSubsegmentation
virtual void addSubsegmentation(long key_min, long key_max, Segmentation *entry)
Add subsegmentation. Call only valid for Multi-segmentations. Default implementation throws an except...
Definition: Segmentation.cpp:61
dd4hep::DDSegmentation::Segmentation::setParameters
virtual void setParameters(const Parameters &parameters)
Set all parameters from an existing set of parameters.
Definition: Segmentation.cpp:129
dd4hep::DDSegmentation::SegmentationParameter::UnitType
UnitType
Defines the parameter unit type (useful to convert to default set of units)
Definition: SegmentationParameter.h:110
dd4hep::DDSegmentation::Segmentation
Base class for all segmentations.
Definition: Segmentation.h:75
dd4hep::DDSegmentation::Vector3D::x
double x() const
Access to x value (required for use with ROOT GenVector)
Definition: Segmentation.h:60
dd4hep::DDSegmentation::Segmentation::position
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.
dd4hep::DDSegmentation::Vector3D::Z
double Z
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Segmentation::type
virtual const std::string & type() const
Access the segmentation type.
Definition: Segmentation.h:104