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

L2 tau identification with a CNN #35640

Merged
merged 14 commits into from Oct 21, 2021
Merged
4 changes: 4 additions & 0 deletions RecoTauTag/HLTProducers/BuildFile.xml
Expand Up @@ -14,5 +14,9 @@
<use name="DataFormats/HLTReco"/>
<use name="HLTrigger/HLTcore"/>
<use name="RecoTracker/TkTrackingRegions"/>
<use name="CUDADataFormats/SiPixelCluster"/>
<use name="CUDADataFormats/Track"/>
<use name="CUDADataFormats/Vertex"/>
<use name="PhysicsTools/TensorFlow"/>
<use name="root"/>
<flags EDM_PLUGIN="1"/>
87 changes: 87 additions & 0 deletions RecoTauTag/HLTProducers/python/applyL2TauTag.py
@@ -0,0 +1,87 @@
import FWCore.ParameterSet.Config as cms
from HLTrigger.Configuration.customizeHLTforPatatrack import customizeHLTforPatatrackTriplets
from RecoTauTag.HLTProducers.l2TauNNProducer_cfi import *
from RecoTauTag.HLTProducers.l2TauTagFilter_cfi import *

def insertL2TauSequence(process, path, ref_module):
ref_idx = path.index(ref_module)
path.insert(ref_idx + 1, process.hltL2TauTagNNSequence)
path.insert(ref_idx + 2, process.hltL2DoubleTauTagNNFilter)
path.insert(ref_idx + 3, process.HLTGlobalPFTauHPSSequence)


def update(process):
thWp = {
'Tight': 0.180858813224404,
'Medium': 0.12267940863785043,
'Loose': 0.08411243185219064,
}

working_point = "Tight"
graphPath = 'RecoTauTag/TrainingFiles/data/L2TauNNTag/L2TauTag_Run3v1.pb'

normalizationDict = 'RecoTauTag/TrainingFiles/data/L2TauNNTag/NormalizationDict.json'

if 'statusOnGPU' not in process. __dict__:
process = customizeHLTforPatatrackTriplets(process)
process.hltL2TauTagNNProducer = l2TauNNProducer.clone(
debugLevel = 0,
L1Taus = [
cms.PSet(
L1CollectionName = cms.string('DoubleTau'),
L1TauTrigger = cms.InputTag('hltL1sDoubleTauBigOR'),
),
],
hbheInput = "hltHbhereco",
hoInput = "hltHoreco",
ebInput = "hltEcalRecHit:EcalRecHitsEB",
eeInput = "hltEcalRecHit:EcalRecHitsEE",
pataVertices = "hltPixelVerticesSoA",
pataTracks = "hltPixelTracksSoA",
BeamSpot = "hltOnlineBeamSpot",
maxVtx = 100,
fractionSumPt2 = 0.3,
minSumPt2 = 0.,
track_pt_min = 1.,
track_pt_max = 20.,
track_chi2_max = 20.,
graphPath = graphPath,
normalizationDict = normalizationDict
)
process.hltL2DoubleTauTagNNFilter = l2TauTagFilter.clone(
nExpected = 2,
L1TauSrc = 'hltL1sDoubleTauBigOR',
L2Outcomes = 'hltL2TauTagNNProducer:DoubleTau',
DiscrWP = thWp[working_point]
)
# L2 updated Sequence
process.hltL2TauTagNNSequence = cms.Sequence(process.HLTDoCaloSequence + process.hltL1sDoubleTauBigOR + process.hltL2TauTagNNProducer)


# Regional -> Global customization
process.hltHpsPFTauTrackPt1DiscriminatorReg.PFTauProducer = "hltHpsPFTauProducer"
process.hltHpsDoublePFTau35Reg.inputTag = "hltHpsPFTauProducer"
process.hltHpsSelectedPFTausTrackPt1Reg.src = "hltHpsPFTauProducer"
process.hltHpsPFTauMediumAbsoluteChargedIsolationDiscriminatorReg.PFTauProducer = "hltHpsPFTauProducer"
process.hltHpsPFTauMediumAbsoluteChargedIsolationDiscriminatorReg.particleFlowSrc = "hltParticleFlow"
process.hltHpsPFTauMediumRelativeChargedIsolationDiscriminatorReg.PFTauProducer = "hltHpsPFTauProducer"
process.hltHpsPFTauMediumRelativeChargedIsolationDiscriminatorReg.particleFlowSrc = "hltParticleFlow"
process.hltHpsPFTauMediumAbsOrRelChargedIsolationDiscriminatorReg.PFTauProducer = "hltHpsPFTauProducer"
process.hltHpsSelectedPFTausTrackPt1MediumChargedIsolationReg.src = "hltHpsPFTauProducer"

process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.HLTL2TauJetsL1TauSeededSequence)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltDoubleL2Tau26eta2p2)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.HLTL2p5IsoTauL1TauSeededSequence)
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.hltDoubleL2IsoTau26eta2p2 )
process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4.remove(process.HLTRegionalPFTauHPSSequence )

