Skip to content

Commit

Permalink
Style and performance improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
hqucms committed Sep 11, 2018
1 parent 11b373f commit 7a0e4dc
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 368 deletions.
15 changes: 15 additions & 0 deletions DataFormats/BTauReco/interface/DeepBoostedJetFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class DeepBoostedJetFeatures {
feature_map_[name];
}

void reserve(const std::string& name, unsigned capacity){
feature_map_[name].reserve(capacity);
}

void fill(const std::string& name, float value){
auto item = feature_map_.find(name);
if (item != feature_map_.end()){
Expand All @@ -34,6 +38,17 @@ class DeepBoostedJetFeatures {
feature_map_[name] = vec;
}

void check_consistency(const std::vector<std::string> &names) const {
if (names.empty()) return;
const auto ref_len = get(names.front()).size();
for (unsigned i=1; i<names.size(); ++i){
if (get(names[i]).size() != ref_len){
throw cms::Exception("InvalidArgument") << "[DeepBoostedJetFeatures::check_consistency()] Inconsistent variable length "
<< get(names[i]).size() << " for " << names[i] << ", should be " << ref_len;
}
}
}

const std::vector<float>& get(const std::string& name) const {
auto item = feature_map_.find(name);
if (item != feature_map_.end()){
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/PatCandidates/interface/Jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ namespace pat {

/// clear daughter references
void clearDaughters() override {
reco::CompositePtrCandidate::clearDaughters();
PATObject<reco::Jet>::clearDaughters();
daughtersTemp_.reset(); // need to reset daughtersTemp_ as well
}

Expand Down
108 changes: 18 additions & 90 deletions PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,102 +191,30 @@
, 'pfNegativeDeepFlavourJetTags:probg' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']]
, 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
# DeepBoostedJetTagging
, 'pfDeepBoostedJetTags:probTbcq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probTbqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probTbc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probTbq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probWcq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probWqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probZbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probZcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probZqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probHbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probHcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probHqqqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probQCDbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probQCDcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probQCDb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probQCDc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfDeepBoostedJetTags:probQCDothers' : [["pfDeepBoostedJetTagInfos"]]
# DeepBoostedJetTagging - Mass-decorrelated
, 'pfMassDecorrelatedDeepBoostedJetTags:probTbcq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probTbqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probTbc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probTbq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probWcq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probWqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probZbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probZcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probZqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probHbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probHcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probHqqqq' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probQCDbb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probQCDcc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probQCDb' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probQCDc' : [["pfDeepBoostedJetTagInfos"]]
, 'pfMassDecorrelatedDeepBoostedJetTags:probQCDothers' : [["pfDeepBoostedJetTagInfos"]]
}

#meta-taggers are simple arithmetic on top of other taggers, they are stored here
#such that in case you want them re-run also the parent tagger is re-run as well
_pfDeepBoostedJetTagsProbs = [
'pfDeepBoostedJetTags:probTbcq',
'pfDeepBoostedJetTags:probTbqq',
'pfDeepBoostedJetTags:probTbc',
'pfDeepBoostedJetTags:probTbq',
'pfDeepBoostedJetTags:probWcq',
'pfDeepBoostedJetTags:probWqq',
'pfDeepBoostedJetTags:probZbb',
'pfDeepBoostedJetTags:probZcc',
'pfDeepBoostedJetTags:probZqq',
'pfDeepBoostedJetTags:probHbb',
'pfDeepBoostedJetTags:probHcc',
'pfDeepBoostedJetTags:probHqqqq',
'pfDeepBoostedJetTags:probQCDbb',
'pfDeepBoostedJetTags:probQCDcc',
'pfDeepBoostedJetTags:probQCDb',
'pfDeepBoostedJetTags:probQCDc',
'pfDeepBoostedJetTags:probQCDothers',
]
_pfMassDecorrelatedDeepBoostedJetTagsProbs = [
'pfMassDecorrelatedDeepBoostedJetTags:probTbcq',
'pfMassDecorrelatedDeepBoostedJetTags:probTbqq',
'pfMassDecorrelatedDeepBoostedJetTags:probTbc',
'pfMassDecorrelatedDeepBoostedJetTags:probTbq',
'pfMassDecorrelatedDeepBoostedJetTags:probWcq',
'pfMassDecorrelatedDeepBoostedJetTags:probWqq',
'pfMassDecorrelatedDeepBoostedJetTags:probZbb',
'pfMassDecorrelatedDeepBoostedJetTags:probZcc',
'pfMassDecorrelatedDeepBoostedJetTags:probZqq',
'pfMassDecorrelatedDeepBoostedJetTags:probHbb',
'pfMassDecorrelatedDeepBoostedJetTags:probHcc',
'pfMassDecorrelatedDeepBoostedJetTags:probHqqqq',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDbb',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDcc',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDb',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDc',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDothers',
]
# meta-taggers are simple arithmetic on top of other taggers, they are stored here
# such that in case you want them re-run also the parent tagger is re-run as well

supportedMetaDiscr = {
'pfDeepCSVDiscriminatorsJetTags:BvsAll' : ['pfDeepCSVJetTags:probudsg', 'pfDeepCSVJetTags:probb', 'pfDeepCSVJetTags:probc', 'pfDeepCSVJetTags:probbb'],
'pfDeepCSVDiscriminatorsJetTags:CvsB' : ['pfDeepCSVJetTags:probudsg', 'pfDeepCSVJetTags:probb', 'pfDeepCSVJetTags:probc', 'pfDeepCSVJetTags:probbb'],
'pfDeepCSVDiscriminatorsJetTags:CvsL' : ['pfDeepCSVJetTags:probudsg', 'pfDeepCSVJetTags:probb', 'pfDeepCSVJetTags:probc', 'pfDeepCSVJetTags:probbb'],
'pfDeepCMVADiscriminatorsJetTags:BvsAll' : ['pfDeepCMVAJetTags:probudsg', 'pfDeepCMVAJetTags:probb', 'pfDeepCMVAJetTags:probc', 'pfDeepCMVAJetTags:probbb'],
'pfDeepCMVADiscriminatorsJetTags:CvsB' : ['pfDeepCMVAJetTags:probudsg', 'pfDeepCMVAJetTags:probb', 'pfDeepCMVAJetTags:probc', 'pfDeepCMVAJetTags:probbb'],
'pfDeepCMVADiscriminatorsJetTags:BvsAll' : ['pfDeepCMVAJetTags:probudsg', 'pfDeepCMVAJetTags:probb', 'pfDeepCMVAJetTags:probc', 'pfDeepCMVAJetTags:probbb'],
'pfDeepCMVADiscriminatorsJetTags:CvsB' : ['pfDeepCMVAJetTags:probudsg', 'pfDeepCMVAJetTags:probb', 'pfDeepCMVAJetTags:probc', 'pfDeepCMVAJetTags:probbb'],
'pfDeepCMVADiscriminatorsJetTags:CvsL' : ['pfDeepCMVAJetTags:probudsg', 'pfDeepCMVAJetTags:probb', 'pfDeepCMVAJetTags:probc', 'pfDeepCMVAJetTags:probbb'],
'pfDeepBoostedDiscriminatorsJetTags:TvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfDeepBoostedDiscriminatorsJetTags:WvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfDeepBoostedDiscriminatorsJetTags:ZvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfDeepBoostedDiscriminatorsJetTags:ZbbvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfDeepBoostedDiscriminatorsJetTags:HbbvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfDeepBoostedDiscriminatorsJetTags:H4qvsQCD' : _pfDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:TvsQCD' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:WvsQCD' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHbbvsQCD' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHccvsQCD' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:bbvsLight' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ccvsLight' : _pfMassDecorrelatedDeepBoostedJetTagsProbs,
}

# -----------------------------------
# setup DeepBoostedJet
from RecoBTag.DeepBoostedJet.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsProbs, _pfDeepBoostedJetTagsMetaDiscrs, \
_pfMassDecorrelatedDeepBoostedJetTagsProbs, _pfMassDecorrelatedDeepBoostedJetTagsMetaDiscrs
# update supportedBtagDiscr
for disc in _pfDeepBoostedJetTagsProbs + _pfMassDecorrelatedDeepBoostedJetTagsProbs:
supportedBtagDiscr[disc] = [["pfDeepBoostedJetTagInfos"]]
# update supportedMetaDiscr
for disc in _pfDeepBoostedJetTagsMetaDiscrs:
supportedMetaDiscr[disc] = _pfDeepBoostedJetTagsProbs
for disc in _pfMassDecorrelatedDeepBoostedJetTagsMetaDiscrs:
supportedMetaDiscr[disc] = _pfMassDecorrelatedDeepBoostedJetTagsProbs
# -----------------------------------
56 changes: 2 additions & 54 deletions PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def applyDeepBtagging( process, postfix="" ) :
# delete module not used anymore (slimmedJets substitutes)
delattr(process, 'selectedUpdatedPatJetsSlimmedDeepFlavour'+postfix)

from RecoBTag.DeepBoostedJet.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll as pfDeepBoostedJetTagsAll

# update slimmed jets to include particle-based deep taggers (keep same name)
# make clone for DeepTags-less slimmed AK8 jets, so output name is preserved
Expand All @@ -61,60 +62,7 @@ def applyDeepBtagging( process, postfix="" ) :
btagDiscriminators = [
'pfDeepDoubleBJetTags:probQ',
'pfDeepDoubleBJetTags:probH',

# DeepBoostedJet (Nominal)
'pfDeepBoostedJetTags:probTbcq',
'pfDeepBoostedJetTags:probTbqq',
'pfDeepBoostedJetTags:probTbc',
'pfDeepBoostedJetTags:probTbq',
'pfDeepBoostedJetTags:probWcq',
'pfDeepBoostedJetTags:probWqq',
'pfDeepBoostedJetTags:probZbb',
'pfDeepBoostedJetTags:probZcc',
'pfDeepBoostedJetTags:probZqq',
'pfDeepBoostedJetTags:probHbb',
'pfDeepBoostedJetTags:probHcc',
'pfDeepBoostedJetTags:probHqqqq',
'pfDeepBoostedJetTags:probQCDbb',
'pfDeepBoostedJetTags:probQCDcc',
'pfDeepBoostedJetTags:probQCDb',
'pfDeepBoostedJetTags:probQCDc',
'pfDeepBoostedJetTags:probQCDothers',
# meta taggers
'pfDeepBoostedDiscriminatorsJetTags:TvsQCD',
'pfDeepBoostedDiscriminatorsJetTags:WvsQCD',
'pfDeepBoostedDiscriminatorsJetTags:ZvsQCD',
'pfDeepBoostedDiscriminatorsJetTags:ZbbvsQCD',
'pfDeepBoostedDiscriminatorsJetTags:HbbvsQCD',
'pfDeepBoostedDiscriminatorsJetTags:H4qvsQCD',

# DeepBoostedJet (mass decorrelated)
'pfMassDecorrelatedDeepBoostedJetTags:probTbcq',
'pfMassDecorrelatedDeepBoostedJetTags:probTbqq',
'pfMassDecorrelatedDeepBoostedJetTags:probTbc',
'pfMassDecorrelatedDeepBoostedJetTags:probTbq',
'pfMassDecorrelatedDeepBoostedJetTags:probWcq',
'pfMassDecorrelatedDeepBoostedJetTags:probWqq',
'pfMassDecorrelatedDeepBoostedJetTags:probZbb',
'pfMassDecorrelatedDeepBoostedJetTags:probZcc',
'pfMassDecorrelatedDeepBoostedJetTags:probZqq',
'pfMassDecorrelatedDeepBoostedJetTags:probHbb',
'pfMassDecorrelatedDeepBoostedJetTags:probHcc',
'pfMassDecorrelatedDeepBoostedJetTags:probHqqqq',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDbb',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDcc',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDb',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDc',
'pfMassDecorrelatedDeepBoostedJetTags:probQCDothers',
# meta taggers
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:TvsQCD',
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:WvsQCD',
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHbbvsQCD',
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHccvsQCD',
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:bbvsLight',
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ccvsLight',

],
] + pfDeepBoostedJetTagsAll,
postfix = 'SlimmedAK8DeepTags'+postfix,
printWarning = False
)
Expand Down
16 changes: 8 additions & 8 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,21 +633,21 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
if btagInfo == 'pfDeepBoostedJetTagInfos':
if pfCandidates.value() == 'packedPFCandidates':
jetSrcName = jetSource.value().lower()
if 'slimmed' in jetSrcName or 'updated' in jetSrcName or 'packed' in jetSrcName:
# case 1: update jets whose daughters are PackedCandidates, e.g., slimmedJetsAK8, packedPatJetsAK8, etc.
if 'slimmed' in jetSrcName or 'updated' in jetSrcName:
# case 1: update jets whose daughters are PackedCandidates, e.g., slimmedJetsAK8, etc.
# daughters are links to original PackedCandidates, so NOT scaled by their puppi weights yet
has_puppi_weighted_daughters = cms.bool(False)
puppi_value_map = cms.InputTag("")
vertex_associator = cms.InputTag("")
has_puppi_weighted_daughters = False
puppi_value_map = ""
vertex_associator = ""
else:
raise ValueError("Cannot run pfDeepBoostedJetTagInfos on jet collection: %s." % jetSource.value())
elif pfCandidates.value() == 'particleFlow':
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
# case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
# daughters are the particles used in jet clustering, so already scaled by their puppi weights
has_puppi_weighted_daughters = cms.bool(True)
puppi_value_map = cms.InputTag("puppi")
vertex_associator = cms.InputTag("primaryVertexAssociation", "original")
# has_puppi_weighted_daughters = True
# puppi_value_map = "puppi"
# vertex_associator = "primaryVertexAssociation:original"
else:
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
Expand Down
Loading

0 comments on commit 7a0e4dc

Please sign in to comment.