CMS 3D CMS Logo

ParticleDecayDrawer.cc
Go to the documentation of this file.
1 /* class ParticleDecayDrawer
2  *
3  * \author Luca Lista, INFN
4  */
12 
14 public:
16 
17 private:
18  void analyze(const edm::Event &, const edm::EventSetup &) override;
20  std::string decay(const reco::Candidate &, std::list<const reco::Candidate *> &) const;
26  std::string printP4(const reco::Candidate &) const;
28  bool accept(const reco::Candidate &, const std::list<const reco::Candidate *> &) const;
30  bool select(const reco::Candidate &) const;
32  bool hasValidDaughters(const reco::Candidate &) const;
33 };
34 
40 #include <iostream>
41 #include <sstream>
42 #include <algorithm>
43 using namespace std;
44 using namespace edm;
45 using namespace reco;
46 
48  : srcToken_(consumes<edm::View<reco::Candidate> >(cfg.getParameter<InputTag>("src"))),
49  pdtToken_(esConsumes<ParticleDataTable, edm::DefaultRecord>()),
50  printP4_(cfg.getUntrackedParameter<bool>("printP4", false)),
51  printPtEtaPhi_(cfg.getUntrackedParameter<bool>("printPtEtaPhi", false)),
52  printVertex_(cfg.getUntrackedParameter<bool>("printVertex", false)) {}
53 
54 bool ParticleDecayDrawer::accept(const reco::Candidate &c, const list<const Candidate *> &skip) const {
55  if (find(skip.begin(), skip.end(), &c) != skip.end())
56  return false;
57  return select(c);
58 }
59 
60 bool ParticleDecayDrawer::select(const reco::Candidate &c) const { return c.status() == 3; }
61 
63  size_t ndau = c.numberOfDaughters();
64  for (size_t i = 0; i < ndau; ++i)
65  if (select(*c.daughter(i)))
66  return true;
67  return false;
68 }
69 
71  pdt_ = es.getHandle(pdtToken_);
73  event.getByToken(srcToken_, particles);
74  list<const Candidate *> skip;
75  vector<const Candidate *> nodes, moms;
76  for (View<Candidate>::const_iterator p = particles->begin(); p != particles->end(); ++p) {
77  if (p->numberOfMothers() > 1) {
78  if (select(*p)) {
79  skip.push_back(&*p);
80  nodes.push_back(&*p);
81  for (size_t j = 0; j < p->numberOfMothers(); ++j) {
82  const Candidate *mom = p->mother(j);
83  const Candidate *grandMom;
84  while ((grandMom = mom->mother()) != nullptr)
85  mom = grandMom;
86  if (select(*mom)) {
87  moms.push_back(mom);
88  }
89  }
90  }
91  }
92  }
93  cout << "-- decay: --" << endl;
94  if (!moms.empty()) {
95  if (moms.size() > 1)
96  for (size_t m = 0; m < moms.size(); ++m) {
97  string dec = decay(*moms[m], skip);
98  if (!dec.empty())
99  cout << "{ " << dec << " } ";
100  }
101  else
102  cout << decay(*moms[0], skip);
103  }
104  if (!nodes.empty()) {
105  cout << "-> ";
106  if (nodes.size() > 1) {
107  for (size_t n = 0; n < nodes.size(); ++n) {
108  skip.remove(nodes[n]);
109  string dec = decay(*nodes[n], skip);
110  if (!dec.empty()) {
111  if (dec.find("->", 0) != string::npos)
112  cout << " ( " << dec << " )";
113  else
114  cout << " " << dec;
115  }
116  }
117  } else {
118  skip.remove(nodes[0]);
119  cout << decay(*nodes[0], skip);
120  }
121  }
122  cout << endl;
123 }
124 
126  ostringstream cout;
127  if (printP4_)
128  cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")";
129  if (printPtEtaPhi_)
130  cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
131  if (printVertex_)
132  cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
133  return cout.str();
134 }
135 
136 string ParticleDecayDrawer::decay(const Candidate &c, list<const Candidate *> &skip) const {
137  string out;
138  if (find(skip.begin(), skip.end(), &c) != skip.end())
139  return out;
140  skip.push_back(&c);
141 
142  int id = c.pdgId();
143  const ParticleData *pd = pdt_->particle(id);
144  assert(pd != nullptr);
145  out += (pd->name() + printP4(c));
146 
147  size_t validDau = 0, ndau = c.numberOfDaughters();
148  for (size_t i = 0; i < ndau; ++i)
149  if (accept(*c.daughter(i), skip))
150  ++validDau;
151  if (validDau == 0)
152  return out;
153 
154  out += " ->";
155 
156  for (size_t i = 0; i < ndau; ++i) {
157  const Candidate *d = c.daughter(i);
158  if (accept(*d, skip)) {
159  string dec = decay(*d, skip);
160  if (dec.find("->", 0) != string::npos)
161  out += (" ( " + dec + " )");
162  else
163  out += (" " + dec);
164  }
165  }
166  return out;
167 }
168 
170 
ParticleDecayDrawer::printP4_
bool printP4_
print parameters
Definition: ParticleDecayDrawer.cc:24
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
ParticleDecayDrawer::printVertex_
bool printVertex_
Definition: ParticleDecayDrawer.cc:24
ESHandle.h
ParticleDecayDrawer::select
bool select(const reco::Candidate &) const
select candidate
Definition: ParticleDecayDrawer.cc:60
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ParticleDecayDrawer::hasValidDaughters
bool hasValidDaughters(const reco::Candidate &) const
has valid daughters in the chain
Definition: ParticleDecayDrawer.cc:62
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ParticleDecayDrawer::pdt_
edm::ESHandle< ParticleDataTable > pdt_
Definition: ParticleDecayDrawer.cc:21
cms::cuda::assert
assert(be >=bs)
EDAnalyzer.h
edm::DefaultRecord
Definition: data_default_record_trait.h:49
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ParticleDecayDrawer::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Definition: ParticleDecayDrawer.cc:19
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
reco::Candidate::mother
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
ParticleDecayDrawer::accept
bool accept(const reco::Candidate &, const std::list< const reco::Candidate * > &) const
accept candidate
Definition: ParticleDecayDrawer.cc:54
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
EDMException.h
optionsL1T.skip
skip
Definition: optionsL1T.py:30
MakerMacros.h
ParticleDecayDrawer::ParticleDecayDrawer
ParticleDecayDrawer(const edm::ParameterSet &)
Definition: ParticleDecayDrawer.cc:47
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
edm::ESHandle< ParticleDataTable >
ParticleDecayDrawer::pdtToken_
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
Definition: ParticleDecayDrawer.cc:22
class-composition.nodes
nodes
Definition: class-composition.py:75
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
ParticleDecayDrawer::printPtEtaPhi_
bool printPtEtaPhi_
Definition: ParticleDecayDrawer.cc:24
Event.h
ParticleDataTable.h
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord >
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
std
Definition: JetResolutionObject.h:76
ParticleDecayDrawer::printP4
std::string printP4(const reco::Candidate &) const
print 4 momenta
Definition: ParticleDecayDrawer.cc:125
EventSetup.h
ParticleDecayDrawer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ParticleDecayDrawer.cc:70
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ztail.d
d
Definition: ztail.py:151
Candidate.h
View.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
ParticleDecayDrawer::decay
std::string decay(const reco::Candidate &, std::list< const reco::Candidate * > &) const
Definition: ParticleDecayDrawer.cc:136
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
ParticleDecayDrawer
Definition: ParticleDecayDrawer.cc:13
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
ParticleDataTable
HepPDT::ParticleDataTable ParticleDataTable
Definition: ParticleDataTable.h:8
edm::InputTag
Definition: InputTag.h:15