Skip to content

Commit

Permalink
Merge pull request cms-sw#47 from battibass/mc_config_update
Browse files Browse the repository at this point in the history
Update the configuration for TnP MC production
  • Loading branch information
HuguesBrun authored Oct 23, 2016
2 parents fa1f8f3 + e1079eb commit d725bb4
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 121 deletions.
133 changes: 133 additions & 0 deletions plugins/GenAdditionalInfo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// $Id: GenAdditionalInfo.cc,v 1.1 2015/08/23 13:49:16 battilan Exp $
//

/**
\class GenAdditionalInfo
\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: GenAdditionalInfo.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 "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
#include "DataFormats/Candidate/interface/CompositeCandidate.h"

class GenAdditionalInfo : public edm::EDProducer
{

public:

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

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

private:

edm::EDGetTokenT<GenEventInfoProduct> m_genInfoTag;
edm::EDGetTokenT<std::vector<PileupSummaryInfo>> m_pileUpInfoTag;
edm::EDGetTokenT<edm::View<reco::Candidate>> m_pairTag;

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

};


GenAdditionalInfo::GenAdditionalInfo(const edm::ParameterSet & iConfig) :
m_genInfoTag(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfoTag"))),
m_pileUpInfoTag(consumes<std::vector<PileupSummaryInfo>>(iConfig.getParameter<edm::InputTag>("pileUpInfoTag"))),
m_pairTag(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("pairTag")))
{

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

}

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

float weight = 1.;

float truePU = -1.;
float actualPU = -1.;

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

edm::Handle<std::vector<PileupSummaryInfo> > puInfo;
ev.getByToken(m_pileUpInfoTag, puInfo);

weight = genInfo->weight();

for( auto & puInfoEntry : *puInfo.product() )
{
int bx = puInfoEntry.getBunchCrossing();

if(bx == 0)
{
truePU = puInfoEntry.getTrueNumInteractions();
actualPU = puInfoEntry.getPU_NumInteractions();
continue;
}
}

}

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

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

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

genWeight[iPair] = weight;
truePileUp[iPair] = truePU;
actualPileUp[iPair] = actualPU;

}

writeValueMap<float>(ev, pairs, genWeight, "genWeight");
writeValueMap<float>(ev, pairs, truePileUp, "truePileUp");
writeValueMap<float>(ev, pairs, actualPileUp, "actualPileUp");

}

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

std::auto_ptr<edm::ValueMap<T> > valMap(new edm::ValueMap<T>());
typename edm::ValueMap<T>::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(GenAdditionalInfo);
102 changes: 0 additions & 102 deletions plugins/GenWeightInfo.cc

This file was deleted.

5 changes: 3 additions & 2 deletions python/common_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@
src = cms.InputTag("tpPairs"),
)

genWeightInfo = cms.EDProducer("GenWeightInfo",
genAdditionalInfo = cms.EDProducer("GenAdditionalInfo",
pairTag= cms.InputTag("tpPairs"),
genInfoTag= cms.InputTag("generator")
genInfoTag = cms.InputTag("generator"),
pileUpInfoTag = cms.InputTag("addPileupInfo")
)

l1hltprescale = cms.EDProducer("ComputeL1HLTPrescales",
Expand Down
35 changes: 18 additions & 17 deletions test/zmumu/tp_from_aod_MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

import os
if "CMSSW_8_0_" in os.environ['CMSSW_VERSION']:
process.GlobalTag.globaltag = cms.string('80X_mcRun2_asymptotic_v4')
process.GlobalTag.globaltag = cms.string('80X_mcRun2_asymptotic_v14')
process.source.fileNames = [
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/382BADA2-A3DA-E511-9E07-0CC47A4D769E.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/6200B483-9EDA-E511-A354-0CC47A4D7636.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/70B70BFF-32DB-E511-A4C6-0CC47A4C8E1C.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/80CC4165-9FDA-E511-815B-0CC47A78A4A0.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/80F7131A-33DB-E511-A2B5-0CC47A4D75F6.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/8AC339C5-A0DA-E511-9B02-0CC47A4C8E96.root',
'/store/relval/CMSSW_8_0_0/RelValZMM_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/D279741B-9EDA-E511-A88D-0025905A6110.root',
'/store/mc/RunIISpring16reHLT80/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PUSpring16RAWAODSIM_reHLT_80X_mcRun2_asymptotic_v14-v1/40001/3459A4AB-D85C-E611-81F5-02163E011488.root',
'/store/mc/RunIISpring16reHLT80/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PUSpring16RAWAODSIM_reHLT_80X_mcRun2_asymptotic_v14-v1/40001/8AB9296A-C55C-E611-9291-02163E012E69.root',
'/store/mc/RunIISpring16reHLT80/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PUSpring16RAWAODSIM_reHLT_80X_mcRun2_asymptotic_v14-v1/40001/9A8A076A-C55C-E611-BE5A-02163E012E69.root',
'/store/mc/RunIISpring16reHLT80/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PUSpring16RAWAODSIM_reHLT_80X_mcRun2_asymptotic_v14-v1/40002/4AC3D851-C45C-E611-8BFD-02163E012E69.root',
'/store/mc/RunIISpring16reHLT80/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PUSpring16RAWAODSIM_reHLT_80X_mcRun2_asymptotic_v14-v1/40003/ACAA69A9-D85C-E611-983F-02163E011488.root',
]
else: raise RuntimeError, "Unknown CMSSW version %s" % os.environ['CMSSW_VERSION']

Expand Down Expand Up @@ -77,10 +75,11 @@
process.muonMatchHLTL3.maxDeltaR = 0.1
from MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff import *
changeRecoMuonInput(process, "mergedMuons")
#useL1Stage2Candidates(process)
#appendL1MatchingAlgo(process)
useL1Stage2Candidates(process)
appendL1MatchingAlgo(process)
#addHLTL1Passthrough(process)
#changeTriggerProcessName(process, "*") # auto-guess
changeTriggerProcessName(process, "*") # auto-guess


from MuonAnalysis.TagAndProbe.common_variables_cff import *
process.load("MuonAnalysis.TagAndProbe.common_modules_cff")
Expand Down Expand Up @@ -198,8 +197,10 @@
probeMultiplicity = cms.InputTag("probeMultiplicity"),
probeMultiplicity_TMGM = cms.InputTag("probeMultiplicityTMGM"),
probeMultiplicity_Pt10_M60140 = cms.InputTag("probeMultiplicityPt10M60140"),
## Gen Weight variable
genWeight = cms.InputTag("genWeightInfo", "genWeight"),
## Gen related variables
genWeight = cms.InputTag("genAdditionalInfo", "genWeight"),
truePileUp = cms.InputTag("genAdditionalInfo", "truePileUp"),
actualPileUp = cms.InputTag("genAdditionalInfo", "actualPileUp"),
## New TuneP variables
newTuneP_probe_pt = cms.InputTag("newTunePVals", "pt"),
newTuneP_probe_sigmaPtOverPt = cms.InputTag("newTunePVals", "ptRelError"),
Expand Down Expand Up @@ -262,7 +263,7 @@
process.probeMultiplicities +
process.bestPairByZMass +
process.newTunePVals +
process.genWeightInfo +
process.genAdditionalInfo +
process.muonDxyPVdzminTags +
process.tpTree
)
Expand Down Expand Up @@ -475,7 +476,7 @@

if True: # turn on for tracking efficiency using L1 seeds
process.probeL1 = cms.EDFilter("CandViewSelector",
src = cms.InputTag("l1extraParticles"),
src = cms.InputTag("gmtStage2Digis:Muon"),
cut = cms.string("pt >= 5 && abs(eta) < 2.4"),
)
process.tpPairsTkL1 = process.tpPairs.clone(decay = "tagMuons@+ probeL1@-", cut = 'mass > 30')
Expand All @@ -489,8 +490,8 @@
arbitration = "OneProbe",
variables = cms.PSet(
KinematicVariables,
bx = cms.string("bx"),
quality = cms.string("gmtMuonCand.quality"),
## bx = cms.string("bx"),
## quality = cms.string("hwQual"),
## track matching variables
tk_deltaR = cms.InputTag("l1ToTkMatch","deltaR"),
tk_deltaEta = cms.InputTag("l1ToTkMatch","deltaEta"),
Expand Down

0 comments on commit d725bb4

Please sign in to comment.