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

DeepCSV and CSVv2 negative tagger bugfix #23206

Merged
merged 18 commits into from Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 53 additions & 6 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Expand Up @@ -322,6 +322,51 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
## setup all required btagInfos : we give a dedicated treatment for different
## types of tagInfos here. A common treatment is possible but might require a more
## general approach anyway in coordination with the btagging POG.

runNegativeVertexing = False
runNegativeCvsLVertexing = False
for btagInfo in requiredTagInfos:
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos' or btagInfo == 'pfNegativeDeepFlavourTagInfos':
runNegativeVertexing = True
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
runNegativeCvsLVertexing = True

if runNegativeVertexing or runNegativeCvsLVertexing:
import RecoVertex.AdaptiveVertexFinder.inclusiveNegativeVertexing_cff as NegVertex

if runNegativeVertexing:
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeVertexFinder.clone(primaryVertices = pvSource,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix,
NegVertex.candidateNegativeVertexMerger.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix)),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix,
NegVertex.candidateNegativeVertexArbitrator.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix)
,primaryVertices = pvSource
,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeSecondaryVertices.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix)),
process, task)

if runNegativeCvsLVertexing:
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeVertexFinderCvsL.clone(primaryVertices = pvSource,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix,
NegVertex.candidateNegativeVertexMergerCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix)),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix,
NegVertex.candidateNegativeVertexArbitratorCvsL.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix)
,primaryVertices = pvSource
,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeSecondaryVerticesCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix)),
process, task)


acceptedTagInfos = list()
for btagInfo in requiredTagInfos:
if hasattr(btag,btagInfo):
Expand Down Expand Up @@ -464,7 +509,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection=svSourceCvsL),
extSVCollection = btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
Expand All @@ -486,7 +531,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection=svSource),
extSVCollection=cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
Expand Down Expand Up @@ -548,12 +593,14 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
process, task)

if 'DeepFlavourTagInfos' in btagInfo:

svUsed = svSource
if btagInfo == 'pfNegativeDeepFlavourTagInfos':
deep_csv_tag_infos = 'pfDeepCSVNegativeTagInfos'
deep_csv_tag_infos = 'pfDeepCSVNegativeTagInfos'
svUsed = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
flip = True
else:
deep_csv_tag_infos = 'pfDeepCSVTagInfos'

flip = False
# use right input tags when running with RECO PF candidates, which actually
# depens of wether jets were slimmed or not (check for s/S-limmed in name)
if not ('limmed' in jetSource.value()):
Expand All @@ -566,7 +613,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
btag.pfDeepFlavourTagInfos.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svSource,
secondary_vertices=svUsed,
shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
puppi_value_map = puppi_value_map,
vertex_associator = vertex_associator,
Expand Down
37 changes: 26 additions & 11 deletions RecoBTag/Combined/python/deepFlavour_cff.py
Expand Up @@ -11,22 +11,37 @@
##

pfDeepCSVNegativeTagInfos = pfDeepCSVTagInfos.clone(
svTagInfos=cms.InputTag('pfInclusiveSecondaryVertexFinderNegativeTagInfos')
)
pfDeepCSVNegativeTagInfos.computer.vertexFlip = True
pfDeepCSVNegativeTagInfos.computer.trackFlip = True
pfDeepCSVNegativeTagInfos.computer.trackSelection.sip3dSigMax = 0
pfDeepCSVNegativeTagInfos.computer.trackPseudoSelection.sip3dSigMax = 0
pfDeepCSVNegativeTagInfos.computer.trackPseudoSelection.sip2dSigMin = -99999.9
pfDeepCSVNegativeTagInfos.computer.trackPseudoSelection.sip2dSigMax = -2.0
svTagInfos=cms.InputTag('pfInclusiveSecondaryVertexFinderNegativeTagInfos'),
computer = dict(
vertexFlip = True,
trackFlip = True,
trackSelection = dict(
sip3dSigMax = 10.0
),
trackPseudoSelection = dict(
sip3dSigMax = 10.0,
sip2dSigMin = -99999.9,
sip2dSigMax = -2.0
)
)
)

pfNegativeDeepCSVJetTags = pfDeepCSVJetTags.clone(
src=cms.InputTag('pfDeepCSVNegativeTagInfos')
)

pfDeepCSVPositiveTagInfos = pfDeepCSVTagInfos.clone()
pfDeepCSVPositiveTagInfos.computer.trackSelection.sip3dSigMin = 0
pfDeepCSVPositiveTagInfos.computer.trackPseudoSelection.sip3dSigMin = 0
pfDeepCSVPositiveTagInfos = pfDeepCSVTagInfos.clone(
computer = dict(
trackSelection = dict(
sip3dSigMin = 0
),
trackPseudoSelection = dict(
sip3dSigMin = 0
)
)

)

