ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetRec
Root
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
7
#include "
JetRec/IParticleExtractor.h
"
8
#include "
JetRec/LineFormatter.h
"
// helper class for debug printing
9
#include "
xAODBase/IParticle.h
"
10
#include <numeric>
11
#include <vector>
12
13
IParticleExtractor::IParticleExtractor
(
const
xAOD::IParticleContainer
* ips,
14
const
std::string &
label
,
15
bool
isGhost,
16
bool
isTrigger) :
17
m_iParticles
(ips),
m_label
(
label
),
18
m_isGhost
(isGhost),
19
m_isTrigger
(isTrigger)
// does not add constits or assoc particles if true
20
{
21
}
22
23
IParticleExtractor::~IParticleExtractor
()=
default
;
24
25
IParticleExtractor
*
IParticleExtractor::clone
()
const
{
26
return
new
IParticleExtractor
(*
this
);
27
}
28
29
IParticleExtractor
*
IParticleExtractor::ghostClone
()
const
{
30
// user responsible for deletion.
31
auto
*
clone
=
new
IParticleExtractor
(*
this
);
32
(*clone).m_isGhost =
true
;
33
return
clone
;
34
}
35
36
void
IParticleExtractor::addToJet
(
xAOD::Jet
&
jet
,
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
72
std::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
104
bool
IParticleExtractor::checkIntegrity
()
const
{
105
for
(
const
auto
*
const
ip: (*
m_iParticles
)){
106
try
{
107
ip->e();
108
}
catch
(...) {
109
return
false
;
110
}
111
}
112
return
true
;
113
}
IParticle.h
IParticleExtractor.h
LineFormatter.h
IParticleExtractor::toString
virtual std::string toString(int level) const override
Definition
IParticleExtractor.cxx:72
IParticleExtractor::clone
virtual IParticleExtractor * clone() const override
Definition
IParticleExtractor.cxx:25
IParticleExtractor::~IParticleExtractor
virtual ~IParticleExtractor()
IParticleExtractor::IParticleExtractor
IParticleExtractor(const xAOD::IParticleContainer *, const std::string &label="", bool isGhost=false, bool isTrigger=false)
Definition
IParticleExtractor.cxx:13
IParticleExtractor::m_iParticles
const xAOD::IParticleContainer * m_iParticles
Definition
IParticleExtractor.h:36
IParticleExtractor::m_isGhost
bool m_isGhost
Definition
IParticleExtractor.h:38
IParticleExtractor::m_isTrigger
bool m_isTrigger
Definition
IParticleExtractor.h:40
IParticleExtractor::checkIntegrity
virtual bool checkIntegrity() const override
Definition
IParticleExtractor.cxx:104
IParticleExtractor::addToJet
virtual void addToJet(xAOD::Jet &, const std::vector< int > &indices) const override
Definition
IParticleExtractor.cxx:36
IParticleExtractor::m_debug
bool m_debug
Definition
IParticleExtractor.h:39
IParticleExtractor::ghostClone
virtual IParticleExtractor * ghostClone() const override
Definition
IParticleExtractor.cxx:29
IParticleExtractor::m_label
std::string m_label
Definition
IParticleExtractor.h:37
LineFormatter
Definition
LineFormatter.h:14
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
label
std::string label(const std::string &format, int i)
Definition
label.h:19
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::IParticleContainer
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
Definition
xAOD/xAODBase/xAODBase/IParticleContainer.h:32
Generated on
for ATLAS Offline Software by
1.17.0