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

Change DeepTauID modules so they can also process RECO input for HLT purposes #31744

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
193 changes: 193 additions & 0 deletions RecoTauTag/HLTProducers/python/deepTauAtHLT.py
@@ -0,0 +1,193 @@
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, decayMode_1Prong0Pi0, decayMode_1Prong1Pi0, decayMode_1Prong2Pi0, decayMode_2Prong0Pi0, decayMode_2Prong1Pi0, decayMode_3Prong0Pi0, decayMode_3Prong1Pi0

from RecoTauTag.RecoTau.PFTauPrimaryVertexProducer_cfi import *
from RecoTauTag.RecoTau.PFTauSecondaryVertexProducer_cfi import *
from RecoTauTag.RecoTau.PFTauTransverseImpactParameters_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 = cms.InputTag('hltHpsPFTauProducerReg'),
Copy link
Contributor

Choose a reason for hiding this comment

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

please drop type specifications for all parameters which already exist.
This is a safer way to protect from parameter name mistakes and will also help in possible parameter migrations.

Suggested change
PFTauProducer = cms.InputTag('hltHpsPFTauProducerReg'),
PFTauProducer = 'hltHpsPFTauProducerReg',

the parameter exists already, as can be seen in $CMSSW_RELEASE_BASE/cfipython/$SCRAM_ARCH/RecoTauTag/RecoTau/pfRecoTauDiscriminationByIsolationContainer_cfi.py

Prediscriminants = requireDecayMode.clone(),
deltaBetaPUTrackPtCutOverride = True, # Set the boolean = True to override.
deltaBetaPUTrackPtCutOverride_val = 0.5, # Set the value for new value.
particleFlowSrc = cms.InputTag("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.VPSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IDdefinitions = cms.VPSet(
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 = cms.InputTag("hltHpsPFTauProducerReg"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
PFTauTag = cms.InputTag("hltHpsPFTauProducerReg"),
PFTauTag = "hltHpsPFTauProducerReg",

similarly for the rest of the existing parameters

ElectronTag = cms.InputTag("hltEgammaCandidates"),
MuonTag = cms.InputTag("hltMuonsReg"),
PVTag = cms.InputTag("hltPixelVertices"),
beamSpot = cms.InputTag("hltOnlineBeamSpot"),
Algorithm = cms.int32(0),
useBeamSpot = True,
RemoveMuonTracks = False,
RemoveElectronTracks = False,
useSelectedTaus = False,
discriminators = cms.VPSet(
cms.PSet(
discriminator = cms.InputTag('hltHpsPFTauDiscriminationByDecayModeFindingNewDMsReg'),
selectionCut = cms.double(0.5)
)
),
cut = cms.string("pt > 18.0 & abs(eta) < 2.4"),
qualityCuts = cms.PSet(
isolationQualityCuts = cms.PSet(
maxDeltaZ = cms.double(0.2),
maxTrackChi2 = cms.double(100.0),
maxTransverseImpactParameter = cms.double(0.03),
minGammaEt = cms.double(1.5),
minTrackHits = cms.uint32(8),
minTrackPixelHits = cms.uint32(0),
minTrackPt = cms.double(1.0),
minTrackVertexWeight = cms.double(-1.0)
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
qualityCuts = cms.PSet(
isolationQualityCuts = cms.PSet(
maxDeltaZ = cms.double(0.2),
maxTrackChi2 = cms.double(100.0),
maxTransverseImpactParameter = cms.double(0.03),
minGammaEt = cms.double(1.5),
minTrackHits = cms.uint32(8),
minTrackPixelHits = cms.uint32(0),
minTrackPt = cms.double(1.0),
minTrackVertexWeight = cms.double(-1.0)
),
qualityCuts = dict(

update only parts that need a change

leadingTrkOrPFCandOption = cms.string('leadPFCand'),
primaryVertexSrc = cms.InputTag("hltPixelVertices"),
pvFindingAlgo = cms.string('closestInDeltaZ'),
recoverLeadingTrk = cms.bool(False),
signalQualityCuts = cms.PSet(
maxDeltaZ = cms.double(0.4),
maxTrackChi2 = cms.double(100.0),
maxTransverseImpactParameter = cms.double(0.1),
minGammaEt = cms.double(1.0),
minNeutralHadronEt = cms.double(30.0),
minTrackHits = cms.uint32(3),
minTrackPixelHits = cms.uint32(0),
minTrackPt = cms.double(0.5),
minTrackVertexWeight = cms.double(-1.0)
),
vertexTrackFiltering = cms.bool(False),
vxAssocQualityCuts = cms.PSet(
maxTrackChi2 = cms.double(100.0),
maxTransverseImpactParameter = cms.double(0.1),
minGammaEt = cms.double(1.0),
minTrackHits = cms.uint32(3),
minTrackPixelHits = cms.uint32(0),
minTrackPt = cms.double(0.5),
minTrackVertexWeight = cms.double(-1.0)
)
)
)

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


#Add all sums and corrections for deepTauProducer
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauPrimaryVertexProducer)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauSecondaryVertexProducer)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauTransverseImpactParameters)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hltFixedGridRhoFastjetAll)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauBasicDiscriminators)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauBasicDiscriminatorsdR03)
Copy link
Contributor

