Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:27

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 # =========================
0004 # Various commom parameters
0005 # =========================
0006 
0007 # This MVA implementation class name
0008 mvaClassName = "ElectronMVAEstimatorRun2"
0009 
0010 # The locatoins of value maps with the actual MVA values and categories
0011 # for all particles.
0012 # The names for the maps are "<module name>:<MVA class name>Values"
0013 # and "<module name>:<MVA class name>Categories"
0014 mvaProducerModuleLabel = "electronMVAValueMapProducer"
0015 
0016 # The files with the variable definitions
0017 mvaVariablesFile        = "RecoEgamma/ElectronIdentification/data/ElectronMVAEstimatorRun2Variables.txt"
0018 
0019 # =======================================
0020 # Define some commonly used category cuts
0021 # =======================================
0022 
0023 EleMVA_3CategoriesCuts = [
0024     "abs(superCluster.eta) < 0.800",
0025     "abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
0026     "abs(superCluster.eta) >= 1.479"
0027     ]
0028 
0029 EleMVA_6CategoriesCuts = [
0030     "pt < 10. && abs(superCluster.eta) < 0.800",
0031     "pt < 10. && abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
0032     "pt < 10. && abs(superCluster.eta) >= 1.479",
0033     "pt >= 10. && abs(superCluster.eta) < 0.800",
0034     "pt >= 10. && abs(superCluster.eta) >= 0.800 && abs(superCluster.eta) < 1.479",
0035     "pt >= 10. && abs(superCluster.eta) >= 1.479",
0036     ]
0037 
0038 # =======================================================
0039 # Define simple containers for MVA cut values and related
0040 # =======================================================
0041 
0042 class EleMVA_WP:
0043     """
0044     This is a container class to hold MVA cut values for a n-category MVA
0045     as well as the names of the value maps that contain the MVA values computed
0046     for all particles in a producer upstream.
0047 
0048     IMPORTANT: the cuts need to be given in alphabetical order, which must
0049     be the order in which they are used by the cut class.
0050     """
0051     def __init__(self,
0052                  idName,
0053                  mvaTag,
0054                  **cuts
0055                  ):
0056         self.idName               = idName
0057         # map with MVA values for all particles
0058         self.mvaValueMapName      = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Values"
0059         # map with category index for all particles
0060         self.mvaCategoriesMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
0061         self.cuts = cuts
0062 
0063     def getCutStrings(self):
0064         keylist = sorted(self.cuts.keys())
0065         return [self.cuts[key] for key in keylist]
0066 
0067 class EleMVARaw_WP:
0068     """
0069     This is a container class to hold MVA cut values for a n-category MVA
0070     as well as the names of the value maps that contain the MVA values computed
0071     for all particles in a producer upstream.
0072 
0073     IMPORTANT: the cuts need to be given in alphabetical order, which must
0074     be the order in which they are used by the cut class.
0075     """
0076     def __init__(self,
0077                  idName,
0078                  mvaTag,
0079                  **cuts
0080                  ):
0081         self.idName               = idName
0082         # map with MVA values for all particles
0083         self.mvaValueMapName      = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "RawValues"
0084         # map with category index for all particles
0085         self.mvaCategoriesMapName = mvaProducerModuleLabel + ":" + mvaClassName + mvaTag + "Categories"
0086         self.cuts = cuts
0087 
0088     def getCutStrings(self):
0089         keylist = sorted(self.cuts.keys())
0090         return [self.cuts[key] for key in keylist]
0091 
0092 # ================================
0093 # Define the complete MVA cut sets
0094 # ================================
0095 
0096 def configureVIDMVAEleID(mvaWP, cutName="GsfEleMVACut"):
0097     """
0098     This function configures the full cms.PSet for a VID ID and returns it.
0099     The inputs: an object of the class EleMVA_WP or similar
0100     that contains all necessary parameters for this MVA.
0101     """
0102     pSet = cms.PSet(
0103         #
0104         idName = cms.string( mvaWP.idName ),
0105         cutFlow = cms.VPSet(
0106             cms.PSet( cutName = cms.string(cutName),
0107                       mvaCuts = cms.vstring( mvaWP.getCutStrings() ),
0108                       mvaValueMapName = cms.InputTag( mvaWP.mvaValueMapName ),
0109                       mvaCategoriesMapName = cms.InputTag( mvaWP.mvaCategoriesMapName ),
0110                       needsAdditionalProducts = cms.bool(True),
0111                       isIgnored = cms.bool(False)
0112                       )
0113             )
0114         )
0115     #
0116     return pSet