ATLAS Offline Software
Classes | Functions
ParticleJetTools Namespace Reference

Classes

class  IParticleLinker
 
struct  LabelDecorators
 
struct  LabelNames
 
struct  Particles
 

Functions

Amg::Vector3D p3 (const xAOD::TruthVertex *p)
 
Amg::Vector3D p3 (const xAOD::Jet &j)
 
Amg::Vector3D signalProcessP3 (const xAOD::TruthEventContainer &)
 
void setJetLabels (const xAOD::Jet &jet, const Particles &particles, const LabelNames &names)
 
void setJetLabels (const xAOD::Jet &jet, const Particles &particles, const LabelDecorators &decs)
 
float partPt (const xAOD::TruthParticle *part)
 
float partLxy (const xAOD::TruthParticle *part, const Amg::Vector3D &origin)
 
float partDR (const xAOD::TruthParticle *part, const xAOD::Jet &jet)
 
int partPdgId (const xAOD::TruthParticle *part)
 
float positionDPhi (const xAOD::TruthParticle *part, const xAOD::Jet &jet, const Amg::Vector3D &origin)
 
float positionDEta (const xAOD::TruthParticle *part, const xAOD::Jet &jet, const Amg::Vector3D &origin)
 
void childrenRemoved (const std::vector< const xAOD::TruthParticle * > &parents, std::vector< const xAOD::TruthParticle * > &children)
 
template<typename T >
void declareProperties (T &tool, LabelNames *n)
 
bool isChild (const xAOD::TruthParticle *p, const xAOD::TruthParticle *c)
 

Function Documentation

◆ childrenRemoved()

void ParticleJetTools::childrenRemoved ( const std::vector< const xAOD::TruthParticle * > &  parents,
std::vector< const xAOD::TruthParticle * > &  children 
)

Definition at line 63 of file ParticleJetLabelCommon.cxx.

66  {
67 
68  if ( &parents == &children ) {
69  // Same vector provided for both inputs. Extra care needed in
70  // this case...
71  const std::vector<const xAOD::TruthParticle*> copyParents = parents;
72  childrenRemoved(copyParents, children);
73  return;
74  }
75  // We can now safely assume that parents will not be modified
76  // during this loop.
77  for ( const xAOD::TruthParticle* p : parents ) {
78  if (!p) continue;
79  children.erase(std::remove_if(children.begin(),
80  children.end(),
81  [p](const xAOD::TruthParticle* c) { return (c && isChild(p, c)); }),
82  children.end());
83  // auto erased = std::erase_if(children, [p](const xAOD::TruthParticle* c) { return (c && isChild(p, c)); }); // C++20
84  }
85  return;
86  }

◆ declareProperties()

template<typename T >
void ParticleJetTools::declareProperties ( T &  tool,
LabelNames n 
)

Definition at line 105 of file ParticleJetLabelCommon.h.

105  {
106  tool.declareProperty("LabelName", n->singleint="", "Jet label attribute to be added.");
107  tool.declareProperty("DoubleLabelName", n->doubleint="", "Jet label attribute to be added (with the possibility of up to 2 matched hadrons).");
108  tool.declareProperty("LabelPtName", n->pt="", "Attribute for labelling particle pt");
109  tool.declareProperty("LabelLxyName", n->Lxy="", "Attribute for Lxy of labelling particle");
110  tool.declareProperty("LabelDRName", n->dr="", "Attribute for dR(part, jet) for labelling particle");
111  tool.declareProperty("LabelPdgIdName", n->pdgId="", "Attribute for pdgID of labelling particle");
112  tool.declareProperty("LabelPositionDPhiName", n->positionDPhi="", "Attribute for the position dPhi of the labeling particle ");
113  tool.declareProperty("LabelPositionDEtaName", n->positionDEta="", "Attribute for the position dEta of the labeling particle ");
114  tool.declareProperty("LabelBarcodeName", n->barcode="", "Attribute for barcode of labeling particle"); // FIXME barcode-based
115  tool.declareProperty("ChildLxyName", n->childLxy="", "Attribute for the labeling particle child Lxy");
116  tool.declareProperty("ChildPtName", n->childPt="", "Attribute for the labeling particle child Pt");
117  tool.declareProperty("ChildPdgIdName", n->childPdgId="", "Attribute for the labeling particle child pdg ID");
118  tool.declareProperty("ChildPositionDPhiName", n->childPositionDPhi="", "Attribute for the position dPhi of the labeling particle child");
119  tool.declareProperty("ChildPositionDEtaName", n->childPositionDEta="", "Attribute for the position dEta of the labeling particle child");
120  }

