ATLAS Offline Software
PixelClusteringTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "PixelClusteringTool.h"
6 
7 #include <Acts/Clusterization/Clusterization.hpp>
8 
14 
15 #include <unordered_set>
16 
17 using CLHEP::micrometer;
18 
19 namespace ActsTrk {
20 
23 {
24  cl.ids.push_back(cell.ID);
25  cl.tots.push_back(cell.TOT);
26  if (cell.LVL1 < cl.lvl1min)
27  cl.lvl1min = cell.LVL1;
28 }
29 
31 {
32  ATH_MSG_DEBUG("Initializing " << name() << " ...");
33  ATH_CHECK(m_pixelRDOTool.retrieve());
35  if (not m_chargeDataKey.empty()) ATH_CHECK(m_pixelReadout.retrieve());
36 
38 
39  ATH_MSG_DEBUG(name() << " successfully initialized");
40  return StatusCode::SUCCESS;
41 }
42 
44  const std::string& type, const std::string& name, const IInterface* parent)
45  : base_class(type,name,parent)
46 {}
47 
49 PixelClusteringTool::makeCluster(const EventContext& ctx,
50  const PixelClusteringTool::Cluster &cluster,
51  const PixelID& pixelID,
52  const InDetDD::SiDetectorElement* element,
53  xAOD::PixelCluster& xaodcluster) const
54 {
55  const PixelChargeCalibCondData *calibData = nullptr;
56  if (not m_chargeDataKey.empty()) {
58  calibData = calibDataHandle.cptr();
59  }
60 
61  const InDetDD::PixelModuleDesign& design =
62  dynamic_cast<const InDetDD::PixelModuleDesign&>(element->design());
63 
64  InDetDD::SiLocalPosition pos_acc(0,0);
65  int tot_acc = 0;
66 
67  std::vector<float> chargeList;
68  if (calibData) chargeList.reserve(cluster.ids.size());
69 
70  int colmax = std::numeric_limits<int>::min();
71  int rowmax = std::numeric_limits<int>::min();
72  int colmin = std::numeric_limits<int>::max();
73  int rowmin = std::numeric_limits<int>::max();
74 
75  float qRowMin = 0.f;
76  float qRowMax = 0.f;
77  float qColMin = 0.f;
78  float qColMax = 0.f;
79 
80  bool hasGanged = false;
81 
82  for (size_t i = 0; i < cluster.ids.size(); i++) {
83  Identifier id = cluster.ids.at(i);
84  hasGanged = hasGanged ||
85  m_pixelRDOTool->isGanged(id, element).has_value();
86 
87  int tot = cluster.tots.at(i);
88  float charge = tot;
89 
90  if (calibData) {
91  Identifier moduleID = pixelID.wafer_id(id);
92  IdentifierHash moduleHash = pixelID.wafer_hash(moduleID);
93  charge = calibData->getCharge(m_pixelReadout->getDiodeType(id),
94  moduleHash,
95  m_pixelReadout->getFE(id, moduleID),
96  tot);
97 
98  // These numbers are taken from the Cluster Maker Tool
99  if (design.getReadoutTechnology() != InDetDD::PixelReadoutTechnology::RD53 && (moduleHash < 12 or moduleHash > 2035)) {
100  charge = tot/8.0*(8000.0-1200.0)+1200.0;
101  }
102  chargeList.push_back(charge);
103  }
104 
105  const int row = pixelID.phi_index(id);
106  if (row > rowmax) {
107  rowmax = row;
108  qRowMax = charge;
109  } else if (row == rowmax) {
110  qRowMax += charge;
111  }
112 
113  if (row < rowmin) {
114  rowmin = row;
115  qRowMin = charge;
116  } else if (row == rowmin) {
117  qRowMin += charge;
118  }
119 
120  const int col = pixelID.eta_index(id);
121  if (col > colmax) {
122  colmax = col;
123  qColMax = charge;
124  } else if (col == colmax) {
125  qColMax += charge;
126  }
127 
128  if (col < colmin) {
129  colmin = col;
130  qColMin = charge;
131  } else if (col == colmin) {
132  qColMin += charge;
133  }
134 
135  InDetDD::SiCellId si_cell = element->cellIdFromIdentifier(id);
137 
138  if (m_useWeightedPos) {
139  pos_acc += tot * pos;
140  tot_acc += tot;
141  } else {
142  pos_acc += pos;
143  tot_acc += 1;
144  }
145  }
146 
147  if (tot_acc > 0)
148  pos_acc /= tot_acc;
149 
150  // Compute omega for charge interpolation correction (if required)
151  // Two pixels may have charge=0 (very rarely, hopefully)
152  float omegax = -1.f;
153  float omegay = -1.f;
154  if(qRowMin + qRowMax > 0) omegax = qRowMax/(qRowMin + qRowMax);
155  if(qColMin + qColMax > 0) omegay = qColMax/(qColMin + qColMax);
156 
157 
158  const int colWidth = colmax - colmin + 1;
159  const int rowWidth = rowmax - rowmin + 1;
160  double etaWidth = design.widthFromColumnRange(colmin, colmax);
161  double phiWidth = design.widthFromRowRange(rowmin, rowmax);
162  InDet::SiWidth siWidth(Amg::Vector2D(rowWidth,colWidth), Amg::Vector2D(phiWidth,etaWidth));
163 
164  // ask for Lorentz correction, get global position
165  double shift = m_pixelLorentzAngleTool->getLorentzShift(element->identifyHash());
166  const Amg::Vector2D localPos = pos_acc;
167  Amg::Vector2D locpos(localPos[Trk::locX]+shift, localPos[Trk::locY]);
168  // find global position of element
169  const Amg::Transform3D& T = element->surface().transform();
170  double Ax[3] = {T(0,0),T(1,0),T(2,0)};
171  double Ay[3] = {T(0,1),T(1,1),T(2,1)};
172  double R [3] = {T(0,3),T(1,3),T(2,3)};
173 
174  const Amg::Vector2D& M = locpos;
175  Amg::Vector3D globalPos(M[0]*Ax[0]+M[1]*Ay[0]+R[0],M[0]*Ax[1]+M[1]*Ay[1]+R[1],M[0]*Ax[2]+M[1]*Ay[2]+R[2]);
176 
177  // Compute error matrix
178  float width0, width1;
179  if (m_broadErrors) {
180  // Use cluster width
181  width0 = siWidth.phiR();
182  width1 = siWidth.z();
183  } else {
184  // Use pixel width
185  width0 = siWidth.phiR() / siWidth.colRow().x();
186  width1 = siWidth.z() / siWidth.colRow().y();
187  }
188 
189  auto errorMatrix = Amg::MatrixX(2,2);
190  errorMatrix.setIdentity();
191  // Assume uniform distribution
192  errorMatrix.fillSymmetric(0,0, width0 * width0 / 12.0);
193  errorMatrix.fillSymmetric(1,1, width1 * width1 / 12.0);
194 
195  // Actually create the cluster (i.e. fill the values)
196  IdentifierHash idHash = element->identifyHash();
197 
198  Eigen::Matrix<float,2,1> localPosition(locpos.x(), locpos.y());
199  Eigen::Matrix<float,2,2> localCovariance = Eigen::Matrix<float,2,2>::Zero();
200  localCovariance(0, 0) = errorMatrix(0, 0);
201  localCovariance(1, 1) = errorMatrix(1, 1);
202 
203  xaodcluster.setMeasurement<2>(idHash, localPosition, localCovariance);
204  xaodcluster.setIdentifier( element->identifierOfPosition(locpos).get_compact() );
205  xaodcluster.setRDOlist(cluster.ids);
206  xaodcluster.globalPosition() = globalPos.cast<float>();
207  xaodcluster.setToTlist(cluster.tots);
209  xaodcluster.setChargelist(chargeList);
211  xaodcluster.setLVL1A(cluster.lvl1min);
212  xaodcluster.setChannelsInPhiEta(siWidth.colRow()[0],
213  siWidth.colRow()[1]);
214  xaodcluster.setWidthInEta(static_cast<float>(siWidth.widthPhiRZ()[1]));
215  xaodcluster.setOmegas(omegax, omegay);
216  xaodcluster.setIsSplit(false);
217  xaodcluster.setSplitProbabilities(0.0, 0.0);
218 
219  return StatusCode::SUCCESS;
220 }
221 
222 
224 PixelClusteringTool::clusterize(const RawDataCollection& RDOs,
225  const PixelID& pixelID,
226  const EventContext& ctx,
227  ClusterContainer& container) const
228 {
229  const InDetDD::SiDetectorElement* element = m_pixelRDOTool->checkCollection(RDOs, ctx);
230  if (element == nullptr)
231  return StatusCode::FAILURE;
232 
233  std::vector<InDet::UnpackedPixelRDO> cells =
234  m_pixelRDOTool->getUnpackedPixelRDOs(RDOs, pixelID, element, ctx);
235 
237  Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>
238  (cells, Acts::Ccl::DefaultConnect<Cell, 2>(m_addCorners));
239 
240  std::size_t previousSizeContainer = container.size();
241  // Fast insertion trick
242  std::vector<xAOD::PixelCluster*> toAddCollection;
243  toAddCollection.reserve(clusters.size());
244  for (std::size_t i(0); i<clusters.size(); ++i)
245  toAddCollection.push_back(new xAOD::PixelCluster());
246  container.insert(container.end(), toAddCollection.begin(), toAddCollection.end());
247 
248  for (std::size_t i(0); i<clusters.size(); ++i) {
249  const Cluster& cluster = clusters[i];
250  ATH_CHECK(makeCluster(ctx, cluster, pixelID, element, *container[previousSizeContainer+i]));
251  }
252 
253  return StatusCode::SUCCESS;
254 }
255 
256 } // namespace ActsTrk
ActsTrk::PixelClusteringTool::m_broadErrors
Gaudi::Property< bool > m_broadErrors
Definition: PixelClusteringTool.h:96
InDetDD::SolidStateDetectorElementBase::identifierOfPosition
Identifier identifierOfPosition(const Amg::Vector2D &localPos) const
Full identifier of the cell for a given position: assumes a raw local position (no Lorentz shift)
Definition: SolidStateDetectorElementBase.cxx:217
query_example.row
row
Definition: query_example.py:24
ActsTrk::PixelClusteringTool::Cluster::tots
std::vector< int > tots
Definition: PixelClusteringTool.h:58
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
xAOD::PixelCluster_v1::setTotalCharge
void setTotalCharge(float totalCharge)
Sets the total charge.
PixelID::phi_index
int phi_index(const Identifier &id) const
Definition: PixelID.h:658
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
max
#define max(a, b)
Definition: cfImp.cxx:41
ActsTrk::PixelClusteringTool::m_pixelLorentzAngleTool
ToolHandle< ISiLorentzAngleTool > m_pixelLorentzAngleTool
Definition: PixelClusteringTool.h:89
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Trk::locX
@ locX
Definition: ParamDefs.h:43
InDetDD::PixelModuleDesign::widthFromRowRange
double widthFromRowRange(const int rowMin, const int rowMax) const
Method to calculate phi width from a row range.
Definition: PixelModuleDesign.cxx:144
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:48
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:44
PixelClusteringTool.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
InDet::SiWidth::widthPhiRZ
const Amg::Vector2D & widthPhiRZ() const
Definition: SiWidth.h:121
ActsTrk::clusterAddCell
void clusterAddCell(PixelClusteringTool::Cluster &cl, const PixelClusteringTool::Cell &cell)
Definition: PixelClusteringTool.cxx:21
xAOD::xAODInDetMeasurement::Utilities::computeTotalToT
int computeTotalToT(const SG::AuxElement &cluster)
Definition: Event/xAOD/xAODInDetMeasurement/Root/Utilities.cxx:22
InDetDD::SolidStateDetectorElementBase::surface
Trk::Surface & surface()
Element Surface.
xAOD::PixelCluster_v1::setRDOlist
void setRDOlist(const std::vector< Identifier > &rdolist)
Sets the list of identifiers of the channels building the cluster.
Definition: PixelCluster_v1.cxx:25
xAOD::PixelCluster_v1::setChargelist
void setChargelist(const std::vector< float > &charges)
Sets the list of charges of the channels building the cluster.
xAOD::PixelCluster_v1::setIsSplit
void setIsSplit(bool isSplit)
Sets if the cluster is split or not.
xAOD::PixelCluster_v1::setWidthInEta
void setWidthInEta(float widthInEta)
Sets the width of the cluster in eta (y) direction.
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
ActsTrk::PixelClusteringTool::m_useWeightedPos
Gaudi::Property< bool > m_useWeightedPos
Definition: PixelClusteringTool.h:95
xAOD::PixelCluster_v1::setTotalToT
void setTotalToT(int totalToT)
Sets the total ToT.
InDetDD::SolidStateDetectorElementBase::identifyHash
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
ActsTrk::PixelClusteringTool::m_addCorners
Gaudi::Property< bool > m_addCorners
Definition: PixelClusteringTool.h:94
InDetDD::PixelReadoutTechnology::RD53
@ RD53
xAOD::PixelCluster_v1::setSplitProbabilities
void setSplitProbabilities(float prob1, float prob2)
Sets the splitting probabilities for the cluster.
InDetDD::SiLocalPosition
Definition: SiLocalPosition.h:31
ActsTrk::PixelClusteringTool::m_chargeDataKey
SG::ReadCondHandleKey< PixelChargeCalibCondData > m_chargeDataKey
Definition: PixelClusteringTool.h:91
ActsTrk::PixelClusteringTool::PixelClusteringTool
PixelClusteringTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: PixelClusteringTool.cxx:43
xAOD::UncalibratedMeasurement_v1::setIdentifier
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
InDetDD::SiDetectorElement::cellIdFromIdentifier
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
Definition: SiDetectorElement.cxx:120
ActsTrk::PixelClusteringTool::m_pixelReadout
ServiceHandle< InDetDD::IPixelReadoutManager > m_pixelReadout
Definition: PixelClusteringTool.h:85
InDetDD::PixelModuleDesign::widthFromColumnRange
double widthFromColumnRange(const int colMin, const int colMax) const
Method to calculate eta width from a column range.
Definition: PixelModuleDesign.cxx:132
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:387
PixelClusterAuxContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
ActsTrk::PixelClusteringTool::initialize
virtual StatusCode initialize() override
Definition: PixelClusteringTool.cxx:30
PixelChargeCalibCondData
Definition: PixelChargeCalibCondData.h:24
PixelClusterContainer.h
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
InDetDD::PixelModuleDesign::localPositionOfCell
virtual SiLocalPosition localPositionOfCell(const SiCellId &cellId) const
readout or diode id -> position.
Definition: PixelModuleDesign.cxx:85
xAOD::PixelCluster_v1::setToTlist
void setToTlist(const std::vector< int > &tots)
Sets the list of ToT of the channels building the cluster.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PixelCluster.h
PixelID::eta_index
int eta_index(const Identifier &id) const
Definition: PixelID.h:664
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.SystemOfUnits.micrometer
int micrometer
Definition: SystemOfUnits.py:71
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
min
#define min(a, b)
Definition: cfImp.cxx:40
xAOD::PixelCluster_v1::setLVL1A
void setLVL1A(int lvl1a)
Sets the LVL1 accept.
xAOD::xAODInDetMeasurement::Utilities::computeTotalCharge
float computeTotalCharge(const SG::AuxElement &cluster)
Definition: Event/xAOD/xAODInDetMeasurement/Root/Utilities.cxx:9
ActsTrk::PixelClusteringTool::clusterize
virtual StatusCode clusterize(const InDetRawDataCollection< PixelRDORawData > &RDOs, const PixelID &pixelID, const EventContext &ctx, xAOD::PixelClusterContainer &container) const override
Definition: PixelClusteringTool.cxx:224
Utilities.h
ActsTrk::PixelClusteringTool::Cluster
Definition: PixelClusteringTool.h:56
xAOD::PixelCluster_v1::globalPosition
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the pixel cluster.
Definition: PixelCluster_v1.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::PixelClusteringTool::Cluster::lvl1min
int lvl1min
Definition: PixelClusteringTool.h:59
charge
double charge(const T &p)
Definition: AtlasPID.h:494
xAOD::PixelCluster_v1::setOmegas
void setOmegas(float omegax, float omegay)
Sets omegax and omegay, i.e.
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
InDetDD::PixelModuleDesign::getReadoutTechnology
PixelReadoutTechnology getReadoutTechnology() const
Definition: PixelModuleDesign.h:368
query_example.col
col
Definition: query_example.py:7
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
InDetDD::SiCellId
Definition: SiCellId.h:29
xAOD::PixelCluster_v1
Definition: PixelCluster_v1.h:17
xAOD::UncalibratedMeasurement_v1::setMeasurement
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
ActsTrk::PixelClusteringTool::ClusterCollection
std::vector< Cluster > ClusterCollection
Definition: PixelClusteringTool.h:62
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
InDet::UnpackedPixelRDO
Definition: PixelRDOTool.h:31
PixelModuleDesign.h
xAOD::PixelCluster_v1::setChannelsInPhiEta
void setChannelsInPhiEta(int channelsInPhi, int channelsInEta)
Sets the dimensions of the cluster in numbers of channels in phi (x) and eta (y) directions.
Definition: PixelCluster_v1.cxx:46
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::phiWidth
phiWidth
Definition: RingSetConf_v1.cxx:612
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
ActsTrk::PixelClusteringTool::m_pixelRDOTool
ToolHandle< InDet::PixelRDOTool > m_pixelRDOTool
Definition: PixelClusteringTool.h:88
InDet::SiWidth
Definition: SiWidth.h:25
InDet::SiWidth::colRow
const Amg::Vector2D & colRow() const
Definition: SiWidth.h:115
ActsTrk::PixelClusteringTool::makeCluster
StatusCode makeCluster(const EventContext &ctx, const PixelClusteringTool::Cluster &cluster, const PixelID &pixelID, const InDetDD::SiDetectorElement *element, xAOD::PixelCluster &container) const
Definition: PixelClusteringTool.cxx:49
PixelChargeCalibCondData::getCharge
float getCharge(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE, float ToT) const
Definition: PixelChargeCalibCondData.cxx:190
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:34
InDet::SiWidth::phiR
double phiR() const
Definition: SiWidth.h:126
ActsTrk::PixelClusteringTool::Cluster::ids
std::vector< Identifier > ids
Definition: PixelClusteringTool.h:57
IdentifierHash
Definition: IdentifierHash.h:38
InDetDD::SiDetectorElement::design
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
PixelID
Definition: PixelID.h:67
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
InDet::SiWidth::z
double z() const
Definition: SiWidth.h:131
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67