diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.h b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.h index 8c1fe0401a517e53b6e3dc5b4c37198b01080936..ad60f03a11682725b40ff418a0987ca489a87fbd 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.h +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.h @@ -46,22 +46,22 @@ namespace InDetDD { public: /** Constructor: */ - TRT_BarrelElement(const GeoVFullPhysVol *volume, - const TRT_BarrelDescriptor *descriptor, - bool isPositive, - unsigned int modIndex, - unsigned int phiIndex, - unsigned int strawLayIndex, - const TRT_ID * idHelper, - const TRT_Conditions * conditions, - const GeoAlignmentStore* geoAlignStore=nullptr); + TRT_BarrelElement(const GeoVFullPhysVol* volume, + const TRT_BarrelDescriptor* descriptor, + bool isPositive, + unsigned int modIndex, + unsigned int phiIndex, + unsigned int strawLayIndex, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, + const GeoAlignmentStore* geoAlignStore = nullptr); + + TRT_BarrelElement(const TRT_BarrelElement& right, + const GeoAlignmentStore* geoAlignStore); - - TRT_BarrelElement(const TRT_BarrelElement &right, const GeoAlignmentStore* geoAlignStore); - /** Destructor: */ - virtual ~TRT_BarrelElement(); - + virtual ~TRT_BarrelElement() = default; + /** Type information */ virtual TRT_BaseElement::Type type() const {return TRT_BaseElement::BARREL;} @@ -88,9 +88,6 @@ namespace InDetDD { /** Default Local -> global transform of the straw (ie before alignment corrections) */ virtual HepGeom::Transform3D defStrawTransform(int straw) const; - - /** Get the number of straws: */ - virtual unsigned int nStraws() const; /** Get the length of the straws (active length): */ virtual const double & strawLength() const; diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.icc b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.icc index 95f743e8d0c152500b89e95a490c681ed6381da4..181f1c73aee7baec404ddedee5627178f4e612cf 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.icc +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BarrelElement.icc @@ -33,27 +33,22 @@ inline const TRT_BarrelCode & TRT_BarrelElement::getCode() const // Get X Position - should not be used anymore -inline double TRT_BarrelElement::strawXPos (unsigned int straw) const { +inline double TRT_BarrelElement::strawXPos (unsigned int straw) const { return strawCenter(straw).x(); } - + // Get Y Position - should not be used anymore inline double TRT_BarrelElement::strawYPos (unsigned int straw) const { return strawCenter(straw).y(); } - + // Get Z Position - should not be used anymore inline double TRT_BarrelElement::strawZPos (unsigned int straw) const { return strawCenter(straw).z(); } -// Get the number of straws: -inline unsigned int TRT_BarrelElement::nStraws() const { - return m_descriptor->nStraws(); -} - // Get the length of the straws: inline const double & TRT_BarrelElement::strawLength() const { - return m_descriptor->strawLength(); + return m_descriptor->strawLength(); } } diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.h b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.h index 27f9092858f5f93c19c1054180173723c6525710..328f2cb92dcaa00baa54549e284c6bff40d4f55f 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.h +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.h @@ -63,12 +63,17 @@ namespace InDetDD { enum Type {BARREL, ENDCAP}; /** Constructor: */ - TRT_BaseElement(const GeoVFullPhysVol *volume, const Identifier& id, const TRT_ID* idHelper, const TRT_Conditions* conditions, const GeoAlignmentStore* geoAlignStore=nullptr); + TRT_BaseElement(const GeoVFullPhysVol* volume, + const Identifier& id, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, + const GeoAlignmentStore* geoAlignStore = nullptr); + + TRT_BaseElement(const TRT_BaseElement& right, + const GeoAlignmentStore* geoAlignStore); - TRT_BaseElement(const TRT_BaseElement&right, const GeoAlignmentStore* geoAlignStore); - /** Destructor: */ - virtual ~TRT_BaseElement(); + virtual ~TRT_BaseElement() = default; /** Type information: returns BARREL or ENDCAP */ virtual TRT_BaseElement::Type type() const = 0; @@ -156,7 +161,7 @@ namespace InDetDD { Amg::Vector3D strawAxis(int straw) const; /** Number of straws in the element. */ - virtual unsigned int nStraws() const = 0; + unsigned int nStraws() const; /** Active straw length */ virtual const double& strawLength() const = 0; @@ -221,27 +226,25 @@ namespace InDetDD { /** Illegal operations: */ TRT_BaseElement(const TRT_BaseElement&right); const TRT_BaseElement& operator=(const TRT_BaseElement&right); - /** Helper method for cache dealing */ void deleteCache(); - void createStrawSurfaces() const; void createStrawSurfacesCache() const; protected: - Identifier m_id; IdentifierHash m_idHash; - const TRT_ID* m_idHelper; - const TRT_Conditions* m_conditions; - + const TRT_ID* m_idHelper=nullptr; + const TRT_Conditions* m_conditions=nullptr; + /* + * The number of straws and the vector below need to + * initialosed in the derived constructors for now. + * This should fine as this is pure virtual class + */ + unsigned int m_nstraws=0; // Amg cache for the straw surfaces - CxxUtils::CachedUniquePtrT< - std::vector<std::unique_ptr<Trk::StraightLineSurface>>> - m_strawSurfaces{}; - - CxxUtils::CachedUniquePtrT<std::vector<std::unique_ptr<SurfaceCache>>> - m_strawSurfacesCache{}; + std::vector<CxxUtils::CachedUniquePtr<Trk::StraightLineSurface>> m_strawSurfaces{}; + std::vector<CxxUtils::CachedUniquePtr<SurfaceCache>> m_strawSurfacesCache{}; //!< helper element surface for the cache CxxUtils::CachedUniquePtr<SurfaceCache> m_surfaceCache; @@ -249,13 +252,12 @@ namespace InDetDD { mutable std::vector<const Trk::Surface*> m_surfaces ATLAS_THREAD_SAFE; // Guarded by m_mutex mutable std::mutex m_mutex; - - const GeoAlignmentStore* m_geoAlignStore{}; + const GeoAlignmentStore* m_geoAlignStore=nullptr; }; } - +#include "TRT_ReadoutGeometry/TRT_BaseElement.icc" #endif diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.icc b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.icc index 828631ffe639d43c00fb32dde2a0a5adf0a6d0bc..e48aed5da52160c20e0411e45a5f079cc584ac05 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.icc +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_BaseElement.icc @@ -3,10 +3,12 @@ */ namespace InDetDD { - -inline const HepGeom::Transform3D & TRT_BaseElement::defTransform() const + +// Get the number of straws: +inline unsigned int +TRT_BaseElement::nStraws() const { - return getMaterialGeom()->getDefAbsoluteTransform(); + return m_nstraws; } } diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_EndcapElement.h b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_EndcapElement.h index 19e612b061c152dc0ab1c11ea0aa8415b2325bb8..644e5b47e171f11329cd023780e2c4779b4a711a 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_EndcapElement.h +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/TRT_ReadoutGeometry/TRT_EndcapElement.h @@ -45,15 +45,15 @@ namespace InDetDD { public: /** Constructor */ - TRT_EndcapElement(const GeoVFullPhysVol *volume, - const TRT_EndcapDescriptor *descriptor, - bool isPositive, - unsigned int wheelIndex, - unsigned int strawLayIndex, - unsigned int phiIndex, - const TRT_ID * idHelper, - const TRT_Conditions * conditions, - const GeoAlignmentStore* geoAlignStore=nullptr); + TRT_EndcapElement(const GeoVFullPhysVol* volume, + const TRT_EndcapDescriptor* descriptor, + bool isPositive, + unsigned int wheelIndex, + unsigned int strawLayIndex, + unsigned int phiIndex, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, + const GeoAlignmentStore* geoAlignStore = nullptr); TRT_EndcapElement(const TRT_EndcapElement &right, const GeoAlignmentStore* geoAlignStore); @@ -66,9 +66,6 @@ namespace InDetDD { /** Default Local -> global transform of the straw (ie before alignment corrections) */ virtual HepGeom::Transform3D defStrawTransform(int straw) const; - /** Number of straws in the element */ - virtual unsigned int nStraws() const; - /** Active straw length */ virtual const double & strawLength() const; diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BarrelElement.cxx b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BarrelElement.cxx index 0b930f6c744f8604faf5073fce6bf92b4c7fda69..6cd61074c81321ee05ef3042f39072fc7e6ed2ba 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BarrelElement.cxx +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BarrelElement.cxx @@ -22,49 +22,54 @@ namespace InDetDD { -TRT_BarrelElement::TRT_BarrelElement(const GeoVFullPhysVol *volume, - const TRT_BarrelDescriptor *descriptor, - bool isPositive, - unsigned int modIndex, - unsigned int phiIndex, - unsigned int strawLayIndex, - const TRT_ID * idHelper, - const TRT_Conditions * conditions, +TRT_BarrelElement::TRT_BarrelElement(const GeoVFullPhysVol* volume, + const TRT_BarrelDescriptor* descriptor, + bool isPositive, + unsigned int modIndex, + unsigned int phiIndex, + unsigned int strawLayIndex, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, const GeoAlignmentStore* geoAlignStore) - : - TRT_BaseElement(volume, - idHelper->layer_id((isPositive ? 1:-1), phiIndex, modIndex, strawLayIndex), - idHelper, conditions, geoAlignStore), - m_code(isPositive,modIndex,phiIndex,strawLayIndex), - m_descriptor(descriptor), - m_nextInPhi(NULL), - m_previousInPhi(NULL), - m_nextInR(NULL), - m_previousInR(NULL) + : TRT_BaseElement(volume, + idHelper->layer_id((isPositive ? 1 : -1), + phiIndex, + modIndex, + strawLayIndex), + idHelper, + conditions, + geoAlignStore) + , m_code(isPositive, modIndex, phiIndex, strawLayIndex) + , m_descriptor(descriptor) + , m_nextInPhi(nullptr) + , m_previousInPhi(nullptr) + , m_nextInR(nullptr) + , m_previousInR(nullptr) { + m_nstraws = m_descriptor->nStraws(); + m_strawSurfaces.resize(m_nstraws); + m_strawSurfacesCache.resize(m_nstraws); } - - TRT_BarrelElement::TRT_BarrelElement(const TRT_BarrelElement &right, const GeoAlignmentStore* geoAlignStore) : - TRT_BaseElement(right,geoAlignStore), - m_code (right.m_code), - m_descriptor (right.m_descriptor), - m_nextInPhi (right.m_nextInPhi), - m_previousInPhi (right.m_previousInPhi), - m_nextInR (right.m_nextInR), - m_previousInR (right.m_previousInR) - { - } - - -TRT_BarrelElement::~TRT_BarrelElement() +TRT_BarrelElement::TRT_BarrelElement(const TRT_BarrelElement& right, + const GeoAlignmentStore* geoAlignStore) + : TRT_BaseElement(right, geoAlignStore) + , m_code(right.m_code) + , m_descriptor(right.m_descriptor) + , m_nextInPhi(right.m_nextInPhi) + , m_previousInPhi(right.m_previousInPhi) + , m_nextInR(right.m_nextInR) + , m_previousInR(right.m_previousInR) { + m_nstraws = right.m_nstraws; + m_strawSurfaces.resize(m_nstraws); + m_strawSurfacesCache.resize(m_nstraws); } const TRT_BarrelConditions * TRT_BarrelElement::getConditionsData() const { - return NULL; + return nullptr; } const TRT_BarrelDescriptor * TRT_BarrelElement::getDescriptor() const @@ -94,10 +99,10 @@ void TRT_BarrelElement::setPreviousInR(const TRT_BarrelElement *element) -HepGeom::Transform3D TRT_BarrelElement::calculateStrawTransform(int straw) const +HepGeom::Transform3D TRT_BarrelElement::calculateStrawTransform(int straw) const { // NB The tranformation to a straw is reconstructed here precisely as - // it was ... hopefully... in the factory. One could eliminate this + // it was ... hopefully... in the factory. One could eliminate this // requirement and make the code a little more robust in this regard but // at the cost of doubling the descriptors. (One descriptor now suffices // for both positive and negative endcaps). @@ -111,7 +116,7 @@ HepGeom::Transform3D TRT_BarrelElement::calculateStrawTransform(int straw) const return Amg::EigenTransformToCLHEP(getMaterialGeom()->getAbsoluteTransform()*((*f)(straw+offsetInto))) * HepGeom::RotateY3D(zAng)*HepGeom::TranslateZ3D(zPos) * calculateLocalStrawTransform(straw); - ////return conditions()->solenoidFrame() + ////return conditions()->solenoidFrame() //// * getMaterialGeom()->getAbsoluteTransform()*((*f)(straw+offsetInto)) //// * HepGeom::RotateY3D(zAng)*HepGeom::TranslateZ3D(zPos) //// * calculateLocalStrawTransform(straw); @@ -149,13 +154,13 @@ HepGeom::Transform3D TRT_BarrelElement::calculateLocalStrawTransform(int straw) } -HepGeom::Transform3D TRT_BarrelElement::defStrawTransform(int straw) const +HepGeom::Transform3D TRT_BarrelElement::defStrawTransform(int straw) const { // Same as calculateStrawTransform, except we use getDefAbsoluteTransform() // rather than getAbsoluteTransform() // NB The tranformation to a straw is reconstructed here precisely as - // it was ... hopefully... in the factory. One could eliminate this + // it was ... hopefully... in the factory. One could eliminate this // requirement and make the code a little more robust in this regard but // at the cost of doubling the descriptors. (One descriptor now suffices // for both positive and negative endcaps). @@ -165,27 +170,27 @@ HepGeom::Transform3D TRT_BarrelElement::defStrawTransform(int straw) const size_t offsetInto = m_descriptor->getStrawTransformOffset(); double zPos = -m_descriptor->strawZPos(); double zAng = m_code.isPosZ() ? M_PI : 0; - return Amg::EigenTransformToCLHEP(getMaterialGeom()->getDefAbsoluteTransform()*((*f)(straw+offsetInto))) + return Amg::EigenTransformToCLHEP(getMaterialGeom()->getDefAbsoluteTransform()*((*f)(straw+offsetInto))) * HepGeom::RotateY3D(zAng)*HepGeom::TranslateZ3D(zPos); } else { std::cout << "calculateStrawTransform: f is 0 !!!!" << std::endl; return HepGeom::Transform3D(); } - + } - -const Trk::SurfaceBounds& TRT_BarrelElement::strawBounds() const + +const Trk::SurfaceBounds& TRT_BarrelElement::strawBounds() const { return m_descriptor->strawBounds(); } -const Trk::Surface& TRT_BarrelElement::elementSurface() const +const Trk::Surface& TRT_BarrelElement::elementSurface() const { if (not m_surface) m_surface.set(std::make_unique<Trk::PlaneSurface>(*this)); return *m_surface; } - + void TRT_BarrelElement::createSurfaceCache() const { // Calculate the surface from the two end straws. @@ -197,13 +202,13 @@ void TRT_BarrelElement::createSurfaceCache() const // Calculate center as the average position of the end straws. Amg::Vector3D* center = new Amg::Vector3D(0.5*(centerFirstStraw+centerLastStraw)); - + Amg::Vector3D phiAxis = centerLastStraw - centerFirstStraw; double width = phiAxis.mag(); phiAxis = phiAxis.normalized(); double elementWidth = width + 2 * m_descriptor->innerTubeRadius(); // Add the straw tube radius - - // Get local z-axis. This is roughly in +ve global z direction (exactly if no misalignment) + + // Get local z-axis. This is roughly in +ve global z direction (exactly if no misalignment) // We could probably use any straw for this but we average the first and last straw and renormalize // to a unit vector. Amg::Vector3D etaAxis = 0.5*(strawAxis(firstStraw) + strawAxis(lastStraw)); @@ -214,7 +219,7 @@ void TRT_BarrelElement::createSurfaceCache() const // of increasing phi and the straw axis is in +ve z direction. Amg::Vector3D* normal = new Amg::Vector3D(phiAxis.cross( etaAxis )); // phi cross z - // Transform from local to global. + // Transform from local to global. // local x axis -> phiAxis // local y axis -> etaAxis // local z axis -> cross product of local x and local y @@ -222,21 +227,23 @@ void TRT_BarrelElement::createSurfaceCache() const // This constructor takes three points in the two coordinate systems. Amg::Transform3D* transform = new Amg::Transform3D(); - + Amg::RotationMatrix3D rotation; rotation.col(0) = phiAxis; rotation.col(1) = etaAxis; rotation.col(2) = (*normal); (*transform) = Amg::Translation3D(*center) * rotation; - + // create the element bounds Trk::RectangleBounds * elementBounds = new Trk::RectangleBounds(0.5*elementWidth, 0.5*strawLength()); // create the surface cache m_surfaceCache.set(std::make_unique<SurfaceCache>(transform, center, normal, elementBounds)); // creaete the surface (only if needed, links are still ok even if cache update) - if (not m_surface) elementSurface(); + if (not m_surface) { + elementSurface(); + } } @@ -244,9 +251,9 @@ int TRT_BarrelElement::strawDirection() const { // Return +1 if the straw local axis is in the same direction as the z axis, -1 otherwise. // The straw axis by convention goes in the direction away from the readout. - // So for -ve endcap this is the positive z direction (we return +1) and in the + // So for -ve endcap this is the positive z direction (we return +1) and in the // +ve endcap its in the -ve z direction (we return -1). - // + // return !(m_code.isPosZ()) ? +1 : -1; } diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BaseElement.cxx b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BaseElement.cxx index 1ec682cc6d645d6b448cd1321ffc7edfa12357d7..b1d19eb1a7f63a9db2a18ec3f878fd0ed7b5cd61 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BaseElement.cxx +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_BaseElement.cxx @@ -5,351 +5,334 @@ #include "TRT_ReadoutGeometry/TRT_BaseElement.h" #include "TRT_ReadoutGeometry/TRT_Conditions.h" -#include "CLHEP/Geometry/Transform3D.h" #include "CLHEP/Geometry/Point3D.h" +#include "CLHEP/Geometry/Transform3D.h" #include "CLHEP/Geometry/Vector3D.h" #include "GeoModelUtilities/GeoAlignmentStore.h" #include "GeoPrimitives/CLHEPtoEigenConverter.h" -#include "InDetIdentifier/TRT_ID.h" #include "GeoModelUtilities/GeoAlignmentStore.h" - +#include "InDetIdentifier/TRT_ID.h" #include <vector> namespace InDetDD { +TRT_BaseElement::TRT_BaseElement(const GeoVFullPhysVol* volume, + const Identifier& id, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, + const GeoAlignmentStore* geoAlignStore) + : Trk::TrkDetElementBase(volume) + , m_id(id) + , m_idHelper(idHelper) + , m_conditions(conditions) + , m_surfaceCache{} + , m_surface{} + , m_surfaces{} + , m_mutex{} + , m_geoAlignStore(geoAlignStore) +{ + m_idHash = m_idHelper->straw_layer_hash(id); +} + +TRT_BaseElement::TRT_BaseElement(const TRT_BaseElement& right, + const GeoAlignmentStore* geoAlignmentStore) + : Trk::TrkDetElementBase(right.getMaterialGeom()) + , m_id(right.m_id) + , m_idHash(right.m_idHash) + , m_idHelper(right.m_idHelper) + , m_conditions(right.m_conditions) + , m_geoAlignStore(geoAlignmentStore) +{} + +Identifier +TRT_BaseElement::identify() const +{ + return m_id; +} + +IdentifierHash +TRT_BaseElement::identifyHash() const +{ + return m_idHash; +} + +// [0] GeoModel / CLHEP Access +const HepGeom::Transform3D +TRT_BaseElement::getAbsoluteTransform(int straw) const +{ + return Amg::EigenTransformToCLHEP(strawTransform(straw)); +} + +// [A] description of the current detector element : Amg first, then CLHEP +// converted methods +const Trk::Surface& +TRT_BaseElement::surface() const +{ + return elementSurface(); +} + +const Trk::SurfaceBounds& +TRT_BaseElement::bounds() const +{ + if (not m_surfaceCache) { + createSurfaceCache(); + } + return *(m_surfaceCache->bounds()); +} + +const Amg::Transform3D& +TRT_BaseElement::transform() const +{ + if (not m_surfaceCache) { + createSurfaceCache(); + } + return *(m_surfaceCache->transform()); +} + +const Amg::Vector3D& +TRT_BaseElement::center() const +{ + if (not m_surfaceCache) { + createSurfaceCache(); + } + return *(m_surfaceCache->center()); +} + +const Amg::Vector3D& +TRT_BaseElement::normal() const +{ + if (not m_surfaceCache) { + createSurfaceCache(); + } + return *(m_surfaceCache->normal()); +} + +// [B] Description of the individual straws +const Trk::Surface& +TRT_BaseElement::surface(const Identifier& id) const +{ + int straw = m_idHelper->straw(id); + if (!m_strawSurfaces[straw]) { + createSurfaceCache(id); + } + return *(m_strawSurfaces[straw].get()); +} + +const std::vector<const Trk::Surface*>& +TRT_BaseElement::surfaces() const +{ + std::lock_guard<std::mutex> lock{ m_mutex }; + if (!m_surfaces.size()) { + m_surfaces.reserve(nStraws()); + for (unsigned is = 0; is < nStraws(); ++is) + m_surfaces.push_back(&strawSurface(is)); + } + return m_surfaces; +} + +const Trk::SurfaceBounds& +TRT_BaseElement::bounds(const Identifier&) const +{ + return strawBounds(); +} + +const Amg::Transform3D& +TRT_BaseElement::transform(const Identifier& id) const +{ + int straw = m_idHelper->straw(id); + if (!m_strawSurfacesCache[straw]) { + createSurfaceCache(id); + } + // forward the transform of the cache + return *(m_strawSurfacesCache[straw]->transform()); +} + +const Amg::Transform3D& +TRT_BaseElement::strawTransform(unsigned int straw) const +{ + if (!m_strawSurfacesCache[straw]) { + Identifier id = m_idHelper->straw_id(identify(), straw); + createSurfaceCache(id); + } + // forward the transform of the cache + return *(m_strawSurfacesCache[straw]->transform()); +} + +const Amg::Vector3D& +TRT_BaseElement::normal(const Identifier&) const +{ + // Not sure if the normal of the straw is ever used. + // nor is there a well defined normal. + // This wont be corrected for alignments. + // Just return the element normal + return normal(); +} + +const Amg::Vector3D& +TRT_BaseElement::center(const Identifier& id) const +{ + int straw = m_idHelper->straw(id); + if (!m_strawSurfacesCache[straw]) { + createSurfaceCache(id); + } + // forward the transform of the cache + return *(m_strawSurfacesCache[straw]->center()); +} + +const Trk::StraightLineSurface& +TRT_BaseElement::strawSurface(int straw) const +{ + if (!m_strawSurfaces[straw]) { + // get the straw identifier to the given straw number and element identifier + Identifier id = m_idHelper->straw_id(identify(), straw); + createSurfaceCache(id); + } + return *(m_strawSurfaces[straw].get()); +} + +const Amg::Transform3D& +TRT_BaseElement::strawTransform(int straw) const +{ + if (!m_strawSurfacesCache[straw]) { + Identifier id = m_idHelper->straw_id(identify(), straw); + createSurfaceCache(id); + } + // forward the transform of the cache + return *(m_strawSurfacesCache[straw]->transform()); +} + +const Amg::Vector3D& +TRT_BaseElement::strawCenter(int straw) const +{ + if (!m_strawSurfacesCache[straw]) { + Identifier id = m_idHelper->straw_id(identify(), straw); + createSurfaceCache(id); + } + // forward the transform of the cache + return *(m_strawSurfacesCache[straw]->center()); +} + +Amg::Vector3D +TRT_BaseElement::strawAxis(int straw) const +{ + return (strawTransform(straw).linear() * Amg::Vector3D::UnitZ() * + strawDirection()); +} + +/// ----- can be removed after full Amg migration ----------------------- +/// (start) +// [A] in CLHEP +const HepGeom::Transform3D +TRT_BaseElement::transformCLHEP() const +{ + return Amg::EigenTransformToCLHEP(*(m_surfaceCache->transform())); +} + +const HepGeom::Point3D<double> +TRT_BaseElement::centerCLHEP() const +{ + + const Amg::Vector3D& cCenter = center(); + return HepGeom::Point3D<double>(cCenter.x(), cCenter.y(), cCenter.z()); +} + +const HepGeom::Vector3D<double> +TRT_BaseElement::normalCLHEP() const +{ + const Amg::Vector3D& cNormal = normal(); + return HepGeom::Vector3D<double>(cNormal.x(), cNormal.y(), cNormal.z()); +} + +// [B] in CLHEP +const HepGeom::Transform3D +TRT_BaseElement::transformCLHEP(const Identifier& id) const +{ + return Amg::EigenTransformToCLHEP(transform(id)); +} + +const HepGeom::Point3D<double> +TRT_BaseElement::centerCLHEP(const Identifier& id) const +{ + const Amg::Vector3D cCenter = center(id); + return HepGeom::Point3D<double>(cCenter.x(), cCenter.y(), cCenter.z()); +} + +const HepGeom::Vector3D<double> +TRT_BaseElement::normalCLHEP(const Identifier&) const +{ + // Not sure if the normal of the straw is ever used. + // nor is there a well defined normal. + // This wont be corrected for alignments. + // Just return the element normal + return normalCLHEP(); +} +//(end) +// ----- can be removed after full Amg migration ----------------------- + +void +TRT_BaseElement::createSurfaceCache(Identifier id) const +{ + int straw = m_idHelper->straw(id); + // get the StrawTransform from GeoModel + HepGeom::Transform3D cStrawTransform = calculateStrawTransform(straw); + + // convert neccessary parts to Amg + if (!m_strawSurfacesCache[straw]) { + Amg::Transform3D* sTransform = + new Amg::Transform3D(Amg::CLHEPTransformToEigen(cStrawTransform)); + Amg::Vector3D* sCenter = new Amg::Vector3D(sTransform->translation()); + // create the surface cache & fill it + m_strawSurfacesCache[straw].set( + std::make_unique<SurfaceCache>(sTransform, sCenter, nullptr, nullptr)); + } + // creaete the surface only if needed (the links are still intact) + if (!m_strawSurfaces[straw]) { + m_strawSurfaces[straw].set( + std::make_unique<Trk::StraightLineSurface>(*this, id)); + } +} + +void +TRT_BaseElement::invalidate() +{ + // Invalidate the caches + // Call and barrel or endcap specific invalidation + invalidateOther(); + // Its enough to delete and zero the caches. + deleteCache(); +} + +void +TRT_BaseElement::deleteCache() +{ + // for all straws + for (size_t i = 0; i < m_strawSurfacesCache.size(); i++) { + m_strawSurfacesCache[i].store(nullptr); + } +} + +void +TRT_BaseElement::updateAllCaches() +{ + // delete the caches first + deleteCache(); + // Strawlayer caches + if (not m_surfaceCache){ + createSurfaceCache(); + } + // Loop over all straws and request items that get cached. + for (unsigned int iStraw = 0; iStraw < nStraws(); iStraw++) { + Identifier strawId = m_idHelper->straw_id(identify(), iStraw); + createSurfaceCache(strawId); + } +} + +const TRT_Conditions* +TRT_BaseElement::conditions() const +{ + return m_conditions; +} - TRT_BaseElement::TRT_BaseElement(const GeoVFullPhysVol *volume, const Identifier & id, const TRT_ID * idHelper, const TRT_Conditions * conditions, const GeoAlignmentStore* geoAlignStore) : - Trk::TrkDetElementBase(volume), - m_id(id), - m_idHelper(idHelper), - m_conditions(conditions), - m_strawSurfaces(nullptr), - m_strawSurfacesCache(nullptr), - m_surfaceCache{}, - m_surface{}, - m_surfaces{}, - m_mutex{}, - m_geoAlignStore(geoAlignStore) - { - m_idHash = m_idHelper->straw_layer_hash(id); - } - - TRT_BaseElement::TRT_BaseElement(const TRT_BaseElement&right, const GeoAlignmentStore* geoAlignmentStore): - Trk::TrkDetElementBase(right.getMaterialGeom()), - m_id (right.m_id), - m_idHash (right.m_idHash), - m_idHelper (right.m_idHelper), - m_conditions (right.m_conditions), - m_geoAlignStore(geoAlignmentStore) - { - } - - Identifier TRT_BaseElement::identify() const - { - return m_id; - } - - IdentifierHash TRT_BaseElement::identifyHash() const - { - return m_idHash; - } - - // [0] GeoModel / CLHEP Access - const HepGeom::Transform3D TRT_BaseElement::getAbsoluteTransform(int straw) const - { - return Amg::EigenTransformToCLHEP(strawTransform(straw)); - } - - // [A] description of the current detector element : Amg first, then CLHEP converted methods - const Trk::Surface& TRT_BaseElement::surface() const - { - return elementSurface(); - } - - const Trk::SurfaceBounds& TRT_BaseElement::bounds() const - { - if (not m_surfaceCache) createSurfaceCache(); - return *(m_surfaceCache->bounds()); - } - - const Amg::Transform3D& TRT_BaseElement::transform() const - { - if (not m_surfaceCache) createSurfaceCache(); - return *(m_surfaceCache->transform()); - } - - - const Amg::Vector3D& TRT_BaseElement::center() const - { - if (not m_surfaceCache) createSurfaceCache(); - return *(m_surfaceCache->center()); - } - - const Amg::Vector3D& TRT_BaseElement::normal() const - { - if (not m_surfaceCache) createSurfaceCache(); - return *(m_surfaceCache->normal()); - } - - // [B] Description of the individual straws - const Trk::Surface& TRT_BaseElement::surface(const Identifier& id) const - { - int straw = m_idHelper->straw(id); - // Create vector of all straws. - if (!m_strawSurfaces) {createStrawSurfaces();} - Trk::Surface * surfacePtr = (*m_strawSurfaces)[straw].get(); - if (!surfacePtr) { - createSurfaceCache(id); - surfacePtr = (*m_strawSurfaces)[straw].get(); - } - return *surfacePtr; - } - - - const std::vector<const Trk::Surface*>& TRT_BaseElement::surfaces() const - { - std::lock_guard<std::mutex> lock{m_mutex}; - if (!m_surfaces.size()){ - m_surfaces.reserve(nStraws()); - for (unsigned is = 0; is<nStraws(); ++is) - m_surfaces.push_back(&strawSurface(is)); - } - return m_surfaces; - } - - - const Trk::SurfaceBounds& TRT_BaseElement::bounds(const Identifier&) const - { - return strawBounds(); - } - - const Amg::Transform3D& TRT_BaseElement::transform(const Identifier & id) const - { - int straw = m_idHelper->straw(id); - if (!m_strawSurfacesCache) {createStrawSurfacesCache();} - SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get(); - if (!sCachePtr) { - createSurfaceCache(id); - sCachePtr = (*m_strawSurfacesCache)[straw].get(); - } - // forward the transform of the cache - return *(sCachePtr->transform()); - } - - const Amg::Transform3D& TRT_BaseElement::strawTransform(unsigned int straw) const - { - if (!m_strawSurfacesCache) {createStrawSurfacesCache();} - SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get(); - if (!sCachePtr) { - Identifier id = m_idHelper->straw_id(identify(), straw); - createSurfaceCache(id); - sCachePtr = (*m_strawSurfacesCache)[straw].get(); - } - // forward the transform of the cache - return *(sCachePtr->transform()); - } - - - const Amg::Vector3D& TRT_BaseElement::normal(const Identifier&) const - { - // Not sure if the normal of the straw is ever used. - // nor is there a well defined normal. - // This wont be corrected for alignments. - // Just return the element normal - return normal(); - } - - const Amg::Vector3D& TRT_BaseElement::center(const Identifier & id) const - { - int straw = m_idHelper->straw(id); - if (!m_strawSurfacesCache) {createStrawSurfacesCache();} - SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get(); - if (!sCachePtr) { - createSurfaceCache(id); - sCachePtr = (*m_strawSurfacesCache)[straw].get(); - } - // forward the transform of the cache - return *(sCachePtr->center()); - } - - const Trk::StraightLineSurface& TRT_BaseElement::strawSurface(int straw) const - { - // Create vector of all straws. - if (!m_strawSurfaces) {createStrawSurfaces();} - Trk::StraightLineSurface* surfacePtr = (*m_strawSurfaces)[straw].get(); - if (!surfacePtr) { - // get the straw identifier to the given straw number and element identifier - Identifier id = m_idHelper->straw_id(identify(), straw); - createSurfaceCache(id); - surfacePtr = (*m_strawSurfaces)[straw].get(); - } - return *surfacePtr; - } - - const Amg::Transform3D& TRT_BaseElement::strawTransform(int straw) const - { - if (!m_strawSurfacesCache) {createStrawSurfacesCache();} - SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get(); - if (!sCachePtr) { - Identifier id = m_idHelper->straw_id(identify(), straw); - createSurfaceCache(id); - sCachePtr = (*m_strawSurfacesCache)[straw].get(); - } - // forward the transform of the cache - return *(sCachePtr->transform()); - } - - const Amg::Vector3D& TRT_BaseElement::strawCenter(int straw) const - { - if (!m_strawSurfacesCache) {createStrawSurfacesCache();} - SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get(); - if (!sCachePtr) { - Identifier id = m_idHelper->straw_id(identify(), straw); - createSurfaceCache(id); - sCachePtr = (*m_strawSurfacesCache)[straw].get(); - } - // forward the transform of the cache - return *(sCachePtr->center()); - } - - Amg::Vector3D TRT_BaseElement::strawAxis(int straw) const - { - return ( strawTransform(straw).linear()*Amg::Vector3D::UnitZ()*strawDirection() ); - } - - /// ----- can be removed after full Amg migration ----------------------- (start) - // [A] in CLHEP - - const HepGeom::Transform3D TRT_BaseElement::transformCLHEP() const - { - return Amg::EigenTransformToCLHEP(*(m_surfaceCache->transform())); - } - - const HepGeom::Point3D<double> TRT_BaseElement::centerCLHEP() const - { - - const Amg::Vector3D& cCenter = center(); - return HepGeom::Point3D<double>(cCenter.x(),cCenter.y(),cCenter.z()); - } - - const HepGeom::Vector3D<double> TRT_BaseElement::normalCLHEP() const - { - const Amg::Vector3D& cNormal = normal(); - return HepGeom::Vector3D<double>(cNormal.x(),cNormal.y(),cNormal.z()); - } - - // [B] in CLHEP - - const HepGeom::Transform3D TRT_BaseElement::transformCLHEP(const Identifier & id) const - { - return Amg::EigenTransformToCLHEP(transform(id)); - } - - const HepGeom::Point3D<double> TRT_BaseElement::centerCLHEP(const Identifier & id) const - { - const Amg::Vector3D cCenter = center(id); - return HepGeom::Point3D<double>(cCenter.x(),cCenter.y(),cCenter.z()); - } - - const HepGeom::Vector3D<double> TRT_BaseElement::normalCLHEP(const Identifier&) const - { - // Not sure if the normal of the straw is ever used. - // nor is there a well defined normal. - // This wont be corrected for alignments. - // Just return the element normal - return normalCLHEP(); - } - - /// ----- can be removed after full Amg migration ----------------------- (end) - - - void TRT_BaseElement::createSurfaceCache(Identifier id) const - { - // should not happen, but worth the protection - if (!m_strawSurfacesCache) { - createStrawSurfacesCache(); - } - if (!m_strawSurfaces) { - createStrawSurfaces(); - } - - int straw = m_idHelper->straw(id); - - // get the StrawTransform from GeoModel - HepGeom::Transform3D cStrawTransform = calculateStrawTransform(straw); - - // convert neccessary parts to Amg - if (!(*m_strawSurfacesCache)[straw]) { - Amg::Transform3D* sTransform = new Amg::Transform3D(Amg::CLHEPTransformToEigen(cStrawTransform)); - Amg::Vector3D* sCenter = new Amg::Vector3D(sTransform->translation()); - // create the surface cache & fill it - (*m_strawSurfacesCache)[straw] = std::make_unique<SurfaceCache>(sTransform, sCenter, nullptr, nullptr); - } - // creaete the surface only if needed (the links are still intact) - if (!(*m_strawSurfaces)[straw]) { - (*m_strawSurfaces)[straw] = std::make_unique<Trk::StraightLineSurface>(*this, id); - } - } - - void TRT_BaseElement::invalidate() - { - // Invalidate the caches - // Call and barrel or endcap specific invalidation - invalidateOther(); - // Its enough to delete and zero the caches. - deleteCache(); - } - - void TRT_BaseElement::deleteCache() - { - // invalidates the cache, surface object can still live - - // for all straws - if (m_strawSurfacesCache) { - for (size_t i = 0; i < m_strawSurfacesCache->size(); i++) { - (*m_strawSurfacesCache)[i].reset(); - } - } - m_strawSurfacesCache.store(nullptr); - } - - void TRT_BaseElement::updateAllCaches() - { - // delete the caches first - deleteCache(); - // Strawlayer caches - if (not m_surfaceCache) createSurfaceCache(); - // Loop over all straws and request items that get cached. - for (unsigned int iStraw=0; iStraw < nStraws(); iStraw++) { - Identifier strawId = m_idHelper->straw_id(identify(),iStraw); - createSurfaceCache(strawId); - } - } - - const TRT_Conditions* TRT_BaseElement::conditions() const - { - return m_conditions; - } - - TRT_BaseElement::~TRT_BaseElement() - { - } - - void - TRT_BaseElement::createStrawSurfaces() const - { - auto strawSurfaces = std::make_unique< - std::vector<std::unique_ptr<Trk::StraightLineSurface>>>(nStraws()); - m_strawSurfaces.set(std::move(strawSurfaces)); - } - - void - TRT_BaseElement::createStrawSurfacesCache() const - { - auto strawSurfacesCache = - std::make_unique<std::vector<std::unique_ptr<SurfaceCache>>>(nStraws()); - m_strawSurfacesCache.set(std::move(strawSurfacesCache)); - } } diff --git a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_EndcapElement.cxx b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_EndcapElement.cxx index 05b17b2b919d03540f413ff61be5a35e9c3c7ffd..d583e97d4ede562a9734e50bb31d2c17903b3f55 100755 --- a/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_EndcapElement.cxx +++ b/InnerDetector/InDetDetDescr/TRT_ReadoutGeometry/src/TRT_EndcapElement.cxx @@ -6,14 +6,14 @@ #include "InDetReadoutGeometry/SurfaceCache.h" #include "TRT_ReadoutGeometry/TRT_Conditions.h" -#include "InDetIdentifier/TRT_ID.h" #include "Identifier/Identifier.h" +#include "InDetIdentifier/TRT_ID.h" -#include "GeoPrimitives/GeoPrimitives.h" #include "GeoPrimitives/CLHEPtoEigenConverter.h" +#include "GeoPrimitives/GeoPrimitives.h" -#include "GeoModelKernel/GeoDefinitions.h" #include "CLHEP/Geometry/Transform3D.h" +#include "GeoModelKernel/GeoDefinitions.h" #include "GeoModelUtilities/GeoAlignmentStore.h" #include "TrkSurfaces/DiscBounds.h" @@ -24,248 +24,284 @@ #include "GeoModelUtilities/GeoAlignmentStore.h" - namespace InDetDD { - TRT_EndcapElement::TRT_EndcapElement(const GeoVFullPhysVol *volume, - const TRT_EndcapDescriptor *descriptor, - bool isPositive, - unsigned int wheelIndex, - unsigned int strawLayIndex, - unsigned int phiIndex, - const TRT_ID * idHelper, - const TRT_Conditions * conditions, - const GeoAlignmentStore* geoAlignStore) : - TRT_BaseElement(volume, - idHelper->layer_id((isPositive ? 2:-2), phiIndex, wheelIndex, strawLayIndex), - idHelper, conditions, geoAlignStore), - m_code(isPositive,wheelIndex,strawLayIndex,phiIndex), - m_descriptor(descriptor), - m_nextInZ(NULL), - m_previousInZ(NULL) - { - } - - TRT_EndcapElement::TRT_EndcapElement(const TRT_EndcapElement &right, const GeoAlignmentStore* geoAlignStore) : - TRT_BaseElement(right,geoAlignStore), - m_code (right.m_code), - m_descriptor (right.m_descriptor), - m_nextInZ (right.m_nextInZ), - m_previousInZ (right.m_previousInZ) - { - } - - TRT_EndcapElement::~TRT_EndcapElement() - {} - - unsigned int TRT_EndcapElement::nStraws() const - { - return m_descriptor->nStraws(); - } - - const double & TRT_EndcapElement::strawLength() const - { - return m_descriptor->strawLength(); - } - - - const TRT_EndcapConditions * TRT_EndcapElement::getConditionsData() const - { - return NULL; - } - - const TRT_EndcapDescriptor * TRT_EndcapElement::getDescriptor() const - { - return m_descriptor; - } - - void TRT_EndcapElement::setNextInZ(const TRT_EndcapElement *element) - { - m_nextInZ=element; - } - - void TRT_EndcapElement::setPreviousInZ(const TRT_EndcapElement *element) - { - m_previousInZ=element; - } - - - HepGeom::Transform3D TRT_EndcapElement::calculateStrawTransform(int straw) const - { - // NB The tranformation to a straw is reconstructed here precisely as - // it was ... hopefully... in the factory. One could eliminate this - // requirement and make the code a little more robust in this regard but - // at the cost of doubling the descriptors. (One descriptor now suffices - // for both positive and negative endcaps). - const GeoXF::Function *f= m_descriptor->getStrawTransform(); - - if (f) { - int istraw = m_code.isPosZ() ? straw : m_descriptor->nStraws()-1 - straw; - - size_t offsetInto = m_descriptor->getStrawTransformOffset(); - - return Amg::EigenTransformToCLHEP(getMaterialGeom()->getAbsoluteTransform()*((*f)(istraw+offsetInto))) - * calculateLocalStrawTransform(straw); - ////return conditions()->solenoidFrame() - //// * getMaterialGeom()->getAbsoluteTransform()*((*f)(istraw+offsetInto)); - - } else { - - // Will not work properly with alignments. - std::cout << "ALTERNATIVE METHOD" << std::endl; - - double phi = m_descriptor->startPhi() + m_descriptor->strawPitch() * straw; - double r = m_descriptor->innerRadius() + 0.5 * m_descriptor->strawLength() ; - CLHEP::Hep3Vector pos(r*cos(phi) - , r*sin(phi) - , (Amg::EigenTransformToCLHEP(getMaterialGeom()->getAbsoluteTransform())*HepGeom::Point3D<double>()).z()); - CLHEP::HepRotation rot; - // Axis (in local (0,0,1)) points towards beam axis. - rot.rotateY(-0.5*M_PI); // Make it point along -ve X. - rot.rotateZ(phi); - return HepGeom::Transform3D(rot, pos); - } - - } - - // The L3 Alignment - HepGeom::Transform3D TRT_EndcapElement::calculateLocalStrawTransform(int straw) const - { - const TRTCond::StrawDxContainer* container = conditions()->dxContainer(); - HepGeom::Transform3D rc ; - if (container) { - - // important note: dx1 moves the 'negative' wire endpoint end dx2 - // the 'positive' wire endpoint in the local straw frame. - // In the global frame, 'dx1' corresponds to the readout side and 'dx2' - // to the side closest the beampipe. - - int bec = getCode().isPosZ() ? +2 : -2 ; - int wheel = getCode().getWheelIndex(); - int phimodule = getCode().getPhiIndex(); - int strawlayer = getCode().getStrawLayerIndex(); - TRTCond::ExpandedIdentifier id = TRTCond::ExpandedIdentifier(bec - ,wheel - ,phimodule - ,strawlayer - ,straw - ,TRTCond::ExpandedIdentifier::STRAW); - - double dx1 = container->getDx1(id); - double dx2 = container->getDx2(id); - double ang = (dx2-dx1)/strawLength(); - double dy = -1*(dx2+dx1)/2.; - - // In the local straw frame: - // - the z-axis is along the straw and points toward the beampipe - // - the x-axis is along global-z and away from the interaction point - // (locX = globZ A-side / locX = -1 *gobZ C-side) - // - the y-axis is along global phi_hat direction determined by the other 2. - // (clockwise C-side, counter clockwise A-Side) - rc = HepGeom::TranslateY3D(dy)*HepGeom::RotateX3D(ang) ; - } - return rc ; - } - - HepGeom::Transform3D TRT_EndcapElement::defStrawTransform(int straw) const - { - // Same as calculateStrawTransform, except we use getDefAbsoluteTransform() - // rather than getAbsoluteTransform() - - // NB The tranformation to a straw is reconstructed here precisely as - // it was ... hopefully... in the factory. One could eliminate this - // requirement and make the code a little more robust in this regard but - // at the cost of doubling the descriptors. (One descriptor now suffices - // for both positive and negative endcaps). - - const GeoXF::Function *f= m_descriptor->getStrawTransform(); - - if (f) { - - int istraw = m_code.isPosZ() ? straw : m_descriptor->nStraws()-1 - straw; - - size_t offsetInto = m_descriptor->getStrawTransformOffset(); - return Amg::EigenTransformToCLHEP(getMaterialGeom()->getDefAbsoluteTransform()*((*f)(istraw+offsetInto))); - - } else { - - double phi = m_descriptor->startPhi() + m_descriptor->strawPitch() * straw; - double r = m_descriptor->innerRadius() + 0.5 * m_descriptor->strawLength() ; - CLHEP::Hep3Vector pos(r*cos(phi) - , r*sin(phi) - , (Amg::EigenTransformToCLHEP(getMaterialGeom()->getDefAbsoluteTransform())*HepGeom::Point3D<double>()).z()); - CLHEP::HepRotation rot; - rot.rotateY(-0.5*M_PI); // Make it point along -ve X. - rot.rotateZ(phi); - return HepGeom::Transform3D(rot, pos); - } - - } - - const Trk::SurfaceBounds& TRT_EndcapElement::strawBounds() const - { - return m_descriptor->strawBounds(); - } - - const Trk::Surface& TRT_EndcapElement::elementSurface() const - { - if (not m_surface) m_surface.set(std::make_unique<Trk::DiscSurface>(*this)); - return *m_surface; - } - - void TRT_EndcapElement::createSurfaceCache() const - { - // Calculate the surface - double phiCenter = m_descriptor->startPhi() + m_descriptor->strawPitch() * 0.5*(nStraws()-1); - double phiHalfWidth = 0.5 * m_descriptor->strawPitch() * nStraws(); - double rMin = m_descriptor->innerRadius(); - double rMax = rMin +m_descriptor->strawLength(); - - // The transform of the endcap is a translation in z for no - // misalignement. For the -ve endcap there is also a 180deg rotation - // around the y axis. getAbsoluteTransform() will also include the - // misalignment. - // - // To get the transform of the element we have to first rotate - // around z to the phi center of the element. We want the local z - // to point in the same direction for both endcaps (approximately - // global z axis). For the negative endcap we therefore have to - // rotate 180 CLHEP::deg around the Y axis. - - // We need to rotate to phi center before we apply the - // misalignment. However, in the negative endcap the the phi - // location is inverted (due to 180 rotation around y axis). This is - // taken care of by the extra 180 CLHEP::deg rotation around Y that we do - // to get the z axis pointing in the correct direction. - - Amg::Transform3D * transform = 0; - if (m_code.isPosZ()) - transform = new Amg::Transform3D((getMaterialGeom()->getAbsoluteTransform() * GeoTrf::RotateZ3D(phiCenter))); - else - transform = new Amg::Transform3D((getMaterialGeom()->getAbsoluteTransform() * GeoTrf::RotateY3D(180*CLHEP::deg) * GeoTrf::RotateZ3D(phiCenter))); - - // create the igredients and the cache - Trk::DiscBounds* bounds = new Trk::DiscBounds(rMin, rMax, phiHalfWidth); - Amg::Vector3D* center = new Amg::Vector3D(transform->translation()); - Amg::Vector3D* normal = new Amg::Vector3D(transform->rotation().col(2)); - m_surfaceCache.set(std::make_unique<SurfaceCache>(transform, center, normal, bounds)); - // create the surface if needed - if (not m_surface) elementSurface(); - } - - - - int TRT_EndcapElement::strawDirection() const - { - // Return +1 if the straw local axis is in the same direction as increasing eta direction, +TRT_EndcapElement::TRT_EndcapElement(const GeoVFullPhysVol* volume, + const TRT_EndcapDescriptor* descriptor, + bool isPositive, + unsigned int wheelIndex, + unsigned int strawLayIndex, + unsigned int phiIndex, + const TRT_ID* idHelper, + const TRT_Conditions* conditions, + const GeoAlignmentStore* geoAlignStore) + : + + TRT_BaseElement(volume, + idHelper->layer_id((isPositive ? 2 : -2), + phiIndex, + wheelIndex, + strawLayIndex), + idHelper, + conditions, + geoAlignStore) + , m_code(isPositive, wheelIndex, strawLayIndex, phiIndex) + , m_descriptor(descriptor) + , m_nextInZ(nullptr) + , m_previousInZ(nullptr) +{ + m_nstraws = m_descriptor->nStraws(); + m_strawSurfaces.resize(m_nstraws); + m_strawSurfacesCache.resize(m_nstraws); +} + +TRT_EndcapElement::TRT_EndcapElement(const TRT_EndcapElement& right, + const GeoAlignmentStore* geoAlignStore) + : TRT_BaseElement(right, geoAlignStore) + , m_code(right.m_code) + , m_descriptor(right.m_descriptor) + , m_nextInZ(right.m_nextInZ) + , m_previousInZ(right.m_previousInZ) +{ + m_nstraws = right.m_nstraws; + m_strawSurfaces.resize(m_nstraws); + m_strawSurfacesCache.resize(m_nstraws); +} + +TRT_EndcapElement::~TRT_EndcapElement() {} + + +const double& +TRT_EndcapElement::strawLength() const +{ + return m_descriptor->strawLength(); +} + +const TRT_EndcapConditions* +TRT_EndcapElement::getConditionsData() const +{ + return nullptr; +} + +const TRT_EndcapDescriptor* +TRT_EndcapElement::getDescriptor() const +{ + return m_descriptor; +} + +void +TRT_EndcapElement::setNextInZ(const TRT_EndcapElement* element) +{ + m_nextInZ = element; +} + +void +TRT_EndcapElement::setPreviousInZ(const TRT_EndcapElement* element) +{ + m_previousInZ = element; +} + +HepGeom::Transform3D +TRT_EndcapElement::calculateStrawTransform(int straw) const +{ + // NB The tranformation to a straw is reconstructed here precisely as + // it was ... hopefully... in the factory. One could eliminate this + // requirement and make the code a little more robust in this regard but + // at the cost of doubling the descriptors. (One descriptor now suffices + // for both positive and negative endcaps). + const GeoXF::Function* f = m_descriptor->getStrawTransform(); + + if (f) { + int istraw = m_code.isPosZ() ? straw : m_descriptor->nStraws() - 1 - straw; + + size_t offsetInto = m_descriptor->getStrawTransformOffset(); + + return Amg::EigenTransformToCLHEP( + getMaterialGeom()->getAbsoluteTransform() * + ((*f)(istraw + offsetInto))) * + calculateLocalStrawTransform(straw); + ////return conditions()->solenoidFrame() + //// * getMaterialGeom()->getAbsoluteTransform()*((*f)(istraw+offsetInto)); + + } else { + + // Will not work properly with alignments. + std::cout << "ALTERNATIVE METHOD" << std::endl; + + double phi = m_descriptor->startPhi() + m_descriptor->strawPitch() * straw; + double r = m_descriptor->innerRadius() + 0.5 * m_descriptor->strawLength(); + CLHEP::Hep3Vector pos( + r * cos(phi), + r * sin(phi), + (Amg::EigenTransformToCLHEP(getMaterialGeom()->getAbsoluteTransform()) * + HepGeom::Point3D<double>()) + .z()); + CLHEP::HepRotation rot; + // Axis (in local (0,0,1)) points towards beam axis. + rot.rotateY(-0.5 * M_PI); // Make it point along -ve X. + rot.rotateZ(phi); + return HepGeom::Transform3D(rot, pos); + } +} + +// The L3 Alignment +HepGeom::Transform3D +TRT_EndcapElement::calculateLocalStrawTransform(int straw) const +{ + const TRTCond::StrawDxContainer* container = conditions()->dxContainer(); + HepGeom::Transform3D rc; + if (container) { + + // important note: dx1 moves the 'negative' wire endpoint end dx2 + // the 'positive' wire endpoint in the local straw frame. + // In the global frame, 'dx1' corresponds to the readout side and 'dx2' + // to the side closest the beampipe. + + int bec = getCode().isPosZ() ? +2 : -2; + int wheel = getCode().getWheelIndex(); + int phimodule = getCode().getPhiIndex(); + int strawlayer = getCode().getStrawLayerIndex(); + TRTCond::ExpandedIdentifier id = + TRTCond::ExpandedIdentifier(bec, + wheel, + phimodule, + strawlayer, + straw, + TRTCond::ExpandedIdentifier::STRAW); + + double dx1 = container->getDx1(id); + double dx2 = container->getDx2(id); + double ang = (dx2 - dx1) / strawLength(); + double dy = -1 * (dx2 + dx1) / 2.; + + // In the local straw frame: + // - the z-axis is along the straw and points toward the beampipe + // - the x-axis is along global-z and away from the interaction point + // (locX = globZ A-side / locX = -1 *gobZ C-side) + // - the y-axis is along global phi_hat direction determined by the + // other 2. + // (clockwise C-side, counter clockwise A-Side) + rc = HepGeom::TranslateY3D(dy) * HepGeom::RotateX3D(ang); + } + return rc; +} + +HepGeom::Transform3D +TRT_EndcapElement::defStrawTransform(int straw) const +{ + // Same as calculateStrawTransform, except we use getDefAbsoluteTransform() + // rather than getAbsoluteTransform() + + // NB The tranformation to a straw is reconstructed here precisely as + // it was ... hopefully... in the factory. One could eliminate this + // requirement and make the code a little more robust in this regard but + // at the cost of doubling the descriptors. (One descriptor now suffices + // for both positive and negative endcaps). + + const GeoXF::Function* f = m_descriptor->getStrawTransform(); + + if (f) { + + int istraw = m_code.isPosZ() ? straw : m_descriptor->nStraws() - 1 - straw; + + size_t offsetInto = m_descriptor->getStrawTransformOffset(); + return Amg::EigenTransformToCLHEP( + getMaterialGeom()->getDefAbsoluteTransform() * + ((*f)(istraw + offsetInto))); + + } else { + + double phi = m_descriptor->startPhi() + m_descriptor->strawPitch() * straw; + double r = m_descriptor->innerRadius() + 0.5 * m_descriptor->strawLength(); + CLHEP::Hep3Vector pos(r * cos(phi), + r * sin(phi), + (Amg::EigenTransformToCLHEP( + getMaterialGeom()->getDefAbsoluteTransform()) * + HepGeom::Point3D<double>()) + .z()); + CLHEP::HepRotation rot; + rot.rotateY(-0.5 * M_PI); // Make it point along -ve X. + rot.rotateZ(phi); + return HepGeom::Transform3D(rot, pos); + } +} + +const Trk::SurfaceBounds& +TRT_EndcapElement::strawBounds() const +{ + return m_descriptor->strawBounds(); +} + +const Trk::Surface& +TRT_EndcapElement::elementSurface() const +{ + if (not m_surface) + m_surface.set(std::make_unique<Trk::DiscSurface>(*this)); + return *m_surface; +} + +void +TRT_EndcapElement::createSurfaceCache() const +{ + // Calculate the surface + double phiCenter = m_descriptor->startPhi() + + m_descriptor->strawPitch() * 0.5 * (nStraws() - 1); + double phiHalfWidth = 0.5 * m_descriptor->strawPitch() * nStraws(); + double rMin = m_descriptor->innerRadius(); + double rMax = rMin + m_descriptor->strawLength(); + + // The transform of the endcap is a translation in z for no + // misalignement. For the -ve endcap there is also a 180deg rotation + // around the y axis. getAbsoluteTransform() will also include the + // misalignment. + // + // To get the transform of the element we have to first rotate + // around z to the phi center of the element. We want the local z + // to point in the same direction for both endcaps (approximately + // global z axis). For the negative endcap we therefore have to + // rotate 180 CLHEP::deg around the Y axis. + + // We need to rotate to phi center before we apply the + // misalignment. However, in the negative endcap the the phi + // location is inverted (due to 180 rotation around y axis). This is + // taken care of by the extra 180 CLHEP::deg rotation around Y that we do + // to get the z axis pointing in the correct direction. + + Amg::Transform3D* transform = 0; + if (m_code.isPosZ()) + transform = + new Amg::Transform3D((getMaterialGeom()->getAbsoluteTransform() * + GeoTrf::RotateZ3D(phiCenter))); + else + transform = new Amg::Transform3D( + (getMaterialGeom()->getAbsoluteTransform() * + GeoTrf::RotateY3D(180 * CLHEP::deg) * GeoTrf::RotateZ3D(phiCenter))); + + // create the igredients and the cache + Trk::DiscBounds* bounds = new Trk::DiscBounds(rMin, rMax, phiHalfWidth); + Amg::Vector3D* center = new Amg::Vector3D(transform->translation()); + Amg::Vector3D* normal = new Amg::Vector3D(transform->rotation().col(2)); + m_surfaceCache.set( + std::make_unique<SurfaceCache>(transform, center, normal, bounds)); + // create the surface if needed + if (not m_surface){ + elementSurface(); + } +} + +int +TRT_EndcapElement::strawDirection() const +{ + // Return +1 if the straw local axis is in the same direction as increasing + // eta direction, // -1 otherwise. - // The straw axis by convention goes in the direction away from the readout. This is - // towards the beam pipe. For +ve endcap it is what we want. For -ve endcap it is oppposite. - // - // - return (m_code.isPosZ()) ? +1 : -1; - } + // The straw axis by convention goes in the direction away from the readout. + // This is towards the beam pipe. For +ve endcap it is what we want. For -ve + // endcap it is oppposite. + // + // + return (m_code.isPosZ()) ? +1 : -1; +} } // end namespace -