From 5cdb02e9ae6aebfa48794c27176125462d24eeff Mon Sep 17 00:00:00 2001 From: Christian Veelken Date: Fri, 24 Apr 2020 18:22:53 +0300 Subject: [PATCH 01/10] - restructured code of againstElectronDeadECAL discriminator to run on either AOD or miniAOD inputs - use eta and phi of impact position of leadingPFChargedHadron on ECAL surface instead of eta and phi of tau at the vertex (taking bending of track in the magnetic field and the zVertex into account) --- RecoTauTag/RecoTau/BuildFile.xml | 5 + .../RecoTau/interface/AntiElectronDeadECAL.h | 74 +++++++ .../RecoTau/interface/AntiElectronIDMVA6.h | 8 +- .../interface/PositionAtECalEntrance.h | 33 +++ ...auDiscriminationAgainstElectronDeadECAL.cc | 78 ++++++++ ...auDiscriminationAgainstElectronDeadECAL.cc | 189 +++--------------- ...scriminationAgainstElectronDeadECAL_cfi.py | 19 ++ ...scriminationAgainstElectronDeadECAL_cfi.py | 5 +- .../RecoTau/src/AntiElectronDeadECAL.cc | 119 +++++++++++ RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 52 ++--- .../RecoTau/src/PositionAtECalEntrance.cc | 42 ++++ 11 files changed, 423 insertions(+), 201 deletions(-) create mode 100644 RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h create mode 100644 RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h create mode 100644 RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc create mode 100644 RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py create mode 100644 RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc create mode 100644 RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc diff --git a/RecoTauTag/RecoTau/BuildFile.xml b/RecoTauTag/RecoTau/BuildFile.xml index 5a798e598d987..ee15b23a648ed 100644 --- a/RecoTauTag/RecoTau/BuildFile.xml +++ b/RecoTauTag/RecoTau/BuildFile.xml @@ -1,12 +1,17 @@ + + + + + diff --git a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h new file mode 100644 index 0000000000000..cf150155cdf42 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h @@ -0,0 +1,74 @@ +#ifndef RecoTauTag_RecoTau_AntiElectronDeadECAL_h +#define RecoTauTag_RecoTau_AntiElectronDeadECAL_h + +/** \class AntiElectronDeadECAL + * + * Flag tau candidates reconstructed near dead ECAL channels, + * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator + * + * The motivation for this flag is this presentation: + * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 + * + * Code adapted from: + * RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc + * + * \authors Lauri Andreas Wendland, + * Christian Veelken + * + * + * + */ + +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" + +#include +#include + +class AntiElectronDeadECAL +{ + public: + explicit AntiElectronDeadECAL(const edm::ParameterSet&); + ~AntiElectronDeadECAL(); + + void beginEvent(const edm::EventSetup&); + + bool operator()(const reco::Candidate* leadPFChargedHadron) const; + + private: + unsigned minStatus_; + double dR_; + + PositionAtECalEntrance positionAtECalEntrance_; + + void updateBadTowers(const edm::EventSetup&); + + struct towerInfo + { + towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) + : id_(id), + nBad_(nBad), + maxStatus_(maxStatus), + eta_(eta), + phi_(phi) + {} + uint32_t id_; + unsigned nBad_; + unsigned maxStatus_; + double eta_; + double phi_; + }; + typedef ROOT::Math::LorentzVector > PolarLorentzVector; + + std::vector badTowers_; + static const uint16_t statusMask_ = 0x1F; + + uint32_t channelStatusId_cache_; + uint32_t caloGeometryId_cache_; + uint32_t idealGeometryId_cache_; + bool isFirstEvent_; +}; + +#endif // RecoTauTag_RecoTau_AntiElectronDeadECAL_h diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 1283be084da1f..aa368a63069c2 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -22,9 +22,8 @@ #include "CondFormats/EgammaObjects/interface/GBRForest.h" #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/PatCandidates/interface/Electron.h" - -#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "DataFormats/PatCandidates/interface/PackedCandidate.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" #include "TMVA/Tools.h" #include "TMVA/Reader.h" @@ -125,7 +124,7 @@ class AntiElectronIDMVA6 { double MVAValue(const pat::Tau& theTau, const pat::Electron& theEle); // this function can be called for category 1 only !! double MVAValue(const pat::Tau& theTau); - // track extrapolation to ECAL entrance (used to re-calculate varibales that might not be available on miniAOD) + // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); private: @@ -168,7 +167,8 @@ class AntiElectronIDMVA6 { std::vector inputFilesToDelete_; - double bField_; + PositionAtECalEntrance positionAtECalEntrance_; + int verbosity_; }; diff --git a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h new file mode 100644 index 0000000000000..5675a79581b16 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h @@ -0,0 +1,33 @@ +#ifndef RecoTauTag_RecoTau_PositionAtECalEntrance_h +#define RecoTauTag_RecoTau_PositionAtECalEntrance_h + +/** \class PositionAtECalEntrance + * + * Extrapolate particle (charged or neutral) to ECAL entrance, + * in order to compute the distance of the tau to ECAL cracks and/or dead ECAL channels + * + * \authors Fabio Colombo, + * Christian Veelken + * + * + * + */ + +#include "FWCore/Framework/interface/EventSetup.h" +#include "DataFormats/Candidate/interface/Candidate.h" + +class PositionAtECalEntrance +{ + public: + PositionAtECalEntrance(); + ~PositionAtECalEntrance(); + + void beginEvent(const edm::EventSetup&); + + reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const; + + private: + double bField_z_; +}; + +#endif // RecoTauTag_RecoTau_PositionAtECalEntrance_h diff --git a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc new file mode 100644 index 0000000000000..3486c06a46987 --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc @@ -0,0 +1,78 @@ + +/** \class PATTauDiscriminationAgainstElectronDeadECAL + * + * Flag tau candidates reconstructed near dead ECAL channels, + * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator + * + * Adopted from RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc + * to enable computation of the discriminator on MiniAOD + * + * The motivation for this flag is this presentation: + * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 + * + * \authors Lauri Andreas Wendland, + * Christian Veelken + * + * + * + */ +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include +#include +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/TauReco/interface/PFTauFwd.h" +#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" + +class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationProducerBase +{ + public: + explicit PATTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) + : PATTauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")), + antiElectronDeadECAL_(cfg) + {} + ~PATTauDiscriminationAgainstElectronDeadECAL() override + {} + + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override + { + antiElectronDeadECAL_.beginEvent(es); + } + + double discriminate(const TauRef& tau) const override + { + double discriminator = 1.; + if ( tau->leadChargedHadrCand().isNonnull() ) { + if ( antiElectronDeadECAL_(tau->leadChargedHadrCand().get()) ) { + discriminator = 0.; + } + } + return discriminator; + } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + std::string moduleLabel_; + + AntiElectronDeadECAL antiElectronDeadECAL_; +}; + +void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +{ + // patTauDiscriminationAgainstElectronDeadECAL + edm::ParameterSetDescription desc; + + desc.add("dR", 0.08); + desc.add("minStatus", 12); + desc.add("verbosity", 0); + + fillProducerDescriptions(desc); // inherited from the base-class + + descriptions.add("patTauDiscriminationAgainstElectronDeadECAL", desc); +} + +DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc index b7f7634c9c41d..b1cec667fa20f 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc @@ -13,191 +13,62 @@ * * */ - -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" #include #include - -#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" -#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "DataFormats/DetId/interface/DetId.h" -#include "DataFormats/EcalDetId/interface/EBDetId.h" -#include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "DataFormats/Math/interface/deltaR.h" +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/TauReco/interface/PFTauFwd.h" #include "DataFormats/TauReco/interface/PFTauDiscriminator.h" +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" -#include - -using namespace reco; - -class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase { -public: +class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase +{ + public: explicit PFRecoTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : PFTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), - isFirstEvent_(true) { - minStatus_ = cfg.getParameter("minStatus"); - dR_ = cfg.getParameter("dR"); - - verbosity_ = cfg.getParameter("verbosity"); + antiElectronDeadECAL_(cfg) + {} + ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override + {} + + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override + { + antiElectronDeadECAL_.beginEvent(es); } - ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override {} - - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { updateBadTowers(es); } - double discriminate(const PFTauRef& pfTau) const override { - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << ":"; - edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PFTauAgainstEleDeadECAL") << "#badTowers = " << badTowers_.size(); - edm::LogPrint("PFTauAgainstEleDeadECAL") - << "tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi(); - } + double discriminate(const reco::PFTauRef& tau) const override + { double discriminator = 1.; - for (std::vector::const_iterator badTower = badTowers_.begin(); badTower != badTowers_.end(); - ++badTower) { - if (deltaR(badTower->eta_, badTower->phi_, pfTau->eta(), pfTau->phi()) < dR_) { - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") - << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_; - } + if ( tau->leadChargedHadrCand().isNonnull() ) { + if ( antiElectronDeadECAL_(tau->leadChargedHadrCand().get()) ) { discriminator = 0.; } } - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; - } return discriminator; } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); -private: - void updateBadTowers(const edm::EventSetup& es) { - // NOTE: modified version of SUSY CAF code - // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - const uint32_t channelStatusId = es.get().cacheIdentifier(); - const uint32_t caloGeometryId = es.get().cacheIdentifier(); - const uint32_t idealGeometryId = es.get().cacheIdentifier(); - - if (!isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && - idealGeometryId == idealGeometryId_cache_) - return; - - edm::ESHandle channelStatus; - es.get().get(channelStatus); - channelStatusId_cache_ = channelStatusId; - - edm::ESHandle caloGeometry; - es.get().get(caloGeometry); - caloGeometryId_cache_ = caloGeometryId; - - edm::ESHandle ttMap; - es.get().get(ttMap); - idealGeometryId_cache_ = idealGeometryId; - - std::map nBadCrystals, maxStatus; - std::map sumEta, sumPhi; - - loopXtals( - nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product()); - loopXtals( - nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product()); - - badTowers_.clear(); - for (std::map::const_iterator it = nBadCrystals.begin(); it != nBadCrystals.end(); ++it) { - uint32_t key = it->first; - badTowers_.push_back( - towerInfo(key, it->second, maxStatus[key], sumEta[key] / it->second, sumPhi[key] / it->second)); - } - - isFirstEvent_ = false; - } - - template - void loopXtals(std::map& nBadCrystals, - std::map& maxStatus, - std::map& sumEta, - std::map& sumPhi, - const EcalChannelStatus* channelStatus, - const CaloGeometry* caloGeometry, - const EcalTrigTowerConstituentsMap* ttMap) const { - // NOTE: modified version of SUSY CAF code - // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - for (int i = 0; i < Id::kSizeForDenseIndexing; ++i) { - Id id = Id::unhashIndex(i); - if (id == Id(0)) - continue; - EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); - unsigned status = (it == channelStatus->end()) ? 0 : (it->getStatusCode() & statusMask_); - if (status >= minStatus_) { - const GlobalPoint& point = caloGeometry->getPosition(id); - uint32_t key = ttMap->towerOf(id); - maxStatus[key] = TMath::Max(status, maxStatus[key]); - ++nBadCrystals[key]; - sumEta[key] += point.eta(); - sumPhi[key] += point.phi(); - } - } - } - - struct towerInfo { - towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) - : id_(id), nBad_(nBad), maxStatus_(maxStatus), eta_(eta), phi_(phi) {} - uint32_t id_; - unsigned nBad_; - unsigned maxStatus_; - double eta_; - double phi_; - }; - typedef ROOT::Math::LorentzVector > PolarLorentzVector; - + private: std::string moduleLabel_; - unsigned minStatus_; - double dR_; - - std::vector badTowers_; - static const uint16_t statusMask_ = 0x1F; - - uint32_t channelStatusId_cache_; - uint32_t caloGeometryId_cache_; - uint32_t idealGeometryId_cache_; - bool isFirstEvent_; - int verbosity_; + AntiElectronDeadECAL antiElectronDeadECAL_; }; -void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +{ // pfRecoTauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; - desc.add("verbosity", 0); - { - edm::ParameterSetDescription pset_Prediscriminants; - pset_Prediscriminants.add("BooleanOperator", "and"); - { - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("leadTrack", psd1); - } - { - // encountered this at - // RecoTauTag/Configuration/python/HPSPFTaus_cff.py - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("decayMode", psd1); - } - desc.add("Prediscriminants", pset_Prediscriminants); - } + desc.add("dR", 0.08); - desc.add("PFTauProducer", edm::InputTag("pfTauProducer")); desc.add("minStatus", 12); + desc.add("verbosity", 0); + + fillProducerDescriptions(desc); // inherited from the base-class + descriptions.add("pfRecoTauDiscriminationAgainstElectronDeadECAL", desc); } diff --git a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py new file mode 100644 index 0000000000000..5e6a0182e69f1 --- /dev/null +++ b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py @@ -0,0 +1,19 @@ +import FWCore.ParameterSet.Config as cms + +from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants + +patTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer("PATTauDiscriminationAgainstElectronDeadECAL", + # tau collection to discriminate + PATTauProducer = cms.InputTag('slimmedTaus'), + + # require no specific prediscriminants when running on MiniAOD, + # assuming that loose tau decay mode (and hence leading track) selection is already applied during MiniAOD production + Prediscriminants = noPrediscriminants, + + # status flag indicating dead/masked ECAL crystals + minStatus = cms.uint32(12), + + # region around dead/masked ECAL crystals that is to be cut + dR = cms.double(0.08), + verbosity = cms.int32(0) +) diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py index f891f28f305d2..0546507354688 100644 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py @@ -1,9 +1,8 @@ import FWCore.ParameterSet.Config as cms -from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack -pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( - "PFRecoTauDiscriminationAgainstElectronDeadECAL", +from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack +pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer("PFRecoTauDiscriminationAgainstElectronDeadECAL", # tau collection to discriminate PFTauProducer = cms.InputTag('pfTauProducer'), diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc new file mode 100644 index 0000000000000..809bca468276e --- /dev/null +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -0,0 +1,119 @@ +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" + +#include "FWCore/Framework/interface/ESHandle.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" +#include "DataFormats/Math/interface/deltaR.h" + +#include + +AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) + : isFirstEvent_(true) +{ + minStatus_ = cfg.getParameter("minStatus"); + dR_ = cfg.getParameter("dR"); +} + +AntiElectronDeadECAL::~AntiElectronDeadECAL() +{} + +void AntiElectronDeadECAL::beginEvent(const edm::EventSetup& es) +{ + updateBadTowers(es); + positionAtECalEntrance_.beginEvent(es); +} + +namespace +{ + template + void loopXtals(std::map& nBadCrystals, + std::map& maxStatus, + std::map& sumEta, + std::map& sumPhi , + const EcalChannelStatus* channelStatus, + const CaloGeometry* caloGeometry, + const EcalTrigTowerConstituentsMap* ttMap, + unsigned minStatus, + const uint16_t statusMask) + { + // NOTE: modified version of SUSY CAF code + // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc + for ( int i = 0; i < Id::kSizeForDenseIndexing; ++i ) { + Id id = Id::unhashIndex(i); + if ( id == Id(0) ) continue; + EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); + unsigned status = ( it == channelStatus->end() ) ? + 0 : (it->getStatusCode() & statusMask); + if ( status >= minStatus ) { + const GlobalPoint& point = caloGeometry->getPosition(id); + uint32_t key = ttMap->towerOf(id); + maxStatus[key] = TMath::Max(status, maxStatus[key]); + ++nBadCrystals[key]; + sumEta[key] += point.eta(); + sumPhi[key] += point.phi(); + } + } + } +} + +void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) +{ + // NOTE: modified version of SUSY CAF code + // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc + const uint32_t channelStatusId = es.get().cacheIdentifier(); + const uint32_t caloGeometryId = es.get().cacheIdentifier(); + const uint32_t idealGeometryId = es.get().cacheIdentifier(); + + if ( !isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && idealGeometryId == idealGeometryId_cache_ ) return; + + edm::ESHandle channelStatus; + es.get().get(channelStatus); + channelStatusId_cache_ = channelStatusId; + + edm::ESHandle caloGeometry; + es.get().get(caloGeometry); + caloGeometryId_cache_ = caloGeometryId; + + edm::ESHandle ttMap; + es.get().get(ttMap); + idealGeometryId_cache_ = idealGeometryId; + + std::map nBadCrystals, maxStatus; + std::map sumEta, sumPhi; + + loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); + loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); + + badTowers_.clear(); + for ( std::map::const_iterator it = nBadCrystals.begin(); + it != nBadCrystals.end(); ++it ) { + uint32_t key = it->first; + badTowers_.push_back(towerInfo(key, it->second, maxStatus[key], sumEta[key]/it->second, sumPhi[key]/it->second)); + } + + isFirstEvent_ = false; +} + + +bool AntiElectronDeadECAL::operator()(const reco::Candidate* leadPFChargedHadron) const +{ + bool isNearBadTower = false; + bool success = false; + reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadPFChargedHadron, success); + if ( success ) { + for ( std::vector::const_iterator badTower = badTowers_.begin(); + badTower != badTowers_.end(); ++badTower ) { + if ( deltaR(badTower->eta_, badTower->phi_, positionAtECalEntrance.eta(), positionAtECalEntrance.phi()) < dR_ ) { + isNearBadTower = true; + } + } + } + return isNearBadTower; +} diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index c66ea912ccd94..06047d64bfa82 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -11,9 +11,6 @@ #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" #include "FWCore/Framework/interface/ESHandle.h" -#include "MagneticField/Engine/interface/MagneticField.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" - #include #include #include @@ -57,7 +54,6 @@ AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) Var_woGwGSF_Endcap_ = new Float_t[23]; Var_wGwGSF_Endcap_ = new Float_t[31]; - bField_ = 0; verbosity_ = 0; } @@ -134,10 +130,7 @@ void AntiElectronIDMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup } isInitialized_ = true; } - - edm::ESHandle pSetup; - es.get().get(pSetup); - bField_ = pSetup->inTesla(GlobalPoint(0, 0, 0)).z(); + positionAtECalEntrance_.beginEvent(es); } double AntiElectronIDMVA6::MVAValue(Float_t TauPt, @@ -624,9 +617,11 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, const reco::Gsf for (const auto& signalPFCand : signalPFCands) { reco::Candidate const* signalCand = signalPFCand.get(); float phi = thePFTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos)) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if ( success ) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -839,9 +834,11 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) { for (const auto& signalPFCand : signalPFCands) { reco::Candidate const* signalCand = signalPFCand.get(); float phi = thePFTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if ( success ) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -981,9 +978,11 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau, const pat::Electron& for (const auto& signalCandPtr : signalCands) { reco::Candidate const* signalCand = signalCandPtr.get(); float phi = theTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if ( success ) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -1172,9 +1171,11 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau) { for (const auto& signalCandPtr : signalCands) { reco::Candidate const* signalCand = signalCandPtr.get(); float phi = theTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if ( success ) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -1329,22 +1330,3 @@ double AntiElectronIDMVA6::dCrackEta(double eta) { return std::abs(retVal); } - -bool AntiElectronIDMVA6::atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos) { - bool result = false; - BaseParticlePropagator theParticle = BaseParticlePropagator( - RawParticle(math::XYZTLorentzVector(part->px(), part->py(), part->pz(), part->energy()), - math::XYZTLorentzVector(part->vertex().x(), part->vertex().y(), part->vertex().z(), 0.), - part->charge()), - 0., - 0., - bField_); - theParticle.propagateToEcalEntrance(false); - if (theParticle.getSuccess() != 0) { - pos = math::XYZPoint(theParticle.particle().vertex()); - result = true; - } else { - result = false; - } - return result; -} diff --git a/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc b/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc new file mode 100644 index 0000000000000..bbc851efd9e36 --- /dev/null +++ b/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc @@ -0,0 +1,42 @@ +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" + +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" + +#include + +PositionAtECalEntrance::PositionAtECalEntrance() + : bField_z_(-1.) +{} + +PositionAtECalEntrance::~PositionAtECalEntrance() +{} + +void PositionAtECalEntrance::beginEvent(const edm::EventSetup& es) +{ + edm::ESHandle bField; + es.get().get(bField); + bField_z_ = bField->inTesla(GlobalPoint(0.,0.,0.)).z(); +} + +reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* particle, bool& success) const +{ + assert(bField_z_ != -1.); + BaseParticlePropagator propagator = BaseParticlePropagator( + RawParticle(math::XYZTLorentzVector(particle->px(), particle->py(), particle->pz(), particle->energy()), + math::XYZTLorentzVector(particle->vertex().x(), particle->vertex().y(), particle->vertex().z(), 0.), + particle->charge()), + 0., + 0., + bField_z_); + propagator.propagateToEcalEntrance(false); + reco::Candidate::Point position; + if ( propagator.getSuccess() != 0 ) { + position = reco::Candidate::Point(propagator.particle().vertex().x(), propagator.particle().vertex().y(), propagator.particle().vertex().z()); + success = true; + } else { + success = false; + } + return position; +} From e6bfb8f5eddb5508c60f1318b29d75a6bf2b87c9 Mon Sep 17 00:00:00 2001 From: Christian Veelken Date: Mon, 27 Apr 2020 18:07:16 +0300 Subject: [PATCH 02/10] add discriminator againstElectronDeadECAL to pat::Taus --- PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py | 1 + PhysicsTools/PatAlgos/python/tools/tauTools.py | 1 + 2 files changed, 2 insertions(+) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py b/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py index 585e22b86a37e..a3ad88c7648ad 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py @@ -164,3 +164,4 @@ def containerID(pset, inputID, provCfgLabel, wps): ["againstElectronTightMVA6", "_Tight"], ["againstElectronVTightMVA6", "_VTight"] ]) +singleID(patTaus.tauIDSources, "hpsPFTauDiscriminationByDeadECALElectronRejection", "againstElectronDeadECAL") diff --git a/PhysicsTools/PatAlgos/python/tools/tauTools.py b/PhysicsTools/PatAlgos/python/tools/tauTools.py index d63e5f1be200f..7beb431372102 100644 --- a/PhysicsTools/PatAlgos/python/tools/tauTools.py +++ b/PhysicsTools/PatAlgos/python/tools/tauTools.py @@ -154,6 +154,7 @@ def _switchToPFTau(process, ("againstElectronMediumMVA6", "DiscriminationByMVA6MediumElectronRejection"), ("againstElectronTightMVA6", "DiscriminationByMVA6TightElectronRejection"), ("againstElectronVTightMVA6", "DiscriminationByMVA6VTightElectronRejection"), + ("againstElectronDeadECAL", "DiscriminationByDeadECALElectronRejection"), ] # switch to PFTau collection produced for fixed dR = 0.07 signal cone size From fb541811c17f5549a2b8429e674c346aa8295510 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Mon, 4 May 2020 14:11:19 +0200 Subject: [PATCH 03/10] Add switch to disable extrapolation to ECal entrance; some fixes and cosmetics --- .../RecoTau/interface/AntiElectronDeadECAL.h | 18 +++-- .../interface/PositionAtECalEntrance.h | 2 +- ...auDiscriminationAgainstElectronDeadECAL.cc | 35 +++++--- ...auDiscriminationAgainstElectronDeadECAL.cc | 33 +++++--- ...scriminationAgainstElectronDeadECAL_cfi.py | 11 ++- ...scriminationAgainstElectronDeadECAL_cfi.py | 11 ++- .../RecoTau/src/AntiElectronDeadECAL.cc | 81 ++++++++++++++----- 7 files changed, 135 insertions(+), 56 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h index cf150155cdf42..157f591bf6cae 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h @@ -35,24 +35,26 @@ class AntiElectronDeadECAL void beginEvent(const edm::EventSetup&); - bool operator()(const reco::Candidate* leadPFChargedHadron) const; + bool operator()(const reco::Candidate* tau) const; private: unsigned minStatus_; double dR_; + int verbosity_; + bool extrapolateToECalEntrance_; PositionAtECalEntrance positionAtECalEntrance_; void updateBadTowers(const edm::EventSetup&); - - struct towerInfo + + struct towerInfo { towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) - : id_(id), - nBad_(nBad), - maxStatus_(maxStatus), - eta_(eta), - phi_(phi) + : id_(id), + nBad_(nBad), + maxStatus_(maxStatus), + eta_(eta), + phi_(phi) {} uint32_t id_; unsigned nBad_; diff --git a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h index 5675a79581b16..4ee3ef33969e1 100644 --- a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h +++ b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h @@ -16,7 +16,7 @@ #include "FWCore/Framework/interface/EventSetup.h" #include "DataFormats/Candidate/interface/Candidate.h" -class PositionAtECalEntrance +class PositionAtECalEntrance { public: PositionAtECalEntrance(); diff --git a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc index 3486c06a46987..dea0da9cee33a 100644 --- a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc @@ -6,7 +6,7 @@ * * Adopted from RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc * to enable computation of the discriminator on MiniAOD - * + * * The motivation for this flag is this presentation: * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 * @@ -32,23 +32,30 @@ class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationP explicit PATTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : PATTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), - antiElectronDeadECAL_(cfg) + verbosity_(cfg.getParameter("verbosity")), + antiElectronDeadECAL_(cfg) {} - ~PATTauDiscriminationAgainstElectronDeadECAL() override + ~PATTauDiscriminationAgainstElectronDeadECAL() override {} - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override - { - antiElectronDeadECAL_.beginEvent(es); + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override + { + antiElectronDeadECAL_.beginEvent(es); } - double discriminate(const TauRef& tau) const override + double discriminate(const TauRef& tau) const override { + if (verbosity_) { + edm::LogPrint("PATTauAgainstEleDeadECAL") << ":"; + edm::LogPrint("PATTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint("PATTauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + } double discriminator = 1.; - if ( tau->leadChargedHadrCand().isNonnull() ) { - if ( antiElectronDeadECAL_(tau->leadChargedHadrCand().get()) ) { - discriminator = 0.; - } + if ( antiElectronDeadECAL_(tau.get()) ) { + discriminator = 0.; + } + if (verbosity_) { + edm::LogPrint("PATTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; } return discriminator; } @@ -57,17 +64,19 @@ class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationP private: std::string moduleLabel_; + int verbosity_; AntiElectronDeadECAL antiElectronDeadECAL_; }; -void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // patTauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; - + desc.add("dR", 0.08); desc.add("minStatus", 12); + desc.add("extrapolateToECalEntrance", true); desc.add("verbosity", 0); fillProducerDescriptions(desc); // inherited from the base-class diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc index b1cec667fa20f..88c6eb4b2b1ee 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc @@ -23,29 +23,36 @@ #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" #include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" -class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase +class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase { public: explicit PFRecoTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : PFTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), - antiElectronDeadECAL_(cfg) + verbosity_(cfg.getParameter("verbosity")), + antiElectronDeadECAL_(cfg) {} - ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override + ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override {} - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override - { - antiElectronDeadECAL_.beginEvent(es); + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override + { + antiElectronDeadECAL_.beginEvent(es); } - double discriminate(const reco::PFTauRef& tau) const override + double discriminate(const reco::PFTauRef& tau) const override { + if (verbosity_) { + edm::LogPrint("PFTauAgainstEleDeadECAL") << ":"; + edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint("PFTauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + } double discriminator = 1.; - if ( tau->leadChargedHadrCand().isNonnull() ) { - if ( antiElectronDeadECAL_(tau->leadChargedHadrCand().get()) ) { - discriminator = 0.; - } + if ( antiElectronDeadECAL_(tau.get()) ) { + discriminator = 0.; + } + if (verbosity_) { + edm::LogPrint("PFTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; } return discriminator; } @@ -54,17 +61,19 @@ class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminatio private: std::string moduleLabel_; + int verbosity_; AntiElectronDeadECAL antiElectronDeadECAL_; }; -void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // pfRecoTauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; desc.add("dR", 0.08); desc.add("minStatus", 12); + desc.add("extrapolateToECalEntrance", true); desc.add("verbosity", 0); fillProducerDescriptions(desc); // inherited from the base-class diff --git a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py index 5e6a0182e69f1..ffda6d2d19b82 100644 --- a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py @@ -2,7 +2,9 @@ from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants -patTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer("PATTauDiscriminationAgainstElectronDeadECAL", +patTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( + "PATTauDiscriminationAgainstElectronDeadECAL", + # tau collection to discriminate PATTauProducer = cms.InputTag('slimmedTaus'), @@ -13,7 +15,12 @@ # status flag indicating dead/masked ECAL crystals minStatus = cms.uint32(12), - # region around dead/masked ECAL crystals that is to be cut + # region around dead/masked ECAL crystals that is to be cut dR = cms.double(0.08), + + # extrapolate leading track to ECAL or use tau direction at the primary event vertex + # in order to compute distance between tau and ECAL crystals + extrapolateToECalEntrance = cms.bool(True), + verbosity = cms.int32(0) ) diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py index 0546507354688..92103b3aab06b 100644 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py @@ -2,7 +2,9 @@ from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack -pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer("PFRecoTauDiscriminationAgainstElectronDeadECAL", +pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( + "PFRecoTauDiscriminationAgainstElectronDeadECAL", + # tau collection to discriminate PFTauProducer = cms.InputTag('pfTauProducer'), @@ -14,7 +16,12 @@ # status flag indicating dead/masked ECAL crystals minStatus = cms.uint32(12), - # region around dead/masked ECAL crystals that is to be cut + # region around dead/masked ECAL crystals that is to be cut dR = cms.double(0.08), + + # extrapolate leading track to ECAL or use tau direction at the primary event vertex + # in order to compute distance between tau and ECAL crystals + extrapolateToECalEntrance = cms.bool(True), + verbosity = cms.int32(0) ) diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc index 809bca468276e..2a65b6787aac4 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -7,10 +7,13 @@ #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" #include "DataFormats/Math/interface/deltaR.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include @@ -19,6 +22,10 @@ AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) { minStatus_ = cfg.getParameter("minStatus"); dR_ = cfg.getParameter("dR"); + + extrapolateToECalEntrance_ = cfg.getParameter("extrapolateToECalEntrance"); + + verbosity_ = cfg.getParameter("verbosity"); } AntiElectronDeadECAL::~AntiElectronDeadECAL() @@ -46,10 +53,10 @@ namespace // NOTE: modified version of SUSY CAF code // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc for ( int i = 0; i < Id::kSizeForDenseIndexing; ++i ) { - Id id = Id::unhashIndex(i); + Id id = Id::unhashIndex(i); if ( id == Id(0) ) continue; EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); - unsigned status = ( it == channelStatus->end() ) ? + unsigned status = ( it == channelStatus->end() ) ? 0 : (it->getStatusCode() & statusMask); if ( status >= minStatus ) { const GlobalPoint& point = caloGeometry->getPosition(id); @@ -63,7 +70,7 @@ namespace } } -void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) +void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { // NOTE: modified version of SUSY CAF code // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc @@ -73,13 +80,13 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) if ( !isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && idealGeometryId == idealGeometryId_cache_ ) return; - edm::ESHandle channelStatus; + edm::ESHandle channelStatus; es.get().get(channelStatus); - channelStatusId_cache_ = channelStatusId; + channelStatusId_cache_ = channelStatusId; - edm::ESHandle caloGeometry; + edm::ESHandle caloGeometry; es.get().get(caloGeometry); - caloGeometryId_cache_ = caloGeometryId; + caloGeometryId_cache_ = caloGeometryId; edm::ESHandle ttMap; es.get().get(ttMap); @@ -87,12 +94,12 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) std::map nBadCrystals, maxStatus; std::map sumEta, sumPhi; - + loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); - + badTowers_.clear(); - for ( std::map::const_iterator it = nBadCrystals.begin(); + for ( std::map::const_iterator it = nBadCrystals.begin(); it != nBadCrystals.end(); ++it ) { uint32_t key = it->first; badTowers_.push_back(towerInfo(key, it->second, maxStatus[key], sumEta[key]/it->second, sumPhi[key]/it->second)); @@ -102,17 +109,55 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) } -bool AntiElectronDeadECAL::operator()(const reco::Candidate* leadPFChargedHadron) const +bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const { bool isNearBadTower = false; - bool success = false; - reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadPFChargedHadron, success); - if ( success ) { - for ( std::vector::const_iterator badTower = badTowers_.begin(); - badTower != badTowers_.end(); ++badTower ) { - if ( deltaR(badTower->eta_, badTower->phi_, positionAtECalEntrance.eta(), positionAtECalEntrance.phi()) < dR_ ) { - isNearBadTower = true; + double tau_eta = tau->eta(); + double tau_phi = tau->phi(); + const reco::Candidate* leadChargedHadron = nullptr; + if (extrapolateToECalEntrance_) { + const reco::PFTau *pfTau = dynamic_cast(tau); + if (pfTau != nullptr) { + leadChargedHadron = pfTau->leadChargedHadrCand().isNonnull() ? + pfTau->leadChargedHadrCand().get() : nullptr; + } + else { + const pat::Tau *patTau = dynamic_cast(tau); + if (patTau != nullptr) { + leadChargedHadron = patTau->leadChargedHadrCand().isNonnull() ? + patTau->leadChargedHadrCand().get() : nullptr; + } + } + } + if ( leadChargedHadron != nullptr ) { + bool success = false; + reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadChargedHadron, success); + if ( success ) { + tau_eta = positionAtECalEntrance.eta(); + tau_phi = positionAtECalEntrance.phi(); + } + } + if ( verbosity_ ) { + edm::LogPrint("TauAgainstEleDeadECAL") << ":" ; + edm::LogPrint("TauAgainstEleDeadECAL") << " #badTowers = " << badTowers_.size() ; + if ( leadChargedHadron != nullptr ) { + edm::LogPrint("TauAgainstEleDeadECAL") + << " leadChargedHadron ("<< leadChargedHadron->pdgId() << "): Pt = " << leadChargedHadron->pt() + << ", eta at ECAL (vtx) = " << tau_eta << " (" << leadChargedHadron->eta() << ")" + << ", phi at ECAL (vtx) = " << tau_phi << " (" << leadChargedHadron->phi() << ")"; + } + else { + edm::LogPrint("TauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; + } + } + for ( std::vector::const_iterator badTower = badTowers_.begin(); + badTower != badTowers_.end(); ++badTower ) { + if ( deltaR(badTower->eta_, badTower->phi_, tau_eta, tau_phi) < dR_ ) { + if ( verbosity_ ) { + edm::LogPrint("TauAgainstEleDeadECAL") << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_ ; } + isNearBadTower = true; + break; } } return isNearBadTower; From 2cf9a25a1f595d04e9d12eab8bec93d1d5156dbe Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Mon, 4 May 2020 16:44:11 +0200 Subject: [PATCH 04/10] code quality fixes --- .../RecoTau/interface/AntiElectronDeadECAL.h | 19 +-- .../interface/PositionAtECalEntrance.h | 9 +- ...auDiscriminationAgainstElectronDeadECAL.cc | 31 ++-- ...auDiscriminationAgainstElectronDeadECAL.cc | 31 ++-- .../RecoTau/src/AntiElectronDeadECAL.cc | 144 +++++++++--------- RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 8 +- .../RecoTau/src/PositionAtECalEntrance.cc | 22 ++- 7 files changed, 122 insertions(+), 142 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h index 157f591bf6cae..5f0bef4677d95 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h @@ -27,9 +27,8 @@ #include #include -class AntiElectronDeadECAL -{ - public: +class AntiElectronDeadECAL { +public: explicit AntiElectronDeadECAL(const edm::ParameterSet&); ~AntiElectronDeadECAL(); @@ -37,7 +36,7 @@ class AntiElectronDeadECAL bool operator()(const reco::Candidate* tau) const; - private: +private: unsigned minStatus_; double dR_; int verbosity_; @@ -47,15 +46,9 @@ class AntiElectronDeadECAL void updateBadTowers(const edm::EventSetup&); - struct towerInfo - { + struct towerInfo { towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) - : id_(id), - nBad_(nBad), - maxStatus_(maxStatus), - eta_(eta), - phi_(phi) - {} + : id_(id), nBad_(nBad), maxStatus_(maxStatus), eta_(eta), phi_(phi) {} uint32_t id_; unsigned nBad_; unsigned maxStatus_; @@ -73,4 +66,4 @@ class AntiElectronDeadECAL bool isFirstEvent_; }; -#endif // RecoTauTag_RecoTau_AntiElectronDeadECAL_h +#endif // RecoTauTag_RecoTau_AntiElectronDeadECAL_h diff --git a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h index 4ee3ef33969e1..d484296affe28 100644 --- a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h +++ b/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h @@ -16,9 +16,8 @@ #include "FWCore/Framework/interface/EventSetup.h" #include "DataFormats/Candidate/interface/Candidate.h" -class PositionAtECalEntrance -{ - public: +class PositionAtECalEntrance { +public: PositionAtECalEntrance(); ~PositionAtECalEntrance(); @@ -26,8 +25,8 @@ class PositionAtECalEntrance reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const; - private: +private: double bField_z_; }; -#endif // RecoTauTag_RecoTau_PositionAtECalEntrance_h +#endif // RecoTauTag_RecoTau_PositionAtECalEntrance_h diff --git a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc index dea0da9cee33a..c62cfac51ea25 100644 --- a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc @@ -26,32 +26,26 @@ #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" #include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" -class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationProducerBase -{ - public: +class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationProducerBase { +public: explicit PATTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : PATTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), verbosity_(cfg.getParameter("verbosity")), - antiElectronDeadECAL_(cfg) - {} - ~PATTauDiscriminationAgainstElectronDeadECAL() override - {} + antiElectronDeadECAL_(cfg) {} + ~PATTauDiscriminationAgainstElectronDeadECAL() override {} - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override - { - antiElectronDeadECAL_.beginEvent(es); - } + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } - double discriminate(const TauRef& tau) const override - { + double discriminate(const TauRef& tau) const override { if (verbosity_) { edm::LogPrint("PATTauAgainstEleDeadECAL") << ":"; edm::LogPrint("PATTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PATTauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + edm::LogPrint("PATTauAgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } double discriminator = 1.; - if ( antiElectronDeadECAL_(tau.get()) ) { + if (antiElectronDeadECAL_(tau.get())) { discriminator = 0.; } if (verbosity_) { @@ -62,15 +56,14 @@ class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationP static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - private: +private: std::string moduleLabel_; int verbosity_; AntiElectronDeadECAL antiElectronDeadECAL_; }; -void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) -{ +void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // patTauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; @@ -79,7 +72,7 @@ void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::Configur desc.add("extrapolateToECalEntrance", true); desc.add("verbosity", 0); - fillProducerDescriptions(desc); // inherited from the base-class + fillProducerDescriptions(desc); // inherited from the base-class descriptions.add("patTauDiscriminationAgainstElectronDeadECAL", desc); } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc index 88c6eb4b2b1ee..7003d8f63be0d 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc @@ -23,32 +23,26 @@ #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" #include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" -class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase -{ - public: +class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase { +public: explicit PFRecoTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : PFTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), verbosity_(cfg.getParameter("verbosity")), - antiElectronDeadECAL_(cfg) - {} - ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override - {} + antiElectronDeadECAL_(cfg) {} + ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override {} - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override - { - antiElectronDeadECAL_.beginEvent(es); - } + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } - double discriminate(const reco::PFTauRef& tau) const override - { + double discriminate(const reco::PFTauRef& tau) const override { if (verbosity_) { edm::LogPrint("PFTauAgainstEleDeadECAL") << ":"; edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PFTauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + edm::LogPrint("PFTauAgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } double discriminator = 1.; - if ( antiElectronDeadECAL_(tau.get()) ) { + if (antiElectronDeadECAL_(tau.get())) { discriminator = 0.; } if (verbosity_) { @@ -59,15 +53,14 @@ class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminatio static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - private: +private: std::string moduleLabel_; int verbosity_; AntiElectronDeadECAL antiElectronDeadECAL_; }; -void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) -{ +void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // pfRecoTauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; @@ -76,7 +69,7 @@ void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::Confi desc.add("extrapolateToECalEntrance", true); desc.add("verbosity", 0); - fillProducerDescriptions(desc); // inherited from the base-class + fillProducerDescriptions(desc); // inherited from the base-class descriptions.add("pfRecoTauDiscriminationAgainstElectronDeadECAL", desc); } diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc index 2a65b6787aac4..9a17522b186a1 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -17,9 +17,7 @@ #include -AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) - : isFirstEvent_(true) -{ +AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) : isFirstEvent_(true) { minStatus_ = cfg.getParameter("minStatus"); dR_ = cfg.getParameter("dR"); @@ -28,57 +26,54 @@ AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) verbosity_ = cfg.getParameter("verbosity"); } -AntiElectronDeadECAL::~AntiElectronDeadECAL() -{} +AntiElectronDeadECAL::~AntiElectronDeadECAL() {} -void AntiElectronDeadECAL::beginEvent(const edm::EventSetup& es) -{ +void AntiElectronDeadECAL::beginEvent(const edm::EventSetup& es) { updateBadTowers(es); positionAtECalEntrance_.beginEvent(es); } -namespace -{ +namespace { template void loopXtals(std::map& nBadCrystals, - std::map& maxStatus, - std::map& sumEta, - std::map& sumPhi , - const EcalChannelStatus* channelStatus, - const CaloGeometry* caloGeometry, - const EcalTrigTowerConstituentsMap* ttMap, + std::map& maxStatus, + std::map& sumEta, + std::map& sumPhi, + const EcalChannelStatus* channelStatus, + const CaloGeometry* caloGeometry, + const EcalTrigTowerConstituentsMap* ttMap, unsigned minStatus, - const uint16_t statusMask) - { + const uint16_t statusMask) { // NOTE: modified version of SUSY CAF code // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - for ( int i = 0; i < Id::kSizeForDenseIndexing; ++i ) { + for (int i = 0; i < Id::kSizeForDenseIndexing; ++i) { Id id = Id::unhashIndex(i); - if ( id == Id(0) ) continue; + if (id == Id(0)) + continue; EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); - unsigned status = ( it == channelStatus->end() ) ? - 0 : (it->getStatusCode() & statusMask); - if ( status >= minStatus ) { - const GlobalPoint& point = caloGeometry->getPosition(id); - uint32_t key = ttMap->towerOf(id); - maxStatus[key] = TMath::Max(status, maxStatus[key]); - ++nBadCrystals[key]; - sumEta[key] += point.eta(); - sumPhi[key] += point.phi(); + unsigned status = (it == channelStatus->end()) ? 0 : (it->getStatusCode() & statusMask); + if (status >= minStatus) { + const GlobalPoint& point = caloGeometry->getPosition(id); + uint32_t key = ttMap->towerOf(id); + maxStatus[key] = TMath::Max(status, maxStatus[key]); + ++nBadCrystals[key]; + sumEta[key] += point.eta(); + sumPhi[key] += point.phi(); } } } -} +} // namespace -void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) -{ +void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { // NOTE: modified version of SUSY CAF code // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc const uint32_t channelStatusId = es.get().cacheIdentifier(); - const uint32_t caloGeometryId = es.get().cacheIdentifier(); + const uint32_t caloGeometryId = es.get().cacheIdentifier(); const uint32_t idealGeometryId = es.get().cacheIdentifier(); - if ( !isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && idealGeometryId == idealGeometryId_cache_ ) return; + if (!isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && + idealGeometryId == idealGeometryId_cache_) + return; edm::ESHandle channelStatus; es.get().get(channelStatus); @@ -92,69 +87,80 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) es.get().get(ttMap); idealGeometryId_cache_ = idealGeometryId; - std::map nBadCrystals, maxStatus; - std::map sumEta, sumPhi; - - loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); - loopXtals(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product(), minStatus_, statusMask_); + std::map nBadCrystals, maxStatus; + std::map sumEta, sumPhi; + + loopXtals(nBadCrystals, + maxStatus, + sumEta, + sumPhi, + channelStatus.product(), + caloGeometry.product(), + ttMap.product(), + minStatus_, + statusMask_); + loopXtals(nBadCrystals, + maxStatus, + sumEta, + sumPhi, + channelStatus.product(), + caloGeometry.product(), + ttMap.product(), + minStatus_, + statusMask_); badTowers_.clear(); - for ( std::map::const_iterator it = nBadCrystals.begin(); - it != nBadCrystals.end(); ++it ) { + for (std::map::const_iterator it = nBadCrystals.begin(); it != nBadCrystals.end(); ++it) { uint32_t key = it->first; - badTowers_.push_back(towerInfo(key, it->second, maxStatus[key], sumEta[key]/it->second, sumPhi[key]/it->second)); + badTowers_.push_back( + towerInfo(key, it->second, maxStatus[key], sumEta[key] / it->second, sumPhi[key] / it->second)); } isFirstEvent_ = false; } - -bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const -{ +bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const { bool isNearBadTower = false; double tau_eta = tau->eta(); double tau_phi = tau->phi(); const reco::Candidate* leadChargedHadron = nullptr; if (extrapolateToECalEntrance_) { - const reco::PFTau *pfTau = dynamic_cast(tau); + const reco::PFTau* pfTau = dynamic_cast(tau); if (pfTau != nullptr) { - leadChargedHadron = pfTau->leadChargedHadrCand().isNonnull() ? - pfTau->leadChargedHadrCand().get() : nullptr; - } - else { - const pat::Tau *patTau = dynamic_cast(tau); + leadChargedHadron = pfTau->leadChargedHadrCand().isNonnull() ? pfTau->leadChargedHadrCand().get() : nullptr; + } else { + const pat::Tau* patTau = dynamic_cast(tau); if (patTau != nullptr) { - leadChargedHadron = patTau->leadChargedHadrCand().isNonnull() ? - patTau->leadChargedHadrCand().get() : nullptr; + leadChargedHadron = patTau->leadChargedHadrCand().isNonnull() ? patTau->leadChargedHadrCand().get() : nullptr; } } } - if ( leadChargedHadron != nullptr ) { + if (leadChargedHadron != nullptr) { bool success = false; reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadChargedHadron, success); - if ( success ) { + if (success) { tau_eta = positionAtECalEntrance.eta(); tau_phi = positionAtECalEntrance.phi(); } } - if ( verbosity_ ) { - edm::LogPrint("TauAgainstEleDeadECAL") << ":" ; - edm::LogPrint("TauAgainstEleDeadECAL") << " #badTowers = " << badTowers_.size() ; - if ( leadChargedHadron != nullptr ) { + if (verbosity_) { + edm::LogPrint("TauAgainstEleDeadECAL") << ":"; + edm::LogPrint("TauAgainstEleDeadECAL") << " #badTowers = " << badTowers_.size(); + if (leadChargedHadron != nullptr) { edm::LogPrint("TauAgainstEleDeadECAL") - << " leadChargedHadron ("<< leadChargedHadron->pdgId() << "): Pt = " << leadChargedHadron->pt() - << ", eta at ECAL (vtx) = " << tau_eta << " (" << leadChargedHadron->eta() << ")" - << ", phi at ECAL (vtx) = " << tau_phi << " (" << leadChargedHadron->phi() << ")"; - } - else { - edm::LogPrint("TauAgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; + << " leadChargedHadron (" << leadChargedHadron->pdgId() << "): Pt = " << leadChargedHadron->pt() + << ", eta at ECAL (vtx) = " << tau_eta << " (" << leadChargedHadron->eta() << ")" + << ", phi at ECAL (vtx) = " << tau_phi << " (" << leadChargedHadron->phi() << ")"; + } else { + edm::LogPrint("TauAgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; } } - for ( std::vector::const_iterator badTower = badTowers_.begin(); - badTower != badTowers_.end(); ++badTower ) { - if ( deltaR(badTower->eta_, badTower->phi_, tau_eta, tau_phi) < dR_ ) { - if ( verbosity_ ) { - edm::LogPrint("TauAgainstEleDeadECAL") << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_ ; + for (std::vector::const_iterator badTower = badTowers_.begin(); badTower != badTowers_.end(); ++badTower) { + if (deltaR(badTower->eta_, badTower->phi_, tau_eta, tau_phi) < dR_) { + if (verbosity_) { + edm::LogPrint("TauAgainstEleDeadECAL") + << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_; } isNearBadTower = true; break; diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 06047d64bfa82..547dc14e07090 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -619,7 +619,7 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, const reco::Gsf float phi = thePFTau.phi(); bool success = false; reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if ( success ) { + if (success) { phi = aPos.Phi(); } sumPhiTimesEnergy += phi * signalCand->energy(); @@ -836,7 +836,7 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) { float phi = thePFTau.phi(); bool success = false; reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if ( success ) { + if (success) { phi = aPos.Phi(); } sumPhiTimesEnergy += phi * signalCand->energy(); @@ -980,7 +980,7 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau, const pat::Electron& float phi = theTau.phi(); bool success = false; reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if ( success ) { + if (success) { phi = aPos.Phi(); } sumPhiTimesEnergy += phi * signalCand->energy(); @@ -1173,7 +1173,7 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau) { float phi = theTau.phi(); bool success = false; reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if ( success ) { + if (success) { phi = aPos.Phi(); } sumPhiTimesEnergy += phi * signalCand->energy(); diff --git a/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc b/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc index bbc851efd9e36..e050511fe7cf4 100644 --- a/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc +++ b/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc @@ -4,24 +4,19 @@ #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" -#include +#include -PositionAtECalEntrance::PositionAtECalEntrance() - : bField_z_(-1.) -{} +PositionAtECalEntrance::PositionAtECalEntrance() : bField_z_(-1.) {} -PositionAtECalEntrance::~PositionAtECalEntrance() -{} +PositionAtECalEntrance::~PositionAtECalEntrance() {} -void PositionAtECalEntrance::beginEvent(const edm::EventSetup& es) -{ +void PositionAtECalEntrance::beginEvent(const edm::EventSetup& es) { edm::ESHandle bField; es.get().get(bField); - bField_z_ = bField->inTesla(GlobalPoint(0.,0.,0.)).z(); + bField_z_ = bField->inTesla(GlobalPoint(0., 0., 0.)).z(); } -reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* particle, bool& success) const -{ +reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* particle, bool& success) const { assert(bField_z_ != -1.); BaseParticlePropagator propagator = BaseParticlePropagator( RawParticle(math::XYZTLorentzVector(particle->px(), particle->py(), particle->pz(), particle->energy()), @@ -32,8 +27,9 @@ reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* bField_z_); propagator.propagateToEcalEntrance(false); reco::Candidate::Point position; - if ( propagator.getSuccess() != 0 ) { - position = reco::Candidate::Point(propagator.particle().vertex().x(), propagator.particle().vertex().y(), propagator.particle().vertex().z()); + if (propagator.getSuccess() != 0) { + position = reco::Candidate::Point( + propagator.particle().vertex().x(), propagator.particle().vertex().y(), propagator.particle().vertex().z()); success = true; } else { success = false; From 6cc80e12e1fe44d185b4ab70da8f5d1f7a8b93de Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Thu, 14 May 2020 17:27:11 +0200 Subject: [PATCH 05/10] Comments from review --- .../Configuration/python/HPSPFTaus_cff.py | 2 +- .../RecoTau/interface/AntiElectronDeadECAL.h | 31 +++--- .../RecoTau/interface/AntiElectronIDMVA6.h | 4 +- ...nce.h => PositionAtECalEntranceComputer.h} | 15 +-- ...auDiscriminationAgainstElectronDeadECAL.cc | 80 -------------- ...auDiscriminationAgainstElectronDeadECAL.cc | 77 -------------- ...auDiscriminationAgainstElectronDeadECAL.cc | 100 ++++++++++++++++++ ...scriminationAgainstElectronDeadECAL_cfi.py | 26 ----- ...scriminationAgainstElectronDeadECAL_cfi.py | 27 ----- .../RecoTau/src/AntiElectronDeadECAL.cc | 35 ++---- ...e.cc => PositionAtECalEntranceComputer.cc} | 15 ++- 11 files changed, 146 insertions(+), 266 deletions(-) rename RecoTauTag/RecoTau/interface/{PositionAtECalEntrance.h => PositionAtECalEntranceComputer.h} (56%) delete mode 100644 RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc delete mode 100644 RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc create mode 100644 RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc delete mode 100644 RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py delete mode 100644 RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py rename RecoTauTag/RecoTau/src/{PositionAtECalEntrance.cc => PositionAtECalEntranceComputer.cc} (57%) diff --git a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py index f5b5c66c46405..e4e48b362898d 100644 --- a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py +++ b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py @@ -13,7 +13,7 @@ from RecoTauTag.RecoTau.PFRecoTauDiscriminationByLeadingTrackFinding_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectron_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectronMVA6_cfi import * -from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi import * +from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstElectronDeadECAL_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuon_cfi import * from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstMuon2Container_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuonMVA_cfi import * diff --git a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h index 5f0bef4677d95..d37bb1b73b5bd 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h @@ -21,12 +21,17 @@ #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESWatcher.h" #include "DataFormats/Candidate/interface/Candidate.h" -#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" #include #include +class EcalChannelStatusRcd; +class CaloGeometryRecord; +class IdealGeometryRecord; + class AntiElectronDeadECAL { public: explicit AntiElectronDeadECAL(const edm::ParameterSet&); @@ -37,17 +42,17 @@ class AntiElectronDeadECAL { bool operator()(const reco::Candidate* tau) const; private: - unsigned minStatus_; - double dR_; - int verbosity_; - bool extrapolateToECalEntrance_; + const unsigned minStatus_; + const double dR2_; + const bool extrapolateToECalEntrance_; + const int verbosity_; - PositionAtECalEntrance positionAtECalEntrance_; + PositionAtECalEntranceComputer positionAtECalEntrance_; void updateBadTowers(const edm::EventSetup&); - struct towerInfo { - towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) + struct TowerInfo { + TowerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) : id_(id), nBad_(nBad), maxStatus_(maxStatus), eta_(eta), phi_(phi) {} uint32_t id_; unsigned nBad_; @@ -55,14 +60,14 @@ class AntiElectronDeadECAL { double eta_; double phi_; }; - typedef ROOT::Math::LorentzVector > PolarLorentzVector; - std::vector badTowers_; + std::vector badTowers_; static const uint16_t statusMask_ = 0x1F; - uint32_t channelStatusId_cache_; - uint32_t caloGeometryId_cache_; - uint32_t idealGeometryId_cache_; + edm::ESWatcher channelStatusWatcher_; + edm::ESWatcher caloGeometryWatcher_; + edm::ESWatcher idealGeometryWatcher_; + bool isFirstEvent_; }; diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index aa368a63069c2..0a6473d62d6ad 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -23,7 +23,7 @@ #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/PatCandidates/interface/Electron.h" #include "DataFormats/PatCandidates/interface/PackedCandidate.h" -#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" #include "TMVA/Tools.h" #include "TMVA/Reader.h" @@ -167,7 +167,7 @@ class AntiElectronIDMVA6 { std::vector inputFilesToDelete_; - PositionAtECalEntrance positionAtECalEntrance_; + PositionAtECalEntranceComputer positionAtECalEntrance_; int verbosity_; }; diff --git a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h b/RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h similarity index 56% rename from RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h rename to RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h index d484296affe28..0b167c2568549 100644 --- a/RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h +++ b/RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h @@ -1,7 +1,7 @@ -#ifndef RecoTauTag_RecoTau_PositionAtECalEntrance_h -#define RecoTauTag_RecoTau_PositionAtECalEntrance_h +#ifndef RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h +#define RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h -/** \class PositionAtECalEntrance +/** \class PositionAtECalEntranceComputer * * Extrapolate particle (charged or neutral) to ECAL entrance, * in order to compute the distance of the tau to ECAL cracks and/or dead ECAL channels @@ -16,17 +16,18 @@ #include "FWCore/Framework/interface/EventSetup.h" #include "DataFormats/Candidate/interface/Candidate.h" -class PositionAtECalEntrance { +class PositionAtECalEntranceComputer { public: - PositionAtECalEntrance(); - ~PositionAtECalEntrance(); + PositionAtECalEntranceComputer(); + ~PositionAtECalEntranceComputer(); void beginEvent(const edm::EventSetup&); + //To do: it seems to more practical to put this to the ES reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const; private: double bField_z_; }; -#endif // RecoTauTag_RecoTau_PositionAtECalEntrance_h +#endif // RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h diff --git a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc deleted file mode 100644 index c62cfac51ea25..0000000000000 --- a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronDeadECAL.cc +++ /dev/null @@ -1,80 +0,0 @@ - -/** \class PATTauDiscriminationAgainstElectronDeadECAL - * - * Flag tau candidates reconstructed near dead ECAL channels, - * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator - * - * Adopted from RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc - * to enable computation of the discriminator on MiniAOD - * - * The motivation for this flag is this presentation: - * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 - * - * \authors Lauri Andreas Wendland, - * Christian Veelken - * - * - * - */ -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include -#include -#include "DataFormats/TauReco/interface/PFTau.h" -#include "DataFormats/TauReco/interface/PFTauFwd.h" -#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" - -class PATTauDiscriminationAgainstElectronDeadECAL : public PATTauDiscriminationProducerBase { -public: - explicit PATTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) - : PATTauDiscriminationProducerBase(cfg), - moduleLabel_(cfg.getParameter("@module_label")), - verbosity_(cfg.getParameter("verbosity")), - antiElectronDeadECAL_(cfg) {} - ~PATTauDiscriminationAgainstElectronDeadECAL() override {} - - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } - - double discriminate(const TauRef& tau) const override { - if (verbosity_) { - edm::LogPrint("PATTauAgainstEleDeadECAL") << ":"; - edm::LogPrint("PATTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PATTauAgainstEleDeadECAL") - << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); - } - double discriminator = 1.; - if (antiElectronDeadECAL_(tau.get())) { - discriminator = 0.; - } - if (verbosity_) { - edm::LogPrint("PATTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; - } - return discriminator; - } - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - std::string moduleLabel_; - int verbosity_; - - AntiElectronDeadECAL antiElectronDeadECAL_; -}; - -void PATTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // patTauDiscriminationAgainstElectronDeadECAL - edm::ParameterSetDescription desc; - - desc.add("dR", 0.08); - desc.add("minStatus", 12); - desc.add("extrapolateToECalEntrance", true); - desc.add("verbosity", 0); - - fillProducerDescriptions(desc); // inherited from the base-class - - descriptions.add("patTauDiscriminationAgainstElectronDeadECAL", desc); -} - -DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc deleted file mode 100644 index 7003d8f63be0d..0000000000000 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc +++ /dev/null @@ -1,77 +0,0 @@ - -/** \class PFRecoTauDiscriminationAgainstElectronDeadECAL - * - * Flag tau candidates reconstructed near dead ECAL channels, - * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator - * - * The motivation for this flag is this presentation: - * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 - * - * \authors Lauri Andreas Wendland, - * Christian Veelken - * - * - * - */ -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include -#include -#include "DataFormats/TauReco/interface/PFTau.h" -#include "DataFormats/TauReco/interface/PFTauFwd.h" -#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" - -class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase { -public: - explicit PFRecoTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) - : PFTauDiscriminationProducerBase(cfg), - moduleLabel_(cfg.getParameter("@module_label")), - verbosity_(cfg.getParameter("verbosity")), - antiElectronDeadECAL_(cfg) {} - ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override {} - - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } - - double discriminate(const reco::PFTauRef& tau) const override { - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << ":"; - edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PFTauAgainstEleDeadECAL") - << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); - } - double discriminator = 1.; - if (antiElectronDeadECAL_(tau.get())) { - discriminator = 0.; - } - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; - } - return discriminator; - } - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - std::string moduleLabel_; - int verbosity_; - - AntiElectronDeadECAL antiElectronDeadECAL_; -}; - -void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // pfRecoTauDiscriminationAgainstElectronDeadECAL - edm::ParameterSetDescription desc; - - desc.add("dR", 0.08); - desc.add("minStatus", 12); - desc.add("extrapolateToECalEntrance", true); - desc.add("verbosity", 0); - - fillProducerDescriptions(desc); // inherited from the base-class - - descriptions.add("pfRecoTauDiscriminationAgainstElectronDeadECAL", desc); -} - -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc new file mode 100644 index 0000000000000..2772823c9b12e --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -0,0 +1,100 @@ +/** \class TauDiscriminationAgainstElectronDeadECALBase + * + * Base class for producing PFTau and PATTau discriminators + * + * Flag tau candidates reconstructed near dead ECAL channels, + * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator + * + * The motivation for this flag is this presentation: + * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 + * + * \authors Lauri Andreas Wendland, + * Christian Veelken + * + * + * + */ +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" + +// helper function retrieve the correct tau type name +template +std::string getTauTypeNameString(bool capitalise) { + // this generic one shoudl never be called. + throw cms::Exception("TauDiscriminationAgainstElectronDeadECALBase") + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; +} +// template specialiazation to get the correct (PF/PAT)Tau type names +template <> +std::string getTauTypeNameString(bool capitalise) { + return capitalise ? "PFRecoTau" : "pfRecoTau"; +} +template <> +std::string getTauTypeNameString(bool capitalise) { + return capitalise ? "PATTau" : "patTau"; +} + +template +class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationProducerBase { +public: + typedef std::vector TauCollection; + typedef edm::Ref TauRef; + explicit TauDiscriminationAgainstElectronDeadECALBase(const edm::ParameterSet& cfg) + : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")), + verbosity_(cfg.getParameter("verbosity")), + antiElectronDeadECAL_(cfg) {} + ~TauDiscriminationAgainstElectronDeadECALBase() override {} + + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } + + double discriminate(const TauRef& tau) const override { + if (verbosity_) { + edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << "<"+getTauTypeNameString(true)+"AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + } + double discriminator = 1.; + if (antiElectronDeadECAL_(tau.get())) { + discriminator = 0.; + } + if (verbosity_) { + edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << "--> discriminator = " << discriminator; + } + return discriminator; + } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + std::string moduleLabel_; + int verbosity_; + + AntiElectronDeadECAL antiElectronDeadECAL_; +}; + +template +void TauDiscriminationAgainstElectronDeadECALBase::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + // {pfReco,pat}TauDiscriminationAgainstElectronDeadECAL + edm::ParameterSetDescription desc; + + desc.add("dR", 0.08); + desc.add("minStatus", 12); + desc.add("extrapolateToECalEntrance", true); + desc.add("verbosity", 0); + + TauDiscriminationProducerBase::fillProducerDescriptions(desc); // inherited from the base-class + + descriptions.add(getTauTypeNameString(false)+"DiscriminationAgainstElectronDeadECAL", desc);//base +} + +typedef TauDiscriminationAgainstElectronDeadECALBase PFRecoTauDiscriminationAgainstElectronDeadECAL; +typedef TauDiscriminationAgainstElectronDeadECALBase PATTauDiscriminationAgainstElectronDeadECAL; + +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); +DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py deleted file mode 100644 index ffda6d2d19b82..0000000000000 --- a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ /dev/null @@ -1,26 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants - -patTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( - "PATTauDiscriminationAgainstElectronDeadECAL", - - # tau collection to discriminate - PATTauProducer = cms.InputTag('slimmedTaus'), - - # require no specific prediscriminants when running on MiniAOD, - # assuming that loose tau decay mode (and hence leading track) selection is already applied during MiniAOD production - Prediscriminants = noPrediscriminants, - - # status flag indicating dead/masked ECAL crystals - minStatus = cms.uint32(12), - - # region around dead/masked ECAL crystals that is to be cut - dR = cms.double(0.08), - - # extrapolate leading track to ECAL or use tau direction at the primary event vertex - # in order to compute distance between tau and ECAL crystals - extrapolateToECalEntrance = cms.bool(True), - - verbosity = cms.int32(0) -) diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py deleted file mode 100644 index 92103b3aab06b..0000000000000 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ /dev/null @@ -1,27 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack - -pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( - "PFRecoTauDiscriminationAgainstElectronDeadECAL", - - # tau collection to discriminate - PFTauProducer = cms.InputTag('pfTauProducer'), - - # Require leading pion ensures that: - # 1) these is at least one track above threshold (0.5 GeV) in the signal cone - # 2) a track OR a pi-zero in the signal cone has pT > 5 GeV - Prediscriminants = requireLeadTrack, - - # status flag indicating dead/masked ECAL crystals - minStatus = cms.uint32(12), - - # region around dead/masked ECAL crystals that is to be cut - dR = cms.double(0.08), - - # extrapolate leading track to ECAL or use tau direction at the primary event vertex - # in order to compute distance between tau and ECAL crystals - extrapolateToECalEntrance = cms.bool(True), - - verbosity = cms.int32(0) -) diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc index 9a17522b186a1..94b804f4fc0ae 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -15,16 +15,7 @@ #include "DataFormats/Math/interface/deltaR.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include - -AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) : isFirstEvent_(true) { - minStatus_ = cfg.getParameter("minStatus"); - dR_ = cfg.getParameter("dR"); - - extrapolateToECalEntrance_ = cfg.getParameter("extrapolateToECalEntrance"); - - verbosity_ = cfg.getParameter("verbosity"); -} +AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) : minStatus_(cfg.getParameter("minStatus")), dR2_(std::pow(cfg.getParameter("dR"),2)), extrapolateToECalEntrance_(cfg.getParameter("extrapolateToECalEntrance")), verbosity_(cfg.getParameter("verbosity")), isFirstEvent_(true) {} AntiElectronDeadECAL::~AntiElectronDeadECAL() {} @@ -55,7 +46,7 @@ namespace { if (status >= minStatus) { const GlobalPoint& point = caloGeometry->getPosition(id); uint32_t key = ttMap->towerOf(id); - maxStatus[key] = TMath::Max(status, maxStatus[key]); + maxStatus[key] = std::max(status, maxStatus[key]); ++nBadCrystals[key]; sumEta[key] += point.eta(); sumPhi[key] += point.phi(); @@ -67,25 +58,19 @@ namespace { void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { // NOTE: modified version of SUSY CAF code // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - const uint32_t channelStatusId = es.get().cacheIdentifier(); - const uint32_t caloGeometryId = es.get().cacheIdentifier(); - const uint32_t idealGeometryId = es.get().cacheIdentifier(); - if (!isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && - idealGeometryId == idealGeometryId_cache_) + if (!isFirstEvent_ && !channelStatusWatcher_.check(es) && !caloGeometryWatcher_.check(es) && + !idealGeometryWatcher_.check(es)) return; edm::ESHandle channelStatus; es.get().get(channelStatus); - channelStatusId_cache_ = channelStatusId; edm::ESHandle caloGeometry; es.get().get(caloGeometry); - caloGeometryId_cache_ = caloGeometryId; edm::ESHandle ttMap; es.get().get(ttMap); - idealGeometryId_cache_ = idealGeometryId; std::map nBadCrystals, maxStatus; std::map sumEta, sumPhi; @@ -110,10 +95,10 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { statusMask_); badTowers_.clear(); - for (std::map::const_iterator it = nBadCrystals.begin(); it != nBadCrystals.end(); ++it) { - uint32_t key = it->first; + for (auto it : nBadCrystals) { + uint32_t key = it.first; badTowers_.push_back( - towerInfo(key, it->second, maxStatus[key], sumEta[key] / it->second, sumPhi[key] / it->second)); + TowerInfo(key, it.second, maxStatus[key], sumEta[key] / it.second, sumPhi[key] / it.second)); } isFirstEvent_ = false; @@ -156,11 +141,11 @@ bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const { << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; } } - for (std::vector::const_iterator badTower = badTowers_.begin(); badTower != badTowers_.end(); ++badTower) { - if (deltaR(badTower->eta_, badTower->phi_, tau_eta, tau_phi) < dR_) { + for (auto const & badTower : badTowers_) { + if (deltaR2(badTower.eta_, badTower.phi_, tau_eta, tau_phi) < dR2_) { if (verbosity_) { edm::LogPrint("TauAgainstEleDeadECAL") - << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_; + << " matches badTower: eta = " << badTower.eta_ << ", phi = " << badTower.phi_; } isNearBadTower = true; break; diff --git a/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc b/RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc similarity index 57% rename from RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc rename to RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc index e050511fe7cf4..aedab0dab18fb 100644 --- a/RecoTauTag/RecoTau/src/PositionAtECalEntrance.cc +++ b/RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc @@ -1,4 +1,4 @@ -#include "RecoTauTag/RecoTau/interface/PositionAtECalEntrance.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" @@ -6,20 +6,20 @@ #include -PositionAtECalEntrance::PositionAtECalEntrance() : bField_z_(-1.) {} +PositionAtECalEntranceComputer::PositionAtECalEntranceComputer() : bField_z_(-1.) {} -PositionAtECalEntrance::~PositionAtECalEntrance() {} +PositionAtECalEntranceComputer::~PositionAtECalEntranceComputer() {} -void PositionAtECalEntrance::beginEvent(const edm::EventSetup& es) { +void PositionAtECalEntranceComputer::beginEvent(const edm::EventSetup& es) { edm::ESHandle bField; es.get().get(bField); bField_z_ = bField->inTesla(GlobalPoint(0., 0., 0.)).z(); } -reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* particle, bool& success) const { +reco::Candidate::Point PositionAtECalEntranceComputer::operator()(const reco::Candidate* particle, bool& success) const { assert(bField_z_ != -1.); BaseParticlePropagator propagator = BaseParticlePropagator( - RawParticle(math::XYZTLorentzVector(particle->px(), particle->py(), particle->pz(), particle->energy()), + RawParticle(particle->p4(), math::XYZTLorentzVector(particle->vertex().x(), particle->vertex().y(), particle->vertex().z(), 0.), particle->charge()), 0., @@ -28,8 +28,7 @@ reco::Candidate::Point PositionAtECalEntrance::operator()(const reco::Candidate* propagator.propagateToEcalEntrance(false); reco::Candidate::Point position; if (propagator.getSuccess() != 0) { - position = reco::Candidate::Point( - propagator.particle().vertex().x(), propagator.particle().vertex().y(), propagator.particle().vertex().z()); + position = propagator.particle().vertex().Vect(); success = true; } else { success = false; From 08cc970a4f84bc7cf20cd9c604c5140021b2b4b9 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Thu, 14 May 2020 18:22:40 +0200 Subject: [PATCH 06/10] fixes from code checks --- ...auDiscriminationAgainstElectronDeadECAL.cc | 26 ++++++++++++------- .../RecoTau/src/AntiElectronDeadECAL.cc | 12 ++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc index 2772823c9b12e..f7c85141129f0 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -26,7 +26,7 @@ template std::string getTauTypeNameString(bool capitalise) { // this generic one shoudl never be called. throw cms::Exception("TauDiscriminationAgainstElectronDeadECALBase") - << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; } // template specialiazation to get the correct (PF/PAT)Tau type names template <> @@ -54,9 +54,10 @@ class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationPro double discriminate(const TauRef& tau) const override { if (verbosity_) { - edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << "<"+getTauTypeNameString(true)+"AgainstElectronDeadECAL::discriminate>:"; - edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") + edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") + << "<" + getTauTypeNameString(true) + "AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } double discriminator = 1.; @@ -64,7 +65,8 @@ class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationPro discriminator = 0.; } if (verbosity_) { - edm::LogPrint(getTauTypeNameString(true)+"AgainstEleDeadECAL") << "--> discriminator = " << discriminator; + edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") + << "--> discriminator = " << discriminator; } return discriminator; } @@ -79,7 +81,8 @@ class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationPro }; template -void TauDiscriminationAgainstElectronDeadECALBase::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void TauDiscriminationAgainstElectronDeadECALBase::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) { // {pfReco,pat}TauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; @@ -88,13 +91,16 @@ void TauDiscriminationAgainstElectronDeadECALBase::fi desc.add("extrapolateToECalEntrance", true); desc.add("verbosity", 0); - TauDiscriminationProducerBase::fillProducerDescriptions(desc); // inherited from the base-class + TauDiscriminationProducerBase::fillProducerDescriptions( + desc); // inherited from the base-class - descriptions.add(getTauTypeNameString(false)+"DiscriminationAgainstElectronDeadECAL", desc);//base + descriptions.add(getTauTypeNameString(false) + "DiscriminationAgainstElectronDeadECAL", desc); //base } -typedef TauDiscriminationAgainstElectronDeadECALBase PFRecoTauDiscriminationAgainstElectronDeadECAL; -typedef TauDiscriminationAgainstElectronDeadECALBase PATTauDiscriminationAgainstElectronDeadECAL; +typedef TauDiscriminationAgainstElectronDeadECALBase + PFRecoTauDiscriminationAgainstElectronDeadECAL; +typedef TauDiscriminationAgainstElectronDeadECALBase + PATTauDiscriminationAgainstElectronDeadECAL; DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc index 94b804f4fc0ae..080c333fcf01b 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -15,7 +15,12 @@ #include "DataFormats/Math/interface/deltaR.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) : minStatus_(cfg.getParameter("minStatus")), dR2_(std::pow(cfg.getParameter("dR"),2)), extrapolateToECalEntrance_(cfg.getParameter("extrapolateToECalEntrance")), verbosity_(cfg.getParameter("verbosity")), isFirstEvent_(true) {} +AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) + : minStatus_(cfg.getParameter("minStatus")), + dR2_(std::pow(cfg.getParameter("dR"), 2)), + extrapolateToECalEntrance_(cfg.getParameter("extrapolateToECalEntrance")), + verbosity_(cfg.getParameter("verbosity")), + isFirstEvent_(true) {} AntiElectronDeadECAL::~AntiElectronDeadECAL() {} @@ -97,8 +102,7 @@ void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { badTowers_.clear(); for (auto it : nBadCrystals) { uint32_t key = it.first; - badTowers_.push_back( - TowerInfo(key, it.second, maxStatus[key], sumEta[key] / it.second, sumPhi[key] / it.second)); + badTowers_.push_back(TowerInfo(key, it.second, maxStatus[key], sumEta[key] / it.second, sumPhi[key] / it.second)); } isFirstEvent_ = false; @@ -141,7 +145,7 @@ bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const { << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; } } - for (auto const & badTower : badTowers_) { + for (auto const& badTower : badTowers_) { if (deltaR2(badTower.eta_, badTower.phi_, tau_eta, tau_phi) < dR2_) { if (verbosity_) { edm::LogPrint("TauAgainstEleDeadECAL") From d1e19f2b7d3ebbc9a84cc00e50914718ad7f3795 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 19 May 2020 17:12:23 +0200 Subject: [PATCH 07/10] 2nd set of review comments --- .../interface/TauDiscriminationProducerBase.h | 13 ++--- ...auDiscriminationAgainstElectronDeadECAL.cc | 48 ++++++------------- .../src/TauDiscriminationProducerBase.cc | 19 ++++---- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h b/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h index cdf527c5af624..521b2ac1f29f0 100644 --- a/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h +++ b/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h @@ -93,6 +93,10 @@ class TauDiscriminationProducerBase : public edm::stream::EDProducer<> { static void fillProducerDescriptions(edm::ParameterSetDescription& desc); + /// helper method to retrieve tau type name, e.g. to build correct cfi getter + //string (i.e. PFTau/PATTauProducer) + static std::string getTauTypeString(); + protected: //value given to taus that fail prediscriminants double prediscriminantFailValue_; @@ -125,13 +129,4 @@ typedef TauDiscriminationProducerBase PATTauDiscriminationProducerBase; -/// helper function retrieve the correct cfi getter string (ie PFTauProducer) -//for this tau type -template -std::string getProducerString() { - // this generic one shoudl never be called. - // these are specialized in TauDiscriminationProducerBase.cc - throw cms::Exception("TauDiscriminationProducerBase") - << "Unsupported TauType used. You must use either PFTau or PATTau."; -} #endif diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc index f7c85141129f0..4a94dc614ca58 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -1,8 +1,7 @@ -/** \class TauDiscriminationAgainstElectronDeadECALBase +/** \class TauDiscriminationAgainstElectronDeadECAL * - * Base class for producing PFTau and PATTau discriminators - * - * Flag tau candidates reconstructed near dead ECAL channels, + * Template class for producing PFTau and PATTau discriminators which + * flag tau candidates reconstructed near dead ECAL channels, * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator * * The motivation for this flag is this presentation: @@ -21,43 +20,26 @@ #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" #include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" -// helper function retrieve the correct tau type name -template -std::string getTauTypeNameString(bool capitalise) { - // this generic one shoudl never be called. - throw cms::Exception("TauDiscriminationAgainstElectronDeadECALBase") - << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; -} -// template specialiazation to get the correct (PF/PAT)Tau type names -template <> -std::string getTauTypeNameString(bool capitalise) { - return capitalise ? "PFRecoTau" : "pfRecoTau"; -} -template <> -std::string getTauTypeNameString(bool capitalise) { - return capitalise ? "PATTau" : "patTau"; -} - template -class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationProducerBase { +class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProducerBase { public: typedef std::vector TauCollection; typedef edm::Ref TauRef; - explicit TauDiscriminationAgainstElectronDeadECALBase(const edm::ParameterSet& cfg) + explicit TauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter("@module_label")), verbosity_(cfg.getParameter("verbosity")), antiElectronDeadECAL_(cfg) {} - ~TauDiscriminationAgainstElectronDeadECALBase() override {} + ~TauDiscriminationAgainstElectronDeadECAL() override {} void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } double discriminate(const TauRef& tau) const override { if (verbosity_) { - edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") - << "<" + getTauTypeNameString(true) + "AgainstElectronDeadECAL::discriminate>:"; - edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") + edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") + << "<" + TauDiscriminationProducerBase::getTauTypeString() + "AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } double discriminator = 1.; @@ -65,7 +47,7 @@ class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationPro discriminator = 0.; } if (verbosity_) { - edm::LogPrint(getTauTypeNameString(true) + "AgainstEleDeadECAL") + edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") << "--> discriminator = " << discriminator; } return discriminator; @@ -81,7 +63,7 @@ class TauDiscriminationAgainstElectronDeadECALBase : public TauDiscriminationPro }; template -void TauDiscriminationAgainstElectronDeadECALBase::fillDescriptions( +void TauDiscriminationAgainstElectronDeadECAL::fillDescriptions( edm::ConfigurationDescriptions& descriptions) { // {pfReco,pat}TauDiscriminationAgainstElectronDeadECAL edm::ParameterSetDescription desc; @@ -94,12 +76,12 @@ void TauDiscriminationAgainstElectronDeadECALBase::fi TauDiscriminationProducerBase::fillProducerDescriptions( desc); // inherited from the base-class - descriptions.add(getTauTypeNameString(false) + "DiscriminationAgainstElectronDeadECAL", desc); //base + descriptions.addWithDefaultLabel(desc); } -typedef TauDiscriminationAgainstElectronDeadECALBase +typedef TauDiscriminationAgainstElectronDeadECAL PFRecoTauDiscriminationAgainstElectronDeadECAL; -typedef TauDiscriminationAgainstElectronDeadECALBase +typedef TauDiscriminationAgainstElectronDeadECAL PATTauDiscriminationAgainstElectronDeadECAL; DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc index c114f0680f0d0..a21fe26fc838c 100644 --- a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc +++ b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc @@ -40,7 +40,7 @@ TauDiscriminationProducerBase("@module_label")) { // tau collection to discriminate - TauProducer_ = iConfig.getParameter(getProducerString()); + TauProducer_ = iConfig.getParameter(getTauTypeString()+"Producer"); Tau_token = consumes(TauProducer_); // prediscriminant operator @@ -172,7 +172,7 @@ template :: fillProducerDescriptions(edm::ParameterSetDescription& desc) { // helper function, it fills the description of the Producers parameter - desc.add(getProducerString(), edm::InputTag("fixme")); + desc.add(getTauTypeString()+"Producer", edm::InputTag("fixme")); { edm::ParameterSetDescription pset_prediscriminants; pset_prediscriminants.add("BooleanOperator", "AND"); @@ -191,14 +191,13 @@ void TauDiscriminationProducerBase -std::string getProducerString() { - return "PFTauProducer"; -} -template <> -std::string getProducerString() { - return "PATTauProducer"; +template +std::string TauDiscriminationProducerBase:: + getTauTypeString() { + if(std::is_same::value) return "PFTau"; + if(std::is_same::value) return "PATTau"; + throw cms::Exception("TauDiscriminationProducerBase") + << "Unsupported TauType used. You must use either PFTau or PATTau."; } // compile our desired types and make available to linker From 407f38cab5afb10dc6af27c73a465e04903feab3 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 19 May 2020 17:35:44 +0200 Subject: [PATCH 08/10] code-checks fixes --- .../TauDiscriminationAgainstElectronDeadECAL.cc | 6 ++++-- .../RecoTau/src/TauDiscriminationProducerBase.cc | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc index 4a94dc614ca58..2905fb0401124 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -37,8 +37,10 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce double discriminate(const TauRef& tau) const override { if (verbosity_) { edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") - << "<" + TauDiscriminationProducerBase::getTauTypeString() + "AgainstElectronDeadECAL::discriminate>:"; - edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + << "<" + TauDiscriminationProducerBase::getTauTypeString() + + "AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") + << " moduleLabel = " << moduleLabel_; edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } diff --git a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc index a21fe26fc838c..50d25e568e6cd 100644 --- a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc +++ b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc @@ -40,7 +40,7 @@ TauDiscriminationProducerBase("@module_label")) { // tau collection to discriminate - TauProducer_ = iConfig.getParameter(getTauTypeString()+"Producer"); + TauProducer_ = iConfig.getParameter(getTauTypeString() + "Producer"); Tau_token = consumes(TauProducer_); // prediscriminant operator @@ -172,7 +172,7 @@ template :: fillProducerDescriptions(edm::ParameterSetDescription& desc) { // helper function, it fills the description of the Producers parameter - desc.add(getTauTypeString()+"Producer", edm::InputTag("fixme")); + desc.add(getTauTypeString() + "Producer", edm::InputTag("fixme")); { edm::ParameterSetDescription pset_prediscriminants; pset_prediscriminants.add("BooleanOperator", "AND"); @@ -192,12 +192,14 @@ void TauDiscriminationProducerBase -std::string TauDiscriminationProducerBase:: - getTauTypeString() { - if(std::is_same::value) return "PFTau"; - if(std::is_same::value) return "PATTau"; +std::string +TauDiscriminationProducerBase::getTauTypeString() { + if (std::is_same::value) + return "PFTau"; + if (std::is_same::value) + return "PATTau"; throw cms::Exception("TauDiscriminationProducerBase") - << "Unsupported TauType used. You must use either PFTau or PATTau."; + << "Unsupported TauType used. You must use either PFTau or PATTau."; } // compile our desired types and make available to linker From 5c27ac19cbcac0413a09e5c70461907b9c790007 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Wed, 20 May 2020 13:21:53 +0200 Subject: [PATCH 09/10] use "this" instead of prefix --- .../TauDiscriminationAgainstElectronDeadECAL.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc index 2905fb0401124..c0433ff38fe4b 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -36,12 +36,12 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce double discriminate(const TauRef& tau) const override { if (verbosity_) { - edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") - << "<" + TauDiscriminationProducerBase::getTauTypeString() + + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") + << "<" + this->getTauTypeString() + "AgainstElectronDeadECAL::discriminate>:"; - edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } double discriminator = 1.; @@ -49,7 +49,7 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce discriminator = 0.; } if (verbosity_) { - edm::LogPrint(TauDiscriminationProducerBase::getTauTypeString() + "AgainstEleDeadECAL") + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << "--> discriminator = " << discriminator; } return discriminator; From 84762b7b9999e9239444467d40cba6cf3d13bca1 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Wed, 20 May 2020 13:40:33 +0200 Subject: [PATCH 10/10] code-format fix --- .../plugins/TauDiscriminationAgainstElectronDeadECAL.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc index c0433ff38fe4b..578a232bb1d67 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -37,10 +37,8 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce double discriminate(const TauRef& tau) const override { if (verbosity_) { edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") - << "<" + this->getTauTypeString() + - "AgainstElectronDeadECAL::discriminate>:"; - edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") - << " moduleLabel = " << moduleLabel_; + << "<" + this->getTauTypeString() + "AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); } @@ -49,8 +47,7 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce discriminator = 0.; } if (verbosity_) { - edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") - << "--> discriminator = " << discriminator; + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << "--> discriminator = " << discriminator; } return discriminator; }