CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ParticleListDrawer Class Reference

Module to analyze the particle listing as provided by common event generators. More...

Inheritance diagram for ParticleListDrawer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ParticleListDrawer (const edm::ParameterSet &)
 
 ~ParticleListDrawer () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

std::string getParticleName (int id) const
 

Private Attributes

int maxEventsToPrint_
 
unsigned int nEventAnalyzed_
 
edm::ESHandle< ParticleDataTablepdt_
 
bool printFlags_
 
bool printOnlyHardInteraction_
 
bool printVertex_
 
edm::InputTag src_
 
edm::EDGetTokenT< reco::CandidateViewsrcToken_
 
bool useMessageLogger_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Module to analyze the particle listing as provided by common event generators.

Module to analyze the particle listing as provided by common event generators equivalent to PYLIST(1) (from pythia). It is expected to run on vectors of reo::GenParticles. For an example of use have a look to:

PhysicsTools/HepMCCandAlgos/test/testParticleTreeDrawer.py

Caveats: Status 3 particles can have daughters both with status 2 and 3. In pythia this is not the same mother-daughter. The relations are correct but special care has to be taken when looking at mother-daughter relation which involve status 2 and 3 particles.

Definition at line 41 of file ParticleListDrawer.cc.

Constructor & Destructor Documentation

◆ ParticleListDrawer()

ParticleListDrawer::ParticleListDrawer ( const edm::ParameterSet pset)
explicit

Definition at line 61 of file ParticleListDrawer.cc.

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)) {}

◆ ~ParticleListDrawer()

ParticleListDrawer::~ParticleListDrawer ( )
inlineoverride

Definition at line 44 of file ParticleListDrawer.cc.

44 {};

Member Function Documentation

◆ analyze()

void ParticleListDrawer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDAnalyzer.

Definition at line 81 of file ParticleListDrawer.cc.

81  {
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 }

References visDQMUpload::buf, HLT_2018_cff::cands, gather_cfg::cout, Exception, spr::find(), newFWLiteAna::found, edm::EventSetup::getData(), getParticleName(), runTauDisplay::gp, charmTagsComputerCvsB_cfi::idx, iEvent, edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, MillePedeFileConverter_cfg::out, AlCaHLTBitMon_ParallelJobs::p, HiggsValidation_cfi::particleName, ecalTrigSettings_cff::particles, pdt_, printFlags_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, and useMessageLogger_.

◆ getParticleName()

std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 71 of file ParticleListDrawer.cc.

71  {
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 }

References triggerObjects_cff::id, pdt_, and contentValuesCheck::ss.

Referenced by analyze().

Member Data Documentation

◆ maxEventsToPrint_

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 53 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ nEventAnalyzed_

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ pdt_

edm::ESHandle<ParticleDataTable> ParticleListDrawer::pdt_
private

Definition at line 52 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

◆ printFlags_

bool ParticleListDrawer::printFlags_
private

Definition at line 57 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ printOnlyHardInteraction_

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ printVertex_

bool ParticleListDrawer::printVertex_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ src_

edm::InputTag ParticleListDrawer::src_
private

Definition at line 50 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ srcToken_

edm::EDGetTokenT<reco::CandidateView> ParticleListDrawer::srcToken_
private

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ useMessageLogger_

bool ParticleListDrawer::useMessageLogger_
private

Definition at line 58 of file ParticleListDrawer.cc.

Referenced by analyze().

ParticleListDrawer::nEventAnalyzed_
unsigned int nEventAnalyzed_
Definition: ParticleListDrawer.cc:54
reco::GenParticle
Definition: GenParticle.h:21
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
charmTagsComputerCvsB_cfi.idx
idx
Definition: charmTagsComputerCvsB_cfi.py:108
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
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
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
ParticleListDrawer::useMessageLogger_
bool useMessageLogger_
Definition: ParticleListDrawer.cc:58
ParticleListDrawer::printFlags_
bool printFlags_
Definition: ParticleListDrawer.cc:57
HiggsValidation_cfi.particleName
particleName
Definition: HiggsValidation_cfi.py:7
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
ParticleListDrawer::printVertex_
bool printVertex_
Definition: ParticleListDrawer.cc:56
ParticleListDrawer::maxEventsToPrint_
int maxEventsToPrint_
Definition: ParticleListDrawer.cc:53
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LogVerbatim
Definition: MessageLogger.h:297
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:113
ParticleListDrawer::src_
edm::InputTag src_
Definition: ParticleListDrawer.cc:50
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Exception
Definition: hltDiff.cc:246
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
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
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27