◆ isChild()

bool ParticleJetTools::isChild ( const xAOD::TruthParticle p,
const xAOD::TruthParticle c 
)
inline

Definition at line 34 of file ParticleJetLabelCommon.cxx.

34  {
35 
36  if ( HepMC::is_same_particle(p,c) ) { return false; }
37 
38  for (size_t iC = 0; iC < p->nChildren(); iC++) {
39  const xAOD::TruthParticle* cc = p->child(iC);
40  if (!cc) { continue; }
41 
42  if ( HepMC::is_same_particle(cc,c) ) { return true; }
43 
44  if (isChild(cc, c)) { return true; }
45  }
46 
47  return false;
48  }

◆ p3() [1/2]

Amg::Vector3D ParticleJetTools::p3 ( const xAOD::Jet j)

Definition at line 54 of file ParticleJetLabelCommon.cxx.

54  {
55  return {j.px(), j.py(), j.pz()};
56  }

◆ p3() [2/2]

Amg::Vector3D ParticleJetTools::p3 ( const xAOD::TruthVertex p)

Definition at line 50 of file ParticleJetLabelCommon.cxx.

50  {
51  if (!p) return {NAN, NAN, NAN};
52  return {p->x(), p->y(), p->z()};
53  }

◆ partDR()

float ParticleJetTools::partDR ( const xAOD::TruthParticle part,
const xAOD::Jet jet 
)

Definition at line 295 of file ParticleJetLabelCommon.cxx.

295  {
296  if (!part) return NAN;
297  return part->p4().DeltaR(jet.p4());
298  }

◆ partLxy()

float ParticleJetTools::partLxy ( const xAOD::TruthParticle part,
const Amg::Vector3D origin 
)

Definition at line 290 of file ParticleJetLabelCommon.cxx.

290  {
291  if (!part) return NAN;
292  if (const auto* vx = part->decayVtx() ) return (p3(vx) - origin).perp();
293  return INFINITY;
294  }

◆ partPdgId()

int ParticleJetTools::partPdgId ( const xAOD::TruthParticle part)

Definition at line 299 of file ParticleJetLabelCommon.cxx.

299  {
300  if (!part) return 0;
301  return part->pdgId();
302  }

◆ partPt()

float ParticleJetTools::partPt ( const xAOD::TruthParticle part)

Definition at line 286 of file ParticleJetLabelCommon.cxx.

286  {
287  if (!part) return NAN;
288  return part->pt();
289  }

◆ positionDEta()

float ParticleJetTools::positionDEta ( const xAOD::TruthParticle part,
const xAOD::Jet jet,
const Amg::Vector3D origin 
)

Definition at line 313 of file ParticleJetLabelCommon.cxx.

315  {
316  if (!part) return NAN;
317  if (const auto* vx = part->decayVtx() ) {
318  Amg::Vector3D displacement = p3(vx) - origin;
319  return displacement.eta() - jet.eta();
320  }
321  return INFINITY;
322  }

◆ positionDPhi()

float ParticleJetTools::positionDPhi ( const xAOD::TruthParticle part,
const xAOD::Jet jet,
const Amg::Vector3D origin 
)

Definition at line 303 of file ParticleJetLabelCommon.cxx.

305  {
306  if (!part) return NAN;
307  if (const auto* vx = part->decayVtx() ) {
308  Amg::Vector3D displacement = p3(vx) - origin;
309  return p3(jet).deltaPhi(displacement);
310  }
311  return INFINITY;
312  }

◆ setJetLabels() [1/2]

void ParticleJetTools::setJetLabels ( const xAOD::Jet jet,
const Particles particles,
const LabelDecorators decs 
)

