CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

std::string getParticleName (int id) const
 

Private Attributes

int maxEventsToPrint_
 
unsigned int nEventAnalyzed_
 
edm::ESHandle< ParticleDataTablepdt_
 
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
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- 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 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 60 of file ParticleListDrawer.cc.

60  :
61  src_(pset.getParameter<InputTag>("src")),
62  srcToken_(consumes<reco::CandidateView>(src_)),
63  maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
64  nEventAnalyzed_(0),
65  printOnlyHardInteraction_(pset.getUntrackedParameter<bool>("printOnlyHardInteraction", false)),
66  printVertex_(pset.getUntrackedParameter<bool>("printVertex", false)),
67  useMessageLogger_(pset.getUntrackedParameter<bool>("useMessageLogger", false)) {
68 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::CandidateView > srcToken_
unsigned int nEventAnalyzed_
ParticleListDrawer::~ParticleListDrawer ( )
inline

Definition at line 44 of file ParticleListDrawer.cc.

44 {};

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 81 of file ParticleListDrawer.cc.

References gather_cfg::cout, spr::find(), newFWLiteAna::found, edm::Event::getByToken(), edm::EventSetup::getData(), getParticleName(), customizeTrackingMonitorSeedNumber::idx, edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, dbtoconf::out, AlCaHLTBitMon_ParallelJobs::p, pdt_, printOnlyHardInteraction_, printVertex_, src_, srcToken_, 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
91  << "[ParticleListDrawer] analysing particle collection " << src_.label() << endl;
92 
93  snprintf(buf, 256, " idx | ID - Name |Stat| Mo1 Mo2 Da1 Da2 |nMo nDa| pt eta phi | px py pz m |");
94  out << buf;
95  if (printVertex_) {
96  snprintf(buf, 256, " vx vy vz |");
97  out << buf;
98  }
99  out << endl;
100 
101  int idx = -1;
102  int iMo1 = -1;
103  int iMo2 = -1;
104  int iDa1 = -1;
105  int iDa2 = -1;
106  vector<const reco::Candidate *> cands;
107  vector<const Candidate *>::const_iterator found = cands.begin();
108  for(CandidateView::const_iterator p = particles->begin();
109  p != particles->end(); ++ p) {
110  cands.push_back(&*p);
111  }
112 
113  for(CandidateView::const_iterator p = particles->begin();
114  p != particles->end();
115  p ++) {
116  if (printOnlyHardInteraction_ && p->status() != 3) 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()) iMo1 = found - cands.begin() ;
135 
136  found = find(cands.begin(), cands.end(), p->mother(nMo-1));
137  if(found != cands.end()) iMo2 = found - cands.begin() ;
138 
139  found = find(cands.begin(), cands.end(), p->daughter(0));
140  if(found != cands.end()) iDa1 = found - cands.begin() ;
141 
142  found = find(cands.begin(), cands.end(), p->daughter(nDa-1));
143  if(found != cands.end()) iDa2 = found - cands.begin() ;
144 
145  char buf[256];
146  snprintf(buf, 256,
147  " %4d | %5d - %10s | %2d | %4d %4d %4d %4d | %2d %2d | %7.3f %10.3f %6.3f | %10.3f %10.3f %10.3f %8.3f |",
148  idx,
149  p->pdgId(),
150  particleName.c_str(),
151  p->status(),
152  iMo1,iMo2,iDa1,iDa2,nMo,nDa,
153  p->pt(),
154  p->eta(),
155  p->phi(),
156  p->px(),
157  p->py(),
158  p->pz(),
159  p->mass()
160  );
161  out << buf;
162 
163  if (printVertex_) {
164  snprintf(buf, 256, " %10.3f %10.3f %10.3f |",
165  p->vertex().x(),
166  p->vertex().y(),
167  p->vertex().z());
168  out << buf;
169  }
170 
171  out << endl;
172  }
173  nEventAnalyzed_++;
174 
175  if (useMessageLogger_)
176  LogVerbatim("ParticleListDrawer") << out.str();
177  else
178  cout << out.str();
179  }
180 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void getData(T &iHolder) const
Definition: EventSetup.h:78
edm::EDGetTokenT< reco::CandidateView > srcToken_
unsigned int nEventAnalyzed_
tuple out
Definition: dbtoconf.py:99
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
std::string const & label() const
Definition: InputTag.h:42
edm::ESHandle< ParticleDataTable > pdt_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::string getParticleName(int id) const
tuple cout
Definition: gather_cfg.py:121
std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 70 of file ParticleListDrawer.cc.

References 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::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 57 of file ParticleListDrawer.cc.

Referenced by analyze().