20 std::atomic<bool> hitNegativeCharge{
false};
29 ATH_CHECK(m_stgcPrepDataContainerKey.initialize());
30 ATH_CHECK(m_rdoContainerKey.initialize());
33 ATH_CHECK(m_prdContainerCacheKey.initialize(!m_prdContainerCacheKey.key().empty()) );
39 ATH_CHECK(m_xAODStripKey.initialize(!m_xAODStripKey.empty()));
40 ATH_CHECK(m_xAODWireKey.initialize(!m_xAODWireKey.empty()));
41 ATH_CHECK(m_xAODPadKey.initialize(!m_xAODPadKey.empty()));
42 return StatusCode::SUCCESS;
51 const sTgcIdHelper& id_helper = m_idHelperSvc->stgcIdHelper();
54 ATH_MSG_DEBUG(
" ***************** Start of process STGC Collection with hash Id: " <<
hash);
56 auto stgcPrepDataContainer = xAODcontainers.
prd;
58 if ( stgcPrepDataContainer->indexFindPtr(
hash) !=
nullptr ) {
59 ATH_MSG_DEBUG(
"In processCollection: collection already contained in the sTGC PrepData container");
60 return StatusCode::FAILURE;
67 if(
lock.OnlineAndPresentInAnotherView() ) {
68 ATH_MSG_DEBUG(
"In processCollection: collection already available in the sTgc PrepData container (via cache)");
69 return StatusCode::SUCCESS;
73 std::unique_ptr<sTgcPrepDataCollection> prdColl = std::make_unique<sTgcPrepDataCollection>(
hash);
78 int getId = id_helper.
get_id(
hash, moduleId, &context);
86 std::vector<sTgcPrepData> sTgcStripPrds;
87 std::vector<sTgcPrepData> sTgcWirePrds;
88 std::vector<sTgcPrepData> sTgcPadPrds;
89 sTgcStripPrds.reserve(rdoColl->
size());
90 sTgcPadPrds.reserve(rdoColl->
size());
91 sTgcWirePrds.reserve(rdoColl->
size());
106 std::vector<Identifier> rdoList{rdoId};
113 if (channelType < 0 || channelType > 2) {
115 return StatusCode::FAILURE;
118 ATH_MSG_ERROR(
"Could not get the local strip position for "<<m_idHelperSvc->toString(rdoId));
119 return StatusCode::FAILURE;
128 ATH_CHECK (m_calibTool->calibrateStrip(ctx, rdo, calibStrip));
129 int calibratedCharge =
static_cast<int>(calibStrip.
charge);
130 if (calibratedCharge < 0 && channelType == 1) {
131 if (!hitNegativeCharge) {
132 ATH_MSG_DEBUG(
"One sTGC RDO or more, such as one with pdo = "<<rdo->charge() <<
" counts, corresponds to a negative charge (" << calibratedCharge <<
"). Skipping these RDOs");
133 hitNegativeCharge =
true;
139 if (channelType == sTgcIdHelper::sTgcChannelTypes::Pad) {
163 std::vector<sTgcPrepData>& sTgcPrds = channelType ==
sTgcIdHelper::Pad ? sTgcPadPrds :
167 auto it = std::find_if(sTgcPrds.begin(), sTgcPrds.end(), [&rdoId](
const sTgcPrepData& prd) {
168 return (prd.identify() == rdoId);
170 if (
it == sTgcPrds.end()) {
171 sTgcPrds.emplace_back(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
172 sTgcPrds.back().setAuthor(sTgcPrepData::Author::RdoToPrdConverter);
173 }
else if (
it->time() > calibStrip.
time) {
174 *
it =
sTgcPrepData(rdoId,
hash, std::move(localPos), std::move(rdoList), std::move(
cov), detEl, calibratedCharge, calibStrip.
time);
175 it->setAuthor(sTgcPrepData::Author::RdoToPrdConverter);
182 prdColl->
push_back(std::make_unique<sTgcPrepData>(rdoId,
195 std::vector<std::unique_ptr<Muon::sTgcPrepData>> sTgcStripClusters;
196 ATH_CHECK(m_clusterBuilderTool->getClusters(ctx, std::move(sTgcStripPrds), sTgcStripClusters));
198 for ( std::unique_ptr<Muon::sTgcPrepData>&
it : sTgcStripClusters ) {
204 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
208 prdColl->
push_back(std::make_unique<sTgcPrepData>(std::move(prd)));
211 const bool convertXAOD = !m_xAODPadKey.empty() || !m_xAODStripKey.empty() ||
212 !m_xAODWireKey.empty();
222 <<m_idHelperSvc->toString(prdId)<<
". "<<
Amg::toString(prd->localPosition())
223 <<
", cov: "<<prd->localCovariance()(0,0)
225 if (!m_xAODPadKey.empty() &&
chType == sTgcIdHelper::sTgcChannelTypes::Pad) {
226 outHit = xAODcontainers.
pad->push_back(std::make_unique<xAOD::sTgcPadHit>());
228 lCov(0,0) = prd->localCovariance()(0,0);
231 outHit->setMeasurement<2>(m_idHelperSvc->detElementHash(prdId),
234 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Wire && !m_xAODWireKey.empty()) {
235 outHit = xAODcontainers.
wire->push_back(std::make_unique<xAOD::sTgcWireHit>());
236 }
else if (
chType == sTgcIdHelper::sTgcChannelTypes::Strip && !m_xAODStripKey.empty()) {
237 auto stripHit = xAODcontainers.
strip->push_back(std::make_unique<xAOD::sTgcStripCluster>());
238 stripHit->setStripCharges(prd->stripCharges());
239 stripHit->setStripNumbers(prd->stripNumbers());
240 stripHit->setStripTimes(prd->stripTimes());
246 if (
chType != sTgcIdHelper::sTgcChannelTypes::Pad){
249 lCov(0,0) = prd->localCovariance()(0,0);
250 outHit->setMeasurement<1>(m_idHelperSvc->detElementHash(prdId),
255 outHit->setChannelNumber(
channel);
256 outHit->setGasGap(
gasGap);
257 outHit->setAuthor(prd->author());
258 outHit->setTime(prd->time());
259 outHit->setCharge(prd->charge());
260 outHit->setIdentifier(prdId.get_compact());
262 outHit->setReadoutElement(m_detMgrR4->getsTgcReadoutElement(prdId));
272 return StatusCode::SUCCESS;
280 if(rdoContainerHandle.isValid()) {
282 return rdoContainerHandle.cptr();
293 const std::vector<IdentifierHash>& idsToDecode)
const
297 if (!rdoContainer)
return;
301 if (rdoColl->empty())
continue;
302 ATH_MSG_DEBUG(
"New RDO collection with " << rdoColl->size() <<
"STGC Hits");
304 const IdentifierHash
hash = rdoColl->identifyHash();
307 if(!idsToDecode.empty() and
std::find(idsToDecode.begin(), idsToDecode.end(),
hash)==idsToDecode.end()) {
312 if(processCollection(ctx, xAODcontainers, rdoColl).isFailure()) {
313 ATH_MSG_DEBUG(
"processCsm returns a bad StatusCode - keep going for new data collections in this event");
321 const std::vector<IdentifierHash>& idVect)
const {
322 ATH_MSG_DEBUG(
"Size of the input hash id vector: " << idVect.size());
325 if (!outCache.
isValid)
return StatusCode::FAILURE;
327 processRDOContainer(ctx, outCache, idVect);
328 return StatusCode::SUCCESS;
335 return StatusCode::FAILURE;
338 return setupOutputContainers(ctx).isValid ? StatusCode::SUCCESS : StatusCode::FAILURE;
343 sTgcRdoToPrepDataToolMT::setupOutputContainers(
const EventContext& ctx)
const {
345 if (!m_xAODStripKey.empty()) {
347 if (!
containers.strip.record(std::make_unique<xAOD::sTgcStripContainer>(),
348 std::make_unique<xAOD::sTgcStripAuxContainer>()).isSuccess()){
349 ATH_MSG_FATAL(
"Failed to record "<<m_xAODStripKey.fullKey());
353 if (!m_xAODPadKey.empty()) {
355 if (!
containers.pad.record(std::make_unique<xAOD::sTgcPadContainer>(),
356 std::make_unique<xAOD::sTgcPadAuxContainer>()).isSuccess()){
361 if (!m_xAODWireKey.empty()) {
363 if (!
containers.wire.record(std::make_unique<xAOD::sTgcWireContainer>(),
364 std::make_unique<xAOD::sTgcWireAuxContainer>()).isSuccess()){
371 if(m_prdContainerCacheKey.key().empty()) {
373 const int hashMax = m_idHelperSvc->stgcIdHelper().module_hash_max();
374 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(hashMax)).isSuccess()){
375 ATH_MSG_FATAL(
"Faile to record "<<m_stgcPrepDataContainerKey.fullKey());
381 if (!update.isValid()) {
382 ATH_MSG_FATAL(
"Invalid UpdateHandle " << m_prdContainerCacheKey.key());
385 if (!
containers.prd.record(std::make_unique<Muon::sTgcPrepDataContainer>(update.ptr())).isSuccess()) {
386 ATH_MSG_FATAL(
"Failed to record "<<m_stgcPrepDataContainerKey.fullKey()
387 <<
" from "<<m_prdContainerCacheKey.fullKey());