ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/ParticleTreeDrawer.cc
Revision: 1.1
Committed: Mon May 19 16:12:28 2008 UTC (16 years, 11 months ago) by mlethuil
Content type: text/plain
Branch: MAIN
CVS Tags: cmssw_1_6_12
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 mlethuil 1.1 #include "UserCode/Morgan/interface/ParticleTreeDrawer.h"
2    
3     #include "FWCore/ParameterSet/interface/ParameterSet.h"
4     #include "FWCore/Framework/interface/Event.h"
5     //#include "FWCore/Framework/interface/Handle.h"
6     #include "FWCore/Framework/interface/EventSetup.h"
7     #include "DataFormats/HepMCCandidate/interface/GenParticleCandidate.h"
8     #include "FWCore/Utilities/interface/EDMException.h"
9     #include <iostream>
10     #include <sstream>
11    
12     using namespace std;
13     using namespace edm;
14     using namespace reco;
15     using namespace HepMC;
16    
17    
18     ParticleTreeDrawer::ParticleTreeDrawer() :
19     src_("genParticleCandidates"), printP4_(false), printPtEtaPhi_(false), printVertex_(false), printStatus_(false)
20     {}
21    
22     void ParticleTreeDrawer::analyze( const Event & event, const EventSetup & es )
23     {
24     es.getData( pdt_ );
25     Handle<CandidateCollection> particles;
26     event.getByLabel( "genParticleCandidates", particles );
27     for( CandidateCollection::const_iterator p = particles->begin();
28     p != particles->end(); ++ p )
29     {
30     if ( p->mother() == 0 )
31     {
32     cout << "-- decay: --" << endl;
33     printDecay( * p, "" );
34     }
35     }
36     }
37    
38     void ParticleTreeDrawer::printP4( const reco::Candidate & c ) const
39     {
40     if ( printP4_ )
41     cout << " (" << c.px() << ", " << c.py() << ", " << c.pz() << "; " << c.energy() << ")";
42     if ( printPtEtaPhi_ )
43     cout << " [" << c.pt() << ": " << c.eta() << ", " << c.phi() << "]";
44     if ( printVertex_ )
45     cout << " {" << c.vx() << ", " << c.vy() << ", " << c.vz() << "}";
46     if ( printStatus_ )
47     cout << "{status: " << c.status() << "}";
48     }
49    
50     void ParticleTreeDrawer::printDecay( const reco::Candidate & c, const std::string & pre ) const
51     {
52     int id = c.pdgId();
53     unsigned int ndau = c.numberOfDaughters();
54     const ParticleData * pd = pdt_->particle( id );
55     assert( pd != 0 );
56    
57     cout << pd->name();
58     printP4( c );
59     cout << endl;
60    
61     if ( ndau == 0 )
62     return;
63    
64     bool lastLevel = true;
65     for( size_t i = 0; i < ndau; ++ i )
66     if ( c.daughter( i )->numberOfDaughters() != 0 )
67     {
68     lastLevel = false;
69     break;
70     }
71    
72     if ( lastLevel )
73     {
74     cout << pre << "+-> ";
75     for( size_t i = 0; i < ndau; ++ i )
76     {
77     const GenParticleCandidate * d =
78     dynamic_cast<const GenParticleCandidate *>( c.daughter( i ) );
79     assert( d != 0 );
80     const ParticleData * pd = pdt_->particle( d->pdgId() );
81     assert( pd != 0 );
82     cout << pd->name();
83     printP4( * d );
84     if ( i != ndau - 1 )
85     cout << " ";
86     }
87     cout << endl;
88     return;
89     }
90    
91     for( size_t i = 0; i < ndau; ++i )
92     {
93     const GenParticleCandidate * d =
94     dynamic_cast<const GenParticleCandidate *>( c.daughter( i ) );
95     cout << pre << "+-> ";
96     string prepre( pre );
97     if ( i == ndau - 1 )
98     prepre += " ";
99     else
100     prepre += "| ";
101     printDecay( * d, prepre );
102     }
103     }
104    
105     //#include "FWCore/Framework/interface/MakerMacros.h"
106    
107     //DEFINE_FWK_MODULE( ParticleTreeDrawer );
108