pfPositiveDeepCSVJetTags = pfDeepCSVJetTags.clone(
src=cms.InputTag('pfDeepCSVPositiveTagInfos')
)
Expand Down
4 changes: 2 additions & 2 deletions RecoBTag/SecondaryVertex/interface/CombinedSVComputer.h
Expand Up @@ -143,7 +143,7 @@ void CombinedSVComputer::fillCommonVariables(reco::TaggingVariableList & vars, r
vars.insert(btau::flightDistance2dSig,flipValue(svInfo.flightDistance(vtx, 2).significance(),true),true);
vars.insert(btau::flightDistance3dVal,flipValue(svInfo.flightDistance(vtx, 3).value(),true),true);
vars.insert(btau::flightDistance3dSig,flipValue(svInfo.flightDistance(vtx, 3).significance(),true),true);
vars.insert(btau::vertexJetDeltaR,Geom::deltaR(svInfo.flightDirection(vtx), jetDir),true);
vars.insert(btau::vertexJetDeltaR,Geom::deltaR(svInfo.flightDirection(vtx), vertexFlip ? -jetDir : jetDir),true);
vars.insert(btau::jetNSecondaryVertices, svInfo.nVertices(), true);
}

Expand Down Expand Up @@ -244,7 +244,7 @@ void CombinedSVComputer::fillCommonVariables(reco::TaggingVariableList & vars, r
vars.insert(btau::trackJetPt, trackJetKinematics.vectorSum().Pt(), true);
vars.insert(btau::trackSumJetDeltaR,VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
vars.insert(btau::trackSumJetEtRatio,allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);

vars.insert(btau::trackSip3dSigAboveCharm, flipValue(threshTrack(ipInfo, reco::btag::IP3DSig, *jet, pv).ip3d.significance(),false),true);
vars.insert(btau::trackSip3dValAboveCharm, flipValue(threshTrack(ipInfo, reco::btag::IP3DSig, *jet, pv).ip3d.value(),false),true);
vars.insert(btau::trackSip2dSigAboveCharm, flipValue(threshTrack(ipInfo, reco::btag::IP2DSig, *jet, pv).ip2d.significance(),false),true);
Expand Down
Expand Up @@ -860,9 +860,10 @@ void TemplatedSecondaryVertexProducer<IPTI,VTX>::produce(edm::Event &event,
else {
for(size_t iExtSv = 0; iExtSv < extSecVertex->size(); iExtSv++){
const VTX & extVertex = (*extSecVertex)[iExtSv];
if( Geom::deltaR2( ( position(extVertex) - pv.position() ), jetDir ) > extSVDeltaRToJet*extSVDeltaRToJet || extVertex.p4().M() < 0.3 )
if( Geom::deltaR2( ( position(extVertex) - pv.position() ), (extSVDeltaRToJet > 0) ? jetDir : -jetDir ) > extSVDeltaRToJet*extSVDeltaRToJet || extVertex.p4().M() < 0.3 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bugfix that affects more than just Deep* negative taggers.
It's worth to be noted in the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean here? That it also affects CSV?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm re-reading the description and now I see that it also mentions "(and CSVv2) ".
OK then.

continue;
extAssoCollection.push_back( extVertex );

}
}
// build combined SV information and filter
Expand Down Expand Up @@ -1021,7 +1022,7 @@ void TemplatedSecondaryVertexProducer<IPTI,VTX>::matchReclusteredJets(const edm:
std::vector<int>& matchedIndices,
const std::string& jetType)
{
std::string type = ( jetType!="" ? jetType + " " : jetType );
std::string type = ( !jetType.empty() ? jetType + " " : jetType );

std::vector<bool> matchedLocks(reclusteredJets.size(),false);

Expand Down
Expand Up @@ -2,10 +2,14 @@

from RecoBTag.SecondaryVertex.pfInclusiveSecondaryVertexFinderTagInfos_cfi import *

pfInclusiveSecondaryVertexFinderNegativeTagInfos = pfInclusiveSecondaryVertexFinderTagInfos.clone()
pfInclusiveSecondaryVertexFinderNegativeTagInfos.extSVDeltaRToJet = cms.double(-0.3)
pfInclusiveSecondaryVertexFinderNegativeTagInfos.vertexCuts.distVal2dMin = -2.5
pfInclusiveSecondaryVertexFinderNegativeTagInfos.vertexCuts.distVal2dMax = -0.01
pfInclusiveSecondaryVertexFinderNegativeTagInfos.vertexCuts.distSig2dMin = -99999.9
pfInclusiveSecondaryVertexFinderNegativeTagInfos.vertexCuts.distSig2dMax = -2.0
pfInclusiveSecondaryVertexFinderNegativeTagInfos.vertexCuts.maxDeltaRToJetAxis = -0.5
pfInclusiveSecondaryVertexFinderNegativeTagInfos = pfInclusiveSecondaryVertexFinderTagInfos.clone(
extSVDeltaRToJet = -0.3,
extSVCollection = 'inclusiveCandidateNegativeSecondaryVertices',
vertexCuts = dict(
distVal2dMin = -2.5,
distVal2dMax = -0.01,
distSig2dMin = -99999.9,
distSig2dMax = -2.0,
maxDeltaRToJetAxis = -0.5
)
)
70 changes: 50 additions & 20 deletions RecoBTag/SecondaryVertex/src/CombinedSVComputer.cc
Expand Up @@ -77,17 +77,32 @@ CombinedSVComputer::threshTrack(const CandIPTagInfo &trackIPTagInfo,
if (kin.vectorSum().M() > charmCut)
return data;
}
if(trackFlip){
static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
0.
};
return dummy;
}
else{
static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
0.
};
return dummy;
}


static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
0.
};
return dummy;
}

const btag::TrackIPData &
Expand Down Expand Up @@ -117,16 +132,31 @@ CombinedSVComputer::threshTrack(const TrackIPTagInfo &trackIPTagInfo,
return data;
}

static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
0.
};
return dummy;
if(trackFlip){
static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
Measurement1D(1.0, 1.0),
0.
};
return dummy;
}
else{
static const btag::TrackIPData dummy = {
GlobalPoint(),
GlobalPoint(),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
Measurement1D(-1.0, 1.0),
0.
};
return dummy;
}

}


