Skip to content

Commit

Permalink
Merge pull request cms-sw#93 from mbluj/CMSSW_10_3_X_recoOnMiniAOD_3
Browse files Browse the repository at this point in the history
Update anti-e tau discriminant
  • Loading branch information
mbluj authored Oct 16, 2018
2 parents 1f32af3 + f3d2173 commit 48d50d0
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 110 deletions.
12 changes: 7 additions & 5 deletions RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ class AntiElectronIDMVA6

// this function can be called for all categories
double MVAValue(const reco::PFTau& thePFTau,
const reco::GsfElectron& theGsfEle, bool usePhiAtEcalEntranceExtrapolation);
const reco::GsfElectron& theGsfEle);
// this function can be called for category 1 only !!
double MVAValue(const reco::PFTau& thePFTau, bool usePhiAtEcalEntranceExtrapolation);
double MVAValue(const reco::PFTau& thePFTau);

// this function can be called for all categories
double MVAValue(const pat::Tau& theTau,
const pat::Electron& theEle, bool usePhiAtEcalEntranceExtrapolation);
const pat::Electron& theEle);
// this function can be called for category 1 only !!
double MVAValue(const pat::Tau& theTau, bool usePhiAtEcalEntranceExtrapolation);
double MVAValue(const pat::Tau& theTau);
// track extrapolation to ECAL entrance (used to re-calculate varibales that might not be available on miniAOD)
bool atECalEntrance(const reco::Candidate* part, math::XYZPoint &pos);

Expand All @@ -153,7 +153,9 @@ class AntiElectronIDMVA6
std::string mvaName_NoEleMatch_wGwoGSF_EC_;
std::string mvaName_woGwGSF_EC_;
std::string mvaName_wGwGSF_EC_;


bool usePhiAtEcalEntranceExtrapolation_;

Float_t* Var_NoEleMatch_woGwoGSF_Barrel_;
Float_t* Var_NoEleMatch_wGwoGSF_Barrel_;
Float_t* Var_woGwGSF_Barrel_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PATTauDiscriminationAgainstElectronMVA6 : public PATTauDiscriminationProdu
{
mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);

usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter<bool>("usePhiAtEcalEntranceExtrapolation");
srcElectrons = cfg.getParameter<edm::InputTag>("srcElectrons");
electronToken = consumes<pat::ElectronCollection>(srcElectrons);
verbosity_ = ( cfg.exists("verbosity") ) ?
Expand Down Expand Up @@ -61,7 +60,6 @@ class PATTauDiscriminationAgainstElectronMVA6 : public PATTauDiscriminationProdu
edm::Handle<TauCollection> taus_;

std::unique_ptr<PATTauDiscriminator> category_output_;
bool usePhiAtEcalEntranceExtrapolation_;

