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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
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
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, 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)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, 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 ( 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)) {}
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::CandidateView > srcToken_
unsigned int nEventAnalyzed_
ParticleListDrawer::~ParticleListDrawer ( )
inlineoverride

Definition at line 44 of file ParticleListDrawer.cc.

References analyze(), iEvent, and AlCaHLTBitMon_QueryRunRegistry::string.

44 {};

Member Function Documentation

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

Definition at line 81 of file ParticleListDrawer.cc.

References edm::View< T >::begin(), HLT_2018_cff::cands, gather_cfg::cout, DEFINE_FWK_MODULE, edm::View< T >::end(), Exception, spr::find(), newFWLiteAna::found, reco::GenParticle::fromHardProcessBeforeFSR(), reco::GenParticle::fromHardProcessFinalState(), edm::Event::getByToken(), edm::EventSetup::getData(), getParticleName(), runTauDisplay::gp, training_settings::idx, reco::GenParticle::isDirectPromptTauDecayProductFinalState(), reco::GenStatusFlags::isFirstCopy(), reco::GenParticle::isHardProcess(), reco::GenParticle::isLastCopy(), reco::GenParticle::isLastCopyBeforeFSR(), reco::GenParticle::isPromptFinalState(), edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, MillePedeFileConverter_cfg::out, AlCaHLTBitMon_ParallelJobs::p, HiggsValidation_cfi::particleName, ecalTrigSettings_cff::particles, pdt_, printFlags_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, reco::GenParticle::statusFlags(), and useMessageLogger_.

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";
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 }
bool isPromptFinalState() const
Definition: GenParticle.h:51
bool isLastCopyBeforeFSR() const
Definition: GenParticle.h:106
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool isLastCopy() const
Definition: GenParticle.h:101
bool isHardProcess() const
Definition: GenParticle.h:72
bool fromHardProcessBeforeFSR() const
Definition: GenParticle.h:94
bool isFirstCopy() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool getData(T &iHolder) const
Definition: EventSetup.h:113
edm::EDGetTokenT< reco::CandidateView > srcToken_
const_iterator begin() const
unsigned int nEventAnalyzed_
const GenStatusFlags & statusFlags() const
Definition: GenParticle.h:38
bool fromHardProcessFinalState() const
Definition: GenParticle.h:75
std::string const & label() const
Definition: InputTag.h:36
edm::ESHandle< ParticleDataTable > pdt_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::string getParticleName(int id) const
bool isDirectPromptTauDecayProductFinalState() const
Definition: GenParticle.h:59
const_iterator end() const
std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 71 of file ParticleListDrawer.cc.

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

Referenced by analyze().

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 }
HepPDT::ParticleData ParticleData
edm::ESHandle< ParticleDataTable > pdt_

Member Data Documentation

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 53 of file ParticleListDrawer.cc.

Referenced by analyze().

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

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

Definition at line 52 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

bool ParticleListDrawer::printFlags_
private

Definition at line 57 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printVertex_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().

edm::InputTag ParticleListDrawer::src_
private

Definition at line 50 of file ParticleListDrawer.cc.

Referenced by analyze().

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

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::useMessageLogger_
private

Definition at line 58 of file ParticleListDrawer.cc.

Referenced by analyze().