ATLAS Offline Software
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
9 #include "xAODBase/IParticle.h"
10 #include <numeric>
11 #include <vector>
12 
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 
24 
26  return new IParticleExtractor(*this);
27 }
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 
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());
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 }
IParticleExtractor::ghostClone
virtual IParticleExtractor * ghostClone() const override
Definition: IParticleExtractor.cxx:29
IParticleExtractor::m_debug
bool m_debug
Definition: IParticleExtractor.h:39
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
IParticle.h
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
IParticleExtractor::m_isTrigger
bool m_isTrigger
Definition: IParticleExtractor.h:40
LineFormatter.h
IParticleExtractor::toString
virtual std::string toString(int level) const override
Definition: IParticleExtractor.cxx:72
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
IParticleExtractor::m_label
std::string m_label
Definition: IParticleExtractor.h:37
IParticleExtractor::IParticleExtractor
IParticleExtractor(const xAOD::IParticleContainer *, const std::string &label="", bool isGhost=false, bool isTrigger=false)
Definition: IParticleExtractor.cxx:13
IParticleExtractor::~IParticleExtractor
virtual ~IParticleExtractor()
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
IParticleExtractor::clone
virtual IParticleExtractor * clone() const override
Definition: IParticleExtractor.cxx:25
IParticleExtractor
Definition: IParticleExtractor.h:18
lumiFormat.i
int i
Definition: lumiFormat.py:92
IParticleExtractor::m_isGhost
bool m_isGhost
Definition: IParticleExtractor.h:38
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
IParticleExtractor::addToJet
virtual void addToJet(xAOD::Jet &, const std::vector< int > &indices) const override
Definition: IParticleExtractor.cxx:36
vtune_athena.formatter
formatter
Definition: vtune_athena.py:19
LineFormatter
Definition: LineFormatter.h:14
IParticleExtractor::m_iParticles
const xAOD::IParticleContainer * m_iParticles
Definition: IParticleExtractor.h:36
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
IParticleExtractor::checkIntegrity
virtual bool checkIntegrity() const override
Definition: IParticleExtractor.cxx:104
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
IParticleExtractor.h
python.compressB64.c
def c
Definition: compressB64.py:93
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.