ATLAS Offline Software
Loading...
Searching...
No Matches
TrackDetailBranches.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
6
7#ifndef XAOD_ANALYSIS
9#endif
10#include "xAODMuon/Muon.h"
11namespace MuonVal{
12
13 /**********************************************************
14 * TrackChi2Branch
15 **********************************************************/
17 VectorBranch<float>(parent.tree(), parent.name() + "_chi2"),
18 m_nDoF {std::make_shared<VectorBranch<unsigned int>>(parent.tree(), parent.name() + "_nDoF")}
19 {
20 parent.getTree().addBranch(m_nDoF);
21 m_nDoF = parent.getTree().getBranch<VectorBranch<unsigned int>>(m_nDoF->name());
22 }
24 const xAOD::TrackParticle* trk = nullptr;
26 trk = static_cast<const xAOD::TrackParticle*>(p);
27 } else if (p->type() == xAOD::Type::ObjectType::Muon) {
28 trk = static_cast<const xAOD::Muon*>(p)->trackParticle(xAOD::Muon::TrackParticleType::Primary);
29 } else {
30 THROW_EXCEPTION("No track particle object has been given to " <<name());
31 }
32
33 push_back(trk->chiSquared());
34 m_nDoF->push_back(trk->numberDoF());
35 }
39
40#ifndef XAOD_ANALYSIS
41 /**********************************************************
42 * EnergylossBranch
43 **********************************************************/
45 VectorBranch<float>{parent.tree(), std::format("{:}_eLoss",
46 parent.name())} {}
50
52 const xAOD::TrackParticle* trk = nullptr;
54 trk = static_cast<const xAOD::TrackParticle*>(p);
55 } else if (p->type() == xAOD::Type::ObjectType::Muon) {
56 trk = static_cast<const xAOD::Muon*>(p)->trackParticle(xAOD::Muon::TrackParticleType::Primary);
57 } else {
58 THROW_EXCEPTION("No track particle object has been given to " <<name());
59 }
60 const Trk::Track* track = trk->track();
61 if (!track) {
62 ATH_MSG_WARNING("Reconstructed track is not available "<<name());
63 push_back(0.f);
64 return;
65 }
66 const Trk::TrackParameters* parsFirst{nullptr}, *parsLast{nullptr};
67 for (const Trk::TrackStateOnSurface* tsos : *track->trackStateOnSurfaces()) {
68 if (!tsos->measurementOnTrack()) {
69 continue;
70 }
71 if (!parsFirst) {
72 parsFirst = tsos->trackParameters();
73 }
74 parsLast = tsos->trackParameters();
75 }
76 assert(parsFirst != nullptr);
77 assert(parsLast != nullptr);
79 push_back((parsLast->momentum().mag() - parsFirst->momentum().mag())* 1.e-3);
80
81 }
82
83 /**********************************************************
84 * ScatteringBranch
85 **********************************************************/
87 Base_t{parent.tree(), std::format("{:}_scatPhi", parent.name())},
88 m_deltaTheta{std::make_unique<Base_t>(parent.tree(), std::format("{:}_scatTheta", parent.name()))},
89 m_sigmaPhi{std::make_unique<Base_t>(parent.tree(), std::format("{:}_scatSigmaPhi", parent.name()))},
90 m_sigmaTheta{std::make_unique<Base_t>(parent.tree(),std::format("{:}_scatSigmaTheta", parent.name()))},
91 m_nScat{std::make_unique<VectorBranch<std::uint8_t>>(parent.tree(), std::format("{:}_nScatters", parent.name()))}{
92 parent.getTree().addBranch(m_deltaTheta);
93 parent.getTree().addBranch(m_sigmaPhi);
94 parent.getTree().addBranch(m_sigmaTheta);
95 parent.getTree().addBranch(m_nScat);
96 m_deltaTheta = parent.getTree().getBranch<Base_t>(m_deltaTheta->name());
97 m_sigmaPhi = parent.getTree().getBranch<Base_t>(m_sigmaPhi->name());
98 m_sigmaTheta = parent.getTree().getBranch<Base_t>(m_sigmaTheta->name());
99 m_nScat = parent.getTree().getBranch<VectorBranch<std::uint8_t>>(m_nScat->name());
100 }
104
106 const xAOD::TrackParticle* trk = nullptr;
107 if (p->type() == xAOD::Type::ObjectType::TrackParticle) {
108 trk = static_cast<const xAOD::TrackParticle*>(p);
109 } else if (p->type() == xAOD::Type::ObjectType::Muon) {
110 trk = static_cast<const xAOD::Muon*>(p)->trackParticle(xAOD::Muon::TrackParticleType::Primary);
111 } else {
112 THROW_EXCEPTION("No track particle object has been given to " <<name());
113 }
114 std::vector<float> dPhi{}, dTheta{}, sigPhi{}, sigTheta{};
115 if (const Trk::Track* track = trk->track(); track != nullptr) {
116 for (const Trk::TrackStateOnSurface* tsos : *track->trackStateOnSurfaces()) {
117 const auto* angles = dynamic_cast<const Trk::ScatteringAngles*>(tsos->materialEffectsOnTrack());
118 if (!angles) {
119 continue;
120 }
121 dPhi.push_back(angles->deltaPhi());
122 dTheta.push_back(angles->deltaTheta());
123 sigPhi.push_back(angles->sigmaDeltaPhi());
124 sigTheta.push_back(angles->sigmaDeltaTheta());
125 }
126 }
127 push_back(std::move(dPhi));
128 m_deltaTheta->push_back(std::move(dTheta));
129 m_sigmaPhi->push_back(std::move(sigPhi));
130 m_sigmaTheta->push_back(std::move(sigTheta));
131 }
132#endif
133}
#define ATH_MSG_WARNING(x)
void operator+=(const xAOD::IParticle *p) override
EnergylossBranch(IParticleFourMomBranch &parent)
void push_back(const xAOD::IParticle *p) override
Similar to the IAuxElementDecoration branch but only accepting IParticles.
Helper class to easily to add xAOD::IParticles and associated decorator variables to the MuonTesterTr...
std::string name() const override final
TTree * tree() override final
void push_back(const xAOD::IParticle *p) override
Similar to the IAuxElementDecoration branch but only accepting IParticles.
std::shared_ptr< VectorBranch< std::uint8_t > > m_nScat
std::shared_ptr< Base_t > m_sigmaTheta
void operator+=(const xAOD::IParticle *p) override
ScatteringBranch(IParticleFourMomBranch &parent)
std::shared_ptr< Base_t > m_deltaTheta
std::shared_ptr< Base_t > m_sigmaPhi
MatrixBranch< float > Base_t
void operator+=(const xAOD::IParticle *p) override
std::shared_ptr< VectorBranch< unsigned int > > m_nDoF
void push_back(const xAOD::IParticle *p) override
Similar to the IAuxElementDecoration branch but only accepting IParticles.
TrackChi2Branch(IParticleFourMomBranch &parent)
VectorBranch(TTree *tree, const std::string &name)
const Amg::Vector3D & momentum() const
Access method for the momentum.
represents a deflection of the track caused through multiple scattering in material.
represents the track state (measurement, material, fit parameters and quality) at a surface.
Class providing the definition of the 4-vector interface.
float numberDoF() const
Returns the number of degrees of freedom of the overall track or vertex fit as float.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
float chiSquared() const
Returns the of the overall track fit.
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19
ParametersBase< TrackParametersDim, Charged > TrackParameters
STL namespace.
@ TrackParticle
The object is a charged track particle.
Definition ObjectType.h:43
@ Muon
The object is a muon.
Definition ObjectType.h:48
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10