Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anti-electron tauID for phase2 #31470

Merged
merged 26 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
af27465
Add electron collection merger
mbluj Jul 14, 2020
18025e9
Phase-2 anti-e MVA payloads
mbluj May 29, 2020
1c5def0
Change electron merger name
mbluj Jul 14, 2020
483badf
initial versions of cffs for phase2 anti-e
mbluj Jul 16, 2020
be8750d
updated cff for anti-e phase2
mbluj Aug 26, 2020
09eab8d
Propagate to HGCal instead of EndcapECal for phase2
mbluj Aug 26, 2020
c88b134
select electrons from multiCl outside barrel and with pt>10GeV
mbluj Sep 1, 2020
1d09b8e
Add support for anti-e phase2 MVA6
mbluj Sep 8, 2020
7e6c3a4
rename cffs for phase2 anti-e MVA6 tauID
mbluj Sep 11, 2020
7047f3b
Define phase2 electronId sources for anti-e MVA6 discriminant
mbluj Sep 11, 2020
bbcfde9
Enable use of phase2 electronId sources for anti-e MVA6 discriminant
mbluj Sep 14, 2020
99de1af
Add WPs of phase2 anti-e MVA6 tauID
mbluj Sep 15, 2020
6f9cb82
Skip computation of unused variables
mbluj Sep 15, 2020
a444e66
Add phase2 anti-e MVA6 tauID to tauID python configuration tool
mbluj Sep 15, 2020
03739f8
Enable phase2 anti-e tauID in miniAOD sequences
mbluj Sep 15, 2020
f8ba5b3
PositionAtECalEntranceComputer: set phase2 flag in C-tor
mbluj Sep 16, 2020
60799fd
Move electron collection mergers to CommonTools/RecoAlgos
mbluj Sep 24, 2020
c8733a3
1st bunch of review comments: mostly code style
mbluj Sep 24, 2020
32b6a3e
Define common setings for anti-e phase2 in one cff
mbluj Sep 24, 2020
a1c9770
Helper function to get track from PFCand
mbluj Sep 24, 2020
da529a1
Switch in description allowing phase-2 configs only in phase-2 era
mbluj Sep 28, 2020
eadcf0f
Migrate PositionAtECalEntranceComputer to use esConsumes
mbluj Sep 29, 2020
daed709
use dict instead of PSet to define anit-e phase2 default payloads
mbluj Oct 15, 2020
2ad8a7b
set of small improvement from code review
mbluj Oct 15, 2020
5363318
Use BaseParticlePropagator also for propagation to HGCal for phase-2
mbluj Oct 16, 2020
9277c0b
small simplification
mbluj Oct 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CommonTools/RecoAlgos/plugins/ElectronCollectionMerger.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* \class ElectronCollectionMerger
*
* Producer of merged Electron collection
*
* \author: Michal Bluj, NCBJ, Poland
*
*/
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CommonTools/UtilAlgos/interface/Merger.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/PatCandidates/interface/Electron.h"

typedef Merger<reco::GsfElectronCollection> GsfElectronCollectionMerger;
DEFINE_FWK_MODULE(GsfElectronCollectionMerger);

