ATLAS Offline Software
SimpleSTgcClusterBuilderTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 
12 using namespace Muon;
13 
14 //============================================================================
15 Muon::SimpleSTgcClusterBuilderTool::SimpleSTgcClusterBuilderTool(const std::string& t, const std::string& n, const IInterface* p)
16 : AthAlgTool(t,n,p) {}
17 
18 
19 //============================================================================
21  ATH_CHECK( m_idHelperSvc.retrieve() );
22  ATH_CHECK(m_uncertCalibKey.initialize());
23  return StatusCode::SUCCESS;
24 }
25 
26 
27 //============================================================================
28 // Build the clusters given a vector of single-hit PRD
30  std::vector<Muon::sTgcPrepData>&& stripsVect,
31  std::vector<std::unique_ptr<Muon::sTgcPrepData>>& clustersVect) const {
32 
33  ATH_MSG_DEBUG("Size of the input vector: " << stripsVect.size());
34 
35  if (stripsVect.empty()) return StatusCode::SUCCESS;
36 
37 
38  // define the identifier hash
39  Identifier chanId = stripsVect.at(0).identify();
40  IdentifierHash hash = m_idHelperSvc->moduleHash(chanId);
41 
42  double resolution = Amg::error(stripsVect.at(0).localCovariance(), Trk::locX);
43  bool isStrip = ( m_idHelperSvc->stgcIdHelper().channelType(chanId) == sTgcIdHelper::Strip );
44  ATH_MSG_DEBUG(" channelType " << m_idHelperSvc->stgcIdHelper().channelType(chanId));
45  ATH_MSG_DEBUG(" isStrip: " << isStrip << "Single channel resolution: " << resolution);
46 
47  SG::ReadCondHandle<NswErrorCalibData> errorCalibDB{m_uncertCalibKey, ctx};
48  if (!errorCalibDB.isValid()) {
49  ATH_MSG_FATAL("Failed to retrieve the parameterized errors "<<m_uncertCalibKey.fullKey());
50  return StatusCode::FAILURE;
51  }
52 
53  Muon::STgcClusterBuilderCommon stgcClusterCommon(m_idHelperSvc->stgcIdHelper(), **errorCalibDB);
54  std::array<std::vector<Muon::sTgcPrepData>, 8> stgcPrdsPerLayer = stgcClusterCommon.sortSTGCPrdPerLayer(std::move(stripsVect));
55 
56  for (std::vector<Muon::sTgcPrepData>& layPrds : stgcPrdsPerLayer) {
57  // Get the strip clusters of the layer.
58  std::vector<std::vector<Muon::sTgcPrepData>> layerClusters = stgcClusterCommon.findStripCluster(std::move(layPrds),
59  m_maxHoleSize);
60 
61  // Loop on the clusters of that gap
62  for (const std::vector<Muon::sTgcPrepData>& cluster: layerClusters) {
63  if (cluster.empty()) continue;
64 
65  // Calculate the cluster position and error using the weighted average
66  std::optional<Muon::STgcClusterPosition> optClusterPos = stgcClusterCommon.weightedAverage(cluster, resolution, isStrip);
67  if (!optClusterPos) {
68  if (msgLvl(MSG::VERBOSE)) {
69  std::stringstream sstr{};
70  for (const Muon::sTgcPrepData& prd : cluster) {
71  sstr << m_idHelperSvc->toString(prd.identify())
72  << ", local pos: "<< Amg::toString(prd.localPosition(), 2)
73  << "), charge: " << prd.charge() << ", time: " << static_cast<int>(prd.time())
74  << std::endl;
75  }
76  ATH_MSG_VERBOSE("Reject invalid cluster..." << std::endl << std::endl << sstr.str());
77  }
78  continue;
79  }
80 
81  Identifier clusterId = (*optClusterPos).getClusterId();
82  double posY = cluster[0].localPosition().y();
83  Amg::Vector2D localPosition((*optClusterPos).getMeanPosition(), posY);
84  auto covN = Amg::MatrixX(1,1);
85  covN(0,0) = (*optClusterPos).getErrorSquared();
86 
87  std::vector<Identifier> rdoList;
88  std::vector<int> elementsCharge;
89  std::vector<short int> elementsTime;
90  std::vector<uint16_t> elementsChannel;
91  for (const Muon::sTgcPrepData& prd : cluster ) {
92  rdoList.push_back(prd.identify());
93  elementsCharge.push_back(prd.charge());
94  elementsChannel.push_back(m_idHelperSvc->stgcIdHelper().channel(prd.identify()));
95  elementsTime.push_back(prd.time());
96  }
97 
98  // memory allocated dynamically for the PrepRawData is managed by Event Store in the converters
99  ATH_MSG_DEBUG("error on cluster " << std::sqrt((covN)(0,0)));
100 
101  std::unique_ptr<sTgcPrepData> prdN = std::make_unique<sTgcPrepData>(
102  clusterId,
103  hash,
104  std::move(localPosition),
105  std::move(rdoList),
106  std::move(covN),
107  cluster.at(0).detectorElement(),
108  std::accumulate(elementsCharge.begin(), elementsCharge.end(), 0),
109  (short int)0,
110  std::move(elementsChannel),
111  std::move(elementsTime),
112  std::move(elementsCharge));
113 
115  clustersVect.push_back(std::move(prdN));
116  }
117  }
118 
119  ATH_MSG_DEBUG("Size of the output cluster vector: " << clustersVect.size());
120 
121  return StatusCode::SUCCESS;
122 }
123 
124 
125 //============================================================================
127 void SimpleSTgcClusterBuilderTool::dumpStrips(std::vector<Muon::sTgcPrepData>& stripsVect, std::vector<Muon::sTgcPrepData*>& clustersVect ) const {
128  ATH_MSG_INFO("====> Dumping all strips: ");
129  for ( const auto& it : stripsVect ) {
130  Identifier stripId = it.identify();
131  ATH_MSG_INFO("Strip identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(stripId) );
132  }
133 
134  ATH_MSG_INFO("Dumping all clusters: ");
135  for ( auto *it : clustersVect ) {
136  Identifier clusterId = it->identify();
137  ATH_MSG_INFO("***> New cluster identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(clusterId) );
138  ATH_MSG_INFO("Cluster size: " << it->rdoList().size() );
139  ATH_MSG_INFO("List of associated RDO's: ");
140  }
141 }
Muon::sTgcPrepData::setAuthor
void setAuthor(const Author a)
Definition: sTgcPrepData.h:116
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::locX
@ locX
Definition: ParamDefs.h:37
Muon::STgcClusterBuilderCommon::sortSTGCPrdPerLayer
std::array< std::vector< sTgcPrepData >, 8 > sortSTGCPrdPerLayer(std::vector< sTgcPrepData > &&stripPrds) const
Separate the sTGC PRDs by layer, from 0 to 7, and sort the PRDs per layer in ascending order of strip...
Definition: STgcClusterBuilderCommon.cxx:20
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
EventPrimitivesHelpers.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
sTgcIdHelper::Strip
@ Strip
Definition: sTgcIdHelper.h:190
Muon::STgcClusterBuilderCommon
Definition: STgcClusterBuilderCommon.h:30
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Dedxcorrection::resolution
double resolution[nGasTypes][nParametersResolution]
Definition: TRT_ToT_Corrections.h:46
sTgcPrepData.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
beamspotman.n
n
Definition: beamspotman.py:731
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::STgcClusterBuilderCommon::weightedAverage
std::optional< STgcClusterPosition > weightedAverage(const std::vector< sTgcPrepData > &cluster, const double resolution, bool isStrip) const
Compute the cluster position using the weighted average method.
Definition: STgcClusterBuilderCommon.cxx:83
Muon::SimpleSTgcClusterBuilderTool::dumpStrips
void dumpStrips(std::vector< Muon::sTgcPrepData > &stripsVect, std::vector< Muon::sTgcPrepData * > &clustersVect) const
private functions
Definition: SimpleSTgcClusterBuilderTool.cxx:127
Muon::SimpleSTgcClusterBuilderTool::SimpleSTgcClusterBuilderTool
SimpleSTgcClusterBuilderTool(const std::string &, const std::string &, const IInterface *)
Default constructor.
Definition: SimpleSTgcClusterBuilderTool.cxx:15
dumpTgcDigiThreshold.isStrip
list isStrip
Definition: dumpTgcDigiThreshold.py:33
Amg::error
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Definition: EventPrimitivesHelpers.h:40
Muon::sTgcPrepData::Author::SimpleClusterBuilder
@ SimpleClusterBuilder
Muon::SimpleSTgcClusterBuilderTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: SimpleSTgcClusterBuilderTool.h:49
Muon::SimpleSTgcClusterBuilderTool::initialize
virtual StatusCode initialize() override
standard initialize method
Definition: SimpleSTgcClusterBuilderTool.cxx:20
beamspotman.posY
posY
Definition: beamspotman.py:1624
Muon::SimpleSTgcClusterBuilderTool::getClusters
StatusCode getClusters(const EventContext &ctx, std::vector< Muon::sTgcPrepData > &&stripsVect, std::vector< std::unique_ptr< Muon::sTgcPrepData >> &clustersVect) const override
Definition: SimpleSTgcClusterBuilderTool.cxx:29
STgcClusterBuilderCommon.h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
GeoPrimitivesToStringConverter.h
SimpleSTgcClusterBuilderTool.h
Muon::STgcClusterBuilderCommon::findStripCluster
std::vector< std::vector< sTgcPrepData > > findStripCluster(std::vector< sTgcPrepData > &&strips, const int maxMissingStrip) const
Find strip clusters, assuming the input vector of PRDs are sorted in ascending order of strip number.
Definition: STgcClusterBuilderCommon.cxx:44
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
AthAlgTool
Definition: AthAlgTool.h:26
Muon::sTgcPrepData
Class to represent sTgc measurements.
Definition: sTgcPrepData.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14