CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParticleTreeDrawer.cc
Go to the documentation of this file.
1 /* class ParticleTreeDrawer
2  *
3  * \author Luca Lista, INFN
4  */
5 #include <sstream>
6 
13 
15 public:
17 private:
18  std::string getParticleName( int id ) const;
19  void analyze( const edm::Event &, const edm::EventSetup&) override;
21  void printDecay( const reco::Candidate &, const std::string & pre ) const;
26  typedef std::vector<int> vint;
29  void printInfo( const reco::Candidate & ) const;
31  bool accept( const reco::Candidate & ) const;
33  bool hasValidDaughters( const reco::Candidate & ) const;
35  std::vector<const reco::Candidate *> cands_;
36 };
37 
43 #include <iostream>
44 #include <algorithm>
45 using namespace std;
46 using namespace edm;
47 using namespace reco;
48 
50  srcToken_( consumes<edm::View<reco::Candidate> >(cfg.getParameter<InputTag>( "src" ) ) ),
51  printP4_( cfg.getUntrackedParameter<bool>( "printP4", false ) ),
52  printPtEtaPhi_( cfg.getUntrackedParameter<bool>( "printPtEtaPhi", false ) ),
53  printVertex_( cfg.getUntrackedParameter<bool>( "printVertex", false ) ),
54  printStatus_( cfg.getUntrackedParameter<bool>( "printStatus", false ) ),
55  printIndex_( cfg.getUntrackedParameter<bool>( "printIndex", false ) ),
56  status_( cfg.getUntrackedParameter<vint>( "status", vint() ) ) {
57 }
58 
60  if ( status_.size() == 0 ) return true;
61  return find( status_.begin(), status_.end(), c.status() ) != status_.end();
62 }
63 
65  size_t ndau = c.numberOfDaughters();
66  for( size_t i = 0; i < ndau; ++ i )
67  if ( accept( * c.daughter( i ) ) )
68  return true;
69  return false;
70 }
71 
73 {
74  const ParticleData * pd = pdt_->particle( id );
75  if (!pd) {
76  std::ostringstream ss;
77  ss << "P" << id;
78  return ss.str();
79  } else
80  return pd->name();
81 }
82 
83 void ParticleTreeDrawer::analyze( const Event & event, const EventSetup & es ) {
84  es.getData( pdt_ );
85  Handle<View<Candidate> > particles;
86  event.getByToken( srcToken_, particles );
87  cands_.clear();
88  for( View<Candidate>::const_iterator p = particles->begin();
89  p != particles->end(); ++ p ) {
90  cands_.push_back( & * p );
91  }
92  for( View<Candidate>::const_iterator p = particles->begin();
93  p != particles->end(); ++ p ) {
94  if ( accept( * p ) ) {
95  if ( p->mother() == 0 ) {
96  cout << "-- decay tree: --" << endl;
97  printDecay( * p, "" );
98  }
99  }
100  }
101 }
102 
104  if ( printP4_ ) cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")";
105  if ( printPtEtaPhi_ ) cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
106  if ( printVertex_ ) cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
107  if ( printStatus_ ) cout << "{status: " << c.status() << "}";
108  if ( printIndex_ ) {
109  int idx = -1;
110  vector<const Candidate *>::const_iterator found = find( cands_.begin(), cands_.end(), & c );
111  if ( found != cands_.end() ) {
112  idx = found - cands_.begin();
113  cout << " <idx: " << idx << ">";
114  }
115  }
116 }
117 
118 void ParticleTreeDrawer::printDecay( const Candidate & c, const string & pre ) const {
119  cout << getParticleName( c.pdgId() );
120  printInfo( c );
121  cout << endl;
122 
123  size_t ndau = c.numberOfDaughters(), validDau = 0;
124  for( size_t i = 0; i < ndau; ++ i )
125  if ( accept( * c.daughter( i ) ) )
126  ++ validDau;
127  if ( validDau == 0 ) return;
128 
129  bool lastLevel = true;
130  for( size_t i = 0; i < ndau; ++ i ) {
131  if ( hasValidDaughters( * c.daughter( i ) ) ) {
132  lastLevel = false;
133  break;
134  }
135  }
136 
137  if ( lastLevel ) {
138  cout << pre << "+-> ";
139  size_t vd = 0;
140  for( size_t i = 0; i < ndau; ++ i ) {
141  const Candidate * d = c.daughter( i );
142  if ( accept( * d ) ) {
143  cout << getParticleName( d->pdgId() );
144  printInfo( * d );
145  if ( vd != validDau - 1 )
146  cout << " ";
147  vd ++;
148  }
149  }
150  cout << endl;
151  return;
152  }
153 
154  for( size_t i = 0; i < ndau; ++i ) {
155  const Candidate * d = c.daughter( i );
156  assert( d != 0 );
157  if ( accept( * d ) ) {
158  cout << pre << "+-> ";
159  string prepre( pre );
160  if ( i == ndau - 1 ) prepre += " ";
161  else prepre += "| ";
162  printDecay( * d, prepre );
163  }
164  }
165 }
166 
168 
170 
171 
int i
Definition: DBlmapReader.cc:9
virtual double energy() const =0
energy
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
tuple cfg
Definition: looper.py:259
void printInfo(const reco::Candidate &) const
print 4 momenta
virtual double pt() const =0
transverse momentum
std::vector< const reco::Candidate * > cands_
pointer to collection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< ParticleDataTable > pdt_
std::string getParticleName(int id) const
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
virtual int status() const =0
status word
assert(m_qm.get())
virtual double pz() const =0
z coordinate of momentum vector
virtual double vx() const =0
x coordinate of vertex position
std::vector< int > vint
accepted status codes
void printDecay(const reco::Candidate &, const std::string &pre) const
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
virtual double vy() const =0
y coordinate of vertex position
void analyze(const edm::Event &, const edm::EventSetup &) override
tuple d
Definition: ztail.py:151
virtual size_type numberOfDaughters() const =0
number of daughters
std::vector< DeviationSensor2D * > vd
bool accept(const reco::Candidate &) const
accept candidate
ParticleTreeDrawer(const edm::ParameterSet &)
bool hasValidDaughters(const reco::Candidate &) const
has valid daughters in the chain
bool printP4_
print parameters
virtual double py() const =0
y coordinate of momentum vector
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
HepPDT::ParticleData ParticleData
virtual double px() const =0
x coordinate of momentum vector
virtual int pdgId() const =0
PDG identifier.
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual double vz() const =0
z coordinate of vertex position
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity