20 constexpr unsigned int dummy_unsigned = 999;
21 constexpr int com_bit = (1<<xAOD::Muon::Author::Commissioning);
22 void increment_unsigned(
unsigned& val) {
23 if (val == dummy_unsigned)
88 return StatusCode::SUCCESS;
95 std::unique_ptr<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>> muonTruthParticleRecoLink{};
97 muonTruthParticleRecoLink = std::make_unique<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>>(
m_muonTruthRecoLink, ctx);
102 if (!muonTruthParticleLink.isValid()) {
104 return StatusCode::FAILURE;
115 bool saw_staco =
false;
116 bool decor_staco =
false;
126 tp =
muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
128 tp =
muon->primaryTrackParticle();
131 bool foundTruth{
false}, setOrigin{
false};
136 if (acc_origin.isAvailable(*tp) && acc_origin(*tp) != 0) {
137 muonTruthParticleOrigin(*
muon) = acc_origin(*tp);
138 muonTruthParticleType(*
muon) = acc_type(*tp);
139 muonTruthParticleClassification(*
muon) = acc_classification(*tp);
144 if (acc_link.isAvailable(*tp)) {
145 truthLink = acc_link(*tp);
147 ATH_MSG_DEBUG(
"Could not find any truth link associated with track having pt:"<<tp->pt()<<
" MeV, eta: "<<tp->eta()<<
", phi: "<<tp->phi()<<
", charge: "<<tp->charge()<<
". d0:"<<tp->d0()<<
", z0: "<<tp->z0());
165 truthParticle->index(),
168 muonTruthParticleLink(*
muon) = muonTruthLink;
170 muonTruthParticleOrigin(*
muon) = acc_origin(*tp);
171 muonTruthParticleType(*
muon) = acc_type(*tp);
172 muonTruthParticleClassification(*
muon) = acc_classification(*tp);
176 if (muonTruthParticleRecoLink && muonTruthParticleRecoLink->operator()(*truthParticle).isValid()){
177 const xAOD::Muon* decor_muon = *muonTruthParticleRecoLink->operator()(*truthParticle);
178 ATH_MSG_VERBOSE(
"Truth particle is already decorated with reco muon "<<decor_muon->
pt()*1.e-3
179 <<
" eta: "<<decor_muon->
eta()<<
" phi: "<<decor_muon->
phi()<<
" charge: "<<
180 decor_muon->
charge()<<
" author: "<<decor_muon->
author()<<
" all authors: "<<
185 ATH_MSG_DEBUG(
"Author of the decorated muon is better than the one of the new candidate");
189 const int com_score = (
muon->allAuthors() & com_bit) - (decor_muon->
allAuthors() &com_bit);
191 ATH_MSG_DEBUG(
"Found two muons reconstructed by an equivalent author. But this one is from the commissioning chain");
202 std::vector<unsigned int> nprecHitsPerChamberLayer(
toInt(ChIndex::ChIndexMax), dummy_unsigned);
203 std::vector<unsigned int> nphiHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
204 std::vector<unsigned int> ntrigEtaHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
206 constexpr int author_sel = (1<<xAOD::Muon::MuidCo) | (1<<xAOD::Muon::MuidSA) | (1<<xAOD::Muon::MuGirl);
210 tp->track(), nprecHitsPerChamberLayer, nphiHitsPerChamberLayer, ntrigEtaHitsPerChamberLayer);
212 muonTruthParticleNPrecMatched(*
muon) = nprecHitsPerChamberLayer;
213 muonTruthParticleNPhiMatched(*
muon) = nphiHitsPerChamberLayer;
214 muonTruthParticleNTrigEtaMatched(*
muon) = ntrigEtaHitsPerChamberLayer;
216 if (muonTruthParticleRecoLink) (*muonTruthParticleRecoLink)(*truthParticle) = muonLink;
223 ATH_MSG_WARNING(
"Could not find the appropiate track particle for muon with pT: " <<
muon->pt() * 1.e-3 <<
" GeV, eta: "
224 <<
muon->eta() <<
", phi: " <<
muon->phi()
225 <<
" author: " <<
muon->author());
229 muonTruthParticleOrigin(*
muon) = 0;
230 muonTruthParticleType(*
muon) = 0;
231 muonTruthParticleClassification(*
muon) = 0;
236 muonTruthParticleNPrecMatched(*
muon) = std::vector<unsigned int>{};
237 muonTruthParticleNPhiMatched(*
muon) = std::vector<unsigned int>{};
238 muonTruthParticleNTrigEtaMatched(*
muon) = std::vector<unsigned int>{};
242 if (
muon->author() == xAOD::Muon::STACO) {
250 decor_staco = !dec_origin.isAvailable (*cmb_trk);
253 dec_origin(*cmb_trk) = acc_origin(*
muon);
254 dec_classification(*cmb_trk) = acc_classification(*
muon);
255 dec_type(*cmb_trk) = acc_type(*
muon);
256 dec_link(*cmb_trk) = acc_link(*
muon);
262 if (muonTruthParticleRecoLink && !muonTruthParticleRecoLink->isAvailable()) {
269 return StatusCode::SUCCESS;
273 std::vector<unsigned int>& nprecHitsPerChamberLayer,
274 std::vector<unsigned int>& nphiHitsPerChamberLayer,
275 std::vector<unsigned int>& ntrigEtaHitsPerChamberLayer)
const {
277 if (!truthParticle || !truthMdtHitsAcc.
isAvailable(*truthParticle)) {
278 ATH_MSG_DEBUG(
"muon has no truth hits vector in the truth association alg");
279 nprecHitsPerChamberLayer.clear();
280 nphiHitsPerChamberLayer.clear();
281 ntrigEtaHitsPerChamberLayer.clear();
284 const std::vector<unsigned long long>& mdtTruth = truthMdtHitsAcc(*truthParticle);
285 std::vector<unsigned long long> cscTruth;
287 if (
m_idHelperSvc->hasCSC()) cscTruth = truthCscHitsAcc(*truthParticle);
288 const std::vector<unsigned long long>& rpcTruth = truthRpcHitsAcc(*truthParticle);
289 const std::vector<unsigned long long>& tgcTruth = truthTgcHitsAcc(*truthParticle);
292 if (!tsit || !tsit->trackParameters() || !tsit->measurementOnTrack())
continue;
308 for (
unsigned int i = 0; i < mdtTruth.size(); ++i) {
309 if (
id == mdtTruth[i]) {
310 if (
chIndex != ChIndex::ChUnknown) {
311 increment_unsigned(nprecHitsPerChamberLayer.at(
toInt(
chIndex)));
317 for (
unsigned int i = 0; i < cscTruth.size(); ++i) {
318 if (
id != cscTruth[i])
continue;
321 if (
index != PhiIndex::PhiUnknown) {
322 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
325 if (
chIndex != ChIndex::ChUnknown) {
326 increment_unsigned(nprecHitsPerChamberLayer.at(
toInt(
chIndex)));
332 for (
unsigned int i = 0; i < rpcTruth.size(); ++i) {
333 if (
id != rpcTruth[i]) {
continue; }
335 if (
index != PhiIndex::PhiUnknown) {
337 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
339 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
toInt(
index)));
345 for (
unsigned int i = 0; i < tgcTruth.size(); ++i) {
346 if (
id != tgcTruth[i]) {
continue; }
348 if (
index != PhiIndex::PhiUnknown) {
350 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
352 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
toInt(
index)));
375 if (identifiers.empty()) {
return; }
376 for (
unsigned int i = 0; i <
vec.size(); ++i) {
377 if (
vec[i] != dummy_unsigned)
continue;
378 for (
unsigned j = 0; j < identifiers.size(); ++j) {
381 const auto phiIdx =
static_cast<PhiIndex>(i);
387 const auto chIdx =
static_cast<ChIndex>(i);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
Helper class to provide constant type-safe access to aux data.
ATLAS-specific HepMC functions.
Handle class for adding a decoration to an object.
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
ElementLink implementation for ROOT usage.
bool toPersistent()
Dummy function provinding the offline interface.
bool isValid() const
Test to see if the link can be dereferenced.
Class for competing MuonClusters, it extends the Trk::CompetingRIOsOnTrack base class.
const std::vector< const MuonClusterOnTrack * > & containedROTs() const
returns the vector of SCT_ClusterOnTrack objects .
SG::ReadHandleKey< xAOD::MuonContainer > m_recoMuKey
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_inputDecorKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleOrigin
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNPhiMatched
Gaudi::Property< bool > m_associateWithInDetTP
StatusCode initialize() override
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_muonTruthRecoLink
Decorations for the filtered muon truth particles.
Gaudi::Property< std::vector< std::string > > m_assocTrkContainers
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleClassification
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleType
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleLink
Decorations for the reconstructed muon particles.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNTrigEtaMatched
void count_chamber_layers(const xAOD::IParticle *truth_particle, const Trk::Track *ptrk, std::vector< unsigned int > &nprecHitsPerChamberLayer, std::vector< unsigned int > &nphiHitsPerChamberLayer, std::vector< unsigned int > &ntrigEtaHitsPerChamberLayer) const
void clear_dummys(const std::vector< unsigned long long > &identifiers, std::vector< unsigned int > &vec) const
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_recoLink
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthMuKey
Key to the filtered muon truth particles.
StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNPrecMatched
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
Helper class to provide type-safe access to aux data.
Handle class for adding a decoration to an object.
This class is the pure abstract base class for all fittable tracking measurements.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
represents the track state (measurement, material, fit parameters and quality) at a surface.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
Class providing the definition of the 4-vector interface.
XAOD_AUXDATA_DEPRECATED bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if a user property is available for reading or not.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
uint16_t allAuthors() const
Get all the authors of this Muon.
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
int authorRank(const xAOD::Muon::Author &a)
ChIndex chIndex(const std::string &index)
convert ChIndex name string to enum
PhiIndex
enum to classify the different phi layers in the muon spectrometer
constexpr int toInt(const EnumType enumVal)
ChIndex
enum to classify the different chamber layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.