ATLAS Offline Software
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 
7 #include "xAODJet/JetContainer.h"
10 #include "AsgMessaging/Check.h"
11 
12 using namespace std;
13 using namespace xAOD;
14 
16  : AsgTool(name) {
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 
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
41  using Linker = ParticleJetTools::IParticleLinker;
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 
130 vector<vector<const TruthParticle*> >
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 
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
ParticleJetDeltaRLabelTool::m_blinker
std::unique_ptr< ParticleJetTools::IParticleLinker > m_blinker
Definition: ParticleJetDeltaRLabelTool.h:52
ParticleJetDeltaRLabelTool::m_taulinker
std::unique_ptr< ParticleJetTools::IParticleLinker > m_taulinker
Definition: ParticleJetDeltaRLabelTool.h:54
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ParticleJetDeltaRLabelTool::match
std::vector< std::vector< const xAOD::TruthParticle * > > match(const xAOD::TruthParticleContainer &parts, const xAOD::JetContainer &jets) const
Definition: ParticleJetDeltaRLabelTool.cxx:131
Check.h
ParticleJetTools::IParticleLinker
Definition: ParticleJetLabelCommon.h:58
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthVertexContainer.h
ParticleJetDeltaRLabelTool::m_bottomPartCollectionKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_bottomPartCollectionKey
Definition: ParticleJetDeltaRLabelTool.h:44
ParticleJetDeltaRLabelTool::decorate
StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: ParticleJetDeltaRLabelTool.cxx:53
ParticleJetDeltaRLabelTool::m_clinker
std::unique_ptr< ParticleJetTools::IParticleLinker > m_clinker
Definition: ParticleJetDeltaRLabelTool.h:53
TruthParticle
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:58
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ParticleJetTools::declareProperties
void declareProperties(T &tool, LabelNames *n)
Definition: ParticleJetLabelCommon.h:105
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
ParticleJetTools::LabelNames::check
void check()
Definition: ParticleJetLabelCommon.cxx:97
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TruthParticleContainer
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
ParticleJetLabelCommon.h
ParticleJetDeltaRLabelTool::m_matchmode
std::string m_matchmode
Matching mode: can be MinDR or MaxPt.
Definition: ParticleJetDeltaRLabelTool.h:66
ParticleJetDeltaRLabelTool::m_taulabelname
std::string m_taulabelname
Definition: ParticleJetDeltaRLabelTool.h:38
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleJetDeltaRLabelTool::m_charmPartCollectionKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_charmPartCollectionKey
Definition: ParticleJetDeltaRLabelTool.h:45
ParticleJetDeltaRLabelTool::m_labelnames
ParticleJetTools::LabelNames m_labelnames
Name of jet label attributes.
Definition: ParticleJetDeltaRLabelTool.h:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ParticleJetDeltaRLabelTool::ParticleJetDeltaRLabelTool
ParticleJetDeltaRLabelTool(const std::string &name)
Constructor.
Definition: ParticleJetDeltaRLabelTool.cxx:15
ParticleJetDeltaRLabelTool::m_tauPartCollectionKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_tauPartCollectionKey
Read handles particle collections for labeling.
Definition: ParticleJetDeltaRLabelTool.h:43
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ParticleJetDeltaRLabelTool::m_drmax
double m_drmax
Maximum dR for matching criterion.
Definition: ParticleJetDeltaRLabelTool.h:63
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
ParticleJetTools::Particles
Definition: ParticleJetLabelCommon.h:69
ParticleJetDeltaRLabelTool::initialize
StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: ParticleJetDeltaRLabelTool.cxx:29
ParticleJetTools::childrenRemoved
void childrenRemoved(const std::vector< const xAOD::TruthParticle * > &parents, std::vector< const xAOD::TruthParticle * > &children)
Definition: ParticleJetLabelCommon.cxx:69
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ParticleJetTools
Definition: ParticleJetLabelCommon.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ReadHandle.h
Handle class for reading from StoreGate.
ParticleJetDeltaRLabelTool::m_labeldecs
std::unique_ptr< ParticleJetTools::LabelDecorators > m_labeldecs
Definition: ParticleJetDeltaRLabelTool.h:37
ParticleJetDeltaRLabelTool::m_truthEventsKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventsKey
Definition: ParticleJetDeltaRLabelTool.h:46
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
ParticleJetTools::signalProcessP3
Amg::Vector3D signalProcessP3(const xAOD::TruthEventContainer &)
Definition: ParticleJetLabelCommon.cxx:62
ParticleJetDeltaRLabelTool::m_jetptmin
double m_jetptmin
Minimum pT for jet selection (in MeV)
Definition: ParticleJetDeltaRLabelTool.h:60
ParticleJetTools::setJetLabels
void setJetLabels(const xAOD::Jet &jet, const Particles &particles, const LabelNames &names)
Definition: ParticleJetLabelCommon.cxx:285
ParticleJetDeltaRLabelTool::m_partptmin
double m_partptmin
Minimum pT for particle selection (in MeV)
Definition: ParticleJetDeltaRLabelTool.h:57
ParticleJetDeltaRLabelTool::m_bottomlabelname
std::string m_bottomlabelname
Definition: ParticleJetDeltaRLabelTool.h:39
ParticleJetDeltaRLabelTool::m_charmlabelname
std::string m_charmlabelname
Definition: ParticleJetDeltaRLabelTool.h:40
JetContainer.h
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
ParticleJetTools::LabelDecorators
Definition: ParticleJetLabelCommon.h:40
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
ParticleJetDeltaRLabelTool.h