forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from violatingcp/L1PFTau_10_5_X_v4
Added NN Tau
- Loading branch information
Showing
14 changed files
with
405 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef DataFormats_Phase2L1ParticleFlow_PFTau_h | ||
#define DataFormats_Phase2L1ParticleFlow_PFTau_h | ||
|
||
#include <algorithm> | ||
#include <vector> | ||
#include "DataFormats/L1Trigger/interface/L1Candidate.h" | ||
|
||
namespace l1t | ||
{ | ||
|
||
class PFTau : public L1Candidate { | ||
public: | ||
PFTau() {} | ||
enum { unidentified=0, oneprong=1, oneprongpi0=2, threeprong=3}; | ||
PFTau(const LorentzVector & p, float iso=-1, float fulliso=-1, int id=0,int hwpt=0, int hweta=0, int hwphi=0) : | ||
PFTau(PolarLorentzVector(p), iso, id, hwpt, hweta, hwphi) {} | ||
PFTau(const PolarLorentzVector & p, float iso=-1, float fulliso=-1,int id=0, int hwpt=0, int hweta=0, int hwphi=0) ; | ||
float chargedIso() const { return iso_; } | ||
float fullIso() const { return fullIso_; } | ||
int id() const { return id_; } | ||
bool passLooseNN() const { return iso_*(0.1+0.2*(min(pt(),100.)))*1./20.1 > 0.05;} | ||
bool passLoosePF() const { return fullIso_ < 10.0;} | ||
bool passTightNN() const { return iso_*(0.1+0.2*(min(pt(),100.)))*1./20.1 > 0.25;} | ||
bool passTightPF() const { return fullIso_ < 5.0;} | ||
|
||
private: | ||
float iso_; | ||
float fullIso_; | ||
int id_; | ||
}; | ||
|
||
typedef std::vector<l1t::PFTau> PFTauCollection; | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "DataFormats/Phase2L1ParticleFlow/interface/PFTau.h" | ||
|
||
l1t::PFTau::PFTau(const PolarLorentzVector & p, float iso, float fulliso, int id, int hwpt, int hweta, int hwphi) : | ||
L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(0)), | ||
iso_(iso), | ||
fullIso_(fulliso), | ||
id_(id) { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef L1TRIGGER_PHASE2L1TAU_L1NNTAU_H | ||
#define L1TRIGGER_PHASE2L1TAU_L1NNTAU_H | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <TLorentzVector.h> | ||
|
||
|
||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/stream/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
#include "DataFormats/Phase2L1ParticleFlow/interface/PFTau.h" | ||
#include "DataFormats/Phase2L1ParticleFlow/interface/PFCandidate.h" | ||
#include "L1Trigger/Phase2L1Taus/interface/TauNNId.h" | ||
|
||
using namespace l1t; | ||
|
||
class L1NNTauProducer : public edm::stream::EDProducer<> { | ||
public: | ||
explicit L1NNTauProducer(const edm::ParameterSet&); | ||
~L1NNTauProducer(); | ||
|
||
private: | ||
TauNNId *fTauNNId; | ||
void addTau(l1t::PFCandidate &iCand,const l1t::PFCandidateCollection &iParts, std::unique_ptr<PFTauCollection> &outputTaus); | ||
float deltaR(auto iPart1, auto iPart2); | ||
virtual void produce( edm::Event& iEvent, const edm::EventSetup& iSetup ) override; | ||
|
||
double fSeedPt; | ||
double fConeSize; | ||
double fTauSize; | ||
int fMaxTaus; | ||
int fNParticles; | ||
edm::EDGetTokenT< vector<l1t::PFCandidate> > fL1PFToken; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef L1TRIGGER_PHASE2L1TAUS_TAUNNID_H | ||
#define L1TRIGGER_PHASE2L1TAUS_TAuNNID_H | ||
|
||
#include <string> | ||
#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" | ||
#include "DataFormats/L1Trigger/interface/L1PFTau.h" | ||
#include "DataFormats/Phase2L1ParticleFlow/interface/PFCandidate.h" | ||
|
||
class TauNNId { | ||
public: | ||
TauNNId(); | ||
~TauNNId(); | ||
|
||
void initialize(std::string iName, const std::string iWeightFile,int iNParticles); | ||
void SetNNVectorVar(); | ||
float EvaluateNN(); | ||
float compute(l1t::PFCandidate &iSeed,l1t::PFCandidateCollection &iParts); | ||
|
||
std::string fInput; | ||
int fNParticles; | ||
float *fPt; | ||
float *fEta; | ||
float *fPhi; | ||
float *fId; | ||
|
||
private: | ||
tensorflow::Session* session; | ||
tensorflow::GraphDef* graphDef; | ||
std::vector<float> NNvectorVar_; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "L1Trigger/Phase2L1Taus/interface/L1NNTauProducer.hh" | ||
|
||
L1NNTauProducer::L1NNTauProducer(const edm::ParameterSet& cfg) : | ||
fSeedPt( cfg.getParameter<double>("seedpt")), | ||
fConeSize( cfg.getParameter<double>("conesize")), | ||
fTauSize( cfg.getParameter<double>("tausize")), | ||
fMaxTaus ( cfg.getParameter<int> ("maxtaus")), | ||
fNParticles ( cfg.getParameter<int> ("nparticles")), | ||
fL1PFToken( consumes< vector<l1t::PFCandidate> >(cfg.getParameter<edm::InputTag>("L1PFObjects"))) { | ||
std::string lNNFile = cfg.getParameter<std::string>("NNFileName");//,"L1Trigger/Phase2L1Taus/data/tau_3layer.pb"); | ||
fTauNNId = new TauNNId(); | ||
if(lNNFile.find("v0") == std::string::npos) fTauNNId->initialize("input_1:0",lNNFile,fNParticles); | ||
if(lNNFile.find("v0") != std::string::npos) fTauNNId->initialize("dense_1_input:0",lNNFile,fNParticles); | ||
|
||
produces< l1t::PFTauCollection >( "L1PFTausNN" ); | ||
} | ||
void L1NNTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
edm::Handle< l1t::PFCandidateCollection > l1PFCandidates; | ||
iEvent.getByToken( fL1PFToken, l1PFCandidates); | ||
|
||
l1t::PFCandidateCollection pfChargedHadrons; | ||
l1t::PFCandidateCollection pfChargedHadrons_sort; | ||
l1t::PFCandidateCollection pfChargedHadrons_seeds; | ||
//for(auto l1PFCand : *l1PFCandidates) if((l1PFCand.id() == l1t::PFCandidate::ChargedHadron || l1PFCand.id() == l1t::PFCandidate::Electron || l1PFCand.id() == l1t::PFCandidate::Photon) && fabs(l1PFCand.eta()) < 2.5) pfChargedHadrons_sort.push_back(l1PFCand); | ||
for(auto l1PFCand : *l1PFCandidates) if((l1PFCand.id() == l1t::PFCandidate::ChargedHadron || l1PFCand.id() == l1t::PFCandidate::Electron) && fabs(l1PFCand.eta()) < 2.5) pfChargedHadrons_sort.push_back(l1PFCand); | ||
std::sort(pfChargedHadrons_sort.begin(), pfChargedHadrons_sort.end(), [](l1t::PFCandidate i,l1t::PFCandidate j){return(i.pt() > j.pt());}); | ||
auto lTaus = std::make_unique<l1t::PFTauCollection>(); | ||
if(pfChargedHadrons_sort.size() == 0) { | ||
if(lTaus->size() == 0) { | ||
PFTau dummy; | ||
lTaus->push_back(dummy); | ||
} | ||
iEvent.put( std::move(lTaus) , "L1PFTausNN" ); | ||
return; | ||
} | ||
pfChargedHadrons_seeds.push_back(pfChargedHadrons_sort[0]); | ||
for(unsigned int i0 = 1; i0 < pfChargedHadrons_sort.size(); i0++) { | ||
bool pMatch = false; | ||
for(unsigned int i1 = 0; i1 < pfChargedHadrons_seeds.size(); i1++) { | ||
if(deltaR(pfChargedHadrons_seeds[i1],pfChargedHadrons_sort[i0]) < 0.4) pMatch = true; | ||
} | ||
if(pMatch) continue; | ||
pfChargedHadrons_seeds.push_back(pfChargedHadrons_sort[i0]); | ||
if(int(pfChargedHadrons_seeds.size()) > fMaxTaus-1) break; | ||
} | ||
for(unsigned int i0 = 0; i0 < pfChargedHadrons_seeds.size(); i0++ ) { | ||
addTau(pfChargedHadrons_seeds[i0],(*l1PFCandidates),lTaus); | ||
} | ||
if(lTaus->size() == 0) { | ||
PFTau dummy; | ||
lTaus->push_back(dummy); | ||
} | ||
std::sort(lTaus->begin(), lTaus->end(), [](l1t::PFTau i,l1t::PFTau j){return(i.pt() > j.pt());}); | ||
iEvent.put( std::move(lTaus) , "L1PFTausNN" ); | ||
} | ||
|
||
// create taus based on grid structure | ||
void L1NNTauProducer::addTau(l1t::PFCandidate &iCand,const l1t::PFCandidateCollection &iParts, std::unique_ptr<l1t::PFTauCollection> &outputTaus){ | ||
l1t::PFCandidateCollection pfTauCands; | ||
TLorentzVector lTot; lTot.SetPtEtaPhiM(0,0,0,0); | ||
TLorentzVector lCand; lCand.SetPtEtaPhiM(0,0,0,0); | ||
int lId = 0; | ||
for(auto l1PFCand : iParts) { | ||
if(deltaR(iCand,l1PFCand) > fConeSize) continue; | ||
TLorentzVector pVec; pVec.SetPtEtaPhiM(l1PFCand.pt(),l1PFCand.eta(),l1PFCand.phi(),0); | ||
lTot += pVec; | ||
if(deltaR(iCand,l1PFCand) < fTauSize && (l1PFCand.id() == l1t::PFCandidate::Electron || l1PFCand.id() == l1t::PFCandidate::ChargedHadron || l1PFCand.id() == l1t::PFCandidate::Photon) ) { | ||
lId++; | ||
if( l1PFCand.id() == l1t::PFCandidate::Electron || l1PFCand.id() == l1t::PFCandidate::ChargedHadron ) lCand += pVec; | ||
} | ||
pfTauCands.push_back(l1PFCand); | ||
} | ||
if(lTot.Pt() < fSeedPt) return; | ||
std::sort(pfTauCands.begin(), pfTauCands.end(), [](l1t::PFCandidate i,l1t::PFCandidate j){return(i.pt() > j.pt());}); | ||
float NN = fTauNNId->compute(iCand,pfTauCands); | ||
math::PtEtaPhiMLorentzVector tempP4(lCand.Pt(),lCand.Eta(),lCand.Phi(),lCand.M()); | ||
l1t::PFTau l1PFTau(tempP4,NN,0,lId); | ||
outputTaus->push_back(l1PFTau); | ||
} | ||
float L1NNTauProducer::deltaR(auto iPart1, auto iPart2){ | ||
float delta_r = 20; | ||
float pDPhi = fabs(iPart1.phi() - iPart2.phi()); | ||
if(pDPhi > 2.*TMath::Pi()-pDPhi) pDPhi = 2.*TMath::Pi()-pDPhi; | ||
delta_r = sqrt((iPart1.eta() - iPart2.eta())*(iPart1.eta() - iPart2.eta()) + pDPhi*pDPhi); | ||
return delta_r; | ||
} | ||
L1NNTauProducer::~L1NNTauProducer(){} | ||
|
||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(L1NNTauProducer); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
L1NNTauProducer = cms.EDProducer("L1NNTauProducer", | ||
seedpt = cms.double(20), | ||
conesize = cms.double(0.4), | ||
tausize = cms.double(0.1), | ||
maxtaus = cms.int32(5), | ||
nparticles = cms.int32(10), | ||
L1PFObjects = cms.InputTag("L1PFProducer","l1pfCandidates"), | ||
NNFileName = cms.string("L1Trigger/Phase2L1Taus/data/tau_3layer.pb") | ||
) | ||
|
||
|
||
L1NNTauProducerPuppi = cms.EDProducer("L1NNTauProducer", | ||
seedpt = cms.double(20), | ||
conesize = cms.double(0.4), | ||
tausize = cms.double(0.1), | ||
maxtaus = cms.int32(5), | ||
nparticles = cms.int32(10), | ||
L1PFObjects = cms.InputTag("L1PFProducer","l1pfCandidates"), | ||
NNFileName = cms.string("L1Trigger/Phase2L1Taus/data/tau_3layer_puppi.pb") | ||
) |
Oops, something went wrong.