DD4hep  1.32.0
Detector Description Toolkit for High Energy Physics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <set>
28 #include <string>
29 #include <vector>
30 
31 namespace dd4hep {
32  namespace DDSegmentation {
33 
34  typedef SegmentationParameter* Parameter;
35  typedef std::vector<Parameter> Parameters;
45 
47  struct Vector3D {
49  Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
50  X(x_val), Y(y_val), Z(z_val) {
51  }
53  template<typename T> Vector3D(const T& v) {
54  X = v.x();
55  Y = v.y();
56  Z = v.Z();
57  }
59  double x() const {
60  return X;
61  }
63  double y() const {
64  return Y;
65  }
67  double z() const {
68  return Z;
69  }
70  double X, Y, Z;
71  };
72 
74  class Segmentation {
75  public:
77  virtual ~Segmentation();
78 
80  virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
82  virtual Vector3D position(const CellID& cellID) const = 0;
84  virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
85  const VolumeID& volumeID) const = 0;
87  virtual VolumeID volumeID(const CellID& cellID) const;
89  virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
91  virtual std::string fieldDescription() const {
92  return _decoder->fieldDescription();
93  }
95  virtual const std::string& name() const {
96  return _name;
97  }
99  virtual void setName(const std::string& value) {
100  _name = value;
101  }
103  virtual const std::string& type() const {
104  return _type;
105  }
107  virtual const std::string& description() const {
108  return _description;
109  }
111  virtual const BitFieldCoder* decoder() const {
112  return _decoder;
113  }
115  virtual void setDecoder(const BitFieldCoder* decoder);
117  virtual Parameter parameter(const std::string& parameterName) const;
119  virtual Parameters parameters() const;
121  virtual void setParameters(const Parameters& parameters);
128  virtual std::vector<double> cellDimensions(const CellID& cellID) const;
133  virtual bool cellsSpanVolumes() const
134  {
135  return false;
136  }
137 
138  protected:
140  Segmentation(const std::string& cellEncoding = "");
143 
145  template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
146  TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
147  bool isOpt = false) {
148  _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
149  }
151  void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
152  const std::string& defaultVal);
153 
155  static double binToPosition(FieldID bin, double cellSize, double offset = 0.);
157  static int positionToBin(double position, double cellSize, double offset = 0.);
158 
160  static double binToPosition(FieldID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
162  static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
163 
165  std::string _name;
167  std::string _type;
169  std::string _description;
171  std::map<std::string, Parameter> _parameters;
172  std::map<std::string, StringParameter> _indexIdentifiers;
174  const BitFieldCoder* _decoder = 0;
177  bool _ownsDecoder = false;
178  private:
181  };
182 
183  } /* namespace DDSegmentation */
184 } /* namespace dd4hep */
185 #endif // DDSEGMENTATION_SEGMENTATION_H
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::Segmentation::_name
std::string _name
The segmentation name.
Definition: Segmentation.h:165
dd4hep::DDSegmentation::Segmentation::_parameters
std::map< std::string, Parameter > _parameters
The parameters for this segmentation.
Definition: Segmentation.h:171
SegmentationParameter.h
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:175
dd4hep::DDSegmentation::Parameter
SegmentationParameter * Parameter
Definition: SegmentationsInterna.h:33
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:47
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:113
dd4hep::DDSegmentation::Segmentation::~Segmentation
virtual ~Segmentation()
Destructor.
Definition: Segmentation.cpp:50
dd4hep::DDSegmentation::StringParameter
TypedSegmentationParameter< std::string > * StringParameter
Definition: Segmentation.h:39
dd4hep::DDSegmentation::IntVecParameter
TypedSegmentationParameter< std::vector< int > > * IntVecParameter
Definition: Segmentation.h:40
dd4hep::DDSegmentation::StringVecParameter
TypedSegmentationParameter< std::vector< std::string > > * StringVecParameter
Definition: Segmentation.h:43
dd4hep::DDSegmentation::DoubleParameter
TypedSegmentationParameter< double > * DoubleParameter
Definition: Segmentation.h:38
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:24
dd4hep::DDSegmentation::Segmentation::cellsSpanVolumes
virtual bool cellsSpanVolumes() const
Definition: Segmentation.h:133
dd4hep::DDSegmentation::Segmentation::_ownsDecoder
bool _ownsDecoder
Keeps track of the decoder ownership.
Definition: Segmentation.h:177
dd4hep::DDSegmentation::Segmentation::name
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:95
dd4hep::DDSegmentation::Vector3D::Vector3D
Vector3D(double x_val=0., double y_val=0., double z_val=0.)
Default constructor.
Definition: Segmentation.h:49
dd4hep::DDSegmentation::FloatParameter
TypedSegmentationParameter< float > * FloatParameter
Definition: Segmentation.h:37
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:53
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:145
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:70
dd4hep::DDSegmentation::Segmentation::decoder
virtual const BitFieldCoder * decoder() const
Access the underlying decoder.
Definition: Segmentation.h:111
dd4hep::DDSegmentation::FloatVecParameter
TypedSegmentationParameter< std::vector< float > > * FloatVecParameter
Definition: Segmentation.h:41
BitFieldCoder.h
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:25
dd4hep::DDSegmentation::DoubleVecParameter
TypedSegmentationParameter< std::vector< double > > * DoubleVecParameter
Definition: Segmentation.h:42
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:169
dd4hep::DDSegmentation::Segmentation::description
virtual const std::string & description() const
Access the description of the segmentation.
Definition: Segmentation.h:107
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:36
dd4hep::DDSegmentation::UnitType
SegmentationParameter::UnitType UnitType
Definition: Segmentation.h:44
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:70
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:67
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:124
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:167
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:91
dd4hep::DDSegmentation::Segmentation::setName
virtual void setName(const std::string &value)
Set the segmentation name.
Definition: Segmentation.h:99
dd4hep::DDSegmentation::Vector3D::y
double y() const
Access to y value (required for use with ROOT GenVector)
Definition: Segmentation.h:63
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:173
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:74
dd4hep::DDSegmentation::Vector3D::x
double x() const
Access to x value (required for use with ROOT GenVector)
Definition: Segmentation.h:59
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:70
dd4hep::DDSegmentation::Segmentation::type
virtual const std::string & type() const
Access the segmentation type.
Definition: Segmentation.h:103