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
Segmentations.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include "DD4hep/Segmentations.h"
16 #include "DD4hep/InstanceCount.h"
17 #include "DD4hep/Printout.h"
18 #include "DD4hep/Plugins.h"
19 #include "DD4hep/Handle.inl"
21 
22 // C/C++ include files
23 #include <iostream>
24 #include <stdexcept>
25 
26 using namespace std;
27 using namespace DD4hep;
28 using namespace DD4hep::Geometry;
29 
31 
33 Segmentation::Segmentation(const string& typ, const string& nam, BitField64* dec) : Handle<Object>()
34 {
35  string seg_type = "segmentation_constructor__"+typ;
36  SegmentationObject* obj = PluginService::Create<SegmentationObject*>(seg_type, dec);
37  if ( obj != 0 ) {
38  assign(obj, nam, typ);
39  if ( !nam.empty() ) obj->setName(nam);
40  return;
41  }
42  // This is fatal and cannot be recovered. We need to throw an exception here.
43  except("Segmentation","FAILED to create segmentation: %s. [Missing factory]",typ.c_str());
44 }
45 
47 std::string Segmentation::type() const {
48  return data<Object>()->type();
49 }
50 
52  return data<Object>()->useForHitPosition != 0;
53 }
54 
57  return data<Object>()->parameters();
58 }
59 
61 Segmentation::Parameter Segmentation::parameter(const std::string& parameterName) const {
62  return data<Object>()->parameter(parameterName);
63 }
64 
67  return Position(data<Object>()->segmentation->position(cell));
68 }
69 
71 long64 Segmentation::cellID(const Position& localPosition, const Position& globalPosition, const long64& volID) const {
72  return data<Object>()->segmentation->cellID(localPosition, globalPosition, volID);
73 }
74 
77  return data<Object>()->segmentation->volumeID(cell);
78 }
79 
81 void Segmentation::neighbours(const CellID& cell, std::set<CellID>& nb) const {
82  data<Object>()->segmentation->neighbours(cell, nb);
83 }
84 
91 std::vector<double> Segmentation::cellDimensions(const CellID& cell) const {
92  return data<Object>()->segmentation->cellDimensions(cell);
93 }
94 
97  return data<Object>()->segmentation;
98 }
99 
101 BitField64* Segmentation::decoder() const {
102  return data<Object>()->segmentation->decoder();
103 }
104 
106 void Segmentation::setDecoder(BitField64* decode) const {
107  data<Object>()->segmentation->setDecoder(decode);
108 }
109 
112  return data<Object>()->detector;
113 }
114 
117  return data<Object>()->sensitive;
118 }
119 
120 #define IMPLEMENT_SEGMENTATION_HANDLE(X) \
121  DD4HEP_INSTANTIATE_HANDLE_UNNAMED(SegmentationWrapper<DDSegmentation::X>);
122 
124 IMPLEMENT_SEGMENTATION_HANDLE(CartesianGrid)
125 
126 #include "DDSegmentation/CartesianGridXY.h"
128 
129 #include "DDSegmentation/CartesianGridXZ.h"
131 
132 #include "DDSegmentation/CartesianGridYZ.h"
134 
135 #include "DDSegmentation/CartesianGridXYZ.h"
137 
138 #include "DDSegmentation/TiledLayerGridXY.h"
139 IMPLEMENT_SEGMENTATION_HANDLE(TiledLayerGridXY)
140 
141 #include "DDSegmentation/MegatileLayerGridXY.h"
142 IMPLEMENT_SEGMENTATION_HANDLE(MegatileLayerGridXY)
143 
144 #include "DDSegmentation/WaferGridXY.h"
146 
147 #include "DDSegmentation/PolarGridRPhi.h"
149 
150 #include "DDSegmentation/PolarGridRPhi2.h"
152 
153 #include "DDSegmentation/ProjectiveCylinder.h"
154 IMPLEMENT_SEGMENTATION_HANDLE(ProjectiveCylinder)
155 
156 #include "DDSegmentation/MultiSegmentation.h"
long long int CellID
Useful typedefs to differentiate cell IDs and volume IDs.
Definition: Primitives.h:32
virtual VolumeID volumeID(const CellID &cellID) const
Determine the volume ID from the full cell ID by removing all local fields.
Implementation class supporting generic Segmentation of sensitive detectors.
void setDecoder(BitField64 *decoder) const
Set the underlying decoder.
bool useForHitPosition() const
Access flag for hit positioning.
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.
Implementation class for the grid XZ segmentation.
virtual BitField64 * decoder() const
Access the underlying decoder.
Definition: Segmentation.h:105
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.
Position position(const long64 &cellID) const
determine the local position based on the cell ID
void setName(const std::string &value)
Set the segmentation name.
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
Definition: Printout.cpp:217
BitField64 * decoder() const
Access the underlying decoder.
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.
Parameters parameters() const
Access to the parameters.
Handle< DetElementObject > detector() const
Access the main detector element using this segmetnation object.
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...
Implementation class for the grid XYZ segmentation.
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...
void assign(Implementation *n, const std::string &nam, const std::string &title)
Assign a new named object. Note: object references must be managed by the user.
Definition: Handle.inl:27
Implementation class for the grid XZ segmentation.
Definition: PolarGridRPhi.h:57
Parameter parameter(const std::string &parameterName) const
Access to parameter by name.
Implementation class for the grid XZ segmentation.
BaseSegmentation * segmentation() const
Access to the base DDSegmentation object. WARNING: Deprecated call!
ROOT::Math::XYZVector Position
Definition: Objects.h:75
DDSegmentation::Parameters Parameters
Definition: Segmentations.h:48
#define IMPLEMENT_SEGMENTATION_HANDLE(X)
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.
VolumeID volumeID(const CellID &cellID) const
Determine the volume ID from the full cell ID by removing all local fields.
DD4HEP_INSTANTIATE_HANDLE_UNNAMED(SegmentationObject)
Implementation class for the grid XY segmentation.
Implementation class for the grid XZ segmentation.
Definition: WaferGridXY.h:57
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
Handle< SensitiveDetectorObject > sensitive() const
Access the sensitive detector using this segmetnation object.
long long int VolumeID
Definition: Primitives.h:35
virtual void setDecoder(BitField64 *decoder)
Set the underlying decoder.
Class to hold a segmentation parameter with its description.
long64 cellID(const Position &localPosition, const Position &globalPosition, const long64 &volumeID) const
determine the cell ID based on the local position
std::string type() const
Accessor: Segmentation type.
Implementation class for the grid XZ segmentation.
Implementation class for the grid YZ segmentation.
long long int long64
Definition: BitField64.h:15