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 68 of file ParticleJetLabelCommon.cxx.

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

◆ 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 36 of file ParticleJetLabelCommon.cxx.

39  {
40 
41  if ( HepMC::uniqueID(p) == HepMC::uniqueID(c) ) { return false; }
42 
43  for (size_t iC = 0; iC < p->nChildren(); iC++) {
44  const xAOD::TruthParticle* cc = p->child(iC);
45  if (!cc) { continue; }
46 
47  if ( HepMC::uniqueID(cc) == HepMC::uniqueID(c) ) { return true; }
48 
49  if (isChild(cc, c)) { return true; }
50  }
51 
52  return false;
53  }

◆ p3() [1/2]

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

Definition at line 59 of file ParticleJetLabelCommon.cxx.

59  {
60  return {j.px(), j.py(), j.pz()};
61  }

◆ p3() [2/2]

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

Definition at line 55 of file ParticleJetLabelCommon.cxx.

55  {
56  if (!p) return {NAN, NAN, NAN};
57  return {p->x(), p->y(), p->z()};
58  }

◆ partDR()

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

Definition at line 300 of file ParticleJetLabelCommon.cxx.

300  {
301  if (!part) return NAN;
302  return part->p4().DeltaR(jet.p4());
303  }

◆ partLxy()

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

Definition at line 295 of file ParticleJetLabelCommon.cxx.

295  {
296  if (!part) return NAN;
297  if (const auto* vx = part->decayVtx() ) return (p3(vx) - origin).perp();
298  return INFINITY;
299  }

◆ partPdgId()

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

Definition at line 304 of file ParticleJetLabelCommon.cxx.

304  {
305  if (!part) return 0;
306  return part->pdgId();
307  }

◆ partPt()

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

Definition at line 291 of file ParticleJetLabelCommon.cxx.

291  {
292  if (!part) return NAN;
293  return part->pt();
294  }

◆ positionDEta()

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

Definition at line 318 of file ParticleJetLabelCommon.cxx.

320  {
321  if (!part) return NAN;
322  if (const auto* vx = part->decayVtx() ) {
323  Amg::Vector3D displacement = p3(vx) - origin;
324  return displacement.eta() - jet.eta();
325  }
326  return INFINITY;
327  }

◆ positionDPhi()

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

Definition at line 308 of file ParticleJetLabelCommon.cxx.

310  {
311  if (!part) return NAN;
312  if (const auto* vx = part->decayVtx() ) {
313  Amg::Vector3D displacement = p3(vx) - origin;
314  return p3(jet).deltaPhi(displacement);
315  }
316  return INFINITY;
317  }

◆ setJetLabels() [1/2]

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

Definition at line 167 of file ParticleJetLabelCommon.cxx.

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

◆ setJetLabels() [2/2]

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

Definition at line 285 of file ParticleJetLabelCommon.cxx.

287  {
288  setJetLabels(jet, particles, LabelDecorators(names));
289  }

◆ signalProcessP3()

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

Definition at line 62 of file ParticleJetLabelCommon.cxx.

62  {
63  if (events.empty()) return {NAN, NAN, NAN};
64  return p3(events.at(0)->signalProcessVertex());
65  }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
ParticleJetTools::isChild
bool isChild(const xAOD::TruthParticle *p, const xAOD::TruthParticle *c)
Definition: ParticleJetLabelCommon.cxx:37
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
python.DecayParser.parents
parents
print ("==> buf:",buf)
Definition: DecayParser.py:31
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
ParticleJetTools::partDR
float partDR(const xAOD::TruthParticle *part, const xAOD::Jet &jet)
Definition: ParticleJetLabelCommon.cxx:300
HepMC::INVALID_PARTICLE_BARCODE
constexpr int INVALID_PARTICLE_BARCODE
Definition: MagicNumbers.h:51
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:318
ParticleJetTools::p3
Amg::Vector3D p3(const xAOD::TruthVertex *p)
Definition: ParticleJetLabelCommon.cxx:55
xAOD::Jet_v1::pz
float pz() const
The z-component of the jet's momentum.
Definition: Jet_v1.cxx:99
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:13
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:41
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:113
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:69
ParticleJetTools::partPt
float partPt(const xAOD::TruthParticle *part)
Definition: ParticleJetLabelCommon.cxx:291
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:308
ParticleJetTools::setJetLabels
void setJetLabels(const xAOD::Jet &jet, const Particles &particles, const LabelNames &names)
Definition: ParticleJetLabelCommon.cxx:285
ParticleJetTools::partLxy
float partLxy(const xAOD::TruthParticle *part, const Amg::Vector3D &origin)
Definition: ParticleJetLabelCommon.cxx:295
HepMC
Definition: Barcode.h:14
ParticleJetTools::partPdgId
int partPdgId(const xAOD::TruthParticle *part)
Definition: ParticleJetLabelCommon.cxx:304
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
python.DecayParser.children
children
Definition: DecayParser.py:32
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:145