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