CMS 3D CMS Logo

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

List of all members.

Public Member Functions

void analyze (const edm::Event &iEvent, const edm::EventSetup &iSetup)
 ParticleListDrawer (const edm::ParameterSet &)
 ~ParticleListDrawer ()

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_

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.

                                                                   :
  src_(pset.getParameter<InputTag>("src")),
  maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
  nEventAnalyzed_(0),
  printOnlyHardInteraction_(pset.getUntrackedParameter<bool>("printOnlyHardInteraction", false)),
  printVertex_(pset.getUntrackedParameter<bool>("printVertex", false)),
  useMessageLogger_(pset.getUntrackedParameter<bool>("useMessageLogger", false)) {
}
ParticleListDrawer::~ParticleListDrawer ( ) [inline]

Definition at line 44 of file ParticleListDrawer.cc.

{};

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, L1TEmulatorMonitor_cff::p, pdt_, printOnlyHardInteraction_, printVertex_, src_, and useMessageLogger_.

                                                                                    {  
  Handle<reco::CandidateView> particles;
  iEvent.getByLabel (src_, particles );
  iSetup.getData( pdt_ );

  if(maxEventsToPrint_ < 0 || nEventAnalyzed_ < static_cast<unsigned int>(maxEventsToPrint_)) {
    ostringstream out;
    char buf[256];

    out << endl
        << "[ParticleListDrawer] analysing particle collection " << src_.label() << endl;

    snprintf(buf, 256, " idx  |    ID -       Name |Stat|  Mo1  Mo2  Da1  Da2 |nMo nDa|    pt       eta     phi   |     px         py         pz        m     |"); 
    out << buf;
    if (printVertex_) {
      snprintf(buf, 256, "        vx       vy        vz     |");
      out << buf;
    }
    out << endl; 

    int idx  = -1;
    int iMo1 = -1;
    int iMo2 = -1;
    int iDa1 = -1;
    int iDa2 = -1;
    vector<const reco::Candidate *> cands;
    vector<const Candidate *>::const_iterator found = cands.begin();
    for(CandidateView::const_iterator p = particles->begin();
        p != particles->end(); ++ p) {
      cands.push_back(&*p);
    }

    for(CandidateView::const_iterator p  = particles->begin();
        p != particles->end(); 
        p ++) {
      if (printOnlyHardInteraction_ && p->status() != 3) continue;

      // Particle Name
      int id = p->pdgId();
      string particleName = getParticleName(id);
      
      // Particle Index
      idx =  p - particles->begin();

      // Particles Mothers and Daighters
      iMo1 = -1;
      iMo2 = -1;
      iDa1 = -1;
      iDa2 = -1;
      int nMo = p->numberOfMothers();
      int nDa = p->numberOfDaughters();

      found = find(cands.begin(), cands.end(), p->mother(0));
      if(found != cands.end()) iMo1 = found - cands.begin() ;

      found = find(cands.begin(), cands.end(), p->mother(nMo-1));
      if(found != cands.end()) iMo2 = found - cands.begin() ;
     
      found = find(cands.begin(), cands.end(), p->daughter(0));
      if(found != cands.end()) iDa1 = found - cands.begin() ;

      found = find(cands.begin(), cands.end(), p->daughter(nDa-1));
      if(found != cands.end()) iDa2 = found - cands.begin() ;

      char buf[256];
      snprintf(buf, 256,
             " %4d | %5d - %10s | %2d | %4d %4d %4d %4d | %2d %2d | %7.3f %10.3f %6.3f | %10.3f %10.3f %10.3f %8.3f |",
             idx,
             p->pdgId(),
             particleName.c_str(),
             p->status(),
             iMo1,iMo2,iDa1,iDa2,nMo,nDa,
             p->pt(),
             p->eta(),
             p->phi(),
             p->px(),
             p->py(),
             p->pz(),
             p->mass()
            );
      out << buf;

      if (printVertex_) {
        snprintf(buf, 256, " %10.3f %10.3f %10.3f |",
                 p->vertex().x(),
                 p->vertex().y(),
                 p->vertex().z());
        out << buf;
      }

      out << endl;
    }
    nEventAnalyzed_++;

    if (useMessageLogger_)
      LogVerbatim("ParticleListDrawer") << out.str();
    else
      cout << out.str();
  }
}
std::string ParticleListDrawer::getParticleName ( int  id) const [private]

Definition at line 68 of file ParticleListDrawer.cc.

References pdt_.

Referenced by analyze().

{
  const ParticleData * pd = pdt_->particle( id );
  if (!pd) {
    std::ostringstream ss;
    ss << "P" << id;
    return ss.str();
  } else
    return pd->name();
}

Member Data Documentation

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

Definition at line 51 of file ParticleListDrawer.cc.

Referenced by analyze(), and getParticleName().

Definition at line 54 of file ParticleListDrawer.cc.

Referenced by analyze().

Definition at line 55 of file ParticleListDrawer.cc.

Referenced by analyze().

Definition at line 50 of file ParticleListDrawer.cc.

Referenced by analyze().

Definition at line 56 of file ParticleListDrawer.cc.

Referenced by analyze().