typedef Merger<pat::ElectronCollection> PATElectronCollectionMerger;
DEFINE_FWK_MODULE(PATElectronCollectionMerger);
3 changes: 2 additions & 1 deletion PhysicsTools/PatAlgos/plugins/PATTauProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ PATTauProducer::PATTauProducer(const edm::ParameterSet& iConfig)
: edm::ParameterSet(),
consumesCollector(),
false),
useUserData_(iConfig.exists("userData")) {
useUserData_(iConfig.exists("userData")),
posAtECalEntranceComputer_(consumesCollector()) {
firstOccurence_ = true;
// initialize the configurables
baseTauToken_ = consumes<edm::View<reco::BaseTau>>(iConfig.getParameter<edm::InputTag>("tauSource"));
Expand Down
7 changes: 6 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def miniAOD_customizeCommon(process):
toKeep = ['deepTau2017v2p1']
)
from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA
phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau MVA
phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA
phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('againstElePhase2v1')) #Phase2 Tau anti-e MVA
tauIdEmbedder.runTauID()
addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task)
delattr(process, 'slimmedTaus')
Expand All @@ -374,6 +375,10 @@ def miniAOD_customizeCommon(process):
process.rerunDiscriminationByIsolationMVADBnewDMwLTPhase2raw.PATTauProducer=_noUpdatedTauName
process.rerunDiscriminationByIsolationMVADBnewDMwLTPhase2.PATTauProducer=_noUpdatedTauName
task.add(process.rerunIsolationMVADBnewDMwLTPhase2Task)
if 'againstElePhase2v1' in tauIdEmbedder.toKeep:
process.patTauDiscriminationByElectronRejectionMVA6Phase2v1Raw.PATTauProducer=_noUpdatedTauName
process.patTauDiscriminationByElectronRejectionMVA6Phase2v1.PATTauProducer=_noUpdatedTauName
task.add(process.patTauDiscriminationByElectronRejectionMVA6Phase2v1Task)
Comment on lines 375 to +381
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be done in phase2_common.toModify( ?
if there is a chance that the list of IDs will grow, it would be better to factor out these calls to a python function, preferably, defined in the same place where all these modules are defined as well. This will decrease unnecessary bloat of the master miniAOD_tools

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage of condition if was selected in similar case with other tauID, please check discussion following this: #30341 (comment).
An alternative way would be direct import of definitions for a cff w/o use of runTauID python tool, but not necessarily simpler.


#-- Rerun tauID against dead ECal towers to taus for the various re-MiniAOD eras
# to enable default behoviour with leading track extrapolation to ECAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,41 @@
label = cms.untracked.string("RecoTauTag_antiElectronMVA6%s_%s_WP%s" % (antiElectronDiscrMVA6_2017_version, gbrForestName, WP))
)
)


# MVA6 phase2
antiElectronDiscrMVA_phase2_categories = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the plan was to phase out use of this *FromPrepDB
@cms-sw/alca-l2 , what's your take?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cfi is kept for testing purposes and we would like to have it complete. Additionally what concerns this particular tauID we are still in process with adding it to phase2 GlobalTags.

'0' : "gbr_NoEleMatch_woGwoGSF_BL",
'2' : "gbr_NoEleMatch_wGwoGSF_BL",
'5' : "gbr_woGwGSF_BL",
'7' : "gbr_wGwGSF_BL",
'8' : "gbr_NoEleMatch_woGwoGSF_FWEC",
'9' : "gbr_NoEleMatch_woGwoGSF_VFWEC",
'10' : "gbr_NoEleMatch_wGwoGSF_FWEC",
'11' : "gbr_NoEleMatch_wGwoGSF_VFWEC",
'13' : "gbr_woGwGSF_FWEC",
'14' : "gbr_woGwGSF_VFWEC",
'15' : "gbr_wGwGSF_FWEC",
'16' : "gbr_wGwGSF_VFWEC"
}
antiElectronDiscrMVA_phase2_WPs = [ "Eff98", "Eff90", "Eff80", "Eff70", "Eff60" ]
antiElectronDiscrMVA_phase2_version = "v1"
for category, gbrForestName in antiElectronDiscrMVA_phase2_categories.items():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('GBRWrapperRcd'),
tag = cms.string("RecoTauTag_antiElectronPhase2MVA6%s_%s" % (antiElectronDiscrMVA_phase2_version, gbrForestName)),
label = cms.untracked.string("RecoTauTag_antiElectronPhase2MVA6%s_%s" % (antiElectronDiscrMVA_phase2_version, gbrForestName))
)
)
for WP in antiElectronDiscrMVA_phase2_WPs:
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('PhysicsTGraphPayloadRcd'),
tag = cms.string("RecoTauTag_antiElectronPhase2MVA6%s_%s_WP%s" % (antiElectronDiscrMVA_phase2_version, gbrForestName, WP)),
label = cms.untracked.string("RecoTauTag_antiElectronPhase2MVA6%s_%s_WP%s" % (antiElectronDiscrMVA_phase2_version, gbrForestName, WP))
)
)

####
# register anti-muon discriminator MVA
antiMuonDiscrMVA_WPs = [ "eff99_5", "eff99_0", "eff98_0" ]
Expand Down
2 changes: 2 additions & 0 deletions RecoTauTag/RecoTau/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<use name="MagneticField/Engine"/>
<use name="MagneticField/Records"/>
<use name="Geometry/CaloTopology"/>
<use name="Geometry/CaloGeometry"/>
<use name="CondFormats/EgammaObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/EcalObjects"/>
Expand All @@ -22,6 +23,7 @@
<use name="PhysicsTools/JetMCUtils"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/BaseParticlePropagator"/>
<use name="RecoLocalCalo/HGCalRecAlgos"/>
<use name="roottmva"/>
<use name="PhysicsTools/TensorFlow"/>
<export>
Expand Down
2 changes: 1 addition & 1 deletion RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IdealGeometryRecord;

class AntiElectronDeadECAL {
public:
explicit AntiElectronDeadECAL(const edm::ParameterSet&);
explicit AntiElectronDeadECAL(const edm::ParameterSet&, edm::ConsumesCollector&&);
~AntiElectronDeadECAL();

void beginEvent(const edm::EventSetup&);
Expand Down
90 changes: 72 additions & 18 deletions RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"

#include "DataFormats/TauReco/interface/PFTau.h"
Expand Down Expand Up @@ -84,44 +85,80 @@ namespace antiElecIDMVA6_blocks {
float mvaInSigmaEtaEta = 0;
float mvaInHadEnergy = 0;
float mvaInDeltaEta = 0;
float eSeedClusterOverPout = 0;
float superClusterEtaWidth = 0;
float superClusterPhiWidth = 0;
float sigmaIEtaIEta5x5 = 0;
float sigmaIPhiIPhi5x5 = 0;
float showerCircularity = 0;
float r9 = 0;
float hgcalSigmaUU = 0;
float hgcalSigmaVV = 0;
float hgcalSigmaEE = 0;
float hgcalSigmaPP = 0;
float hgcalNLayers = 0;
float hgcalFirstLayer = 0;
float hgcalLastLayer = 0;
float hgcalLayerEfrac10 = 0;
float hgcalLayerEfrac90 = 0;
float hgcalEcEnergyEE = 0;
float hgcalEcEnergyFH = 0;
float hgcalMeasuredDepth = 0;
float hgcalExpectedDepth = 0;
float hgcalExpectedSigma = 0;
float hgcalDepthCompatibility = 0;
};
} // namespace antiElecIDMVA6_blocks

template <class TauType, class ElectronType>
class AntiElectronIDMVA6 {
public:
AntiElectronIDMVA6(const edm::ParameterSet&);
typedef std::vector<ElectronType> ElectronCollection;
typedef edm::Ref<ElectronCollection> ElectronRef;

AntiElectronIDMVA6(const edm::ParameterSet&, edm::ConsumesCollector&&);
~AntiElectronIDMVA6();

void beginEvent(const edm::Event&, const edm::EventSetup&);

double MVAValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
double mvaValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
const antiElecIDMVA6_blocks::TauGammaVecs& tauGammaVecs,
const antiElecIDMVA6_blocks::ElecVars& elecVars);

double MVAValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
double mvaValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
const antiElecIDMVA6_blocks::TauGammaMoms& tauGammaMoms,
const antiElecIDMVA6_blocks::ElecVars& elecVars);

double mvaValuePhase2(const antiElecIDMVA6_blocks::TauVars& tauVars,
const antiElecIDMVA6_blocks::TauGammaMoms& tauGammaMoms,
const antiElecIDMVA6_blocks::ElecVars& elecVars);

// this function can be called for all categories
double MVAValue(const TauType& theTau, const ElectronType& theEle);
double mvaValue(const TauType& theTau, const ElectronRef& theEleRef);
// this function can be called for category 1 only !!
double MVAValue(const TauType& theTau);
double mvaValue(const TauType& theTau);

// overloaded method with explicit tau type to avoid partial imlementation of full class
antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const reco::PFTau& theTau);
antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const pat::Tau& theTau);
antiElecIDMVA6_blocks::TauVars getTauVars(const TauType& theTau);
antiElecIDMVA6_blocks::TauGammaVecs getTauGammaVecs(const TauType& theTau);
antiElecIDMVA6_blocks::ElecVars getElecVars(const ElectronType& theEle);

// 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);
antiElecIDMVA6_blocks::ElecVars getElecVars(const ElectronRef& theEleRef);
// overloaded method with explicit electron type to avoid partial imlementation of full class
void getElecVarsHGCalTypeSpecific(const reco::GsfElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars);
void getElecVarsHGCalTypeSpecific(const pat::ElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars);

private:
double dCrackEta(double eta);
double minimum(double a, double b);
double dCrackPhi(double phi, double eta);
bool energyWeightedEtaAndPhiAtECal(
const pat::Tau& theTau,
float& eta,
float& phi); // MB: needed only for pat::Tau and called within pat::Tau specific method so also pat::Tau specific

static constexpr float ecalBarrelEndcapEtaBorder_ = 1.479;
static constexpr float ecalEndcapVFEndcapEtaBorder_ = 2.4;

