diff --git a/DDCore/include/DD4hep/MultiSegmentation.h b/DDCore/include/DD4hep/MultiSegmentation.h new file mode 100644 index 0000000000000000000000000000000000000000..e933afdb8e24ac7438b0af206acfd3e5f03f040c --- /dev/null +++ b/DDCore/include/DD4hep/MultiSegmentation.h @@ -0,0 +1,104 @@ +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// \author Markus Frank +// \date 2016-10-18 +// \version 1.0 +// +//========================================================================== +#ifndef DD4HEP_DDCORE_MULTISEGMENTATION_H +#define DD4HEP_DDCORE_MULTISEGMENTATION_H 1 + +// Framework include files +#include "DD4hep/Segmentations.h" +#include "DDSegmentation/MultiSegmentation.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for base segmentations + namespace DDSegmentation { class MultiSegmentation; } + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Geometry { + + // Forward declarations + class Segmentation; + template <typename T> class SegmentationWrapper; + + /// We need some abbreviation to make the code more readable. + typedef Handle<SegmentationWrapper<DDSegmentation::MultiSegmentation> > MultiSegmentationHandle; + + /// Implementation class for the grid XZ segmentation. + /** + * Concrete user handle to serve specific needs of client code + * which requires access to the base functionality not served + * by the super-class Segmentation. + * + * Note: + * We only check the validity of the underlying handle. + * If for whatever reason the implementation object is not valid + * This is not checked. + * In principle this CANNOT happen unless some brain-dead has + * fiddled with the handled object directly..... + * + * Note: + * The handle base corrsponding to this object in for + * conveniance reasons instantiated in DD4hep/src/Segmentations.cpp. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_GEOMETRY + */ + class MultiSegmentation : public MultiSegmentationHandle { + public: + typedef MultiSegmentationHandle::Implementation Object; + typedef DDSegmentation::MultiSegmentation::Segmentations Segmentations; + + public: + /// Default constructor + MultiSegmentation() = default; + /// Copy constructor + MultiSegmentation(const MultiSegmentation& e) = default; + /// Copy Constructor from segmentation base object + MultiSegmentation(const Segmentation& e) : Handle<Object>(e) {} + /// Copy constructor from handle + MultiSegmentation(const Handle<Object>& e) : Handle<Object>(e) {} + /// Copy constructor from other polymorph/equivalent handle + template <typename Q> MultiSegmentation(const Handle<Q>& e) : Handle<Object>(e) {} + /// Assignment operator + MultiSegmentation& operator=(const MultiSegmentation& seg) = default; + /// Equality operator + bool operator==(const MultiSegmentation& seg) const + { return m_element == seg.m_element; } + /// access the field name used to discriminate sub-segmentations + const std::string& discriminatorName() const; + /// Discriminating bitfield entry + BitFieldValue* discriminator() const; + /// The underlying sub-segementations + const Segmentations& subSegmentations() const; + /// determine the position based on the cell ID + Position position(const CellID& cellID) const; + /// determine the cell ID based on the position + CellID cellID(const Position& local, const Position& global, const VolumeID& volID) const; + const std::string& fieldNameY() const; + /** \brief Returns a vector<double> of the cellDimensions of the given cell ID + in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi + + Returns a vector of the cellDimensions of the given cell ID + \param cellID is ignored as all cells have the same dimension + \return std::vector<double> size 2: + -# size in x + -# size in z + */ + std::vector<double> cellDimensions(const CellID& cellID) const; + }; + + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif // DD4HEP_DDCORE_MULTISEGMENTATION_H diff --git a/DDCore/include/DD4hep/objects/SegmentationsInterna.h b/DDCore/include/DD4hep/objects/SegmentationsInterna.h new file mode 100644 index 0000000000000000000000000000000000000000..db063b514b2e443fa9f83971284a203b50213c79 --- /dev/null +++ b/DDCore/include/DD4hep/objects/SegmentationsInterna.h @@ -0,0 +1,127 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_GEOMETRY_SEGMENTATIONSINTERNA_H +#define DD4HEP_GEOMETRY_SEGMENTATIONSINTERNA_H + +// Framework include files +#include "DD4hep/Handle.h" +#include "DD4hep/Objects.h" +#include "DDSegmentation/Segmentation.h" + +// C/C++ include files + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Geometry { + + // Forward declarations + class DetElementObject; + class SegmentationObject; + class SensitiveDetectorObject; + + /// Implementation class supporting generic Segmentation of sensitive detectors + /** + * The SegmentationObject wraps the functionality of the DDSegmentation base class. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_GEOMETRY + */ + class SegmentationObject { + public: + typedef DDSegmentation::Segmentation BaseSegmentation; + typedef DDSegmentation::Parameters Parameters; + typedef DDSegmentation::Parameter Parameter; + + public: + /// Standard constructor + SegmentationObject(BaseSegmentation* s = 0); + /// Default destructor + virtual ~SegmentationObject(); + /// Access the encoding string + std::string fieldDescription() const; + /// Access the segmentation name + const std::string& name() const; + /// Set the segmentation name + void setName(const std::string& value); + /// Access the segmentation type + const std::string& type() const; + /// Access the description of the segmentation + const std::string& description() const; + /// Access the underlying decoder + BitField64* decoder() const; + /// Set the underlying decoder + void setDecoder(BitField64* decoder) const; + /// Access to parameter by name + Parameter parameter(const std::string& parameterName) const; + /// Access to all parameters + Parameters parameters() const; + /// Set all parameters from an existing set of parameters + void setParameters(const Parameters& parameters); + + /** Segmentation interface */ + /// Determine the local position based on the cell ID + Position position(const CellID& cellID) const; + /// Determine the cell ID based on the position + CellID cellID(const Position& localPosition, + const Position& globalPosition, + const VolumeID& volumeID) const; + /// Determine the volume ID from the full cell ID by removing all local fields + VolumeID volumeID(const CellID& cellID) const; + /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours + void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const; + + /// Magic word to check object integrity + unsigned long magic; + /// Flag to use segmentation for hit positioning + unsigned char useForHitPosition; + /// Reference to hosting top level DetElement structure + Handle<DetElementObject> detector; + /// Reference to hosting top level sensitve detector structure + Handle<SensitiveDetectorObject> sensitive; + /// Reference to base segmentation + BaseSegmentation* segmentation; + }; + + /// Concrete wrapper class for segmentation implementation based on DDSegmentation objects + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_GEOMETRY + */ + template <typename IMP> class SegmentationWrapper : public SegmentationObject { + public: + /// DDSegmentation aggregate + IMP* implementation; + public: + /// Standard constructor + SegmentationWrapper(DDSegmentation::BitField64* decoder); + /// Default destructor + virtual ~SegmentationWrapper(); + }; + + /// Standard constructor + template <typename IMP> inline + SegmentationWrapper<IMP>::SegmentationWrapper(DDSegmentation::BitField64* decode) + : SegmentationObject(implementation=new IMP(decode)) + { + } + + /// Default destructor + template <typename IMP> inline SegmentationWrapper<IMP>::~SegmentationWrapper() { + } + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_GEOMETRY_SEGMENTATIONSINTERNA_H */ diff --git a/DDCore/src/MultiSegmentation.cpp b/DDCore/src/MultiSegmentation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a856122b9593ebdb6379e703eec1e911997b5b48 --- /dev/null +++ b/DDCore/src/MultiSegmentation.cpp @@ -0,0 +1,64 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/MultiSegmentation.h" +#include "DD4hep/objects/SegmentationsInterna.h" +#include "DDSegmentation/MultiSegmentation.h" + +// C/C++ include files + +using namespace std; +using namespace DD4hep::Geometry; + +/// access the field name used to discriminate sub-segmentations +const std::string& MultiSegmentation::discriminatorName() const { + return access()->implementation->discriminatorName(); +} + +/// Discriminating bitfield entry +BitFieldValue* MultiSegmentation::discriminator() const { + return access()->implementation->discriminator(); +} + +/// The underlying sub-segementations +const MultiSegmentation::Segmentations& +MultiSegmentation::subSegmentations() const { + return access()->implementation->subSegmentations(); +} + +/// determine the position based on the cell ID +Position MultiSegmentation::position(const CellID& id) const { + return Position(access()->implementation->position(id)); +} + +/// determine the cell ID based on the position +DD4hep::CellID MultiSegmentation::cellID(const Position& local, + const Position& global, + const VolumeID& volID) const +{ + return access()->implementation->cellID(local, global, volID); +} + +/** \brief Returns a vector<double> of the cellDimensions of the given cell ID + in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi + + Returns a vector of the cellDimensions of the given cell ID + \param cellID is ignored as all cells have the same dimension + \return vector<double> size 2: + -# size in x + -# size in y +*/ +vector<double> MultiSegmentation::cellDimensions(const CellID& id) const { + return access()->implementation->cellDimensions(id); +} diff --git a/DDCore/src/SegmentationsInterna.cpp b/DDCore/src/SegmentationsInterna.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78591ba84f66d7145db51073d52d9bdd4436de6e --- /dev/null +++ b/DDCore/src/SegmentationsInterna.cpp @@ -0,0 +1,108 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/objects/SegmentationsInterna.h" +#include "DD4hep/InstanceCount.h" + +// C/C++ include files + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Geometry; +using DD4hep::DDSegmentation::Parameter; +using DD4hep::DDSegmentation::Parameters; +//using DD4hep::DDSegmentation::SegmentationParameter; + +/// Standard constructor +SegmentationObject::SegmentationObject(BaseSegmentation* s) + : magic(magic_word()), useForHitPosition(0), + detector(0), sensitive(0), segmentation(s) +{ + InstanceCount::increment(this); +} + +/// Default destructor +SegmentationObject::~SegmentationObject() { + InstanceCount::decrement(this); + if (segmentation) { + delete segmentation; + } +} + +/// Access the encoding string +string SegmentationObject::fieldDescription() const { + return segmentation->fieldDescription(); +} + +/// Access the segmentation name +const string& SegmentationObject::name() const { + return segmentation->name(); +} +/// Set the segmentation name +void SegmentationObject::setName(const string& value) { + segmentation->setName(value); +} + +/// Access the segmentation type +const string& SegmentationObject::type() const { + return segmentation->type(); +} + +/// Access the description of the segmentation +const string& SegmentationObject::description() const { + return segmentation->description(); +} + +/// Access the underlying decoder +BitField64* SegmentationObject::decoder() const { + return segmentation->decoder(); +} + +/// Set the underlying decoder +void SegmentationObject::setDecoder(BitField64* ptr_decoder) const { + segmentation->setDecoder(ptr_decoder); +} + +/// Access to parameter by name +Parameter SegmentationObject::parameter(const string& parameterName) const { + return segmentation->parameter(parameterName); +} + +/// Access to all parameters +Parameters SegmentationObject::parameters() const { + return segmentation->parameters(); +} + +/// Set all parameters from an existing set of parameters +void SegmentationObject::setParameters(const Parameters& params) { + segmentation->setParameters(params); +} + +/// Determine the local position based on the cell ID +Position SegmentationObject::position(const CellID& cell) const { + return Position(segmentation->position(cell)); +} + +/// Determine the cell ID based on the position +CellID SegmentationObject::cellID(const Position& local, + const Position& global, + const VolumeID& volID) const { + return segmentation->cellID(local, global, volID); +} + +/// Determine the volume ID from the full cell ID by removing all local fields +VolumeID SegmentationObject::volumeID(const CellID& cell) const { + return segmentation->volumeID(cell); +}