7 #include "GaudiKernel/ThreadLocalContext.h"
16 #include "GeoModelHelpers/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 "
930 "unsolvedAmbiguity");
940 hasAMatchingEtaHit =
false;
943 "Detector Element not found for Identifier from the "
946 <<
"> =>>ignore this hit");
949 hasAMatchingEtaHit =
false;
955 "Identifier from the cabling service <"
957 <<
"> inconsistent with the geometry of detector element "
960 <<
"> =>>ignore this hit /// there are unmasked "
964 "Identifier from the cabling service <"
966 <<
"> inconsistent with the geometry of detector element "
969 <<
"> =>>ignore this hit");
978 << tempGlobalPosition.x() <<
", "
979 << tempGlobalPosition.y() <<
", "
980 << tempGlobalPosition.z() <<
") ");
984 tempGlobalPosition, tempGlobalPosition, pointLocPos);
987 std::vector<Identifier> identifierList{
channelId};
994 double errPos = stripWidth / std::sqrt(12.0);
997 mat *= errPos * errPos;
1000 int ambiguityFlag = 0;
1001 if (solvePhiAmb_thisHit) {
1002 if (processingetaview)
1004 if (unsolvedAmbiguity)
1005 ambiguityFlag = digitVec.size();
1006 else if (hasAMatchingEtaHit)
1007 ambiguityFlag = nMatchingEtaHits;
1013 std::optional<double> StripTimeFromCool = readHandle->getStripTime(
channelId);
1014 if (StripTimeFromCool) {
1015 time -= (*StripTimeFromCool);
1023 channelId, rpcHashId, pointLocPos, identifierList,
1025 rpcChan->
ijk(),
threshold, overlap, cmaId, padId, sectorId,
1030 " Adding RpcCoinData @ "
1031 << newCoinData <<
" to collection "
1035 collectionTrg->size());
1036 collectionTrg->push_back(newCoinData);
1040 <<
"ambiguityFlag = " << ambiguityFlag);
1043 channelId, rpcHashId, pointLocPos, identifierList,
1049 << newPrepData <<
" to collection "
1053 collection->size());
1054 collection->push_back(newPrepData);
1069 "processingphiview, nMatchingEtaHits, nDuplicatePhiHits, "
1070 "unsolvedAmbiguity, solvePhiAmb_thisHit : "
1071 << processingphiview <<
", " << nMatchingEtaHits <<
", "
1072 << nDuplicatePhiHits <<
", " << unsolvedAmbiguity <<
", "
1073 << solvePhiAmb_thisHit);
1074 if ((processingphiview && (nMatchingEtaHits == 0)) &&
1075 (nDuplicatePhiHits == 0) && (!unsolvedAmbiguity) &&
1076 (solvePhiAmb_thisHit)) {
1077 unsolvedAmbiguity =
true;
1082 "No eta prepData matching any phi hit from this CM hit \n"
1083 <<
"loop once again and store all phi digits potentially "
1084 "generating this CM hit");
1085 }
else if (unsolvedAmbiguity)
1086 notFinished =
false;
1088 notFinished =
false;
1093 ATH_MSG_DEBUG(
"***************** Stop of processPad eta/phiview "
1094 << processingetaview <<
"/" << processingphiview
1095 <<
"***************** for Pad online Id " << padId
1096 <<
" m_logic sector ID " << sectorId);
1098 return StatusCode::SUCCESS;
1102 State& state)
const {
1105 return StatusCode::SUCCESS;
1108 ATH_MSG_DEBUG(
"Retrieving Nrpc RDO container from the store");
1111 if (!rdoNrpcContainerHandle.isPresent()) {
1113 <<
" container failed !");
1114 return StatusCode::FAILURE;
1117 if (rdoNrpcContainerHandle->empty()) {
1119 ATH_MSG_DEBUG(
"Empty NRPC RDO container - no nrpc rdo in this event ");
1120 return StatusCode::SUCCESS;
1122 ATH_MSG_DEBUG(
"Not empty NRPC RDO container in this event ");
1125 if (!readCdo.isValid()) {
1127 <<
" from the conditions store");
1128 return StatusCode::FAILURE;
1133 for (
const xAOD::NRPCRDO* nrpcrdo : *rdoNrpcContainerHandle) {
1141 if (!readCdo->getOfflineId(
cabling_data, msgStream()) ||
1144 return StatusCode::FAILURE;
1150 muDetMgr->getRpcReadoutElement(chanId);
1153 std::vector<Identifier> identifierList{chanId};
1157 <<
" global position "
1164 const double stripWidth = descriptor->
StripWidth(
1167 const double errPos = stripWidth / std::sqrt(12.0);
1170 mat *= errPos * errPos;
1172 int ambiguityFlag = 0;
1174 const float time = nrpcrdo->time();
1176 const float timeoverthr = nrpcrdo->timeoverthr();
1178 const IdentifierHash rpcHashId =
m_idHelperSvc->moduleHash(chanId);
1180 new RpcPrepData(chanId, rpcHashId, pointLocPos, identifierList,
mat,
1181 descriptor, time, timeoverthr, 0, ambiguityFlag);
1184 collection->
size());
1187 return StatusCode::SUCCESS;
1194 bool& triggerHit,
unsigned short&
threshold,
unsigned short& overlap,
1198 if ((highPtCm && rpcChan->
ijk() < 2) || (rpcChan->
ijk() > 5)) {
1208 if (rpcChan->
ijk() == 7) {
1213 if (rpcChan->
ijk() == 6) {
1217 cmtype =
" in low pT CM ";
1219 cmtype =
" in high pT CM ";
1221 <<
" bcid is " << rpcChan->
bcid()
1222 <<
" time is " << rpcChan->
time()
1223 <<
" ch " << rpcChan->
channel());
1226 while (itDnext != itD_end) {
1230 <<
" bcid is " << rpcChan->
bcid()
1232 << rpcChanNext->
time());
1233 if (rpcChanNext->
ijk() < 7)
1236 if (rpcChanNext->
ijk() == 7) {
1238 if (rpcChanNext->
bcid() == rpcChan->
bcid() &&
1239 rpcChanNext->
time() == rpcChan->
time()) {
1241 << rpcChanNext->
thr() <<
"/" << rpcChanNext->
ovl());
1243 overlap = rpcChanNext->
ovl();
1246 "ijk =7 after a ijk = 6 BUT bdid/tick don't match - will not "
1247 "assign threshold/overlap ");
1253 if (rpcChanNext->
ijk() == 6) {
1258 "RPC cm hit with ijk = 6 not followed by ijk = 6 or 7 - will "
1259 "not assign threshold / overlap");
1270 << rpcChan->
ijk() <<
" threshold / overlap = " <<
threshold