Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUSY branches on CMSSW 9_4_7 (not backward compatible with 940) #16

Open
wants to merge 3 commits into
base: CMSSW_9_4_X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion plugins/SusyElectronVariableHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class SusyElectronVariableHelper : public edm::EDProducer {
private:
edm::EDGetTokenT<std::vector<pat::Electron>> probesToken_;
edm::EDGetTokenT<edm::View<reco::Candidate>> probesViewToken_;
edm::EDGetTokenT<edm::View<reco::Candidate>> probes2ViewToken_;
edm::EDGetTokenT<edm::ValueMap<float>> mvaToken_;
edm::EDGetTokenT<edm::ValueMap<float>> dxyToken_;
edm::EDGetTokenT<edm::ValueMap<float>> dzToken_;
Expand All @@ -230,13 +231,15 @@ class SusyElectronVariableHelper : public edm::EDProducer {
SusyElectronVariableHelper::SusyElectronVariableHelper(const edm::ParameterSet & iConfig) :
probesToken_( consumes<std::vector<pat::Electron>>(iConfig.getParameter<edm::InputTag>("probes"))),
probesViewToken_( consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("probes"))),
probes2ViewToken_( consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("probesWithLepMVA"))),
mvaToken_( consumes<edm::ValueMap<float>>( iConfig.getParameter<edm::InputTag>("mvas"))),
dxyToken_( consumes<edm::ValueMap<float>>( iConfig.getParameter<edm::InputTag>("dxy"))),
dzToken_( consumes<edm::ValueMap<float>>( iConfig.getParameter<edm::InputTag>("dz"))),
leptonMvaToken_( consumes<edm::ValueMap<float>>( iConfig.getParameter<edm::InputTag>("leptonMvas"))),
rhoToken_( consumes<double>( iConfig.getParameter<edm::InputTag>("rho"))) {

produces<edm::ValueMap<float> >("sip3d");
produces<edm::ValueMap<float> >("electronMVATTH");

workingPoints = {"ConvVeto", "MVAVLooseFO", "MVAVLoose", "Mini", "Mini2", "Mini4",
"MVAVLooseMini", "MVAVLooseMini2", "MVAVLooseMini4", "MVATight", "MVAWP80", "MVAWP90",
Expand Down Expand Up @@ -269,6 +272,7 @@ void SusyElectronVariableHelper::produce(edm::Event & iEvent, const edm::EventSe
// read input
edm::Handle<std::vector<pat::Electron>> probes; iEvent.getByToken(probesToken_, probes);
edm::Handle<edm::View<reco::Candidate>> probes_view; iEvent.getByToken(probesViewToken_, probes_view);
edm::Handle<edm::View<reco::Candidate>> probes2_view; iEvent.getByToken(probes2ViewToken_, probes2_view);
edm::Handle<edm::ValueMap<float>> mvas; iEvent.getByToken(mvaToken_, mvas);
edm::Handle<edm::ValueMap<float>> dxys; iEvent.getByToken(dxyToken_, dxys);
edm::Handle<edm::ValueMap<float>> dzs; iEvent.getByToken(dzToken_, dzs);
Expand All @@ -277,6 +281,7 @@ void SusyElectronVariableHelper::produce(edm::Event & iEvent, const edm::EventSe

// prepare vector for output
std::vector<float> sip3dValues;
std::vector<float> leptonMvaValues;


std::map<TString, std::vector<bool>> passWorkingPoints;
Expand All @@ -287,6 +292,8 @@ void SusyElectronVariableHelper::produce(edm::Event & iEvent, const edm::EventSe
size_t i = 0;
for(const auto &probe: *probes){
edm::RefToBase<reco::Candidate> pp = probes_view->refAt(i);
edm::RefToBase<reco::Candidate> ppLepMVA = probes2_view->refAt(i); // LeptonMVA were added with reference to a different collection. Here we assume that the order or electrons is the same in the two collections (slimmedElectronsWithUserData and slimmedElectronsWithUserDataWithVID), which should be true since they are just clones


float ip3d = probe.dB(pat::Electron::PV3D);
float ip3d_err = probe.edB(pat::Electron::PV3D);
Expand All @@ -298,10 +305,11 @@ void SusyElectronVariableHelper::produce(edm::Event & iEvent, const edm::EventSe
float jetPtRatio = probe.userFloat("ptRatio");
float jetPtRel = probe.userFloat("ptRel");
int missingInnerHits = probe.gsfTrack()->hitPattern().numberOfAllHits(reco::HitPattern::MISSING_INNER_HITS);
float leptonMva = (*leptonMvas)[pp];
float leptonMva = (*leptonMvas)[ppLepMVA];


sip3dValues.push_back(sip3d);
leptonMvaValues.push_back(leptonMva);

passWorkingPoints["ConvVeto"].push_back( probe.passConversionVeto());
passWorkingPoints["MVAVLooseFO"].push_back( PassMVAVLooseFO(mva, fabs(probe.superCluster()->eta())));
Expand Down Expand Up @@ -359,6 +367,7 @@ void SusyElectronVariableHelper::produce(edm::Event & iEvent, const edm::EventSe
}

Store(iEvent, probes, sip3dValues, "sip3d");
Store(iEvent, probes, leptonMvaValues, "electronMVATTH");

for(TString wp : workingPoints){
Store(iEvent, probes, passWorkingPoints[wp], ("pass" + wp).Data());
Expand Down
3 changes: 2 additions & 1 deletion python/TnPTreeProducer_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@
setattr( process.tnpEleIDs.variables , 'el_miniIsoChg', cms.string("userFloat('miniIsoChg')") )
setattr( process.tnpEleIDs.variables , 'el_miniIsoAll', cms.string("userFloat('miniIsoAll')") )
setattr( process.tnpEleIDs.variables , 'el_ptRatio', cms.string("userFloat('ptRatio')") )
setattr( process.tnpEleIDs.variables , 'el_ptRatioUncorr', cms.string("userFloat('ptRatioUncorr')") )
setattr( process.tnpEleIDs.variables , 'el_ptRel', cms.string("userFloat('ptRel')") )
setattr( process.tnpEleIDs.variables , 'el_MVATTH', cms.InputTag("electronMVATTH") )
setattr( process.tnpEleIDs.variables , 'el_MVATTH', cms.InputTag("susyEleVarHelper:electronMVATTH") )
setattr( process.tnpEleIDs.variables , 'el_sip3d', cms.InputTag("susyEleVarHelper:sip3d") )
def addFlag(name):
setattr( process.tnpEleIDs.flags, 'passing'+name, cms.InputTag('probes'+name ) )
Expand Down
69 changes: 47 additions & 22 deletions python/electronsExtrasSUSY_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,90 @@ def addSusyIDs(process, options):
from PhysicsTools.NanoAOD.electrons_cff import slimmedElectronsWithUserData
from PhysicsTools.NanoAOD.electrons_cff import electronMVATTH

doJEC = True
if (doJEC):
from PhysicsTools.NanoAOD.jets_cff import updatedJets
from PhysicsTools.NanoAOD.jets_cff import jetCorrFactors # is this needed?
jetCorrFactors.src ='slimmedJets'
updatedJets.jetSource ='slimmedJets'
process.updatedJets = updatedJets
process.jetCorrFactors = jetCorrFactors
else:
ptRatioRelForEle.srcJet = cms.InputTag("slimmedJets")

process.isoForEle = isoForEle
process.ptRatioRelForEle = ptRatioRelForEle
process.slimmedElectronsWithUserData = slimmedElectronsWithUserData
process.electronMVATTH = electronMVATTH

# Also save the raw ptRatio, with the JECs from the miniAOD
ptRatioRelForEleUncorr = ptRatioRelForEle.clone()
ptRatioRelForEleUncorr.srcJet = cms.InputTag("slimmedJets")
process.ptRatioRelForEleUncorr = ptRatioRelForEleUncorr


# Make a new electron collection, with additional variables that are used for the LeptonMVA below
process.slimmedElectronsWithUserData.src = cms.InputTag(options['ELECTRON_COLL'])
process.slimmedElectronsWithUserData.userFloats = cms.PSet(
miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"),
miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"),
PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"),
PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"),
PFIsoAll04 = cms.InputTag("isoForEle:PFIsoAll04"),
ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"),
ptRatioUncorr = cms.InputTag("ptRatioRelForEleUncorr:ptRatio"),
ptRel = cms.InputTag("ptRatioRelForEle:ptRel"),
jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"),
)
process.slimmedElectronsWithUserData.userIntFromBools = cms.PSet() # Removed
process.slimmedElectronsWithUserData.userInts = cms.PSet() # Removed

# Run the ttH MVA, modify src and take MVA directly from VID (VID must run before this producer)
process.electronMVATTH.src = cms.InputTag("slimmedElectronsWithUserData")
process.electronMVATTH.variables = cms.PSet(
LepGood_pt = cms.string("pt"),
LepGood_eta = cms.string("eta"),
LepGood_jetNDauChargedMVASel = cms.string("userFloat('jetNDauChargedMVASel')"),
LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
LepGood_jetPtRelv2 = cms.string("userFloat('ptRel')"),
LepGood_jetPtRatio = cms.string("min(userFloat('ptRatio'),1.5)"),
LepGood_jetBTagCSV = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):-99.0"),
LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
LepGood_mvaIdSpring16HZZ = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values"),
)

# At the end of this, everything we need is either a userfloat or in a producer linked with slimmedElectronsWithUserData
# Run the ttH MVA
# Cannot take EGMMVA directly from VID, because the TTHMVA producer only loads userFloat. Need to first put the EGMMVA in the object as a userFloats, with the names the TTHMVA expects
process.slimmedElectronsWithUserDataWithVID = process.slimmedElectronsWithUserData.clone()
process.slimmedElectronsWithUserDataWithVID.src = cms.InputTag("slimmedElectronsWithUserData")
process.slimmedElectronsWithUserDataWithVID.userCands = cms.PSet() # Removed
process.slimmedElectronsWithUserDataWithVID.userFloats = cms.PSet(
mvaSpring16HZZ = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values"),
mvaFall17noIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values"),
)

process.electronMVATTH.src = cms.InputTag("slimmedElectronsWithUserDataWithVID")

# At the end of this, everything we need is either a userfloat or in a producer linked with slimmedElectronsWithUserData or slimmedElectronsWithUserDataWithVID

# Next, we'll call Tom's MyElectronVariableHelper, which will calculate all the needed IDs. Alternatively, we could hack these into the fitter, since all the needed variables exist...
# ... if the fitter can edit the probe requirements both at the numerator and the denominator, then all the work can be done there, starting from the loosest Tag/Probe combination!

process.susyEleVarHelper = cms.EDProducer("SusyElectronVariableHelper",
probes = cms.InputTag("slimmedElectronsWithUserData"),
probesWithLepMVA = cms.InputTag("slimmedElectronsWithUserDataWithVID"),
mvas = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values"),
dxy = cms.InputTag("eleVarHelper:dxy"),
dz = cms.InputTag("eleVarHelper:dz"),
leptonMvas = cms.InputTag("electronMVATTH"),
rho = cms.InputTag("fixedGridRhoFastjetAll"),
)

# Notes on the order of processes:
# VID needs to run on the collection used to make goodElectrons (slimmedElectronsWithUserData) --> This means we can never add VID results to the collection making goodElectrons...
# The DataEmbedder (slimmedElectronsWithUserData) breaks the references, so we need to run VID and EleVarHelper after it --> Again, can never add VID results as userFloats
# Solution: make a temp electron collection with VID, use it to calculate the TTHMVA, and then teach the SusyElectronVariableHelper to load 2 electron collections, taking MVATTH from the temp one and adding it as a susyEleVarHelper variable. That way, the susyEleVarHelper re-establishes the link between TTHMVA and the main electron collection

process.susy_sequence = cms.Sequence()

process.susy_sequence = cms.Sequence(
process.isoForEle +
process.ptRatioRelForEle +
process.slimmedElectronsWithUserData
)
if (doJEC) :
process.susy_sequence += process.jetCorrFactors
process.susy_sequence += process.updatedJets
process.susy_sequence += process.ptRatioRelForEleUncorr

process.susy_sequence += process.isoForEle
process.susy_sequence += process.ptRatioRelForEle
process.susy_sequence += process.slimmedElectronsWithUserData

process.susy_sequence_requiresVID = cms.Sequence(
process.slimmedElectronsWithUserDataWithVID +
process.electronMVATTH +
process.susyEleVarHelper
)
Expand Down