ATLAS Offline Software
Loading...
Searching...
No Matches
CaruanaSTgcClusterBuilderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12using namespace Muon;
13
14Muon::CaruanaSTgcClusterBuilderTool::CaruanaSTgcClusterBuilderTool(const std::string& t, const std::string& n, const IInterface* p) :
15 AthAlgTool(t,n,p)
16{
17}
18
20{
21 ATH_CHECK( m_idHelperSvc.retrieve() );
22 ATH_CHECK(m_DetectorManagerKey.initialize());
23 ATH_CHECK(m_uncertCalibKey.initialize());
24 return StatusCode::SUCCESS;
25}
26
27//
28// Build the clusters given a vector of single-hit PRD
29//
30StatusCode Muon::CaruanaSTgcClusterBuilderTool::getClusters(const EventContext& ctx,
31 std::vector<Muon::sTgcPrepData>&& stripsVect,
32 std::vector<std::unique_ptr<Muon::sTgcPrepData>>& clustersVect) const
33{
34
35 ATH_MSG_DEBUG("Size of the input vector: " << stripsVect.size());
36
37 if (stripsVect.empty()) {
38 ATH_MSG_DEBUG("Size of the channel vectors is zero");
39 return StatusCode::SUCCESS;
40 }
41
43 if (!errorCalibDB.isValid()) {
44 ATH_MSG_FATAL("Failed to retrieve the parameterized errors "<<m_uncertCalibKey.fullKey());
45 return StatusCode::FAILURE;
46 }
47
48 Muon::STgcClusterBuilderCommon stgcClusterCommon(m_idHelperSvc->stgcIdHelper(), **errorCalibDB);
49
50 // define the identifier hash
51 Identifier chanId = stripsVect.at(0).identify();
52 IdentifierHash hash = m_idHelperSvc->moduleHash(chanId);
53
54 int channelType = m_idHelperSvc->stgcIdHelper().channelType(stripsVect.at(0).identify());
55 double resolution = Amg::error(stripsVect.at(0).localCovariance(), Trk::locX);
56 ATH_MSG_DEBUG("ChannelType: " << channelType << " Single channel resolution: " << resolution);
57
58 // Separate hits by layer (using index = 0 to 7) and sort them
59 std::array<std::vector<Muon::sTgcPrepData>, 8> stgcPrdsPerLayer = stgcClusterCommon.sortSTGCPrdPerLayer(std::move(stripsVect));
60
62 if(!detManager.isValid()){
63 ATH_MSG_ERROR("Null pointer to the read MuonDetectorManager conditions object");
64 return StatusCode::FAILURE;
65 }
66
67 // Loop over the 8 layers, from 0 to 7
68 for (std::vector<sTgcPrepData>& unmerged : stgcPrdsPerLayer) {
69 // Get the strip clusters of the layer.
70 std::vector<std::vector<Muon::sTgcPrepData>> layerClusters = stgcClusterCommon.findStripCluster(std::move(unmerged),
72
73 // Loop over the clusters of that gap
74 for (std::vector<Muon::sTgcPrepData>& cluster: layerClusters) {
76 std::vector<Identifier> rdoList;
77 //vectors to hold the properties of the elements of a cluster
78 std::vector<int> elementsCharge;
79 std::vector<short int> elementsTime;
80 std::vector<uint16_t> elementsChannel;
81 std::vector<double> elementsLocalPositions;
82 std::vector<Identifier> elementsIdentifier;
83 double posY = (cluster.at(0)).localPosition().y();
84
85 // loop on the strips and set the cluster weighted position and charge
86 for (const sTgcPrepData& it : cluster ){
87 rdoList.push_back(it.identify());
88 elementsCharge.push_back(it.charge());
89 elementsChannel.push_back(m_idHelperSvc->stgcIdHelper().channel(it.identify()));
90 elementsTime.push_back(it.time());
91 elementsLocalPositions.push_back(it.localPosition().x());
92 elementsIdentifier.push_back(it.identify());
93 }
94
95 // Use the Caruana method to reconstruct clusters, determining the cluster mean position and error.
96 // If the Caruana method fails at some point, the reconstruction reverts to the weighted average method.
97 Identifier clusterId;
98 double reconstructedPosX{0};
99 double sigmaSq{0};
100 std::optional<Muon::STgcClusterPosition> optStripCluster = stgcClusterCommon.caruanaGaussianFitting(cluster,
103 detManager.cptr());
104 if (optStripCluster.has_value()) {
105 clusterId = (*optStripCluster).getClusterId();
106 reconstructedPosX = (*optStripCluster).getMeanPosition();
107 sigmaSq = (*optStripCluster).getErrorSquared();
109 } else {
110 ATH_MSG_DEBUG("sTGC cluster reconstruction using the Caruana method failed, reversing to the weighted average");
111
112 // Fallback to the weighted average when the Caruana method fails
113 bool isStrip = (channelType == sTgcIdHelper::sTgcChannelTypes::Strip);
114 // Calculate the cluster position and error using the weighted average
115 std::optional<Muon::STgcClusterPosition> optClusterWA = stgcClusterCommon.weightedAverage(cluster, resolution, isStrip);
116 // Skip the cluster if the weighted average also fails
117 if (!optClusterWA) {
118 if (msgLvl(MSG::VERBOSE)) {
119 std::stringstream sstr{};
120 for (const Muon::sTgcPrepData& prd : cluster) {
121 sstr << m_idHelperSvc->stgcIdHelper().print_to_string(prd.identify())
122 << ", local pos: ("<< prd.localPosition().x() << "," << prd.localPosition().y()
123 << "), charge: " << prd.charge() << ", time: " << static_cast<int>(prd.time())
124 << std::endl;
125 }
126 ATH_MSG_VERBOSE("Reject invalid cluster..." << std::endl << std::endl << sstr.str());
127 }
128 continue;
129 }
131
132 clusterId = (*optClusterWA).getClusterId();
133 reconstructedPosX = (*optClusterWA).getMeanPosition();
134 sigmaSq = (*optClusterWA).getErrorSquared();
135 }
136
137 Amg::Vector2D localPosition(reconstructedPosX,posY);
138 auto covN = Amg::MatrixX(1,1);
139 covN(0,0) = sigmaSq;
140 ATH_MSG_DEBUG("Reconstructed a cluster at mean local position: "<< Amg::toString(localPosition,2)
141 << " with error on cluster: " << std::sqrt((covN)(0,0)));
142
143 std::unique_ptr<sTgcPrepData> prdN = std::make_unique<sTgcPrepData>(clusterId,
144 hash,
145 std::move(localPosition),
146 std::move(rdoList),
147 std::move(covN),
148 cluster.at(0).detectorElement(),
149 std::accumulate(elementsCharge.begin(), elementsCharge.end(), 0),
150 (short int)0,
151 std::move(elementsChannel),
152 std::move(elementsTime),
153 std::move(elementsCharge));
154 prdN->setAuthor(author);
155 clustersVect.push_back(std::move(prdN));
156 }
157 }
158
159 ATH_MSG_DEBUG("Size of the output cluster vector: " << clustersVect.size());
160
161 return StatusCode::SUCCESS;
162}
163
164
166void CaruanaSTgcClusterBuilderTool::dumpStrips( std::vector<Muon::sTgcPrepData>& stripsVect,
167 std::vector<Muon::sTgcPrepData*>& clustersVect ) const
168{
169
170 ATH_MSG_INFO("====> Dumping all strips: ");
171 for ( const auto& it : stripsVect ) {
172 Identifier stripId = it.identify();
173 ATH_MSG_INFO("Strip identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(stripId) );
174 }
175
176 ATH_MSG_INFO("Dumping all clusters: ");
177 for ( auto *it : clustersVect ) {
178 Identifier clusterId = it->identify();
179 ATH_MSG_INFO("***> New cluster identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(clusterId) );
180 ATH_MSG_INFO("Cluster size: " << it->rdoList().size() );
181 ATH_MSG_INFO("List of associated RDO's: ");
182
183 }
184
185 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
This is a "hash" representation of an Identifier.
SG::ReadCondHandleKey< NswErrorCalibData > m_uncertCalibKey
Gaudi::Property< unsigned int > m_maxHoleSize
CaruanaSTgcClusterBuilderTool(const std::string &, const std::string &, const IInterface *)
Default constructor.
virtual StatusCode initialize()
standard initialize method
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
StatusCode getClusters(const EventContext &ctx, std::vector< Muon::sTgcPrepData > &&stripsVect, std::vector< std::unique_ptr< Muon::sTgcPrepData > > &clustersVect) const
void dumpStrips(std::vector< Muon::sTgcPrepData > &stripsVect, std::vector< Muon::sTgcPrepData * > &clustersVect) const
private functions
std::optional< STgcClusterPosition > weightedAverage(const std::vector< sTgcPrepData > &cluster, const double resolution, bool isStrip) const
Compute the cluster position using the weighted average method.
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...
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.
std::optional< STgcClusterPosition > caruanaGaussianFitting(const std::vector< sTgcPrepData > &cluster, const double positionResolution, const double angularResolution, const MuonGM::MuonDetectorManager *detManager) const
Method to fit analytically a cluster to a Gaussian function to obtain the position of the cluster The...
Class to represent sTgc measurements.
const_pointer_type cptr()
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
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 ...
Eigen::Matrix< double, 2, 1 > Vector2D
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
@ locX
Definition ParamDefs.h:37