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

Public Member Functions

void analyze (const edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 ParticleListDrawer (const edm::ParameterSet &)
 
 ~ParticleListDrawer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

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_
 
bool useMessageLogger_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- 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::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

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

59  :
60  src_(pset.getParameter<InputTag>("src")),
61  maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
62  nEventAnalyzed_(0),
63  printOnlyHardInteraction_(pset.getUntrackedParameter<bool>("printOnlyHardInteraction", false)),
64  printVertex_(pset.getUntrackedParameter<bool>("printVertex", false)),
65  useMessageLogger_(pset.getUntrackedParameter<bool>("useMessageLogger", false)) {
66 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 79 of file ParticleListDrawer.cc.

References gather_cfg::cout, spr::find(), newFWLiteAna::found, edm::Event::getByLabel(), edm::EventSetup::getData(), getParticleName(), edm::InputTag::label(), maxEventsToPrint_, nEventAnalyzed_, dbtoconf::out, AlCaHLTBitMon_ParallelJobs::p, pdt_, printOnlyHardInteraction_, printVertex_, src_, and useMessageLogger_.

79  {
81  iEvent.getByLabel (src_, particles );
82  iSetup.getData( pdt_ );
83 
84  if(maxEventsToPrint_ < 0 || nEventAnalyzed_ < static_cast<unsigned int>(maxEventsToPrint_)) {
85  ostringstream out;
86  char buf[256];
87 
88  out << endl
89  << "[ParticleListDrawer] analysing particle collection " << src_.label() << endl;
90 
91  snprintf(buf, 256, " idx | ID - Name |Stat| Mo1 Mo2 Da1 Da2 |nMo nDa| pt eta phi | px py pz m |");
92  out << buf;
93  if (printVertex_) {
94  snprintf(buf, 256, " vx vy vz |");
95  out << buf;
96  }
97  out << endl;
98 
99  int idx = -1;
100  int iMo1 = -1;
101  int iMo2 = -1;
102  int iDa1 = -1;
103  int iDa2 = -1;
104  vector<const reco::Candidate *> cands;
105  vector<const Candidate *>::const_iterator found = cands.begin();
106  for(CandidateView::const_iterator p = particles->begin();
107  p != particles->end(); ++ p) {
108  cands.push_back(&*p);
109  }
110 
111  for(CandidateView::const_iterator p = particles->begin();
112  p != particles->end();
113  p ++) {
114  if (printOnlyHardInteraction_ && p->status() != 3) continue;
115 
116  // Particle Name
117  int id = p->pdgId();
118  string particleName = getParticleName(id);
119 
120  // Particle Index
121  idx = p - particles->begin();
122 
123  // Particles Mothers and Daighters
124  iMo1 = -1;
125  iMo2 = -1;
126  iDa1 = -1;
127  iDa2 = -1;
128  int nMo = p->numberOfMothers();
129  int nDa = p->numberOfDaughters();
130 
131  found = find(cands.begin(), cands.end(), p->mother(0));
132  if(found != cands.end()) iMo1 = found - cands.begin() ;
133 
134  found = find(cands.begin(), cands.end(), p->mother(nMo-1));
135  if(found != cands.end()) iMo2 = found - cands.begin() ;
136 
137  found = find(cands.begin(), cands.end(), p->daughter(0));
138  if(found != cands.end()) iDa1 = found - cands.begin() ;
139 
140  found = find(cands.begin(), cands.end(), p->daughter(nDa-1));
141  if(found != cands.end()) iDa2 = found - cands.begin() ;
142 
143  char buf[256];
144  snprintf(buf, 256,
145  " %4d | %5d - %10s | %2d | %4d %4d %4d %4d | %2d %2d | %7.3f %10.3f %6.3f | %10.3f %10.3f %10.3f %8.3f |",
146  idx,
147  p->pdgId(),
148  particleName.c_str(),
149  p->status(),
150  iMo1,iMo2,iDa1,iDa2,nMo,nDa,
151  p->pt(),
152  p->eta(),
153  p->phi(),
154  p->px(),
155  p->py(),
156  p->pz(),
157  p->mass()
158  );
159  out << buf;
160 
161  if (printVertex_) {
162  snprintf(buf, 256, " %10.3f %10.3f %10.3f |",
163  p->vertex().x(),
164  p->vertex().y(),
165  p->vertex().z());
166  out << buf;
167  }
168 
169  out << endl;
170  }
171  nEventAnalyzed_++;
172 
173  if (useMessageLogger_)
174  LogVerbatim("ParticleListDrawer") << out.str();
175  else
176  cout << out.str();
177  }
178 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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:67
unsigned int nEventAnalyzed_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple out
Definition: dbtoconf.py:99
std::string const & label() const
Definition: InputTag.h:25
edm::ESHandle< ParticleDataTable > pdt_
std::string getParticleName(int id) const
tuple cout
Definition: gather_cfg.py:121
std::string ParticleListDrawer::getParticleName ( int  id) const
private

Definition at line 68 of file ParticleListDrawer.cc.

References errorMatrix2Lands_multiChannel::id, and pdt_.

Referenced by analyze().

69 {
70  const ParticleData * pd = pdt_->particle( id );
71  if (!pd) {
72  std::ostringstream ss;
73  ss << "P" << id;
74  return ss.str();
75  } else
76  return pd->name();
77 }
HepPDT::ParticleData ParticleData
edm::ESHandle< ParticleDataTable > pdt_

Member Data Documentation

int ParticleListDrawer::maxEventsToPrint_
private

Definition at line 52 of file ParticleListDrawer.cc.

Referenced by analyze().

unsigned int ParticleListDrawer::nEventAnalyzed_
private

Definition at line 53 of file ParticleListDrawer.cc.

Referenced by analyze().

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

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

bool ParticleListDrawer::printOnlyHardInteraction_
private

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::printVertex_
private

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

edm::InputTag ParticleListDrawer::src_
private

Definition at line 50 of file ParticleListDrawer.cc.

Referenced by analyze().

bool ParticleListDrawer::useMessageLogger_
private

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().