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