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 = cms.vstring(
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 = cms.vstring(
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 = self.cuts.keys()
90  keylist.sort()
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)