Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:50

0001 import FWCore.ParameterSet.Config as cms
0002 from functools import reduce
0003 
0004 # whether to use the old or newer (automatically adapting
0005 # to the MC menu) method of configuring the monitoring
0006 # modules for the HLT paths
0007 use_new_method = False
0008 
0009 
0010 if not use_new_method:
0011     #----------------------------------------------------------------------
0012     # traditional method of configuring the HLT paths
0013     #----------------------------------------------------------------------
0014 
0015     class dummy:
0016         pass
0017 
0018     samples=dummy()
0019     paths=dummy()
0020 
0021     ##########################################################
0022     # Define which preselections to run                      #
0023     ##########################################################
0024 
0025     samples.names = ['Wenu',
0026                      'Zee',
0027                      'GammaJet',
0028                      'DiGamma']
0029     samples.pdgid = [ 11,
0030                       11,
0031                       22,
0032                       22]
0033     samples.num   = [1,
0034                      2,
0035                      1,
0036                      2]
0037 
0038     #which triggers for which sample
0039 
0040     paths.Wenu = [#'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM',
0041                   #'HLT_Ele10_LW_L1RDQM',
0042                   #'HLT_Ele15_SW_L1RDQM',
0043                   #'HLT_Ele10_LW_EleId_L1RDQM',
0044                   #'HLT_Ele15_SiStrip_L1RDQM'
0045                   #'HLT_Ele10_SW_EleId_HT70U_L1R_v2_DQM',
0046                   #'HLT_Ele10_SW_HT100U_L1R_v2_DQM',
0047                   #'HLT_Ele10_SW_HT70U_L1R_v2_DQM',
0048                   #'HLT_Ele10_SW_L1R_v2_DQM',
0049                   #'HLT_Ele12_SW_TighterEleId_L1R_v2_DQM',
0050                   #'HLT_Ele17_SW_Isol_L1R_v2_DQM',
0051                   #'HLT_Ele17_SW_L1R_v2_DQM',
0052                   #'HLT_Ele17_SW_TighterEleIdIsol_L1R_v3_DQM',
0053                   #'HLT_Ele22_SW_L1R_v2_DQM',
0054                   #'HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2_DQM',
0055                   #'HLT_Ele22_SW_TighterEleId_L1R_v3_DQM',
0056                   #'HLT_Ele32_SW_TighterEleId_L1R_v2_DQM'
0057                  ]
0058 
0059     paths.Zee = paths.Wenu + [#'HLT_DoubleEle5_SW_L1RDQM'
0060                               #'HLT_DoubleEle17_SW_L1R_v1_DQM',
0061                               #'HLT_DoubleEle4_SW_eeRes_L1R_v2_DQM',
0062                               #'HLT_DoubleEle5_SW_Upsilon_L1R_v2_DQM',
0063                               #'HLT_DoubleEle8_SW_HT70U_L1R_v1_DQM'
0064                              ]
0065 
0066     paths.GammaJet = [#'HLT_Photon10_L1R_DQM',
0067                       #'HLT_Photon15_TrackIso_L1R_DQM',
0068                       #'HLT_Photon15_LooseEcalIso_L1R_DQM',
0069                       #'HLT_Photon20_Cleaned_L1R_DQM',
0070                       #'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM'
0071                       #'HLT_Photon10_Cleaned_L1R_DQM',
0072                       #'HLT_Photon110_NoHE_Cleaned_L1R_v1_DQM',
0073                       #'HLT_Photon20_Cleaned_L1R_DQM',
0074                       #'HLT_Photon20_NoHE_L1R_DQM',
0075                       #'HLT_Photon30_Cleaned_L1R_DQM',
0076                       #'HLT_Photon40_CaloId_Cleaned_L1R_v1_DQM',
0077                       #'HLT_Photon50_Cleaned_L1R_v1_DQM',
0078                       #'HLT_Photon50_NoHE_L1R_DQM',
0079                       #'HLT_Photon70_Cleaned_L1R_v1_DQM'
0080                      ]
0081 
0082     paths.DiGamma  = [#'HLT_Photon10_L1R_DQM','HLT_DoublePhoton10_L1R_DQM'
0083                       #'HLT_DoublePhoton22_L1R_v1_DQM',
0084                       #'HLT_DoublePhoton5_CEP_L1R_v3_DQM'
0085                      ]
0086 
0087     pathlumi = { 'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM': '8e29',
0088                  'HLT_Ele10_LW_L1RDQM':'8e29',
0089                  'HLT_Ele15_SW_L1RDQM':'1e31',
0090                  'HLT_Ele10_LW_EleId_L1RDQM':'8e29',
0091                  'HLT_Ele15_SiStrip_L1RDQM':'8e29',
0092                  'HLT_DoubleEle5_SW_L1RDQM':'8e29',
0093                  'HLT_Photon10_L1R_DQM':'8e29',
0094                  'HLT_Photon15_TrackIso_L1R_DQM':'8e29',
0095                  'HLT_Photon15_LooseEcalIso_L1R_DQM':'8e29',
0096                  'HLT_Photon20_Cleaned_L1R_DQM':'8e29',
0097                  'HLT_DoublePhoton10_L1R_DQM':'8e29',
0098                  'HLT_Photon25_L1R_DQM':'1e31',
0099                  'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM':'1e31'}
0100 
0101     # add the new paths automatically
0102     for path in paths.Wenu + paths.Zee + paths.GammaJet + paths.DiGamma:
0103         pathlumi[path] = '8e29'
0104 
0105     lumiprocess = { '8e29':'HLT',
0106                     '1e31':'HLT'
0107                     }
0108 
0109 
0110     ##########################################################
0111     # produce generated paricles in acceptance               #
0112     ##########################################################
0113 
0114     genp = cms.EDFilter("PdgIdAndStatusCandViewSelector",
0115         status = cms.vint32(3),
0116         src = cms.InputTag("genParticles"),
0117         pdgId = cms.vint32(11)  # replaced in loop
0118     )
0119 
0120     fiducial = cms.EDFilter("EtaPtMinCandViewSelector",
0121         src = cms.InputTag("genp"),
0122         etaMin = cms.double(-2.5),  # to be replaced in loop ?
0123         etaMax = cms.double(2.5),   # to be replaced in loop ?
0124         ptMin = cms.double(2.0)     # to be replaced in loop ?
0125     )
0126 
0127     ##########################################################
0128     # loop over samples to create modules and sequence       #
0129     ##########################################################
0130 
0131     tmp = cms.SequencePlaceholder("tmp")
0132     egammaSelectors = cms.Sequence(tmp) # no empty sequences allowed, start with dummy
0133     egammaValidators= cms.Sequence(tmp) # same
0134 
0135     #loop over samples
0136     for samplenum in range(len(samples.names)):
0137 
0138         # clone genparticles and select correct type
0139         genpartname = "genpart"+samples.names[samplenum]
0140         globals()[genpartname] = genp.clone()
0141         setattr(globals()[genpartname],"pdgId",cms.vint32(samples.pdgid[samplenum]) ) # set pdgId
0142         egammaSelectors *= globals()[genpartname]                            # add to sequence
0143 
0144         # clone generator fiducial region
0145         fiducialname = "fiducial"+samples.names[samplenum]
0146         globals()[fiducialname] = fiducial.clone()
0147         setattr(globals()[fiducialname],"src",cms.InputTag(genpartname) ) # set input collection
0148         egammaSelectors *= globals()[fiducialname]               # add to sequence
0149 
0150         # loop over triggers for each sample
0151         for trig in getattr(paths,samples.names[samplenum]):
0152             trigname = trig + samples.names[samplenum] 
0153             #import appropriate config snippet
0154             filename = "HLTriggerOffline.Egamma."+trig+"_cfi"
0155             trigdef =__import__( filename )
0156             import sys
0157             globals()[trigname] = getattr(sys.modules[filename],trig).clone()    # clone imported config
0158             setattr(globals()[trigname],"cutcollection",cms.InputTag(fiducialname))        # set preselacted generator collection
0159             setattr(globals()[trigname],"cutnum",cms.int32( samples.num[samplenum]  )) # cut value for preselection
0160             setattr(globals()[trigname],"pdgGen",cms.int32( samples.pdgid[samplenum])) #correct pdgId for MC matching
0161             getattr(globals()[trigname],'triggerobject').setProcessName( lumiprocess[pathlumi[trig]] )         #set proper process name
0162             for filterpset in getattr(globals()[trigname],'filters'):
0163                 getattr(filterpset,'HLTCollectionLabels').setProcessName( lumiprocess[pathlumi[trig]] )
0164                 for isocollections in getattr(filterpset,'IsoCollections'):
0165                     isocollections.setProcessName( lumiprocess[pathlumi[trig]])
0166 
0167             egammaValidators *= globals()[trigname]                      # add to sequence
0168 
0169 
0170     egammaSelectors.remove(tmp)  # remove the initial dummy
0171     egammaValidators.remove(tmp)
0172 
0173     # selectors go into separate "prevalidation" sequence
0174     egammaValidationSequence   = cms.Sequence( egammaValidators )
0175 
0176 else:
0177     #----------------------------------------------------------------------
0178     # new method
0179     #----------------------------------------------------------------------
0180 
0181     import sys, os
0182 
0183     # prefix for printouts
0184     msgPrefix = "[" + os.path.basename(__file__) + "]"
0185 
0186     import HLTriggerOffline.Egamma.EgammaHLTValidationUtils as EgammaHLTValidationUtils
0187 
0188 
0189     # maps from Egamma HLT path category to number of type and number of generated
0190     # particles required for the histogramming
0191     configData = {
0192         "singleElectron": { "genPid" : 11, "numGenerated" : 1,},
0193         "doubleElectron": { "genPid" : 11, "numGenerated" : 2 },
0194         "singlePhoton":   { "genPid" : 22, "numGenerated" : 1 },
0195         "doublePhoton":   { "genPid" : 22, "numGenerated" : 2 },
0196         }
0197 
0198     #----------------------------------------
0199     # generate generator level selection modules
0200     #
0201     # note that this is common between full and
0202     # fast simulation
0203     #----------------------------------------
0204     egammaSelectors = []
0205 
0206     for hltPathCategory, thisCategoryData in configData.items():
0207         # all paths in the current category share the same
0208         # generator level requirement
0209         #
0210         # add a sequence for this generator level requirement
0211 
0212         generatorRequirementSequence = EgammaHLTValidationUtils.makeGeneratedParticleAndFiducialVolumeFilter(None,
0213                                                                                                              thisCategoryData['genPid'],
0214                                                                                                              thisCategoryData['numGenerated'])
0215 
0216         # dirty hack: get all modules of this sequence and add them
0217         # to globals() (which is not the same as calling globals() in makeGeneratedParticleAndFiducialVolumeFilter)
0218         # so that they will be added to the process
0219         for module in EgammaHLTValidationUtils.getModulesOfSequence(generatorRequirementSequence):
0220             globals()[module.label_()] = module
0221 
0222         # avoid that this variable is added to the process object when importing this _cff
0223         # (otherwise the last filter will appear with module name 'module' instead
0224         # of the name given by us...)
0225         del module
0226 
0227         egammaSelectors.append(generatorRequirementSequence)
0228         
0229     #----------------------------------------
0230     # compose the DQM anlyser paths
0231     #----------------------------------------
0232 
0233     egammaValidators = []
0234     egammaValidatorsFS = []
0235 
0236     for isFastSim, validators in (
0237         (False, egammaValidators),
0238         (True,  egammaValidatorsFS),
0239         ):
0240 
0241         #--------------------
0242         # a 'reference' process to take (and analyze) the HLT menu from
0243         #--------------------
0244         refProcess = cms.Process("REF")
0245 
0246         if isFastSim:
0247             refProcess.load("FastSimulation.Configuration.HLT_GRun_cff")
0248         else:
0249             refProcess.load("HLTrigger.Configuration.HLT_GRun_cff")
0250 
0251         #--------------------
0252 
0253         pathsByCategory = EgammaHLTValidationUtils.findEgammaPaths(refProcess)
0254 
0255         for hltPathCategory, thisCategoryData in configData.items():
0256 
0257             # get the HLT path objects for this category
0258             paths = pathsByCategory[hltPathCategory]
0259 
0260             # fix: if there are no paths for some reason,
0261             # provide some dummy objects which we can delete
0262             # after the loop over the paths 
0263             path = None
0264             dqmModule = None
0265 
0266             for path in paths:
0267 
0268                 # name of the HLT path
0269                 pathName = path.label_()
0270 
0271                 # we currently exclude a few 'problematic' paths (for which we
0272                 # don't have a full recipe how to produce a monitoring path
0273                 # for them).
0274                 #
0275                 # we exclude paths which contain EDFilters which we don't know
0276                 # how to handle in the DQM modules
0277                 moduleCXXtypes = EgammaHLTValidationUtils.getCXXTypesOfPath(refProcess,path)
0278                 # print >> sys.stderr,"module types:", moduleCXXtypes
0279 
0280                 hasProblematicType = False
0281 
0282                 for problematicType in [
0283                     # this list was collected empirically
0284                     'HLTEgammaTriggerFilterObjectWrapper', 
0285                     'EgammaHLTPhotonTrackIsolationProducersRegional',
0286                     ]:
0287 
0288                     if problematicType in moduleCXXtypes:
0289                         ## print >> sys.stderr,msgPrefix, "SKIPPING PATH",pathName,"BECAUSE DON'T KNOW HOW TO HANDLE A MODULE WITH C++ TYPE",problematicType
0290                         hasProblematicType = True
0291                         break
0292 
0293                 if hasProblematicType:
0294                     continue
0295 
0296                 ## print >> sys.stderr,msgPrefix, "adding E/gamma HLT dqm module for path",pathName
0297 
0298                 dqmModuleName = pathName
0299                 if isFastSim:
0300                     dqmModuleName = dqmModuleName + "FastSim"
0301 
0302                 dqmModuleName = dqmModuleName + "_DQM"
0303 
0304                 dqmModule = EgammaHLTValidationUtils.EgammaDQMModuleMaker(refProcess, pathName,
0305                                                                           thisCategoryData['genPid'],        # type of generated particle
0306                                                                           thisCategoryData['numGenerated']   # number of generated particles
0307                                                                           ).getResult()
0308 
0309                 # add the module to the process object
0310                 globals()[dqmModuleName] = dqmModule
0311 
0312                 # and to the sequence
0313                 validators.append(dqmModule)
0314 
0315             # end of loop over paths
0316 
0317             # if we don't do the following deletes, loading this configuration
0318             # will pick these variables up and add it to the process object...
0319             del path
0320             del dqmModule
0321 
0322         # end of loop over analysis types (single electron, ...)
0323 
0324         #--------------------
0325         # we don't need the MC HLT Menu path any more
0326         del refProcess
0327 
0328     # end of loop over full/fast sim
0329 
0330     #--------------------
0331     
0332     # convert from list to sequence ('concatenate' them using '*')
0333     import operator
0334 
0335     egammaSelectors = cms.Sequence(reduce(operator.mul, egammaSelectors))
0336     
0337     # selectors go into separate "prevalidation" sequence
0338     egammaValidationSequence   = cms.Sequence(reduce(operator.mul, egammaValidators))
0339     egammaValidationSequenceFS = cms.Sequence(reduce(operator.mul, egammaValidatorsFS))
0340 
0341 
0342     #--------------------