Definition at line 162 of file ParticleJetLabelCommon.cxx.

164  {
165 
166  // we also want to save information about the maximum pt particle of the labeling partons
167  auto getMaxPtPart = [](const auto& container) -> const xAOD::TruthParticle* {
168  if (container.size() == 0) return nullptr;
169  auto itr = std::max_element(container.begin(), container.end(),
170  [](auto* p1, auto* p2) {
171  return p1->pt() < p2->pt();
172  });
173  return *itr;
174  };
175 
176  // set truth label for jets above pt threshold
177  // hierarchy: b > c > tau > light
178  int label = 0; // default: light
179  const xAOD::TruthParticle* labelling_particle = nullptr;
180  const xAOD::TruthParticle* child_particle = nullptr;
181  if (particles.b.size()) {
182  label = 5;
183  labelling_particle = getMaxPtPart(particles.b);
184  child_particle = getCharmChild(labelling_particle);
185  } else if (particles.c.size()) {
186  label = 4;
187  labelling_particle = getMaxPtPart(particles.c);
188  } else if (particles.tau.size()) {
189  label = 15;
190  labelling_particle = getMaxPtPart(particles.tau);
191  }
192 
193  const Amg::Vector3D& origin = particles.origin;
194 
195  // decorate info about the labelling particle
196  decs.singleint(jet) = label;
197  if (label == 0) {
198  decs.pt(jet) = NAN;
199  decs.Lxy(jet) = NAN;
200  decs.dr(jet) = NAN;
201  decs.pdgId(jet) = 0;
202  decs.positionDPhi(jet) = NAN;
203  decs.positionDEta(jet) = NAN;
204  decs.barcode(jet) = HepMC::INVALID_PARTICLE_BARCODE; // FIXME barcode-based
205  decs.childLxy(jet) = NAN;
206  decs.childPt(jet) = NAN;
207  decs.childPdgId(jet) = 0;
208  decs.childPositionDPhi(jet) = NAN;
209  decs.childPositionDEta(jet) = NAN;
210  } else {
211  decs.pt(jet) = partPt(labelling_particle);
212  decs.Lxy(jet) = partLxy(labelling_particle, origin);
213  decs.dr(jet) = partDR(labelling_particle, jet);
214  decs.pdgId(jet) = partPdgId(labelling_particle);
215  decs.positionDPhi(jet) = positionDPhi(labelling_particle, jet, origin);
216  decs.positionDEta(jet) = positionDEta(labelling_particle, jet, origin);
217  decs.barcode(jet) = labelling_particle ?
218  HepMC::barcode(labelling_particle) : HepMC::INVALID_PARTICLE_BARCODE; // FIXME barcode-based
219  decs.childLxy(jet) = partLxy(child_particle, origin);
220  decs.childPt(jet) = partPt(child_particle);
221  decs.childPdgId(jet) = partPdgId(child_particle);
222  decs.childPositionDPhi(jet) = positionDPhi(child_particle, jet, origin);
223  decs.childPositionDEta(jet) = positionDEta(child_particle, jet, origin);
224  }
225 
226  // extended flavour label
227  int double_label = 0;
228  if (particles.b.size()) {
229  if (particles.b.size() >= 2)
230  double_label = 55;
231 
232  else if (particles.c.size())
233  double_label = 54;
234 
235  else
236  double_label = 5;
237 
238  } else if (particles.c.size()) {
239  if (particles.c.size() >= 2)
240  double_label = 44;
241 
242  else
243  double_label = 4;
244 
245  } else if (particles.tau.size()){
246 
247  bool hasElectrondecay = false;
248  bool hasMuondecay = false;
249  bool hasHadronicdecay = false;
250  for (auto itau: particles.tau){
251  for (size_t i = 0; i< itau->nChildren(); i++){ // tau children loop
252  if (itau->child(i)->absPdgId() == 12 || itau->child(i)->absPdgId() == 14 || itau->child(i)->absPdgId() == 16) continue;
253  if (MC::isMuon(itau->child(i))) hasMuondecay = true;
254  else if (MC::isElectron(itau->child(i))) hasElectrondecay = true;
255  else hasHadronicdecay = true;
256  }
257  }
258 
259  if (particles.tau.size() >= 2){
260  // check if we have at least one hadronic tau
261  if (hasHadronicdecay){
262  // check if we have also tau->mu decay
263  if (hasMuondecay) double_label = 151513;
264  // check if we have also tau->el decay
265  else if (hasElectrondecay) double_label = 151511;
266  // otherwise fully hadronic di-tau decay
267  else double_label = 1515;
268  }
269  } else {
270  // only consider hadronic tau decay
271  if (hasHadronicdecay) double_label = 15;
272  }
273 
274  }
275 
276  decs.doubleint(jet) = double_label;
277 
278  }

