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

Updates towards enabling deepTauID at HLT #35619

Merged
merged 5 commits into from Oct 18, 2021
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
2 changes: 2 additions & 0 deletions RecoTauTag/HLTProducers/interface/L1THLTTauMatching.h
Expand Up @@ -28,5 +28,7 @@ class L1THLTTauMatching : public edm::global::EDProducer<> {
const edm::EDGetTokenT<reco::PFTauCollection> jetSrc;
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tauTrigger;
const double mEt_Min;
const bool reduceTauContent;
const bool keepOriginalVertex;
};
#endif
140 changes: 115 additions & 25 deletions RecoTauTag/HLTProducers/python/deepTauAtHLT.py
Expand Up @@ -12,12 +12,12 @@

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

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

process.hltFixedGridRhoFastjetAll = cms.EDProducer( "FixedGridRhoProducerFastjet",
process.hltFixedGridRhoFastjetAllTau = cms.EDProducer( "FixedGridRhoProducerFastjet",
gridSpacing = cms.double( 0.55 ),
maxRapidity = cms.double( 5.0 ),
pfCandidatesTag = cms.InputTag( "hltParticleFlowReg" )
Expand All @@ -35,16 +35,16 @@ def update(process):
)

## Cut based isolations dR=0.5
process.hpsPFTauBasicDiscriminators = pfRecoTauDiscriminationByIsolation.clone(
PFTauProducer = 'hltHpsPFTauProducerReg',
Prediscriminants = requireDecayMode.clone(),
process.hpsPFTauBasicDiscriminatorsForDeepTau = pfRecoTauDiscriminationByIsolation.clone(
PFTauProducer = 'hltHpsL1JetsHLTForDeepTauInput',
Prediscriminants = cms.PSet( BooleanOperator = cms.string( "and" ) ),
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),
deltaBetaFactor = "%0.4f"%(_ak4dBetaCorrection),
qualityCuts = dict(isolationQualityCuts = dict(minTrackHits = 3, minGammaEt = 1.0, minTrackPt = 0.5)),
IDdefinitions = [
cms.PSet(
Expand Down Expand Up @@ -80,11 +80,11 @@ def update(process):
)

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

process.hpsPFTauPrimaryVertexProducer = PFTauPrimaryVertexProducer.clone(
process.hpsPFTauPrimaryVertexProducerForDeepTau = PFTauPrimaryVertexProducer.clone(
PFTauTag = "hltHpsPFTauProducerReg",
ElectronTag = "hltEgammaCandidates",
MuonTag = "hltMuonsReg",
Expand All @@ -100,41 +100,131 @@ def update(process):
qualityCuts = PFTauQualityCuts
)

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

chargedIsolationQualityCuts = PFTauQualityCuts.clone(
isolationQualityCuts = cms.PSet(
maxDeltaZ = cms.double( 0.2 ),
minTrackPt = cms.double( 0.5 ),
minGammaEt = cms.double( 0.5 ),
minTrackHits = cms.uint32( 3 ),
minTrackPixelHits = cms.uint32( 0 ),
maxTrackChi2 = cms.double( 100.0 ),
maxTransverseImpactParameter = cms.double( 0.1 ),
useTracksInsteadOfPFHadrons = cms.bool( False )
),
primaryVertexSrc = "hltPixelVertices",
signalQualityCuts = cms.PSet(
maxDeltaZ = cms.double( 0.2 ),
minTrackPt = cms.double( 0.0 ),
minGammaEt = cms.double( 0.5 ),
minTrackHits = cms.uint32( 3 ),
minTrackPixelHits = cms.uint32( 0 ),
maxTrackChi2 = cms.double( 1000.0 ),
maxTransverseImpactParameter = cms.double( 0.2 ),
useTracksInsteadOfPFHadrons = cms.bool( False ),
minNeutralHadronEt = cms.double( 1.0 )
),
vxAssocQualityCuts = cms.PSet(
minTrackPt = cms.double( 0.0 ),
minGammaEt = cms.double( 0.5 ),
minTrackHits = cms.uint32( 3 ),
minTrackPixelHits = cms.uint32( 0 ),
maxTrackChi2 = cms.double( 1000.0 ),
maxTransverseImpactParameter = cms.double( 0.2 ),
useTracksInsteadOfPFHadrons = cms.bool( False )
),
)

process.hltHpsL1JetsHLTForDeepTauInput = process.hltHpsL1JetsHLTDoublePFTauTrackPt1MediumChargedIsolationMatchReg.clone(
mbluj marked this conversation as resolved.
Show resolved Hide resolved
L1TauTrigger = "hltL1sTauVeryBigOR",
JetSrc = "hltHpsPFTauProducerReg",
ReduceTauContent = False,
KeepOriginalVertex = 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',
]
'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',
]

def getLinExpression(x1, x2, y1, y2):
return "(((({3}-{2})/({1}-{0}))*(pt-{0}))+{2})".format(x1, x2, y1, y2)

working_points = ["0.", "0.92"]
val1, val2 = ("0.49948551", "0.125")
working_points = ["{0}*(pt < 35)+".format(val1)+getLinExpression("35", "300", val1, val2)+ "*(35 <= pt && pt < 300) + {0}*(pt >= 300)".format(val2)]

process.deepTauProducer = DeepTau.clone(
taus = 'hltHpsPFTauProducerReg',
taus = 'hltHpsL1JetsHLTForDeepTauInput',
pfcands = 'hltParticleFlowReg',
vertices = 'hltPixelVertices',
rho = 'hltFixedGridRhoFastjetAll',
rho = 'hltFixedGridRhoFastjetAllTau',
graph_file = file_names,
disable_dxy_pca = cms.bool(True),
is_online = cms.bool(True),
basicTauDiscriminators = 'hpsPFTauBasicDiscriminators',
basicTauDiscriminatorsdR03 = 'hpsPFTauBasicDiscriminatorsdR03',
Prediscriminants = requireDecayMode.clone(),
disable_dxy_pca = True,
is_online = True,
pfTauTransverseImpactParameters = 'hpsPFTauTransverseImpactParametersForDeepTau',
basicTauDiscriminators = 'hpsPFTauBasicDiscriminatorsForDeepTau',
basicTauDiscriminatorsdR03 = 'hpsPFTauBasicDiscriminatorsdR03ForDeepTau',
Prediscriminants = cms.PSet( BooleanOperator = cms.string( "and" ) ),
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)
process.HLTHPSDeepTau35IsoPFTauSequenceReg = cms.Sequence(process.hpsPFTauPrimaryVertexProducerForDeepTau + process.hpsPFTauSecondaryVertexProducerForDeepTau + process.hpsPFTauTransverseImpactParametersForDeepTau + process.hltFixedGridRhoFastjetAllTau + process.hltHpsL1JetsHLTForDeepTauInput + process.hpsPFTauBasicDiscriminatorsForDeepTau + process.hpsPFTauBasicDiscriminatorsdR03ForDeepTau + process.deepTauProducer)

process.hltHpsSelectedPFTausTrackPt1DeepTau35IsolationReg = process.hltHpsSelectedPFTausTrackPt1MediumChargedIsolationReg.clone(
src = "hltHpsL1JetsHLTForDeepTauInput",
discriminators = [
# cms.PSet(
# discriminator = cms.InputTag( "hltHpsPFTauTrackPt1DiscriminatorReg" ),
# selectionCut = cms.double( 0.5 )
# )
],
discriminatorContainers = [
cms.PSet(
discriminator = cms.InputTag( "deepTauProducer", "VSjet" ),
rawValues = cms.vstring(),
selectionCuts = cms.vdouble(),
workingPoints = cms.vstring(working_points),
)
]
)

process.hltHpsDoublePFTau35TrackPt1DeepTau35IsolationReg = process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationReg.clone(
inputTag = "hltHpsSelectedPFTausTrackPt1DeepTau35IsolationReg",
)

process.hltHpsL1JetsHLTDoublePFTauTrackPt1DeepTauMatchReg = process.hltHpsL1JetsHLTDoublePFTauTrackPt1MediumChargedIsolationMatchReg.clone(
JetSrc = "hltHpsSelectedPFTausTrackPt1DeepTau35IsolationReg",
)

process.hltHpsDoublePFTau35TrackPt1DeepTauL1HLTMatchedReg = process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationL1HLTMatchedReg.clone(
inputTag = "hltHpsL1JetsHLTDoublePFTauTrackPt1DeepTauMatchReg",
)

process.hltHpsDoublePFTau35TrackPt1DeepTau35IsolationDz02Reg = process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationDz02Reg.clone(
JetSrc = "hltHpsL1JetsHLTDoublePFTauTrackPt1DeepTauMatchReg"
)

process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.HLTHPSMediumChargedIsoPFTauSequenceReg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltHpsSelectedPFTausTrackPt1MediumChargedIsolationReg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationReg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltHpsL1JetsHLTDoublePFTauTrackPt1MediumChargedIsolationMatchReg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationL1HLTMatchedReg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltHpsDoublePFTau35TrackPt1MediumChargedIsolationDz02Reg)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.HLTEndSequence)

process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4 += (process.HLTHPSDeepTau35IsoPFTauSequenceReg + process.hltHpsSelectedPFTausTrackPt1DeepTau35IsolationReg + process.hltHpsDoublePFTau35TrackPt1DeepTau35IsolationReg + process.hltHpsL1JetsHLTDoublePFTauTrackPt1DeepTauMatchReg + process.hltHpsDoublePFTau35TrackPt1DeepTauL1HLTMatchedReg + process.hltHpsDoublePFTau35TrackPt1DeepTau35IsolationDz02Reg + process.HLTEndSequence)

return process
25 changes: 18 additions & 7 deletions RecoTauTag/HLTProducers/src/L1THLTTauMatching.cc
Expand Up @@ -3,6 +3,7 @@
#include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "DataFormats/TauReco/interface/PFTau.h"
#include "DataFormats/Common/interface/RefVector.h"

//
// class decleration
Expand All @@ -15,7 +16,9 @@ using namespace trigger;
L1THLTTauMatching::L1THLTTauMatching(const edm::ParameterSet& iConfig)
: jetSrc(consumes<PFTauCollection>(iConfig.getParameter<InputTag>("JetSrc"))),
tauTrigger(consumes<trigger::TriggerFilterObjectWithRefs>(iConfig.getParameter<InputTag>("L1TauTrigger"))),
mEt_Min(iConfig.getParameter<double>("EtMin")) {
mEt_Min(iConfig.getParameter<double>("EtMin")),
reduceTauContent(iConfig.getParameter<bool>("ReduceTauContent")),
keepOriginalVertex(iConfig.getParameter<bool>("KeepOriginalVertex")) {
produces<PFTauCollection>();
}
L1THLTTauMatching::~L1THLTTauMatching() {}
Expand Down Expand Up @@ -47,9 +50,16 @@ void L1THLTTauMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const ed
if (myJet.leadChargedHadrCand().isNonnull()) {
a = myJet.leadChargedHadrCand()->vertex();
}
PFTau myPFTau(std::numeric_limits<int>::quiet_NaN(), myJet.p4(), a);
if (myJet.pt() > mEt_Min) {
tauL2jets->push_back(myPFTau);

auto myPFTau =
reduceTauContent ? PFTau(std::numeric_limits<int>::quiet_NaN(), myJet.p4(), myJet.vertex()) : PFTau(myJet);

mbluj marked this conversation as resolved.
Show resolved Hide resolved
if (!keepOriginalVertex) {
myPFTau.setVertex(a);
}

if (myPFTau.pt() > mEt_Min) {
tauL2jets->push_back(myJet);
}
break;
}
Expand All @@ -66,8 +76,9 @@ void L1THLTTauMatching::fillDescriptions(edm::ConfigurationDescriptions& descrip
desc.add<edm::InputTag>("JetSrc", edm::InputTag("hltSelectedPFTausTrackPt1MediumIsolationReg"))
->setComment("Input collection of PFTaus");
desc.add<double>("EtMin", 0.0)->setComment("Minimal pT of PFTau to match");
descriptions.setComment(
"This module produces collection of PFTaus matched to L1 Taus / Jets passing a HLT filter (Only p4 and vertex of "
"returned PFTaus are set).");
desc.add<bool>("ReduceTauContent", true)->setComment("Should produce taus with reduced content (Only p4 and vertex)");
desc.add<bool>("KeepOriginalVertex", false)
->setComment("Should use original vertex instead of setting the vertex to that of the leading charged hadron");
descriptions.setComment("This module produces collection of PFTaus matched to L1 Taus / Jets passing a HLT filter.");
descriptions.add("L1THLTTauMatching", desc);
}
9 changes: 9 additions & 0 deletions RecoTauTag/RecoTau/plugins/DeepTauId.cc
Expand Up @@ -1532,6 +1532,15 @@ class DeepTauId : public deep_tau::DeepTauBase {
<< "invalid prediction = " << pred << " for tau_index = " << tau_index << ", pred_index = " << k;
predictions.matrix<float>()(tau_index, k) = pred;
}
} else {
// This else statement was added as a part of the DeepTau@HLT development. It does not affect the current state
// of offline DeepTauId code as there the preselection is not used (it was added in the DeepTau@HLT). It returns
// default values for deepTau score if the preselection failed. Before this statement the values given for this tau
// were random. k == 2 corresponds to the tau score and all other k values to e, mu and jets. By defining in this way
// the final score is -1.
for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
predictions.matrix<float>()(tau_index, k) = (k == 2) ? -1.f : 2.f;
}
mbluj marked this conversation as resolved.
Show resolved Hide resolved
}
}
return predictions;
Expand Down
20 changes: 19 additions & 1 deletion RecoTauTag/RecoTau/plugins/PFTauSelectorDefinition.h
Expand Up @@ -126,6 +126,10 @@ struct PFTauSelectorDefinition {
throw cms::Exception("Configuration")
<< "PFTauSelector: Requested working point '" << disc.rawLabels[i] << "' not found!\n";
}
} else if (psetsFromProvenance.exists("VSjetWP")) {
// This else statement was added in the update of the HLT paths to use DeepTauId instead of charged isolation. Because the DeepTauId module is shared
// with offline and its psetsFromProvenance do not contain any of the above but only VSxWP, this selector would automatically go to the else statement
// that follows this one and fail. It is left empty because at HLT the raw values are not used and no action is needed here.
} else
throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID list found in provenace config!\n";
// find working point indices
Expand Down Expand Up @@ -157,8 +161,22 @@ struct PFTauSelectorDefinition {
throw cms::Exception("Configuration")
<< "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
}
} else if (psetsFromProvenance.exists("VSjetWP")) {
auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("VSjetWP");
for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
bool found = false;
for (size_t j = 0; j < idlist.size(); ++j) {
if (disc.wpLabels[i] == idlist[j]) {
found = true;
disc.wpCuts[i] = j;
}
}
if (!found)
throw cms::Exception("Configuration")
<< "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
}
} else
throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID list found in provenace config!\n";
throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID WP list found in provenace config!\n";
}
}

Expand Down
9 changes: 7 additions & 2 deletions RecoTauTag/RecoTau/src/DeepTauBase.cc
Expand Up @@ -30,7 +30,11 @@ namespace deep_tau {
static const int n_params = 3;
static const auto handler = [](int, Bool_t, const char*, const char*) -> void {};

const std::string fn_str = prefix + cut_str + "}";
std::string fn_str = prefix;
if (cut_str.find("return") == std::string::npos)
fn_str += " return " + cut_str + ";}";
else
fn_str += cut_str + "}";
auto old_handler = SetErrorHandler(handler);
fn_ = std::make_unique<TF1>("fn_", fn_str.c_str(), 0, 1, n_params);
SetErrorHandler(old_handler);
Expand All @@ -40,8 +44,9 @@ namespace deep_tau {
}

double TauWPThreshold::operator()(const reco::BaseTau& tau, bool isPFTau) const {
if (!fn_)
if (!fn_) {
return value_;
}

if (isPFTau)
fn_->SetParameter(0, dynamic_cast<const reco::PFTau&>(tau).decayMode());
Expand Down