CMS 3D CMS Logo

ParticleListDrawer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <iostream>
4 #include <sstream>
5 
19 
37 using namespace std;
38 using namespace reco;
39 using namespace edm;
40 
42 public:
43  explicit ParticleListDrawer(const edm::ParameterSet&);
44  ~ParticleListDrawer() override{};
45  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
46 
47 private:
48  std::string getParticleName(int id) const;
49 
53  int maxEventsToPrint_; // Must be signed, because -1 is used for no limit
54  unsigned int nEventAnalyzed_;
59 };
60 
62  : src_(pset.getParameter<InputTag>("src")),
63  srcToken_(consumes<reco::CandidateView>(src_)),
64  maxEventsToPrint_(pset.getUntrackedParameter<int>("maxEventsToPrint", 1)),
65  nEventAnalyzed_(0),
66  printOnlyHardInteraction_(pset.getUntrackedParameter<bool>("printOnlyHardInteraction", false)),
67  printVertex_(pset.getUntrackedParameter<bool>("printVertex", false)),
68  printFlags_(pset.getUntrackedParameter<bool>("printFlags", false)),
69  useMessageLogger_(pset.getUntrackedParameter<bool>("useMessageLogger", false)) {}
70 
72  const ParticleData* pd = pdt_->particle(id);
73  if (!pd) {
74  std::ostringstream ss;
75  ss << "P" << id;
76  return ss.str();
77  } else
78  return pd->name();
79 }
80 
83  iEvent.getByToken(srcToken_, particles);
84  iSetup.getData(pdt_);
85 
86  if (maxEventsToPrint_ < 0 || nEventAnalyzed_ < static_cast<unsigned int>(maxEventsToPrint_)) {
87  ostringstream out;
88  char buf[256];
89 
90  out << endl << "[ParticleListDrawer] analysing particle collection " << src_.label() << endl;
91 
92  snprintf(buf,
93  sizeof(buf),
94  " idx | ID - Name |Stat| Mo1 Mo2 Da1 Da2 |nMo nDa| pt eta phi | px "
95  " py pz m |");
96  out << buf;
97  if (printVertex_) {
98  snprintf(buf, sizeof(buf), " vx vy vz |");
99  out << buf;
100  }
101  out << endl;
102 
103  int idx = -1;
104  int iMo1 = -1;
105  int iMo2 = -1;
106  int iDa1 = -1;
107  int iDa2 = -1;
108  vector<const reco::Candidate*> cands;
109  vector<const Candidate*>::const_iterator found = cands.begin();
110  for (CandidateView::const_iterator p = particles->begin(); p != particles->end(); ++p) {
111  cands.push_back(&*p);
112  }
113 
114  for (CandidateView::const_iterator p = particles->begin(); p != particles->end(); p++) {
115  if (printOnlyHardInteraction_ && p->status() != 3)
116  continue;
117 
118  // Particle Name
119  int id = p->pdgId();
120  string particleName = getParticleName(id);
121 
122  // Particle Index
123  idx = p - particles->begin();
124 
125  // Particles Mothers and Daighters
126  iMo1 = -1;
127  iMo2 = -1;
128  iDa1 = -1;
129  iDa2 = -1;
130  int nMo = p->numberOfMothers();
131  int nDa = p->numberOfDaughters();
132 
133  found = find(cands.begin(), cands.end(), p->mother(0));
134  if (found != cands.end())
135  iMo1 = found - cands.begin();
136 
137  found = find(cands.begin(), cands.end(), p->mother(nMo - 1));
138  if (found != cands.end())
139  iMo2 = found - cands.begin();
140 
141  found = find(cands.begin(), cands.end(), p->daughter(0));
142  if (found != cands.end())
143  iDa1 = found - cands.begin();
144 
145  found = find(cands.begin(), cands.end(), p->daughter(nDa - 1));
146  if (found != cands.end())
147  iDa2 = found - cands.begin();
148 
149  char buf[2400];
150  snprintf(
151  buf,
152  sizeof(buf),
153  " %4d | %5d - %10s | %2d | %4d %4d %4d %4d | %2d %2d | %7.3f %10.3f %6.3f | %10.3f %10.3f %10.3f %8.3f |",
154  idx,
155  p->pdgId(),
156  particleName.c_str(),
157  p->status(),
158  iMo1,
159  iMo2,
160  iDa1,
161  iDa2,
162  nMo,
163  nDa,
164  p->pt(),
165  p->eta(),
166  p->phi(),
167  p->px(),
168  p->py(),
169  p->pz(),
170  p->mass());
171  out << buf;
172 
173  if (printVertex_) {
174  snprintf(buf, sizeof(buf), " %10.3f %10.3f %10.3f |", p->vertex().x(), p->vertex().y(), p->vertex().z());
175  out << buf;
176  }
177 
178  if (printFlags_) {
179  const reco::GenParticle* gp = dynamic_cast<const reco::GenParticle*>(&*p);
180  if (!gp)
181  throw cms::Exception("Unsupported", "Status flags can be printed only for reco::GenParticle objects\n");
182  if (gp->isPromptFinalState())
183  out << " PromptFinalState";
184  if (gp->isDirectPromptTauDecayProductFinalState())
185  out << " DirectPromptTauDecayProductFinalState";
186  if (gp->isHardProcess())
187  out << " HardProcess";
188  if (gp->fromHardProcessFinalState())
189  out << " HardProcessFinalState";
190  if (gp->fromHardProcessBeforeFSR())
191  out << " HardProcessBeforeFSR";
192  if (gp->statusFlags().isFirstCopy())
193  out << " FirstCopy";
194  if (gp->isLastCopy())
195  out << " LastCopy";
196  if (gp->isLastCopyBeforeFSR())
197  out << " LastCopyBeforeFSR";
198  }
199 
200  out << endl;
201  }
202  nEventAnalyzed_++;
203 
204  if (useMessageLogger_)
205  LogVerbatim("ParticleListDrawer") << out.str();
206  else
207  cout << out.str();
208  }
209 }
210 
electrons_cff.bool
bool
Definition: electrons_cff.py:372
funct::false
false
Definition: Factorize.h:34
ParticleListDrawer::nEventAnalyzed_
unsigned int nEventAnalyzed_
Definition: ParticleListDrawer.cc:54
ESHandle.h
ParticleListDrawer::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: ParticleListDrawer.cc:81
reco::GenParticle
Definition: GenParticle.h:21
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
ParticleListDrawer::srcToken_
edm::EDGetTokenT< reco::CandidateView > srcToken_
Definition: ParticleListDrawer.cc:51
EDAnalyzer.h
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
ParticleListDrawer::printOnlyHardInteraction_
bool printOnlyHardInteraction_
Definition: ParticleListDrawer.cc:55
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
ParticleListDrawer::pdt_
edm::ESHandle< ParticleDataTable > pdt_
Definition: ParticleListDrawer.cc:52
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
GenParticle.h
CandidateFwd.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParticleListDrawer::useMessageLogger_
bool useMessageLogger_
Definition: ParticleListDrawer.cc:58
ParticleListDrawer::printFlags_
bool printFlags_
Definition: ParticleListDrawer.cc:57
edm::ESHandle< ParticleDataTable >
HiggsValidation_cfi.particleName
particleName
Definition: HiggsValidation_cfi.py:7
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ParticleDataTable.h
ParticleListDrawer::printVertex_
bool printVertex_
Definition: ParticleListDrawer.cc:56
ParticleListDrawer::maxEventsToPrint_
int maxEventsToPrint_
Definition: ParticleListDrawer.cc:53
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LogVerbatim
Definition: MessageLogger.h:297
ParticleListDrawer::~ParticleListDrawer
~ParticleListDrawer() override
Definition: ParticleListDrawer.cc:44
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:113
ParticleListDrawer::src_
edm::InputTag src_
Definition: ParticleListDrawer.cc:50
std
Definition: JetResolutionObject.h:76
Ref.h
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Exception
Definition: hltDiff.cc:246
ParticleListDrawer
Module to analyze the particle listing as provided by common event generators.
Definition: ParticleListDrawer.cc:41
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
EventSetup.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
ParticleListDrawer::getParticleName
std::string getParticleName(int id) const
Definition: ParticleListDrawer.cc:71
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
Candidate.h
ParameterSet.h
edm::Event
Definition: Event.h:73
ParticleListDrawer::ParticleListDrawer
ParticleListDrawer(const edm::ParameterSet &)
Definition: ParticleListDrawer.cc:61
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27