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

Preparations of deep tau ID for hlt phase2 (backport to CMSSW_11_1_X) #32831

Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6041fed
removed unnessecary argument of EventSetup from getPredictions function
JamminJones Jul 16, 2020
1106f5e
Changed DeepTau modules so that they can use AOD and RECO input
lwezenbe Sep 7, 2020
0d7ee8a
Update DeepTauId.cc
lwezenbe Sep 7, 2020
dc11b7f
Added customization file used for testing module at RECO level
lwezenbe Sep 8, 2020
9a818d9
- Clean up whitespaces, empty lines and unneeded lines
lwezenbe Sep 22, 2020
01c2673
Changed type of electron_collection and muon_collection in lightLepFu…
lwezenbe Sep 22, 2020
31b7b15
- Implement Prediscriminators
lwezenbe Sep 28, 2020
59cc574
Switch discriminator indices for RECO from configuration input to mat…
lwezenbe Sep 29, 2020
e30bdf6
Translated map with indices for the basic discriminators to enum
lwezenbe Oct 2, 2020
37e02d2
Cleanup of leftover lines from testing
lwezenbe Oct 2, 2020
29dc4c1
Made stringFromDiscriminator map and the vectors defining required di…
lwezenbe Oct 6, 2020
71587f8
Once again forgot to remove a print line from testing
lwezenbe Oct 6, 2020
ffdd965
- Changed some member names to be according to the naming conventions
lwezenbe Oct 6, 2020
d7acd1a
apply code formatting
Oct 9, 2020
95ba68e
remove redundant const qualifiers
Oct 11, 2020
2c367d2
move deepTauAtHLT.py to RecoTauTag/HLTProducers
Oct 12, 2020
9a6c59d
Make changes requested in PR https://github.com/cms-sw/cmssw/pull/31744
lwezenbe Oct 30, 2020
7ef5bb2
fix code format
Oct 30, 2020
66081f5
Make changes requested in PR https://github.com/cms-sw/cmssw/pull/317…
lwezenbe Oct 30, 2020
bafab6e
fix input pfCand_muon_dz_sig
Nov 10, 2020
4c11e4a
pass WPList as ponter instead of by reference, to allow for the case …
veelken Dec 18, 2020
788a035
added option to apply HGCal work-around when computing the charged is…
veelken Dec 18, 2020
4b4a1f3
- improved checks of input variables
veelken Dec 18, 2020
73158e9
added disable_CellIndex_workaround parameter to enable/disable bug-fi…
veelken Dec 23, 2020
5bda512
set "disable_hcalFraction_workaround" and"disable_CellIndex_workaroun…
veelken Jan 11, 2021
204a818
code polishing as suggested by Sebastian
veelken Jan 11, 2021
36c54c8
more code polishing, following comments by Sebastian
veelken Jan 11, 2021
5239bb2
set disable_hcalFraction_workaround to false by default
veelken Jan 11, 2021
03552b5
inverted definition of disable_CellIndex_workaround, as requested by …
veelken Jan 11, 2021
4430e19
apply code checks and automated format
Jan 12, 2021
af4f5bf
Default value changes in DeepTauId module and puppiweight functions (…
lwezenbe Jan 15, 2021
d9c79d5
add mutex to protect set operation
Jan 15, 2021
7abd081
better placement of mutex
Jan 18, 2021
9457485
apply code format
Jan 19, 2021
e111e75
more elegant method to ensure thread safety
Jan 19, 2021
a96b375
follow up on review
Jan 28, 2021
1d7a7de
fix handling of CellGrids
Feb 3, 2021
6ec8f51
follow up on review
Feb 5, 2021
541726e
fix code format
Feb 5, 2021
6834218
use non-static lambda in DeepTauId::CellGrid::tryGetCellIndex
slava77 Feb 6, 2021
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
140 changes: 140 additions & 0 deletions RecoTauTag/HLTProducers/python/deepTauAtHLT.py
@@ -0,0 +1,140 @@
import FWCore.ParameterSet.Config as cms

from RecoTauTag.RecoTau.PFRecoTauDiscriminationByIsolation_cfi import *
from RecoTauTag.RecoTau.PFRecoTauQualityCuts_cfi import PFTauQualityCuts
from RecoTauTag.RecoTau.PFRecoTauDiscriminationByHPSSelection_cfi import hpsSelectionDiscriminator

from RecoTauTag.RecoTau.PFTauPrimaryVertexProducer_cfi import *
from RecoTauTag.RecoTau.PFTauSecondaryVertexProducer_cfi import *
from RecoTauTag.RecoTau.PFTauTransverseImpactParameters_cfi import *

from RecoTauTag.RecoTau.DeepTau_cfi import *

from RecoTauTag.RecoTau.PFRecoTauPFJetInputs_cfi import PFRecoTauPFJetInputs
## DeltaBeta correction factor
ak4dBetaCorrection = 0.20

def update(process):
process.options.wantSummary = cms.untracked.bool(True)

process.hltFixedGridRhoFastjetAll = cms.EDProducer( "FixedGridRhoProducerFastjet",
gridSpacing = cms.double( 0.55 ),
maxRapidity = cms.double( 5.0 ),
pfCandidatesTag = cms.InputTag( "hltParticleFlowReg" )
)

PFTauQualityCuts.primaryVertexSrc = cms.InputTag("hltPixelVertices")

## Decay mode prediscriminant
requireDecayMode = cms.PSet(
BooleanOperator = cms.string("and"),
decayMode = cms.PSet(
Producer = cms.InputTag('hltHpsPFTauDiscriminationByDecayModeFindingNewDMsReg'),
cut = cms.double(0.5)
)
)

## Cut based isolations dR=0.5
process.hpsPFTauBasicDiscriminators = pfRecoTauDiscriminationByIsolation.clone(
PFTauProducer = 'hltHpsPFTauProducerReg',
Prediscriminants = requireDecayMode.clone(),
deltaBetaPUTrackPtCutOverride = True, # Set the boolean = True to override.
deltaBetaPUTrackPtCutOverride_val = 0.5, # Set the value for new value.
particleFlowSrc = 'hltParticleFlowReg',
vertexSrc = PFTauQualityCuts.primaryVertexSrc,
customOuterCone = PFRecoTauPFJetInputs.isolationConeSize,
isoConeSizeForDeltaBeta = 0.8,
deltaBetaFactor = "%0.4f"%(ak4dBetaCorrection),
qualityCuts = dict(isolationQualityCuts = dict(minTrackHits = 3, minGammaEt = 1.0, minTrackPt = 0.5)),
IDdefinitions = [
cms.PSet(
IDname = cms.string("ChargedIsoPtSum"),
ApplyDiscriminationByTrackerIsolation = cms.bool(True),
storeRawSumPt = cms.bool(True)
),
cms.PSet(
IDname = cms.string("NeutralIsoPtSum"),
ApplyDiscriminationByECALIsolation = cms.bool(True),
storeRawSumPt = cms.bool(True)
),
cms.PSet(
IDname = cms.string("NeutralIsoPtSumWeight"),
ApplyDiscriminationByWeightedECALIsolation = cms.bool(True),
storeRawSumPt = cms.bool(True),
UseAllPFCandsForWeights = cms.bool(True)
),
cms.PSet(
IDname = cms.string("TauFootprintCorrection"),
storeRawFootprintCorrection = cms.bool(True)
),
cms.PSet(
IDname = cms.string("PhotonPtSumOutsideSignalCone"),
storeRawPhotonSumPt_outsideSignalCone = cms.bool(True)
),
cms.PSet(
IDname = cms.string("PUcorrPtSum"),
applyDeltaBetaCorrection = cms.bool(True),
storeRawPUsumPt = cms.bool(True)
),
],
)

## Cut based isolations dR=0.3
process.hpsPFTauBasicDiscriminatorsdR03 = process.hpsPFTauBasicDiscriminators.clone(
customOuterCone = 0.3
)

process.hpsPFTauPrimaryVertexProducer = PFTauPrimaryVertexProducer.clone(
PFTauTag = "hltHpsPFTauProducerReg",
ElectronTag = "hltEgammaCandidates",
MuonTag = "hltMuonsReg",
PVTag = "hltPixelVertices",
beamSpot = "hltOnlineBeamSpot",
discriminators = [
cms.PSet(
discriminator = cms.InputTag('hltHpsPFTauDiscriminationByDecayModeFindingNewDMsReg'),
selectionCut = cms.double(0.5)
)
],
cut = "pt > 18.0 & abs(eta) < 2.4",
qualityCuts = PFTauQualityCuts
)

process.hpsPFTauSecondaryVertexProducer = PFTauSecondaryVertexProducer.clone(
PFTauTag = "hltHpsPFTauProducerReg"
)
process.hpsPFTauTransverseImpactParameters = PFTauTransverseImpactParameters.clone(
PFTauTag = "hltHpsPFTauProducerReg",
PFTauPVATag = "hpsPFTauPrimaryVertexProducer",
PFTauSVATag = "hpsPFTauSecondaryVertexProducer",
useFullCalculation = True
)

file_names = [
'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
]

working_points = ["0.", "0.92"]

process.deepTauProducer = DeepTau.clone(
taus = 'hltHpsPFTauProducerReg',
pfcands = 'hltParticleFlowReg',
vertices = 'hltPixelVertices',
rho = 'hltFixedGridRhoFastjetAll',
graph_file = file_names,
disable_dxy_pca = cms.bool(True),
is_online = cms.bool(True),
basicTauDiscriminators = 'hpsPFTauBasicDiscriminators',
basicTauDiscriminatorsdR03 = 'hpsPFTauBasicDiscriminatorsdR03',
Prediscriminants = requireDecayMode.clone(),
VSeWP = working_points,
VSmuWP = working_points,
VSjetWP = working_points
)

# Add DeepTauProducer
process.HLTHPSMediumChargedIsoPFTauSequenceReg += (process.hpsPFTauPrimaryVertexProducer + process.hpsPFTauSecondaryVertexProducer + process.hpsPFTauTransverseImpactParameters + process.hltFixedGridRhoFastjetAll + process.hpsPFTauBasicDiscriminators + process.hpsPFTauBasicDiscriminatorsdR03 + process.deepTauProducer)

return process
51 changes: 43 additions & 8 deletions RecoTauTag/RecoTau/interface/DeepTauBase.h
Expand Up @@ -19,18 +19,26 @@
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "DataFormats/TauReco/interface/TauDiscriminatorContainer.h"
#include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
#include "DataFormats/PatCandidates/interface/PATTauDiscriminator.h"
#include "CommonTools/Utils/interface/StringObjectFunction.h"
#include "RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/RefToBase.h"
#include "DataFormats/Provenance/interface/ProductProvenance.h"
#include "DataFormats/Provenance/interface/ProcessHistoryID.h"
#include "FWCore/Common/interface/Provenance.h"
#include <TF1.h>
#include <map>

namespace deep_tau {

class TauWPThreshold {
public:
explicit TauWPThreshold(const std::string& cut_str);
double operator()(const pat::Tau& tau) const;
double operator()(const reco::BaseTau& tau, bool isPFTau) const;

private:
std::unique_ptr<TF1> fn_;
Expand All @@ -57,9 +65,9 @@ namespace deep_tau {

class DeepTauBase : public edm::stream::EDProducer<edm::GlobalCache<DeepTauCache>> {
public:
using TauType = pat::Tau;
using TauDiscriminator = reco::TauDiscriminatorContainer;
using TauCollection = std::vector<TauType>;
using TauCollection = edm::View<reco::BaseTau>;
using CandidateCollection = edm::View<reco::Candidate>;
using TauRef = edm::Ref<TauCollection>;
using TauRefProd = edm::RefProd<TauCollection>;
using ElectronCollection = pat::ElectronCollection;
Expand All @@ -76,7 +84,8 @@ namespace deep_tau {

std::unique_ptr<TauDiscriminator> get_value(const edm::Handle<TauCollection>& taus,
const tensorflow::Tensor& pred,
const WPList& working_points) const;
const WPList* working_points,
bool is_online) const;
};

using OutputCollection = std::map<std::string, Output>;
Expand All @@ -89,19 +98,45 @@ namespace deep_tau {
static std::unique_ptr<DeepTauCache> initializeGlobalCache(const edm::ParameterSet& cfg);
static void globalEndJob(const DeepTauCache* cache) {}

template <typename ConsumeType>
struct TauDiscInfo {
edm::InputTag label;
edm::Handle<ConsumeType> handle;
edm::EDGetTokenT<ConsumeType> disc_token;
double cut;
void fill(const edm::Event& evt) { evt.getByToken(disc_token, handle); }
};

// select boolean operation on prediscriminants (and = 0x01, or = 0x00)
uint8_t andPrediscriminants_;
std::vector<TauDiscInfo<pat::PATTauDiscriminator>> patPrediscriminants_;
std::vector<TauDiscInfo<reco::PFTauDiscriminator>> recoPrediscriminants_;

enum BasicDiscriminator {
ChargedIsoPtSum,
NeutralIsoPtSum,
NeutralIsoPtSumWeight,
FootprintCorrection,
PhotonPtSumOutsideSignalCone,
PUcorrPtSum
};

private:
virtual tensorflow::Tensor getPredictions(edm::Event& event,
const edm::EventSetup& es,
edm::Handle<TauCollection> taus) = 0;
virtual tensorflow::Tensor getPredictions(edm::Event& event, edm::Handle<TauCollection> taus) = 0;
virtual void createOutputs(edm::Event& event, const tensorflow::Tensor& pred, edm::Handle<TauCollection> taus);

protected:
edm::EDGetTokenT<TauCollection> tausToken_;
edm::EDGetTokenT<pat::PackedCandidateCollection> pfcandToken_;
edm::EDGetTokenT<CandidateCollection> pfcandToken_;
edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
std::map<std::string, WPList> workingPoints_;
const bool is_online_;
OutputCollection outputs_;
const DeepTauCache* cache_;

static const std::map<BasicDiscriminator, std::string> stringFromDiscriminator_;
static const std::vector<BasicDiscriminator> requiredBasicDiscriminators_;
static const std::vector<BasicDiscriminator> requiredBasicDiscriminatorsdR03_;
};

} // namespace deep_tau
Expand Down
4 changes: 1 addition & 3 deletions RecoTauTag/RecoTau/plugins/DPFIsolation.cc
Expand Up @@ -74,9 +74,7 @@ class DPFIsolation : public deep_tau::DeepTauBase {
}

private:
tensorflow::Tensor getPredictions(edm::Event& event,
const edm::EventSetup& es,
edm::Handle<TauCollection> taus) override {
tensorflow::Tensor getPredictions(edm::Event& event, edm::Handle<TauCollection> taus) override {
edm::Handle<pat::PackedCandidateCollection> pfcands;
event.getByToken(pfcandToken_, pfcands);

Expand Down