Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:10

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry
0003 from os import path
0004 
0005 weightFileBaseDir = "RecoEgamma/PhotonIdentification/data/MVA"
0006 
0007 # division between barrel and endcap
0008 ebeeSplit = 1.479
0009 # categories
0010 category_cuts = cms.vstring(
0011     "abs(superCluster.eta) <  1.479",
0012     "abs(superCluster.eta) >= 1.479",
0013     )
0014 
0015 # This MVA implementation class name
0016 mvaClassName = "PhotonMVAEstimator"
0017 
0018 # The locatoins of value maps with the actual MVA values and categories
0019 # for all particles.
0020 # The names for the maps are "<module name>:<MVA class name>Values" 
0021 # and "<module name>:<MVA class name>Categories"
0022 mvaProducerModuleLabel = "photonMVAValueMapProducer"
0023 
0024 # =======================================================
0025 # Define simple containers for MVA cut values and related
0026 # =======================================================
0027 
0028 class PhoMVA_2Categories_WP:
0029     """
0030     This is a container class to hold MVA cut values for a 2-category MVA
0031     as well as the names of the value maps that contain the MVA values computed
0032     for all particles in a producer upstream.
0033     """
0034     def __init__(self,
0035                  idName,
0036                  mvaValueMapName,
0037                  mvaCategoriesMapName,
0038                  cutCategory0,
0039                  cutCategory1
0040                  ):
0041         self.idName       = idName
0042         self.mvaValueMapName      = mvaValueMapName
0043         self.mvaCategoriesMapName = mvaCategoriesMapName
0044         self.cutCategory0 = cutCategory0
0045         self.cutCategory1 = cutCategory1
0046 
0047     def getCutValues(self):
0048         return [self.cutCategory0, self.cutCategory1]
0049 
0050 # ==============================================================
0051 # Define the complete MVA cut sets
0052 # ==============================================================
0053     
0054 def configureVIDMVAPhoID_V1( mvaWP ):
0055     """
0056     This function configures the full cms.PSet for a VID ID and returns it.
0057     The inputs: an object of the class PhoMVA_2Categories_WP or similar
0058     that contains all necessary parameters for this MVA.
0059     """
0060     parameterSet =  cms.PSet(
0061         #
0062         idName = cms.string( mvaWP.idName ), 
0063         cutFlow = cms.VPSet( 
0064             cms.PSet( cutName = cms.string("PhoMVACut"),
0065                       mvaCuts = cms.vdouble( mvaWP.getCutValues() ),
0066                       mvaValueMapName = cms.InputTag( mvaWP.mvaValueMapName ),
0067                       mvaCategoriesMapName =cms.InputTag( mvaWP.mvaCategoriesMapName ),
0068                       needsAdditionalProducts = cms.bool(True),
0069                       isIgnored = cms.bool(False)
0070                       )
0071             )
0072         )
0073     #
0074     return parameterSet
0075 
0076 # ===============================================
0077 # High level function to create a two category ID
0078 # ===============================================
0079 
0080 # mvaTag:
0081 #         The mvaTag is an extra string attached to the names of the products
0082 #         such as ValueMaps that needs to distinguish cases when the same MVA estimator
0083 #         class is used with different tuning/weights
0084 # variablesFile:
0085 #         The file listing the variables used in this MVA
0086 # weightFiles:
0087 #         The weight files in the order EB first, then EE
0088 # wpConfig:
0089 #         A dictionary with the names and cut values of the working points
0090 # addKwargsForValueProducer:
0091 #         Additional keyword parameters passed to the producer config
0092 
0093 def configureFullVIDMVAPhoID(mvaTag, variablesFile, weightFiles, wpConfig, **addKwargsForValueProducer):
0094 
0095     mvaValueMapName        = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Values"
0096     mvaCategoriesMapName   = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
0097 
0098     # Create the PSet that will be fed to the MVA value map producer
0099     producer_config = cms.PSet( 
0100         mvaName             = cms.string(mvaClassName),
0101         mvaTag              = cms.string(mvaTag),
0102         weightFileNames     = cms.vstring(*weightFiles),
0103         variableDefinition  = cms.string(variablesFile),
0104         **addKwargsForValueProducer
0105         )
0106 
0107     # Create the VPset's for VID cuts
0108     VID_config = {}
0109     for wpc in wpConfig:
0110         idName = wpc["idName"]
0111         VID_config[idName] = configureVIDMVAPhoID_V1(
0112                 PhoMVA_2Categories_WP(
0113                     idName = idName,
0114                     mvaValueMapName = mvaValueMapName,           # map with MVA values for all particles
0115                     mvaCategoriesMapName = mvaCategoriesMapName, # map with category index for all particles
0116                     cutCategory0 =  wpc["cuts"]["EB"],  # EB
0117                     cutCategory1 =  wpc["cuts"]["EE"]   # EE
0118                 )
0119             )
0120 
0121     configs = {"producer_config": producer_config, "VID_config": VID_config}
0122     return configs