Expand Down
Expand Up @@ -86,6 +86,7 @@ class TrackVertexArbitration{
double trackMinPt;
int trackMinPixels;
double maxTimeSignificance;
double sign;
};

#include "DataFormats/GeometryVector/interface/VectorUtil.h"
Expand All @@ -107,7 +108,9 @@ TrackVertexArbitration<VTX>::TrackVertexArbitration(const edm::ParameterSet &par
trackMinPixels (params.getParameter<int32_t>("trackMinPixels")),
maxTimeSignificance (params.getParameter<double>("maxTimeSignificance"))
{
dRCut*=dRCut;
sign = 1.0;
if(dRCut < 0){sign = -1.0;}
dRCut*=dRCut;
}
template <class VTX>
bool TrackVertexArbitration<VTX>::trackFilterArbitrator(const reco::TransientTrack &track) const
Expand Down Expand Up @@ -203,7 +206,7 @@ std::vector<VTX> TrackVertexArbitration<VTX>::trackVertexArbitrator(
GlobalError refPointErr = tsos.cartesianError().position();
Measurement1D isv = dist.distance(VertexState(RecoVertex::convertPos(sv->position()),RecoVertex::convertError(sv->error())),VertexState(refPoint, refPointErr));

float dR = Geom::deltaR2(flightDir,tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());
float dR = Geom::deltaR2(( (sign > 0) ? flightDir : -flightDir),tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());

double timeSig = 0.;
if( svHasTime && edm::isFinite(tt.timeExt()) ) {
Expand Down
Expand Up @@ -285,11 +285,13 @@ void TemplatedInclusiveVertexFinder<InputContainer,VTX>::produce(edm::Event &eve
#endif
}
GlobalPoint sv((*v).position().x(),(*v).position().y(),(*v).position().z());
float vscal = dir.unit().dot((sv-ppv).unit()) ;
// std::cout << "Vscal: " << vscal << std::endl;
if(dlen.significance() > vertexMinDLenSig && vscal > vertexMinAngleCosine && v->normalisedChiSquared() < 10 && dlen2.significance() > vertexMinDLen2DSig)
float vscal = dir.unit().dot((sv-ppv).unit());
if(dlen.significance() > vertexMinDLenSig &&
( (vertexMinAngleCosine > 0) ? (vscal > vertexMinAngleCosine) : (vscal < vertexMinAngleCosine) )
&& v->normalisedChiSquared() < 10 && dlen2.significance() > vertexMinDLen2DSig)
{
recoVertices->push_back(*v);

#ifdef VTXDEBUG
std::cout << "ADDED" << std::endl;
#endif
Expand Down