19 std::atomic<bool> hitNegativeCharge{
false};
32 ATH_CHECK(m_stgcPrepDataContainerKey.initialize());
33 ATH_CHECK(m_rdoContainerKey.initialize());
36 ATH_CHECK(m_prdContainerCacheKey.initialize(!m_prdContainerCacheKey.key().empty()) );
42 ATH_CHECK(m_xAODStripKey.initialize(!m_xAODStripKey.empty()));
43 ATH_CHECK(m_xAODWireKey.initialize(!m_xAODWireKey.empty()));
44 ATH_CHECK(m_xAODPadKey.initialize(!m_xAODPadKey.empty()));
45 return StatusCode::SUCCESS;
54 const sTgcIdHelper& id_helper = m_idHelperSvc->stgcIdHelper();
57 ATH_MSG_DEBUG(
" ***************** Start of process STGC Collection with hash Id: " <<
hash);
59 auto stgcPrepDataContainer = xAODcontainers.
prd;
61 if ( stgcPrepDataContainer->indexFindPtr(
hash) !=
nullptr ) {
62 ATH_MSG_DEBUG(
"In processCollection: collection already contained in the sTGC PrepData container");
63 return StatusCode::FAILURE;
71 ATH_MSG_DEBUG(
"In processCollection: collection already available in the sTgc PrepData container (via cache)");
72 return StatusCode::SUCCESS;
76 std::unique_ptr<sTgcPrepDataCollection> prdColl = std::make_unique<sTgcPrepDataCollection>(
hash);
81 int getId = id_helper.
get_id(
hash, moduleId, &context);
89 std::vector<sTgcPrepData> sTgcStripPrds;
90 std::vector<sTgcPrepData> sTgcWirePrds;
91 std::vector<sTgcPrepData> sTgcPadPrds;
92 sTgcStripPrds.reserve(rdoColl->
size());
93 sTgcPadPrds.reserve(rdoColl->
size());
94 sTgcWirePrds.reserve(rdoColl->
size());
101 if(!muonDetMgr.isValid()){
102 ATH_MSG_ERROR(
"Null pointer to the read MuonDetectorManager conditions object");
103 return StatusCode::FAILURE;
110 const Identifier rdoId = rdo->identify();
112 if (!m_idHelperSvc->issTgc(rdoId)) {
113 ATH_MSG_WARNING(
"The given Identifier "<<rdoId.get_compact()<<
" ("<<m_idHelperSvc->toString(rdoId)<<
") is no sTGC Identifier, continuing");
117 std::vector<Identifier> rdoList;
118 rdoList.push_back(rdoId);
125 if (channelType < 0 || channelType > 2) {
127 return StatusCode::FAILURE;
131 if ( !getLocalPos ) {
132 ATH_MSG_ERROR(
"Could not get the local strip position for "<<m_idHelperSvc->toString(rdoId));
133 return StatusCode::FAILURE;
142 ATH_CHECK (m_calibTool->calibrateStrip(ctx, rdo, calibStrip));
143 int calibratedCharge =
static_cast<int>(calibStrip.
charge);
144 if (calibratedCharge < 0 && channelType == 1) {
145 if (!hitNegativeCharge) {
146 ATH_MSG_WARNING(
"One sTGC RDO or more, such as one with pdo = "<<rdo->charge() <<
" counts, corresponds to a negative charge (" << calibratedCharge <<
"). Skipping these RDOs");
147 hitNegativeCharge =
true;
153 if (channelType == sTgcIdHelper::sTgcChannelTypes::Pad) {
177 std::vector<sTgcPrepData>& sTgcPrds = channelType ==
sTgcIdHelper::Pad ? sTgcPadPrds :
181 auto it = std::find_if(sTgcPrds.begin(), sTgcPrds.end(), [&rdoId](
const sTgcPrepData& prd) {
182 return (prd.identify() == rdoId);
184 if (
it == sTgcPrds.end()) {
185 sTgcPrds.emplace_back(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
187 }
else if (
it->time() > calibStrip.
time) {
188 *
it =
sTgcPrepData(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
196 prdColl->
push_back(std::make_unique<sTgcPrepData>(rdoId,
209 std::vector<std::unique_ptr<Muon::sTgcPrepData>> sTgcStripClusters;
210 ATH_CHECK(m_clusterBuilderTool->getClusters(ctx, std::move(sTgcStripPrds), sTgcStripClusters));
212 for ( std::unique_ptr<Muon::sTgcPrepData>&
it : sTgcStripClusters ) {
218 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
222 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
225 const bool convertXAOD = !m_xAODPadKey.empty() || !m_xAODStripKey.empty() ||
226 !m_xAODWireKey.empty();
230 const Identifier prdId = prd->identify();
236 <<m_idHelperSvc->toString(prdId)<<
". "<<
Amg::toString(prd->localPosition())
237 <<
", cov: "<<prd->localCovariance()(0,0)
239 if (!m_xAODPadKey.empty() &&
chType == sTgcIdHelper::sTgcChannelTypes::Pad) {
240 outHit = xAODcontainers.
pad->push_back(std::make_unique<xAOD::sTgcPadHit>());
242 lCov(0,0) = prd->localCovariance()(0,0);
245 outHit->setMeasurement<2>(m_idHelperSvc->detElementHash(prdId),
248 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Wire && !m_xAODWireKey.empty()) {
249 outHit = xAODcontainers.
wire->push_back(std::make_unique<xAOD::sTgcWireHit>());
250 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Strip && !m_xAODStripKey.empty()) {
251 auto stripHit = xAODcontainers.
strip->push_back(std::make_unique<xAOD::sTgcStripCluster>());
252 stripHit->setStripCharges(prd->stripCharges());
253 stripHit->setStripNumbers(prd->stripNumbers());
254 stripHit->setStripTimes(prd->stripTimes());
260 if (
chType != sTgcIdHelper::sTgcChannelTypes::Pad){
263 lCov(0,0) = prd->localCovariance()(0,0);
264 outHit->setMeasurement<1>(m_idHelperSvc->detElementHash(prdId),
269 outHit->setChannelNumber(
channel);
270 outHit->setGasGap(
gasGap);
271 outHit->setAuthor(prd->author());
272 outHit->setTime(prd->time());
273 outHit->setCharge(prd->charge());
274 outHit->setIdentifier(prdId.get_compact());
276 outHit->setReadoutElement(m_detMgrR4->getsTgcReadoutElement(prdId));
286 return StatusCode::SUCCESS;
294 if(rdoContainerHandle.isValid()) {
296 return rdoContainerHandle.cptr();
307 const std::vector<IdentifierHash>& idsToDecode)
const
311 if (!rdoContainer)
return;
315 if (rdoColl->empty())
continue;
316 ATH_MSG_DEBUG(
"New RDO collection with " << rdoColl->size() <<
"STGC Hits");
318 const IdentifierHash
hash = rdoColl->identifyHash();
321 if(!idsToDecode.empty() and
std::find(idsToDecode.begin(), idsToDecode.end(),
hash)==idsToDecode.end()) {
326 if(processCollection(ctx, xAODcontainers, rdoColl).isFailure()) {
327 ATH_MSG_DEBUG(
"processCsm returns a bad StatusCode - keep going for new data collections in this event");
335 const std::vector<IdentifierHash>& idVect)
const {
336 ATH_MSG_DEBUG(
"Size of the input hash id vector: " << idVect.size());
339 if (!outCache.
isValid)
return StatusCode::FAILURE;
341 processRDOContainer(ctx, outCache, idVect);
342 return StatusCode::SUCCESS;
349 return StatusCode::FAILURE;
352 return setupOutputContainers(ctx).isValid ? StatusCode::SUCCESS : StatusCode::FAILURE;
361 if (!
containers.strip.record(std::make_unique<xAOD::sTgcStripContainer>(),
362 std::make_unique<xAOD::sTgcStripAuxContainer>()).isSuccess()){
369 if (!
containers.pad.record(std::make_unique<xAOD::sTgcPadContainer>(),
370 std::make_unique<xAOD::sTgcPadAuxContainer>()).isSuccess()){
377 if (!
containers.wire.record(std::make_unique<xAOD::sTgcWireContainer>(),
378 std::make_unique<xAOD::sTgcWireAuxContainer>()).isSuccess()){
387 const int hashMax =
m_idHelperSvc->stgcIdHelper().module_hash_max();
388 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(hashMax)).isSuccess()){
399 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(
update.ptr())).isSuccess()) {