Skip to content

Commit

Permalink
Merge pull request #9 from battibass/nVerticesFixPlusGenWeight
Browse files Browse the repository at this point in the history
Fix a few things + add gen weight information to TnP pairs
  • Loading branch information
gpetruc committed Aug 31, 2015
2 parents 031a41b + b10a763 commit 0d48950
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 5 deletions.
102 changes: 102 additions & 0 deletions plugins/GenWeightInfo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// $Id: GenWeightInfo.cc,v 1.1 2015/08/23 13:49:16 battilan Exp $
//

/**
\class GenWeightInfo
\brief Adds generator level information to the T&P according to 74X interface.
https://indico.cern.ch/event/402279/contribution/5/attachments/805964/1104514/mcaod-Jun17-2015.pdf
\Author Carlo Battilana
\version $Id: GenWeightInfo.cc,v 1.1 2015/08/23 13:49:16 battilan Exp $
*/


#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/Common/interface/ValueMap.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "DataFormats/Candidate/interface/CompositeCandidate.h"

class GenWeightInfo : public edm::EDProducer
{

public:

explicit GenWeightInfo(const edm::ParameterSet & iConfig);
virtual ~GenWeightInfo() { }

virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) final;

private:

edm::InputTag m_genInfoTag;
edm::InputTag m_pairTag;

/// Write a ValueMap<float> in the event
void writeValueMap(edm::Event &ev, const edm::Handle<edm::View<reco::Candidate> > & handle,
const std::vector<float> & values, const std::string & label) const ;

};


GenWeightInfo::GenWeightInfo(const edm::ParameterSet & iConfig) :
m_genInfoTag(iConfig.getParameter<edm::InputTag>("genInfoTag")),
m_pairTag(iConfig.getParameter<edm::InputTag>("pairTag"))
{

produces<edm::ValueMap<float> >("genWeight");

}

void GenWeightInfo::produce(edm::Event & ev, const edm::EventSetup & iSetup)
{

float weight = 1.;

if (!ev.isRealData())
{
edm::Handle<GenEventInfoProduct> genInfo;
ev.getByLabel(m_genInfoTag, genInfo);

weight = genInfo->weight();
}

edm::Handle<edm::View<reco::Candidate> > pairs;
ev.getByLabel(m_pairTag, pairs);

size_t n = pairs->size();
std::vector<float> genWeight(n,0);

for (size_t iPair = 0; iPair < n; ++iPair)
{
const reco::Candidate & pair = (*pairs)[iPair];
if (pair.numberOfDaughters() != 2) throw cms::Exception("CorruptData") <<
"[GenWeightInfo::produce] GenWeightInfo should be used on composite candidates with two daughters, this one has " << pair.numberOfDaughters() << "\n";

genWeight[iPair] = weight;
}

writeValueMap(ev, pairs, genWeight, "genWeight");

}

void GenWeightInfo::writeValueMap(edm::Event & ev, const edm::Handle<edm::View<reco::Candidate> > & handle,
const std::vector<float> & values, const std::string & label) const
{

std::auto_ptr<edm::ValueMap<float> > valMap(new edm::ValueMap<float>());
edm::ValueMap<float>::Filler filler(*valMap);
filler.insert(handle, values.begin(), values.end());
filler.fill();
ev.put(valMap, label);

}


#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(GenWeightInfo);
5 changes: 5 additions & 0 deletions python/common_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@
src = cms.InputTag("tpPairs"),
)

genWeightInfo = cms.EDProducer("GenWeightInfo",
pairTag= cms.InputTag("tpPairs"),
genInfoTag= cms.InputTag("generator")
)

