CMS 3D CMS Logo

mvaElectronID_tools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 # =========================
4 # Various commom parameters
5 # =========================
6 
7 # This MVA implementation class name
8 mvaClassName = "ElectronMVAEstimatorRun2"
9 
10 # The locatoins of value maps with the actual MVA values and categories
11 # for all particles.
12 # The names for the maps are "<module name>:<MVA class name>Values"
13 # and "<module name>:<MVA class name>Categories"
14 mvaProducerModuleLabel = "electronMVAValueMapProducer"
15 
16 # The files with the variable definitions
17 mvaVariablesFile = "RecoEgamma/ElectronIdentification/data/ElectronMVAEstimatorRun2Variables.txt"
18 mvaVariablesFileRun3 = "RecoEgamma/ElectronIdentification/data/ElectronIDVariablesRun3.txt"
19 mvaVariablesFileRun3NonIso = "RecoEgamma/ElectronIdentification/data/ElectronIDVariablesRun3NonIso.txt"
20 
21 # =======================================
22 # Define some commonly used category cuts
23 # =======================================
24 
25 EleMVA_3CategoriesCuts = [
26  "abs(superCluster.eta) < 0.800",
27  "abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
28  "abs(superCluster.eta) >= 1.479"
29  ]
30 
31 EleMVA_6CategoriesCuts = [
32  "pt < 10. && abs(superCluster.eta) < 0.800",
33  "pt < 10. && abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
34  "pt < 10. && abs(superCluster.eta) >= 1.479",
35  "pt >= 10. && abs(superCluster.eta) < 0.800",
36  "pt >= 10. && abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
37  "pt >= 10. && abs(superCluster.eta) >= 1.479",
38  ]
39 
40 # =======================================================
41 # Define simple containers for MVA cut values and related
42 # =======================================================
43 
44 class EleMVA_WP:
45  """
46  This is a container class to hold MVA cut values for a n-category MVA
47  as well as the names of the value maps that contain the MVA values computed
48  for all particles in a producer upstream.
49 
50  IMPORTANT: the cuts need to be given in alphabetical order, which must
51  be the order in which they are used by the cut class.
52  """
53  def __init__(self,
54  idName,
55  mvaTag,
56  **cuts
57  ):
58  self.idName = idName
59  # map with MVA values for all particles
60  self.mvaValueMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Values"
61  # map with category index for all particles
62  self.mvaCategoriesMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
63  self.cuts = cuts
64 
65  def getCutStrings(self):
66  keylist = sorted(self.cuts.keys())
67  return [self.cuts[key] for key in keylist]
68 
70  """
71  This is a container class to hold MVA cut values for a n-category MVA
72  as well as the names of the value maps that contain the MVA values computed
73  for all particles in a producer upstream.
74 
75  IMPORTANT: the cuts need to be given in alphabetical order, which must
76  be the order in which they are used by the cut class.
77  """
78  def __init__(self,
79  idName,
80  mvaTag,
81  **cuts
82  ):
83  self.idName = idName
84  # map with MVA values for all particles
85  self.mvaValueMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "RawValues"
86  # map with category index for all particles
87  self.mvaCategoriesMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
88  self.cuts = cuts
89 
90  def getCutStrings(self):
91  keylist = sorted(self.cuts.keys())
92  return [self.cuts[key] for key in keylist]
93 
94 # ================================
95 # Define the complete MVA cut sets
96 # ================================
97 
98 def configureVIDMVAEleID(mvaWP, cutName="GsfEleMVACut"):
99  """
100  This function configures the full cms.PSet for a VID ID and returns it.
101  The inputs: an object of the class EleMVA_WP or similar
102  that contains all necessary parameters for this MVA.
103  """
104  pSet = cms.PSet(
105  #
106  idName = cms.string( mvaWP.idName ),
107  cutFlow = cms.VPSet(
108  cms.PSet( cutName = cms.string(cutName),
109  mvaCuts = cms.vstring( mvaWP.getCutStrings() ),
110  mvaValueMapName = cms.InputTag( mvaWP.mvaValueMapName ),
111  mvaCategoriesMapName = cms.InputTag( mvaWP.mvaCategoriesMapName ),
112  needsAdditionalProducts = cms.bool(True),
113  isIgnored = cms.bool(False)
114  )
115  )
116  )
117  #
118  return pSet
def configureVIDMVAEleID(mvaWP, cutName="GsfEleMVACut")
def __init__(self, idName, mvaTag, cuts)
def __init__(self, idName, mvaTag, cuts)