Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:21

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