Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:10:00

0001 #!/usr/bin/env python
0002 
0003 #----------------------------------------------------------------------
0004 #
0005 # takes the MC menu and generates python configuration
0006 # files for the EmDQM module (one per supported path)
0007 #
0008 # see an example file at HLTriggerOffline/Egamma/python/HLT_Ele17_SW_TighterEleIdIsol_L1RDQM_cfi.py
0009 #----------------------------------------------------------------------
0010 
0011 from __future__ import print_function
0012 import FWCore.ParameterSet.Config as cms
0013 import HLTriggerOffline.Egamma.EgammaHLTValidationUtils as EgammaHLTValidationUtils
0014 import sys, os
0015 
0016 # prefix for printouts
0017 # msgPrefix = "[" + os.path.basename(__file__) + "]"
0018 msgPrefix = ''
0019 
0020 
0021 
0022 #----------------------------------------------------------------------
0023 
0024 def makeOnePath(path, isFastSim):
0025     """ given a path object, returns the python text to be written
0026     to a _cff.py file"""
0027 
0028     # name of the HLT path
0029     pathName = path.label_()
0030 
0031     # we currently exclude a few 'problematic' paths (for which we
0032     # don't have a full recipe how to produce a monitoring path
0033     # for them).
0034     #
0035     # we exclude paths which contain EDFilters which we don't know
0036     # how to handle in the DQM modules
0037     moduleCXXtypes = EgammaHLTValidationUtils.getCXXTypesOfPath(refProcess,path)
0038     # print >> sys.stderr,"module types:", moduleCXXtypes
0039 
0040     hasProblematicType = False
0041 
0042     for problematicType in [
0043         # this list was collected empirically
0044         'HLTEgammaTriggerFilterObjectWrapper', 
0045         'EgammaHLTPhotonTrackIsolationProducersRegional',
0046         ]:
0047 
0048         if problematicType in moduleCXXtypes:
0049             print(msgPrefix +  "SKIPPING PATH",pathName,"BECAUSE DON'T KNOW HOW TO HANDLE A MODULE WITH C++ TYPE",problematicType, file=sys.stderr)
0050             return None
0051 
0052     # print >> sys.stderr,msgPrefix, "adding E/gamma HLT dqm module for path",pathName
0053 
0054     dqmModuleName = pathName
0055     if isFastSim:
0056         dqmModuleName = dqmModuleName + "FastSim"
0057 
0058     dqmModuleName = dqmModuleName + "_DQM"
0059 
0060     # global dqmModule
0061 
0062     dqmModule = EgammaHLTValidationUtils.EgammaDQMModuleMaker(refProcess, pathName,
0063                                                               thisCategoryData['genPid'],        # type of generated particle
0064                                                               thisCategoryData['numGenerated']   # number of generated particles
0065                                                               ).getResult()
0066 
0067 
0068     return dqmModuleName + " = " + repr(dqmModule)
0069     
0070 
0071     
0072 
0073 #----------------------------------------------------------------------
0074 # main
0075 #----------------------------------------------------------------------
0076 # parse command line options
0077 from optparse import OptionParser
0078 
0079 parser = OptionParser(
0080     """
0081    usage: %prog [options] output_dir
0082    creates a set of files configuring the EmDQM module
0083    which can then be included from HLTriggerOffline/Egamma/python/EgammaValidation_cff.py
0084 
0085    """
0086 )
0087 (options, ARGV) = parser.parse_args()
0088 
0089 isFastSim = False
0090 
0091 #----------------------------------------
0092 
0093 if len(ARGV) != 1:
0094     print("must specify exactly one non-option argument: the output directory", file=sys.stderr)
0095     sys.exit(1)
0096 
0097 outputDir = ARGV.pop(0)
0098 
0099 if os.path.exists(outputDir):
0100     print("output directory " + outputDir + " already exists, refusing to overwrite it / files in it", file=sys.stderr)
0101     sys.exit(1)
0102     
0103 
0104 
0105 #----------------------------------------
0106 # compose the DQM anlyser paths
0107 #----------------------------------------
0108 
0109 
0110 # maps from Egamma HLT path category to number of type and number of generated
0111 # particles required for the histogramming
0112 configData = {
0113     "singleElectron": { "genPid" : 11, "numGenerated" : 1,},
0114     "doubleElectron": { "genPid" : 11, "numGenerated" : 2 },
0115     "singlePhoton":   { "genPid" : 22, "numGenerated" : 1 },
0116     "doublePhoton":   { "genPid" : 22, "numGenerated" : 2 },
0117     }
0118 
0119 
0120 egammaValidators = []
0121 egammaValidatorsFS = []
0122 
0123 pathToPythonText = {}
0124 
0125 
0126 #--------------------
0127 # a 'reference' process to take (and analyze) the HLT menu from
0128 #--------------------
0129 refProcess = cms.Process("REF")
0130 
0131 if isFastSim:
0132     refProcess.load("FastSimulation.Configuration.HLT_GRun_cff")
0133 else:
0134     refProcess.load("HLTrigger.Configuration.HLT_GRun_cff")
0135 
0136 #--------------------
0137 
0138 pathsByCategory = EgammaHLTValidationUtils.findEgammaPaths(refProcess)
0139 
0140 os.mkdir(outputDir)
0141 allPathsWritten = []
0142 
0143 
0144 
0145 for hltPathCategory, thisCategoryData in configData.items():
0146 
0147     # get the HLT path objects for this category
0148     paths = pathsByCategory[hltPathCategory]
0149 
0150     # fix: if there are no paths for some reason,
0151     # provide some dummy objects which we can delete
0152     # after the loop over the paths 
0153     path = None
0154     dqmModule = None
0155 
0156     for path in paths:
0157 
0158         pathName = path.label_()
0159 
0160         res = makeOnePath(path, isFastSim)
0161 
0162         if res == None:
0163             continue
0164 
0165         res = res.splitlines()
0166 
0167         res = [
0168             "#----------------------------------------",
0169             "# path " + pathName,
0170             "#----------------------------------------",
0171             "",
0172             "import FWCore.ParameterSet.Config as cms",
0173             "",
0174             ] + res
0175 
0176         outputFname = os.path.join(outputDir,pathName + "_DQM_cfi.py")
0177         assert(not os.path.exists(outputFname))
0178         fout = open(outputFname,"w")
0179         for line in res:
0180             print(line, file=fout)
0181         fout.close()
0182 
0183         print("wrote",outputFname, file=sys.stderr)
0184         allPathsWritten.append(pathName)
0185 
0186     # end of loop over paths
0187 
0188 # end of loop over analysis types (single electron, ...)
0189 
0190 print("generated the following paths:", file=sys.stderr)
0191 for pathName in sorted(allPathsWritten):
0192     print("  " + pathName)