CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParticleDecayDrawer.cc
Go to the documentation of this file.
1 /* class ParticleDecayDrawer
2  *
3  * \author Luca Lista, INFN
4  */
10 
12 public:
14 private:
15  void analyze( const edm::Event &, const edm::EventSetup & );
17  std::string decay( const reco::Candidate &, std::list<const reco::Candidate *> & ) const;
22  std::string printP4( const reco::Candidate & ) const;
24  bool accept( const reco::Candidate &, const std::list<const reco::Candidate *> & ) const;
26  bool select( const reco::Candidate & ) const;
28  bool hasValidDaughters( const reco::Candidate & ) const;
29 };
30 
37 #include <iostream>
38 #include <sstream>
39 #include <algorithm>
40 using namespace std;
41 using namespace edm;
42 using namespace reco;
43 
45  src_( cfg.getParameter<InputTag>( "src" ) ),
46  printP4_( cfg.getUntrackedParameter<bool>( "printP4", false ) ),
47  printPtEtaPhi_( cfg.getUntrackedParameter<bool>( "printPtEtaPhi", false ) ),
48  printVertex_( cfg.getUntrackedParameter<bool>( "printVertex", false ) ) {
49 }
50 
51 bool ParticleDecayDrawer::accept( const reco::Candidate & c, const list<const Candidate *> & skip ) const {
52  if( find( skip.begin(), skip.end(), & c ) != skip.end() ) return false;
53  return select( c );
54 }
55 
57  return c.status() == 3;
58 }
59 
61  size_t ndau = c.numberOfDaughters();
62  for( size_t i = 0; i < ndau; ++ i )
63  if ( select( * c.daughter( i ) ) )
64  return true;
65  return false;
66 }
67 
68 void ParticleDecayDrawer::analyze( const Event & event, const EventSetup & es ) {
69  es.getData( pdt_ );
70  Handle<View<Candidate> > particles;
71  event.getByLabel( src_, particles );
72  list<const Candidate *> skip;
73  vector<const Candidate *> nodes, moms;
74  for( View<Candidate>::const_iterator p = particles->begin();
75  p != particles->end(); ++ p ) {
76  if( p->numberOfMothers() > 1 ) {
77  if ( select( * p ) ) {
78  skip.push_back( & * p );
79  nodes.push_back( & * p );
80  for( size_t j = 0; j < p->numberOfMothers(); ++ j ) {
81  const Candidate * mom = p->mother( j );
82  const Candidate * grandMom;
83  while ( ( grandMom = mom->mother() ) != 0 )
84  mom = grandMom;
85  if ( select( * mom ) ) {
86  moms.push_back( mom );
87  }
88  }
89  }
90  }
91  }
92  cout << "-- decay: --" << endl;
93  if( moms.size() > 0 ) {
94  if ( moms.size() > 1 )
95  for( size_t m = 0; m < moms.size(); ++ m ) {
96  string dec = decay( * moms[ m ], skip );
97  if ( ! dec.empty() )
98  cout << "{ " << dec << " } ";
99  }
100  else
101  cout << decay( * moms[ 0 ], skip );
102  }
103  if ( nodes.size() > 0 ) {
104  cout << "-> ";
105  if ( nodes.size() > 1 ) {
106  for( size_t n = 0; n < nodes.size(); ++ n ) {
107  skip.remove( nodes[ n ] );
108  string dec = decay( * nodes[ n ], skip );
109  if ( ! dec.empty() ) {
110  if ( dec.find( "->", 0 ) != string::npos )
111  cout << " ( " << dec << " )";
112  else
113  cout << " " << dec;
114  }
115  }
116  } else {
117  skip.remove( nodes[ 0 ] );
118  cout << decay( * nodes[ 0 ], skip );
119  }
120  }
121  cout << endl;
122 }
123 
124 string ParticleDecayDrawer::printP4( const Candidate & c ) const {
125  ostringstream cout;
126  if ( printP4_ ) cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")";
127  if ( printPtEtaPhi_ ) cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
128  if ( printVertex_ ) cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
129  return cout.str();
130 }
131 
133  list<const Candidate *> & skip ) const {
134  string out;
135  if ( find( skip.begin(), skip.end(), & c ) != skip.end() )
136  return out;
137  skip.push_back( & c );
138 
139 
140  int id = c.pdgId();
141  const ParticleData * pd = pdt_->particle( id );
142  assert( pd != 0 );
143  out += ( pd->name() + printP4( c ) );
144 
145  size_t validDau = 0, ndau = c.numberOfDaughters();
146  for( size_t i = 0; i < ndau; ++ i )
147  if ( accept( * c.daughter( i ), skip ) )
148  ++ validDau;
149  if ( validDau == 0 ) return out;
150 
151  out += " ->";
152 
153  for( size_t i = 0; i < ndau; ++ i ) {
154  const Candidate * d = c.daughter( i );
155  if ( accept( * d, skip ) ) {
156  string dec = decay( * d, skip );
157  if ( dec.find( "->", 0 ) != string::npos )
158  out += ( " ( " + dec + " )" );
159  else
160  out += ( " " + dec );
161  }
162  }
163  return out;
164 }
165 
167 
169 
bool hasValidDaughters(const reco::Candidate &) const
has valid daughters in the chain
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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) ...
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool accept(const reco::Candidate &, const std::list< const reco::Candidate * > &) const
accept candidate
std::string printP4(const reco::Candidate &) const
print 4 momenta
virtual int status() const =0
status word
virtual double pz() const =0
z coordinate of momentum vector
virtual double vx() const =0
x coordinate of vertex position
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
edm::ESHandle< ParticleDataTable > pdt_
void getData(T &iHolder) const
Definition: EventSetup.h:67
virtual double vy() const =0
y coordinate of vertex position
virtual size_type numberOfDaughters() const =0
number of daughters
std::string decay(const reco::Candidate &, std::list< const reco::Candidate * > &) const
bool select(const reco::Candidate &) const
select candidate
ParticleDecayDrawer(const edm::ParameterSet &)
int j
Definition: DBlmapReader.cc:9
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
tuple out
Definition: dbtoconf.py:99
virtual int pdgId() const =0
PDG identifier.
virtual double vz() const =0
z coordinate of vertex position
void analyze(const edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity