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