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::one::EDAnalyzer<> edm::one::EDAnalyzerBase 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::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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::DefaultRecordpdtToken_
 
bool printFlags_
 
bool printOnlyHardInteraction_
 
bool printVertex_
 
edm::InputTag src_
 
edm::EDGetTokenT< reco::CandidateViewsrcToken_
 
bool useMessageLogger_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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< Bconsumes (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 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 ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
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::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)) {}
edm::EDGetTokenT< reco::CandidateView > srcToken_
unsigned int nEventAnalyzed_
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_

◆ ~ParticleListDrawer()

ParticleListDrawer::~ParticleListDrawer ( )
inlineoverride

Definition at line 45 of file ParticleListDrawer.cc.

45 {};

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 84 of file ParticleListDrawer.cc.

References visDQMUpload::buf, HLT_2023v12_cff::cands, gather_cfg::cout, Exception, spr::find(), newFWLiteAna::found, edm::EventSetup::getHandle(), getParticleName(), runTauDisplay::gp, heavyIonCSV_trainingSettings::idx, iEvent, edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, MillePedeFileConverter_cfg::out, AlCaHLTBitMon_ParallelJobs::p, HiggsValidation_cfi::particleName, ecalTrigSettings_cff::particles, pdt_, pdtToken_, printFlags_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, 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";
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 }
Log< level::Info, true > LogVerbatim
std::string const & label() const
Definition: InputTag.h:36
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_
int iEvent
Definition: GenABIO.cc:224
unsigned int nEventAnalyzed_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::string getParticleName(int id) const
edm::ESHandle< ParticleDataTable > pdt_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_

◆ getParticleName()

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

Definition at line 74 of file ParticleListDrawer.cc.

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

Member Data Documentation

◆ maxEventsToPrint_

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ nEventAnalyzed_

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ pdt_

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

Definition at line 53 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

◆ pdtToken_

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

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ printFlags_

bool ParticleListDrawer::printFlags_
private

Definition at line 59 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ printOnlyHardInteraction_

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 57 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ printVertex_

bool ParticleListDrawer::printVertex_
private

Definition at line 58 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ src_

edm::InputTag ParticleListDrawer::src_
private

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ srcToken_

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

Definition at line 52 of file ParticleListDrawer.cc.

Referenced by analyze().

◆ useMessageLogger_

bool ParticleListDrawer::useMessageLogger_
private

Definition at line 60 of file ParticleListDrawer.cc.

Referenced by analyze().