21 std::atomic<bool> hitNegativeCharge{
false};
34 ATH_CHECK(m_updateKey.initialize(!m_updateKey.key().empty()));
35 ATH_CHECK(m_xAODKey.initialize(!m_xAODKey.empty()));
36 return StatusCode::SUCCESS;
39 StatusCode MmRdoToPrepDataToolMT::processCollection(
const EventContext& ctx,
42 const std::vector<IdentifierHash>& idsToDecode,
44 ATH_MSG_DEBUG(
" ***************** Start of process MM Collection");
45 const MmIdHelper& id_helper = m_idHelperSvc->mmIdHelper();
47 bool merge = m_merge || rdoColl->
size() > 100;
52 if (!idsToDecode.empty() and
std::find(idsToDecode.begin(), idsToDecode.end(),
53 hash) == idsToDecode.end()) {
55 return StatusCode::SUCCESS;
62 ATH_MSG_DEBUG(
"In processCollection: collection already contained in the MM PrepData container");
63 return StatusCode::SUCCESS;
70 if (
lock.OnlineAndPresentInAnotherView()) {
71 ATH_MSG_DEBUG(
"In processCollection: collection already available in the MM PrepData container (via cache)");
72 return StatusCode::SUCCESS;
74 auto prdColl = std::make_unique<MMPrepDataCollection>(
hash);
79 if (id_helper.
get_id(
hash, moduleId, &context) != 0) {
83 prdColl->setIdentifier(moduleId);
88 if (!MuonDetMgr.isValid()) {
89 ATH_MSG_ERROR(
"Null pointer to the read MuonDetectorManager conditions object");
90 return StatusCode::FAILURE;
93 std::vector<MMPrepData> MMprds;
103 std::vector<Identifier> rdoList;
106 rdoList.push_back(prdId);
115 ATH_MSG_WARNING(
"Could not get the local strip position for "<< m_idHelperSvc->toString(prdId));
127 ATH_CHECK(m_calibTool->calibrateStrip(ctx, rdo, calibStrip));
128 if (calibStrip.
charge < 0) {
129 if (!hitNegativeCharge || msgLvl(
MSG::DEBUG)) {
130 ATH_MSG_DEBUG(
"One MM RDO or more, such as one with pdo = "<< rdo->charge()
131 <<
" counts, corresponds to a negative charge ("<< calibStrip.
charge <<
"). Skipping these RDOs");
132 hitNegativeCharge =
true;
147 ATH_MSG_DEBUG(
" MM detector surface direction phi "<< gdir.phi() <<
" global radius hit " << globalPos.perp()
148 <<
" phi pos " << globalPos.phi() <<
" global z "<< globalPos.z());
154 localPos.x() += calibStrip.
dx;
158 auto mpd = std::make_unique<MMPrepData>(prdId,
hash,
159 std::move(localPos), std::move(rdoList), std::move(
cov),
162 mpd->setAuthor(MMPrepData::Author::RDOTOPRDConverter);
164 prdColl->push_back(std::move(mpd));
167 if (calibStrip.
charge < m_singleStripChargeCut) {
172 MMPrepData mpd(prdId,
hash, std::move(localPos), std::move(rdoList),
178 mpd.
setAuthor(MMPrepData::Author::RDOTOPRDConverter);
179 MMprds.push_back(std::move(mpd));
184 std::vector<std::unique_ptr<MMPrepData>>
clusters;
189 for (std::unique_ptr<MMPrepData>& prdN :
clusters) {
190 prdN->setHashAndIndex(prdColl->identifyHash(), prdColl->size());
191 prdColl->push_back(std::move(prdN));
197 std::vector<const MMPrepData*> sortMe{prdColl->begin(), prdColl->end()};
201 cluster->setIdentifier(prd->identify().get_compact());
202 cluster->setMeasurement(m_idHelperSvc->detElementHash(prd->identify()),
205 cluster->setGasGap(id_helper.
gasGap(prd->identify()));
206 cluster->setChannelNumber(id_helper.
channel(prd->identify()));
207 cluster->setTime(prd->time());
208 cluster->setCharge(prd->charge());
209 cluster->setDriftDist(prd->driftDist());
210 cluster->setAngle(prd->angle());
211 cluster->setChiSqProb(prd->chisqProb());
212 cluster->setAuthor(prd->author());
213 cluster->setQuality(prd->quality());
214 cluster->setStripNumbers(prd->stripNumbers());
215 cluster->setStripTimes(prd->stripTimes());
216 cluster->setStripCharges(prd->stripCharges());
217 cluster->setStripDriftDist(prd->stripDriftDist());
218 cluster->setStripDriftErrors(prd->stripDriftErrors());
225 return StatusCode::SUCCESS;
229 MmRdoToPrepDataToolMT::getRdoContainer(
const EventContext& ctx)
const {
231 if (rdoContainerHandle.isValid()) {
233 return rdoContainerHandle.cptr();
240 void MmRdoToPrepDataToolMT::processRDOContainer(
const EventContext& ctx,
243 const std::vector<IdentifierHash>& idsToDecode)
const {
252 if (rdoColl->empty()){
255 ATH_MSG_DEBUG(
"New RDO collection with " << rdoColl->size() <<
"MM Hits");
257 if (processCollection(ctx, mmPrepDataContainer, xAODContainer, idsToDecode, rdoColl).isFailure()) {
259 "processCsm returns a bad StatusCode - keep going for new data "
260 "collections in this event");
267 const std::vector<IdentifierHash>& idVect)
const {
270 ATH_MSG_DEBUG(
"Size of the RDO container to be decoded: " << idVect.size());
274 if (!mmPrepDataContainer) {
275 return StatusCode::FAILURE;
280 if (!m_xAODKey.empty()) {
282 ATH_CHECK(outputContainer.record(std::make_unique<xAOD::MMClusterContainer>(),
283 std::make_unique<xAOD::MMClusterAuxContainer>()));
284 xAODContainer = outputContainer.ptr();
287 processRDOContainer(ctx, mmPrepDataContainer, xAODContainer, idVect);
289 return StatusCode::SUCCESS;
293 const std::vector<uint32_t>&)
const {
295 return StatusCode::FAILURE;
297 StatusCode MmRdoToPrepDataToolMT::provideEmptyContainer(
const EventContext& ctx)
const {
298 if (!m_xAODKey.empty()) {
300 ATH_CHECK(writeHandle.record(std::make_unique<xAOD::MMClusterContainer>(),
301 std::make_unique<xAOD::MMClusterAuxContainer>()));
304 return setupMM_PrepDataContainer(ctx) ? StatusCode::SUCCESS
305 : StatusCode::FAILURE;
309 MmRdoToPrepDataToolMT::setupMM_PrepDataContainer(
const EventContext& ctx)
const {
312 if (m_updateKey.key().empty()) {
315 handle.record(std::make_unique<MMPrepDataContainer>(
316 m_idHelperSvc->mmIdHelper().module_hash_max()));
318 if (
status.isFailure() || !handle.isValid()) {
320 "Could not record container of MicroMega PrepData Container at "
321 << m_writeKey.key());
327 if (!update.isValid()) {
331 StatusCode status = handle.record(std::make_unique<MMPrepDataContainer>(update.ptr()));
332 if (
status.isFailure() || !handle.isValid()) {
334 "Could not record container of MM PrepData Container using cache "
335 << m_updateKey.key() <<
" - "
336 << m_writeKey.key());
340 << m_updateKey.key());