Skip to content

Commit

Permalink
Merge pull request cms-sw#10 from YoungKwonJo/master
Browse files Browse the repository at this point in the history
added npile-up for genericNtuple
  • Loading branch information
jhgoh committed Feb 11, 2014
2 parents 9ca86bf + 57245a7 commit c0ac739
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GenericNtuple/interface/GenericEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct GenericEvent

int run_, lumi_, event_;
double puWeight_, puWeightUp_, puWeightDn_;
int nVertex_;
int nVertex_, npileup_;

typedef std::vector<int> ints;
typedef std::vector<unsigned int> uints;
Expand Down
19 changes: 18 additions & 1 deletion GenericNtuple/plugins/KGenericNtupleMaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class KGenericNtupleMaker : public edm::EDAnalyzer
edm::InputTag genJetLabel_;
edm::InputTag puWeightLabel_;
edm::InputTag vertexLabel_;
edm::InputTag puNVertexLabel_;

edm::InputTag muonLabel_;
edm::InputTag electronLabel_;
Expand Down Expand Up @@ -99,6 +100,7 @@ KGenericNtupleMaker::KGenericNtupleMaker(const edm::ParameterSet& pset)
// Input labels
puWeightLabel_ = pset.getParameter<edm::InputTag>("puWeight");
vertexLabel_ = pset.getParameter<edm::InputTag>("vertex");
puNVertexLabel_ = pset.getParameter<edm::InputTag>("puNVertex");

edm::ParameterSet electronPSet = pset.getParameter<edm::ParameterSet>("electron");
electronMinNumber_ = electronPSet.getParameter<unsigned int>("minNumber");
Expand Down Expand Up @@ -169,9 +171,18 @@ void KGenericNtupleMaker::analyze(const edm::Event& event, const edm::EventSetup

edm::Handle<reco::VertexCollection> vertexHandle;
event.getByLabel(vertexLabel_, vertexHandle);
fevent_->nVertex_ = vertexHandle->size();
// fevent_->nVertex_ = vertexHandle->size();
const reco::Vertex& pv = vertexHandle->at(0);

int nv = 0 ;

for(reco::VertexCollection::const_iterator v=vertexHandle->begin(); v!=vertexHandle->end(); ++v){
if (!(v->isFake()) && (v->ndof()>4) && (fabs(v->z())<=24.0) && (v->position().Rho()<=2.0) ) {
nv++;
}
}
fevent_->nVertex_ = nv;

if ( !isMC_ )
{
fevent_->puWeight_ = 1.0;
Expand All @@ -187,8 +198,14 @@ void KGenericNtupleMaker::analyze(const edm::Event& event, const edm::EventSetup
fevent_->puWeight_ = *(puWeightHandle.product() );
fevent_->puWeightUp_ = *(puWeightUpHandle.product());
fevent_->puWeightDn_ = *(puWeightDnHandle.product());

edm::Handle<int> npileup_;
event.getByLabel(puNVertexLabel_, npileup_);

fevent_->npileup_ = *npileup_;
}


edm::Handle<Electrons> electronHandle;
event.getByLabel(electronLabel_, electronHandle);
for ( int i=0, n=electronHandle->size(); i<n; ++i )
Expand Down
1 change: 1 addition & 0 deletions GenericNtuple/python/genericNtupleMaker_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

puWeight = cms.InputTag("pileupWeight"),
vertex = cms.InputTag("goodOfflinePrimaryVertices"),
puNVertex = cms.InputTag("pileupWeight",'nTrueInteraction'),
eventCounters = cms.vstring(),

electron = cms.PSet(
Expand Down
2 changes: 2 additions & 0 deletions GenericNtuple/src/GenericEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void GenericEvent::book(TTree* tree)
tree_->Branch("puWeightUp", &puWeightUp_, "puWeightUp/D");
tree_->Branch("puWeightDn", &puWeightDn_, "puWeightDn/D");
tree_->Branch("nVertex", &nVertex_, "nVertex/I");
tree_->Branch("npileup", &npileup_, "npileup/I");

tree_->Branch("muons_pt" , muons_pt_ );
tree_->Branch("muons_eta" , muons_eta_ );
Expand Down Expand Up @@ -253,6 +254,7 @@ void GenericEvent::setBranch(TTree* tree)
tree_->SetBranchAddress("puWeightUp", &puWeightUp_);
tree_->SetBranchAddress("puWeightDn", &puWeightDn_);
tree_->SetBranchAddress("nVertex", &nVertex_);
tree_->SetBranchAddress("npileup", &npileup_);

tree_->SetBranchAddress("muons_pt" , &muons_pt_ );
tree_->SetBranchAddress("muons_eta" , &muons_eta_ );
Expand Down

0 comments on commit c0ac739

Please sign in to comment.