diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index f3649e24c4964e1316d18540bf1bc6b5b30ccce8..f41d41a112968266307cf7fe5b7ab5c73a3e93df 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -143,14 +143,17 @@ namespace DD4hep { void check(bool condition, const std::string& msg) const; /// Templated default constructor - template <typename T> static void* _construct() { return new T(); } + template <typename T> static void* _construct() + { return new T(); } /// Templated copy constructor - template <typename T> static void* _copy(const void* ptr) { return new T(*(T*)ptr); } + template <typename T> static void* _copy(const void* ptr, DetElement elt) + { return new T(*(dynamic_cast<const T*>((T*)ptr)),elt); } /// Templated destructor function - template <typename T> static void _delete(void* ptr) { delete (T*)(ptr); } + template <typename T> static void _delete(void* ptr) + { delete (T*)(ptr); } /// Add an extension object to the detector element - void* i_addExtension(void* ptr, const std::type_info& info, void* (*construct)(), void* (*copy)(const void*), void (*destruct)(void*)); + void* i_addExtension(void* ptr, const std::type_info& info, void* (*copy)(const void*, DetElement), void (*destruct)(void*)); /// Access an existing extension object from the detector element void* i_extension(const std::type_info& info) const; @@ -183,7 +186,7 @@ namespace DD4hep { DetElement clone(const std::string& new_name, int new_id) const; template<typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) - { return (IFACE*)i_addExtension(c,typeid(IFACE),_construct<CONCRETE>,_copy<CONCRETE>,_delete<IFACE>); } + { return (IFACE*)i_addExtension(dynamic_cast<IFACE*>(c),typeid(IFACE),_copy<CONCRETE>,_delete<IFACE>); } template <class T> T* extension() const { return (T*)i_extension(typeid(T)); } diff --git a/DDCore/include/DD4hep/Segmentations.h b/DDCore/include/DD4hep/Segmentations.h index 6bfe53cec11c42325c3283089017776c966f1bf7..6d0171c9c84cbbfbb0ac484cd32d9dd1746e91e1 100644 --- a/DDCore/include/DD4hep/Segmentations.h +++ b/DDCore/include/DD4hep/Segmentations.h @@ -67,7 +67,7 @@ namespace DD4hep { template <typename Q> Segmentation(const Handle<Q>& e) : Handle<Implementation>(e){} /// Constructor to create a new segmentation object (to be called by super class only) - Segmentation(LCDD& lcdd, const std::string& type); + Segmentation(const std::string& type); Object& _data() const { return *data<Object>(); } bool useForHitPosition() const; const std::string type() const; @@ -82,7 +82,7 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> ProjectiveCylinder(const Handle<Q>& e) : Segmentation(e) {} /// Constructor to create a new segmentation object - ProjectiveCylinder(LCDD& lcdd); + ProjectiveCylinder(); /// Accessors: get number of bins in theta int thetaBins() const; /// Accessors: get number of bins in phi @@ -102,7 +102,7 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> NonProjectiveCylinder(const Handle<Q>& e) : Segmentation(e) {} /// Constructor to create a new segmentation object - NonProjectiveCylinder(LCDD& lcdd); + NonProjectiveCylinder(); /// Accessors: get size of bins in Z double gridSizeZ() const; /// Accessors: get size of bins in phi @@ -122,7 +122,7 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> ProjectiveZPlane(const Handle<Q>& e) : Segmentation(e) {} /// Constructor to create a new segmentation object - ProjectiveZPlane(LCDD& lcdd); + ProjectiveZPlane(); /// Accessors: get number of bins in theta int thetaBins() const; /// Accessors: get number of bins in phi @@ -142,9 +142,9 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> GridXY(const Handle<Q>& e) : Segmentation(e) {} /// Constructor to be used when creating a new object. Data are taken from the input handle - GridXY(LCDD& lcdd, const std::string& tag); + GridXY(const std::string& tag); /// Constructor to be used when creating a new object. - GridXY(LCDD& lcdd, const std::string& tag, double size_x, double size_y); + GridXY(const std::string& tag, double size_x, double size_y); /// Accessors: set grid size in X void setGridSizeX(double value); /// Accessors: set grid size in Y @@ -160,9 +160,9 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> GridXYZ(const Handle<Q>& e) : GridXY(e) {} /// Constructor to be used when creating a new object. - GridXYZ(LCDD& lcdd); + GridXYZ(); /// Constructor to be used when creating a new object. - GridXYZ(LCDD& lcdd, double size_x, double size_y, double size_z); + GridXYZ(double size_x, double size_y, double size_z); /// Accessors: set grid size in Z void setGridSizeZ(double value); }; @@ -176,7 +176,7 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> CartesianGridXY(const Handle<Q>& e) : GridXY(e) {} /// Constructor to be used when creating a new object. Data are taken from the input handle - CartesianGridXY(LCDD& lcdd) : GridXY(lcdd,"cartesian_grid_xy") {} + CartesianGridXY() : GridXY("cartesian_grid_xy") {} }; /** @class GlobalGridXY Segmentations.h DD4hep/lcdd/Segmentations.h @@ -188,7 +188,7 @@ namespace DD4hep { /// Constructor to be used when reading the already parsed object template <typename Q> GlobalGridXY(const Handle<Q>& e) : GridXY(e) {} /// Constructor to be used when creating a new object. Data are taken from the input handle - GlobalGridXY(LCDD& lcdd) : GridXY(lcdd,"global_grid_xy") {} + GlobalGridXY() : GridXY("global_grid_xy") {} }; } /* End namespace Geometry */ diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp index 932727381a29fc0899dc32a3d474a06719a13627..e706836da3c782d896c182805adabd852a25b403 100644 --- a/DDCore/src/Detector.cpp +++ b/DDCore/src/Detector.cpp @@ -20,7 +20,7 @@ using namespace DD4hep::Geometry; namespace { struct ExtensionEntry { void* (*construct)(); - void* (*copy)(const void*); + void* (*copy)(const void*,DetElement); void (*destruct)(void*); int id; }; @@ -146,7 +146,7 @@ Value<TNamed,DetElement::Object>* DetElement::Object::clone(int new_id, int flag const std::type_info* info = (*i).first; ExtensionMap::const_iterator j = m.find(info); const ExtensionEntry& e = (*j).second; - obj->extensions[info] = (*(e.copy))((*i).second); + obj->extensions[info] = (*(e.copy))((*i).second,det); } obj->children.clear(); @@ -246,7 +246,7 @@ DetElement::DetElement(DetElement parent, const string& name, int id) { } /// Add an extension object to the detector element -void* DetElement::i_addExtension(void* ptr, const std::type_info& info, void* (*construct)(), void* (*copy)(const void*), void (*destruct)(void*)) { +void* DetElement::i_addExtension(void* ptr, const std::type_info& info, void* (*copy)(const void*,DetElement), void (*destruct)(void*)) { Object& o = _data(); Extensions::iterator j = o.extensions.find(&info); if ( j == o.extensions.end() ) { @@ -254,7 +254,7 @@ void* DetElement::i_addExtension(void* ptr, const std::type_info& info, void* (* ExtensionMap::iterator i = m.find(&info); if ( i == m.end() ) { ExtensionEntry entry; - entry.construct = construct; + entry.construct = 0;//construct; entry.destruct = destruct; entry.copy = copy; entry.id = ++s_extensionID; @@ -262,6 +262,7 @@ void* DetElement::i_addExtension(void* ptr, const std::type_info& info, void* (* i = m.find(&info); } ExtensionEntry& e = (*i).second; + cout << "Extension["<<name()<<"]:" << ptr << " " << typeid(*(TNamed*)ptr).name() << endl; return o.extensions[&info] = ptr; } throw runtime_error("addExtension: The object "+string(name())+ diff --git a/DDCore/src/Segementations.cpp b/DDCore/src/Segementations.cpp index c8efb892898f1d2afcdf1002e9840b91dd827f67..1cf06135f143931aa0f5c3907554d8eee27acd10 100644 --- a/DDCore/src/Segementations.cpp +++ b/DDCore/src/Segementations.cpp @@ -13,7 +13,7 @@ using namespace std; using namespace DD4hep::Geometry; -Segmentation::Segmentation(LCDD& /* lcdd */, const string& type) { +Segmentation::Segmentation(const string& type) { assign(new Value<TNamed,Segmentation::Object>(),"segmentation",type); } @@ -25,8 +25,8 @@ const string Segmentation::type() const { return m_element->GetTitle(); } -ProjectiveCylinder::ProjectiveCylinder(LCDD& lcdd) -: Segmentation(lcdd,"projective_cylinder") {} +ProjectiveCylinder::ProjectiveCylinder() +: Segmentation("projective_cylinder") {} /// Accessors: get number of bins in theta int ProjectiveCylinder::thetaBins() const { @@ -48,8 +48,8 @@ void ProjectiveCylinder::setPhiBins(int value) { _data().data.cylindrical_binning.nphi = value; } -NonProjectiveCylinder::NonProjectiveCylinder(LCDD& lcdd) -: Segmentation(lcdd, "nonprojective_cylinder") +NonProjectiveCylinder::NonProjectiveCylinder() +: Segmentation("nonprojective_cylinder") { } @@ -72,8 +72,8 @@ void NonProjectiveCylinder::setPhiBinSize(double value) { } /// Constructor to be used when creating a new DOM tree. -ProjectiveZPlane::ProjectiveZPlane(LCDD& lcdd) -: Segmentation(lcdd,"projective_zplane") +ProjectiveZPlane::ProjectiveZPlane() +: Segmentation("projective_zplane") { } @@ -98,14 +98,14 @@ void ProjectiveZPlane::setPhiBins(int value) { } /// Constructor to be used when creating a new object. Data are taken from the input handle -GridXY::GridXY(LCDD& lcdd, const std::string& tag) -: Segmentation(lcdd,tag) +GridXY::GridXY(const std::string& tag) +: Segmentation(tag) { } /// Constructor to be used when creating a new object. -GridXY::GridXY(LCDD& lcdd, const std::string& tag, double size_x, double size_y) -: Segmentation(lcdd,tag) +GridXY::GridXY(const std::string& tag, double size_x, double size_y) +: Segmentation(tag) { _data().data.cartesian_grid.grid_size_x = size_x; _data().data.cartesian_grid.grid_size_y = size_y; @@ -122,14 +122,14 @@ void GridXY::setGridSizeY(double value) { } /// Constructor to be used when creating a new DOM tree. -GridXYZ::GridXYZ(LCDD& lcdd) -: GridXY(lcdd, "grid_xyz") +GridXYZ::GridXYZ() +: GridXY("grid_xyz") { } /// Constructor to be used when creating a new object. -GridXYZ::GridXYZ(LCDD& lcdd, double size_x, double size_y, double size_z) -: GridXY(lcdd, "grid_xyz", size_x, size_y) +GridXYZ::GridXYZ(double size_x, double size_y, double size_z) +: GridXY("grid_xyz", size_x, size_y) { _data().data.cartesian_grid.grid_size_z = size_z; } diff --git a/DDCore/src/compact/Compact2Objects.cpp b/DDCore/src/compact/Compact2Objects.cpp index 783fd0568dedfd72996f4163c82f6af980928f67..337e6f76195b3a273739cd27308b6504ade66eb7 100644 --- a/DDCore/src/compact/Compact2Objects.cpp +++ b/DDCore/src/compact/Compact2Objects.cpp @@ -181,43 +181,43 @@ namespace DD4hep { namespace Geometry { return attr; } - template <> Elt_t toObject<GridXYZ>(lcdd_t& lcdd, const xml_h& e) { - GridXYZ obj(lcdd); + template <> Elt_t toObject<GridXYZ>(lcdd_t& /* lcdd */, const xml_h& e) { + GridXYZ obj; if ( e.hasAttr(_A(gridSizeX)) ) obj.setGridSizeX(e.attr<float>(_A(gridSizeX))); if ( e.hasAttr(_A(gridSizeY)) ) obj.setGridSizeY(e.attr<float>(_A(gridSizeY))); if ( e.hasAttr(_A(gridSizeZ)) ) obj.setGridSizeZ(e.attr<float>(_A(gridSizeZ))); return obj; } - template <> Elt_t toObject<GlobalGridXY>(lcdd_t& lcdd, const xml_h& e) { - GlobalGridXY obj(lcdd); + template <> Elt_t toObject<GlobalGridXY>(lcdd_t& /* lcdd */, const xml_h& e) { + GlobalGridXY obj; if ( e.hasAttr(_A(gridSizeX)) ) obj.setGridSizeX(e.attr<float>(_A(gridSizeX))); if ( e.hasAttr(_A(gridSizeY)) ) obj.setGridSizeY(e.attr<float>(_A(gridSizeY))); return obj; } - template <> Elt_t toObject<CartesianGridXY>(lcdd_t& lcdd, const xml_h& e) { - CartesianGridXY obj(lcdd); + template <> Elt_t toObject<CartesianGridXY>(lcdd_t& /* lcdd */, const xml_h& e) { + CartesianGridXY obj; if ( e.hasAttr(_A(gridSizeX)) ) obj.setGridSizeX(e.attr<double>(_A(gridSizeX))); if ( e.hasAttr(_A(gridSizeY)) ) obj.setGridSizeY(e.attr<double>(_A(gridSizeY))); return obj; } - template <> Elt_t toObject<ProjectiveCylinder>(lcdd_t& lcdd, const xml_h& e) { - ProjectiveCylinder obj(lcdd); + template <> Elt_t toObject<ProjectiveCylinder>(lcdd_t& /* lcdd */, const xml_h& e) { + ProjectiveCylinder obj; if ( e.hasAttr(_A(phiBins)) ) obj.setPhiBins(e.attr<int>(_A(phiBins))); if ( e.hasAttr(_A(thetaBins)) ) obj.setThetaBins(e.attr<int>(_A(thetaBins))); return obj; } - template <> Elt_t toObject<NonProjectiveCylinder>(lcdd_t& lcdd, const xml_h& e) { - NonProjectiveCylinder obj(lcdd); + template <> Elt_t toObject<NonProjectiveCylinder>(lcdd_t& /* lcdd */, const xml_h& e) { + NonProjectiveCylinder obj; if ( e.hasAttr(_A(gridSizePhi)) ) obj.setThetaBinSize(e.attr<double>(_A(gridSizePhi))); if ( e.hasAttr(_A(gridSizeZ)) ) obj.setPhiBinSize(e.attr<double>(_A(gridSizeZ))); return obj; } - template <> Elt_t toObject<ProjectiveZPlane>(lcdd_t& lcdd, const xml_h& e) { - ProjectiveZPlane obj(lcdd); + template <> Elt_t toObject<ProjectiveZPlane>(lcdd_t& /* lcdd */, const xml_h& e) { + ProjectiveZPlane obj; if ( e.hasAttr(_A(phiBins)) ) obj.setThetaBins(e.attr<int>(_A(phiBins))); if ( e.hasAttr(_A(thetaBins)) ) obj.setPhiBins(e.attr<int>(_A(thetaBins))); return obj; diff --git a/DDExamples/ILDExDet/include/FixedPadAngleDiskLayout.h b/DDExamples/ILDExDet/include/FixedPadAngleDiskLayout.h index 5ae9436a9a14fa5bdd417634e56978013defe8b5..33156c1058ec7e08d755c2d9f328b4c8a547ffa6 100644 --- a/DDExamples/ILDExDet/include/FixedPadAngleDiskLayout.h +++ b/DDExamples/ILDExDet/include/FixedPadAngleDiskLayout.h @@ -10,6 +10,7 @@ #define FixedPadAngleDiskLayout_H #include "DD4hep/Detector.h" +#include "DD4hep/Segmentations.h" #include "PadLayout.h" #include <Exceptions.h> @@ -18,51 +19,60 @@ namespace DD4hep { struct FixedPadAngleDiskLayout : public PadLayout { - Geometry::DetElement module; - //various constructors - FixedPadAngleDiskLayout() {} - FixedPadAngleDiskLayout(const Geometry::DetElement& e) : module(e) {} - FixedPadAngleDiskLayout(const FixedPadAngleDiskLayout& p) : module(p.module) {} - + Geometry::DetElement module; + Geometry::ProjectiveCylinder pads; + Geometry::Tube tube; + /// Default empty constructor + FixedPadAngleDiskLayout() : module(), pads(), tube() {} + + /// Standard constructor with arguments + FixedPadAngleDiskLayout(const Geometry::DetElement& d); + + /// Standard extension constructor. det is the NEW detector element e.g. when reflecting a detector + FixedPadAngleDiskLayout(const FixedPadAngleDiskLayout& c,const Geometry::DetElement& det); + + /// Default destructor + virtual ~FixedPadAngleDiskLayout() {} + /** The type of pad layout (segmentation) on this module. */ - std::string getPadType() const; + virtual std::string getPadType() const; /** The total number of pads on this module. */ - int getNPads() const; + virtual int getNPads() const; /** The total number of rows on this module. */ - int getNRows() const; + virtual int getNRows() const; /** The number of pads in a given row on this module. */ - int getNPadsInRow(int row)const; + virtual int getNPadsInRow(int row)const; /** The height of a given row on this module. */ - double getRowHeight (int row) const; + virtual double getRowHeight (int row) const; /** The pad pitch (sensitive plus surroundings = effective size) of a given pad on this module. */ - double getPadPitch (int padIndex) const; + virtual double getPadPitch (int padIndex) const; /** The row which contains the given pad on this module. */ - int getRowNumber (int padIndex) const; + virtual int getRowNumber (int padIndex) const; /** The position of a pad within the row on this module. */ - int getPadNumber (int padIndex) const; + virtual int getPadNumber (int padIndex) const; /** The pad id for a pad with padNum in row with rowNum on this module. */ - int getPadIndex (int rowNum, int padNum)const ; + virtual int getPadIndex (int rowNum, int padNum)const ; /** The right neighbour of a pad with the given index on this module. */ - int getRightNeighbour (int padIndex) const; + virtual int getRightNeighbour (int padIndex) const; /** The left neighbour of a pad with the given index on this module. */ - int getLeftNeighbour (int padIndex) const; + virtual int getLeftNeighbour (int padIndex) const; /** The center of a pad on this module in global coordinates. */ - std::vector<double> getPadCenter (int padIndex) const; + virtual std::vector<double> getPadCenter (int padIndex) const; /** Closest pad to a given location. */ - int getNearestPad (double c0, double c1) const; + virtual int getNearestPad (double c0, double c1) const; }; } diff --git a/DDExamples/ILDExDet/include/PadLayout.h b/DDExamples/ILDExDet/include/PadLayout.h new file mode 100644 index 0000000000000000000000000000000000000000..f08ff11f0e62a168183295d702f0dc3756704bab --- /dev/null +++ b/DDExamples/ILDExDet/include/PadLayout.h @@ -0,0 +1,64 @@ +// $Id:$ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : A.Muennich +// +//==================================================================== +#ifndef PadLayout_H +#define PadLayout_H + +#include <string> +#include <vector> + +namespace DD4hep { + + + struct PadLayout { + /// Default destructir + virtual ~PadLayout() {} + + /** The type of pad layout (segmentation) on this module. + */ + virtual std::string getPadType() const=0; + /** The total number of pads on this module. + */ + virtual int getNPads() const=0; + /** The total number of rows on this module. + */ + virtual int getNRows() const=0; + /** The number of pads in a given row on this module. + */ + virtual int getNPadsInRow(int row)const=0; + /** The height of a given row on this module. + */ + virtual double getRowHeight (int row) const=0; + /** The pad pitch (sensitive plus surroundings = effective size) of a given pad on this module. + */ + virtual double getPadPitch (int padIndex) const=0; + /** The row which contains the given pad on this module. + */ + virtual int getRowNumber (int padIndex) const=0; + /** The position of a pad within the row on this module. + */ + virtual int getPadNumber (int padIndex) const=0; + /** The pad id for a pad with padNum in row with rowNum on this module. + */ + virtual int getPadIndex (int rowNum, int padNum)const=0; + /** The right neighbour of a pad with the given index on this module. + */ + virtual int getRightNeighbour (int padIndex) const=0; + /** The left neighbour of a pad with the given index on this module. + */ + virtual int getLeftNeighbour (int padIndex) const=0; + /** The center of a pad on this module in global coordinates. + */ + virtual std::vector<double> getPadCenter (int padIndex) const=0; + /** Closest pad to a given location. + */ + virtual int getNearestPad (double c0, double c1) const=0; + }; + +} +#endif diff --git a/DDExamples/ILDExDet/include/TPCModule.h b/DDExamples/ILDExDet/include/TPCModule.h index 3f62cb8f46bcfc738575159347731a38123ed68f..9ab2b0b90108eb1dc81480338403990b63e7c864 100644 --- a/DDExamples/ILDExDet/include/TPCModule.h +++ b/DDExamples/ILDExDet/include/TPCModule.h @@ -27,7 +27,7 @@ namespace DD4hep { TPCModule() : padLayout(0) {} TPCModule(const Ref_t& e) : Geometry::DetElement(e), padLayout(0) {getExtension();} TPCModule(const Geometry::DetElement& e) : Geometry::DetElement(e), padLayout(0) {getExtension();} - TPCModule(const std::string& name, const std::string& type, int id) : Geometry::DetElement(name,type,id), padLayout(0) {getExtension();} + // TPCModule(const std::string& name, const std::string& type, int id) : Geometry::DetElement(name,type,id), padLayout(0) {getExtension();} template<typename T> TPCModule& operator=(const T& h) { m_element = h.m_element; getExtension(); @@ -44,43 +44,43 @@ namespace DD4hep { //Now all the functionality that depends on specific implementation of padlayout /** The type of pad layout (segmentation) on this module. */ - virtual std::string getPadType() const { padLayout->getPadType(); } + std::string getPadType() const { return padLayout->getPadType(); } /** The total number of pads on this module. */ - virtual int getNPads() const { padLayout->getNPads(); } + int getNPads() const { return padLayout->getNPads(); } /** The total number of rows on this module. */ - virtual int getNRows() const { padLayout->getNRows(); } + int getNRows() const { return padLayout->getNRows(); } /** The number of pads in a given row on this module. */ - virtual int getNPadsInRow(int row)const { padLayout->getNPadsInRow(row); } + int getNPadsInRow(int row)const { return padLayout->getNPadsInRow(row); } /** The height of a given row on this module. */ - virtual double getRowHeight (int row) const { padLayout->getRowHeight (row); } + double getRowHeight (int row) const { return padLayout->getRowHeight (row); } /** The pad pitch (sensitive plus surroundings = effective size) of a given pad on this module. */ - virtual double getPadPitch (int padIndex) const { padLayout->getPadPitch (padIndex); } + double getPadPitch (int padIndex) const { return padLayout->getPadPitch (padIndex); } /** The row which contains the given pad on this module. */ - virtual int getRowNumber (int padIndex) const { padLayout->getRowNumber (padIndex);} + int getRowNumber (int padIndex) const { return padLayout->getRowNumber (padIndex);} /** The position of a pad within the row on this module. */ - virtual int getPadNumber (int padIndex) const { padLayout->getPadNumber (padIndex); } + int getPadNumber (int padIndex) const { return padLayout->getPadNumber (padIndex); } /** The pad id for a pad with padNum in row with rowNum on this module. */ - virtual int getPadIndex (int rowNum, int padNum)const { padLayout->getPadIndex (rowNum, padNum); } + int getPadIndex (int rowNum, int padNum)const { return padLayout->getPadIndex (rowNum, padNum); } /** The right neighbour of a pad with the given index on this module. */ - virtual int getRightNeighbour (int padIndex) const { padLayout->getRightNeighbour (padIndex); } + int getRightNeighbour (int padIndex) const { return padLayout->getRightNeighbour (padIndex); } /** The left neighbour of a pad with the given index on this module. */ - virtual int getLeftNeighbour (int padIndex) const { padLayout->getLeftNeighbour (padIndex) ;} + int getLeftNeighbour (int padIndex) const { return padLayout->getLeftNeighbour (padIndex) ;} /** The center of a pad on this module in global coordinates. */ - virtual std::vector<double> getPadCenter (int padIndex) const { padLayout->getPadCenter (padIndex) ;} + std::vector<double> getPadCenter (int padIndex) const { return padLayout->getPadCenter (padIndex) ;} /** Closest pad to a given location. */ - virtual int getNearestPad (double c0, double c1) const { padLayout->getNearestPad (c0,c1); } + int getNearestPad (double c0, double c1) const { return padLayout->getNearestPad (c0,c1); } }; } diff --git a/DDExamples/ILDExDet/src/FixedPadAngleDiskLayout.cpp b/DDExamples/ILDExDet/src/FixedPadAngleDiskLayout.cpp index 14df42e6e6f42b409c9b7eac3b2638585f31d0a8..e328bd11e48ad56b6dd979f934dda1674e9f82ec 100644 --- a/DDExamples/ILDExDet/src/FixedPadAngleDiskLayout.cpp +++ b/DDExamples/ILDExDet/src/FixedPadAngleDiskLayout.cpp @@ -18,7 +18,7 @@ #include "DD4hep/LCDD.h" #include "FixedPadAngleDiskLayout.h" -#include "TPCModule.h" +//#include "TPCModule.h" #include "TGeoTube.h" #include "TGeoMatrix.h" #include "TGeoManager.h" @@ -31,25 +31,35 @@ namespace DD4hep { using namespace Geometry; + /// Standard constructor with arguments + FixedPadAngleDiskLayout::FixedPadAngleDiskLayout(const Geometry::DetElement& d) : module(d) { + pads = module.readout().segmentation(); + tube = module.volume().solid(); + } + + /// Standard extension constructor. det is the NEW detector element e.g. when reflecting a detector + FixedPadAngleDiskLayout::FixedPadAngleDiskLayout(const FixedPadAngleDiskLayout& /* c */, const Geometry::DetElement& d) : module(d) { + pads = module.readout().segmentation(); + tube = module.volume().solid(); + } std::string FixedPadAngleDiskLayout::getPadType()const { - ProjectiveCylinder pads= module.readout().segmentation(); - string typ = pads.type(); - return typ.empty() ? "" : typ; + //ProjectiveCylinder pads= module.readout().segmentation(); + return pads.type(); } int FixedPadAngleDiskLayout::getNPads()const { - ProjectiveCylinder pads= module.readout().segmentation(); + //ProjectiveCylinder pads= module.readout().segmentation(); return pads.thetaBins()* pads.phiBins(); } int FixedPadAngleDiskLayout::getNRows()const { - ProjectiveCylinder pads= module.readout().segmentation(); + //ProjectiveCylinder pads= module.readout().segmentation(); return pads.thetaBins(); } int FixedPadAngleDiskLayout::getNPadsInRow(int row)const { - ProjectiveCylinder pads= module.readout().segmentation(); + //ProjectiveCylinder pads= module.readout().segmentation(); return pads.phiBins(); } @@ -57,7 +67,7 @@ namespace DD4hep { if(row>getNRows() || row<0) throw OutsideGeometryException("getRowHeight: Requested row not on module querried!"); //all rows are the same for FixedPadAngleDiskLayout=ProjectiveCylinder - Tube tube=module.volume().solid(); + ////Tube tube=module.volume().solid(); double module_height= tube->GetRmax()-tube->GetRmin(); return module_height/getNRows(); } @@ -72,7 +82,7 @@ namespace DD4hep { if(pad>getNPads() || pad<0) throw OutsideGeometryException("getPadPitch: Requested pad not on module querried!"); int row=getRowNumber(pad); - Tube tube=module.volume().solid(); + /////Tube tube=module.volume().solid(); double pad_radius=tube->GetRmin()+(row+0.5)*getRowHeight(0); double module_width= tube->GetPhi2()-tube->GetPhi1(); double pad_angle=module_width/getNPadsInRow(row); @@ -115,30 +125,17 @@ namespace DD4hep { if(pad>getNPads()) throw OutsideGeometryException("getPadCenter: Requested pad not on module querried!"); int row=getRowNumber(pad); - Tube tube=module.volume().solid(); + //////Tube tube=module.volume().solid(); double pad_radius=tube->GetRmin()+(row+0.5)*getRowHeight(0); double module_width= tube->GetPhi2()-tube->GetPhi1(); double pad_angle=(getPadNumber(pad)+0.5)*module_width/getNPadsInRow(row); //local center coordinates in module system - double pad_x=pad_radius*cos(pad_angle*M_PI/180.); - double pad_y=pad_radius*sin(pad_angle*M_PI/180.); + double pad_x = pad_radius*cos(pad_angle*M_PI/180.); + double pad_y = pad_radius*sin(pad_angle*M_PI/180.); //trafo to global coordinates - Double_t point_local[3]; - Double_t point_global[3]; - Double_t point_global_m[3]; - Double_t point_global_t[3]; - point_local[0] = pad_x; - point_local[1] = pad_y; - point_local[2] = TPCModule(module).getModuleZPosition(); - - Position global, global_w, global_r, global_p, local(point_local[0],point_local[1],point_local[2]); + Position global_w, local(pad_x,pad_y,0);//TPCModule(module).getModuleZPosition(); module.localToWorld(local,global_w); - // this->localToParent(local,global); -// std::cout<<"Exp-Local: "<<point_local[0]<<" "<<point_local[1]<<" "<<point_local[2]<<std::endl; -// std::cout<<"Det-Par: " << global.x << " " << global.y << " " << global.z << std::endl; -// std::cout<<"Det-Top: " << global_w.x << " " << global_w.y << " " << global_w.z << std::endl; - vector<double> center; center.push_back(global_w.x); @@ -149,18 +146,18 @@ namespace DD4hep { int FixedPadAngleDiskLayout::getNearestPad(double c0,double c1)const { //find z position of module in world coordinates - Position fake_local(0,0,TPCModule(module).getModuleZPosition()); + Position fake_local(0,0,0); Position fake_global; module.localToWorld(fake_local,fake_global); - //trafo to local coordinates + // trafo to local coordinates Position global(c0,c1,fake_global.z), local; module.worldToLocal(global,local); Double_t point_local[3]={local.x,local.y,local.z}; //check if it is on that module - bool onMod=module.volume().solid()->Contains(point_local); + ////Tube tube=module.volume().solid(); + bool onMod=tube->Contains(point_local); if(!onMod) throw OutsideGeometryException("getNearestPad: Requested point not on module querried!"); - Tube tube=module.volume().solid(); double module_width= tube->GetPhi2()-tube->GetPhi1(); double radius=sqrt(point_local[0]*point_local[0]+point_local[1]*point_local[1]); int row=(radius-tube->GetRmin())/getRowHeight(0); diff --git a/DDExamples/ILDExDet/src/TPCModule.cpp b/DDExamples/ILDExDet/src/TPCModule.cpp index c50e76bfa8f117b0da30ca0055da4b266e1dd41b..6ecacd078213a9a9ed87bca5dd1267ee516632bf 100644 --- a/DDExamples/ILDExDet/src/TPCModule.cpp +++ b/DDExamples/ILDExDet/src/TPCModule.cpp @@ -29,17 +29,15 @@ namespace DD4hep { void TPCModule::getExtension() { padLayout = isValid() ? extension<PadLayout>() : 0; } - + int TPCModule::getID()const { return _data().id; } - - - + double TPCModule::getModuleZPosition() const { //for internal use only, gives back coordinate in local system - TGeoMatrix *nm=placement()->GetMatrix(); - const Double_t *trans=nm->GetTranslation(); + TGeoMatrix *nm = placement()->GetMatrix(); + const Double_t *trans = nm->GetTranslation(); return trans[2]; } } diff --git a/DDExamples/ILDExDet/src/compact/ILDExTPC_geo.cpp b/DDExamples/ILDExDet/src/compact/ILDExTPC_geo.cpp index 85d5ac017e94e841d5da99434dcd93674d9569bd..b796fdd106785bd199813dadb0aa5fa44a9d311a 100644 --- a/DDExamples/ILDExDet/src/compact/ILDExTPC_geo.cpp +++ b/DDExamples/ILDExDet/src/compact/ILDExTPC_geo.cpp @@ -76,16 +76,16 @@ static Ref_t create_element(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens) //templated TPCModule DetElement module(part_det,m_nam,mdcount); - //additional data of module - //PadLayout* layout = new FixedPadAngleDiskLayout(module); - //module.addExtension<PadLayout>(layout); - PadLayout* layout = module.addExtension<PadLayout>(new FixedPadAngleDiskLayout(module)); - module.setReadout(xml_pads); mdcount++; double rotz=md*2*M_PI/nmodules+row.modulePitch()/(rmin+(rmax-rmin))/2; PlacedVolume m_phv = part_vol.placeVolume(mr_vol,Position(0,0,0),Rotation(0,0,rotz)); m_phv.addPhysVolID("module",md); module.setPlacement(m_phv); + + module.setReadout(xml_pads); + // Readout and placement must be present before adding extension, + // since they are aquired internally for optimisation reasons. (MF) + module.addExtension<PadLayout>(new FixedPadAngleDiskLayout(module)); }//modules }//rows }//module groups diff --git a/DDExamples/ILDExReco/ILDExReco.cpp b/DDExamples/ILDExReco/ILDExReco.cpp index 9f609a631c72fc2287807fc306d8b8c5cc51d05b..831dd3bf15b1c3df77e62ff57b9b2a9fcf41aaba 100644 --- a/DDExamples/ILDExReco/ILDExReco.cpp +++ b/DDExamples/ILDExReco/ILDExReco.cpp @@ -61,7 +61,9 @@ int main(int argc,char** argv) { TPCModule mymod=tpc.getModule(10,1); cout << "-----> Module 10 EP 1 ID:\t " << mymod.getID()<<endl; - cout << "-----> Module 10 Pads:\t " << mymod.getPadType()<<endl; + string typ = mymod.getPadType(); + //cout << "-----> Module 10 Pads:\t " << mymod.getPadType()<<endl; + cout << "-----> Module 10 Pads:\t " << typ<<endl; cout << "-----> Module 10 NPads:\t " << mymod.getNPads()<<endl; cout << "-----> Module 10 pad rows:\t " << mymod.getNRows()<<endl; cout << "-----> Module 10 pads in rows:\t " << mymod.getNPadsInRow(0)<<endl;