CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/HLTriggerOffline/Egamma/python/EgammaValidation_cff.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 
00003 # whether to use the old or newer (automatically adapting
00004 # to the MC menu) method of configuring the monitoring
00005 # modules for the HLT paths
00006 use_new_method = False
00007 
00008 
00009 if not use_new_method:
00010     #----------------------------------------------------------------------
00011     # traditional method of configuring the HLT paths
00012     #----------------------------------------------------------------------
00013 
00014     class dummy:
00015         pass
00016 
00017     samples=dummy()
00018     paths=dummy()
00019 
00020     ##########################################################
00021     # Define which preselections to run                      #
00022     ##########################################################
00023 
00024     samples.names = ['Wenu',
00025                      'Zee',
00026                      'GammaJet',
00027                      'DiGamma']
00028     samples.pdgid = [ 11,
00029                       11,
00030                       22,
00031                       22]
00032     samples.num   = [1,
00033                      2,
00034                      1,
00035                      2]
00036 
00037     #which triggers for which sample
00038 
00039     paths.Wenu = [#'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM',
00040                   #'HLT_Ele10_LW_L1RDQM',
00041                   #'HLT_Ele15_SW_L1RDQM',
00042                   #'HLT_Ele10_LW_EleId_L1RDQM',
00043                   #'HLT_Ele15_SiStrip_L1RDQM'
00044                   #'HLT_Ele10_SW_EleId_HT70U_L1R_v2_DQM',
00045                   #'HLT_Ele10_SW_HT100U_L1R_v2_DQM',
00046                   #'HLT_Ele10_SW_HT70U_L1R_v2_DQM',
00047                   #'HLT_Ele10_SW_L1R_v2_DQM',
00048                   #'HLT_Ele12_SW_TighterEleId_L1R_v2_DQM',
00049                   #'HLT_Ele17_SW_Isol_L1R_v2_DQM',
00050                   #'HLT_Ele17_SW_L1R_v2_DQM',
00051                   #'HLT_Ele17_SW_TighterEleIdIsol_L1R_v3_DQM',
00052                   #'HLT_Ele22_SW_L1R_v2_DQM',
00053                   #'HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2_DQM',
00054                   #'HLT_Ele22_SW_TighterEleId_L1R_v3_DQM',
00055                   #'HLT_Ele32_SW_TighterEleId_L1R_v2_DQM'
00056                  ]
00057 
00058     paths.Zee = paths.Wenu + [#'HLT_DoubleEle5_SW_L1RDQM'
00059                               #'HLT_DoubleEle17_SW_L1R_v1_DQM',
00060                               #'HLT_DoubleEle4_SW_eeRes_L1R_v2_DQM',
00061                               #'HLT_DoubleEle5_SW_Upsilon_L1R_v2_DQM',
00062                               #'HLT_DoubleEle8_SW_HT70U_L1R_v1_DQM'
00063                              ]
00064 
00065     paths.GammaJet = [#'HLT_Photon10_L1R_DQM',
00066                       #'HLT_Photon15_TrackIso_L1R_DQM',
00067                       #'HLT_Photon15_LooseEcalIso_L1R_DQM',
00068                       #'HLT_Photon20_Cleaned_L1R_DQM',
00069                       #'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM'
00070                       #'HLT_Photon10_Cleaned_L1R_DQM',
00071                       #'HLT_Photon110_NoHE_Cleaned_L1R_v1_DQM',
00072                       #'HLT_Photon20_Cleaned_L1R_DQM',
00073                       #'HLT_Photon20_NoHE_L1R_DQM',
00074                       #'HLT_Photon30_Cleaned_L1R_DQM',
00075                       #'HLT_Photon40_CaloId_Cleaned_L1R_v1_DQM',
00076                       #'HLT_Photon50_Cleaned_L1R_v1_DQM',
00077                       #'HLT_Photon50_NoHE_L1R_DQM',
00078                       #'HLT_Photon70_Cleaned_L1R_v1_DQM'
00079                      ]
00080 
00081     paths.DiGamma  = [#'HLT_Photon10_L1R_DQM','HLT_DoublePhoton10_L1R_DQM'
00082                       #'HLT_DoublePhoton22_L1R_v1_DQM',
00083                       #'HLT_DoublePhoton5_CEP_L1R_v3_DQM'
00084                      ]
00085 
00086     pathlumi = { 'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM': '8e29',
00087                  'HLT_Ele10_LW_L1RDQM':'8e29',
00088                  'HLT_Ele15_SW_L1RDQM':'1e31',
00089                  'HLT_Ele10_LW_EleId_L1RDQM':'8e29',
00090                  'HLT_Ele15_SiStrip_L1RDQM':'8e29',
00091                  'HLT_DoubleEle5_SW_L1RDQM':'8e29',
00092                  'HLT_Photon10_L1R_DQM':'8e29',
00093                  'HLT_Photon15_TrackIso_L1R_DQM':'8e29',
00094                  'HLT_Photon15_LooseEcalIso_L1R_DQM':'8e29',
00095                  'HLT_Photon20_Cleaned_L1R_DQM':'8e29',
00096                  'HLT_DoublePhoton10_L1R_DQM':'8e29',
00097                  'HLT_Photon25_L1R_DQM':'1e31',
00098                  'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM':'1e31'}
00099 
00100     # add the new paths automatically
00101     for path in paths.Wenu + paths.Zee + paths.GammaJet + paths.DiGamma:
00102         pathlumi[path] = '8e29'
00103 
00104     lumiprocess = { '8e29':'HLT',
00105                     '1e31':'HLT'
00106                     }
00107 
00108 
00109     ##########################################################
00110     # produce generated paricles in acceptance               #
00111     ##########################################################
00112 
00113     genp = cms.EDFilter("PdgIdAndStatusCandViewSelector",
00114         status = cms.vint32(3),
00115         src = cms.InputTag("genParticles"),
00116         pdgId = cms.vint32(11)  # replaced in loop
00117     )
00118 
00119     fiducial = cms.EDFilter("EtaPtMinCandViewSelector",
00120         src = cms.InputTag("genp"),
00121         etaMin = cms.double(-2.5),  # to be replaced in loop ?
00122         etaMax = cms.double(2.5),   # to be replaced in loop ?
00123         ptMin = cms.double(2.0)     # to be replaced in loop ?
00124     )
00125 
00126     ##########################################################
00127     # loop over samples to create modules and sequence       #
00128     ##########################################################
00129 
00130     tmp = cms.SequencePlaceholder("tmp")
00131     egammaSelectors = cms.Sequence(tmp) # no empty sequences allowed, start with dummy
00132     egammaValidators= cms.Sequence(tmp) # same
00133 
00134     #loop over samples
00135     for samplenum in range(len(samples.names)):
00136 
00137         # clone genParticles and select correct type
00138         genpartname = "genpart"+samples.names[samplenum]
00139         globals()[genpartname] = genp.clone()
00140         setattr(globals()[genpartname],"pdgId",cms.vint32(samples.pdgid[samplenum]) ) # set pdgId
00141         egammaSelectors *= globals()[genpartname]                            # add to sequence
00142 
00143         # clone generator fiducial region
00144         fiducialname = "fiducial"+samples.names[samplenum]
00145         globals()[fiducialname] = fiducial.clone()
00146         setattr(globals()[fiducialname],"src",cms.InputTag(genpartname) ) # set input collection
00147         egammaSelectors *= globals()[fiducialname]               # add to sequence
00148 
00149         # loop over triggers for each sample
00150         for trig in getattr(paths,samples.names[samplenum]):
00151             trigname = trig + samples.names[samplenum] 
00152             #import appropriate config snippet
00153             filename = "HLTriggerOffline.Egamma."+trig+"_cfi"
00154             trigdef =__import__( filename )
00155             import sys
00156             globals()[trigname] = getattr(sys.modules[filename],trig).clone()    # clone imported config
00157             setattr(globals()[trigname],"cutcollection",cms.InputTag(fiducialname))        # set preselacted generator collection
00158             setattr(globals()[trigname],"cutnum",cms.int32( samples.num[samplenum]  )) # cut value for preselection
00159             setattr(globals()[trigname],"pdgGen",cms.int32( samples.pdgid[samplenum])) #correct pdgId for MC matching
00160             getattr(globals()[trigname],'triggerobject').setProcessName( lumiprocess[pathlumi[trig]] )         #set proper process name
00161             for filterpset in getattr(globals()[trigname],'filters'):
00162                 getattr(filterpset,'HLTCollectionLabels').setProcessName( lumiprocess[pathlumi[trig]] )
00163                 for isocollections in getattr(filterpset,'IsoCollections'):
00164                     isocollections.setProcessName( lumiprocess[pathlumi[trig]])
00165 
00166             egammaValidators *= globals()[trigname]                      # add to sequence
00167 
00168 
00169     egammaSelectors.remove(tmp)  # remove the initial dummy
00170     egammaValidators.remove(tmp)
00171 
00172     # selectors go into separate "prevalidation" sequence
00173     egammaValidationSequence   = cms.Sequence( egammaValidators )
00174     egammaValidationSequenceFS = cms.Sequence( egammaValidators )
00175 
00176 else:
00177     #----------------------------------------------------------------------
00178     # new method
00179     #----------------------------------------------------------------------
00180 
00181     import sys, os
00182 
00183     # prefix for printouts
00184     msgPrefix = "[" + os.path.basename(__file__) + "]"
00185 
00186     import HLTriggerOffline.Egamma.EgammaHLTValidationUtils as EgammaHLTValidationUtils
00187 
00188 
00189     # maps from Egamma HLT path category to number of type and number of generated
00190     # particles required for the histogramming
00191     configData = {
00192         "singleElectron": { "genPid" : 11, "numGenerated" : 1,},
00193         "doubleElectron": { "genPid" : 11, "numGenerated" : 2 },
00194         "singlePhoton":   { "genPid" : 22, "numGenerated" : 1 },
00195         "doublePhoton":   { "genPid" : 22, "numGenerated" : 2 },
00196         }
00197 
00198     #----------------------------------------
00199     # generate generator level selection modules
00200     #
00201     # note that this is common between full and
00202     # fast simulation
00203     #----------------------------------------
00204     egammaSelectors = []
00205 
00206     for hltPathCategory, thisCategoryData in configData.iteritems():
00207         # all paths in the current category share the same
00208         # generator level requirement
00209         #
00210         # add a sequence for this generator level requirement
00211 
00212         generatorRequirementSequence = EgammaHLTValidationUtils.makeGeneratedParticleAndFiducialVolumeFilter(None,
00213                                                                                                              thisCategoryData['genPid'],
00214                                                                                                              thisCategoryData['numGenerated'])
00215 
00216         # dirty hack: get all modules of this sequence and add them
00217         # to globals() (which is not the same as calling globals() in makeGeneratedParticleAndFiducialVolumeFilter)
00218         # so that they will be added to the process
00219         for module in EgammaHLTValidationUtils.getModulesOfSequence(generatorRequirementSequence):
00220             globals()[module.label_()] = module
00221 
00222         # avoid that this variable is added to the process object when importing this _cff
00223         # (otherwise the last filter will appear with module name 'module' instead
00224         # of the name given by us...)
00225         del module
00226 
00227         egammaSelectors.append(generatorRequirementSequence)
00228         
00229     #----------------------------------------
00230     # compose the DQM anlyser paths
00231     #----------------------------------------
00232 
00233     egammaValidators = []
00234     egammaValidatorsFS = []
00235 
00236     for isFastSim, validators in (
00237         (False, egammaValidators),
00238         (True,  egammaValidatorsFS),
00239         ):
00240 
00241         #--------------------
00242         # a 'reference' process to take (and analyze) the HLT menu from
00243         #--------------------
00244         refProcess = cms.Process("REF")
00245 
00246         if isFastSim:
00247             refProcess.load("FastSimulation.Configuration.HLT_GRun_cff")
00248         else:
00249             refProcess.load("HLTrigger.Configuration.HLT_GRun_cff")
00250 
00251         #--------------------
00252 
00253         pathsByCategory = EgammaHLTValidationUtils.findEgammaPaths(refProcess)
00254 
00255         for hltPathCategory, thisCategoryData in configData.iteritems():
00256 
00257             # get the HLT path objects for this category
00258             paths = pathsByCategory[hltPathCategory]
00259 
00260             # fix: if there are no paths for some reason,
00261             # provide some dummy objects which we can delete
00262             # after the loop over the paths 
00263             path = None
00264             dqmModule = None
00265 
00266             for path in paths:
00267 
00268                 # name of the HLT path
00269                 pathName = path.label_()
00270 
00271                 # we currently exclude a few 'problematic' paths (for which we
00272                 # don't have a full recipe how to produce a monitoring path
00273                 # for them).
00274                 #
00275                 # we exclude paths which contain EDFilters which we don't know
00276                 # how to handle in the DQM modules
00277                 moduleCXXtypes = EgammaHLTValidationUtils.getCXXTypesOfPath(refProcess,path)
00278                 # print >> sys.stderr,"module types:", moduleCXXtypes
00279 
00280                 hasProblematicType = False
00281 
00282                 for problematicType in [
00283                     # this list was collected empirically
00284                     'HLTEgammaTriggerFilterObjectWrapper', 
00285                     'EgammaHLTPhotonTrackIsolationProducersRegional',
00286                     ]:
00287 
00288                     if problematicType in moduleCXXtypes:
00289                         ## print >> sys.stderr,msgPrefix, "SKIPPING PATH",pathName,"BECAUSE DON'T KNOW HOW TO HANDLE A module WITH C++ TYPE",problematicType
00290                         hasProblematicType = True
00291                         break
00292 
00293                 if hasProblematicType:
00294                     continue
00295 
00296                 ## print >> sys.stderr,msgPrefix, "adding E/gamma HLT dqm module for path",pathName
00297 
00298                 dqmModuleName = pathName
00299                 if isFastSim:
00300                     dqmModuleName = dqmModuleName + "FastSim"
00301 
00302                 dqmModuleName = dqmModuleName + "_DQM"
00303 
00304                 dqmModule = EgammaHLTValidationUtils.EgammaDQMModuleMaker(refProcess, pathName,
00305                                                                           thisCategoryData['genPid'],        # type of generated particle
00306                                                                           thisCategoryData['numGenerated']   # number of generated particles
00307                                                                           ).getResult()
00308 
00309                 # add the module to the process object
00310                 globals()[dqmModuleName] = dqmModule
00311 
00312                 # and to the sequence
00313                 validators.append(dqmModule)
00314 
00315             # end of loop over paths
00316 
00317             # if we don't do the following deletes, loading this Configuration
00318             # will pick these variables up and add it to the process object...
00319             del path
00320             del dqmModule
00321 
00322         # end of loop over analysis types (single electron, ...)
00323 
00324         #--------------------
00325         # we don't need the MC HLT Menu path any more
00326         del refProcess
00327 
00328     # end of loop over full/fast sim
00329 
00330     #--------------------
00331     
00332     # convert from list to sequence ('concatenate' them using '*')
00333     import operator
00334 
00335     egammaSelectors = cms.Sequence(reduce(operator.mul, egammaSelectors))
00336     
00337     # selectors go into separate "prevalidation" sequence
00338     egammaValidationSequence   = cms.Sequence(reduce(operator.mul, egammaValidators))
00339     egammaValidationSequenceFS = cms.Sequence(reduce(operator.mul, egammaValidatorsFS))
00340 
00341 
00342     #--------------------