CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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_
 
edm::ESGetToken
< ParticleDataTable,
edm::DefaultRecord
pdtToken_
 
bool printFlags_
 
bool printOnlyHardInteraction_
 
bool printVertex_
 
edm::InputTag src_
 
edm::EDGetTokenT
< reco::CandidateView
srcToken_
 
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 wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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 42 of file ParticleListDrawer.cc.

Constructor & Destructor Documentation

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

Definition at line 63 of file ParticleListDrawer.cc.

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)) {}
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::CandidateView > srcToken_
unsigned int nEventAnalyzed_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
ParticleListDrawer::~ParticleListDrawer ( )
inlineoverride

Definition at line 45 of file ParticleListDrawer.cc.

45 {};

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 84 of file ParticleListDrawer.cc.

References visDQMUpload::buf, HLT_FULL_cff::cands, gather_cfg::cout, Exception, spr::find(), newFWLiteAna::found, reco::GenParticle::fromHardProcessBeforeFSR(), reco::GenParticle::fromHardProcessFinalState(), edm::Event::getByToken(), edm::EventSetup::getHandle(), getParticleName(), runTauDisplay::gp, reco::GenParticle::isDirectPromptTauDecayProductFinalState(), reco::GenStatusFlags::isFirstCopy(), reco::GenParticle::isHardProcess(), reco::GenParticle::isLastCopy(), reco::GenParticle::isLastCopyBeforeFSR(), reco::GenParticle::isPromptFinalState(), edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, submitPVResolutionJobs::out, AlCaHLTBitMon_ParallelJobs::p, pdt_, pdtToken_, printFlags_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, reco::GenParticle::statusFlags(), and useMessageLogger_.

84  {
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";
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 }
Log< level::Info, true > LogVerbatim
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:539
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
edm::EDGetTokenT< reco::CandidateView > srcToken_
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
tuple cout
Definition: gather_cfg.py:144
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 74 of file ParticleListDrawer.cc.

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

Referenced by analyze().

74  {
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 }
uint16_t *__restrict__ id
HepPDT::ParticleData ParticleData
edm::ESHandle< ParticleDataTable > pdt_

Member Data Documentation

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().

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

Definition at line 53 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

edm::ESGetToken<ParticleDataTable, edm::DefaultRecord> ParticleListDrawer::pdtToken_
private

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printFlags_
private

Definition at line 59 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 57 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printVertex_
private

Definition at line 58 of file ParticleListDrawer.cc.

Referenced by analyze().

edm::InputTag ParticleListDrawer::src_
private

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze().

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

Definition at line 52 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::useMessageLogger_
private

Definition at line 60 of file ParticleListDrawer.cc.

Referenced by analyze().