◆ setJetLabels() [2/2]

void ParticleJetTools::setJetLabels ( const xAOD::Jet jet,
const Particles particles,
const LabelNames names 
)

Definition at line 280 of file ParticleJetLabelCommon.cxx.

282  {
283  setJetLabels(jet, particles, LabelDecorators(names));
284  }

◆ signalProcessP3()

Amg::Vector3D ParticleJetTools::signalProcessP3 ( const xAOD::TruthEventContainer events)

Definition at line 57 of file ParticleJetLabelCommon.cxx.

57  {
58  if (events.empty()) return {NAN, NAN, NAN};
59  return p3(events.at(0)->signalProcessVertex());
60  }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
ParticleJetTools::isChild
bool isChild(const xAOD::TruthParticle *p, const xAOD::TruthParticle *c)
Definition: ParticleJetLabelCommon.cxx:34
python.DecayParser.parents
parents
print ("==> buf:",buf)
Definition: DecayParser.py:31
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
ParticleJetTools::partDR
float partDR(const xAOD::TruthParticle *part, const xAOD::Jet &jet)
Definition: ParticleJetLabelCommon.cxx:295
HepMC::INVALID_PARTICLE_BARCODE
constexpr int INVALID_PARTICLE_BARCODE
Definition: MagicNumbers.h:53
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:354
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
ParticleJetTools::positionDEta
float positionDEta(const xAOD::TruthParticle *part, const xAOD::Jet &jet, const Amg::Vector3D &origin)
Definition: ParticleJetLabelCommon.cxx:313
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
xAOD::Jet_v1::pz
float pz() const
The z-component of the jet's momentum.
Definition: Jet_v1.cxx:99
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
python.subdetectors.mmg.names
names
Definition: mmg.py:8
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::Jet_v1::py
float py() const
The y-component of the jet's momentum.
Definition: Jet_v1.cxx:94
ParticleJetTools::childrenRemoved
void childrenRemoved(const std::vector< const xAOD::TruthParticle * > &parents, std::vector< const xAOD::TruthParticle * > &children)
Definition: ParticleJetLabelCommon.cxx:64
ParticleJetTools::partPt
float partPt(const xAOD::TruthParticle *part)
Definition: ParticleJetLabelCommon.cxx:286
xAOD::Jet_v1::px
float px() const
The x-component of the jet's momentum.
Definition: Jet_v1.cxx:90
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ParticleJetTools::positionDPhi
float positionDPhi(const xAOD::TruthParticle *part, const xAOD::Jet &jet, const Amg::Vector3D &origin)
Definition: ParticleJetLabelCommon.cxx:303
ParticleJetTools::setJetLabels
void setJetLabels(const xAOD::Jet &jet, const Particles &particles, const LabelNames &names)
Definition: ParticleJetLabelCommon.cxx:280
ParticleJetTools::partLxy
float partLxy(const xAOD::TruthParticle *part, const Amg::Vector3D &origin)
Definition: ParticleJetLabelCommon.cxx:290
HepMC
Definition: Barcode.h:14
ParticleJetTools::partPdgId
int partPdgId(const xAOD::TruthParticle *part)
Definition: ParticleJetLabelCommon.cxx:299
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
python.DecayParser.children
children
Definition: DecayParser.py:32
TRTCalib_cfilter.p3
p3
Definition: TRTCalib_cfilter.py:132
python.compressB64.c
def c
Definition: compressB64.py:93
python.handimod.cc
int cc
Definition: handimod.py:523
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:154