ATLAS Offline Software
Loading...
Searching...
No Matches
HgtdTimedClusteringTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "Acts/Clusterization/TimedClusterization.hpp"
10
11namespace Hgtd {
12 static inline int getCellRow(const Hgtd::UnpackedHgtdRDO& cell)
13 { return cell.ROW; }
14
15 static inline int getCellColumn(const Hgtd::UnpackedHgtdRDO& cell)
16 { return cell.COL; }
17
18 static inline double getCellTime(const Hgtd::UnpackedHgtdRDO& cell)
19 { return cell.TOA; }
20
23 {
24 cl.ids.push_back(cell.ID.get_compact());
25 cl.tots.push_back(cell.TOT);
26 cl.times.push_back(cell.TOA);
27 }
28}
29
30
31namespace ActsTrk {
33 const std::string& name,
34 const IInterface* parent)
35 : base_class(type, name, parent)
36 {}
37
39 {
40 ATH_MSG_DEBUG("Initializing " << name() << "...");
41
42 ATH_CHECK(detStore()->retrieve(m_hgtd_det_mgr, "HGTD"));
43 ATH_CHECK(detStore()->retrieve(m_hgtd_id, "HGTD_ID"));
44 ATH_CHECK(m_hgtd_tdc_calib_tool.retrieve(EnableTool{m_use_altiroc_rdo.value()}));
45
47
48 return StatusCode::SUCCESS;
49 }
50
51 std::any HgtdTimedClusteringTool::createEventDataCache(xAOD::HGTDClusterContainer& cont, std::size_t nClusterRDOs) const {
52 return HgtdAuxDataCache(cont,nClusterRDOs);
53 }
54
55 StatusCode HgtdTimedClusteringTool::clusterize(const EventContext& /*ctx*/,
56 const RawDataCollection& RDOs,
57 std::vector<ClusterCollection>& collection) const
58 {
59 collection.emplace_back();
60 ClusterCollection &clusters=collection.back();
61 // best guess about number of expected clusters is one cluster per RDO
62 clusters.reserve(RDOs.size());
63 // Unpack RDOs (would need a proper function here)
64 CellCollection cells;
65 cells.reserve(RDOs.size());
66 for (const HGTD_RDO* rdo : RDOs) {
67 Identifier id = rdo->identify();
68 cells.emplace_back(-1,
69 m_hgtd_id->phi_index(id),
70 m_hgtd_id->eta_index(id),
71 rdo->getTOA(),
72 rdo->getTOT(),
73 id);
74 }
75
76 ATH_MSG_DEBUG("Clustering on " << RDOs.size() << " RDOs using time information");
77 Acts::Ccl::ClusteringData data;
78 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>
79 (data, cells, clusters, Acts::Ccl::TimedConnect<Cell, 2ul>(m_timeTollerance.value(), m_addCorners.value()));
80 ATH_MSG_DEBUG(" \\_ " << clusters.size() << " clusters reconstructed");
81 return StatusCode::SUCCESS;
82 }
83
84 StatusCode HgtdTimedClusteringTool::makeClusters(const EventContext& ctx,
85 const ClusterCollection& clusters,
87 size_t& icluster,
88 std::any& cache) const
89 {
90 HgtdAuxDataCache* auxDataCache = std::any_cast<HgtdAuxDataCache> (&cache);
91 if (!auxDataCache) throw std::bad_any_cast();
92 assert( icluster+clusters.size() <= container.size() );
93 for (std::size_t i(0); i<clusters.size(); ++i) {
94 const typename HgtdTimedClusteringTool::Cluster& cluster = clusters[i];
95 assert(icluster+i == container[icluster+i]->index());
96 ATH_CHECK(makeCluster(ctx, cluster, *container[icluster+i],auxDataCache));
97 }
98
99 return StatusCode::SUCCESS;
100 }
101
102 StatusCode HgtdTimedClusteringTool::makeCluster(const EventContext& /*ctx*/,
103 const typename HgtdTimedClusteringTool::Cluster &cluster,
104 xAOD::HGTDCluster& xaodcluster,
105 HgtdAuxDataCache* auxDataCache) const
106 {
107 if (cluster.ids.empty()) return StatusCode::SUCCESS;
108
109 InDetDD::SiLocalPosition pos_acc(0,0);
110 double tot_time = 0;
111
112 unsigned int icluster=xaodcluster.index();
113 unsigned int n_rdos = auxDataCache->rdoList.getBeginIndex(icluster);
114 assert(icluster==0 || n_rdos == auxDataCache->totList.getBeginIndex(icluster));
115 assert( n_rdos+cluster.ids.size() <= auxDataCache->rdoList.nObjects() );
116 assert( cluster.tots.size() == cluster.ids.size());
117 for (size_t i = 0; i < cluster.ids.size(); i++) {
118 Identifier rdo_id(cluster.ids[i]);
119 // @TODO get detector only once, all clusters should belong to the same detector element
120 const InDetDD::HGTD_DetectorElement* element = m_hgtd_det_mgr->getDetectorElement(rdo_id);
121 InDetDD::SiCellId si_cell_id = element->cellIdFromIdentifier(rdo_id);
122 InDetDD::SiLocalPosition si_pos = element->design().localPositionOfCell(si_cell_id);
123
124 auxDataCache->rdoList.setValue(n_rdos,rdo_id.get_compact());
125 auxDataCache->totList.setValue(n_rdos,cluster.tots[i]);
126 ++n_rdos;
127
128 pos_acc += si_pos;
129 tot_time += cluster.times[i];
130 }
131
132 pos_acc /= cluster.ids.size();
133 tot_time /= cluster.ids.size();
134
135 // Create the cluster
136 Eigen::Matrix<float, 3, 1> loc_pos(pos_acc.xPhi(), pos_acc.xEta(), tot_time);
137 Eigen::Matrix<float, 3, 3> cov_matrix= Eigen::Matrix<float, 3, 3>::Zero();
138
139 constexpr float xWidth = 1.3;
140 constexpr float yWidth = 1.3;
141 cov_matrix(0,0) = xWidth * xWidth / 12 / cluster.ids.size(); // i.e. Cov XX
142 cov_matrix(1,1) = yWidth * yWidth / 12 / cluster.ids.size(); // i.e. Cov YY
143 constexpr float time_of_arrival_err = 0.035;
144 cov_matrix(2,2) = time_of_arrival_err * time_of_arrival_err / cluster.ids.size(); // i.e. Cov TT
145 // @TODO get detector element only once by caller aka. makeClusters
146 IdentifierHash id_hash = m_hgtd_det_mgr->getDetectorElement(Identifier(cluster.ids.front()))->identifyHash();
147
148 // Fill
149 xaodcluster.setMeasurement<3>(id_hash,loc_pos,cov_matrix);
150 xaodcluster.setIdentifier(cluster.ids.front());
151 auxDataCache->rdoList.updateEndIndex(icluster,n_rdos);
152 auxDataCache->totList.updateEndIndex(icluster,n_rdos);
153
154 return StatusCode::SUCCESS;
155 }
156
157StatusCode HgtdTimedClusteringTool::clusterize(const EventContext& /*ctx*/,
158 const HGTD_ALTIROC_RDO_Collection& RDOs,
159 std::vector<ClusterCollection>& collection) const
160{
161 collection.emplace_back();
162 ClusterCollection &clusters=collection.back();
163 // best guess about number of expected clusters is one cluster per RDO
164 clusters.reserve(RDOs.size());
165 // Unpack RDOs (would need a proper function here)
166 CellCollection cells;
167 cells.reserve(RDOs.size());
168 for (const HGTD_ALTIROC_RDO* rdo : RDOs) {
169 Identifier id = rdo->identify();
170
171 const InDetDD::HGTD_DetectorElement* element = m_hgtd_det_mgr->getDetectorElement(id);
172 uint8_t time_of_flight = m_hgtd_tdc_calib_tool->TOA2Time(element, rdo->getToA());
173
174 ATH_MSG_DEBUG("Recovered Time of Arrival: " << time_of_flight);
175
176 cells.emplace_back(-1,
177 m_hgtd_id->phi_index(id),
178 m_hgtd_id->eta_index(id),
179 time_of_flight,
180 rdo->getToT(),
181 id);
182 }
183
184 ATH_MSG_DEBUG("Clustering on " << RDOs.size() << " RDOs using time information");
185 Acts::Ccl::ClusteringData data;
186 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>
187 (data, cells, clusters, Acts::Ccl::TimedConnect<Cell, 2ul>(m_timeTollerance.value(), m_addCorners.value()));
188 ATH_MSG_DEBUG(" \\_ " << clusters.size() << " clusters reconstructed");
189 return StatusCode::SUCCESS;
190}
191
192} // namespace
193
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Define structures for fast filling of xAOD objects.
IHGTDClusteringTool::Cluster Cluster
virtual std::any createEventDataCache(xAOD::HGTDClusterContainer &cont, std::size_t nClusterRDOs) const override
virtual StatusCode clusterize(const EventContext &ctx, const RawDataCollection &RDOs, std::vector< ClusterCollection > &collection) const override
const HGTD_DetectorManager * m_hgtd_det_mgr
virtual StatusCode makeClusters(const EventContext &ctx, const ClusterCollection &clusters, xAOD::HGTDClusterContainer &container, size_t &icluster, std::any &cache) const override
StatusCode makeCluster(const EventContext &ctx, const typename HgtdTimedClusteringTool::Cluster &cluster, xAOD::HGTDCluster &xaodcluster, HgtdAuxDataCache *cache) const
virtual StatusCode initialize() override
HgtdTimedClusteringTool(const std::string &type, const std::string &name, const IInterface *parent)
ToolHandle< HGTD_TdcCalibrationTool > m_hgtd_tdc_calib_tool
Gaudi::Property< double > m_timeTollerance
IHGTDClusteringTool::ClusterCollection ClusterCollection
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Class to hold geometrical description of an HGTD detector element.
SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
const HGTD_ModuleDesign & design() const override final
access to the local description:
virtual SiLocalPosition localPositionOfCell(const SiCellId &cellId) const
readout or diode id -> position.
Identifier for the strip or pixel cell.
Definition SiCellId.h:29
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
double xEta() const
position along eta direction:
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
void updateEndIndex(unsigned int obj_i, unsigned int elm_i)
unsigned int getBeginIndex(unsigned int obj_i) const
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
static int getCellColumn(const Hgtd::UnpackedHgtdRDO &cell)
static int getCellRow(const Hgtd::UnpackedHgtdRDO &cell)
static void clusterAddCell(ActsTrk::HgtdTimedClusteringTool::Cluster &cl, const ActsTrk::HgtdTimedClusteringTool::Cell &cell)
static double getCellTime(const Hgtd::UnpackedHgtdRDO &cell)
Definition index.py:1
HGTDClusterContainer_v1 HGTDClusterContainer
Define the version of the HGTD cluster container.
HGTDCluster_v1 HGTDCluster
Define the version of the pixel cluster class.
Definition HGTDCluster.h:13
xAOD::xAODInDetMeasurement::Utilities::JaggedVecEltCache< int > totList
xAOD::xAODInDetMeasurement::Utilities::JaggedVecEltCache< Identifier::value_type > rdoList
std::vector< Identifier::value_type > ids