CMS 3D CMS Logo

ParticleTreeDrawer.cc
Go to the documentation of this file.
1 /* class ParticleTreeDrawer
2  *
3  * \author Luca Lista, INFN
4  */
5 #include <sstream>
6 
14 
16 public:
18 
19 private:
20  std::string getParticleName(int id) const;
21  void analyze(const edm::Event &, const edm::EventSetup &) override;
23  void printDecay(const reco::Candidate &, const std::string &pre) const;
29  typedef std::vector<int> vint;
32  void printInfo(const reco::Candidate &) const;
34  bool accept(const reco::Candidate &) const;
36  bool hasValidDaughters(const reco::Candidate &) const;
38  std::vector<const reco::Candidate *> cands_;
39 };
40 
46 #include <iostream>
47 #include <algorithm>
48 using namespace std;
49 using namespace edm;
50 using namespace reco;
51 
53  : srcToken_(consumes<edm::View<reco::Candidate> >(cfg.getParameter<InputTag>("src"))),
55  printP4_(cfg.getUntrackedParameter<bool>("printP4", false)),
56  printPtEtaPhi_(cfg.getUntrackedParameter<bool>("printPtEtaPhi", false)),
57  printVertex_(cfg.getUntrackedParameter<bool>("printVertex", false)),
58  printStatus_(cfg.getUntrackedParameter<bool>("printStatus", false)),
59  printIndex_(cfg.getUntrackedParameter<bool>("printIndex", false)),
60  status_(cfg.getUntrackedParameter<vint>("status", vint())) {}
61 
63  if (status_.empty())
64  return true;
65  return find(status_.begin(), status_.end(), c.status()) != status_.end();
66 }
67 
69  size_t ndau = c.numberOfDaughters();
70  for (size_t i = 0; i < ndau; ++i)
71  if (accept(*c.daughter(i)))
72  return true;
73  return false;
74 }
75 
77  const ParticleData *pd = pdt_->particle(id);
78  if (!pd) {
79  std::ostringstream ss;
80  ss << "P" << id;
81  return ss.str();
82  } else
83  return pd->name();
84 }
85 
87  pdt_ = es.getHandle(pdtToken_);
89  event.getByToken(srcToken_, particles);
90  cands_.clear();
91  for (View<Candidate>::const_iterator p = particles->begin(); p != particles->end(); ++p) {
92  cands_.push_back(&*p);
93  }
94  for (View<Candidate>::const_iterator p = particles->begin(); p != particles->end(); ++p) {
95  if (accept(*p)) {
96  if (p->mother() == nullptr) {
97  cout << "-- decay tree: --" << endl;
98  printDecay(*p, "");
99  }
100  }
101  }
102 }
103 
105  if (printP4_)
106  cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")";
107  if (printPtEtaPhi_)
108  cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
109  if (printVertex_)
110  cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
111  if (printStatus_)
112  cout << "{status: " << c.status() << "}";
113  if (printIndex_) {
114  int idx = -1;
115  vector<const Candidate *>::const_iterator found = find(cands_.begin(), cands_.end(), &c);
116  if (found != cands_.end()) {
117  idx = found - cands_.begin();
118  cout << " <idx: " << idx << ">";
119  }
120  }
121 }
122 
123 void ParticleTreeDrawer::printDecay(const Candidate &c, const string &pre) const {
124  cout << getParticleName(c.pdgId());
125  printInfo(c);
126  cout << endl;
127 
128  size_t ndau = c.numberOfDaughters(), validDau = 0;
129  for (size_t i = 0; i < ndau; ++i)
130  if (accept(*c.daughter(i)))
131  ++validDau;
132  if (validDau == 0)
133  return;
134 
135  bool lastLevel = true;
136  for (size_t i = 0; i < ndau; ++i) {
137  if (hasValidDaughters(*c.daughter(i))) {
138  lastLevel = false;
139  break;
140  }
141  }
142 
143  if (lastLevel) {
144  cout << pre << "+-> ";
145  size_t vd = 0;
146  for (size_t i = 0; i < ndau; ++i) {
147  const Candidate *d = c.daughter(i);
148  if (accept(*d)) {
149  cout << getParticleName(d->pdgId());
150  printInfo(*d);
151  if (vd != validDau - 1)
152  cout << " ";
153  vd++;
154  }
155  }
156  cout << endl;
157  return;
158  }
159 
160  for (size_t i = 0; i < ndau; ++i) {
161  const Candidate *d = c.daughter(i);
162  assert(d != nullptr);
163  if (accept(*d)) {
164  cout << pre << "+-> ";
165  string prepre(pre);
166  if (i == ndau - 1)
167  prepre += " ";
168  else
169  prepre += "| ";
170  printDecay(*d, prepre);
171  }
172  }
173 }
174 
176 
ParticleTreeDrawer::status_
vint status_
Definition: ParticleTreeDrawer.cc:30
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
ParticleTreeDrawer::printP4_
bool printP4_
print parameters
Definition: ParticleTreeDrawer.cc:27
funct::false
false
Definition: Factorize.h:29
ESHandle.h
ParticleTreeDrawer::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Definition: ParticleTreeDrawer.cc:22
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ParticleTreeDrawer::getParticleName
std::string getParticleName(int id) const
Definition: ParticleTreeDrawer.cc:76
ParticleTreeDrawer::pdtToken_
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
Definition: ParticleTreeDrawer.cc:25
cms::cuda::assert
assert(be >=bs)
ParticleTreeDrawer::pdt_
edm::ESHandle< ParticleDataTable > pdt_
Definition: ParticleTreeDrawer.cc:24
vd
std::vector< DeviationSensor2D * > vd
Definition: DeviationsFromFileSensor2D.h:21
EDAnalyzer.h
edm::DefaultRecord
Definition: data_default_record_trait.h:49
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
EDMException.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParticleTreeDrawer::printInfo
void printInfo(const reco::Candidate &) const
print 4 momenta
Definition: ParticleTreeDrawer.cc:104
edm::ESHandle< ParticleDataTable >
ParticleTreeDrawer::printPtEtaPhi_
bool printPtEtaPhi_
Definition: ParticleTreeDrawer.cc:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View
Definition: CaloClusterFwd.h:14
ParticleTreeDrawer::printVertex_
bool printVertex_
Definition: ParticleTreeDrawer.cc:27
ParticleTreeDrawer::hasValidDaughters
bool hasValidDaughters(const reco::Candidate &) const
has valid daughters in the chain
Definition: ParticleTreeDrawer.cc:68
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ParticleDataTable.h
ParticleTreeDrawer::ParticleTreeDrawer
ParticleTreeDrawer(const edm::ParameterSet &)
Definition: ParticleTreeDrawer.cc:52
ParticleTreeDrawer::cands_
std::vector< const reco::Candidate * > cands_
pointer to collection
Definition: ParticleTreeDrawer.cc:38
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::EventSetup
Definition: EventSetup.h:58
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord >
ParticleTreeDrawer::printDecay
void printDecay(const reco::Candidate &, const std::string &pre) const
Definition: ParticleTreeDrawer.cc:123
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
ParticleTreeDrawer::printIndex_
bool printIndex_
Definition: ParticleTreeDrawer.cc:27
std
Definition: JetResolutionObject.h:76
ParticleTreeDrawer::vint
std::vector< int > vint
accepted status codes
Definition: ParticleTreeDrawer.cc:29
ParticleTreeDrawer::accept
bool accept(const reco::Candidate &) const
accept candidate
Definition: ParticleTreeDrawer.cc:62
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
EventSetup.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
ParticleTreeDrawer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ParticleTreeDrawer.cc:86
ztail.d
d
Definition: ztail.py:151
Candidate.h
View.h
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
event
Definition: event.py:1
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
ParticleDataTable
HepPDT::ParticleDataTable ParticleDataTable
Definition: ParticleDataTable.h:8
ParticleTreeDrawer
Definition: ParticleTreeDrawer.cc:15
edm::InputTag
Definition: InputTag.h:15
ParticleTreeDrawer::printStatus_
bool printStatus_
Definition: ParticleTreeDrawer.cc:27