ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleExtractor.cxx
Go to the documentation of this file.
1// this file is -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
8#include "JetRec/LineFormatter.h" // helper class for debug printing
10#include <numeric>
11#include <vector>
12
14 const std::string & label,
15 bool isGhost,
16 bool isTrigger) :
18 m_isGhost(isGhost),
19 m_isTrigger(isTrigger)// does not add constits or assoc particles if true
20{
21}
22
24
28
30 // user responsible for deletion.
31 auto *clone = new IParticleExtractor(*this);
32 (*clone).m_isGhost = true;
33 return clone;
34}
35
37 const std::vector<int>& indices) const{
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}
69
70
71
72std::string IParticleExtractor::toString(int level) const {
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}
101
102
103
105 for(const auto *const ip: (*m_iParticles)){
106 try{
107 ip->e();
108 } catch(...) {
109 return false;
110 }
111 }
112 return true;
113}
virtual std::string toString(int level) const override
virtual IParticleExtractor * clone() const override
virtual ~IParticleExtractor()
IParticleExtractor(const xAOD::IParticleContainer *, const std::string &label="", bool isGhost=false, bool isTrigger=false)
const xAOD::IParticleContainer * m_iParticles
virtual bool checkIntegrity() const override
virtual void addToJet(xAOD::Jet &, const std::vector< int > &indices) const override
virtual IParticleExtractor * ghostClone() const override
Class providing the definition of the 4-vector interface.
std::string label(const std::string &format, int i)
Definition label.h:19
Jet_v1 Jet
Definition of the current "jet version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.