PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ElectroWeakAnalysis/ZMuMu/plugins/EventVtxInfoNtupleDumper.cc

https://github.com/aivanov-cern/cmssw
C++ | 86 lines | 60 code | 17 blank | 9 comment | 1 complexity | 4dec72db990989e14aef4d672812bebc MD5 | raw file
 1#include "FWCore/Framework/interface/EDProducer.h"
 2#include "FWCore/Utilities/interface/InputTag.h"
 3#include "DataFormats/Common/interface/Handle.h"
 4#include "FWCore/Framework/interface/Event.h"
 5#include "FWCore/ParameterSet/interface/ParameterSet.h"
 6#include "DataFormats/VertexReco/interface/Vertex.h"
 7#include "DataFormats/VertexReco/interface/VertexFwd.h"
 8
 9#include <vector>
10
11using namespace edm;
12using namespace std;
13using namespace reco;
14
15
16class EventVtxInfoNtupleDumper : public edm::EDProducer {
17public:
18  EventVtxInfoNtupleDumper( const edm::ParameterSet & );
19   
20private:
21  void produce( edm::Event &, const edm::EventSetup & ) override;
22  edm::InputTag primaryVertices_;
23
24};
25
26EventVtxInfoNtupleDumper::EventVtxInfoNtupleDumper( const ParameterSet & cfg ) : 
27  primaryVertices_(cfg.getParameter<InputTag>("primaryVertices")) {
28  produces<int>( "numPV" ).setBranchAlias( "numPV" );
29  produces<int>( "nTrkPV" ).setBranchAlias( "nTrkPV" );
30  produces<float>( "chi2PV" ).setBranchAlias( "chi2PV" );
31  produces<float>( "ndofPV" ).setBranchAlias( "ndofPV" );
32  produces<float>( "zPV" ).setBranchAlias( "zPV" );
33  produces<float>( "rhoPV" ).setBranchAlias( "rhoPV" );
34  //  produces<std::vector< unsigned int > >( "nTrkPV" ).setBranchAlias( "nTrkPV" );
35  //  produces<std::vector< float > >( "chi2PV" ).setBranchAlias( "chi2PV" );
36  //  produces<std::vector< float > >( "ndofPV" ).setBranchAlias( "ndofPV" );
37}
38
39
40
41void EventVtxInfoNtupleDumper::produce( Event & evt, const EventSetup & ) {
42  
43  Handle<reco::VertexCollection> primaryVertices;  // Collection of primary Vertices
44  evt.getByLabel(primaryVertices_, primaryVertices);
45  auto_ptr<int> nVtxs( new int );
46  auto_ptr<int> nTrkVtx( new int );
47  auto_ptr<float> chi2Vtx( new float );
48  auto_ptr<float> ndofVtx( new float );
49  auto_ptr<float> zVtx( new float );
50  auto_ptr<float> rhoVtx( new float );
51  //  auto_ptr< vector< unsigned int > > nTrkVtx( new vector< unsigned int > );
52  //  auto_ptr< vector< float > > chi2Vtx( new vector< float > );
53  //  auto_ptr< vector< float > > ndofVtx( new vector< float > );
54
55  const reco::Vertex &pv = (*primaryVertices)[0];
56
57  *nVtxs = -1;
58  *nTrkVtx = -1;
59  *chi2Vtx = -1.0;
60  *ndofVtx = -1.0;
61  *zVtx = -1000;
62  *rhoVtx = -1000;
63  if( !(pv.isFake()) ) {
64    *nVtxs = primaryVertices->size();
65    *nTrkVtx = pv.tracksSize();
66    *chi2Vtx = pv.chi2();
67    *ndofVtx = pv.ndof();
68    *zVtx = pv.z();
69    *rhoVtx = pv.position().Rho();
70  }
71  //  nTrkVtx->push_back(pv.tracksSize());
72  //  chi2Vtx->push_back(pv.chi2());
73  //  ndofVtx->push_back(pv.ndof());
74  evt.put( nVtxs, "numPV" );
75  evt.put( nTrkVtx, "nTrkPV" );
76  evt.put( chi2Vtx, "chi2PV" );
77  evt.put( ndofVtx, "ndofPV" );
78  evt.put( zVtx, "zPV" );
79  evt.put( rhoVtx, "rhoPV" );
80
81}
82
83#include "FWCore/Framework/interface/MakerMacros.h"
84
85DEFINE_FWK_MODULE( EventVtxInfoNtupleDumper );
86