l1hltprescale = cms.EDProducer("ComputeL1HLTPrescales",
probes = cms.InputTag("tagMuons"),
hltConfig = cms.string("HLT"),
Expand Down
12 changes: 8 additions & 4 deletions test/zmumu/tp_from_aod_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@


if TRIGGER == "SingleMu":
process.triggerResultsFilter.triggerConditions = cms.vstring( 'HLT_IsoMu24_eta2p1_v*', 'HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v*' )
process.triggerResultsFilter.triggerConditions = cms.vstring( 'HLT_Mu45_eta2p1_v*', 'HLT_Mu50_v*',
'HLT_IsoMu24_eta2p1_v*', 'HLT_IsoMu20_eta2p1_v*',
'HLT_IsoMu27_v*', 'HLT_IsoMu20_v*' )
elif TRIGGER == "DoubleMu":
process.triggerResultsFilter.triggerConditions = cms.vstring( 'HLT_Mu8_v*', 'HLT_Mu17_v*', 'HLT_Mu17_TkMu8_NoDZ_v*', 'HLT_Mu13_Mu8_NoDZ_v*' )
process.triggerResultsFilter.triggerConditions = cms.vstring( 'HLT_Mu8_v*', 'HLT_Mu17_v*',
'HLT_Mu8_TrkIsoVVL_v*', 'HLT_Mu17_TrkIsoVVL_v*',
'HLT_Mu17_TkMu8_v*', 'HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*' )
else:
raise RuntimeError, "TRIGGER must be 'SingleMu' or 'DoubleMu'"

Expand Down Expand Up @@ -184,7 +188,6 @@
# pt = cms.string("pt"),
# eta = cms.string("eta"),
# phi = cms.string("phi"),
# nVertices = cms.InputTag("nverticesModule"),
# combRelIso = cms.string("(isolationR03.emEt + isolationR03.hadEt + isolationR03.sumPt)/pt"),
# chargedHadIso04 = cms.string("pfIsolationR04().sumChargedHadronPt"),
# neutralHadIso04 = cms.string("pfIsolationR04().sumNeutralHadronEt"),
Expand All @@ -194,7 +197,8 @@
# dzPV = cms.InputTag("muonDxyPVdzminTags","dzPV"),
AllVariables,
ExtraIsolationVariables,
MVAIsoVariablesPlain,
MVAIsoVariablesPlain,
nVertices = cms.InputTag("nverticesModule"),
isoTrk03Abs = cms.InputTag("probeMuonsIsoValueMaps","probeMuonsIsoFromDepsTk"),
isoTrk03Rel = cms.InputTag("probeMuonsIsoValueMaps","probeMuonsRelIsoFromDepsTk"),
dxyBS = cms.InputTag("muonDxyPVdzminTags","dxyBS"),
Expand Down
5 changes: 4 additions & 1 deletion test/zmumu/tp_from_aod_MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
# pt = cms.string("pt"),
# eta = cms.string("eta"),
# phi = cms.string("phi"),
# nVertices = cms.InputTag("nverticesModule"),
# combRelIso = cms.string("(isolationR03.emEt + isolationR03.hadEt + isolationR03.sumPt)/pt"),
# chargedHadIso04 = cms.string("pfIsolationR04().sumChargedHadronPt"),
# neutralHadIso04 = cms.string("pfIsolationR04().sumNeutralHadronEt"),
Expand All @@ -169,6 +168,7 @@
AllVariables,
ExtraIsolationVariables,
MVAIsoVariablesPlain,
nVertices = cms.InputTag("nverticesModule"),
isoTrk03Abs = cms.InputTag("probeMuonsIsoValueMaps","probeMuonsIsoFromDepsTk"),
isoTrk03Rel = cms.InputTag("probeMuonsIsoValueMaps","probeMuonsRelIsoFromDepsTk"),
dxyBS = cms.InputTag("muonDxyPVdzminTags","dxyBS"),
Expand All @@ -187,6 +187,8 @@
probeMultiplicity = cms.InputTag("probeMultiplicity"),
probeMultiplicity_TMGM = cms.InputTag("probeMultiplicityTMGM"),
probeMultiplicity_Pt10_M60140 = cms.InputTag("probeMultiplicityPt10M60140"),
## Gen Weight variable
genWeight = cms.InputTag("genWeightInfo", "genWeight"),
## New TuneP variables
newTuneP_probe_pt = cms.InputTag("newTunePVals", "pt"),
newTuneP_probe_sigmaPtOverPt = cms.InputTag("newTunePVals", "ptRelError"),
Expand Down Expand Up @@ -233,6 +235,7 @@
process.probeMultiplicities +
process.bestPairByZMass +
process.newTunePVals +
process.genWeightInfo +
process.muonDxyPVdzminTags +
process.tpTree
)
Expand Down

0 comments on commit 0d48950

Please sign in to comment.