ATLAS Offline Software
ActsFatrasWriteHandler.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ActsFatrasWriteHandler.cxx
8 
9 // class header
10 #include "ActsFatrasWriteHandler.h"
11 //InDet
14 
15 //Tracking ACTS
17 
18 
19 ActsFatrasWriteHandler::ActsFatrasWriteHandler(const std::string& type, const std::string& name,
20  const IInterface* parent)
21  : AthAlgTool(type, name, parent){}
22 
24 
26 {
27  ATH_MSG_INFO(name() << " initialize()" );
28  // Get the Pixel Identifier-helper
29  ATH_CHECK(detStore()->retrieve(m_pixIdHelper, "PixelID"));
30  // Get the SCT Identifier-helper
32  // setup handle keys
33  for(auto const& HitCollectionName:m_HitCollectionNames){
34  m_HitCollectionKeys.push_back(static_cast<std::string>(HitCollectionName));
35  }
36  ATH_CHECK(m_HitCollectionKeys.initialize());
37 
38  ATH_MSG_INFO(name() << " initialize() successful" );
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode ActsFatrasWriteHandler::WriteHits(std::vector<SiHitCollection>& HitCollections, const EventContext& ctx) const
43 {
44  auto HitsWriteHandles = m_HitCollectionKeys.makeHandles(ctx);
45  for(long unsigned int i=0;i<HitCollections.size();++i){
46  ATH_MSG_DEBUG(name() << " WriteHits: adding "<<m_HitCollectionNames[i]<< " "<<HitCollections[i].size()<<" hits");
47  ATH_CHECK(HitsWriteHandles[i].record(std::make_unique<SiHitCollection>(HitCollections[i])));
48  ATH_MSG_DEBUG(name() << " WriteHits: added "<<m_HitCollectionNames[i]<< " "<<HitCollections[i].size()<<" hits");
49  }
50  return StatusCode::SUCCESS;
51 }
52 
54 {
55  return StatusCode::SUCCESS;
56 }
57 
59  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
60  const std::vector<ActsFatras::Hit>& hits,
61  SiHitCollection& pixelSiHits, SiHitCollection& sctSiHits) const
62 {
63  ATH_MSG_VERBOSE(name() << " particle " << isp << " with " << hits.size() << " hits");
64  for (auto& hit:hits){
65  double energyDeposit = hit.depositedEnergy();
66  double time = hit.time();
67 
68  // get the ACTS geo identifier
69  auto hit_geoid = hit.geometryId();
70  // get the ACTS surface
71  try {
72  auto acts_surface = trackingGeometry->findSurface(hit_geoid);
73  const ActsDetectorElement* acts_de = dynamic_cast<const ActsDetectorElement*>(acts_surface->associatedDetectorElement());
74 
75  const Trk::Surface& hitSurface = acts_de->atlasSurface();
76  ATH_MSG_VERBOSE(name() << " Surface position global atlas: " << hitSurface.center());
77  // get the ATLAS identifier and hash identifier
78  Identifier hitId = hitSurface.associatedDetectorElementIdentifier();
79  ATH_MSG_VERBOSE(name() << " hit Id Acts|atlas: "<< hit_geoid <<"|" << hitId);
80  const Trk::TrkDetElementBase* detElementBase = hitSurface.associatedDetectorElement();
81  const InDetDD::SiDetectorElement* hitSiDetElement = dynamic_cast<const InDetDD::SiDetectorElement*>((detElementBase));
82  ATH_MSG_VERBOSE(name() << " hit position global Acts|atlas: " << hit.position() <<"|" << detElementBase->center());
83 
84  auto intersection = hitSurface.globalToLocal(hit.position());
85  ATH_MSG_VERBOSE(name() << " hit isOnSurface: "<<hitSurface.isOnSurface(hit.position()));
86  ATH_MSG_VERBOSE(name() << " intersection (atlas local) " << intersection.value().x() <<"," << intersection.value().y());
87  double interX = intersection.value().x();
88  double interY = intersection.value().y();
89 
90  double thickness = hitSiDetElement->thickness();
91  ATH_MSG_VERBOSE(name() << " thickness (atlas)" << thickness);
92 
93  const Amg::Transform3D &hitTransform = hitSiDetElement->transformHit().inverse();
94  // get the momentum direction into the local frame
95  Amg::Vector3D particleDir = hit.direction();
96  const Amg::Transform3D& sTransform = hitSurface.transform();
97  Amg::Vector3D localDirection = sTransform.inverse().linear() * particleDir;
98  localDirection *= thickness/cos(localDirection.theta());
99  // moving direction
100  int movingDirection = localDirection.z() > 0. ? 1 : -1;
101  // get he local distance of the intersection in x,y
102  double distX = localDirection.x();
103  double distY = localDirection.y();
104  // local entries in x,y
105  double localEntryX = interX-0.5*distX;
106  double localEntryY = interY-0.5*distY;
107  double localExitX = interX+0.5*distX;
108  double localExitY = interY+0.5*distY;
110  // transform into the hit frame
111  Amg::Vector3D localEntry(hitTransform * (sTransform * Amg::Vector3D(localEntryX,localEntryY,-0.5*movingDirection*thickness)));
112  Amg::Vector3D localExit(hitTransform * (sTransform * Amg::Vector3D(localExitX,localExitY,0.5*movingDirection*thickness)));
113  const HepGeom::Point3D<double> localEntryHep( localEntry.x(), localEntry.y(), localEntry.z() );
114  const HepGeom::Point3D<double> localExitHep( localExit.x(), localExit.y(), localExit.z() );
115 
116  auto isPixel=hitSiDetElement->isPixel();
117  ATH_MSG_VERBOSE(name() << " localEntryHep|localExitHep (atlas)" << localEntryHep << "|" << localExitHep);
118  ATH_MSG_VERBOSE(name() << " isPixel " << isPixel);
119  ATH_MSG_VERBOSE(name() << " barrel_ec (atlas)" << (isPixel ? m_pixIdHelper->barrel_ec(hitId) : m_sctIdHelper->barrel_ec(hitId)));
120  ATH_MSG_VERBOSE(name() << " layer_disk (atlas)" << (isPixel ? m_pixIdHelper->layer_disk(hitId) : m_sctIdHelper->layer_disk(hitId)));
121  ATH_MSG_VERBOSE(name() << " eta_module (atlas)" << (isPixel ? m_pixIdHelper->eta_module(hitId) : m_sctIdHelper->eta_module(hitId)));
122  ATH_MSG_VERBOSE(name() << " phi_module (atlas)" << (isPixel ? m_pixIdHelper->phi_module(hitId) : m_sctIdHelper->phi_module(hitId)));
123 
124  auto partLink = isp.getParticleLink();
125  auto siHit = SiHit(localEntryHep,
126  localExitHep,
128  time,
129  *partLink,
130  isPixel ? 0 : 1,
131  isPixel ? m_pixIdHelper->barrel_ec(hitId) : m_sctIdHelper->barrel_ec(hitId),
132  isPixel ? m_pixIdHelper->layer_disk(hitId) : m_sctIdHelper->layer_disk(hitId),
133  isPixel ? m_pixIdHelper->eta_module(hitId) : m_sctIdHelper->eta_module(hitId),
134  isPixel ? m_pixIdHelper->phi_module(hitId) : m_sctIdHelper->phi_module(hitId),
135  isPixel ? 0 : m_sctIdHelper->side(hitId));
136  if (isPixel)
137  pixelSiHits.push_back(siHit);
138  else
139  sctSiHits.push_back(siHit);
140  ATH_MSG_VERBOSE(name() << " convert and store 1 hit, total" << pixelSiHits.size() << "Pixel | "<<sctSiHits.size()<< " SCT hits stored for particle" << isp);
141  }
142  catch (const std::exception& e){
143  ATH_MSG_DEBUG(name() << "Can not find Acts Surface (" << e.what() << ")...Skip...");
144  }
145  }
146 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ActsFatrasWriteHandler::ActsFatrasWriteHandler
ActsFatrasWriteHandler(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: ActsFatrasWriteHandler.cxx:19
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
Trk::Surface::associatedDetectorElement
const TrkDetElementBase * associatedDetectorElement() const
return associated Detector Element
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsFatrasWriteHandler::initialize
virtual StatusCode initialize() override
Definition: ActsFatrasWriteHandler.cxx:25
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
ActsFatrasWriteHandler::WriteHits
StatusCode WriteHits(std::vector< SiHitCollection > &HitCollections, const EventContext &ctx) const
Definition: ActsFatrasWriteHandler.cxx:42
Trk::Surface::associatedDetectorElementIdentifier
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
AtlasHitsVector
Definition: AtlasHitsVector.h:33
ISF::ISFParticle
Definition: ISFParticle.h:42
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Trk::energyDeposit
@ energyDeposit
Definition: MeasurementType.h:32
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
SiHit
Definition: SiHit.h:19
ActsFatrasWriteHandler::~ActsFatrasWriteHandler
~ActsFatrasWriteHandler()
Destructor.
Definition: ActsFatrasWriteHandler.cxx:23
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trk::Surface::isOnSurface
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const
This method returns true if the GlobalPosition is on the Surface for both, within or without check of...
Definition: Surface.cxx:123
ActsFatrasWriteHandler::finalize
virtual StatusCode finalize() override
Definition: ActsFatrasWriteHandler.cxx:53
lumiFormat.i
int i
Definition: lumiFormat.py:85
InDetDD::SolidStateDetectorElementBase::thickness
double thickness() const
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ActsFatrasWriteHandler.h
ActsDetectorElement::atlasSurface
const Trk::Surface & atlasSurface() const
Return a shared pointer on the ATLAS surface associated with this identifier,.
Definition: ActsDetectorElement.cxx:267
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
calibdata.exception
exception
Definition: calibdata.py:496
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsDetectorElement
Definition: ActsDetectorElement.h:42
ActsDetectorElement.h
InDetDD::SiDetectorElement::isPixel
bool isPixel() const
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ActsFatrasWriteHandler::m_sctIdHelper
const SCT_ID * m_sctIdHelper
the SCT ID helper
Definition: ActsFatrasWriteHandler.h:70
SiDetectorElement.h
ISF::ISFParticle::getParticleLink
const HepMcParticleLink * getParticleLink() const
HepMcParticleLink accessors.
Definition: ISFParticle.h:172
ActsFatrasWriteHandler::m_HitCollectionNames
std::array< StringProperty, 2 > m_HitCollectionNames
Definition: ActsFatrasWriteHandler.h:72
Trk::Surface::globalToLocal
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const =0
Specified by each surface type: GlobalToLocal method without dynamic memory allocation - boolean chec...
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
AthAlgTool
Definition: AthAlgTool.h:26
ActsFatrasWriteHandler::m_HitCollectionKeys
SG::WriteHandleKeyArray< SiHitCollection > m_HitCollectionKeys
Definition: ActsFatrasWriteHandler.h:73
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
InDetDD::SolidStateDetectorElementBase::transformHit
const GeoTrf::Transform3D & transformHit() const
Local (simulation/hit frame) to global transform.
ActsFatrasWriteHandler::createHits
void createHits(const ISF::ISFParticle &isp, std::shared_ptr< const Acts::TrackingGeometry > trackingGeometry, const std::vector< ActsFatras::Hit > &hits, SiHitCollection &pixelSiHits, SiHitCollection &sctSiHits) const
Loop over the hits and call the hit creator, provide the ActsFatras::Particle to create the hits.
Definition: ActsFatrasWriteHandler.cxx:58
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::TrkDetElementBase::center
virtual const Amg::Vector3D & center() const =0
Return the center of the element.
ActsFatrasWriteHandler::m_pixIdHelper
const PixelID * m_pixIdHelper
the Pixel ID helper
Definition: ActsFatrasWriteHandler.h:69
AtlasHitsVector::push_back
void push_back(const T &t)
Definition: AtlasHitsVector.h:145
Identifier
Definition: IdentifierFieldParser.cxx:14
SiHitCollection.h