CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mvaPhotonID_tools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry
3 from os import path
4 
5 weightFileBaseDir = "RecoEgamma/PhotonIdentification/data/MVA"
6 
7 # division between barrel and endcap
8 ebeeSplit = 1.479
9 # categories
10 category_cuts = cms.vstring(
11  "abs(superCluster.eta) < 1.479",
12  "abs(superCluster.eta) >= 1.479",
13  )
14 
15 # This MVA implementation class name
16 mvaClassName = "PhotonMVAEstimator"
17 
18 # The locatoins of value maps with the actual MVA values and categories
19 # for all particles.
20 # The names for the maps are "<module name>:<MVA class name>Values"
21 # and "<module name>:<MVA class name>Categories"
22 mvaProducerModuleLabel = "photonMVAValueMapProducer"
23 
24 # =======================================================
25 # Define simple containers for MVA cut values and related
26 # =======================================================
27 
29  """
30  This is a container class to hold MVA cut values for a 2-category MVA
31  as well as the names of the value maps that contain the MVA values computed
32  for all particles in a producer upstream.
33  """
34  def __init__(self,
35  idName,
36  mvaValueMapName,
37  mvaCategoriesMapName,
38  cutCategory0,
39  cutCategory1
40  ):
41  self.idName = idName
42  self.mvaValueMapName = mvaValueMapName
43  self.mvaCategoriesMapName = mvaCategoriesMapName
44  self.cutCategory0 = cutCategory0
45  self.cutCategory1 = cutCategory1
46 
47  def getCutValues(self):
48  return [self.cutCategory0, self.cutCategory1]
49 
50 # ==============================================================
51 # Define the complete MVA cut sets
52 # ==============================================================
53 
55  """
56  This function configures the full cms.PSet for a VID ID and returns it.
57  The inputs: an object of the class PhoMVA_2Categories_WP or similar
58  that contains all necessary parameters for this MVA.
59  """
60  parameterSet = cms.PSet(
61  #
62  idName = cms.string( mvaWP.idName ),
63  cutFlow = cms.VPSet(
64  cms.PSet( cutName = cms.string("PhoMVACut"),
65  mvaCuts = cms.vdouble( mvaWP.getCutValues() ),
66  mvaValueMapName = cms.InputTag( mvaWP.mvaValueMapName ),
67  mvaCategoriesMapName =cms.InputTag( mvaWP.mvaCategoriesMapName ),
68  needsAdditionalProducts = cms.bool(True),
69  isIgnored = cms.bool(False)
70  )
71  )
72  )
73  #
74  return parameterSet
75 
76 # ===============================================
77 # High level function to create a two category ID
78 # ===============================================
79 
80 # mvaTag:
81 # The mvaTag is an extra string attached to the names of the products
82 # such as ValueMaps that needs to distinguish cases when the same MVA estimator
83 # class is used with different tuning/weights
84 # variablesFile:
85 # The file listing the variables used in this MVA
86 # weightFiles:
87 # The weight files in the order EB first, then EE
88 # wpConfig:
89 # A dictionary with the names and cut values of the working points
90 # addKwargsForValueProducer:
91 # Additional keyword parameters passed to the producer config
92 
93 def configureFullVIDMVAPhoID(mvaTag, variablesFile, weightFiles, wpConfig, **addKwargsForValueProducer):
94 
95  mvaValueMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Values"
96  mvaCategoriesMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
97 
98  # Create the PSet that will be fed to the MVA value map producer
99  producer_config = cms.PSet(
100  mvaName = cms.string(mvaClassName),
101  mvaTag = cms.string(mvaTag),
102  weightFileNames = cms.vstring(*weightFiles),
103  variableDefinition = cms.string(variablesFile),
104  **addKwargsForValueProducer
105  )
106 
107  # Create the VPset's for VID cuts
108  VID_config = {}
109  for wpc in wpConfig:
110  idName = wpc["idName"]
111  VID_config[idName] = configureVIDMVAPhoID_V1(
113  idName = idName,
114  mvaValueMapName = mvaValueMapName, # map with MVA values for all particles
115  mvaCategoriesMapName = mvaCategoriesMapName, # map with category index for all particles
116  cutCategory0 = wpc["cuts"]["EB"], # EB
117  cutCategory1 = wpc["cuts"]["EE"] # EE
118  )
119  )
120 
121  configs = {"producer_config": producer_config, "VID_config": VID_config}
122  return configs