CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

ParticleTreeDrawer Class Reference

Inheritance diagram for ParticleTreeDrawer:
edm::EDAnalyzer

List of all members.

Public Member Functions

 ParticleTreeDrawer (const edm::ParameterSet &)

Private Types

typedef std::vector< int > vint
 accepted status codes

Private Member Functions

bool accept (const reco::Candidate &) const
 accept candidate
void analyze (const edm::Event &, const edm::EventSetup &)
std::string getParticleName (int id) const
bool hasValidDaughters (const reco::Candidate &) const
 has valid daughters in the chain
void printDecay (const reco::Candidate &, const std::string &pre) const
void printInfo (const reco::Candidate &) const
 print 4 momenta

Private Attributes

std::vector< const
reco::Candidate * > 
cands_
 pointer to collection
edm::ESHandle< ParticleDataTablepdt_
bool printIndex_
bool printP4_
 print parameters
bool printPtEtaPhi_
bool printStatus_
bool printVertex_
edm::InputTag src_
vint status_

Detailed Description

Definition at line 13 of file ParticleTreeDrawer.cc.


Member Typedef Documentation

typedef std::vector<int> ParticleTreeDrawer::vint [private]

accepted status codes

Definition at line 25 of file ParticleTreeDrawer.cc.


Constructor & Destructor Documentation

ParticleTreeDrawer::ParticleTreeDrawer ( const edm::ParameterSet cfg)

Definition at line 49 of file ParticleTreeDrawer.cc.

                                                                 :
  src_( cfg.getParameter<InputTag>( "src" ) ),
  printP4_( cfg.getUntrackedParameter<bool>( "printP4", false ) ),
  printPtEtaPhi_( cfg.getUntrackedParameter<bool>( "printPtEtaPhi", false ) ),
  printVertex_( cfg.getUntrackedParameter<bool>( "printVertex", false ) ),
  printStatus_( cfg.getUntrackedParameter<bool>( "printStatus", false ) ),
  printIndex_( cfg.getUntrackedParameter<bool>( "printIndex", false ) ),
  status_( cfg.getUntrackedParameter<vint>( "status", vint() ) ) {
}

Member Function Documentation

bool ParticleTreeDrawer::accept ( const reco::Candidate c) const [private]

accept candidate

Definition at line 59 of file ParticleTreeDrawer.cc.

References spr::find(), reco::Candidate::status(), and status_.

