ATLAS Offline Software
MuonRecoChainTester.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 // Framework includes
5 #include "MuonRecoChainTester.h"
6 
13 #include "StoreGate/ReadHandle.h"
14 
15 using namespace MuonVal;
16 using namespace MuonPRDTest;
17 
18 
19 namespace {
20 template <class RefPartType, class SearchPartType>
21  const SearchPartType* findClosestParticle(const RefPartType* reference,
22  const DataVector<SearchPartType>& candidateContainer) {
23  const SearchPartType* best{nullptr};
24  for (const SearchPartType* candidate : candidateContainer) {
25  if (!best || xAOD::P4Helpers::deltaR2(reference, candidate) <
27  best = candidate;
28  }
29  }
30  return best;
31  }
32 
33 }
34 namespace MuonValR4{
35 
36  MuonRecoChainTester::MuonRecoChainTester(const std::string& name, ISvcLocator* pSvcLocator):
37  AthHistogramAlgorithm{name, pSvcLocator}{}
38 
40  int evOpts{0};
41  if (m_isMC) evOpts |= EventInfoBranch::isMC;
42  m_tree.addBranch(std::make_shared<EventInfoBranch>(m_tree, evOpts));
43 
44  m_tree.addBranch(std::make_shared<SegmentVariables>(m_tree, m_legacySegmentKey, "LegacySegments", msgLevel()));
45  m_tree.addBranch(std::make_shared<SegmentVariables>(m_tree, m_r4PatternSegmentKey, "HoughSegments", msgLevel()));
46  m_tree.addBranch(std::make_shared<SegmentVariables>(m_tree, m_segmentKeyR4, "SegmentsR4", msgLevel()));
47  if (m_isMC) {
48  m_tree.addBranch(std::make_shared<SegmentVariables>(m_tree, m_truthSegmentKey, "TruthSegments", msgLevel()));
49  }
50 
55 
56  m_legacyTrks = std::make_shared<IParticleFourMomBranch>(m_tree, "LegacyMSTrks");
57  m_legacyTrks->addVariable(std::make_shared<TrackChi2Branch>(*m_legacyTrks));
58  m_TrksHoughR4 = std::make_shared<IParticleFourMomBranch>(m_tree, "HoughMSTrks");
59  m_TrksHoughR4->addVariable(std::make_shared<TrackChi2Branch>(*m_TrksHoughR4));
60 
61  m_TrksSegmentR4 = std::make_shared<IParticleFourMomBranch>(m_tree, "MSTrksR4");
62  m_TrksSegmentR4->addVariable(std::make_shared<TrackChi2Branch>(*m_TrksSegmentR4));
63 
67 
68  if (m_isMC) {
69  m_truthTrks = std::make_shared<IParticleFourMomBranch>(m_tree, "TruthMuons");
70  m_truthTrks->addVariable<int>("legacyMatched");
71  m_truthTrks->addVariable<int>("houghMatched");
72  m_truthTrks->addVariable<int>("r4Matched");
73 
75  }
76  ATH_CHECK(m_tree.init(this));
77  return StatusCode::SUCCESS;
78  }
80 
81  static const SG::Decorator<int> acc_legacyMatched{"legacyMatched"};
82  static const SG::Decorator<int> acc_houghMatched{"houghMatched"};
83  static const SG::Decorator<int> acc_r4Matched{"r4Matched"};
84 
85  const EventContext& ctx{Gaudi::Hive::currentContext()};
87  ATH_CHECK(legacyTrks.isPresent());
89  ATH_CHECK(trksFromHoughR4.isPresent());
91  ATH_CHECK(trksR4.isPresent());
92 
93  for (const xAOD::TrackParticle* trk : *legacyTrks) {
94  m_legacyTrks->push_back(trk);
95  }
96  for (const xAOD::TrackParticle* trk : *trksR4) {
97  m_TrksSegmentR4->push_back(trk);
98  }
99  for (const xAOD::TrackParticle* trk : *trksFromHoughR4) {
100  m_TrksHoughR4->push_back(trk);
101  }
102 
104  if (!m_truthKey.empty()) {
106  ATH_CHECK(readHandle.isPresent());
107  for (const xAOD::TruthParticle* truth : *readHandle) {
108  if (!truth->isMuon()) continue;
109  if (truth->status() != 1) continue;
110  truthParts.push_back(truth);
111  }
112  }
113  constexpr double matchDR = 0.05;
114  for (const xAOD::TruthParticle* truth : truthParts){
115  const xAOD::TrackParticle* closestLeg = findClosestParticle(truth, *legacyTrks);
116  const xAOD::TrackParticle* closestHoughR4 = findClosestParticle(truth, *trksFromHoughR4);
117  const xAOD::TrackParticle* closestR4 = findClosestParticle(truth, *trksR4);
118  acc_legacyMatched(*truth) = closestLeg && xAOD::P4Helpers::deltaR(truth, closestLeg) < matchDR?
119  static_cast<int>(m_legacyTrks->find(closestLeg)) : -1;
120  acc_houghMatched(*truth) = closestHoughR4 && xAOD::P4Helpers::deltaR(truth, closestHoughR4) < matchDR ?
121  static_cast<int>(m_TrksHoughR4->find(closestHoughR4)) : -1;
122  acc_r4Matched(*truth) = closestR4 && xAOD::P4Helpers::deltaR(truth, closestR4) < matchDR ?
123  static_cast<int>(m_TrksSegmentR4->find(closestR4)) : -1;
124  m_truthTrks->push_back(truth);
125  }
126 
127 
128  if(!m_tree.fill(ctx)) {
129  return StatusCode::FAILURE;
130  }
131  return StatusCode::SUCCESS;
132  }
135  return StatusCode::SUCCESS;
136  }
137 }
MuonValR4::MuonRecoChainTester::m_TrksSegmentR4
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_TrksSegmentR4
Definition: MuonRecoChainTester.h:53
MuonVal::MuonTesterTree::init
StatusCode init(OWNER *instance)
Initialize method.
MuonRecoChainTester.h
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
MuonVal::EventInfoBranch::isMC
@ isMC
Flag determining whether the branch is simulation.
Definition: EventInfoBranch.h:20
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
MuonValR4::MuonRecoChainTester::m_TrackKeyR4
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackKeyR4
Definition: MuonRecoChainTester.h:46
ParticleVariables.h
EventInfoBranch.h
reference
Definition: hcg.cxx:437
MuonValR4::MuonRecoChainTester::m_legacySegmentKey
Gaudi::Property< std::string > m_legacySegmentKey
Keys to the segment collections.
Definition: MuonRecoChainTester.h:36
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MuonValR4::MuonRecoChainTester::m_truthKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
Key to the truth particle collection.
Definition: MuonRecoChainTester.h:49
TrackChi2Branch.h
MuonValR4::MuonRecoChainTester::finalize
virtual StatusCode finalize() override
Definition: MuonRecoChainTester.cxx:133
SG::Decorator< int >
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
MuonValR4::MuonRecoChainTester::m_TrackKeyHoughR4
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackKeyHoughR4
Definition: MuonRecoChainTester.h:45
MuonValR4::MuonRecoChainTester::m_truthSegmentKey
Gaudi::Property< std::string > m_truthSegmentKey
Segment from the truth hits.
Definition: MuonRecoChainTester.h:42
python.utils.best
def best(iterable, priorities=[3, 2, 1, -1, 0])
Definition: DataQuality/DQUtils/python/utils.py:50
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MuonValR4::MuonRecoChainTester::m_TrksHoughR4
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_TrksHoughR4
Definition: MuonRecoChainTester.h:52
AthHistogramAlgorithm
Definition: AthHistogramAlgorithm.h:32
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonValR4
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Definition: IPatternVisualizationTool.h:23
MuonValR4::MuonRecoChainTester::m_legacyTrks
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_legacyTrks
Definition: MuonRecoChainTester.h:51
MuonValR4::MuonRecoChainTester::m_segmentKeyR4
Gaudi::Property< std::string > m_segmentKeyR4
Segments made from the R4 segment maker.
Definition: MuonRecoChainTester.h:40
MuonVal
Class to store array like branches into the n-tuples.
Definition: MuonTPMetaDataAlg.cxx:25
MuonValR4::MuonRecoChainTester::m_truthTrks
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_truthTrks
Definition: MuonRecoChainTester.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonValR4::MuonRecoChainTester::m_isMC
Gaudi::Property< bool > m_isMC
Definition: MuonRecoChainTester.h:31
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
MuonPRDTest
Definition: CSCDigitVariables.h:10
MuonValR4::MuonRecoChainTester::initialize
virtual StatusCode initialize() override
Definition: MuonRecoChainTester.cxx:39
MuonValR4::MuonRecoChainTester::m_r4PatternSegmentKey
Gaudi::Property< std::string > m_r4PatternSegmentKey
Segments seeded from the R4 pattern but made with the legacy segment maker.
Definition: MuonRecoChainTester.h:38
SegmentVariables.h
MuonVal::MuonTesterTree::fill
bool fill(const EventContext &ctx)
Fills the tree per call.
Definition: MuonTesterTree.cxx:89
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
MuonValR4::MuonRecoChainTester::m_tree
MuonVal::MuonTesterTree m_tree
Definition: MuonRecoChainTester.h:29
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ReadHandle.h
Handle class for reading from StoreGate.
MuonValR4::MuonRecoChainTester::execute
virtual StatusCode execute() override
Definition: MuonRecoChainTester.cxx:79
MuonValR4::MuonRecoChainTester::m_legacyTrackKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_legacyTrackKey
Key to the track collections.
Definition: MuonRecoChainTester.h:44
MuonVal::MuonTesterTree::addBranch
bool addBranch(std::shared_ptr< IMuonTesterBranch > branch)
Branch is added to the tree without transferring the ownership.
Definition: MuonTesterTree.cxx:61