Choose a reason for hiding this comment

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

is the intention really to insert at the next to last element or to append?

Suggested change
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauPrimaryVertexProducer)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauSecondaryVertexProducer)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauTransverseImpactParameters)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hltFixedGridRhoFastjetAll)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauBasicDiscriminators)
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.hpsPFTauBasicDiscriminatorsdR03)
process.HLTHPSMediumChargedIsoPFTauSequenceReg += (process.hpsPFTauPrimaryVertexProducer + process.hpsPFTauSecondaryVertexProducer + process.hpsPFTauTransverseImpactParameters + process.hltFixedGridRhoFastjetAll + process.hpsPFTauBasicDiscriminators + process.hpsPFTauBasicDiscriminatorsdR03)

would be a bit less verbose

Copy link
Contributor

Choose a reason for hiding this comment

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

The intention was to append, I will make the change


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 = cms.EDProducer("DeepTauId",
taus = cms.InputTag("hltHpsPFTauProducerReg"),
Copy link
Contributor

Choose a reason for hiding this comment

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

is it justifiable to set this from scratch rather than cloning from the offline variant?
I'd expect that cloning would be more maintainable

Copy link
Contributor

Choose a reason for hiding this comment

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

There was no special reason for doing it this way. I am changing this to use a clone

pfcands = cms.InputTag('hltParticleFlowReg'),
vertices = cms.InputTag('hltPixelVertices'),
rho = cms.InputTag('hltFixedGridRhoFastjetAll'),
graph_file = cms.vstring(file_names),
mem_mapped = cms.bool(False),
version = cms.uint32(2),
debug_level = cms.int32(0),
disable_dxy_pca = cms.bool(True),
is_online = cms.bool(True),
pfTauTransverseImpactParameters = cms.InputTag('hpsPFTauTransverseImpactParameters'),
basicTauDiscriminators = cms.untracked.InputTag('hpsPFTauBasicDiscriminators'),
basicTauDiscriminatorsdR03 = cms.untracked.InputTag('hpsPFTauBasicDiscriminatorsdR03'),
Prediscriminants = requireDecayMode.clone(),

VSeWP = cms.vstring(working_points),
VSmuWP = cms.vstring(working_points),
VSjetWP = cms.vstring(working_points)
)

# Add DeepTauProducer
process.HLTHPSMediumChargedIsoPFTauSequenceReg.insert(-1, process.deepTauProducer)

return process
50 changes: 45 additions & 5 deletions RecoTauTag/RecoTau/interface/DeepTauBase.h
Expand Up @@ -19,18 +19,29 @@
#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 "DataFormats/TauReco/interface/PFTauTransverseImpactParameterAssociation.h"
#include "DataFormats/TauReco/interface/PFTauTransverseImpactParameterFwd.h"
#include "DataFormats/TauReco/interface/PFTauTransverseImpactParameter.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

are these include needed?
it looks like PFTauTransverseImpactParameterAssociation and PFTauTransverseImpactParameter are not used in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

#include "DataFormats/TauReco/interface/PFTauTransverseImpactParameterAssociation.h"
This is needed for i.e. this line:

edm::Handle<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::PFTauTransverseImpactParameterRef>>>

The other two includes can actually be removed

Copy link
Contributor

Choose a reason for hiding this comment

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

it's more appropriate to add an include in the file where it's needed.
here it sounds like this include needs to be moved to DeepTauId.cc

#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()(edm::View<reco::BaseTau>::const_reference& tau, bool is_online) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
double operator()(edm::View<reco::BaseTau>::const_reference& tau, bool is_online) const;
double operator()(const reco::BaseTau& tau, bool is_online) const;

do we really need to couple to the collection type?

here and below, it looks like isPFTau is a more appropriate flag compared to is_online.
I accept that in some other parts of the code is_online corresponds to an algorithmic choice relevant for online; the flag can stay there


private:
std::unique_ptr<TF1> fn_;
Expand All @@ -57,9 +68,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 CandidateType = edm::View<reco::Candidate>;
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be CandidateCollection to match the style above ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

using TauRef = edm::Ref<TauCollection>;
using TauRefProd = edm::RefProd<TauCollection>;
using ElectronCollection = pat::ElectronCollection;
Expand All @@ -76,7 +87,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,17 +101,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); };
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
void fill(const edm::Event& evt) { evt.getByToken(disc_token, handle); };
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, 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<CandidateType> 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