bool isInitialized_;
bool loadMVAfromDB_;
Expand All @@ -135,17 +172,25 @@ class AntiElectronIDMVA6 {
std::string mvaName_NoEleMatch_wGwoGSF_EC_;
std::string mvaName_woGwGSF_EC_;
std::string mvaName_wGwGSF_EC_;
std::string mvaName_NoEleMatch_woGwoGSF_VFEC_;
std::string mvaName_NoEleMatch_wGwoGSF_VFEC_;
std::string mvaName_woGwGSF_VFEC_;
std::string mvaName_wGwGSF_VFEC_;

bool usePhiAtEcalEntranceExtrapolation_;

float* Var_NoEleMatch_woGwoGSF_Barrel_;
float* Var_NoEleMatch_wGwoGSF_Barrel_;
float* Var_woGwGSF_Barrel_;
float* Var_wGwGSF_Barrel_;
float* Var_NoEleMatch_woGwoGSF_Endcap_;
float* Var_NoEleMatch_wGwoGSF_Endcap_;
float* Var_woGwGSF_Endcap_;
float* Var_wGwGSF_Endcap_;
std::vector<float> var_NoEleMatch_woGwoGSF_Barrel_;
std::vector<float> var_NoEleMatch_wGwoGSF_Barrel_;
std::vector<float> var_woGwGSF_Barrel_;
std::vector<float> var_wGwGSF_Barrel_;
std::vector<float> var_NoEleMatch_woGwoGSF_Endcap_;
std::vector<float> var_NoEleMatch_wGwoGSF_Endcap_;
std::vector<float> var_woGwGSF_Endcap_;
std::vector<float> var_wGwGSF_Endcap_;
std::vector<float> var_NoEleMatch_woGwoGSF_VFEndcap_;
std::vector<float> var_NoEleMatch_wGwoGSF_VFEndcap_;
std::vector<float> var_woGwGSF_VFEndcap_;
std::vector<float> var_wGwGSF_VFEndcap_;

const GBRForest* mva_NoEleMatch_woGwoGSF_BL_;
const GBRForest* mva_NoEleMatch_wGwoGSF_BL_;
Expand All @@ -155,12 +200,21 @@ class AntiElectronIDMVA6 {
const GBRForest* mva_NoEleMatch_wGwoGSF_EC_;
const GBRForest* mva_woGwGSF_EC_;
const GBRForest* mva_wGwGSF_EC_;
const GBRForest* mva_NoEleMatch_woGwoGSF_VFEC_;
const GBRForest* mva_NoEleMatch_wGwoGSF_VFEC_;
const GBRForest* mva_woGwGSF_VFEC_;
const GBRForest* mva_wGwGSF_VFEC_;

std::vector<TFile*> inputFilesToDelete_;

const bool isPhase2_;

PositionAtECalEntranceComputer positionAtECalEntrance_;

int verbosity_;
std::map<std::string, edm::EDGetTokenT<edm::ValueMap<float>>> electronIds_tokens_;
std::map<std::string, edm::Handle<edm::ValueMap<float>>> electronIds_;

const int verbosity_;
};

#endif
16 changes: 15 additions & 1 deletion RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
*/

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"

class MagneticField;
class IdealMagneticFieldRecord;

class PositionAtECalEntranceComputer {
public:
PositionAtECalEntranceComputer();
PositionAtECalEntranceComputer(edm::ConsumesCollector&&, bool isPhase2 = false);
PositionAtECalEntranceComputer(edm::ConsumesCollector&, bool isPhase2 = false);
~PositionAtECalEntranceComputer();

void beginEvent(const edm::EventSetup&);
Expand All @@ -27,7 +34,14 @@ class PositionAtECalEntranceComputer {
reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const;

private:
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> bField_esToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeo_esToken_;
double bField_z_;
bool isPhase2_;
hgcal::RecHitTools recHitTools_;
float hgcalFace_z_;
static constexpr float ecalBarrelEndcapEtaBorder_ = 1.479;
static constexpr float hgcalHfEtaBorder_ = 3.0;
};

#endif // RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProduce
: TauDiscriminationProducerBase<TauType, TauDiscriminator>::TauDiscriminationProducerBase(cfg),
moduleLabel_(cfg.getParameter<std::string>("@module_label")),
verbosity_(cfg.getParameter<int>("verbosity")),
antiElectronDeadECAL_(cfg) {}
antiElectronDeadECAL_(cfg, edm::EDConsumerBase::consumesCollector()) {}
~TauDiscriminationAgainstElectronDeadECAL() override {}

void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); }
Expand Down
Loading