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

Constructor & Destructor Documentation

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

Definition at line 62 of file ParticleListDrawer.cc.

62  :
63  src_(pset.getParameter<InputTag>("src")),
64  srcToken_(consumes<reco::CandidateView>(src_)),
65  maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
66  nEventAnalyzed_(0),
67  printOnlyHardInteraction_(pset.getUntrackedParameter<bool>("printOnlyHardInteraction", false)),
68  printVertex_(pset.getUntrackedParameter<bool>("printVertex", false)),
69  printFlags_(pset.getUntrackedParameter<bool>("printFlags", false)),
70  useMessageLogger_(pset.getUntrackedParameter<bool>("useMessageLogger", false)) {
71 }
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 45 of file ParticleListDrawer.cc.

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

45 {};

Member Function Documentation

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

Definition at line 84 of file ParticleListDrawer.cc.

References edm::View< T >::begin(), egammaForCoreTracking_cff::cands, gather_cfg::cout, DEFINE_FWK_MODULE, edm::View< T >::end(), Exception, spr::find(), runEdmFileComparison::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, HadronAndPartonSelector_cfi::particles, pdt_, printFlags_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, reco::GenParticle::statusFlags(), and useMessageLogger_.

84  {
86  iEvent.getByToken(srcToken_, particles );
87  iSetup.getData( pdt_ );
88 
89  if(maxEventsToPrint_ < 0 || nEventAnalyzed_ < static_cast<unsigned int>(maxEventsToPrint_)) {
90  ostringstream out;
91  char buf[256];
92 
93  out << endl
94  << "[ParticleListDrawer] analysing particle collection " << src_.label() << endl;
95 
96  snprintf(buf, sizeof(buf), " idx | ID - Name |Stat| Mo1 Mo2 Da1 Da2 |nMo nDa| pt eta phi | px py pz m |");
97  out << buf;
98  if (printVertex_) {
99  snprintf(buf, sizeof(buf), " vx vy vz |");
100  out << buf;
101  }
102  out << endl;
103 
104  int idx = -1;
105  int iMo1 = -1;
106  int iMo2 = -1;
107  int iDa1 = -1;
108  int iDa2 = -1;
109  vector<const reco::Candidate *> cands;
110  vector<const Candidate *>::const_iterator found = cands.begin();
111  for(CandidateView::const_iterator p = particles->begin();
112  p != particles->end(); ++ p) {
113  cands.push_back(&*p);
114  }
115 
116  for(CandidateView::const_iterator p = particles->begin();
117  p != particles->end();
118  p ++) {
119  if (printOnlyHardInteraction_ && p->status() != 3) 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()) iMo1 = found - cands.begin() ;
138 
139  found = find(cands.begin(), cands.end(), p->mother(nMo-1));
140  if(found != cands.end()) iMo2 = found - cands.begin() ;
141 
142  found = find(cands.begin(), cands.end(), p->daughter(0));
143  if(found != cands.end()) iDa1 = found - cands.begin() ;
144 
145  found = find(cands.begin(), cands.end(), p->daughter(nDa-1));
146  if(found != cands.end()) iDa2 = found - cands.begin() ;
147 
148  char buf[2400];
149  snprintf(buf, sizeof(buf),
150  " %4d | %5d - %10s | %2d | %4d %4d %4d %4d | %2d %2d | %7.3f %10.3f %6.3f | %10.3f %10.3f %10.3f %8.3f |",
151  idx,
152  p->pdgId(),
153  particleName.c_str(),
154  p->status(),
155  iMo1,iMo2,iDa1,iDa2,nMo,nDa,
156  p->pt(),
157  p->eta(),
158  p->phi(),
159  p->px(),
160  p->py(),
161  p->pz(),
162  p->mass()
163  );
164  out << buf;
165 
166  if (printVertex_) {
167  snprintf(buf, sizeof(buf), " %10.3f %10.3f %10.3f |",
168  p->vertex().x(),
169  p->vertex().y(),
170  p->vertex().z());
171  out << buf;
172  }
173 
174  if (printFlags_) {
175  const reco::GenParticle *gp = dynamic_cast<const reco::GenParticle *>(&*p);
176  if (!gp) throw cms::Exception("Unsupported", "Status flags can be printed only for reco::GenParticle objects\n");
177  if (gp->isPromptFinalState()) out << " PromptFinalState";
178  if (gp->isDirectPromptTauDecayProductFinalState()) out << " DirectPromptTauDecayProductFinalState";
179  if (gp->isHardProcess()) out << " HardProcess";
180  if (gp->fromHardProcessFinalState()) out << " HardProcessFinalState";
181  if (gp->fromHardProcessBeforeFSR()) out << " HardProcessBeforeFSR";
182  if (gp->statusFlags().isFirstCopy()) out << " FirstCopy";
183  if (gp->isLastCopy()) out << " LastCopy";
184  if (gp->isLastCopyBeforeFSR()) out << " LastCopyBeforeFSR";
185  }
186 
187  out << endl;
188  }
189  nEventAnalyzed_++;
190 
191  if (useMessageLogger_)
192  LogVerbatim("ParticleListDrawer") << out.str();
193  else
194  cout << out.str();
195  }
196 }
bool isPromptFinalState() const
Definition: GenParticle.h:54
bool isLastCopyBeforeFSR() const
Definition: GenParticle.h:103
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool isLastCopy() const
Definition: GenParticle.h:98
bool isHardProcess() const
Definition: GenParticle.h:73
bool fromHardProcessBeforeFSR() const
Definition: GenParticle.h:91
bool isFirstCopy() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool getData(T &iHolder) const
Definition: EventSetup.h:111
edm::EDGetTokenT< reco::CandidateView > srcToken_
const_iterator begin() const
unsigned int nEventAnalyzed_
const GenStatusFlags & statusFlags() const
Definition: GenParticle.h:41
bool fromHardProcessFinalState() const
Definition: GenParticle.h:76
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:62
const_iterator end() const
std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 73 of file ParticleListDrawer.cc.

References triggerObjects_cff::id, and pdt_.

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

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 55 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().

bool ParticleListDrawer::printFlags_
private

Definition at line 58 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printVertex_
private

Definition at line 57 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 59 of file ParticleListDrawer.cc.

Referenced by analyze().