7 #include "GaudiKernel/ThreadLocalContext.h"
16 #include "GeoModelKernel/throwExcept.h"
22 m_idHelperSvc{idHelperSvc} {
23 const IdentifierHash hashMax =
m_idHelperSvc->rpcIdHelper().module_hash_max();
24 rpcPrepDataCollections.resize(hashMax);
25 rpcCoinDataCollections.resize(hashMax);
29 const IdentifierHash rpdModHash =
m_idHelperSvc->moduleHash(chanId);
30 std::unique_ptr<RpcPrepDataCollection>& coll = rpcPrepDataCollections[rpdModHash];
32 coll = std::make_unique<RpcPrepDataCollection>(rpdModHash);
38 const IdentifierHash rpdModHash =
m_idHelperSvc->moduleHash(chanId);
39 std::unique_ptr<RpcCoinDataCollection>& coll = rpcCoinDataCollections[rpdModHash];
41 coll = std::make_unique<RpcCoinDataCollection>(rpdModHash);
49 const std::string&
name,
64 "Inconsistent setting of properties (solvePhiAmbiguities entails "
65 "reduceCablingOverlap)");
90 return StatusCode::SUCCESS;
93 const EventContext& ctx,
State& state)
const {
99 return StatusCode::FAILURE;
102 std::make_unique<RpcPrepDataContainer>(
update.ptr());
107 state.
prepDataCont = std::make_unique<RpcPrepDataContainer>(
112 state.
coinDataCont = std::make_unique<RpcCoinDataContainer>(
121 return StatusCode::FAILURE;
124 std::make_unique<RpcCoinDataContainer>(
update.ptr());
130 return StatusCode::SUCCESS;
135 const std::vector<IdentifierHash>& idVect)
const {
136 ATH_MSG_DEBUG(
"Calling Core decode function from MT decode function (hash vector)");
142 ATH_MSG_DEBUG(
"Core decode processed in MT decode (hash vector)");
147 return StatusCode::SUCCESS;
153 const std::vector<uint32_t>& robIds)
const {
155 "Calling Core decode function from MT decode function (ROB vector)");
161 ATH_MSG_DEBUG(
"Core decode processed in MT decode (ROB vector)");
166 return StatusCode::SUCCESS;
173 return StatusCode::SUCCESS;
181 ATH_CHECK(writeHandleXAOD.record(std::make_unique<xAOD::RpcStripContainer>(),
182 std::make_unique<xAOD::RpcStripAuxContainer>()));
186 if (!collection || collection->empty()) {
192 std::vector<const RpcPrepData*> sortMe{collection->begin(), collection->end()};
196 xAOD::RpcStrip* strip = writeHandleXAOD->push_back(std::make_unique<xAOD::RpcStrip>());
197 strip->setDoubletPhi(idHelper.doubletPhi(
id));
198 strip->setGasGap(idHelper.gasGap(
id));
199 strip->setMeasuresPhi(idHelper.measuresPhi(
id));
200 strip->setStripNumber(idHelper.channel(
id));
201 strip->setAmbiguityFlag(prd->ambiguityFlag());
202 strip->setTimeOverThreshold(prd->timeOverThreshold());
203 strip->setTime(prd->time());
205 strip->setTriggerInfo(prd->triggerInfo());
208 strip->setMeasurement(
m_idHelperSvc->detElementHash(
id), std::move(locPos), std::move(locCov));
212 const IdentifierHash
hash = collection->identifyHash();
216 ATH_MSG_DEBUG(
"RpcPrepDataCollection already contained in IDC "
234 return StatusCode::SUCCESS;
238 const EventContext& ctx,
State& state)
const {
240 return StatusCode::SUCCESS;
245 if (!collection || collection->empty()) {
248 const IdentifierHash
hash = collection->identifyHash();
252 ATH_MSG_DEBUG(
"RpcCoinDataCollection already contained in IDC "
273 return StatusCode::SUCCESS;
279 const std::vector<IdentifierHash>& idVect,
280 bool firstTimeInTheEvent)
const {
281 int sizeVectorRequested = idVect.size();
282 ATH_MSG_DEBUG(
"Decode method called for " << sizeVectorRequested
283 <<
" offline collections");
284 if (sizeVectorRequested == 0)
289 std::vector<IdentifierHash> idVectToBeDecoded;
290 idVectToBeDecoded.reserve(idVect.size());
292 if (firstTimeInTheEvent) {
296 ATH_MSG_DEBUG(
"Whole event has already been decoded; nothing to do.");
297 return StatusCode::SUCCESS;
299 if (sizeVectorRequested == 0)
303 if (sizeVectorRequested != 0) {
307 for (
const IdentifierHash& itHashId : idVect) {
309 idVectToBeDecoded.push_back(itHashId);
311 if (idVectToBeDecoded.empty()) {
313 "All requested offline collections have already been decoded; "
315 return StatusCode::SUCCESS;
318 <<
" offline collections have not yet been decoded and "
319 "will be decoded now.");
322 "The list of offline collection hash ids to be decoded:");
323 for (
const IdentifierHash& itHashId : idVectToBeDecoded)
332 "Stored empty container. Decoding RPC RDO into RPC PrepRawData is "
334 return StatusCode::SUCCESS;
344 std::vector<IdentifierHash> rdoHashVec;
345 if (sizeVectorRequested != 0) {
347 "Looking for pads IdHash to be decoded for the requested collection "
349 ATH_CHECK(rpcCabling->giveRDO_fromPRD(idVectToBeDecoded, rdoHashVec));
356 ATH_MSG_DEBUG(
"Retrieving Rpc PAD container from the store");
358 if (!rdoContainerHandle.isValid()) {
360 return StatusCode::FAILURE;
365 if (rdoContainerHandle->numberOfCollections() == 0) {
367 ATH_MSG_DEBUG(
"Empty pad container - no rpc rdo in this event ");
368 return StatusCode::SUCCESS;
373 bool processingetaview{
true}, processingphiview{
false};
375 processingetaview =
false;
376 bool doingSecondLoopAmbigColls =
false;
378 int ipad{0}, nPrepRawData{0}, nPhiPrepRawData{0}, nEtaPrepRawData{0};
379 if (processingphiview)
382 if (processingetaview)
388 if (sizeVectorRequested != 0) {
390 for (
const IdentifierHash& iPadHash : rdoHashVec) {
391 const RpcPad* rdoColl = rdoContainerHandle->indexFindPtr(iPadHash);
394 << iPadHash <<
" not found in the rdoContainerHandle.");
401 <<
", with " << rdoColl->
size()
404 processingphiview, nPrepRawData, idVectToBeDecoded, doingSecondLoopAmbigColls));
409 for (
const RpcPad* rdoColl : *rdoContainerHandle) {
411 if (rdoColl->empty())
415 << (
int)(rdoColl->identifyHash())
416 <<
", with " << rdoColl->size()
420 processingphiview, nPrepRawData, idVectToBeDecoded, doingSecondLoopAmbigColls));
424 if (processingetaview) {
425 processingetaview =
false;
426 processingphiview =
true;
427 nEtaPrepRawData = nPrepRawData;
428 ATH_MSG_DEBUG(
"*** " << nEtaPrepRawData <<
" eta PrepRawData registered");
430 processingphiview =
false;
431 nPhiPrepRawData = nPrepRawData - nEtaPrepRawData;
432 ATH_MSG_DEBUG(
"*** " << nPhiPrepRawData <<
" phi PrepRawData registered");
435 doingSecondLoopAmbigColls =
true;
436 processingetaview =
true;
438 <<
" ambiguous collections were stored:");
439 idVectToBeDecoded.clear();
443 idVectToBeDecoded.push_back(itAmbiColl);
446 ATH_CHECK(rpcCabling->giveRDO_fromPRD(idVectToBeDecoded, rdoHashVec));
450 ATH_MSG_DEBUG(
"*** " << nPrepRawData <<
" PrepRawData registered");
456 return StatusCode::SUCCESS;
461 const EventContext& ctx,
State& state,
const std::vector<uint32_t>& robIds,
462 bool firstTimeInTheEvent)
const {
466 int sizeVectorRequested = robIds.size();
467 ATH_MSG_DEBUG(
"Decode method called for " << sizeVectorRequested <<
" ROBs");
469 std::vector<uint32_t> robIdsToBeDecoded;
470 robIdsToBeDecoded.reserve(robIds.size());
472 if (firstTimeInTheEvent) {
476 ATH_MSG_DEBUG(
"Whole event has already been decoded; nothing to do.");
477 return StatusCode::SUCCESS;
484 robIdsToBeDecoded.push_back(robid);
487 if (robIdsToBeDecoded.empty()) {
489 "All requested ROBs have already been decoded; nothing to do.");
490 return StatusCode::SUCCESS;
493 <<
" ROBs have not yet been decoded and will be decoded now.");
496 for (
uint32_t robid : robIdsToBeDecoded)
505 if (state.
m_decodedRobIds.size() == rpcCabling->giveFullListOfRobIds().size())
511 "Stored empty container. Decoding RPC RDO into RPC PrepRawData is "
513 return StatusCode::SUCCESS;
519 ATH_MSG_DEBUG(
"Retrieving Rpc PAD container from the store");
521 if (!rdoContainerHandle.isValid()) {
523 return StatusCode::SUCCESS;
528 if (rdoContainerHandle->empty()) {
530 ATH_MSG_DEBUG(
"Empty pad container - no rpc rdo in this event ");
531 return StatusCode::SUCCESS;
536 std::vector<IdentifierHash> rdoHashVec;
538 13 * robIdsToBeDecoded.size());
539 ATH_CHECK(rpcCabling->giveRDO_fromROB(robIdsToBeDecoded, rdoHashVec));
542 bool processingetaview =
true;
543 bool processingphiview =
false;
545 processingetaview =
false;
547 int ipad{0}, nPrepRawData{0}, nPhiPrepRawData{0}, nEtaPrepRawData{0};
548 if (processingphiview)
551 if (processingetaview)
559 for (
const IdentifierHash& padHashId : rdoHashVec) {
560 const RpcPad* rdoColl = rdoContainerHandle->indexFindPtr(padHashId);
563 << (
unsigned int)padHashId
564 <<
" not found in the rdoContainerHandle.");
569 << ipad <<
", online id " << (
int)(rdoColl->
identifyHash())
570 <<
", with " << rdoColl->
size() <<
" CM inside ");
572 processingphiview, nPrepRawData, rdoHashVec,
false));
575 if (processingetaview) {
576 processingetaview =
false;
577 processingphiview =
true;
578 nEtaPrepRawData = nPrepRawData;
579 ATH_MSG_DEBUG(
"*** " << nEtaPrepRawData <<
" eta PrepRawData registered");
581 processingphiview =
false;
582 nPhiPrepRawData = nPrepRawData - nEtaPrepRawData;
583 ATH_MSG_DEBUG(
"*** " << nPhiPrepRawData <<
" phi PrepRawData registered");
586 ATH_MSG_DEBUG(
"*** " << nPrepRawData <<
" PrepRawData registered");
593 return StatusCode::SUCCESS;
598 const EventContext& ctx,
State& state,
const RpcPad* rdoColl,
599 bool& processingetaview,
bool& processingphiview,
int& nPrepRawData,
600 const std::vector<IdentifierHash>& idVect,
601 bool doingSecondLoopAmbigColls)
const {
606 ATH_MSG_DEBUG(
"***************** Start of processPad eta/phiview "
607 << processingetaview <<
"/" << processingphiview);
613 << padId <<
" m_logic sector ID " << sectorId);
620 IdentifierHash rpcHashId{0};
629 for (; itCM != itCM_e; ++itCM) {
631 bool etaview =
false;
634 bool highPtCm =
false;
636 uint16_t cmaId = (*itCM)->onlineId();
638 << icm <<
" CM online ID " << cmaId
639 <<
" with n. of hits = " << (*itCM)->size());
667 if (processingetaview && (!etaview))
669 if (processingphiview && etaview)
679 for (; itD != itD_e; ++itD) {
683 unsigned short overlap = 99;
693 << rpcChan->
time() <<
" ijk "
695 if (rpcChan->
ijk() < 7)
701 bool triggerHit =
false;
711 solvePhiAmb_thisHit =
false;
712 reduceCablOvl_thisHit =
false;
714 "RpcFiredChannel: it's a triggerHit or a lowPt coinc. in a high pt "
716 <<
" ijk = " << rpcChan->
ijk() <<
" isHighPtCM " << highPtCm
717 <<
" thr/ovl = " <<
threshold <<
"/" << overlap);
723 rpcChan, sectorId, padId, cmaId, time, rpcCabling.cptr())};
726 int nMatchingEtaHits = 0;
727 int nDuplicatePhiHits = 0;
728 bool unsolvedAmbiguity =
false;
729 bool notFinished =
true;
738 while (notFinished) {
741 "size of the corresponding list of ID = " << digitVec.size());
742 if (digitVec.empty()) {
756 if (!idVect.empty() &&
757 std::find(idVect.begin(), idVect.end(), rpcHashId) == idVect.end()) {
765 bool hasAMatchingEtaHit = 0;
768 if ((oldIdTrg !=
parentId) || !collectionTrg) {
773 <<
static_cast<unsigned int>(rpcHashId));
779 }
else if ((oldId !=
parentId) || !collection) {
784 <<
static_cast<unsigned int>(rpcHashId));
794 bool duplicate =
false;
795 if (reduceCablOvl_thisHit) {
796 if (collection->begin() != collection->end()) {
799 << collection->size());
800 int current_dbphi{0}, current_dbz{0}, current_gg{0};
801 if (processingphiview) {
807 "Check also for eta hits matching dbz, dbphi, gg "
808 << current_dbz <<
" " << current_dbphi <<
" "
816 hasAMatchingEtaHit =
false;
821 float previous_time = rpc->time();
823 if (time < previous_time) {
826 "time of the prd previously stored is now updated with "
828 << previous_time <<
" -> " << rpc->time());
834 if (processingphiview) {
835 if (solvePhiAmb_thisHit) {
836 if (!unsolvedAmbiguity) {
838 rpc->identify()) == 0) {
850 if (fabs(time - rpc->time()) <
852 hasAMatchingEtaHit =
true;
854 "There's a matching eta hit with id "
870 if (hasAMatchingEtaHit)
874 if (processingphiview && duplicate)
882 if (solvePhiAmb_thisHit && (!etaview))
884 <<
" hasAMatchingEtaHit = "
885 << hasAMatchingEtaHit);
890 " solvePhiAmb_thisHit, processingetaview, processingphiview, "
891 "hasAMatchingEtaHit, unsolvedAmbiguity "
892 << solvePhiAmb_thisHit <<
" " << processingetaview <<
" "
893 << processingphiview <<
" " << hasAMatchingEtaHit <<
" "
894 << unsolvedAmbiguity);
895 if ((!solvePhiAmb_thisHit) || processingetaview ||
896 (processingphiview &&
897 (hasAMatchingEtaHit || unsolvedAmbiguity))) {
898 if (unsolvedAmbiguity) {
899 if (idVect.empty()) {
905 "unsolvedAmbiguity is true, adding collection with hash "
907 << (
int)rpcHashId <<
" to ambiguous collections vector");
911 ambiguousCollections.insert(rpcHashId);
913 "collection not yet processed; added to ambiguous "
914 "collection vector; going to the next offline "
917 }
else if (!doingSecondLoopAmbigColls) {
918 ambiguousCollections.insert(rpcHashId);
920 "collection already processed and "
921 "doingSecondLoopAmbigColls=false; added to ambiguous "
922 "collection vector; going to the next offline channel "
927 "collection already processed and "
928 "doingSecondLoopAmbigColls=true; trying to store data "
929 "even if unsolvedAmbiguity");
939 hasAMatchingEtaHit =
false;
942 "Detector Element not found for Identifier from the "
945 <<
"> =>>ignore this hit");
948 hasAMatchingEtaHit =
false;
954 "Identifier from the cabling service <"
956 <<
"> inconsistent with the geometry of detector element "
959 <<
"> =>>ignore this hit /// there are unmasked "
963 "Identifier from the cabling service <"
965 <<
"> inconsistent with the geometry of detector element "
968 <<
"> =>>ignore this hit");
977 << tempGlobalPosition.x() <<
", "
978 << tempGlobalPosition.y() <<
", "
979 << tempGlobalPosition.z() <<
") ");
983 tempGlobalPosition, tempGlobalPosition, pointLocPos);
986 std::vector<Identifier> identifierList{
channelId};
993 double errPos = stripWidth / std::sqrt(12.0);
996 mat *= errPos * errPos;
999 int ambiguityFlag = 0;
1000 if (solvePhiAmb_thisHit) {
1001 if (processingetaview)
1003 if (unsolvedAmbiguity)
1004 ambiguityFlag = digitVec.size();
1005 else if (hasAMatchingEtaHit)
1006 ambiguityFlag = nMatchingEtaHits;
1012 std::optional<double> StripTimeFromCool = readHandle->getStripTime(
channelId);
1013 if (StripTimeFromCool) {
1014 time -= (*StripTimeFromCool);
1022 channelId, rpcHashId, pointLocPos, identifierList,
1024 rpcChan->
ijk(),
threshold, overlap, cmaId, padId, sectorId,
1029 " Adding RpcCoinData @ "
1030 << newCoinData <<
" to collection "
1034 collectionTrg->size());
1035 collectionTrg->push_back(newCoinData);
1039 <<
"ambiguityFlag = " << ambiguityFlag);
1042 channelId, rpcHashId, pointLocPos, identifierList,
1048 << newPrepData <<
" to collection "
1052 collection->size());
1053 collection->push_back(newPrepData);
1068 "processingphiview, nMatchingEtaHits, nDuplicatePhiHits, "
1069 "unsolvedAmbiguity, solvePhiAmb_thisHit : "
1070 << processingphiview <<
", " << nMatchingEtaHits <<
", "
1071 << nDuplicatePhiHits <<
", " << unsolvedAmbiguity <<
", "
1072 << solvePhiAmb_thisHit);
1073 if ((processingphiview && (nMatchingEtaHits == 0)) &&
1074 (nDuplicatePhiHits == 0) && (!unsolvedAmbiguity) &&
1075 (solvePhiAmb_thisHit)) {
1076 unsolvedAmbiguity =
true;
1081 "No eta prepData matching any phi hit from this CM hit \n"
1082 <<
"loop once again and store all phi digits potentially "
1083 "generating this CM hit");
1084 }
else if (unsolvedAmbiguity)
1085 notFinished =
false;
1087 notFinished =
false;
1092 ATH_MSG_DEBUG(
"***************** Stop of processPad eta/phiview "
1093 << processingetaview <<
"/" << processingphiview
1094 <<
"***************** for Pad online Id " << padId
1095 <<
" m_logic sector ID " << sectorId);
1097 return StatusCode::SUCCESS;
1101 State& state)
const {
1104 return StatusCode::SUCCESS;
1107 ATH_MSG_DEBUG(
"Retrieving Nrpc RDO container from the store");
1109 if (!rdoNrpcContainerHandle.isPresent()) {
1111 <<
" container failed !");
1112 return StatusCode::FAILURE;
1115 if (rdoNrpcContainerHandle->empty()) {
1117 ATH_MSG_DEBUG(
"Empty NRPC RDO container - no nrpc rdo in this event ");
1118 return StatusCode::SUCCESS;
1120 ATH_MSG_DEBUG(
"Not empty NRPC RDO container in this event ");
1123 if (!readCdo.isValid()) {
1125 <<
" from the conditions store");
1126 return StatusCode::FAILURE;
1131 for (
const xAOD::NRPCRDO* nrpcrdo : *rdoNrpcContainerHandle) {
1134 translateCache.
subDetector = nrpcrdo->subdetector();
1135 translateCache.tdcSector = nrpcrdo->tdcsector();
1136 translateCache.tdc = nrpcrdo->tdc();
1137 translateCache.channelId = nrpcrdo->channel();
1139 if (!readCdo->getOfflineId(translateCache, msgStream()) ||
1140 !readCdo->convert(translateCache, chanId,
false)) {
1142 return StatusCode::FAILURE;
1148 muDetMgr->getRpcReadoutElement(chanId);
1151 std::vector<Identifier> identifierList{chanId};
1155 <<
" global position "
1162 const double stripWidth = descriptor->
StripWidth(
1165 const double errPos = stripWidth / std::sqrt(12.0);
1168 mat *= errPos * errPos;
1170 int ambiguityFlag = 0;
1172 const float time = nrpcrdo->time();
1174 const float timeoverthr = nrpcrdo->timeoverthr();
1176 const IdentifierHash rpcHashId =
m_idHelperSvc->moduleHash(chanId);
1178 new RpcPrepData(chanId, rpcHashId, pointLocPos, identifierList,
mat,
1179 descriptor, time, timeoverthr, 0, ambiguityFlag);
1182 collection->
size());
1185 return StatusCode::SUCCESS;
1192 bool& triggerHit,
unsigned short&
threshold,
unsigned short& overlap,
1196 if ((highPtCm && rpcChan->
ijk() < 2) || (rpcChan->
ijk() > 5)) {
1206 if (rpcChan->
ijk() == 7) {
1211 if (rpcChan->
ijk() == 6) {
1215 cmtype =
" in low pT CM ";
1217 cmtype =
" in high pT CM ";
1219 <<
" bcid is " << rpcChan->
bcid()
1220 <<
" time is " << rpcChan->
time()
1221 <<
" ch " << rpcChan->
channel());
1224 while (itDnext != itD_end) {
1228 <<
" bcid is " << rpcChan->
bcid()
1230 << rpcChanNext->
time());
1231 if (rpcChanNext->
ijk() < 7)
1234 if (rpcChanNext->
ijk() == 7) {
1236 if (rpcChanNext->
bcid() == rpcChan->
bcid() &&
1237 rpcChanNext->
time() == rpcChan->
time()) {
1239 << rpcChanNext->
thr() <<
"/" << rpcChanNext->
ovl());
1241 overlap = rpcChanNext->
ovl();
1244 "ijk =7 after a ijk = 6 BUT bdid/tick don't match - will not "
1245 "assign threshold/overlap ");
1251 if (rpcChanNext->
ijk() == 6) {
1256 "RPC cm hit with ijk = 6 not followed by ijk = 6 or 7 - will "
1257 "not assign threshold / overlap");
1268 << rpcChan->
ijk() <<
" threshold / overlap = " <<
threshold