Skip to content
Snippets Groups Projects
Commit 8a196a3f authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'TRT_BaseElement_further_refactor' into 'master'

ATLASRECTS-5781: TRT_BaseElement MT issues Part I

See merge request atlas/athena!38491
parents b1af09f5 fdbb3674
No related branches found
No related tags found
No related merge requests found
Showing with 710 additions and 691 deletions
......@@ -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;
......
......@@ -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();
}
}
......@@ -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
......@@ -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;
}
}
......@@ -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;
......
......@@ -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;
}
......
......@@ -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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment