Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-09 23:46:49

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