From 4559f4e3de684a457e3c4c374583f836f1935abb Mon Sep 17 00:00:00 2001 From: Swagata Mukherjee Date: Tue, 31 Jul 2018 23:50:11 +0200 Subject: [PATCH 01/13] Cutbased photonID Fall17 V2 --- ...e03_pfChargedHadrons_90percentBased_V2.txt | 9 + ...e03_pfNeutralHadrons_90percentBased_V2.txt | 9 + ...ons_cone03_pfPhotons_90percentBased_V2.txt | 9 + .../cutBasedPhotonID_Fall17_100X_V2_cff.py | 154 ++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt create mode 100644 RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt create mode 100644 RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt create mode 100644 RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt new file mode 100644 index 0000000000000..1dc879b16581c --- /dev/null +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt @@ -0,0 +1,9 @@ +# The constants are based on 90% contours of isolation. +# |eta| min |eta| max effective area +0.0000 1.0000 0.0404 +1.0000 1.4790 0.0396 +1.4790 2.0000 0.0364 +2.0000 2.2000 0.0353 +2.2000 2.3000 0.0351 +2.3000 2.4000 0.0347 +2.4000 5.0000 0.0337 diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt new file mode 100644 index 0000000000000..970f1f659429d --- /dev/null +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt @@ -0,0 +1,9 @@ +# The constants are based on 90% contours of isolation. +# |eta| min |eta| max effective area +0.0000 1.0000 0.067 +1.0000 1.4790 0.105 +1.4790 2.0000 0.079 +2.0000 2.2000 0.023 +2.2000 2.3000 0.008 +2.3000 2.4000 0.003 +2.4000 5.0000 0.014 diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt new file mode 100644 index 0000000000000..83419bef02fee --- /dev/null +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt @@ -0,0 +1,9 @@ +# The constants are based on 90% contours of isolation. +# |eta| min |eta| max effective area +0.0000 1.0000 0.111 +1.0000 1.4790 0.095 +1.4790 2.0000 0.062 +2.0000 2.2000 0.084 +2.2000 2.3000 0.107 +2.3000 2.4000 0.121 +2.4000 5.0000 0.147 diff --git a/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py new file mode 100644 index 0000000000000..863c12c243f59 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py @@ -0,0 +1,154 @@ +from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry + +import FWCore.ParameterSet.Config as cms + +# Common functions and classes for ID definition are imported here: +from RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_tools \ + import ( WorkingPoint_V2, + IsolationCutInputs, + configureVIDCutBasedPhoID_V5 ) + +# The cut values are taken from the twiki: +# https://twiki.cern.ch/twiki/bin/viewauth/CMS/CutBasedPhotonIdentificationRun2 +# (where they may not stay, if a newer version of cuts becomes available for these +# conditions) + +# See also the presentation explaining these working points (this will not change): +# https://indico.cern.ch/event/732974/contributions/3072291/attachments/1685029/2709189/PhotonIDStudy.pdf + + +# +# First, define cut values +# + +# Loose working point Barrel and Endcap +idName = "cutBasedPhotonID-Fall17-100X-V2-loose" +WP_Loose_EB = WorkingPoint_V2( + idName , # idName + 0.0313 , # hOverECut + 0.0108 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 1.272 , # absPFChaHadIsoWithEACut_C1 + 0 , # absPFChaHadIsoWithEACut_C2 + 8.3828 , # absPFNeuHadIsoWithEACut_C1 + 0.01512 , # absPFNeuHadIsoWithEACut_C2 + 0.00002259 , # absPFNeuHadIsoWithEACut_C3 + 4.2891 , # absPFPhoIsoWithEACut_C1 + 0.004017 # absPFPhoIsoWithEACut_C2 + ) +WP_Loose_EE = WorkingPoint_V2( + idName , #idName + 0.0431 , # hOverECut + 0.0281 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 1.4449 , # absPFChaHadIsoWithEACut_C1 + 0.00 , # absPFChaHadIsoWithEACut_C2 + 13.6894 , # absPFNeuHadIsoWithEACut_C1 + 0.0117 , # absPFNeuHadIsoWithEACut_C2 + 0.000023 , # absPFNeuHadIsoWithEACut_C3 + 4.2969 , # absPFPhoIsoWithEACut_C1 + 0.0037 # absPFPhoIsoWithEACut_C2 + ) + +# Medium working point Barrel and Endcap +idName = "cutBasedPhotonID-Fall17-100X-V2-medium" +WP_Medium_EB = WorkingPoint_V2( + idName , # idName + 0.02 , # hOverECut + 0.01 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 0.6127 , # absPFChaHadIsoWithEACut_C1 + 0.00 , # absPFChaHadIsoWithEACut_C2 + 3.6265 , # absPFNeuHadIsoWithEACut_C1 + 0.01512 , # absPFNeuHadIsoWithEACut_C2 + 0.00002259 , # absPFNeuHadIsowithEACut_C3 + 2.3692 , # absPFPhoIsoWithEACut_C1 + 0.004017 # absPFPhoIsoWithEACut_C2 + ) + +WP_Medium_EE = WorkingPoint_V2( + idName , #idName + 0.0248 , # hOverECut + 0.0271 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 0.7981 , # absPFChaHadIsoWithEACut_C1 + 0.00 , # absPFChaHadIsoWithEACut_C2 + 2.3737 , # absPFNeuHadIsoWithEACut_C1 + 0.0117 , # absPFNeuHadIsoWithEACut_C2 + 0.000023 , # absPFNeuHadIsowithEACut_C3 + 3.1760 , # absPFPhoIsoWithEACut_C1 + 0.0037 # absPFPhoIsoWithEACut_C2 + ) + +# Tight working point Barrel and Endcap +idName = "cutBasedPhotonID-Fall17-100X-V2-tight" +WP_Tight_EB = WorkingPoint_V2( + idName , # idName + 0.02 , # hOverECut + 0.01 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 0.0939 , # absPFChaHadIsoWithEACut_C1 + 0.00 , # absPFChaHadIsoWithEACut_C2 + 3.6195 , # absPFNeuHadIsoWithEACut_C1 + 0.01512 , # absPFNeuHadIsoWithEACut_C2 + 0.00002259 , # absPFNeuHadIsowithEACut_C3 + 2.0018 , # absPFPhoIsoWithEACut_C1 + 0.004017 # absPFPhoIsoWithEACut_C2 + ) + +WP_Tight_EE = WorkingPoint_V2( + idName , #idName + 0.0219 , # hOverECut + 0.0268 , # full5x5_SigmaIEtaIEtaCut +# Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 + 0.2629 , # absPFChaHadIsoWithEACut_C1 + 0.00 , # absPFChaHadIsoWithEACut_C2 + 2.1436 , # absPFNeuHadIsoWithEACut_C1 + 0.0117 , # absPFNeuHadIsoWithEACut_C2 + 0.000023 , # absPFNeuHadIsowithEACut_C3 + 3.0133 , # absPFPhoIsoWithEACut_C1 + 0.0037 # absPFPhoIsoWithEACut_C2 + ) + + +# Second, define where to find the precomputed isolations and what effective +# areas to use for pile-up correction +isoInputs = IsolationCutInputs( + # chHadIsolationMapName + 'photonIDValueMapProducer:phoChargedIsolation' , + # chHadIsolationEffAreas + "RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt", + # neuHadIsolationMapName + 'photonIDValueMapProducer:phoNeutralHadronIsolation' , + # neuHadIsolationEffAreas + "RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt" , + # phoIsolationMapName + "photonIDValueMapProducer:phoPhotonIsolation" , + # phoIsolationEffAreas + "RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt" +) + +# +# Finally, set up VID configuration for all cuts +# +cutBasedPhotonID_Fall17_100X_V2_loose = configureVIDCutBasedPhoID_V5 ( WP_Loose_EB, WP_Loose_EE, isoInputs) +cutBasedPhotonID_Fall17_100X_V2_medium = configureVIDCutBasedPhoID_V5 ( WP_Medium_EB, WP_Medium_EE, isoInputs) +cutBasedPhotonID_Fall17_100X_V2_tight = configureVIDCutBasedPhoID_V5 ( WP_Tight_EB, WP_Tight_EE, isoInputs) + +## The MD5 sum numbers below reflect the exact set of cut variables +# and values above. If anything changes, one has to +# 1) comment out the lines below about the registry, +# 2) run "calculateMD5 +# 3) update the MD5 sum strings below and uncomment the lines again. +# + +central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_loose.idName, + '4578dfcceb0bfd1ba5ac28973c843fd0') +central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_medium.idName, + '28b186c301061395f394a81266c8d7de') +central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_tight.idName, + '6f4f0ed6a8bf2de8dcf0bc3349b0546d') + +cutBasedPhotonID_Fall17_100X_V2_loose.isPOGApproved = cms.untracked.bool(True) +cutBasedPhotonID_Fall17_100X_V2_medium.isPOGApproved = cms.untracked.bool(True) +cutBasedPhotonID_Fall17_100X_V2_tight.isPOGApproved = cms.untracked.bool(True) From 4bba6c70077132253a0959e570ad35759f4677cd Mon Sep 17 00:00:00 2001 From: Swagata Mukherjee Date: Tue, 18 Sep 2018 20:19:18 +0200 Subject: [PATCH 02/13] update phoID v2 cutbased --- ...e03_pfChargedHadrons_90percentBased_V2.txt | 14 ++--- ...e03_pfNeutralHadrons_90percentBased_V2.txt | 14 ++--- ...ons_cone03_pfPhotons_90percentBased_V2.txt | 14 ++--- .../cutBasedPhotonID_Fall17_100X_V2_cff.py | 60 +++++++++---------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt index 1dc879b16581c..a0835051ec5d8 100644 --- a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt @@ -1,9 +1,9 @@ # The constants are based on 90% contours of isolation. # |eta| min |eta| max effective area -0.0000 1.0000 0.0404 -1.0000 1.4790 0.0396 -1.4790 2.0000 0.0364 -2.0000 2.2000 0.0353 -2.2000 2.3000 0.0351 -2.3000 2.4000 0.0347 -2.4000 5.0000 0.0337 +0.0000 1.0000 0.0112 +1.0000 1.4790 0.0108 +1.4790 2.0000 0.0106 +2.0000 2.2000 0.01002 +2.2000 2.3000 0.0098 +2.3000 2.4000 0.0089 +2.4000 5.0000 0.0087 diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt index 970f1f659429d..41090422c318a 100644 --- a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt @@ -1,9 +1,9 @@ # The constants are based on 90% contours of isolation. # |eta| min |eta| max effective area -0.0000 1.0000 0.067 -1.0000 1.4790 0.105 -1.4790 2.0000 0.079 -2.0000 2.2000 0.023 -2.2000 2.3000 0.008 -2.3000 2.4000 0.003 -2.4000 5.0000 0.014 +0.0000 1.0000 0.0668 +1.0000 1.4790 0.1054 +1.4790 2.0000 0.0786 +2.0000 2.2000 0.0233 +2.2000 2.3000 0.0078 +2.3000 2.4000 0.0028 +2.4000 5.0000 0.0137 diff --git a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt index 83419bef02fee..7269ec2b79cb7 100644 --- a/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt +++ b/RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt @@ -1,9 +1,9 @@ # The constants are based on 90% contours of isolation. # |eta| min |eta| max effective area -0.0000 1.0000 0.111 -1.0000 1.4790 0.095 -1.4790 2.0000 0.062 -2.0000 2.2000 0.084 -2.2000 2.3000 0.107 -2.3000 2.4000 0.121 -2.4000 5.0000 0.147 +0.0000 1.0000 0.1113 +1.0000 1.4790 0.0953 +1.4790 2.0000 0.0619 +2.0000 2.2000 0.0837 +2.2000 2.3000 0.1070 +2.3000 2.4000 0.1212 +2.4000 5.0000 0.1466 diff --git a/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py index 863c12c243f59..22381750868ff 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py @@ -25,28 +25,28 @@ idName = "cutBasedPhotonID-Fall17-100X-V2-loose" WP_Loose_EB = WorkingPoint_V2( idName , # idName - 0.0313 , # hOverECut - 0.0108 , # full5x5_SigmaIEtaIEtaCut + 0.04596 , # hOverECut + 0.0106 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 1.272 , # absPFChaHadIsoWithEACut_C1 + 1.694 , # absPFChaHadIsoWithEACut_C1 0 , # absPFChaHadIsoWithEACut_C2 - 8.3828 , # absPFNeuHadIsoWithEACut_C1 + 24.032 , # absPFNeuHadIsoWithEACut_C1 0.01512 , # absPFNeuHadIsoWithEACut_C2 0.00002259 , # absPFNeuHadIsoWithEACut_C3 - 4.2891 , # absPFPhoIsoWithEACut_C1 + 2.876 , # absPFPhoIsoWithEACut_C1 0.004017 # absPFPhoIsoWithEACut_C2 ) WP_Loose_EE = WorkingPoint_V2( idName , #idName - 0.0431 , # hOverECut - 0.0281 , # full5x5_SigmaIEtaIEtaCut + 0.0590 , # hOverECut + 0.0272 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 1.4449 , # absPFChaHadIsoWithEACut_C1 + 2.089 , # absPFChaHadIsoWithEACut_C1 0.00 , # absPFChaHadIsoWithEACut_C2 - 13.6894 , # absPFNeuHadIsoWithEACut_C1 + 19.722 , # absPFNeuHadIsoWithEACut_C1 0.0117 , # absPFNeuHadIsoWithEACut_C2 0.000023 , # absPFNeuHadIsoWithEACut_C3 - 4.2969 , # absPFPhoIsoWithEACut_C1 + 4.162 , # absPFPhoIsoWithEACut_C1 0.0037 # absPFPhoIsoWithEACut_C2 ) @@ -54,29 +54,29 @@ idName = "cutBasedPhotonID-Fall17-100X-V2-medium" WP_Medium_EB = WorkingPoint_V2( idName , # idName - 0.02 , # hOverECut - 0.01 , # full5x5_SigmaIEtaIEtaCut + 0.02197 , # hOverECut + 0.01015 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 0.6127 , # absPFChaHadIsoWithEACut_C1 + 1.141 , # absPFChaHadIsoWithEACut_C1 0.00 , # absPFChaHadIsoWithEACut_C2 - 3.6265 , # absPFNeuHadIsoWithEACut_C1 + 1.189 , # absPFNeuHadIsoWithEACut_C1 0.01512 , # absPFNeuHadIsoWithEACut_C2 0.00002259 , # absPFNeuHadIsowithEACut_C3 - 2.3692 , # absPFPhoIsoWithEACut_C1 + 2.08 , # absPFPhoIsoWithEACut_C1 0.004017 # absPFPhoIsoWithEACut_C2 ) WP_Medium_EE = WorkingPoint_V2( idName , #idName - 0.0248 , # hOverECut - 0.0271 , # full5x5_SigmaIEtaIEtaCut + 0.0326 , # hOverECut + 0.0272 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 0.7981 , # absPFChaHadIsoWithEACut_C1 + 1.051 , # absPFChaHadIsoWithEACut_C1 0.00 , # absPFChaHadIsoWithEACut_C2 - 2.3737 , # absPFNeuHadIsoWithEACut_C1 + 2.718 , # absPFNeuHadIsoWithEACut_C1 0.0117 , # absPFNeuHadIsoWithEACut_C2 0.000023 , # absPFNeuHadIsowithEACut_C3 - 3.1760 , # absPFPhoIsoWithEACut_C1 + 3.867 , # absPFPhoIsoWithEACut_C1 0.0037 # absPFPhoIsoWithEACut_C2 ) @@ -84,29 +84,29 @@ idName = "cutBasedPhotonID-Fall17-100X-V2-tight" WP_Tight_EB = WorkingPoint_V2( idName , # idName - 0.02 , # hOverECut - 0.01 , # full5x5_SigmaIEtaIEtaCut + 0.02148 , # hOverECut + 0.00996 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 0.0939 , # absPFChaHadIsoWithEACut_C1 + 0.65 , # absPFChaHadIsoWithEACut_C1 0.00 , # absPFChaHadIsoWithEACut_C2 - 3.6195 , # absPFNeuHadIsoWithEACut_C1 + 0.317 , # absPFNeuHadIsoWithEACut_C1 0.01512 , # absPFNeuHadIsoWithEACut_C2 0.00002259 , # absPFNeuHadIsowithEACut_C3 - 2.0018 , # absPFPhoIsoWithEACut_C1 + 2.044 , # absPFPhoIsoWithEACut_C1 0.004017 # absPFPhoIsoWithEACut_C2 ) WP_Tight_EE = WorkingPoint_V2( idName , #idName - 0.0219 , # hOverECut - 0.0268 , # full5x5_SigmaIEtaIEtaCut + 0.0321 , # hOverECut + 0.0271 , # full5x5_SigmaIEtaIEtaCut # Isolation cuts are generally absIso < C1 + pt*C2, except for NeuHad is < C1 + pt*C2 + pt*pt*C3 - 0.2629 , # absPFChaHadIsoWithEACut_C1 + 0.517 , # absPFChaHadIsoWithEACut_C1 0.00 , # absPFChaHadIsoWithEACut_C2 - 2.1436 , # absPFNeuHadIsoWithEACut_C1 + 2.716 , # absPFNeuHadIsoWithEACut_C1 0.0117 , # absPFNeuHadIsoWithEACut_C2 0.000023 , # absPFNeuHadIsowithEACut_C3 - 3.0133 , # absPFPhoIsoWithEACut_C1 + 3.032 , # absPFPhoIsoWithEACut_C1 0.0037 # absPFPhoIsoWithEACut_C2 ) From cc33f7818c33515aee725f320aa7c6213d1373a0 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 16 Aug 2018 10:01:09 +0200 Subject: [PATCH 03/13] Fall17_94X_v2 MVA Photon ID --- .../PatAlgos/python/slimming/miniAOD_tools.py | 1 + .../mvaPhotonID_Fall17_94X_V2_cff.py | 55 +++++++++++++++++++ .../python/PhotonMVAValueMapProducer_cfi.py | 3 + .../PhotonIdentification/test/runtests.sh | 4 +- .../test/testPhotonMVA_cfg.py | 3 + 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 57dc96463ab7e..d30f7bc6eb314 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -320,6 +320,7 @@ def miniAOD_customizeCommon(process): photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff', 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff'] switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py new file mode 100644 index 0000000000000..9fce0619529e4 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py @@ -0,0 +1,55 @@ +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * +# +# In this file we define the locations of the MVA weights, cuts on the MVA values +# for specific working points, and configure those cuts in VID +# +# +# The following MVA is derived for Fall17 samples for photons. +# See more documentation in these presentations: +# https://indico.cern.ch/event/697079/contributions/2968123/attachments/1632966/2604131/PhotonID_EGM_13.04.2018.pdf +# +mvaTag = "RunIIFall17v2" +mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt" +mvaWeightFiles = [ + path.join(weightFileBaseDir, "Fall17/EB_V2.weights.xml.gz"), + path.join(weightFileBaseDir, "Fall17/EE_V2.weights.xml.gz"), + ] +# Set up the VID working point parameters +wpConfig = [ + # The working point for this MVA that is expected to have about 90% signal + # efficiency in each category for photons with pt>30 GeV (somewhat lower + # for lower pt photons). + {"idName" : "mvaPhoID-RunIIFall17-v2-wp90", + "cuts" : { "EB" : -0.02, + "EE" : -0.26 }}, + # The working point for this MVA that is expected to have about 90% signal + # efficiency in each category for photons with pt>30 GeV (somewhat lower + # for lower pt photons). + {"idName" : "mvaPhoID-RunIIFall17-v2-wp80", + "cuts" : { "EB" : 0.42, + "EE" : 0.14 }}, + ] +# Create the PSet that will be fed to the MVA value map producer and the +# VPset's for VID cuts +configs = configureFullVIDMVAPhoID(mvaTag=mvaTag, + variablesFile=mvaVariablesFile, + weightFiles=mvaWeightFiles, + wpConfig=wpConfig, + # Category parameters + nCategories = cms.int32(2), + categoryCuts = category_cuts) +mvaPhoID_RunIIFall17_v2_producer_config = configs["producer_config"] +mvaPhoID_RunIIFall17_v2_wp90 = configs["VID_config"]["mvaPhoID-RunIIFall17-v2-wp90"] +mvaPhoID_RunIIFall17_v2_wp80 = configs["VID_config"]["mvaPhoID-RunIIFall17-v2-wp80"] +# The MD5 sum numbers below reflect the exact set of cut variables +# and values above. If anything changes, one has to +# 1) comment out the lines below about the registry, +# 2) run "calculateIdMD5 +# 3) update the MD5 sum strings below and uncomment the lines again. +# +central_id_registry.register( mvaPhoID_RunIIFall17_v2_wp90.idName, + '5c06832759b1faf7dd6fc45ed1aef3a2') +central_id_registry.register( mvaPhoID_RunIIFall17_v2_wp80.idName, + '3013ddce7a3ad8b54827c29f5d92282e') +mvaPhoID_RunIIFall17_v2_wp90.isPOGApproved = cms.bool(True) +mvaPhoID_RunIIFall17_v2_wp80.isPOGApproved = cms.bool(True) diff --git a/RecoEgamma/PhotonIdentification/python/PhotonMVAValueMapProducer_cfi.py b/RecoEgamma/PhotonIdentification/python/PhotonMVAValueMapProducer_cfi.py index d9a9d95330a11..6bd60d9f32947 100644 --- a/RecoEgamma/PhotonIdentification/python/PhotonMVAValueMapProducer_cfi.py +++ b/RecoEgamma/PhotonIdentification/python/PhotonMVAValueMapProducer_cfi.py @@ -14,6 +14,9 @@ from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff import * mvaConfigsForPhoProducer.append( mvaPhoID_RunIIFall17_v1p1_producer_config ) +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff import * +mvaConfigsForPhoProducer.append( mvaPhoID_RunIIFall17_v2_producer_config ) + photonMVAValueMapProducer = cms.EDProducer('PhotonMVAValueMapProducer', # The module automatically detects AOD vs miniAOD, so we configure both # diff --git a/RecoEgamma/PhotonIdentification/test/runtests.sh b/RecoEgamma/PhotonIdentification/test/runtests.sh index a7be141b0f28c..fd94875bacee8 100755 --- a/RecoEgamma/PhotonIdentification/test/runtests.sh +++ b/RecoEgamma/PhotonIdentification/test/runtests.sh @@ -7,10 +7,12 @@ ids_to_test=( 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff' 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff' 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff' + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff' + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff' ) for id_set in "${ids_to_test[@]}"; do echo Checking: $id_set cmsRun ${LOCAL_TEST_DIR}/runPhoton_VID.py 1 $id_set || die "Failure using runPhoton_VID.py on AOD $id_set" $? cmsRun ${LOCAL_TEST_DIR}/runPhoton_VID.py 0 $id_set || die "Failure using runPhoton_VID.py on MiniAOD $id_set" $? -done \ No newline at end of file +done diff --git a/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py b/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py index fee6ae3cb7e45..d0d0f7aaa493c 100644 --- a/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py +++ b/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py @@ -38,6 +38,7 @@ 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff', ] #add them to the VID producer @@ -62,11 +63,13 @@ "photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values", "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1Values", "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values", + "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values", ), phoMVAValMapLabels = cms.untracked.vstring( "Spring16NonTrigV1", "Fall17v1", "Fall17v1p1", + "Fall17v2", ), phoMVACats = cms.untracked.vstring( "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1Categories", From b3ea443b1ae3ca19a185617268647f766ab19e60 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Mon, 17 Sep 2018 19:51:14 +0200 Subject: [PATCH 04/13] fix worst charged iso variable --- .../python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py index 9fce0619529e4..31f963ffd16b5 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py @@ -9,7 +9,7 @@ # https://indico.cern.ch/event/697079/contributions/2968123/attachments/1632966/2604131/PhotonID_EGM_13.04.2018.pdf # mvaTag = "RunIIFall17v2" -mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt" +mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt" mvaWeightFiles = [ path.join(weightFileBaseDir, "Fall17/EB_V2.weights.xml.gz"), path.join(weightFileBaseDir, "Fall17/EE_V2.weights.xml.gz"), From 7326dcda3621d3426656cba445267507e07e2da5 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Mon, 19 Nov 2018 16:05:00 +0100 Subject: [PATCH 05/13] Renamed cut based ID and put in MiniAOD --- .../PatAlgos/python/slimming/miniAOD_tools.py | 1 + ... => cutBasedPhotonID_Fall17_94X_V2_cff.py} | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) rename RecoEgamma/PhotonIdentification/python/Identification/{cutBasedPhotonID_Fall17_100X_V2_cff.py => cutBasedPhotonID_Fall17_94X_V2_cff.py} (86%) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index d30f7bc6eb314..6f36d926805be 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -318,6 +318,7 @@ def miniAOD_customizeCommon(process): #VID Photon IDs process.patPhotons.addPhotonID = cms.bool(True) photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff', + 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff', diff --git a/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_94X_V2_cff.py similarity index 86% rename from RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py rename to RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_94X_V2_cff.py index 22381750868ff..2bce2bd0feaa0 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_100X_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/cutBasedPhotonID_Fall17_94X_V2_cff.py @@ -22,7 +22,7 @@ # # Loose working point Barrel and Endcap -idName = "cutBasedPhotonID-Fall17-100X-V2-loose" +idName = "cutBasedPhotonID-Fall17-94X-V2-loose" WP_Loose_EB = WorkingPoint_V2( idName , # idName 0.04596 , # hOverECut @@ -51,7 +51,7 @@ ) # Medium working point Barrel and Endcap -idName = "cutBasedPhotonID-Fall17-100X-V2-medium" +idName = "cutBasedPhotonID-Fall17-94X-V2-medium" WP_Medium_EB = WorkingPoint_V2( idName , # idName 0.02197 , # hOverECut @@ -81,7 +81,7 @@ ) # Tight working point Barrel and Endcap -idName = "cutBasedPhotonID-Fall17-100X-V2-tight" +idName = "cutBasedPhotonID-Fall17-94X-V2-tight" WP_Tight_EB = WorkingPoint_V2( idName , # idName 0.02148 , # hOverECut @@ -131,9 +131,9 @@ # # Finally, set up VID configuration for all cuts # -cutBasedPhotonID_Fall17_100X_V2_loose = configureVIDCutBasedPhoID_V5 ( WP_Loose_EB, WP_Loose_EE, isoInputs) -cutBasedPhotonID_Fall17_100X_V2_medium = configureVIDCutBasedPhoID_V5 ( WP_Medium_EB, WP_Medium_EE, isoInputs) -cutBasedPhotonID_Fall17_100X_V2_tight = configureVIDCutBasedPhoID_V5 ( WP_Tight_EB, WP_Tight_EE, isoInputs) +cutBasedPhotonID_Fall17_94X_V2_loose = configureVIDCutBasedPhoID_V5 ( WP_Loose_EB, WP_Loose_EE, isoInputs) +cutBasedPhotonID_Fall17_94X_V2_medium = configureVIDCutBasedPhoID_V5 ( WP_Medium_EB, WP_Medium_EE, isoInputs) +cutBasedPhotonID_Fall17_94X_V2_tight = configureVIDCutBasedPhoID_V5 ( WP_Tight_EB, WP_Tight_EE, isoInputs) ## The MD5 sum numbers below reflect the exact set of cut variables # and values above. If anything changes, one has to @@ -142,13 +142,13 @@ # 3) update the MD5 sum strings below and uncomment the lines again. # -central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_loose.idName, +central_id_registry.register(cutBasedPhotonID_Fall17_94X_V2_loose.idName, '4578dfcceb0bfd1ba5ac28973c843fd0') -central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_medium.idName, +central_id_registry.register(cutBasedPhotonID_Fall17_94X_V2_medium.idName, '28b186c301061395f394a81266c8d7de') -central_id_registry.register(cutBasedPhotonID_Fall17_100X_V2_tight.idName, +central_id_registry.register(cutBasedPhotonID_Fall17_94X_V2_tight.idName, '6f4f0ed6a8bf2de8dcf0bc3349b0546d') -cutBasedPhotonID_Fall17_100X_V2_loose.isPOGApproved = cms.untracked.bool(True) -cutBasedPhotonID_Fall17_100X_V2_medium.isPOGApproved = cms.untracked.bool(True) -cutBasedPhotonID_Fall17_100X_V2_tight.isPOGApproved = cms.untracked.bool(True) +cutBasedPhotonID_Fall17_94X_V2_loose.isPOGApproved = cms.untracked.bool(True) +cutBasedPhotonID_Fall17_94X_V2_medium.isPOGApproved = cms.untracked.bool(True) +cutBasedPhotonID_Fall17_94X_V2_tight.isPOGApproved = cms.untracked.bool(True) From fde7b8ed6376149de42b15161e3e6837a07e1219 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Mon, 26 Nov 2018 18:32:02 +0100 Subject: [PATCH 06/13] Backporting #25293 --- ...PhotonMVAEstimatorRun2VariablesFall17.txt} | 6 ++-- ...tonMVAEstimatorRun2VariablesFall17V1p1.txt | 2 +- ...hotonMVAEstimatorRun2VariablesSpring16.txt | 2 +- .../plugins/PhotonIDValueMapProducer.cc | 36 +++++++++---------- .../mvaPhotonID_Fall17_94X_V1_cff.py | 6 ++-- .../mvaPhotonID_Fall17_94X_V1p1_cff.py | 4 +-- .../mvaPhotonID_Fall17_94X_V2_cff.py | 5 +-- ...vaPhotonID_Spring15_25ns_nonTrig_V0_cff.py | 4 +-- ...vaPhotonID_Spring15_25ns_nonTrig_V2_cff.py | 4 +-- ...PhotonID_Spring15_25ns_nonTrig_V2p1_cff.py | 4 +-- ...vaPhotonID_Spring15_50ns_nonTrig_V0_cff.py | 4 +-- ...vaPhotonID_Spring15_50ns_nonTrig_V1_cff.py | 4 +-- ...vaPhotonID_Spring15_50ns_nonTrig_V2_cff.py | 4 +-- ...PhotonID_Spring15_50ns_nonTrig_V2p1_cff.py | 4 +-- .../mvaPhotonID_Spring16_nonTrig_V1_cff.py | 4 +-- .../Identification/mvaPhotonID_tools.py | 3 ++ 16 files changed, 48 insertions(+), 48 deletions(-) rename RecoEgamma/PhotonIdentification/data/{PhotonMVAEstimatorRun2VariablesFall17V1.txt => PhotonMVAEstimatorRun2VariablesFall17.txt} (92%) diff --git a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1.txt b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt similarity index 92% rename from RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1.txt rename to RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt index fdcb2d112f894..0c26e6c6f6aff 100644 --- a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1.txt +++ b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt @@ -1,5 +1,5 @@ # -# File: PhotonMVAEstimatorRun2VariablesFall17V1.txt +# File: PhotonMVAEstimatorRun2VariablesFall17.txt # # This file is to be read by the MVAVariableManager class. Lists all the # variables which appear in the xml files for the MVA based Photon IDs for Run2. @@ -22,7 +22,7 @@ s4 full5x5_showerShapeVariables.e2x2/full5x5_showerShapeV scEta superCluster.eta None None rho fixedGridRhoAll None None esEffSigmaRR full5x5_showerShapeVariables.effSigmaRR None None -esEnergy/SCRawE superCluster.preshowerEnergy/superCluster.rawEnergy None None +esEnergyOverRawE superCluster.preshowerEnergy/superCluster.rawEnergy None None phoIso03 photonIDValueMapProducer:phoPhotonIsolation None None chgIsoWrtChosenVtx photonIDValueMapProducer:phoChargedIsolation None None -chgIsoWrtWorstVtx photonIDValueMapProducer:phoWorstChargedIsolationWithPVConstraint None None +chgIsoWrtWorstVtx photonIDValueMapProducer:phoWorstChargedIsolationConeVetoPVConstr None None diff --git a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt index 2775f64f054ec..72ad0262e8027 100644 --- a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt +++ b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt @@ -22,7 +22,7 @@ s4 full5x5_showerShapeVariables.e2x2/full5x5_showerShapeV scEta superCluster.eta None None rho fixedGridRhoAll None None esEffSigmaRR full5x5_showerShapeVariables.effSigmaRR None None -esEnergy/SCRawE superCluster.preshowerEnergy/superCluster.rawEnergy None None +esEnergyOverRawE superCluster.preshowerEnergy/superCluster.rawEnergy None None phoIso03 photonIDValueMapProducer:phoPhotonIsolation None None chgIsoWrtChosenVtx photonIDValueMapProducer:phoChargedIsolation None None chgIsoWrtWorstVtx photonIDValueMapProducer:phoWorstChargedIsolation None None diff --git a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring16.txt b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring16.txt index cb731b954d56a..875927f1feb37 100644 --- a/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring16.txt +++ b/RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring16.txt @@ -25,6 +25,6 @@ phiWidth superCluster.phiWidth CITK_isoPhotons egmPhotonIsolation:gamma-DR030- None None CITK_isoPhoCorrMax2p5 egmPhotonIsolation:gamma-DR030- None None CITK_isoChargedHad egmPhotonIsolation:h+-DR030- None None -chgIsoWrtWorstVtx photonIDValueMapProducer:phoWorstChargedIsolationWithConeVeto None None +chgIsoWrtWorstVtx photonIDValueMapProducer:phoWorstChargedIsolationConeVeto None None esEffSigmaRR full5x5_showerShapeVariables.effSigmaRR None None esEnergy/SCRawE superCluster.preshowerEnergy/superCluster.rawEnergy None None diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index 6383bd5aec92e..4c207c4776889 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -123,9 +123,9 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { constexpr static char phoNeutralHadronIsolation_[] = "phoNeutralHadronIsolation"; constexpr static char phoPhotonIsolation_[] = "phoPhotonIsolation"; constexpr static char phoWorstChargedIsolation_[] = "phoWorstChargedIsolation"; - constexpr static char phoWorstChargedIsolationWithConeVeto_[] = "phoWorstChargedIsolationWithConeVeto"; - constexpr static char phoWorstChargedIsolationWithPVConstraint_[] = "phoWorstChargedIsolationWithPVConstraint"; - constexpr static char phoWorstChargedIsolationWithConeVetoWithPVConstraint_[] = "phoWorstChargedIsolationWithConeVetoWithPVConstraint"; + constexpr static char phoWorstChargedIsolationConeVeto_[] = "phoWorstChargedIsolationConeVeto"; + constexpr static char phoWorstChargedIsolationConeVetoPVConstr_[] = "phoWorstChargedIsolationConeVetoPVConstr"; + constexpr static char phoWorstChargedIsolationConeVetoWithPVConstraint_[] = "phoWorstChargedIsolationConeVetoWithPVConstraint"; //PFCluster Isolation constexpr static char phoTrkIsolation_[] = "phoTrkIsolation"; @@ -151,9 +151,9 @@ constexpr char PhotonIDValueMapProducer::phoChargedIsolation_[]; constexpr char PhotonIDValueMapProducer::phoNeutralHadronIsolation_[]; constexpr char PhotonIDValueMapProducer::phoPhotonIsolation_[]; constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationWithConeVeto_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationWithPVConstraint_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationWithConeVetoWithPVConstraint_[]; +constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVeto_[]; +constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVetoPVConstr_[]; +constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVetoWithPVConstraint_[]; //PFCluster Isolation constexpr char PhotonIDValueMapProducer::phoTrkIsolation_[]; @@ -226,9 +226,9 @@ PhotonIDValueMapProducer::PhotonIDValueMapProducer(const edm::ParameterSet& iCon produces >(phoNeutralHadronIsolation_); produces >(phoPhotonIsolation_); produces >(phoWorstChargedIsolation_); - produces >(phoWorstChargedIsolationWithConeVeto_); - produces >(phoWorstChargedIsolationWithPVConstraint_); - produces >(phoWorstChargedIsolationWithConeVetoWithPVConstraint_); + produces >(phoWorstChargedIsolationConeVeto_); + produces >(phoWorstChargedIsolationConeVetoPVConstr_); + produces >(phoWorstChargedIsolationConeVetoWithPVConstraint_); //PFCluster Isolations produces >(phoTrkIsolation_); @@ -333,9 +333,9 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup std::vector phoNeutralHadronIsolation; std::vector phoPhotonIsolation; std::vector phoWorstChargedIsolation; - std::vector phoWorstChargedIsolationWithConeVeto; - std::vector phoWorstChargedIsolationWithPVConstraint; - std::vector phoWorstChargedIsolationWithConeVetoWithPVConstraint; + std::vector phoWorstChargedIsolationConeVeto; + std::vector phoWorstChargedIsolationConeVetoPVConstr; + std::vector phoWorstChargedIsolationConeVetoWithPVConstraint; //PFCluster Isolations std::vector phoTrkIsolation; @@ -489,14 +489,14 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, isAOD, isPVConstraint,pv, coneSizeDR, dxyMax, dzMax, dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationWithConeVeto .push_back( worstChargedIsoWithConeVeto ); + phoWorstChargedIsolationConeVeto .push_back( worstChargedIsoWithConeVeto ); isPVConstraint=true; float worstChargedIsoWithPVConstraint = computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, isAOD, isPVConstraint,pv,coneSizeDR, dxyMax, dzMax, dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationWithPVConstraint .push_back( worstChargedIsoWithPVConstraint ); + phoWorstChargedIsolationConeVetoPVConstr .push_back( worstChargedIsoWithPVConstraint ); // Worst isolation computed with cone vetos and a ptMin cut, as in // Run 2 Hgg code. @@ -507,7 +507,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, isAOD,isPVConstraint, pv, coneSizeDR, dxyMax, dzMax, dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationWithConeVetoWithPVConstraint .push_back( worstChargedIsoWithConeVetoWithPVConstraint ); + phoWorstChargedIsolationConeVetoWithPVConstraint .push_back( worstChargedIsoWithConeVetoWithPVConstraint ); @@ -530,9 +530,9 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup writeValueMap(iEvent, src, phoNeutralHadronIsolation, phoNeutralHadronIsolation_); writeValueMap(iEvent, src, phoPhotonIsolation, phoPhotonIsolation_); writeValueMap(iEvent, src, phoWorstChargedIsolation, phoWorstChargedIsolation_); - writeValueMap(iEvent, src, phoWorstChargedIsolationWithConeVeto, phoWorstChargedIsolationWithConeVeto_); - writeValueMap(iEvent, src, phoWorstChargedIsolationWithPVConstraint, phoWorstChargedIsolationWithPVConstraint_); - writeValueMap(iEvent, src, phoWorstChargedIsolationWithConeVetoWithPVConstraint, phoWorstChargedIsolationWithConeVetoWithPVConstraint_); + writeValueMap(iEvent, src, phoWorstChargedIsolationConeVeto, phoWorstChargedIsolationConeVeto_); + writeValueMap(iEvent, src, phoWorstChargedIsolationConeVetoPVConstr, phoWorstChargedIsolationConeVetoPVConstr_); + writeValueMap(iEvent, src, phoWorstChargedIsolationConeVetoWithPVConstraint, phoWorstChargedIsolationConeVetoWithPVConstraint_); //PFCluster Isolation writeValueMap(iEvent, src, phoTrkIsolation, phoTrkIsolation_); writeValueMap(iEvent, src, phoHcalPFClIsolation, phoHcalPFClIsolation_); diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1_cff.py index 34d9aa32a985f..266f08c520ccb 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1_cff.py @@ -8,10 +8,10 @@ # https://indico.cern.ch/event/662751/contributions/2778043/attachments/1562017/2459674/EGamma_WorkShop_21.11.17_Debabrata.pdf mvaTag = "RunIIFall17v1" -mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1.txt" +mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17.txt" mvaWeightFiles = [ - "RecoEgamma/PhotonIdentification/data/Fall17/HggPhoId_92X_barrel_BDT.weights.xml", - "RecoEgamma/PhotonIdentification/data/Fall17/HggPhoId_92X_endcap_BDT.weights.xml" + path.join(weightFileBaseDir, "Fall17/EB_V1.weights.xml.gz"), + path.join(weightFileBaseDir, "Fall17/EE_V1.weights.xml.gz"), ] # Set up the VID working point parameters diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1p1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1p1_cff.py index 2cd3e5bacf63c..3c063828407a8 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1p1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V1p1_cff.py @@ -10,8 +10,8 @@ mvaTag = "RunIIFall17v1p1" mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesFall17V1p1.txt" mvaWeightFiles = [ - "RecoEgamma/PhotonIdentification/data/Fall17/HggPhoId_92X_barrel_BDT.weights.xml", - "RecoEgamma/PhotonIdentification/data/Fall17/HggPhoId_92X_endcap_BDT.weights.xml" + path.join(weightFileBaseDir, "Fall17/EB_V1.weights.xml.gz"), + path.join(weightFileBaseDir, "Fall17/EE_V1.weights.xml.gz"), ] # Set up the VID working point parameters diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py index 31f963ffd16b5..adf420d87a609 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Fall17_94X_V2_cff.py @@ -34,10 +34,7 @@ configs = configureFullVIDMVAPhoID(mvaTag=mvaTag, variablesFile=mvaVariablesFile, weightFiles=mvaWeightFiles, - wpConfig=wpConfig, - # Category parameters - nCategories = cms.int32(2), - categoryCuts = category_cuts) + wpConfig=wpConfig) mvaPhoID_RunIIFall17_v2_producer_config = configs["producer_config"] mvaPhoID_RunIIFall17_v2_wp90 = configs["VID_config"]["mvaPhoID-RunIIFall17-v2-wp90"] mvaPhoID_RunIIFall17_v2_wp80 = configs["VID_config"]["mvaPhoID-RunIIFall17-v2-wp80"] diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py index 2a958749e9fda..267b3da9530cc 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py @@ -28,8 +28,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V0 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EB_V0.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EE_V0.weights.xml" + path.join(weightFileBaseDir, "Spring15/25ns_EB_V0.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/25ns_EE_V0.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py index c9fa4613035f9..0f2e9b0eeda25 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py @@ -29,8 +29,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V2 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EB_V2.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EE_V2.weights.xml" + path.join(weightFileBaseDir, "Spring15/25ns_EB_V2.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/25ns_EE_V2.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py index 58797eb1b6b86..548c5f4ce0e1b 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py @@ -31,8 +31,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V2p1 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EB_V2.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_25ns_EE_V2.weights.xml" + path.join(weightFileBaseDir, "Spring15/25ns_EB_V2.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/25ns_EE_V2.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py index d80480c63810a..b7c1ce6c72155 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py @@ -28,8 +28,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V0 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EB_V0.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EE_V0.weights.xml" + path.join(weightFileBaseDir, "Spring15/50ns_EB_V0.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/50ns_EE_V0.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py index 27e6859efb177..e63268bb8e121 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py @@ -28,8 +28,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V1 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EB_V1.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EE_V1.weights.xml" + path.join(weightFileBaseDir, "Spring15/50ns_EB_V1.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/50ns_EE_V1.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py index a62f9cc09fcf5..fe27e209e02c2 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py @@ -30,8 +30,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V2 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EB_V2.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EE_V2.weights.xml" + path.join(weightFileBaseDir, "Spring15/50ns_EB_V2.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/50ns_EE_V2.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py index e1b16cee38608..6563250e11a2d 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py @@ -32,8 +32,8 @@ # 1 endcap photons mvaSpring15NonTrigWeightFiles_V2p1 = cms.vstring( - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EB_V2.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring15/photon_general_MVA_Spring15_50ns_EE_V2.weights.xml" + path.join(weightFileBaseDir, "Spring15/50ns_EB_V2.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring15/50ns_EE_V2.weights.xml.gz"), ) # Load some common definitions for MVA machinery diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring16_nonTrig_V1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring16_nonTrig_V1_cff.py index cc2a239e12f58..2f4b29b7d38cf 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring16_nonTrig_V1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring16_nonTrig_V1_cff.py @@ -11,8 +11,8 @@ mvaTag = "Run2Spring16NonTrigV1" mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring16.txt" mvaWeightFiles = [ - "RecoEgamma/PhotonIdentification/data/Spring16/photon_general_MVA_Spring16_EB_V3.weights.xml", - "RecoEgamma/PhotonIdentification/data/Spring16/photon_general_MVA_Spring16_EE_V3.weights.xml" + path.join(weightFileBaseDir, "Spring16/EB_V1.weights.xml.gz"), + path.join(weightFileBaseDir, "Spring16/EE_V1.weights.xml.gz"), ] effAreasPath_pho = "RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased_3bins.txt" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_tools.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_tools.py index 03d3c36978d8f..fdf395761c9dc 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_tools.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_tools.py @@ -1,5 +1,8 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry +from os import path + +weightFileBaseDir = "RecoEgamma/PhotonIdentification/data/MVA" # division between barrel and endcap ebeeSplit = 1.479 From e78ff2dec5c2047a4933b6f8a0b165c967002dab Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Wed, 18 Jul 2018 21:26:48 +0200 Subject: [PATCH 07/13] Attempt to improve PhotonIDValueMapProducer --- .../plugins/PhotonIDValueMapProducer.cc | 1076 +++++++---------- 1 file changed, 439 insertions(+), 637 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index 4c207c4776889..bfdf872f5c473 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -1,686 +1,488 @@ -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/Common/interface/View.h" - #include "DataFormats/EgammaCandidates/interface/Photon.h" -#include "DataFormats/PatCandidates/interface/Photon.h" - #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" - #include "DataFormats/PatCandidates/interface/PackedCandidate.h" - +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" -#include -#include - -// Introduce these two types for brevity of casting -typedef edm::Ptr recoCandPtr; -typedef edm::Ptr patCandPtr; - -// This template function finds whether theCandidate is in thefootprint +// This template function finds whether theCandidate is in thefootprint // collection. It is templated to be able to handle both reco and pat // photons (from AOD and miniAOD, respectively). template -bool isInFootprint(const T& thefootprint, const U& theCandidate) { - for ( auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr ) { - if( itr->key() == theCandidate.key() ) return true; - } - return false; +bool isInFootprint(const T& footprint, const U& candidate) +{ + for (auto& it : footprint) { + if (it.key() == candidate.key()) + return true; + } + return false; } class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { - public: - - explicit PhotonIDValueMapProducer(const edm::ParameterSet&); - ~PhotonIDValueMapProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - private: - - void produce(edm::Event&, const edm::EventSetup&) override; - - void writeValueMap(edm::Event &iEvent, - const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const ; - - // This function computes charged hadron isolation - // with respect to multiple PVs and returns the worst - // of the found isolation values. - // The function implements the computation method taken directly - // from Run 1 code of H->gamma gamma, specifically from - // the class CiCPhotonID of the HiggsTo2photons anaysis code. - // Template is introduced to handle reco/pat photons and aod/miniAOD - // PF candidates collections - template - float computeWorstPFChargedIsolation(const T& photon, - const U& pfCandidates, - const edm::Handle vertices, - bool isAOD, bool isPVConstraint,const reco::Vertex& pv, - float dRmax, float dxyMax, float dzMax, - float dRvetoBarrel, float dRvetoEndcap, float ptMin); - - // Some helper functions that are needed to access info in - // AOD vs miniAOD - reco::PFCandidate::ParticleType - candidatePdgId(const edm::Ptr candidate, bool isAOD); - - const reco::Track* getTrackPointer(const edm::Ptr candidate, bool isAOD); - void getImpactParameters(const edm::Ptr& candidate, - bool isAOD, const reco::Vertex& pv, float &dxy, float &dz); - - - - // The object that will compute 5x5 quantities - std::unique_ptr lazyToolnoZS; - - // for AOD case - edm::EDGetTokenT ebReducedRecHitCollection_; - edm::EDGetTokenT eeReducedRecHitCollection_; - edm::EDGetTokenT esReducedRecHitCollection_; - edm::EDGetTokenT vtxToken_; - edm::EDGetTokenT > > particleBasedIsolationToken_; - edm::EDGetTokenT > pfCandidatesToken_; - edm::EDGetToken src_; - - // for miniAOD case - edm::EDGetTokenT ebReducedRecHitCollectionMiniAOD_; - edm::EDGetTokenT eeReducedRecHitCollectionMiniAOD_; - edm::EDGetTokenT esReducedRecHitCollectionMiniAOD_; - edm::EDGetTokenT vtxTokenMiniAOD_; - edm::EDGetTokenT > > particleBasedIsolationTokenMiniAOD_; - edm::EDGetTokenT > pfCandidatesTokenMiniAOD_; - edm::EDGetToken srcMiniAOD_; - - // check whether a non-null preshower is there - bool usesES_; - - // Cluster shapes - constexpr static char phoFull5x5SigmaIEtaIEta_[] = "phoFull5x5SigmaIEtaIEta"; - constexpr static char phoFull5x5SigmaIEtaIPhi_[] = "phoFull5x5SigmaIEtaIPhi"; - constexpr static char phoFull5x5E1x3_[] = "phoFull5x5E1x3"; - constexpr static char phoFull5x5E2x2_[] = "phoFull5x5E2x2"; - constexpr static char phoFull5x5E2x5Max_[] = "phoFull5x5E2x5Max"; - constexpr static char phoFull5x5E5x5_[] = "phoFull5x5E5x5"; - constexpr static char phoESEffSigmaRR_[] = "phoESEffSigmaRR"; - // Cluster shape ratios - constexpr static char phoFull5x5E1x3byE5x5_[] = "phoFull5x5E1x3byE5x5"; - constexpr static char phoFull5x5E2x2byE5x5_[] = "phoFull5x5E2x2byE5x5"; - constexpr static char phoFull5x5E2x5byE5x5_[] = "phoFull5x5E2x5byE5x5"; - // Isolations - constexpr static char phoChargedIsolation_[] = "phoChargedIsolation"; - constexpr static char phoNeutralHadronIsolation_[] = "phoNeutralHadronIsolation"; - constexpr static char phoPhotonIsolation_[] = "phoPhotonIsolation"; - constexpr static char phoWorstChargedIsolation_[] = "phoWorstChargedIsolation"; - constexpr static char phoWorstChargedIsolationConeVeto_[] = "phoWorstChargedIsolationConeVeto"; - constexpr static char phoWorstChargedIsolationConeVetoPVConstr_[] = "phoWorstChargedIsolationConeVetoPVConstr"; - constexpr static char phoWorstChargedIsolationConeVetoWithPVConstraint_[] = "phoWorstChargedIsolationConeVetoWithPVConstraint"; - - //PFCluster Isolation - constexpr static char phoTrkIsolation_[] = "phoTrkIsolation"; - constexpr static char phoHcalPFClIsolation_[] = "phoHcalPFClIsolation"; - constexpr static char phoEcalPFClIsolation_[] = "phoEcalPFClIsolation"; - +public: + explicit PhotonIDValueMapProducer(const edm::ParameterSet&); + ~PhotonIDValueMapProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + + // This function computes charged hadron isolation with respect to multiple + // PVs and returns the worst of the found isolation values. The function + // implements the computation method taken directly from Run 1 code of + // H->gamma gamma, specifically from the class CiCPhotonID of the + // HiggsTo2photons anaysis code. Template is introduced to handle reco/pat + // photons and aod/miniAOD PF candidates collections + template + float computeWorstPFChargedIsolation( + const T& photon, + const U& pfCands, + const edm::Handle vertices, + const reco::Vertex& pv, + unsigned char options); + + // Some helper functions that are needed to access info in + // AOD vs miniAOD + reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr candidate); + + const reco::Track* getTrackPointer(const edm::Ptr candidate); + void getImpactParameters( + const edm::Ptr& candidate, const reco::Vertex& pv, float& dxy, float& dz); + + // The object that will compute 5x5 quantities + std::unique_ptr lazyToolnoZS; + + // check whether a non-null preshower is there + const bool usesES_; + + // for AOD case + const edm::EDGetTokenT ebReducedRecHitCollection_; + const edm::EDGetTokenT eeReducedRecHitCollection_; + const edm::EDGetTokenT esReducedRecHitCollection_; + const edm::EDGetTokenT vtxToken_; + const edm::EDGetTokenT>> particleBasedIsolationToken_; + const edm::EDGetTokenT> pfCandsToken_; + const edm::EDGetToken src_; + + // for miniAOD case + const edm::EDGetTokenT ebReducedRecHitCollectionMiniAOD_; + const edm::EDGetTokenT eeReducedRecHitCollectionMiniAOD_; + const edm::EDGetTokenT esReducedRecHitCollectionMiniAOD_; + const edm::EDGetTokenT vtxTokenMiniAOD_; + const edm::EDGetTokenT>> particleBasedIsolationTokenMiniAOD_; + const edm::EDGetTokenT> pfCandsTokenMiniAOD_; + const edm::EDGetToken srcMiniAOD_; + + bool isAOD_; }; -// Cluster shapes -constexpr char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIEta_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIPhi_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E1x3_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E2x2_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E2x5Max_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E5x5_[]; -constexpr char PhotonIDValueMapProducer::phoESEffSigmaRR_[]; -// Cluster shape ratios -constexpr char PhotonIDValueMapProducer::phoFull5x5E1x3byE5x5_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E2x2byE5x5_[]; -constexpr char PhotonIDValueMapProducer::phoFull5x5E2x5byE5x5_[]; -// Isolations -constexpr char PhotonIDValueMapProducer::phoChargedIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoNeutralHadronIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoPhotonIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVeto_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVetoPVConstr_[]; -constexpr char PhotonIDValueMapProducer::phoWorstChargedIsolationConeVetoWithPVConstraint_[]; - -//PFCluster Isolation -constexpr char PhotonIDValueMapProducer::phoTrkIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoHcalPFClIsolation_[]; -constexpr char PhotonIDValueMapProducer::phoEcalPFClIsolation_[]; - - -PhotonIDValueMapProducer::PhotonIDValueMapProducer(const edm::ParameterSet& iConfig) { - - // - // Declare consummables, handle both AOD and miniAOD case - // - ebReducedRecHitCollection_ = mayConsume(iConfig.getParameter - ("ebReducedRecHitCollection")); - ebReducedRecHitCollectionMiniAOD_ = mayConsume(iConfig.getParameter - ("ebReducedRecHitCollectionMiniAOD")); - - eeReducedRecHitCollection_ = mayConsume(iConfig.getParameter - ("eeReducedRecHitCollection")); - eeReducedRecHitCollectionMiniAOD_ = mayConsume(iConfig.getParameter - ("eeReducedRecHitCollectionMiniAOD")); - - if (!iConfig.getParameter("esReducedRecHitCollection").label().empty() || - !iConfig.getParameter("esReducedRecHitCollectionMiniAOD").label().empty()) { - usesES_ = true; - esReducedRecHitCollection_ = mayConsume(iConfig.getParameter - ("esReducedRecHitCollection")); - esReducedRecHitCollectionMiniAOD_ = mayConsume(iConfig.getParameter - ("esReducedRecHitCollectionMiniAOD")); - - } else { - usesES_ = false; - } - - vtxToken_ = mayConsume(iConfig.getParameter("vertices")); - vtxTokenMiniAOD_ = mayConsume(iConfig.getParameter("verticesMiniAOD")); - - // reco photons are castable into pat photons, so no need to handle reco/pat seprately - src_ = mayConsume >(iConfig.getParameter("src")); - srcMiniAOD_ = mayConsume >(iConfig.getParameter("srcMiniAOD")); - - // The particleBasedIsolation object is relevant only for AOD, RECO format - particleBasedIsolationToken_ = mayConsume > > - (iConfig.getParameter("particleBasedIsolation")); - - // AOD has reco::PFCandidate vector, and miniAOD has pat::PackedCandidate vector. - // Both inherit from reco::Candidate, so we go to the base class. We can cast into - // the full type later if needed. Since the collection names are different, we - // introduce both collections - pfCandidatesToken_ = mayConsume< edm::View >(iConfig.getParameter("pfCandidates")); - pfCandidatesTokenMiniAOD_ = mayConsume< edm::View >(iConfig.getParameter("pfCandidatesMiniAOD")); - - // - // Declare producibles - // - // Cluster shapes - produces >(phoFull5x5SigmaIEtaIEta_); - produces >(phoFull5x5SigmaIEtaIPhi_); - produces >(phoFull5x5E1x3_); - produces >(phoFull5x5E2x2_); - produces >(phoFull5x5E2x5Max_); - produces >(phoFull5x5E5x5_); - produces >(phoESEffSigmaRR_); - // Cluster shape ratios - produces >(phoFull5x5E1x3byE5x5_); - produces >(phoFull5x5E2x2byE5x5_); - produces >(phoFull5x5E2x5byE5x5_); - // Isolations - produces >(phoChargedIsolation_); - produces >(phoNeutralHadronIsolation_); - produces >(phoPhotonIsolation_); - produces >(phoWorstChargedIsolation_); - produces >(phoWorstChargedIsolationConeVeto_); - produces >(phoWorstChargedIsolationConeVetoPVConstr_); - produces >(phoWorstChargedIsolationConeVetoWithPVConstraint_); - - //PFCluster Isolations - produces >(phoTrkIsolation_); - produces >(phoHcalPFClIsolation_); - produces >(phoEcalPFClIsolation_); +constexpr int nVars_ = 19; + +const std::string names[nVars_] = { + // Cluster shapes + "phoFull5x5SigmaIEtaIEta", // 0 + "phoFull5x5SigmaIEtaIPhi", + "phoFull5x5E1x3", + "phoFull5x5E2x2", + "phoFull5x5E2x5Max", + "phoFull5x5E5x5", // 5 + "phoESEffSigmaRR", + // Cluster shape ratios + "phoFull5x5E1x3byE5x5", + "phoFull5x5E2x2byE5x5", + "phoFull5x5E2x5byE5x5", + // Isolations + "phoChargedIsolation", // 10 + "phoNeutralHadronIsolation", + "phoPhotonIsolation", + "phoWorstChargedIsolation", + "phoWorstChargedIsolationConeVeto", + "phoWorstChargedIsolationConeVetoPVConstr", // 15 + // PFCluster Isolation + "phoTrkIsolation", + "phoHcalPFClIsolation", + "phoEcalPFClIsolation" +}; +// options and bitflags +constexpr float coneSizeDR = 0.3; +constexpr float dxyMax = 0.1; +constexpr float dzMax = 0.2; +constexpr float dRvetoBarrel = 0.02; +constexpr float dRvetoEndcap = 0.02; +constexpr float ptMin = 0.1; + +const unsigned char PV_CONSTRAINT = 0x1; +const unsigned char DR_VETO = 0x2; +const unsigned char PT_MIN_THRESH = 0x8; + +PhotonIDValueMapProducer::PhotonIDValueMapProducer(const edm::ParameterSet& cfg) + : usesES_(!cfg.getParameter("esReducedRecHitCollection").label().empty() + || !cfg.getParameter("esReducedRecHitCollectionMiniAOD").label().empty()) + // Declare consummables, handle both AOD and miniAOD case + , ebReducedRecHitCollection_( + mayConsume(cfg.getParameter("ebReducedRecHitCollection"))) + , eeReducedRecHitCollection_( + mayConsume(cfg.getParameter("eeReducedRecHitCollection"))) + , esReducedRecHitCollection_( + mayConsume(cfg.getParameter("esReducedRecHitCollection"))) + , vtxToken_(mayConsume(cfg.getParameter("vertices"))) + // The particleBasedIsolation object is relevant only for AOD, RECO format + , particleBasedIsolationToken_(mayConsume>>( + cfg.getParameter("particleBasedIsolation"))) + // AOD has reco::PFCandidate vector, and miniAOD has pat::PackedCandidate + // vector. Both inherit from reco::Candidate, so we go to the base class. + // We can cast into the full type later if needed. Since the collection + // names are different, we introduce both collections + , pfCandsToken_(mayConsume>(cfg.getParameter("pfCandidates"))) + // reco photons are castable into pat photons, so no need to handle reco/pat seprately + , src_(mayConsume>(cfg.getParameter("src"))) + , ebReducedRecHitCollectionMiniAOD_( + mayConsume(cfg.getParameter("ebReducedRecHitCollectionMiniAOD"))) + , eeReducedRecHitCollectionMiniAOD_( + mayConsume(cfg.getParameter("eeReducedRecHitCollectionMiniAOD"))) + , esReducedRecHitCollectionMiniAOD_( + mayConsume(cfg.getParameter("esReducedRecHitCollectionMiniAOD"))) + , vtxTokenMiniAOD_(mayConsume(cfg.getParameter("verticesMiniAOD"))) + , pfCandsTokenMiniAOD_( + mayConsume>(cfg.getParameter("pfCandidatesMiniAOD"))) + , srcMiniAOD_(mayConsume>(cfg.getParameter("srcMiniAOD"))) +{ + // Declare producibles + for (int i = 0; i < nVars_; ++i) + produces>(names[i]); } -PhotonIDValueMapProducer::~PhotonIDValueMapProducer() { -} +PhotonIDValueMapProducer::~PhotonIDValueMapProducer() {} + +void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + edm::Handle> src; -void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - using namespace edm; - - // Constants - const float coneSizeDR = 0.3; - const float dxyMax = 0.1; - const float dzMax = 0.2; - - edm::Handle > src; - - bool isAOD = true; - iEvent.getByToken(src_, src); - if( !src.isValid() ){ - isAOD = false; - iEvent.getByToken(srcMiniAOD_,src); - } - if( !src.isValid() ) { - throw cms::Exception("IllDefinedDataTier") - << "DataFormat does not contain a photon source!"; - } - - // Configure Lazy Tools - if (usesES_) { - if( isAOD ) - lazyToolnoZS = std::make_unique(iEvent, iSetup, - ebReducedRecHitCollection_, - eeReducedRecHitCollection_, - esReducedRecHitCollection_); - else - lazyToolnoZS = std::make_unique(iEvent, iSetup, - ebReducedRecHitCollectionMiniAOD_, - eeReducedRecHitCollectionMiniAOD_, - esReducedRecHitCollectionMiniAOD_); - } else { - if( isAOD ) - lazyToolnoZS = std::make_unique(iEvent, iSetup, - ebReducedRecHitCollection_, - eeReducedRecHitCollection_); - else - lazyToolnoZS = std::make_unique(iEvent, iSetup, - ebReducedRecHitCollectionMiniAOD_, - eeReducedRecHitCollectionMiniAOD_); - - } - - // Get PV - edm::Handle vertices; - iEvent.getByToken(vtxToken_, vertices); - if( !vertices.isValid() ) - iEvent.getByToken(vtxTokenMiniAOD_, vertices); - if (vertices->empty()) return; // skip the event if no PV found - const reco::Vertex &pv = vertices->front(); - - edm::Handle< edm::ValueMap > > particleBasedIsolationMap; - if( isAOD ){ - // this exists only in AOD - iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap); - } - - edm::Handle< edm::View > pfCandidatesHandle; - - iEvent.getByToken(pfCandidatesToken_, pfCandidatesHandle); - if( !pfCandidatesHandle.isValid() ) - iEvent.getByToken(pfCandidatesTokenMiniAOD_, pfCandidatesHandle); - - if( !isAOD && !src->empty() ) { - edm::Ptr test(src->ptrAt(0)); - if( test.isNull() || !test.isAvailable() ) { - throw cms::Exception("InvalidConfiguration") - <<"DataFormat is detected as miniAOD but cannot cast to pat::Photon!"; + isAOD_ = true; + iEvent.getByToken(src_, src); + if (!src.isValid()) { + isAOD_ = false; + iEvent.getByToken(srcMiniAOD_, src); } - } - - // size_t n = src->size(); - // Cluster shapes - std::vector phoFull5x5SigmaIEtaIEta; - std::vector phoFull5x5SigmaIEtaIPhi; - std::vector phoFull5x5E1x3; - std::vector phoFull5x5E2x2; - std::vector phoFull5x5E2x5Max; - std::vector phoFull5x5E5x5; - std::vector phoESEffSigmaRR; - // Cluster shape ratios - std::vector phoFull5x5E1x3byE5x5; - std::vector phoFull5x5E2x2byE5x5; - std::vector phoFull5x5E2x5byE5x5; - // Isolations - std::vector phoChargedIsolation; - std::vector phoNeutralHadronIsolation; - std::vector phoPhotonIsolation; - std::vector phoWorstChargedIsolation; - std::vector phoWorstChargedIsolationConeVeto; - std::vector phoWorstChargedIsolationConeVetoPVConstr; - std::vector phoWorstChargedIsolationConeVetoWithPVConstraint; - - //PFCluster Isolations - std::vector phoTrkIsolation; - std::vector phoHcalPFClIsolation; - std::vector phoEcalPFClIsolation; - - // reco::Photon::superCluster() is virtual so we can exploit polymorphism - for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) { - const auto& iPho = src->ptrAt(idxpho); - - // - // Compute full 5x5 quantities - // - const auto& theseed = *(iPho->superCluster()->seed()); - - // For full5x5_sigmaIetaIeta, for 720 we use: lazy tools for AOD, - // and userFloats or lazy tools for miniAOD. From some point in 72X and on, one can - // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta() - // for both formats. - float see = -999; - std::vector vCov = lazyToolnoZS->localCovariances( theseed ); - see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0])); - float sep = vCov[1]; - phoFull5x5SigmaIEtaIEta.push_back(see); - phoFull5x5SigmaIEtaIPhi.push_back(sep); - - phoFull5x5E1x3 .push_back(lazyToolnoZS-> e1x3 (theseed) ); - phoFull5x5E2x2 .push_back(lazyToolnoZS-> e2x2 (theseed) ); - phoFull5x5E2x5Max.push_back(lazyToolnoZS-> e2x5Max(theseed) ); - phoFull5x5E5x5 .push_back(lazyToolnoZS-> e5x5 (theseed) ); - - phoFull5x5E1x3byE5x5.push_back(phoFull5x5E1x3[idxpho]/phoFull5x5E5x5[idxpho]); - phoFull5x5E2x2byE5x5.push_back(phoFull5x5E2x2[idxpho]/phoFull5x5E5x5[idxpho]); - phoFull5x5E2x5byE5x5.push_back(phoFull5x5E2x5Max[idxpho]/phoFull5x5E5x5[idxpho]); - - phoESEffSigmaRR .push_back(lazyToolnoZS->eseffsirir( *(iPho->superCluster()) ) ); - - // - // Compute absolute uncorrected isolations with footprint removal - // - - // First, find photon direction with respect to the good PV - math::XYZVector photon_directionWrtVtx(iPho->superCluster()->x() - pv.x(), - iPho->superCluster()->y() - pv.y(), - iPho->superCluster()->z() - pv.z()); - - //PFCluster Isolations - phoTrkIsolation .push_back( iPho->trkSumPtSolidConeDR04()); - if (isAOD) - { - phoHcalPFClIsolation .push_back(0.f); - phoEcalPFClIsolation .push_back(0.f); - } - else - { - edm::Ptr patPhotonPtr(src->ptrAt(idxpho)); - phoHcalPFClIsolation .push_back(patPhotonPtr->hcalPFClusterIso()); - phoEcalPFClIsolation .push_back(patPhotonPtr->ecalPFClusterIso()); - } - - - // Zero the isolation sums - float chargedIsoSum = 0; - float neutralHadronIsoSum = 0; - float photonIsoSum = 0; - - // Loop over all PF candidates - for (unsigned idxcand = 0; idxcand < pfCandidatesHandle->size(); ++idxcand ){ - - // Here, the type will be a simple reco::Candidate. We cast it - // for full PFCandidate or PackedCandidate below as necessary - const auto& iCand = pfCandidatesHandle->ptrAt(idxcand); - - // One would think that we should check that this iCand from - // the generic PF collection is not identical to the iPho photon - // for which we are computing the isolations. However, it turns out - // to be unnecessary. Below, in the function isInFootprint(), we drop - // this iCand if it is in the footprint, and this always removes - // the iCand if it matches the iPho. - // The explicit check at this point is not totally trivial because - // of non-triviality of implementation of this check for miniAOD (PackedCandidates - // of the PF collection do not contain the supercluser link, so can't use that). - // if( isAOD ){ - // if( ((const recoCandPtr)iCand)->superClusterRef() == iPho->superCluster() ) continue; - // } - - - // Check if this candidate is within the isolation cone - float dR2 = deltaR2(photon_directionWrtVtx.Eta(),photon_directionWrtVtx.Phi(), - iCand->eta(), iCand->phi()); - if( dR2 > coneSizeDR*coneSizeDR ) continue; - - // Check if this candidate is not in the footprint - bool inFootprint = false; - if(isAOD) { - inFootprint = isInFootprint( (*particleBasedIsolationMap)[iPho], iCand ); - } else { - edm::Ptr patPhotonPtr(src->ptrAt(idxpho)); - inFootprint = isInFootprint(patPhotonPtr->associatedPackedPFCandidates(), iCand); - } - - if( inFootprint ) continue; - - // Find candidate type - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD); - - // Increment the appropriate isolation sum - if( thisCandidateType == reco::PFCandidate::h ){ - // for charged hadrons, additionally check consistency - // with the PV - float dxy = -999, dz=-999; - getImpactParameters(iCand, isAOD, pv, dxy, dz); - - - if(fabs(dxy) > dxyMax) continue; - if (fabs(dz) > dzMax) continue; - - // The candidate is eligible, increment the isolaiton - chargedIsoSum += iCand->pt(); - } - - if( thisCandidateType == reco::PFCandidate::h0 ) - neutralHadronIsoSum += iCand->pt(); - - if( thisCandidateType == reco::PFCandidate::gamma ) - photonIsoSum += iCand->pt(); + if (!src.isValid()) { + throw cms::Exception("IllDefinedDataTier") << "DataFormat does not contain a photon source!"; } - phoChargedIsolation .push_back( chargedIsoSum ); - phoNeutralHadronIsolation.push_back( neutralHadronIsoSum ); - phoPhotonIsolation .push_back( photonIsoSum ); - - // Worst isolation computed with no vetos or ptMin cut, as in - // Run 1 Hgg code. - float dRvetoBarrel = 0.0; - float dRvetoEndcap = 0.0; - float ptMin = 0.0; - bool isPVConstraint=false; - float worstChargedIso = - computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, - isAOD, isPVConstraint,pv,coneSizeDR, dxyMax, dzMax, - dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolation .push_back( worstChargedIso ); - - // Worst isolation computed with cone vetos and a ptMin cut, as in - // Run 2 Hgg code. - dRvetoBarrel = 0.02; - dRvetoEndcap = 0.02; - ptMin = 0.1; - float worstChargedIsoWithConeVeto = - computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, - isAOD, isPVConstraint,pv, coneSizeDR, dxyMax, dzMax, - dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationConeVeto .push_back( worstChargedIsoWithConeVeto ); - - isPVConstraint=true; - float worstChargedIsoWithPVConstraint = - computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, - isAOD, isPVConstraint,pv,coneSizeDR, dxyMax, dzMax, - dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationConeVetoPVConstr .push_back( worstChargedIsoWithPVConstraint ); - - // Worst isolation computed with cone vetos and a ptMin cut, as in - // Run 2 Hgg code. - dRvetoBarrel = 0.02; - dRvetoEndcap = 0.02; - ptMin = 0.1; - float worstChargedIsoWithConeVetoWithPVConstraint = - computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices, - isAOD,isPVConstraint, pv, coneSizeDR, dxyMax, dzMax, - dRvetoBarrel, dRvetoEndcap, ptMin); - phoWorstChargedIsolationConeVetoWithPVConstraint .push_back( worstChargedIsoWithConeVetoWithPVConstraint ); - - - - } - - // Cluster shapes - writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIEta, phoFull5x5SigmaIEtaIEta_); - writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIPhi, phoFull5x5SigmaIEtaIPhi_); - writeValueMap(iEvent, src, phoFull5x5E1x3 , phoFull5x5E1x3_); - writeValueMap(iEvent, src, phoFull5x5E2x2 , phoFull5x5E2x2_); - writeValueMap(iEvent, src, phoFull5x5E2x5Max, phoFull5x5E2x5Max_); - writeValueMap(iEvent, src, phoFull5x5E5x5 , phoFull5x5E5x5_); - writeValueMap(iEvent, src, phoESEffSigmaRR , phoESEffSigmaRR_); - // Cluster shape ratios - writeValueMap(iEvent, src, phoFull5x5E1x3byE5x5 , phoFull5x5E1x3byE5x5_); - writeValueMap(iEvent, src, phoFull5x5E2x2byE5x5 , phoFull5x5E2x2byE5x5_); - writeValueMap(iEvent, src, phoFull5x5E2x5byE5x5 , phoFull5x5E2x5byE5x5_); - // Isolation - writeValueMap(iEvent, src, phoChargedIsolation, phoChargedIsolation_); - writeValueMap(iEvent, src, phoNeutralHadronIsolation, phoNeutralHadronIsolation_); - writeValueMap(iEvent, src, phoPhotonIsolation, phoPhotonIsolation_); - writeValueMap(iEvent, src, phoWorstChargedIsolation, phoWorstChargedIsolation_); - writeValueMap(iEvent, src, phoWorstChargedIsolationConeVeto, phoWorstChargedIsolationConeVeto_); - writeValueMap(iEvent, src, phoWorstChargedIsolationConeVetoPVConstr, phoWorstChargedIsolationConeVetoPVConstr_); - writeValueMap(iEvent, src, phoWorstChargedIsolationConeVetoWithPVConstraint, phoWorstChargedIsolationConeVetoWithPVConstraint_); - //PFCluster Isolation - writeValueMap(iEvent, src, phoTrkIsolation, phoTrkIsolation_); - writeValueMap(iEvent, src, phoHcalPFClIsolation, phoHcalPFClIsolation_); - writeValueMap(iEvent, src, phoEcalPFClIsolation, phoEcalPFClIsolation_); + // Configure Lazy Tools + if (usesES_) { + if (isAOD_) + lazyToolnoZS = std::make_unique( + iEvent, iSetup, ebReducedRecHitCollection_, eeReducedRecHitCollection_, esReducedRecHitCollection_); + else + lazyToolnoZS + = std::make_unique(iEvent, iSetup, ebReducedRecHitCollectionMiniAOD_, + eeReducedRecHitCollectionMiniAOD_, esReducedRecHitCollectionMiniAOD_); + } else { + if (isAOD_) + lazyToolnoZS = std::make_unique( + iEvent, iSetup, ebReducedRecHitCollection_, eeReducedRecHitCollection_); + else + lazyToolnoZS = std::make_unique( + iEvent, iSetup, ebReducedRecHitCollectionMiniAOD_, eeReducedRecHitCollectionMiniAOD_); + } -} + // Get PV + edm::Handle vertices; + iEvent.getByToken(vtxToken_, vertices); + if (!vertices.isValid()) + iEvent.getByToken(vtxTokenMiniAOD_, vertices); + if (vertices->empty()) + return; // skip the event if no PV found + const reco::Vertex& pv = vertices->front(); + + edm::Handle>> particleBasedIsolationMap; + if (isAOD_) { + // this exists only in AOD + iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap); + } -void PhotonIDValueMapProducer::writeValueMap(edm::Event &iEvent, - const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const -{ - using namespace edm; - using namespace std; - auto valMap = std::make_unique>(); - edm::ValueMap::Filler filler(*valMap); - filler.insert(handle, values.begin(), values.end()); - filler.fill(); - iEvent.put(std::move(valMap), label); + edm::Handle> pfCandsHandle; + + iEvent.getByToken(pfCandsToken_, pfCandsHandle); + if (!pfCandsHandle.isValid()) + iEvent.getByToken(pfCandsTokenMiniAOD_, pfCandsHandle); + + if (!isAOD_ && !src->empty()) { + edm::Ptr test(src->ptrAt(0)); + if (test.isNull() || !test.isAvailable()) { + throw cms::Exception("InvalidConfiguration") + << "DataFormat is detected as miniAOD but cannot cast to pat::Photon!"; + } + } + + std::vector vars[nVars_]; + + // reco::Photon::superCluster() is virtual so we can exploit polymorphism + for (unsigned i = 0; i < src->size(); ++i) { + const auto& iPho = src->ptrAt(i); + + // + // Compute full 5x5 quantities + // + const auto& theseed = *(iPho->superCluster()->seed()); + + // For full5x5_sigmaIetaIeta, for 720 we use: lazy tools for AOD, + // and userFloats or lazy tools for miniAOD. From some point in 72X and on, one can + // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta() + // for both formats. + std::vector vCov = lazyToolnoZS->localCovariances(theseed); + vars[0].push_back(isnan(vCov[0]) ? 0. : sqrt(vCov[0])); + vars[1].push_back(vCov[1]); + vars[2].push_back(lazyToolnoZS->e1x3(theseed)); + vars[3].push_back(lazyToolnoZS->e2x2(theseed)); + vars[4].push_back(lazyToolnoZS->e2x5Max(theseed)); + vars[5].push_back(lazyToolnoZS->e5x5(theseed)); + vars[6].push_back(lazyToolnoZS->eseffsirir(*(iPho->superCluster()))); + vars[7].push_back(vars[2][i] / vars[5][i]); + vars[8].push_back(vars[3][i] / vars[5][i]); + vars[9].push_back(vars[4][i] / vars[5][i]); + + // + // Compute absolute uncorrected isolations with footprint removal + // + + // First, find photon direction with respect to the good PV + math::XYZVector phoWrtVtx( + iPho->superCluster()->x() - pv.x(), iPho->superCluster()->y() - pv.y(), iPho->superCluster()->z() - pv.z()); + + // isolation sums + float chargedIsoSum = 0.; + float neutralHadronIsoSum = 0.; + float photonIsoSum = 0.; + + // Loop over all PF candidates + for (unsigned int idxcand = 0; idxcand < pfCandsHandle->size(); ++idxcand) { + + // Here, the type will be a simple reco::Candidate. We cast it + // for full PFCandidate or PackedCandidate below as necessary + const auto& iCand = pfCandsHandle->ptrAt(idxcand); + + // One would think that we should check that this iCand from the + // generic PF collection is not identical to the iPho photon for + // which we are computing the isolations. However, it turns out to + // be unnecessary. Below, in the function isInFootprint(), we drop + // this iCand if it is in the footprint, and this always removes + // the iCand if it matches the iPho. The explicit check at this + // point is not totally trivial because of non-triviality of + // implementation of this check for miniAOD (PackedCandidates of + // the PF collection do not contain the supercluser link, so can't + // use that). + // + // if( isAOD_ ) { + // if( ((const edm::Ptr)iCand)->superClusterRef() == iPho->superCluster() ) + // continue; + // } + + // Check if this candidate is within the isolation cone + float dR2 = deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi()); + if (dR2 > coneSizeDR * coneSizeDR) + continue; + + // Check if this candidate is not in the footprint + if (isAOD_) { + if(isInFootprint((*particleBasedIsolationMap)[iPho], iCand)) + continue; + } else { + edm::Ptr patPhotonPtr(src->ptrAt(i)); + if(isInFootprint(patPhotonPtr->associatedPackedPFCandidates(), iCand)) + continue; + } + + // Find candidate type + reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand); + + // Increment the appropriate isolation sum + if (thisCandidateType == reco::PFCandidate::h) { + // for charged hadrons, additionally check consistency + // with the PV + float dxy = -999; + float dz = -999; + getImpactParameters(iCand, pv, dxy, dz); + + if (fabs(dxy) > dxyMax || fabs(dz) > dzMax) + continue; + + // The candidate is eligible, increment the isolaiton + chargedIsoSum += iCand->pt(); + } + + if (thisCandidateType == reco::PFCandidate::h0) + neutralHadronIsoSum += iCand->pt(); + + if (thisCandidateType == reco::PFCandidate::gamma) + photonIsoSum += iCand->pt(); + } + + vars[10].push_back(chargedIsoSum); + vars[11].push_back(neutralHadronIsoSum); + vars[12].push_back(photonIsoSum); + + // Worst isolation computed with no vetos or ptMin cut, as in Run 1 Hgg code. + unsigned char options = 0; + vars[13].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + + // Worst isolation computed with cone vetos and a ptMin cut, as in Run 2 Hgg code. + options |= PT_MIN_THRESH | DR_VETO; + vars[14].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + + // Like before, but adding primary vertex constraint + options |= PV_CONSTRAINT; + vars[15].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + + // PFCluster Isolations + vars[16].push_back(iPho->trkSumPtSolidConeDR04()); + if (isAOD_) { + vars[17].push_back(0.f); + vars[18].push_back(0.f); + } else { + edm::Ptr patPhotonPtr{ src->ptrAt(i) }; + vars[17].push_back(patPhotonPtr->hcalPFClusterIso()); + vars[18].push_back(patPhotonPtr->ecalPFClusterIso()); + } + + } + + // write the value maps + for (int i = 0; i < nVars_; ++i) { + auto valMap = std::make_unique>(); + edm::ValueMap::Filler filler(*valMap); + filler.insert(src, vars[i].begin(), vars[i].end()); + filler.fill(); + iEvent.put(std::move(valMap), names[i]); + } } -void PhotonIDValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); +void PhotonIDValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +{ + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.add("ebReducedRecHitCollection"); + desc.add("ebReducedRecHitCollectionMiniAOD"); + desc.add("eeReducedRecHitCollection"); + desc.add("eeReducedRecHitCollectionMiniAOD"); + desc.add("esReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsES")); + desc.add("esReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma:reducedESRecHits")); + desc.add("vertices"); + desc.add("verticesMiniAOD"); + desc.add("src"); + desc.add("srcMiniAOD"); + desc.add("particleBasedIsolation"); + desc.add("pfCandidates"); + desc.add("pfCandidatesMiniAOD"); + descriptions.addDefault(desc); } // Charged isolation with respect to the worst vertex. See more // comments above at the function declaration. template -float PhotonIDValueMapProducer -::computeWorstPFChargedIsolation(const T& photon, const U& pfCandidates, - const edm::Handle vertices, - bool isAOD, bool isPVConstraint,const reco::Vertex& pv, - float dRmax, float dxyMax, float dzMax, - float dRvetoBarrel, float dRvetoEndcap, float ptMin){ - - - float worstIsolation = 999; - std::vector allIsolations; - - float dRveto; - if (photon->isEB()) - dRveto = dRvetoBarrel; - else - dRveto = dRvetoEndcap; - - //Calculate isolation sum separately for each vertex - for(unsigned int ivtx=0; ivtxsize(); ++ivtx) { - - // Shift the photon according to the vertex - reco::VertexRef vtx(vertices, ivtx); - math::XYZVector photon_directionWrtVtx(photon->superCluster()->x() - vtx->x(), - photon->superCluster()->y() - vtx->y(), - photon->superCluster()->z() - vtx->z()); - - float sum = 0; - // Loop over the PFCandidates - for(unsigned i=0; isize(); i++) { - - const auto& iCand = pfCandidates->ptrAt(i); - - //require that PFCandidate is a charged hadron - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD); - if (thisCandidateType != reco::PFCandidate::h) - continue; - - if (iCand->pt() < ptMin) - continue; - - float dxy=-999, dz=-999; - if(isPVConstraint) getImpactParameters(iCand, isAOD, pv, dxy, dz); - else getImpactParameters(iCand, isAOD, *vtx, dxy, dz); - - - - if( fabs(dxy) > dxyMax) continue; - if ( fabs(dz) > dzMax) continue; - - float dR2 = deltaR2(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(), - iCand->eta(), iCand->phi()); - if(dR2 > dRmax*dRmax || dR2 < dRveto*dRveto) continue; - - sum += iCand->pt(); - } +float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, const U& pfCands, + const edm::Handle vertices, const reco::Vertex& pv, unsigned char options) +{ + float worstIsolation = 0.0; - allIsolations.push_back(sum); - } + const float dRveto = photon->isEB() ? dRvetoBarrel : dRvetoEndcap; - if( !allIsolations.empty() ) - worstIsolation = * std::max_element( allIsolations.begin(), allIsolations.end() ); - - return worstIsolation; -} + // Calculate isolation sum separately for each vertex + for (unsigned int ivtx = 0; ivtx < vertices->size(); ++ivtx) { + // Shift the photon according to the vertex + reco::VertexRef vtx(vertices, ivtx); + math::XYZVector phoWrtVtx(photon->superCluster()->x() - vtx->x(), + photon->superCluster()->y() - vtx->y(), photon->superCluster()->z() - vtx->z()); -reco::PFCandidate::ParticleType -PhotonIDValueMapProducer::candidatePdgId(const edm::Ptr candidate, - bool isAOD){ - - reco::PFCandidate::ParticleType thisCandidateType = reco::PFCandidate::X; - if( isAOD ) - thisCandidateType = ( (const recoCandPtr)candidate)->particleId(); - else { - // the neutral hadrons and charged hadrons can be of pdgId types - // only 130 (K0L) and +-211 (pi+-) in packed candidates - const int pdgId = ( (const patCandPtr)candidate)->pdgId(); - if( pdgId == 22 ) - thisCandidateType = reco::PFCandidate::gamma; - else if( abs(pdgId) == 130) // PDG ID for K0L - thisCandidateType = reco::PFCandidate::h0; - else if( abs(pdgId) == 211) // PDG ID for pi+- - thisCandidateType = reco::PFCandidate::h; - } - return thisCandidateType; -} + float sum = 0; + // Loop over the PFCandidates + for (unsigned int i = 0; i < pfCands->size(); i++) { -const reco::Track* -PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr candidate, bool isAOD){ + const auto& iCand = pfCands->ptrAt(i); - const reco::Track* theTrack = nullptr; - if( isAOD ) - theTrack = &*( ((const recoCandPtr) candidate)->trackRef()); - else - theTrack = &( ((const patCandPtr) candidate)->pseudoTrack()); + // require that PFCandidate is a charged hadron + reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand); + if (thisCandidateType != reco::PFCandidate::h) + continue; - return theTrack; + if ((options & PT_MIN_THRESH) && iCand->pt() < ptMin) + continue; + + float dxy = -999; + float dz = -999; + if (options & PV_CONSTRAINT) + getImpactParameters(iCand, pv, dxy, dz); + else + getImpactParameters(iCand, *vtx, dxy, dz); + + if (fabs(dxy) > dxyMax || fabs(dz) > dzMax) + continue; + + float dR2 = deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi()); + if (dR2 > coneSizeDR * coneSizeDR || + (options & DR_VETO && dR2 < dRveto * dRveto)) + continue; + + sum += iCand->pt(); + } + + worstIsolation = std::max(sum, worstIsolation); + } + + return worstIsolation; } -void PhotonIDValueMapProducer::getImpactParameters(const edm::Ptr& candidate, - bool isAOD, const reco::Vertex& pv, - float &dxy, float &dz){ +reco::PFCandidate::ParticleType PhotonIDValueMapProducer::candidatePdgId( + const edm::Ptr candidate) +{ + if (isAOD_) + return ((const edm::Ptr)candidate)->particleId(); - dxy=-999; - dz=-999; - if( isAOD ) { - const reco::Track *theTrack = &*( ((const recoCandPtr) candidate)->trackRef()); - dxy = theTrack->dxy(pv.position()); - dz = theTrack->dz(pv.position()); - } else { - const pat::PackedCandidate & aCand = *(patCandPtr(candidate)); - dxy = aCand.dxy(pv.position()); - dz = aCand.dz(pv.position()); + // the neutral hadrons and charged hadrons can be of pdgId types + // only 130 (K0L) and +-211 (pi+-) in packed candidates + const int pdgId = ((const edm::Ptr)candidate)->pdgId(); + if (pdgId == 22) + return reco::PFCandidate::gamma; + else if (abs(pdgId) == 130) // PDG ID for K0L + return reco::PFCandidate::h0; + else if (abs(pdgId) == 211) // PDG ID for pi+- + return reco::PFCandidate::h; + else + return reco::PFCandidate::X; +} - } +const reco::Track* PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr candidate) +{ + return isAOD_ ? + &*(((const edm::Ptr)candidate)->trackRef()) : + &(((const edm::Ptr)candidate)->pseudoTrack()); +} +void PhotonIDValueMapProducer::getImpactParameters( + const edm::Ptr& candidate, const reco::Vertex& pv, float& dxy, float& dz) +{ + if (isAOD_) { + auto theTrack = *static_cast>(candidate)->trackRef(); + dxy = theTrack.dxy(pv.position()); + dz = theTrack.dz(pv.position()); + } else { + auto aCand = *static_cast>(candidate); + dxy = aCand.dxy(pv.position()); + dz = aCand.dz(pv.position()); + } } DEFINE_FWK_MODULE(PhotonIDValueMapProducer); From fedf904031ee1447e01097db2aa2bf758029bfed Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 1 Nov 2018 13:24:30 +0100 Subject: [PATCH 08/13] cache AOD/miniAOD values to speed up repeated computations --- .../plugins/PhotonIDValueMapProducer.cc | 86 +++++++++++-------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index bfdf872f5c473..a948286ae0124 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -12,6 +12,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +namespace { // This template function finds whether theCandidate is in thefootprint // collection. It is templated to be able to handle both reco and pat // photons (from AOD and miniAOD, respectively). @@ -25,6 +26,31 @@ bool isInFootprint(const T& footprint, const U& candidate) return false; } + struct CachingPtrCandidate { + CachingPtrCandidate(const reco::Candidate* cPtr, bool isAOD) : + candidate(cPtr), + track(isAOD? &*static_cast(cPtr)->trackRef() : nullptr), + packed(isAOD? nullptr : static_cast(cPtr)) + {} + + const reco::Candidate* candidate; + const reco::Track* track; + const pat::PackedCandidate* packed; + }; + + void getImpactParameters(const CachingPtrCandidate& candidate, const reco::Vertex& pv, float& dxy, float& dz) + { + if (candidate.track != nullptr) { + dxy = candidate.track->dxy(pv.position()); + dz = candidate.track->dz(pv.position()); + } else { + dxy = candidate.packed->dxy(pv.position()); + dz = candidate.packed->dz(pv.position()); + } + } + +}; + class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { public: @@ -52,11 +78,9 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { // Some helper functions that are needed to access info in // AOD vs miniAOD - reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr candidate); + reco::PFCandidate::ParticleType candidatePdgId(const reco::Candidate* candidate); const reco::Track* getTrackPointer(const edm::Ptr candidate); - void getImpactParameters( - const edm::Ptr& candidate, const reco::Vertex& pv, float& dxy, float& dz); // The object that will compute 5x5 quantities std::unique_ptr lazyToolnoZS; @@ -305,7 +329,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup } // Find candidate type - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand); + reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(&*iCand); // Increment the appropriate isolation sum if (thisCandidateType == reco::PFCandidate::h) { @@ -313,7 +337,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup // with the PV float dxy = -999; float dz = -999; - getImpactParameters(iCand, pv, dxy, dz); + getImpactParameters(CachingPtrCandidate(&*iCand, isAOD_), pv, dxy, dz); if (fabs(dxy) > dxyMax || fabs(dz) > dzMax) continue; @@ -399,6 +423,21 @@ float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, const float dRveto = photon->isEB() ? dRvetoBarrel : dRvetoEndcap; + std::vector chargedCands; + chargedCands.reserve(pfCands->size()); + for (auto const& aCand : *pfCands){ + + // require that PFCandidate is a charged hadron + reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(&aCand); + if (thisCandidateType != reco::PFCandidate::h) + continue; + + if ((options & PT_MIN_THRESH) && aCand.pt() < ptMin) + continue; + + chargedCands.emplace_back(&aCand, isAOD_); + } + // Calculate isolation sum separately for each vertex for (unsigned int ivtx = 0; ivtx < vertices->size(); ++ivtx) { @@ -409,28 +448,19 @@ float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, float sum = 0; // Loop over the PFCandidates - for (unsigned int i = 0; i < pfCands->size(); i++) { - - const auto& iCand = pfCands->ptrAt(i); - - // require that PFCandidate is a charged hadron - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand); - if (thisCandidateType != reco::PFCandidate::h) - continue; - - if ((options & PT_MIN_THRESH) && iCand->pt() < ptMin) - continue; + for (auto const& aCCand : chargedCands) { float dxy = -999; float dz = -999; if (options & PV_CONSTRAINT) - getImpactParameters(iCand, pv, dxy, dz); + getImpactParameters(aCCand, pv, dxy, dz); else - getImpactParameters(iCand, *vtx, dxy, dz); + getImpactParameters(aCCand, *vtx, dxy, dz); if (fabs(dxy) > dxyMax || fabs(dz) > dzMax) continue; + auto iCand = aCCand.candidate; float dR2 = deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi()); if (dR2 > coneSizeDR * coneSizeDR || (options & DR_VETO && dR2 < dRveto * dRveto)) @@ -446,14 +476,14 @@ float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, } reco::PFCandidate::ParticleType PhotonIDValueMapProducer::candidatePdgId( - const edm::Ptr candidate) + const reco::Candidate* candidate) { if (isAOD_) - return ((const edm::Ptr)candidate)->particleId(); + return static_cast(candidate)->particleId(); // the neutral hadrons and charged hadrons can be of pdgId types // only 130 (K0L) and +-211 (pi+-) in packed candidates - const int pdgId = ((const edm::Ptr)candidate)->pdgId(); + const int pdgId = static_cast(candidate)->pdgId(); if (pdgId == 22) return reco::PFCandidate::gamma; else if (abs(pdgId) == 130) // PDG ID for K0L @@ -471,18 +501,4 @@ const reco::Track* PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr)candidate)->pseudoTrack()); } -void PhotonIDValueMapProducer::getImpactParameters( - const edm::Ptr& candidate, const reco::Vertex& pv, float& dxy, float& dz) -{ - if (isAOD_) { - auto theTrack = *static_cast>(candidate)->trackRef(); - dxy = theTrack.dxy(pv.position()); - dz = theTrack.dz(pv.position()); - } else { - auto aCand = *static_cast>(candidate); - dxy = aCand.dxy(pv.position()); - dz = aCand.dz(pv.position()); - } -} - DEFINE_FWK_MODULE(PhotonIDValueMapProducer); From 9b56f8afe2d9410a729452e76cdc8f67fd6636eb Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Mon, 3 Dec 2018 00:05:39 +0100 Subject: [PATCH 09/13] Cleaned imports in Spring15 phtoton MVA cfg --- .../mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py | 7 +------ .../mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py | 7 +------ .../mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py | 7 +------ .../mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py | 7 +------ .../mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py | 7 +------ .../mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py | 7 +------ .../mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py | 7 +------ 7 files changed, 7 insertions(+), 42 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py index 267b3da9530cc..89c195410c3bb 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V0_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15ValMaps.txt" @@ -32,9 +30,6 @@ path.join(weightFileBaseDir, "Spring15/25ns_EE_V0.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py index 0f2e9b0eeda25..5a76e775f9da6 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15ValMaps.txt" @@ -33,9 +31,6 @@ path.join(weightFileBaseDir, "Spring15/25ns_EE_V2.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py index 548c5f4ce0e1b..b835d4f0a3283 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_25ns_nonTrig_V2p1_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15.txt" @@ -35,9 +33,6 @@ path.join(weightFileBaseDir, "Spring15/25ns_EE_V2.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py index b7c1ce6c72155..d47a094c245e4 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V0_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15ValMaps.txt" @@ -32,9 +30,6 @@ path.join(weightFileBaseDir, "Spring15/50ns_EE_V0.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py index e63268bb8e121..381f20bd179ff 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V1_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15ValMaps.txt" @@ -32,9 +30,6 @@ path.join(weightFileBaseDir, "Spring15/50ns_EE_V1.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py index fe27e209e02c2..9c8cd6854d9b9 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15ValMaps.txt" @@ -34,9 +32,6 @@ path.join(weightFileBaseDir, "Spring15/50ns_EE_V2.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" diff --git a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py index 6563250e11a2d..577de6e0de238 100644 --- a/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py +++ b/RecoEgamma/PhotonIdentification/python/Identification/mvaPhotonID_Spring15_50ns_nonTrig_V2p1_cff.py @@ -1,6 +1,4 @@ -from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry - -import FWCore.ParameterSet.Config as cms +from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun2VariablesSpring15.txt" @@ -36,9 +34,6 @@ path.join(weightFileBaseDir, "Spring15/50ns_EE_V2.weights.xml.gz"), ) -# Load some common definitions for MVA machinery -from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_tools import * - # The locatoins of value maps with the actual MVA values and categories # for all particles. # The names for the maps are ":Values" From 3cef419a64fb6c1476cd2bd82608105a5af31f50 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Mon, 3 Dec 2018 00:10:55 +0100 Subject: [PATCH 10/13] Sync PhotonIDValueMapProducer with master plus MultiToken and Utils --- .../Trigger/python/HLTEGTnPMonitor_cfi.py | 2 +- PhysicsTools/NanoAOD/python/photons_cff.py | 2 +- RecoEgamma/EgammaTools/interface/MultiToken.h | 180 ++++++++++ RecoEgamma/EgammaTools/interface/Utils.h | 25 ++ .../plugins/PhotonIDValueMapProducer.cc | 323 +++++++----------- .../python/PhotonIDValueMapProducer_cfi.py | 31 -- .../python/egmPhotonIDs_cff.py | 2 +- .../python/photonIDValueMapProducer_cff.py | 9 + 8 files changed, 342 insertions(+), 232 deletions(-) create mode 100644 RecoEgamma/EgammaTools/interface/MultiToken.h create mode 100644 RecoEgamma/EgammaTools/interface/Utils.h delete mode 100644 RecoEgamma/PhotonIdentification/python/PhotonIDValueMapProducer_cfi.py create mode 100644 RecoEgamma/PhotonIdentification/python/photonIDValueMapProducer_cff.py diff --git a/DQMOffline/Trigger/python/HLTEGTnPMonitor_cfi.py b/DQMOffline/Trigger/python/HLTEGTnPMonitor_cfi.py index 72bbd7a0f8446..84a5de9c9984a 100644 --- a/DQMOffline/Trigger/python/HLTEGTnPMonitor_cfi.py +++ b/DQMOffline/Trigger/python/HLTEGTnPMonitor_cfi.py @@ -989,7 +989,7 @@ setupVIDSelection(egmGsfElectronIDsForDQM,item) -from RecoEgamma.PhotonIdentification.PhotonIDValueMapProducer_cfi import photonIDValueMapProducer +from RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff import photonIDValueMapProducer from RecoEgamma.PhotonIdentification.egmPhotonIDs_cfi import egmPhotonIDs egmPhotonIDsForDQM = egmPhotonIDs.clone() egmPhotonIDsForDQM.physicsObjectsIDs = cms.VPSet() diff --git a/PhysicsTools/NanoAOD/python/photons_cff.py b/PhysicsTools/NanoAOD/python/photons_cff.py index af089c2eaddeb..f129799494382 100644 --- a/PhysicsTools/NanoAOD/python/photons_cff.py +++ b/PhysicsTools/NanoAOD/python/photons_cff.py @@ -11,7 +11,7 @@ from PhysicsTools.SelectorUtils.tools.vid_id_tools import setupVIDSelection from RecoEgamma.PhotonIdentification.egmPhotonIDs_cfi import * -from RecoEgamma.PhotonIdentification.PhotonIDValueMapProducer_cfi import * +from RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff import * from RecoEgamma.PhotonIdentification.PhotonMVAValueMapProducer_cfi import * from RecoEgamma.PhotonIdentification.PhotonRegressionValueMapProducer_cfi import * from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationMiniAOD_cff import * diff --git a/RecoEgamma/EgammaTools/interface/MultiToken.h b/RecoEgamma/EgammaTools/interface/MultiToken.h new file mode 100644 index 0000000000000..ed8ee2df3c71e --- /dev/null +++ b/RecoEgamma/EgammaTools/interface/MultiToken.h @@ -0,0 +1,180 @@ +#ifndef RecoEgamma_EgammaTools_MultiToken_H +#define RecoEgamma_EgammaTools_MultiToken_H + +#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Utilities/interface/InputTag.h" + +/* + * This class is a wrapper around a vector of EDM tokens, of which at least one + * is expected to yield a valid handle. + * + * The first time you call getValidHandle() or getHandle(), it will go over all + * tokens and try to get a valid handle. If no token yields a valid handle, it + * will either throw and exception or return the last non-valid handle. + * + * Once it found a valid handle, it will remember which token was used to get + * it and therefore doesn't need to loop over all tokens from there on. + * + * Example use case: auto-detection of AOD vs. MiniAOD. + * + * Created by Jonas Rembser on August 3, 2018. + */ + +#include + +template +class MultiTokenT { + + using GoodIndexType = std::shared_ptr>; + + public: + + template + MultiTokenT(edm::ConsumesCollector && cc, Tags ... tags) + : isMaster_(true) + , tokens_({cc.mayConsume(edm::InputTag(tags))...}) + , goodIndex_(std::make_shared>(-1)) + {} + + // Constructor which gets the input tags from a config to create the tokens plus master token + template + MultiTokenT(const MultiTokenT& master, edm::ConsumesCollector && cc, Tags ... tags) + : isMaster_(false) + , tokens_({cc.mayConsume(edm::InputTag(tags))...}) + , goodIndex_(master.getGoodTokenIndexPtr()) + {} + + // Constructor which gets the input tags from a config to create the tokens + template + MultiTokenT(edm::ConsumesCollector && cc, const edm::ParameterSet& pset, Tags && ... tags) + : isMaster_(true) + , tokens_({cc.mayConsume(pset.getParameter(tags))...}) + , goodIndex_(std::make_shared>(-1)) + {} + + // Constructor which gets the input tags from a config to create the tokens plus master token + template + MultiTokenT(const MultiTokenT& master, edm::ConsumesCollector && cc, const edm::ParameterSet& pset, Tags && ... tags) + : isMaster_(false) + , tokens_({cc.mayConsume(pset.getParameter(tags))...}) + , goodIndex_(master.getGoodTokenIndexPtr()) + {} + + // Get a handle on the event data, non-valid handle is allowed + edm::Handle getHandle(const edm::Event& iEvent) const + { + edm::Handle handle; + + // If we already know which token works, take that one + if (*goodIndex_ >= 0) { + iEvent.getByToken(tokens_[*goodIndex_], handle); + return handle; + } + + if (!isMaster_) { + throw cms::Exception("MultiTokenTException") << + "Trying to get a handle from a depending MultiToken before the master!"; + } + + // If not, set the good token index parallel to getting the handle + handle = getInitialHandle(iEvent); + + if (*goodIndex_ == -1) { + *goodIndex_ = tokens_.size() - 1; + } + return handle; + } + + // Get a handle on the event data, + // throw exception if no token yields a valid handle + edm::Handle getValidHandle(const edm::Event& iEvent) const + { + edm::Handle handle; + + // If we already know which token works, take that one + if (*goodIndex_ >= 0) { + iEvent.getByToken(tokens_[*goodIndex_], handle); + if (!handle.isValid()) + throw cms::Exception("MultiTokenTException") << + "Token gave valid handle previously but not anymore!"; + return handle; + } + + if (!isMaster_) { + throw cms::Exception("MultiTokenTException") << + "Trying to get a handle from a depending MultiToken before the master!"; + } + + // If not, set the good token index parallel to getting the handle + handle = getInitialHandle(iEvent); + + if (*goodIndex_ == -1) { + throw cms::Exception("MultiTokenTException") << "Neither handle is valid!"; + } + return handle; + } + + // get the good token + edm::EDGetTokenT get(const edm::Event& iEvent) const + { + // If we already know which token works, take that index + if (*goodIndex_ >= 0) + return tokens_[*goodIndex_]; + + // If this is not a master MultiToken, just return what it got + if (!isMaster_) { + throw cms::Exception("MultiTokenTException") << + "Trying to get a handle from a depending MultiToken before the master!"; + } + + // Find which token is the good one by trying to get a handle + edm::Handle handle; + for (auto token:tokens_ ) { + iEvent.getByToken(token, handle); + if (handle.isValid()) { + return token; + } + } + + throw cms::Exception("MultiTokenTException") << "Neither token is valid!"; + } + + int getGoodTokenIndex() const + { + return *goodIndex_; + } + + GoodIndexType getGoodTokenIndexPtr() const + { + return goodIndex_; + } + + private: + + edm::Handle getInitialHandle(const edm::Event& iEvent) const + { + // Try to retrieve the collection from the event. If we fail to + // retrieve the collection with one name, we next look for the one with + // the other name and so on. + edm::Handle handle; + for (size_t i = 0; i < tokens_.size(); ++i) { + iEvent.getByToken(tokens_[i], handle); + if (handle.isValid()) { + *goodIndex_ = i; + return handle; + } + } + return handle; + } + + const bool isMaster_; + const std::vector> tokens_; + const GoodIndexType goodIndex_; +}; + +#endif diff --git a/RecoEgamma/EgammaTools/interface/Utils.h b/RecoEgamma/EgammaTools/interface/Utils.h new file mode 100644 index 0000000000000..84755b5dabfef --- /dev/null +++ b/RecoEgamma/EgammaTools/interface/Utils.h @@ -0,0 +1,25 @@ +#ifndef RecoEgamma_EgammaTools_Utils_H +#define RecoEgamma_EgammaTools_Utils_H + +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "FWCore/Framework/interface/Event.h" + +#include +#include +#include + +template +void writeValueMap(edm::Event &iEvent, + const edm::Handle& handle, + const std::vector& values, + const std::string& label) +{ + auto valMap = std::make_unique>(); + typename edm::ValueMap::Filler filler(*valMap); + filler.insert(handle, values.begin(), values.end()); + filler.fill(); + iEvent.put(std::move(valMap),label); +} + +#endif diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index a948286ae0124..b0ed77a3d03d6 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -8,23 +8,30 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +#include "RecoEgamma/EgammaTools/interface/MultiToken.h" +#include "RecoEgamma/EgammaTools/interface/Utils.h" +#include "FWCore/Utilities/interface/isFinite.h" namespace { -// This template function finds whether theCandidate is in thefootprint -// collection. It is templated to be able to handle both reco and pat -// photons (from AOD and miniAOD, respectively). -template -bool isInFootprint(const T& footprint, const U& candidate) -{ - for (auto& it : footprint) { - if (it.key() == candidate.key()) - return true; - } - return false; -} + + // This template function finds whether theCandidate is in thefootprint + // collection. It is templated to be able to handle both reco and pat + // photons (from AOD and miniAOD, respectively). + template + bool isInFootprint(const T& footprint, + const edm::Ptr& candidate) + { + for (auto& it : footprint) { + if (it.key() == candidate.key()) + return true; + } + return false; + } struct CachingPtrCandidate { CachingPtrCandidate(const reco::Candidate* cPtr, bool isAOD) : @@ -49,18 +56,38 @@ bool isInFootprint(const T& footprint, const U& candidate) } } + // Some helper functions that are needed to access info in + // AOD vs miniAOD + reco::PFCandidate::ParticleType getCandidatePdgId(const reco::Candidate* candidate, bool isAOD) + { + if (isAOD) + return static_cast(candidate)->particleId(); + + // the neutral hadrons and charged hadrons can be of pdgId types + // only 130 (K0L) and +-211 (pi+-) in packed candidates + const int pdgId = static_cast(candidate)->pdgId(); + if (pdgId == 22) + return reco::PFCandidate::gamma; + else if (abs(pdgId) == 130) // PDG ID for K0L + return reco::PFCandidate::h0; + else if (abs(pdgId) == 211) // PDG ID for pi+- + return reco::PFCandidate::h; + else + return reco::PFCandidate::X; + } + }; -class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { +class PhotonIDValueMapProducer : public edm::global::EDProducer<> { public: explicit PhotonIDValueMapProducer(const edm::ParameterSet&); - ~PhotonIDValueMapProducer() override; + ~PhotonIDValueMapProducer() override {} static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; // This function computes charged hadron isolation with respect to multiple // PVs and returns the worst of the found isolation values. The function @@ -68,45 +95,25 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { // H->gamma gamma, specifically from the class CiCPhotonID of the // HiggsTo2photons anaysis code. Template is introduced to handle reco/pat // photons and aod/miniAOD PF candidates collections - template float computeWorstPFChargedIsolation( - const T& photon, - const U& pfCands, - const edm::Handle vertices, + const reco::Photon& photon, + const edm::View& pfCands, + const reco::VertexCollection& vertices, const reco::Vertex& pv, - unsigned char options); - - // Some helper functions that are needed to access info in - // AOD vs miniAOD - reco::PFCandidate::ParticleType candidatePdgId(const reco::Candidate* candidate); - - const reco::Track* getTrackPointer(const edm::Ptr candidate); - - // The object that will compute 5x5 quantities - std::unique_ptr lazyToolnoZS; + unsigned char options, bool isAOD) const; // check whether a non-null preshower is there const bool usesES_; - // for AOD case - const edm::EDGetTokenT ebReducedRecHitCollection_; - const edm::EDGetTokenT eeReducedRecHitCollection_; - const edm::EDGetTokenT esReducedRecHitCollection_; - const edm::EDGetTokenT vtxToken_; - const edm::EDGetTokenT>> particleBasedIsolationToken_; - const edm::EDGetTokenT> pfCandsToken_; - const edm::EDGetToken src_; - - // for miniAOD case - const edm::EDGetTokenT ebReducedRecHitCollectionMiniAOD_; - const edm::EDGetTokenT eeReducedRecHitCollectionMiniAOD_; - const edm::EDGetTokenT esReducedRecHitCollectionMiniAOD_; - const edm::EDGetTokenT vtxTokenMiniAOD_; - const edm::EDGetTokenT>> particleBasedIsolationTokenMiniAOD_; - const edm::EDGetTokenT> pfCandsTokenMiniAOD_; - const edm::EDGetToken srcMiniAOD_; - - bool isAOD_; + // Dual Tokens for AOD and MiniAOD case + const MultiTokenT> src_; + const MultiTokenT ebRecHits_; + const MultiTokenT eeRecHits_; + const MultiTokenT esRecHits_; + const MultiTokenT vtxToken_; + const MultiTokenT> pfCandsToken_; + const edm::EDGetToken particleBasedIsolationToken_; + }; constexpr int nVars_ = 19; @@ -152,34 +159,14 @@ const unsigned char PT_MIN_THRESH = 0x8; PhotonIDValueMapProducer::PhotonIDValueMapProducer(const edm::ParameterSet& cfg) : usesES_(!cfg.getParameter("esReducedRecHitCollection").label().empty() || !cfg.getParameter("esReducedRecHitCollectionMiniAOD").label().empty()) - // Declare consummables, handle both AOD and miniAOD case - , ebReducedRecHitCollection_( - mayConsume(cfg.getParameter("ebReducedRecHitCollection"))) - , eeReducedRecHitCollection_( - mayConsume(cfg.getParameter("eeReducedRecHitCollection"))) - , esReducedRecHitCollection_( - mayConsume(cfg.getParameter("esReducedRecHitCollection"))) - , vtxToken_(mayConsume(cfg.getParameter("vertices"))) - // The particleBasedIsolation object is relevant only for AOD, RECO format + , src_( consumesCollector(), cfg, "src", "srcMiniAOD") + , ebRecHits_ (src_, consumesCollector(), cfg, "ebReducedRecHitCollection", "ebReducedRecHitCollectionMiniAOD") + , eeRecHits_ (src_, consumesCollector(), cfg, "eeReducedRecHitCollection", "eeReducedRecHitCollectionMiniAOD") + , esRecHits_ (src_, consumesCollector(), cfg, "esReducedRecHitCollection", "esReducedRecHitCollectionMiniAOD") + , vtxToken_ (src_, consumesCollector(), cfg, "vertices", "verticesMiniAOD") + , pfCandsToken_(src_, consumesCollector(), cfg, "pfCandidates", "pfCandidatesMiniAOD") , particleBasedIsolationToken_(mayConsume>>( - cfg.getParameter("particleBasedIsolation"))) - // AOD has reco::PFCandidate vector, and miniAOD has pat::PackedCandidate - // vector. Both inherit from reco::Candidate, so we go to the base class. - // We can cast into the full type later if needed. Since the collection - // names are different, we introduce both collections - , pfCandsToken_(mayConsume>(cfg.getParameter("pfCandidates"))) - // reco photons are castable into pat photons, so no need to handle reco/pat seprately - , src_(mayConsume>(cfg.getParameter("src"))) - , ebReducedRecHitCollectionMiniAOD_( - mayConsume(cfg.getParameter("ebReducedRecHitCollectionMiniAOD"))) - , eeReducedRecHitCollectionMiniAOD_( - mayConsume(cfg.getParameter("eeReducedRecHitCollectionMiniAOD"))) - , esReducedRecHitCollectionMiniAOD_( - mayConsume(cfg.getParameter("esReducedRecHitCollectionMiniAOD"))) - , vtxTokenMiniAOD_(mayConsume(cfg.getParameter("verticesMiniAOD"))) - , pfCandsTokenMiniAOD_( - mayConsume>(cfg.getParameter("pfCandidatesMiniAOD"))) - , srcMiniAOD_(mayConsume>(cfg.getParameter("srcMiniAOD"))) + cfg.getParameter("particleBasedIsolation")) /* ...only for AOD... */ ) { // Declare producibles @@ -187,69 +174,41 @@ PhotonIDValueMapProducer::PhotonIDValueMapProducer(const edm::ParameterSet& cfg) produces>(names[i]); } -PhotonIDValueMapProducer::~PhotonIDValueMapProducer() {} - -void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +void PhotonIDValueMapProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { - edm::Handle> src; + // Get the handles + auto src = src_.getValidHandle(iEvent); + auto vertices = vtxToken_.getValidHandle(iEvent); + auto pfCandsHandle = pfCandsToken_.getValidHandle(iEvent); - isAOD_ = true; - iEvent.getByToken(src_, src); - if (!src.isValid()) { - isAOD_ = false; - iEvent.getByToken(srcMiniAOD_, src); - } - if (!src.isValid()) { - throw cms::Exception("IllDefinedDataTier") << "DataFormat does not contain a photon source!"; + bool isAOD = src_.getGoodTokenIndex() == 0; + edm::Handle>> particleBasedIsolationMap; + if (isAOD) { // this exists only in AOD + iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap); + } else if (!src->empty()) { + edm::Ptr test(src->ptrAt(0)); + if (test.isNull() || !test.isAvailable()) { + throw cms::Exception("InvalidConfiguration") + << "DataFormat is detected as miniAOD but cannot cast to pat::Photon!"; + } } - // Configure Lazy Tools + // Configure Lazy Tools, which will compute 5x5 quantities + std::unique_ptr lazyToolnoZS; + if (usesES_) { - if (isAOD_) - lazyToolnoZS = std::make_unique( - iEvent, iSetup, ebReducedRecHitCollection_, eeReducedRecHitCollection_, esReducedRecHitCollection_); - else - lazyToolnoZS - = std::make_unique(iEvent, iSetup, ebReducedRecHitCollectionMiniAOD_, - eeReducedRecHitCollectionMiniAOD_, esReducedRecHitCollectionMiniAOD_); + lazyToolnoZS = std::make_unique( + iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent), esRecHits_.get(iEvent)); } else { - if (isAOD_) - lazyToolnoZS = std::make_unique( - iEvent, iSetup, ebReducedRecHitCollection_, eeReducedRecHitCollection_); - else - lazyToolnoZS = std::make_unique( - iEvent, iSetup, ebReducedRecHitCollectionMiniAOD_, eeReducedRecHitCollectionMiniAOD_); + lazyToolnoZS = std::make_unique( + iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent)); } // Get PV - edm::Handle vertices; - iEvent.getByToken(vtxToken_, vertices); - if (!vertices.isValid()) - iEvent.getByToken(vtxTokenMiniAOD_, vertices); if (vertices->empty()) return; // skip the event if no PV found const reco::Vertex& pv = vertices->front(); - edm::Handle>> particleBasedIsolationMap; - if (isAOD_) { - // this exists only in AOD - iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap); - } - - edm::Handle> pfCandsHandle; - - iEvent.getByToken(pfCandsToken_, pfCandsHandle); - if (!pfCandsHandle.isValid()) - iEvent.getByToken(pfCandsTokenMiniAOD_, pfCandsHandle); - - if (!isAOD_ && !src->empty()) { - edm::Ptr test(src->ptrAt(0)); - if (test.isNull() || !test.isAvailable()) { - throw cms::Exception("InvalidConfiguration") - << "DataFormat is detected as miniAOD but cannot cast to pat::Photon!"; - } - } - std::vector vars[nVars_]; // reco::Photon::superCluster() is virtual so we can exploit polymorphism @@ -266,7 +225,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta() // for both formats. std::vector vCov = lazyToolnoZS->localCovariances(theseed); - vars[0].push_back(isnan(vCov[0]) ? 0. : sqrt(vCov[0])); + vars[0].push_back(edm::isNotFinite(vCov[0]) ? 0. : sqrt(vCov[0])); vars[1].push_back(vCov[1]); vars[2].push_back(lazyToolnoZS->e1x3(theseed)); vars[3].push_back(lazyToolnoZS->e2x2(theseed)); @@ -308,7 +267,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup // the PF collection do not contain the supercluser link, so can't // use that). // - // if( isAOD_ ) { + // if( isAOD ) { // if( ((const edm::Ptr)iCand)->superClusterRef() == iPho->superCluster() ) // continue; // } @@ -319,7 +278,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup continue; // Check if this candidate is not in the footprint - if (isAOD_) { + if (isAOD) { if(isInFootprint((*particleBasedIsolationMap)[iPho], iCand)) continue; } else { @@ -329,7 +288,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup } // Find candidate type - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(&*iCand); + reco::PFCandidate::ParticleType thisCandidateType = getCandidatePdgId(&*iCand, isAOD); // Increment the appropriate isolation sum if (thisCandidateType == reco::PFCandidate::h) { @@ -337,7 +296,8 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup // with the PV float dxy = -999; float dz = -999; - getImpactParameters(CachingPtrCandidate(&*iCand, isAOD_), pv, dxy, dz); + + getImpactParameters(CachingPtrCandidate(&*iCand, isAOD), pv, dxy, dz); if (fabs(dxy) > dxyMax || fabs(dz) > dzMax) continue; @@ -359,19 +319,19 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup // Worst isolation computed with no vetos or ptMin cut, as in Run 1 Hgg code. unsigned char options = 0; - vars[13].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + vars[13].push_back(computeWorstPFChargedIsolation(*iPho, *pfCandsHandle, *vertices, pv, options, isAOD)); // Worst isolation computed with cone vetos and a ptMin cut, as in Run 2 Hgg code. options |= PT_MIN_THRESH | DR_VETO; - vars[14].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + vars[14].push_back(computeWorstPFChargedIsolation(*iPho, *pfCandsHandle, *vertices, pv, options, isAOD)); // Like before, but adding primary vertex constraint options |= PV_CONSTRAINT; - vars[15].push_back(computeWorstPFChargedIsolation(iPho, pfCandsHandle, vertices, pv, options)); + vars[15].push_back(computeWorstPFChargedIsolation(*iPho, *pfCandsHandle, *vertices, pv, options, isAOD)); // PFCluster Isolations vars[16].push_back(iPho->trkSumPtSolidConeDR04()); - if (isAOD_) { + if (isAOD) { vars[17].push_back(0.f); vars[18].push_back(0.f); } else { @@ -379,72 +339,65 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup vars[17].push_back(patPhotonPtr->hcalPFClusterIso()); vars[18].push_back(patPhotonPtr->ecalPFClusterIso()); } - } // write the value maps for (int i = 0; i < nVars_; ++i) { - auto valMap = std::make_unique>(); - edm::ValueMap::Filler filler(*valMap); - filler.insert(src, vars[i].begin(), vars[i].end()); - filler.fill(); - iEvent.put(std::move(valMap), names[i]); + writeValueMap(iEvent, src, vars[i], names[i]); } } -void PhotonIDValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) -{ - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.add("ebReducedRecHitCollection"); - desc.add("ebReducedRecHitCollectionMiniAOD"); - desc.add("eeReducedRecHitCollection"); - desc.add("eeReducedRecHitCollectionMiniAOD"); - desc.add("esReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsES")); - desc.add("esReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma:reducedESRecHits")); - desc.add("vertices"); - desc.add("verticesMiniAOD"); - desc.add("src"); - desc.add("srcMiniAOD"); - desc.add("particleBasedIsolation"); - desc.add("pfCandidates"); - desc.add("pfCandidatesMiniAOD"); - descriptions.addDefault(desc); +void PhotonIDValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + // photonIDValueMapProducer + edm::ParameterSetDescription desc; + desc.add("particleBasedIsolation", edm::InputTag("particleBasedIsolation","gedPhotons")); + desc.add("src", edm::InputTag("gedPhotons")); + desc.add("srcMiniAOD", edm::InputTag("slimmedPhotons","","@skipCurrentProcess")); + desc.add("esReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedESRecHits")); + desc.add("eeReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEE")); + desc.add("pfCandidates", edm::InputTag("particleFlow")); + desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("ebReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEBRecHits")); + desc.add("eeReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEERecHits")); + desc.add("esReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsES")); + desc.add("pfCandidatesMiniAOD", edm::InputTag("packedPFCandidates")); + desc.add("verticesMiniAOD", edm::InputTag("offlineSlimmedPrimaryVertices")); + desc.add("ebReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEB")); + descriptions.add("photonIDValueMapProducer", desc); } + // Charged isolation with respect to the worst vertex. See more // comments above at the function declaration. -template -float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, const U& pfCands, - const edm::Handle vertices, const reco::Vertex& pv, unsigned char options) +float PhotonIDValueMapProducer::computeWorstPFChargedIsolation(const reco::Photon& photon, const edm::View& pfCands, + const reco::VertexCollection& vertices, const reco::Vertex& pv, unsigned char options, bool isAOD) const { float worstIsolation = 0.0; - const float dRveto = photon->isEB() ? dRvetoBarrel : dRvetoEndcap; + const float dRveto = photon.isEB() ? dRvetoBarrel : dRvetoEndcap; std::vector chargedCands; - chargedCands.reserve(pfCands->size()); - for (auto const& aCand : *pfCands){ + chargedCands.reserve(pfCands.size()); + for (auto const& aCand : pfCands){ // require that PFCandidate is a charged hadron - reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(&aCand); + reco::PFCandidate::ParticleType thisCandidateType = getCandidatePdgId(&aCand, isAOD); if (thisCandidateType != reco::PFCandidate::h) continue; if ((options & PT_MIN_THRESH) && aCand.pt() < ptMin) continue; - chargedCands.emplace_back(&aCand, isAOD_); + chargedCands.emplace_back(&aCand, isAOD); } // Calculate isolation sum separately for each vertex - for (unsigned int ivtx = 0; ivtx < vertices->size(); ++ivtx) { + for (unsigned int ivtx = 0; ivtx < vertices.size(); ++ivtx) { // Shift the photon according to the vertex - reco::VertexRef vtx(vertices, ivtx); - math::XYZVector phoWrtVtx(photon->superCluster()->x() - vtx->x(), - photon->superCluster()->y() - vtx->y(), photon->superCluster()->z() - vtx->z()); + const reco::VertexRef vtx(&vertices, ivtx); + math::XYZVector phoWrtVtx(photon.superCluster()->x() - vtx->x(), + photon.superCluster()->y() - vtx->y(), photon.superCluster()->z() - vtx->z()); float sum = 0; // Loop over the PFCandidates @@ -475,30 +428,4 @@ float PhotonIDValueMapProducer ::computeWorstPFChargedIsolation(const T& photon, return worstIsolation; } -reco::PFCandidate::ParticleType PhotonIDValueMapProducer::candidatePdgId( - const reco::Candidate* candidate) -{ - if (isAOD_) - return static_cast(candidate)->particleId(); - - // the neutral hadrons and charged hadrons can be of pdgId types - // only 130 (K0L) and +-211 (pi+-) in packed candidates - const int pdgId = static_cast(candidate)->pdgId(); - if (pdgId == 22) - return reco::PFCandidate::gamma; - else if (abs(pdgId) == 130) // PDG ID for K0L - return reco::PFCandidate::h0; - else if (abs(pdgId) == 211) // PDG ID for pi+- - return reco::PFCandidate::h; - else - return reco::PFCandidate::X; -} - -const reco::Track* PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr candidate) -{ - return isAOD_ ? - &*(((const edm::Ptr)candidate)->trackRef()) : - &(((const edm::Ptr)candidate)->pseudoTrack()); -} - DEFINE_FWK_MODULE(PhotonIDValueMapProducer); diff --git a/RecoEgamma/PhotonIdentification/python/PhotonIDValueMapProducer_cfi.py b/RecoEgamma/PhotonIdentification/python/PhotonIDValueMapProducer_cfi.py deleted file mode 100644 index aa3d6ac3be251..0000000000000 --- a/RecoEgamma/PhotonIdentification/python/PhotonIDValueMapProducer_cfi.py +++ /dev/null @@ -1,31 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -photonIDValueMapProducer = cms.EDProducer('PhotonIDValueMapProducer', - # The module automatically detects AOD vs miniAOD, so we configure both - # - # AOD case - # - ebReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"), - eeReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"), - esReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsES"), - particleBasedIsolation = cms.InputTag("particleBasedIsolation","gedPhotons"), - vertices = cms.InputTag("offlinePrimaryVertices"), - pfCandidates = cms.InputTag("particleFlow"), - src = cms.InputTag('gedPhotons'), - # - # miniAOD case - # - ebReducedRecHitCollectionMiniAOD = cms.InputTag("reducedEgamma:reducedEBRecHits"), - eeReducedRecHitCollectionMiniAOD = cms.InputTag("reducedEgamma:reducedEERecHits"), - esReducedRecHitCollectionMiniAOD = cms.InputTag("reducedEgamma:reducedESRecHits"), - verticesMiniAOD = cms.InputTag("offlineSlimmedPrimaryVertices"), - pfCandidatesMiniAOD = cms.InputTag("packedPFCandidates"), - # there is no need for the isolation map here, for miniAOD it is inside packedPFCandidates - srcMiniAOD = cms.InputTag('slimmedPhotons',processName=cms.InputTag.skipCurrentProcess()), - ) - -from Configuration.Eras.Modifier_phase2_common_cff import phase2_common -phase2_common.toModify(photonIDValueMapProducer, - esReducedRecHitCollection = cms.InputTag(""), - esReducedRecHitCollectionMiniAOD = cms.InputTag(""), -) diff --git a/RecoEgamma/PhotonIdentification/python/egmPhotonIDs_cff.py b/RecoEgamma/PhotonIdentification/python/egmPhotonIDs_cff.py index 5640dfcc98232..26f3b0afec97e 100644 --- a/RecoEgamma/PhotonIdentification/python/egmPhotonIDs_cff.py +++ b/RecoEgamma/PhotonIdentification/python/egmPhotonIDs_cff.py @@ -8,7 +8,7 @@ def loadEgmIdSequence(process, dataFormat): # Load the producer module to build full 5x5 cluster shapes and whatever # else is needed for IDs - process.load("RecoEgamma.PhotonIdentification.PhotonIDValueMapProducer_cfi") + process.load("RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff") # Load the producer for MVA IDs. Make sure it is also added to the sequence! process.load("RecoEgamma.PhotonIdentification.PhotonMVAValueMapProducer_cfi") diff --git a/RecoEgamma/PhotonIdentification/python/photonIDValueMapProducer_cff.py b/RecoEgamma/PhotonIdentification/python/photonIDValueMapProducer_cff.py new file mode 100644 index 0000000000000..8eef1d5e56966 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/python/photonIDValueMapProducer_cff.py @@ -0,0 +1,9 @@ +from RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cfi import * + +import FWCore.ParameterSet.Config as cms + +from Configuration.Eras.Modifier_phase2_common_cff import phase2_common +phase2_common.toModify(photonIDValueMapProducer, + esReducedRecHitCollection = "", + esReducedRecHitCollectionMiniAOD = "", +) From 74d39e1c0945cc0271c4601fd5225b49e0c14b4e Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 11 Dec 2018 01:55:23 +0100 Subject: [PATCH 11/13] Photon Fall17 V2 IDs only for run2_miniAOD_devel --- .../PatAlgos/python/slimming/miniAOD_tools.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 6f36d926805be..7b9f4fce2fcd3 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -318,10 +318,8 @@ def miniAOD_customizeCommon(process): #VID Photon IDs process.patPhotons.addPhotonID = cms.bool(True) photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff', - 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', - 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff', 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff'] switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) @@ -342,6 +340,24 @@ def miniAOD_customizeCommon(process): cms.InputTag('reducedEgamma','reducedGedPhotons') for idmod in photon_ids: setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task) + + # add Fall17V2 photon IDs only when a specific modifier is active. + # This is done by configuring all IDs plus Fall17 V2 in a separate temporary process, + # from which the configuration is taken to modify the actual process. + tmp_process = cms.Process("PhotonMVANtuplizer2") + photon_ids = photon_ids + ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff', + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff'] + switchOnVIDPhotonIdProducer(tmp_process,DataFormat.AOD) + for idmod in photon_ids: + setupAllVIDIdsInModule(tmp_process,idmod,setupVIDPhotonSelection) + + from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel + run2_miniAOD_devel.toModify(process.photonMVAValueMapProducer, + mvaConfigurations = tmp_process.photonMVAValueMapProducer.mvaConfigurations) + + run2_miniAOD_devel.toModify(process.egmPhotonIDs, + physicsObjectIDs = tmp_process.egmPhotonIDs.physicsObjectIDs) + del tmp_process #add the cut base IDs bitmaps of which cuts passed from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier From 99daa85373539ab16ed41bbca123e306f1df1b67 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 11 Dec 2018 08:36:37 +0100 Subject: [PATCH 12/13] Make list of photon IDs a PSet which is toModify --- .../PatAlgos/python/slimming/miniAOD_tools.py | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 7b9f4fce2fcd3..1eb9d9a630b25 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -317,11 +317,20 @@ def miniAOD_customizeCommon(process): #VID Photon IDs process.patPhotons.addPhotonID = cms.bool(True) - photon_ids = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff', + + photon_id_config = cms.PSet(photon_ids = cms.vstring([ + 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff', 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff', 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff', - 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff'] + 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff', + ])) + + from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel + run2_miniAOD_devel.toModify(photon_id_config, photon_ids = photon_id_config.photon_ids + \ + ["RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff", + "RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff"] + switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) process.egmPhotonIsolation.srcToIsolate = \ cms.InputTag("reducedEgamma","reducedGedPhotons") @@ -338,27 +347,9 @@ def miniAOD_customizeCommon(process): cms.InputTag("reducedEgamma","reducedPhotonPfCandMap") process.photonMVAValueMapProducer.src = \ cms.InputTag('reducedEgamma','reducedGedPhotons') - for idmod in photon_ids: + for idmod in photon_id_config.photon_ids.value(): setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task) - # add Fall17V2 photon IDs only when a specific modifier is active. - # This is done by configuring all IDs plus Fall17 V2 in a separate temporary process, - # from which the configuration is taken to modify the actual process. - tmp_process = cms.Process("PhotonMVANtuplizer2") - photon_ids = photon_ids + ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff', - 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff'] - switchOnVIDPhotonIdProducer(tmp_process,DataFormat.AOD) - for idmod in photon_ids: - setupAllVIDIdsInModule(tmp_process,idmod,setupVIDPhotonSelection) - - from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel - run2_miniAOD_devel.toModify(process.photonMVAValueMapProducer, - mvaConfigurations = tmp_process.photonMVAValueMapProducer.mvaConfigurations) - - run2_miniAOD_devel.toModify(process.egmPhotonIDs, - physicsObjectIDs = tmp_process.egmPhotonIDs.physicsObjectIDs) - del tmp_process - #add the cut base IDs bitmaps of which cuts passed from RecoEgamma.EgammaTools.egammaObjectModifications_tools import makeVIDBitsModifier egamma_modifications.append(makeVIDBitsModifier(process,"egmGsfElectronIDs","egmPhotonIDs")) From 6457cd05b44043bfabc7d51a8f9d6b557e3daf49 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 11 Dec 2018 09:00:48 +0100 Subject: [PATCH 13/13] Add missing paranthesis --- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 1eb9d9a630b25..86380f1305d39 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -329,7 +329,7 @@ def miniAOD_customizeCommon(process): from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel run2_miniAOD_devel.toModify(photon_id_config, photon_ids = photon_id_config.photon_ids + \ ["RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff", - "RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff"] + "RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff"]) switchOnVIDPhotonIdProducer(process,DataFormat.AOD, task) process.egmPhotonIsolation.srcToIsolate = \