Referenced by analyze(), hasValidDaughters(), and printDecay().

                                                               {
  if ( status_.size() == 0 ) return true;
  return find( status_.begin(), status_.end(), c.status() ) != status_.end();
}
void ParticleTreeDrawer::analyze ( const edm::Event event,
const edm::EventSetup es 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 83 of file ParticleTreeDrawer.cc.

References accept(), cands_, gather_cfg::cout, edm::EventSetup::getData(), AlCaHLTBitMon_ParallelJobs::p, pdt_, printDecay(), and src_.

                                                                             {  
  es.getData( pdt_ );
  Handle<View<Candidate> > particles;
  event.getByLabel( src_, particles );
  cands_.clear();
  for( View<Candidate>::const_iterator p = particles->begin();
       p != particles->end(); ++ p ) {
    cands_.push_back( & * p );
  }
  for( View<Candidate>::const_iterator p = particles->begin();
       p != particles->end(); ++ p ) {
    if ( accept( * p ) ) {
      if ( p->mother() == 0 ) {
        cout << "-- decay tree: --" << endl;
        printDecay( * p, "" );
      }
    }
  }
}
std::string ParticleTreeDrawer::getParticleName ( int  id) const [private]

Definition at line 72 of file ParticleTreeDrawer.cc.

References errorMatrix2Lands_multiChannel::id, and pdt_.

Referenced by printDecay().

{
  const ParticleData * pd = pdt_->particle( id );
  if (!pd) {
    std::ostringstream ss;
    ss << "P" << id;
    return ss.str();
  } else
    return pd->name();
}
bool ParticleTreeDrawer::hasValidDaughters ( const reco::Candidate c) const [private]

has valid daughters in the chain

Definition at line 64 of file ParticleTreeDrawer.cc.

References accept(), reco::Candidate::daughter(), i, and reco::Candidate::numberOfDaughters().

Referenced by printDecay().

                                                                          {
  size_t ndau = c.numberOfDaughters();
  for( size_t i = 0; i < ndau; ++ i )
    if ( accept( * c.daughter( i ) ) )
      return true;
  return false;
}
void ParticleTreeDrawer::printDecay ( const reco::Candidate ,
const std::string &  pre 
) const [private]

Definition at line 118 of file ParticleTreeDrawer.cc.

References accept(), gather_cfg::cout, reco::Candidate::daughter(), getParticleName(), hasValidDaughters(), i, reco::Candidate::numberOfDaughters(), reco::Candidate::pdgId(), and printInfo().

Referenced by analyze().

                                                                                   {
  cout << getParticleName( c.pdgId() );
  printInfo( c );
  cout << endl;

  size_t ndau = c.numberOfDaughters(), validDau = 0;
  for( size_t i = 0; i < ndau; ++ i )
    if ( accept( * c.daughter( i ) ) )
      ++ validDau;
  if ( validDau == 0 ) return;
  
  bool lastLevel = true;
  for( size_t i = 0; i < ndau; ++ i ) {
    if ( hasValidDaughters( * c.daughter( i ) ) ) {
      lastLevel = false;
      break;
    }      
  }
  
  if ( lastLevel ) {
    cout << pre << "+-> ";
    size_t vd = 0;
    for( size_t i = 0; i < ndau; ++ i ) {
      const Candidate * d = c.daughter( i );
      if ( accept( * d ) ) {
        cout << getParticleName( d->pdgId() );
        printInfo( * d );
        if ( vd != validDau - 1 )
          cout << " ";
        vd ++;
      }
    }
    cout << endl;
    return;
  }

  for( size_t i = 0; i < ndau; ++i ) {
    const Candidate * d = c.daughter( i );
    assert( d != 0 );
    if ( accept( * d ) ) {
      cout << pre << "+-> ";
      string prepre( pre );
      if ( i == ndau - 1 ) prepre += "    ";
      else prepre += "|   ";
      printDecay( * d, prepre );
    }
  }
}
void ParticleTreeDrawer::printInfo ( const reco::Candidate c) const [private]

print 4 momenta

Definition at line 103 of file ParticleTreeDrawer.cc.

References trackerHits::c, cands_, gather_cfg::cout, reco::Candidate::energy(), reco::Candidate::eta(), spr::find(), newFWLiteAna::found, reco::Candidate::phi(), printIndex_, printP4_, printPtEtaPhi_, printStatus_, printVertex_, reco::Candidate::pt(), reco::Candidate::px(), reco::Candidate::py(), reco::Candidate::pz(), reco::Candidate::status(), reco::Candidate::vx(), reco::Candidate::vy(), and reco::Candidate::vz().

Referenced by printDecay().

                                                              {
  if ( printP4_ ) cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")"; 
  if ( printPtEtaPhi_ ) cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
  if ( printVertex_ ) cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
  if ( printStatus_ ) cout << "{status: " << c.status() << "}";
  if ( printIndex_ ) {
    int idx = -1;
    vector<const Candidate *>::const_iterator found = find( cands_.begin(), cands_.end(), & c );
    if ( found != cands_.end() ) {
      idx = found - cands_.begin();
      cout << " <idx: " << idx << ">";
    }
  }
}

Member Data Documentation

std::vector<const reco::Candidate *> ParticleTreeDrawer::cands_ [private]

pointer to collection

Definition at line 34 of file ParticleTreeDrawer.cc.

Referenced by analyze(), and printInfo().

Definition at line 21 of file ParticleTreeDrawer.cc.

Referenced by analyze(), and getParticleName().

Definition at line 23 of file ParticleTreeDrawer.cc.

Referenced by printInfo().

print parameters

Definition at line 23 of file ParticleTreeDrawer.cc.

Referenced by printInfo().

Definition at line 23 of file ParticleTreeDrawer.cc.

Referenced by printInfo().

Definition at line 23 of file ParticleTreeDrawer.cc.

Referenced by printInfo().

Definition at line 23 of file ParticleTreeDrawer.cc.

Referenced by printInfo().

Definition at line 19 of file ParticleTreeDrawer.cc.

Referenced by analyze().

Definition at line 26 of file ParticleTreeDrawer.cc.

Referenced by accept().