20 constexpr unsigned int dummy_unsigned = 999;
21 void increment_unsigned(
unsigned& val) {
22 if (val == dummy_unsigned)
87 return StatusCode::SUCCESS;
94 std::unique_ptr<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>> muonTruthParticleRecoLink{};
96 muonTruthParticleRecoLink = std::make_unique<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>>(
m_muonTruthRecoLink, ctx);
101 if (!muonTruthParticleLink.isValid()) {
103 return StatusCode::FAILURE;
114 bool saw_staco =
false;
115 bool decor_staco =
false;
126 using enum xAOD::Muon::TrackParticleType;
127 tp =
muon->trackParticle(useID ?InnerDetectorTrackParticle : Primary);
129 bool foundTruth{
false}, setOrigin{
false};
134 if (acc_origin.isAvailable(*tp) && acc_origin(*tp) != 0) {
135 muonTruthParticleOrigin(*
muon) = acc_origin(*tp);
136 muonTruthParticleType(*
muon) = acc_type(*tp);
137 muonTruthParticleClassification(*
muon) = acc_classification(*tp);
142 if (acc_link.isAvailable(*tp)) {
143 truthLink = acc_link(*tp);
145 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());
163 truthParticle->index(),
166 muonTruthParticleLink(*
muon) = muonTruthLink;
168 muonTruthParticleOrigin(*
muon) = acc_origin(*tp);
169 muonTruthParticleType(*
muon) = acc_type(*tp);
170 muonTruthParticleClassification(*
muon) = acc_classification(*tp);
174 if (muonTruthParticleRecoLink && muonTruthParticleRecoLink->operator()(*truthParticle).isValid()){
175 const xAOD::Muon* decor_muon = *muonTruthParticleRecoLink->operator()(*truthParticle);
176 ATH_MSG_VERBOSE(
"Truth particle is already decorated with reco muon "<<decor_muon->
pt()*1.e-3
177 <<
" eta: "<<decor_muon->
eta()<<
" phi: "<<decor_muon->
phi()<<
" charge: "<<
178 decor_muon->
charge()<<
" author: "<<decor_muon->
author()<<
" all authors: "<<
183 ATH_MSG_DEBUG(
"Author of the decorated muon is better than the one of the new candidate");
194 std::vector<unsigned int> nprecHitsPerChamberLayer(
toInt(ChIndex::ChIndexMax), dummy_unsigned);
195 std::vector<unsigned int> nphiHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
196 std::vector<unsigned int> ntrigEtaHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
198 constexpr std::array<xAOD::Muon::Author, 3> author_sel{xAOD::Muon::Author::MuidCo,
199 xAOD::Muon::Author::MuidSA,
200 xAOD::Muon::Author::MuGirl};
204 tp->
track(), nprecHitsPerChamberLayer, nphiHitsPerChamberLayer, ntrigEtaHitsPerChamberLayer);
206 muonTruthParticleNPrecMatched(*
muon) = nprecHitsPerChamberLayer;
207 muonTruthParticleNPhiMatched(*
muon) = nphiHitsPerChamberLayer;
208 muonTruthParticleNTrigEtaMatched(*
muon) = ntrigEtaHitsPerChamberLayer;
210 if (muonTruthParticleRecoLink) (*muonTruthParticleRecoLink)(*truthParticle) = muonLink;
217 ATH_MSG_WARNING(
"Could not find the appropiate track particle for muon with pT: " <<
muon->pt() * 1.e-3 <<
" GeV, eta: "
218 <<
muon->eta() <<
", phi: " <<
muon->phi()
219 <<
" author: " <<
muon->author());
223 muonTruthParticleOrigin(*
muon) = 0;
224 muonTruthParticleType(*
muon) = 0;
225 muonTruthParticleClassification(*
muon) = 0;
230 muonTruthParticleNPrecMatched(*
muon) = std::vector<unsigned int>{};
231 muonTruthParticleNPhiMatched(*
muon) = std::vector<unsigned int>{};
232 muonTruthParticleNTrigEtaMatched(*
muon) = std::vector<unsigned int>{};
236 if (
muon->author() == xAOD::Muon::Author::STACO) {
244 decor_staco = !dec_origin.isAvailable (*cmb_trk);
247 dec_origin(*cmb_trk) = acc_origin(*
muon);
248 dec_classification(*cmb_trk) = acc_classification(*
muon);
249 dec_type(*cmb_trk) = acc_type(*
muon);
250 dec_link(*cmb_trk) = acc_link(*
muon);
256 if (muonTruthParticleRecoLink && !muonTruthParticleRecoLink->isAvailable()) {
263 return StatusCode::SUCCESS;
267 std::vector<unsigned int>& nprecHitsPerChamberLayer,
268 std::vector<unsigned int>& nphiHitsPerChamberLayer,
269 std::vector<unsigned int>& ntrigEtaHitsPerChamberLayer)
const {
271 if (!truthParticle || !truthMdtHitsAcc.
isAvailable(*truthParticle)) {
272 ATH_MSG_DEBUG(
"muon has no truth hits vector in the truth association alg");
273 nprecHitsPerChamberLayer.clear();
274 nphiHitsPerChamberLayer.clear();
275 ntrigEtaHitsPerChamberLayer.clear();
278 const std::vector<unsigned long long>& mdtTruth = truthMdtHitsAcc(*truthParticle);
279 std::vector<unsigned long long> cscTruth;
281 if (
m_idHelperSvc->hasCSC()) cscTruth = truthCscHitsAcc(*truthParticle);
282 const std::vector<unsigned long long>& rpcTruth = truthRpcHitsAcc(*truthParticle);
283 const std::vector<unsigned long long>& tgcTruth = truthTgcHitsAcc(*truthParticle);
286 if (!tsit || !tsit->trackParameters() || !tsit->measurementOnTrack())
continue;
302 for (
unsigned int i = 0; i < mdtTruth.size(); ++i) {
303 if (
id == mdtTruth[i]) {
304 if (
chIndex != ChIndex::ChUnknown) {
305 increment_unsigned(nprecHitsPerChamberLayer.at(
toInt(
chIndex)));
311 for (
unsigned int i = 0; i < cscTruth.size(); ++i) {
312 if (
id != cscTruth[i])
continue;
315 if (
index != PhiIndex::PhiUnknown) {
316 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
319 if (
chIndex != ChIndex::ChUnknown) {
320 increment_unsigned(nprecHitsPerChamberLayer.at(
toInt(
chIndex)));
326 for (
unsigned int i = 0; i < rpcTruth.size(); ++i) {
327 if (
id != rpcTruth[i]) {
continue; }
329 if (
index != PhiIndex::PhiUnknown) {
331 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
333 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
toInt(
index)));
339 for (
unsigned int i = 0; i < tgcTruth.size(); ++i) {
340 if (
id != tgcTruth[i]) {
continue; }
342 if (
index != PhiIndex::PhiUnknown) {
344 increment_unsigned(nphiHitsPerChamberLayer.at(
toInt(
index)));
346 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
toInt(
index)));
369 if (identifiers.empty()) {
return; }
370 for (
unsigned int i = 0; i <
vec.size(); ++i) {
371 if (
vec[i] != dummy_unsigned)
continue;
372 for (
unsigned j = 0; j < identifiers.size(); ++j) {
375 const auto phiIdx =
static_cast<PhiIndex>(i);
381 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
Check if the element can be found.
Class for competing MuonClusters, it extends the Trk::CompetingRIOsOnTrack base class.
const std::vector< std::unique_ptr< 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.
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 pt() const override
The transverse momentum ( ) of the particle.
virtual double eta() const override
The pseudorapidity ( ) of the particle.
virtual double phi() const override
The azimuthal angle ( ) of the particle.
uint16_t allAuthors() const
Get all the authors of this Muon.
float z0() const
Returns the parameter.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
float d0() const
Returns the parameter.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float charge() const
Returns the charge.
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.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
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.