CMS 3D CMS Logo

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