ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleExtractor Class Reference

#include <IParticleExtractor.h>

Inheritance diagram for IParticleExtractor:
Collaboration diagram for IParticleExtractor:

Public Member Functions

 IParticleExtractor (const xAOD::IParticleContainer *, const std::string &label="", bool isGhost=false, bool isTrigger=false)
virtual ~IParticleExtractor ()
virtual IParticleExtractorclone () const override
virtual IParticleExtractorghostClone () const override
virtual void addToJet (xAOD::Jet &, const std::vector< int > &indices) const override
virtual std::string toString (int level) const override
virtual bool checkIntegrity () const override

Private Attributes

const xAOD::IParticleContainerm_iParticles
std::string m_label
bool m_isGhost
bool m_debug {false}
bool m_isTrigger {false}

Detailed Description

Definition at line 18 of file IParticleExtractor.h.

Constructor & Destructor Documentation

◆ IParticleExtractor()

IParticleExtractor::IParticleExtractor ( const xAOD::IParticleContainer * ips,
const std::string & label = "",
bool isGhost = false,
bool isTrigger = false )

Definition at line 13 of file IParticleExtractor.cxx.

16 :
18 m_isGhost(isGhost),
19 m_isTrigger(isTrigger)// does not add constits or assoc particles if true
20{
21}
const xAOD::IParticleContainer * m_iParticles
std::string label(const std::string &format, int i)
Definition label.h:19

◆ ~IParticleExtractor()

IParticleExtractor::~IParticleExtractor ( )
virtualdefault

Member Function Documentation

◆ addToJet()

void IParticleExtractor::addToJet ( xAOD::Jet & jet,
const std::vector< int > & indices ) const
overridevirtual

Implements IConstituentExtractor.

Definition at line 36 of file IParticleExtractor.cxx.

37 {
38 //Add a template specialisation for muon segments
39
40 std::vector<const xAOD::IParticle*> constituents;
41 constituents.reserve(indices.size());
42 for(auto i : indices){
43 if(m_debug){
44 constituents.push_back(m_iParticles->at(i));
45 } else {
46 constituents.push_back((*m_iParticles)[i]);
47 }
48 }
49
50 if(m_isGhost) {
51 // ghosts (in this context) are objects to be stored with the
52 // jet, but with a scaled momentum so they have no kinimatical effect.
53 double ptSum = std::accumulate(constituents.begin(),
54 constituents.end(),
55 0.0,
56 [](double sumPt, const xAOD::IParticle* p){
57 return sumPt + p->pt();});
58
59 if ( (!m_isTrigger) || (m_label == "GhostTrack") ){jet.setAssociatedObjects(m_label, constituents);}
60 jet.setAttribute<float>(m_label + "Pt", ptSum);
61 jet.setAttribute<int>(m_label+"Count", constituents.size());
62 } else {
63 // these are constituents
64 for(const auto *c: constituents) {
65 jet.addConstituent(c);
66 }
67 }
68}
void setAttribute(const std::string &name, const T &v)
void addConstituent(const ElementLink< IParticleContainer > &link, float weight=1.0)
Add a constituent directly in the ElementLink format.
Definition Jet_v1.cxx:111
void setAssociatedObjects(const std::string &name, const std::vector< const T * > &vec)
set associated objects from a vector of arbitrary object.
std::pair< long int, long int > indices

◆ checkIntegrity()

bool IParticleExtractor::checkIntegrity ( ) const
overridevirtual

Implements IConstituentExtractor.

Definition at line 104 of file IParticleExtractor.cxx.

104 {
105 for(const auto *const ip: (*m_iParticles)){
106 try{
107 ip->e();
108 } catch(...) {
109 return false;
110 }
111 }
112 return true;
113}

◆ clone()

IParticleExtractor * IParticleExtractor::clone ( ) const
overridevirtual

Implements IConstituentExtractor.

Definition at line 25 of file IParticleExtractor.cxx.

25 {
26 return new IParticleExtractor(*this);
27}
IParticleExtractor(const xAOD::IParticleContainer *, const std::string &label="", bool isGhost=false, bool isTrigger=false)

◆ ghostClone()

IParticleExtractor * IParticleExtractor::ghostClone ( ) const
overridevirtual

Implements IConstituentExtractor.

Definition at line 29 of file IParticleExtractor.cxx.

29 {
30 // user responsible for deletion.
31 auto *clone = new IParticleExtractor(*this);
32 (*clone).m_isGhost = true;
33 return clone;
34}
virtual IParticleExtractor * clone() const override

◆ toString()

std::string IParticleExtractor::toString ( int level) const
overridevirtual

Implements IConstituentExtractor.

Definition at line 72 of file IParticleExtractor.cxx.

72 {
73 std::ostringstream oss{"", std::ios::ate};
74 oss << "IParticleExtractor dump level (" << level << ")"
75 << " label " << m_label
76 << " isGhost: " << std::boolalpha << m_isGhost
77 << " isTrigger: " << std::boolalpha << m_isTrigger
78 << " No of IParticles: " << m_iParticles->size();
79
80 if (level > 0){
81
82 oss << "\n IParticle energies\n";
83 std::vector<float> energies;
84 energies.reserve(m_iParticles->size());
85 std::transform(m_iParticles->begin(),
86 m_iParticles->end(),
87 std::back_inserter(energies),
88 [](const xAOD::IParticle* p){return p->e();});
89
90 LineFormatter formatter(10); // 10 numbers/line
91 oss << formatter(energies) << '\n';
92
93 std::vector<const xAOD::IParticle*> adds(m_iParticles->begin(),
94 m_iParticles->end());
95 oss << "\n IParticle addresses\n"
96 << formatter(adds)
97 << '\n';
98 }
99 return oss.str();
100}

Member Data Documentation

◆ m_debug

bool IParticleExtractor::m_debug {false}
private

Definition at line 39 of file IParticleExtractor.h.

39{false};

◆ m_iParticles

const xAOD::IParticleContainer* IParticleExtractor::m_iParticles
private

Definition at line 36 of file IParticleExtractor.h.

◆ m_isGhost

bool IParticleExtractor::m_isGhost
private

Definition at line 38 of file IParticleExtractor.h.

◆ m_isTrigger

bool IParticleExtractor::m_isTrigger {false}
private

Definition at line 40 of file IParticleExtractor.h.

40{false};

◆ m_label

std::string IParticleExtractor::m_label
private

Definition at line 37 of file IParticleExtractor.h.


The documentation for this class was generated from the following files: