CMS 3D CMS Logo

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