CMS 3D CMS Logo

PFPileUp Class Reference

Identifies pile-up candidates from a collection of PFCandidates, and produces the corresponding collection of PileUpCandidates. More...

#include <PhysicsTools/PFCandProducer/interface/PFPileUp.h>

Inheritance diagram for PFPileUp:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void beginJob (const edm::EventSetup &c)
 PFPileUp (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~PFPileUp ()

Private Member Functions

reco::VertexRef chargedHadronVertex (const edm::Handle< reco::VertexCollection > &vertices, const reco::PFCandidate &pfcand) const

Private Attributes

edm::InputTag inputTagPFCandidates_
 PFCandidates to be analyzed.
edm::InputTag inputTagVertices_
 vertices
bool verbose_
 verbose ?


Detailed Description

Identifies pile-up candidates from a collection of PFCandidates, and produces the corresponding collection of PileUpCandidates.

Author:
Colin Bernet
Date:
february 2008

Definition at line 31 of file PFPileUp.h.


Constructor & Destructor Documentation

PFPileUp::PFPileUp ( const edm::ParameterSet iConfig  )  [explicit]

Definition at line 20 of file PFPileUp.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), inputTagPFCandidates_, inputTagVertices_, and verbose_.

00020                                                  {
00021   
00022 
00023 
00024   inputTagPFCandidates_ 
00025     = iConfig.getParameter<InputTag>("PFCandidates");
00026 
00027   inputTagVertices_ 
00028     = iConfig.getParameter<InputTag>("Vertices");
00029 
00030   verbose_ = 
00031     iConfig.getUntrackedParameter<bool>("verbose",false);
00032 
00033 
00034 
00035   produces<reco::PileUpPFCandidateCollection>();
00036   
00037 }

PFPileUp::~PFPileUp (  ) 

Definition at line 41 of file PFPileUp.cc.

00041 { }


Member Function Documentation

void PFPileUp::beginJob ( const edm::EventSetup c  )  [virtual]

Reimplemented from edm::EDProducer.

Definition at line 45 of file PFPileUp.cc.

00045 { }

VertexRef PFPileUp::chargedHadronVertex ( const edm::Handle< reco::VertexCollection > &  vertices,
const reco::PFCandidate pfcand 
) const [private]

Definition at line 107 of file PFPileUp.cc.

References index, reco::PFCandidate::trackRef(), reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), and reco::Particle::vertex().

Referenced by produce().

00107                                                                                                          {
00108 
00109   
00110   reco::TrackBaseRef trackBaseRef( pfcand.trackRef() );
00111   
00112   unsigned nFoundVertex = 0;
00113   size_t  iVertex = 0;
00114   unsigned index=0;
00115   typedef reco::VertexCollection::const_iterator IV;
00116   for(IV iv=vertices->begin(); iv!=vertices->end(); ++iv, ++index) {
00117 //     cout<<(*iv).x()<<" "
00118 //      <<(*iv).y()<<" "
00119 //      <<(*iv).z()<<endl;
00120 
00121     const reco::Vertex& vtx = *iv;
00122     
00123     typedef reco::Vertex::trackRef_iterator IT;
00124     
00125     // loop on tracks in vertices
00126     for(IT iTrack=vtx.tracks_begin(); 
00127         iTrack!=vtx.tracks_end(); ++iTrack) {
00128          
00129       const reco::TrackBaseRef& baseRef = *iTrack;
00130 
00131       // one of the tracks in the vertex is the same as 
00132       // the track considered in the function
00133       if(baseRef == trackBaseRef ) {
00134         iVertex = index;
00135         nFoundVertex++;
00136       }         
00137     }
00138   } 
00139 
00140   if( nFoundVertex == 1) {
00141     return VertexRef( vertices, iVertex);
00142   }
00143   else if(nFoundVertex>1) assert(false);
00144 
00145   assert( !iVertex );
00146 
00147   // no vertex found with this track. 
00148   // as a secondary solution, associate the closest vertex in z
00149 
00150   double dzmin = 10000;
00151   double ztrack = pfcand.vertex().z();
00152   bool foundVertex = false;
00153   index = 0;
00154   for(IV iv=vertices->begin(); iv!=vertices->end(); ++iv, ++index) {
00155 
00156     double dz = fabs(ztrack - iv->z());
00157     if(dz<dzmin) {
00158       dzmin = dz; 
00159       iVertex = index;
00160       foundVertex = true;
00161     }
00162   }
00163 
00164   if( foundVertex ) 
00165     return VertexRef( vertices, iVertex);  
00166   else 
00167     return VertexRef();
00168 }

void PFPileUp::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 48 of file PFPileUp.cc.

References chargedHadronVertex(), pfpat::fetchCollection(), h, i, inputTagPFCandidates_, inputTagVertices_, edm::Ref< C, T, F >::isNull(), edm::Ref< C, T, F >::key(), and edm::Event::put().

00049                                                     {
00050   
00051 //   LogDebug("PFPileUp")<<"START event: "<<iEvent.id().event()
00052 //                       <<" in run "<<iEvent.id().run()<<endl;
00053   
00054   
00055   
00056   // get PFCandidates
00057 
00058   Handle<PFCandidateCollection> pfCandidates;
00059   pfpat::fetchCollection(pfCandidates, 
00060                          inputTagPFCandidates_, 
00061                          iEvent );
00062 
00063   
00064   // get vertices 
00065 
00066   Handle<VertexCollection> vertices;
00067   pfpat::fetchCollection(vertices, 
00068                          inputTagVertices_, 
00069                          iEvent );
00070   
00071   auto_ptr< reco::PileUpPFCandidateCollection > 
00072     pOutput( new reco::PileUpPFCandidateCollection ); 
00073   
00074   for( unsigned i=0; i<pfCandidates->size(); i++ ) {
00075     
00076     // const reco::PFCandidate& cand = (*pfCandidates)[i];
00077     PFCandidatePtr candptr(pfCandidates, i);
00078 
00079 //     PFCandidateRef pfcandref(pfCandidates,i); 
00080 
00081     VertexRef vertexref;
00082 
00083     switch( candptr->particleId() ) {
00084     case PFCandidate::h:
00085       vertexref = chargedHadronVertex( vertices, *candptr );
00086       break;
00087     default:
00088       continue;
00089     } 
00090     
00091     // no associated vertex, or primary vertex
00092     // not pile-up
00093     if( vertexref.isNull() || 
00094         vertexref.key()==0 ) continue;
00095 
00096     pOutput->push_back( PileUpPFCandidate( candptr, vertexref ) );
00097    
00098   }
00099   
00100   iEvent.put( pOutput );
00101   
00102 }


Member Data Documentation

edm::InputTag PFPileUp::inputTagPFCandidates_ [private]

PFCandidates to be analyzed.

Definition at line 50 of file PFPileUp.h.

Referenced by PFPileUp(), and produce().

edm::InputTag PFPileUp::inputTagVertices_ [private]

vertices

Definition at line 53 of file PFPileUp.h.

Referenced by PFPileUp(), and produce().

bool PFPileUp::verbose_ [private]

verbose ?

Definition at line 56 of file PFPileUp.h.

Referenced by PFPileUp().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:44 2009 for CMSSW by  doxygen 1.5.4