ATLAS Offline Software
Loading...
Searching...
No Matches
ParticleJetDeltaRLabelTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "AsgMessaging/Check.h"
11
12using namespace std;
13using namespace xAOD;
14
16 : AsgTool(name) {
17 declareProperties(*this, &m_labelnames);
18 declareProperty("BLabelName", m_bottomlabelname="ConeExclBHadronsFinal", "Name of the attribute to be added for matched B hadrons.");
19 declareProperty("CLabelName", m_charmlabelname="ConeExclCHadronsFinal", "Name of the attribute to be added for matched C hadrons.");
20 declareProperty("TauLabelName", m_taulabelname="ConeExclTausFinal", "Name of the attribute to be added for matched taus.");
21 declareProperty("PartPtMin", m_partptmin=5000, "Minimum pT of particles for labeling (MeV)");
22 declareProperty("JetPtMin", m_jetptmin=10000, "Minimum pT of jets to be lebeled (MeV)");
23 declareProperty("DRMax", m_drmax=0.3, "Maximum deltaR between a particle and jet to be labeled");
24 declareProperty("MatchMode", m_matchmode="MinDR",
25 "In the case that a particle matches two jets, the closest (MatchMode=MinDR) or highest-pT (MatchMode=MaxPt) jet will be labeled");
26}
27
28
30
31 m_labelnames.check();
32
33 // initialize keys
37 ATH_CHECK(m_truthEventsKey.initialize());
38
39 // get the keys to the containers we just read, to build element
40 // links later
45
46 // build label decorators
48
49 return StatusCode::SUCCESS;
50}
51
52
54
55 namespace pjt = ParticleJetTools;
56
57 ATH_MSG_VERBOSE("In " << name() << "::modify()");
58
59 // Retrieve the particle and jet containers
64
65 if (!truthtausReadHandle.isValid()){
66 ATH_MSG_ERROR(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthtausReadHandle.key());
67 return StatusCode::FAILURE;
68 }
69
70 if (!truthbsReadHandle.isValid()){
71 ATH_MSG_ERROR(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthbsReadHandle.key());
72 return StatusCode::FAILURE;
73 }
74
75 if (!truthcsReadHandle.isValid()){
76 ATH_MSG_ERROR(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthcsReadHandle.key());
77 return StatusCode::FAILURE;
78 }
79
80 if (!truthEventsHandle.isValid()){
81 ATH_MSG_ERROR(" Invalid ReadHandle for TruthEvents with key: " << truthEventsHandle.key());
82 return StatusCode::FAILURE;
83 }
84
85 vector<vector<const TruthParticle*> > jetlabelpartsb = match(*truthbsReadHandle, jets);
86 vector<vector<const TruthParticle*> > jetlabelpartsc = match(*truthcsReadHandle, jets);
87 vector<vector<const TruthParticle*> > jetlabelpartstau = match(*truthtausReadHandle, jets);
88
89 Amg::Vector3D origin = pjt::signalProcessP3(*truthEventsHandle);
90
91 for (unsigned int iJet = 0; iJet < jets.size(); iJet++) {
92 // remove children whose parent hadrons are also in the jet.
93 // don't care about double tau jets
94 // so leave them for now.
95
97 childrenRemoved(jetlabelpartsb[iJet], jetlabelpartsb[iJet]);
98 childrenRemoved(jetlabelpartsb[iJet], jetlabelpartsc[iJet]);
99 childrenRemoved(jetlabelpartsc[iJet], jetlabelpartsc[iJet]);
100
101
102 const Jet& jet = *jets.at(iJet);
103
104 m_blinker->decorate(jet, jetlabelpartsb.at(iJet));
105 m_clinker->decorate(jet, jetlabelpartsc.at(iJet));
106 m_taulinker->decorate(jet, jetlabelpartstau.at(iJet));
107
108 // set truth label to -99 for jets below pt threshold
109 if (jet.pt() < m_jetptmin) {
110 m_labeldecs->singleint(jet) = -99;
111 m_labeldecs->doubleint(jet) = -99;
112 continue;
113 }
114
115 // set truth label for jets above pt threshold
116 // hierarchy: b > c > tau > light
118 .b = jetlabelpartsb.at(iJet),
119 .c = jetlabelpartsc.at(iJet),
120 .tau = jetlabelpartstau.at(iJet),
121 .origin = origin
122 };
124 }
125
126 return StatusCode::SUCCESS;
127}
128
129
130vector<vector<const TruthParticle*> >
132 const TruthParticleContainer& parts,
133 const JetContainer& jets) const {
134
135 ATH_MSG_VERBOSE("In " << name() << "::match()");
136
137 vector<vector<const TruthParticle*> > jetlabelparts(jets.size(), vector<const TruthParticle*>());
138
139 // determine the match mode
140 bool mindrmatch;
141 if (m_matchmode == "MinDR")
142 mindrmatch = true;
143 else if (m_matchmode == "MaxPt")
144 mindrmatch = false;
145 else {
146 ATH_MSG_FATAL("MatchMode must be MinDR or MaxPt");
147 return jetlabelparts;
148 }
149
150 // loop over particles and find the best matched jet
151 for (TruthParticleContainer::const_iterator part_itr = parts.begin();
152 part_itr != parts.end(); ++part_itr) {
153
154 const TruthParticle* part = *part_itr;
155
156 if (part->pt() < m_partptmin)
157 continue;
158
159 double mindr = DBL_MAX;
160 double maxpt = 0;
161 int mindrjetidx = -1;
162 int maxptjetidx = -1;
163 for (unsigned int iJet = 0; iJet < jets.size(); iJet++) {
164
165 const Jet& jet = *jets.at(iJet);
166
167 double pt = jet.pt();
168 if (pt < m_jetptmin)
169 continue;
170
171 double dr = jet.p4().DeltaR(part->p4());
172 // too far for matching criterion
173 if (dr > m_drmax)
174 continue;
175
176 // store the matched jet
177 if (dr < mindr) {
178 mindr = dr;
179 mindrjetidx = iJet;
180 }
181
182 if (pt > maxpt) {
183 maxpt = pt;
184 maxptjetidx = iJet;
185 }
186 }
187
188 // store the label particle with the jet
189 if (mindrmatch && mindrjetidx >= 0)
190 jetlabelparts.at(mindrjetidx).push_back(part);
191 else if (maxptjetidx >= 0)
192 jetlabelparts.at(maxptjetidx).push_back(part);
193 }
194
195 return jetlabelparts;
196}
197
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
Handle class for reading from StoreGate.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
std::vector< std::vector< const xAOD::TruthParticle * > > match(const xAOD::TruthParticleContainer &parts, const xAOD::JetContainer &jets) const
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_charmPartCollectionKey
ParticleJetDeltaRLabelTool(const std::string &name)
Constructor.
std::unique_ptr< ParticleJetTools::IParticleLinker > m_blinker
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventsKey
ParticleJetTools::LabelNames m_labelnames
Name of jet label attributes.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_bottomPartCollectionKey
double m_jetptmin
Minimum pT for jet selection (in MeV)
StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
double m_drmax
Maximum dR for matching criterion.
std::unique_ptr< ParticleJetTools::IParticleLinker > m_clinker
std::string m_matchmode
Matching mode: can be MinDR or MaxPt.
std::unique_ptr< ParticleJetTools::LabelDecorators > m_labeldecs
double m_partptmin
Minimum pT for particle selection (in MeV)
StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_tauPartCollectionKey
Read handles particle collections for labeling.
std::unique_ptr< ParticleJetTools::IParticleLinker > m_taulinker
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
Eigen::Matrix< double, 3, 1 > Vector3D
void setJetLabels(const xAOD::Jet &jet, const Particles &particles, const LabelNames &names)
void childrenRemoved(const std::vector< const xAOD::TruthParticle * > &parents, std::vector< const xAOD::TruthParticle * > &children)
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setRcore setEtHad setFside pt
JetContainer_v1 JetContainer
Definition of the current "jet container version".