CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/ElectroWeakAnalysis/ZMuMu/plugins/EventVtxInfoNtupleDumper.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "DataFormats/VertexReco/interface/Vertex.h"
00007 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00008 
00009 #include <vector>
00010 
00011 using namespace edm;
00012 using namespace std;
00013 using namespace reco;
00014 
00015 
00016 class EventVtxInfoNtupleDumper : public edm::EDProducer {
00017 public:
00018   EventVtxInfoNtupleDumper( const edm::ParameterSet & );
00019    
00020 private:
00021   void produce( edm::Event &, const edm::EventSetup & );
00022   edm::InputTag primaryVertices_;
00023 
00024 };
00025 
00026 EventVtxInfoNtupleDumper::EventVtxInfoNtupleDumper( const ParameterSet & cfg ) : 
00027   primaryVertices_(cfg.getParameter<InputTag>("primaryVertices")) {
00028   produces<int>( "numPV" ).setBranchAlias( "numPV" );
00029   produces<int>( "nTrkPV" ).setBranchAlias( "nTrkPV" );
00030   produces<float>( "chi2PV" ).setBranchAlias( "chi2PV" );
00031   produces<float>( "ndofPV" ).setBranchAlias( "ndofPV" );
00032   produces<float>( "zPV" ).setBranchAlias( "zPV" );
00033   produces<float>( "rhoPV" ).setBranchAlias( "rhoPV" );
00034   //  produces<std::vector< unsigned int > >( "nTrkPV" ).setBranchAlias( "nTrkPV" );
00035   //  produces<std::vector< float > >( "chi2PV" ).setBranchAlias( "chi2PV" );
00036   //  produces<std::vector< float > >( "ndofPV" ).setBranchAlias( "ndofPV" );
00037 }
00038 
00039 
00040 
00041 void EventVtxInfoNtupleDumper::produce( Event & evt, const EventSetup & ) {
00042   
00043   Handle<reco::VertexCollection> primaryVertices;  // Collection of primary Vertices
00044   evt.getByLabel(primaryVertices_, primaryVertices);
00045   auto_ptr<int> nVtxs( new int );
00046   auto_ptr<int> nTrkVtx( new int );
00047   auto_ptr<float> chi2Vtx( new float );
00048   auto_ptr<float> ndofVtx( new float );
00049   auto_ptr<float> zVtx( new float );
00050   auto_ptr<float> rhoVtx( new float );
00051   //  auto_ptr< vector< unsigned int > > nTrkVtx( new vector< unsigned int > );
00052   //  auto_ptr< vector< float > > chi2Vtx( new vector< float > );
00053   //  auto_ptr< vector< float > > ndofVtx( new vector< float > );
00054 
00055   const reco::Vertex &pv = (*primaryVertices)[0];
00056 
00057   *nVtxs = -1;
00058   *nTrkVtx = -1;
00059   *chi2Vtx = -1.0;
00060   *ndofVtx = -1.0;
00061   *zVtx = -1000;
00062   *rhoVtx = -1000;
00063   if( !(pv.isFake()) ) {
00064     *nVtxs = primaryVertices->size();
00065     *nTrkVtx = pv.tracksSize();
00066     *chi2Vtx = pv.chi2();
00067     *ndofVtx = pv.ndof();
00068     *zVtx = pv.z();
00069     *rhoVtx = pv.position().Rho();
00070   }
00071   //  nTrkVtx->push_back(pv.tracksSize());
00072   //  chi2Vtx->push_back(pv.chi2());
00073   //  ndofVtx->push_back(pv.ndof());
00074   evt.put( nVtxs, "numPV" );
00075   evt.put( nTrkVtx, "nTrkPV" );
00076   evt.put( chi2Vtx, "chi2PV" );
00077   evt.put( ndofVtx, "ndofPV" );
00078   evt.put( zVtx, "zPV" );
00079   evt.put( rhoVtx, "rhoPV" );
00080 
00081 }
00082 
00083 #include "FWCore/Framework/interface/MakerMacros.h"
00084 
00085 DEFINE_FWK_MODULE( EventVtxInfoNtupleDumper );
00086