20 std::atomic<bool> hitNegativeCharge{
false};
33 ATH_CHECK(m_stgcPrepDataContainerKey.initialize());
34 ATH_CHECK(m_rdoContainerKey.initialize());
37 ATH_CHECK(m_prdContainerCacheKey.initialize(!m_prdContainerCacheKey.key().empty()) );
43 ATH_CHECK(m_xAODStripKey.initialize(!m_xAODStripKey.empty()));
44 ATH_CHECK(m_xAODWireKey.initialize(!m_xAODWireKey.empty()));
45 ATH_CHECK(m_xAODPadKey.initialize(!m_xAODPadKey.empty()));
46 return StatusCode::SUCCESS;
55 const sTgcIdHelper& id_helper = m_idHelperSvc->stgcIdHelper();
58 ATH_MSG_DEBUG(
" ***************** Start of process STGC Collection with hash Id: " <<
hash);
60 auto stgcPrepDataContainer = xAODcontainers.
prd;
62 if ( stgcPrepDataContainer->indexFindPtr(
hash) !=
nullptr ) {
63 ATH_MSG_DEBUG(
"In processCollection: collection already contained in the sTGC PrepData container");
64 return StatusCode::FAILURE;
72 ATH_MSG_DEBUG(
"In processCollection: collection already available in the sTgc PrepData container (via cache)");
73 return StatusCode::SUCCESS;
77 std::unique_ptr<sTgcPrepDataCollection> prdColl = std::make_unique<sTgcPrepDataCollection>(
hash);
82 int getId = id_helper.
get_id(
hash, moduleId, &context);
90 std::vector<sTgcPrepData> sTgcStripPrds;
91 std::vector<sTgcPrepData> sTgcWirePrds;
92 std::vector<sTgcPrepData> sTgcPadPrds;
93 sTgcStripPrds.reserve(rdoColl->
size());
94 sTgcPadPrds.reserve(rdoColl->
size());
95 sTgcWirePrds.reserve(rdoColl->
size());
102 if(!muonDetMgr.isValid()){
103 ATH_MSG_ERROR(
"Null pointer to the read MuonDetectorManager conditions object");
104 return StatusCode::FAILURE;
113 if (!m_idHelperSvc->issTgc(rdoId)) {
114 ATH_MSG_WARNING(
"The given Identifier "<<rdoId.get_compact()<<
" ("<<m_idHelperSvc->toString(rdoId)<<
") is no sTGC Identifier, continuing");
118 std::vector<Identifier> rdoList;
119 rdoList.push_back(rdoId);
126 if (channelType < 0 || channelType > 2) {
128 return StatusCode::FAILURE;
132 if ( !getLocalPos ) {
133 ATH_MSG_ERROR(
"Could not get the local strip position for "<<m_idHelperSvc->toString(rdoId));
134 return StatusCode::FAILURE;
143 ATH_CHECK (m_calibTool->calibrateStrip(ctx, rdo, calibStrip));
144 int calibratedCharge =
static_cast<int>(calibStrip.
charge);
145 if (calibratedCharge < 0 && channelType == 1) {
146 if (!hitNegativeCharge) {
147 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");
148 hitNegativeCharge =
true;
154 if (channelType == sTgcIdHelper::sTgcChannelTypes::Pad) {
178 std::vector<sTgcPrepData>& sTgcPrds = channelType ==
sTgcIdHelper::Pad ? sTgcPadPrds :
182 auto it = std::find_if(sTgcPrds.begin(), sTgcPrds.end(), [&rdoId](
const sTgcPrepData& prd) {
183 return (prd.identify() == rdoId);
185 if (
it == sTgcPrds.end()) {
186 sTgcPrds.emplace_back(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
188 }
else if (
it->time() > calibStrip.
time) {
189 *
it =
sTgcPrepData(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
197 prdColl->
push_back(std::make_unique<sTgcPrepData>(rdoId,
210 std::vector<std::unique_ptr<Muon::sTgcPrepData>> sTgcStripClusters;
211 ATH_CHECK(m_clusterBuilderTool->getClusters(ctx, std::move(sTgcStripPrds), sTgcStripClusters));
213 for ( std::unique_ptr<Muon::sTgcPrepData>&
it : sTgcStripClusters ) {
219 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
223 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
226 const bool convertXAOD = !m_xAODPadKey.empty() || !m_xAODStripKey.empty() ||
227 !m_xAODWireKey.empty();
237 <<m_idHelperSvc->toString(prdId)<<
". "<<
Amg::toString(prd->localPosition())
238 <<
", cov: "<<prd->localCovariance()(0,0)
240 if (!m_xAODPadKey.empty() &&
chType == sTgcIdHelper::sTgcChannelTypes::Pad) {
241 outHit = xAODcontainers.
pad->push_back(std::make_unique<xAOD::sTgcPadHit>());
243 lCov(0,0) = prd->localCovariance()(0,0);
246 outHit->setMeasurement<2>(m_idHelperSvc->detElementHash(prdId),
249 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Wire && !m_xAODWireKey.empty()) {
250 outHit = xAODcontainers.
wire->push_back(std::make_unique<xAOD::sTgcWireHit>());
251 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Strip && !m_xAODStripKey.empty()) {
252 auto stripHit = xAODcontainers.
strip->push_back(std::make_unique<xAOD::sTgcStripCluster>());
253 stripHit->setStripCharges(prd->stripCharges());
254 stripHit->setStripNumbers(prd->stripNumbers());
255 stripHit->setStripTimes(prd->stripTimes());
261 if (
chType != sTgcIdHelper::sTgcChannelTypes::Pad){
264 lCov(0,0) = prd->localCovariance()(0,0);
265 outHit->setMeasurement<1>(m_idHelperSvc->detElementHash(prdId),
270 outHit->setChannelNumber(
channel);
271 outHit->setGasGap(
gasGap);
272 outHit->setAuthor(prd->author());
273 outHit->setTime(prd->time());
274 outHit->setCharge(prd->charge());
275 outHit->setIdentifier(prdId.get_compact());
277 outHit->setReadoutElement(m_detMgrR4->getsTgcReadoutElement(prdId));
287 return StatusCode::SUCCESS;
295 if(rdoContainerHandle.isValid()) {
297 return rdoContainerHandle.cptr();
308 const std::vector<IdentifierHash>& idsToDecode)
const
312 if (!rdoContainer)
return;
316 if (rdoColl->empty())
continue;
317 ATH_MSG_DEBUG(
"New RDO collection with " << rdoColl->size() <<
"STGC Hits");
319 const IdentifierHash
hash = rdoColl->identifyHash();
322 if(!idsToDecode.empty() and
std::find(idsToDecode.begin(), idsToDecode.end(),
hash)==idsToDecode.end()) {
327 if(processCollection(ctx, xAODcontainers, rdoColl).isFailure()) {
328 ATH_MSG_DEBUG(
"processCsm returns a bad StatusCode - keep going for new data collections in this event");
336 const std::vector<IdentifierHash>& idVect)
const {
337 ATH_MSG_DEBUG(
"Size of the input hash id vector: " << idVect.size());
340 if (!outCache.
isValid)
return StatusCode::FAILURE;
342 processRDOContainer(ctx, outCache, idVect);
343 return StatusCode::SUCCESS;
350 return StatusCode::FAILURE;
353 return setupOutputContainers(ctx).isValid ? StatusCode::SUCCESS : StatusCode::FAILURE;
362 if (!
containers.strip.record(std::make_unique<xAOD::sTgcStripContainer>(),
363 std::make_unique<xAOD::sTgcStripAuxContainer>()).isSuccess()){
370 if (!
containers.pad.record(std::make_unique<xAOD::sTgcPadContainer>(),
371 std::make_unique<xAOD::sTgcPadAuxContainer>()).isSuccess()){
378 if (!
containers.wire.record(std::make_unique<xAOD::sTgcWireContainer>(),
379 std::make_unique<xAOD::sTgcWireAuxContainer>()).isSuccess()){
388 const int hashMax =
m_idHelperSvc->stgcIdHelper().module_hash_max();
389 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(hashMax)).isSuccess()){
400 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(
update.ptr())).isSuccess()) {