int verbosity_;
};
Expand Down Expand Up @@ -89,22 +87,21 @@ double PATTauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTa
if( (*theTauRef).leadChargedHadrCand().isNonnull()) {
int numSignalPFGammaCandsInSigCone = 0;
const reco::CandidatePtrVector signalGammaCands = theTauRef->signalGammaCands();
for( reco::CandidatePtrVector::const_iterator gamma = signalGammaCands.begin(); gamma != signalGammaCands.end(); ++gamma ){
double dR = deltaR((*gamma)->p4(), theTauRef->leadChargedHadrCand()->p4());
for ( const auto & gamma : signalGammaCands ) {
double dR = deltaR(gamma->p4(), theTauRef->leadChargedHadrCand()->p4());
double signalrad = std::max(0.05, std::min(0.10, 3.0/std::max(1.0, theTauRef->pt())));
// gammas inside the tau signal cone
if (dR < signalrad) {
numSignalPFGammaCandsInSigCone += 1;
}
}
// loop over the electrons
for( unsigned int ie = 0; ie < Electrons->size(); ++ie ){
const pat::Electron& theElectron = Electrons->at(ie);
for ( const auto & theElectron : *Electrons ) {
if ( theElectron.pt() > 10. ) { // CV: only take electrons above some minimal energy/Pt into account...
double deltaREleTau = deltaR(theElectron.p4(), theTauRef->p4());
deltaRDummy = deltaREleTau;
if( deltaREleTau < 0.3 ){
double mva_match = mva_->MVAValue(*theTauRef, theElectron, usePhiAtEcalEntranceExtrapolation_);
double mva_match = mva_->MVAValue(*theTauRef, theElectron);
bool hasGsfTrack = false;
pat::PackedCandidate const* packedLeadTauCand = dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
if( abs(packedLeadTauCand->pdgId()) == 11 )
Expand Down Expand Up @@ -142,7 +139,7 @@ double PATTauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTa
} // end of loop over electrons

if ( !isGsfElectronMatched ) {
mvaValue = mva_->MVAValue(*theTauRef, usePhiAtEcalEntranceExtrapolation_);
mvaValue = mva_->MVAValue(*theTauRef);
bool hasGsfTrack = false;
pat::PackedCandidate const* packedLeadTauCand = dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
if( abs(packedLeadTauCand->pdgId()) == 11 ) hasGsfTrack = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ class PFRecoTauDiscriminationAgainstElectronMVA6 : public PFTauDiscriminationPro
public:
explicit PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet& cfg)
: PFTauDiscriminationProducerBase(cfg),
mva_(nullptr),
mva_(),
category_output_()
{
mva_ = new AntiElectronIDMVA6(cfg);
mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);

usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter<bool>("usePhiAtEcalEntranceExtrapolation");
srcGsfElectrons_ = cfg.getParameter<edm::InputTag>("srcGsfElectrons");
GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);

Expand All @@ -51,26 +50,20 @@ class PFRecoTauDiscriminationAgainstElectronMVA6 : public PFTauDiscriminationPro

void endEvent(edm::Event&) override;

~PFRecoTauDiscriminationAgainstElectronMVA6() override
{
delete mva_;
}
~PFRecoTauDiscriminationAgainstElectronMVA6() override {}

private:
bool isInEcalCrack(double) const;

std::string moduleLabel_;

AntiElectronIDMVA6* mva_;
float* mvaInput_;
std::unique_ptr<AntiElectronIDMVA6> mva_;

edm::InputTag srcGsfElectrons_;
edm::EDGetTokenT<reco::GsfElectronCollection> GsfElectrons_token;
edm::Handle<reco::GsfElectronCollection> gsfElectrons_;
edm::Handle<TauCollection> taus_;

std::unique_ptr<PFTauDiscriminator> category_output_;
bool usePhiAtEcalEntranceExtrapolation_;

int verbosity_;
};
Expand Down Expand Up @@ -127,10 +120,9 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef&
int numSignalGammaCandsInSigCone = 0;
const std::vector<reco::CandidatePtr>& signalGammaCands = thePFTauRef->signalGammaCands();

for ( std::vector<reco::CandidatePtr>::const_iterator pfGamma = signalGammaCands.begin();
pfGamma != signalGammaCands.end(); ++pfGamma ) {
for ( const auto & pfGamma : signalGammaCands ) {

double dR = deltaR((*pfGamma)->p4(), thePFTauRef->leadChargedHadrCand()->p4());
double dR = deltaR(pfGamma->p4(), thePFTauRef->leadChargedHadrCand()->p4());
double signalrad = std::max(0.05, std::min(0.10, 3.0/std::max(1.0, thePFTauRef->pt())));

// pfGammas inside the tau signal cone
Expand All @@ -140,21 +132,19 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef&
}

// loop over the electrons
for ( reco::GsfElectronCollection::const_iterator theGsfElectron = gsfElectrons_->begin();
theGsfElectron != gsfElectrons_->end(); ++theGsfElectron ) {
if ( theGsfElectron->pt() > 10. ) { // CV: only take electrons above some minimal energy/Pt into account...
double deltaREleTau = deltaR(theGsfElectron->p4(), thePFTauRef->p4());
for ( const auto & theGsfElectron : *gsfElectrons_ ) {
if ( theGsfElectron.pt() > 10. ) { // CV: only take electrons above some minimal energy/Pt into account...
double deltaREleTau = deltaR(theGsfElectron.p4(), thePFTauRef->p4());
deltaRDummy = deltaREleTau;
if ( deltaREleTau < 0.3 ) {
double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron, usePhiAtEcalEntranceExtrapolation_);
double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron);
const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand();
bool hasGsfTrack = false;
if (lpfch.isNonnull()) {
hasGsfTrack = lpfch->gsfTrackRef().isNonnull();
}

if ( !hasGsfTrack )
hasGsfTrack = theGsfElectron->gsfTrack().isNonnull();
hasGsfTrack = theGsfElectron.gsfTrack().isNonnull();

//// Veto taus that go to Ecal crack
if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
Expand Down Expand Up @@ -188,7 +178,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef&
} // end of loop over electrons

if ( !isGsfElectronMatched ) {
mvaValue = mva_->MVAValue(*thePFTauRef, usePhiAtEcalEntranceExtrapolation_);
mvaValue = mva_->MVAValue(*thePFTauRef);
const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand();
bool hasGsfTrack = false;
if (lpfch.isNonnull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

patTauDiscriminationAgainstElectronMVA6 = cms.EDProducer("PATTauDiscriminationAgainstElectronMVA6",
# tau collection to discriminate
PFTauProducer = cms.InputTag('slimmedTaus'),
PATTauProducer = cms.InputTag('slimmedTaus'),

# Require leading pion ensures that:
# 1) these is at least one track above threshold (0.5 GeV) in the signal cone
Expand Down
Loading

0 comments on commit 48d50d0

Please sign in to comment.