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
 
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
 
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_
 
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::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
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 = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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...
 
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 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)) {}

◆ ~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::EDAnalyzer.

Definition at line 84 of file ParticleListDrawer.cc.

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 }

References visDQMUpload::buf, HLT_FULL_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_.

◆ getParticleName()

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

Definition at line 74 of file ParticleListDrawer.cc.

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 }

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

Referenced by analyze().

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().

ParticleListDrawer::nEventAnalyzed_
unsigned int nEventAnalyzed_
Definition: ParticleListDrawer.cc:56
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:52
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
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
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
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:60
ParticleListDrawer::printFlags_
bool printFlags_
Definition: ParticleListDrawer.cc:59
HiggsValidation_cfi.particleName
particleName
Definition: HiggsValidation_cfi.py:7
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15144
ParticleListDrawer::printVertex_
bool printVertex_
Definition: ParticleListDrawer.cc:58
ParticleListDrawer::maxEventsToPrint_
int maxEventsToPrint_
Definition: ParticleListDrawer.cc:55
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
ParticleListDrawer::src_
edm::InputTag src_
Definition: ParticleListDrawer.cc:51
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
ParticleListDrawer::pdtToken_
edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
Definition: ParticleListDrawer.cc:54
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
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27