insertL2TauSequence(process, process.HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v4, process.hltPreDoubleMediumChargedIsoPFTauHPS35Trk1eta2p1Reg)


old_diTau_paths = ['HLT_IsoMu24_eta2p1_TightChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_CrossL1_v1', 'HLT_IsoMu24_eta2p1_MediumChargedIsoPFTauHPS35_Trk1_TightID_eta2p1_Reg_CrossL1_v1','HLT_IsoMu24_eta2p1_TightChargedIsoPFTauHPS35_Trk1_TightID_eta2p1_Reg_CrossL1_v1','HLT_IsoMu24_eta2p1_MediumChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_CrossL1_v4','HLT_IsoMu24_eta2p1_MediumChargedIsoPFTauHPS30_Trk1_eta2p1_Reg_CrossL1_v1','HLT_DoubleMediumChargedIsoPFTauHPS30_L1MaxMass_Trk1_eta2p1_Reg_v1','HLT_DoubleTightChargedIsoPFTauHPS35_Trk1_eta2p1_Reg_v1','HLT_DoubleMediumChargedIsoPFTauHPS35_Trk1_TightID_eta2p1_Reg_v1','HLT_DoubleTightChargedIsoPFTauHPS35_Trk1_TightID_eta2p1_Reg_v1','HLT_DoubleMediumChargedIsoPFTauHPS40_Trk1_eta2p1_Reg_v1','HLT_DoubleTightChargedIsoPFTauHPS40_Trk1_eta2p1_Reg_v1','HLT_DoubleMediumChargedIsoPFTauHPS40_Trk1_TightID_eta2p1_Reg_v1','HLT_DoubleTightChargedIsoPFTauHPS40_Trk1_TightID_eta2p1_Reg_v1']
for path in old_diTau_paths:
if path in process.__dict__:
process.schedule.remove(getattr(process, path))


return process
77 changes: 77 additions & 0 deletions RecoTauTag/HLTProducers/src/L2TauTagFilter.cc
@@ -0,0 +1,77 @@
/*
* \class L2TauTagFilter
*
* L2Tau identification using Convolutional NN.
*
* \author Valeria D'Amante, Università di Siena and INFN Pisa
* Konstantin Androsov, EPFL and ETHZ
*/

// user include files
#include "HLTrigger/HLTcore/interface/HLTFilter.h"
#include "FWCore/Framework/interface/ESHandle.h"
azotz marked this conversation as resolved.
Show resolved Hide resolved
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "DataFormats/Common/interface/Handle.h"
azotz marked this conversation as resolved.
Show resolved Hide resolved
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"

class L2TauTagFilter : public HLTFilter {
public:
explicit L2TauTagFilter(const edm::ParameterSet& cfg)
: HLTFilter(cfg),
nExpected_(cfg.getParameter<int>("nExpected")),
l1TauSrc_(cfg.getParameter<edm::InputTag>("L1TauSrc")),
l1TauSrcToken_(consumes<trigger::TriggerFilterObjectWithRefs>(l1TauSrc_)),
l2OutcomesToken_(consumes<std::vector<float>>(cfg.getParameter<edm::InputTag>("L2Outcomes"))),
discrWP_(cfg.getParameter<double>("DiscrWP")) {}
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
makeHLTFilterDescription(desc);
desc.add<int>("nExpected", 2)->setComment("number of expected taus per event");
desc.add<edm::InputTag>("L1TauSrc", edm::InputTag(""))
->setComment("Which trigger should the L1 Taus collection pass");
desc.add<edm::InputTag>("L2Outcomes", edm::InputTag(""))->setComment("L2 CNN outcomes");
desc.add<double>("DiscrWP", 0.1227)->setComment("value of discriminator threshold");
descriptions.addWithDefaultLabel(desc);
}

bool hltFilter(edm::Event& event,
const edm::EventSetup& eventsetup,
trigger::TriggerFilterObjectWithRefs& filterproduct) const override {
if (saveTags())
filterproduct.addCollectionTag(l1TauSrc_);

int nTauPassed = 0;

l1t::TauVectorRef l1Taus;
auto const& l1TriggeredTaus = event.get(l1TauSrcToken_);
l1TriggeredTaus.getObjects(trigger::TriggerL1Tau, l1Taus);

auto const& L2Outcomes = event.get(l2OutcomesToken_);
if (L2Outcomes.size() != l1Taus.size()) {
throw cms::Exception("Inconsistent Data", "L2TauTagFilter::hltFilter") << "CNN output size != L1 taus size \n";
}
for (size_t l1_idx = 0; l1_idx < l1Taus.size(); l1_idx++) {
if (L2Outcomes[l1_idx] >= discrWP_) {
filterproduct.addObject(nTauPassed, l1Taus[l1_idx]);
nTauPassed++;
}
}

return nTauPassed >= nExpected_;
}

private:
const int nExpected_;
const edm::InputTag l1TauSrc_;
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> l1TauSrcToken_;
const edm::EDGetTokenT<std::vector<float>> l2OutcomesToken_;
const double discrWP_;
};

//define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(L2TauTagFilter);