8 #include "Identifier/Identifier.h"
22 const std::set<int> bad_origins{
35 using namespace MuonStationIndex;
40 ATH_CHECK(m_muonTruthSegmentContainerName.initialize());
42 ATH_CHECK(m_CSC_SDO_TruthNames.initialize(!m_CSC_SDO_TruthNames.empty()));
48 if(m_idHelperSvc->hasRPC()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthRpcHits");}
49 if(m_idHelperSvc->hasTGC()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthTgcHits");}
50 if(m_idHelperSvc->hasMDT()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthMdtHits");}
51 if(m_idHelperSvc->hasMM()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthMMHits");}
52 if(m_idHelperSvc->hasSTGC()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthStgcHits");}
53 if(m_idHelperSvc->hasCSC()) {m_truthHitsKeyArray.emplace_back(m_muonTruth,
"truthCscHits");}
54 ATH_CHECK(m_truthHitsKeyArray.initialize());
55 return StatusCode::SUCCESS;
69 ATH_CHECK(segmentContainer.
record(std::make_unique<xAOD::MuonSegmentContainer>(),
70 std::make_unique<xAOD::MuonSegmentAuxContainer>()));
71 ATH_MSG_DEBUG(
"Recorded MuonSegmentContainer with key: " << segmentContainer.
name());
77 bool goodMuon = bad_origins.find(iOrigin) == bad_origins.end();
86 ATH_CHECK(createSegments(ctx, truthLink,
ids, *segmentContainer));
91 ATH_MSG_DEBUG(
"Registered " << segmentContainer->size() <<
" truth muon segments ");
93 return StatusCode::SUCCESS;
101 for (
const unsigned long long& hit_compID : hitCollection(truthParticle)){
103 if (m_idHelperSvc->isTgc(
id)) {
112 ids[m_idHelperSvc->chamberIndex(
id) ].push_back(
id);
116 return StatusCode::SUCCESS;
128 std::array<const MuonSimDataCollection*, techMax> sdoCollections{};
129 bool useSDO = !m_CSC_SDO_TruthNames.empty();
137 sdoCollections[
toInt(m_idHelperSvc->technologyIndex(
id))] = coll;
141 for (
const auto& [chIdx, assocIds] :
ids) {
144 bool firstPosSet{
false}, secondPosSet{
false};
147 uint8_t nprecLayers{0}, nphiLayers{0}, ntrigEtaLayers{0};
148 std::unordered_set<int> phiLayers{}, etaLayers{}, precLayers{};
151 for (
const auto&
id : assocIds) {
153 bool measPhi = m_idHelperSvc->measuresPhi(
id);
154 bool isCsc = m_idHelperSvc->isCsc(
id);
155 bool isMM = m_idHelperSvc->isMM(
id);
156 bool isTrig = m_idHelperSvc->isTrigger(
id);
157 bool isEndcap = m_idHelperSvc->isEndcap(
id);
159 phiLayers.insert(m_idHelperSvc->gasGap(
id));
162 if (!chId.is_valid()) chId =
id;
164 precLayers.insert(m_idHelperSvc->gasGap(
id));
166 int iid = 10 * m_idHelperSvc->mdtIdHelper().multilayer(
id) + m_idHelperSvc->mdtIdHelper().tubeLayer(
id);
167 precLayers.insert(iid);
171 etaLayers.insert(m_idHelperSvc->gasGap(
id));
182 if (sdoCollections[
toInt(techIdx)]) {
183 auto pos = sdoCollections[
toInt(techIdx)]->find(
id);
184 if (
pos != sdoCollections[
toInt(techIdx)]->
end()) {
185 gpos =
pos->second.globalPosition();
186 if (gpos.perp() > 0.1) ok =
true;
195 return std::abs(
p1.z()) < std::abs(
p2.z());
197 return p1.perp() <
p2.perp();
202 }
else if (!secondPosSet) {
205 if (isSmaller(secondPos, firstPos))
std::swap(firstPos, secondPos);
208 if (isSmaller(gpos, firstPos))
210 else if (isSmaller(secondPos, gpos))
216 auto pos = cscCollection->find(
id);
217 if (
pos == cscCollection->end()) {
221 ATH_MSG_DEBUG(
"found csc sdo with " <<
pos->second.getdeposits().size() <<
" deposits");
222 Amg::Vector3D locpos(0,
pos->second.getdeposits()[0].second.ypos(),
pos->second.getdeposits()[0].second.zpos());
223 gpos = descriptor->
localToGlobalCoords(locpos, m_idHelperSvc->cscIdHelper().elementID(
id));
228 }
else if (!secondPosSet) {
231 if (secondPos.perp() < firstPos.perp())
std::swap(firstPos, secondPos);
233 if (gpos.perp() < firstPos.perp())
235 else if (secondPos.perp() < gpos.perp())
240 if (precLayers.size() > 2) {
241 if (!phiLayers.empty()) nphiLayers = phiLayers.size();
242 ntrigEtaLayers = etaLayers.size();
243 nprecLayers = precLayers.size();
244 ATH_MSG_DEBUG(
" total counts: precision " <<
static_cast<int>(nprecLayers) <<
" phi layers " <<
static_cast<int>(nphiLayers)
245 <<
" eta trig layers " <<
static_cast<int>(ntrigEtaLayers)
247 <<
" truthLink " << truthLink);
250 segment->setNHits(nprecLayers, nphiLayers, ntrigEtaLayers);
252 truthParticleLinkAcc(
"truthParticleLink");
253 truthParticleLinkAcc(*
segment) = truthLink;
254 if (chId.is_valid()) {
255 int eta = m_idHelperSvc->stationEta(chId);
256 int sector = m_idHelperSvc->sector(chId);
261 if (firstPosSet && secondPosSet) {
264 ATH_MSG_DEBUG(
" got position : r " << gpos.perp() <<
" z " << gpos.z() <<
" and direction: theta " << gdir.theta()
265 <<
" phi " << gdir.phi());
266 segment->setPosition(gpos.x(), gpos.y(), gpos.z());
267 segment->setDirection(gdir.x(), gdir.y(), gdir.z());
271 return StatusCode::SUCCESS;