ATLAS Offline Software
Loading...
Searching...
No Matches
TestMacroHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4
5#ifndef XAOD_STANDALONE
11#include <xAODEgamma/Electron.h>
12#include <xAODMuon/Muon.h>
16namespace CP {
17
22
27
28 //############################################################################
29 // IsoCorrectionTestHelper
30 //############################################################################
31 bool IsoCorrectionTestHelper::init() { return true; }
32 bool IsoCorrectionTestHelper::fill(const EventContext&) { return true; }
35 const std::vector<std::unique_ptr<IsolationWP>>& WPs) :
36 MuonTesterBranch(outTree, ContainerName),
37 m_cont_name{ContainerName} {
38 // Retrieve the isolaiton accessors directly from the WP
39 for (const std::unique_ptr<IsolationWP>& W : WPs) {
40 for (const auto& C : W->conditions()) {
41 for (unsigned int t = 0; t < C->num_types(); ++t) {
42 const IsoType iso_type = C->type(t);
43 bool add = std::find_if(m_iso_branches.begin(), m_iso_branches.end(), [iso_type](const IsolationBranches& known) {
44 return known.Accessor->isotype() == iso_type;
45 }) == m_iso_branches.end();
46 if (add) m_iso_branches.emplace_back(*this, iso_type, "");
47 }
48 }
49 // Assume only 1 WP
50 break;
51 }
52 }
53 void IsoCorrectionTestHelper::SetClusters(const ClusterSet& clusters) { m_clusters = clusters; }
55 m_acc_used_for_corr = std::make_optional<CharAccessor>(acc);
56 }
58 m_acc_passDefault = std::make_optional<CharAccessor>(acc);
59 }
61 m_acc_passCorrected = std::make_optional<CharAccessor>(acc);
62 }
63 void IsoCorrectionTestHelper::SetBackupPreFix(const std::string& prefix) {
64 for (IsolationBranches& branch : m_iso_branches) {
65 branch.Accessor = std::make_unique<IsoVariableHelper>(branch.Accessor->isotype(), prefix);
66 }
67 }
68
70 if (!Particles) {
71 Error("IsoCorrectionTestHelper::Fill()", "No particles given");
72 return StatusCode::FAILURE;
73 }
74
75 for (const xAOD::IParticle* object : *Particles) {
76 if (m_acc_used_for_corr != std::nullopt && (!(*m_acc_used_for_corr).isAvailable(*object) || !(*m_acc_used_for_corr)(*object)))
77 continue;
78 m_pt.push_back(object->pt());
79 m_eta.push_back(object->eta());
80 m_phi.push_back(object->phi());
81 m_e.push_back(object->e());
82 m_Q.push_back(Charge(object));
83 for (IsolationBranches& branch : m_iso_branches) {
84 if (!FillIsolationBranches(object, branch.Accessor, branch.original_cones, branch.corrected_cones).isSuccess()) {
85 Error("IsoCorrectionTestHelper()", "Failed to fill isolation");
86 return StatusCode::FAILURE;
87 }
88 }
89 if (m_acc_passDefault != std::nullopt && !(*m_acc_passDefault).isAvailable(*object)) {
90 Error("IsoCorrectionTestHelper()", "It has not been stored whether the particle passes the default isolation");
91 return StatusCode::FAILURE;
92 } else
93 m_orig_passIso.push_back(m_acc_passDefault != std::nullopt ? (*m_acc_passDefault)(*object) : false);
94
95 if (m_acc_passCorrected != std::nullopt && !(*m_acc_passCorrected).isAvailable(*object)) {
96 Error("IsoCorrectionTestHelper()", "It has not been stored whether the particle passes the corrected isolation.");
97 return StatusCode::FAILURE;
98 } else
99 m_corr_passIso.push_back(m_acc_passCorrected != std::nullopt ? (*m_acc_passCorrected)(*object) : false);
101 if (object->type() != xAOD::Type::ObjectType::Electron && object->type() != xAOD::Type::ObjectType::Muon) continue;
102
103 const xAOD::TrackParticle* assoc_track = nullptr;
104 CaloClusterPtr assoc_cluster{};
105 FlowElementPtr assoc_flow{};
106 if (object->type() == xAOD::Type::ObjectType::Muon) {
107 const xAOD::Muon* mu = dynamic_cast<const xAOD::Muon*>(object);
108 assoc_track = mu->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
109 if (m_clusters.empty())
110 assoc_cluster = mu->cluster();
111 else {
112 assoc_cluster = (*std::min_element(m_clusters.begin(), m_clusters.end(),[mu](const CaloClusterPtr& a, const
113 CaloClusterPtr& b){
114 return xAOD::P4Helpers::deltaR2(a, mu) < xAOD::P4Helpers::deltaR2(b, mu);
115 }));
116 }
117 } else if (object->type() == xAOD::Type::ObjectType::Electron) {
118 const xAOD::Electron* el = dynamic_cast<const xAOD::Electron*>(object);
120 assoc_cluster = el->caloCluster(0);
121 }
122 if (!m_flows.empty()) {
123 assoc_flow = (*std::min_element(m_flows.begin(), m_flows.end(),[object](const FlowElementPtr& a, const
124 FlowElementPtr& b){
125 return xAOD::P4Helpers::deltaR2(a, object) < xAOD::P4Helpers::deltaR2(b, object);
126 }));
127 }
128 m_assoc_track_pt.push_back(assoc_track ? assoc_track->pt() : FLT_MAX);
129
130 if (acc_assocCaloIsDec.isAvailable(*object) && acc_assocCaloIsDec(*object)) {
131 m_assoc_cluster_et.push_back(acc_assocClustEne(*object));
132 m_assoc_cluster_eta.push_back(acc_assocClustEta(*object));
133 m_assoc_cluster_phi.push_back(acc_assocClustPhi(*object));
134 } else if (assoc_cluster) {
136 m_assoc_cluster_eta.push_back(assoc_cluster->eta());
137 m_assoc_cluster_phi.push_back(assoc_cluster->phi());
138 } else {
139 m_assoc_cluster_et += FLT_MAX;
140 m_assoc_cluster_eta += FLT_MAX;
141 m_assoc_cluster_phi += FLT_MAX;
142 }
143 if (acc_assocPflowIsDec.isAvailable(*object) && acc_assocPflowIsDec(*object)) {
144 m_assoc_pflow_et.push_back( acc_assocPflowEne(*object));
145 m_assoc_pflow_eta.push_back(acc_assocPflowEta(*object));
146 m_assoc_pflow_phi.push_back(acc_assocPflowPhi(*object));
147 } else if (assoc_flow) {
148 m_assoc_pflow_et.push_back(assoc_flow->e() * assoc_flow.weight);
149 m_assoc_pflow_eta.push_back(assoc_flow->eta());
150 m_assoc_pflow_phi.push_back(assoc_flow->phi());
151 } else {
152 m_assoc_pflow_et += FLT_MAX;
153 m_assoc_pflow_eta += FLT_MAX;
154 m_assoc_pflow_phi += FLT_MAX;
155 }
156 }
157 return StatusCode::SUCCESS;
158 }
160 static const FloatAccessor acc_charge("charge");
161 if (!acc_charge.isAvailable(*P))
162 return 0;
163 else
164 return acc_charge(*P);
165 }
166
169 if (!Acc) return StatusCode::SUCCESS;
170 float IsoValue{-1.};
171 if (Acc->getOriginalIsolation(P, IsoValue).code() != CorrectionCode::Ok) return StatusCode::FAILURE;
172 Original.push_back(IsoValue);
173 if (Acc->getIsolation(P, IsoValue).code() != CorrectionCode::Ok) return StatusCode::FAILURE;
174 Corrected.push_back(IsoValue);
175 return StatusCode::SUCCESS;
176 }
177} // namespace CP
178#endif
static Double_t a
static Double_t P(Double_t *tt, Double_t *par)
@ Ok
The correction was done successfully.
MuonVal::VectorBranch< float > & m_assoc_track_pt
bool init() override final
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
MuonVal::VectorBranch< bool > & m_orig_passIso
IsoCorrectionTestHelper(MuonVal::MuonTesterTree &outTree, const std::string &ContainerName, const std::vector< std::unique_ptr< IsolationWP > > &WP)
MuonVal::VectorBranch< float > & m_assoc_pflow_phi
MuonVal::VectorBranch< float > & m_assoc_cluster_phi
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
MuonVal::VectorBranch< float > & m_e
void SetIsolationDecorator(const std::string &acc)
Pipe the name of te decorator encoding whether the object already passed the vanilla isolation.
void SetClusters(const ClusterSet &clusters)
set the list of all clusters from the Cluster container matched by the IsolationCloseByCorrectionTool...
MuonVal::VectorBranch< float > & m_assoc_pflow_eta
MuonVal::VectorBranch< int > & m_Q
MuonVal::VectorBranch< float > & m_assoc_cluster_eta
MuonVal::VectorBranch< float > & m_pt
std::optional< CharAccessor > m_acc_used_for_corr
void SetFlowElements(const PflowSet &flows)
MuonVal::VectorBranch< bool > & m_corr_passIso
MuonVal::VectorBranch< float > & m_phi
StatusCode FillIsolationBranches(const xAOD::IParticle *P, const IsoHelperPtr &Acc, MuonVal::VectorBranch< float > &Original, MuonVal::VectorBranch< float > &Corrected)
StatusCode Fill(const xAOD::IParticleContainer *Particles)
MuonVal::VectorBranch< float > & m_assoc_cluster_et
void SetUpdatedIsoDecorator(const std::string &acc)
Pipe the name of te decorator encoding whether the object already passed the corrected isolation.
std::optional< CharAccessor > m_acc_passCorrected
MuonVal::VectorBranch< float > & m_eta
std::optional< CharAccessor > m_acc_passDefault
void SetSelectionDecorator(const std::string &acc)
Pipe the name of the decorator selecting the objects dumped to the TTree.
float Charge(const xAOD::IParticle *P) const
std::vector< IsolationBranches > m_iso_branches
MuonVal::VectorBranch< float > & m_assoc_pflow_et
void SetBackupPreFix(const std::string &prefix)
Specify whether the vanilla isolation variable is backuped to another set of decorators.
static const caloDecorNames & caloDecors()
Returns an array with the calo cluster decoration names [0]-> eta, [1]->phi, [2]->energy....
static float clusterEtMinusTile(const xAOD::CaloCluster *C)
MuonTesterBranch(MuonTesterTree &tree, const std::string &br_name)
void push_back(const T &value)
Adds a new element at the end of the vector.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double phi() const override
The azimuthal angle ( ) of the particle.
virtual double eta() const override
The pseudorapidity ( ) of the particle.
virtual double e() const override
The total energy of the particle.
Class providing the definition of the 4-vector interface.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
struct color C
Select isolated Photons, Electrons and Muons.
std::unique_ptr< IsoVariableHelper > IsoHelperPtr
static const FloatAccessor acc_assocClustPhi
static const FloatAccessor acc_assocClustEta
static const CharAccessor acc_assocPflowIsDec
static const FloatAccessor acc_assocPflowEta
static const CharAccessor acc_assocCaloIsDec
static const FloatAccessor acc_assocPflowPhi
static const FloatAccessor acc_assocClustEne
static const FloatAccessor acc_assocPflowEne
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
Electron_v1 Electron
Definition of the current "egamma version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
For the flow elements we need a special derivate which also contains the weights.