CMS 3D CMS Logo

EgammaValidation_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from functools import reduce
3 import six
4 
5 # whether to use the old or newer (automatically adapting
6 # to the MC menu) method of configuring the monitoring
7 # modules for the HLT paths
8 use_new_method = False
9 
10 
11 if not use_new_method:
12  #----------------------------------------------------------------------
13  # traditional method of configuring the HLT paths
14  #----------------------------------------------------------------------
15 
16  class dummy:
17  pass
18 
19  samples=dummy()
20  paths=dummy()
21 
22 
25 
26  samples.names = ['Wenu',
27  'Zee',
28  'GammaJet',
29  'DiGamma']
30  samples.pdgid = [ 11,
31  11,
32  22,
33  22]
34  samples.num = [1,
35  2,
36  1,
37  2]
38 
39  #which triggers for which sample
40 
41  paths.Wenu = [#'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM',
42  #'HLT_Ele10_LW_L1RDQM',
43  #'HLT_Ele15_SW_L1RDQM',
44  #'HLT_Ele10_LW_EleId_L1RDQM',
45  #'HLT_Ele15_SiStrip_L1RDQM'
46  #'HLT_Ele10_SW_EleId_HT70U_L1R_v2_DQM',
47  #'HLT_Ele10_SW_HT100U_L1R_v2_DQM',
48  #'HLT_Ele10_SW_HT70U_L1R_v2_DQM',
49  #'HLT_Ele10_SW_L1R_v2_DQM',
50  #'HLT_Ele12_SW_TighterEleId_L1R_v2_DQM',
51  #'HLT_Ele17_SW_Isol_L1R_v2_DQM',
52  #'HLT_Ele17_SW_L1R_v2_DQM',
53  #'HLT_Ele17_SW_TighterEleIdIsol_L1R_v3_DQM',
54  #'HLT_Ele22_SW_L1R_v2_DQM',
55  #'HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2_DQM',
56  #'HLT_Ele22_SW_TighterEleId_L1R_v3_DQM',
57  #'HLT_Ele32_SW_TighterEleId_L1R_v2_DQM'
58  ]
59 
60  paths.Zee = paths.Wenu + [#'HLT_DoubleEle5_SW_L1RDQM'
61  #'HLT_DoubleEle17_SW_L1R_v1_DQM',
62  #'HLT_DoubleEle4_SW_eeRes_L1R_v2_DQM',
63  #'HLT_DoubleEle5_SW_Upsilon_L1R_v2_DQM',
64  #'HLT_DoubleEle8_SW_HT70U_L1R_v1_DQM'
65  ]
66 
67  paths.GammaJet = [#'HLT_Photon10_L1R_DQM',
68  #'HLT_Photon15_TrackIso_L1R_DQM',
69  #'HLT_Photon15_LooseEcalIso_L1R_DQM',
70  #'HLT_Photon20_Cleaned_L1R_DQM',
71  #'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM'
72  #'HLT_Photon10_Cleaned_L1R_DQM',
73  #'HLT_Photon110_NoHE_Cleaned_L1R_v1_DQM',
74  #'HLT_Photon20_Cleaned_L1R_DQM',
75  #'HLT_Photon20_NoHE_L1R_DQM',
76  #'HLT_Photon30_Cleaned_L1R_DQM',
77  #'HLT_Photon40_CaloId_Cleaned_L1R_v1_DQM',
78  #'HLT_Photon50_Cleaned_L1R_v1_DQM',
79  #'HLT_Photon50_NoHE_L1R_DQM',
80  #'HLT_Photon70_Cleaned_L1R_v1_DQM'
81  ]
82 
83  paths.DiGamma = [#'HLT_Photon10_L1R_DQM','HLT_DoublePhoton10_L1R_DQM'
84  #'HLT_DoublePhoton22_L1R_v1_DQM',
85  #'HLT_DoublePhoton5_CEP_L1R_v3_DQM'
86  ]
87 
88  pathlumi = { 'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM': '8e29',
89  'HLT_Ele10_LW_L1RDQM':'8e29',
90  'HLT_Ele15_SW_L1RDQM':'1e31',
91  'HLT_Ele10_LW_EleId_L1RDQM':'8e29',
92  'HLT_Ele15_SiStrip_L1RDQM':'8e29',
93  'HLT_DoubleEle5_SW_L1RDQM':'8e29',
94  'HLT_Photon10_L1R_DQM':'8e29',
95  'HLT_Photon15_TrackIso_L1R_DQM':'8e29',
96  'HLT_Photon15_LooseEcalIso_L1R_DQM':'8e29',
97  'HLT_Photon20_Cleaned_L1R_DQM':'8e29',
98  'HLT_DoublePhoton10_L1R_DQM':'8e29',
99  'HLT_Photon25_L1R_DQM':'1e31',
100  'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM':'1e31'}
101 
102  # add the new paths automatically
103  for path in paths.Wenu + paths.Zee + paths.GammaJet + paths.DiGamma:
104  pathlumi[path] = '8e29'
105 
106  lumiprocess = { '8e29':'HLT',
107  '1e31':'HLT'
108  }
109 
110 
111 
114 
115  genp = cms.EDFilter("PdgIdAndStatusCandViewSelector",
116  status = cms.vint32(3),
117  src = cms.InputTag("genParticles"),
118  pdgId = cms.vint32(11) # replaced in loop
119  )
120 
121  fiducial = cms.EDFilter("EtaPtMinCandViewSelector",
122  src = cms.InputTag("genp"),
123  etaMin = cms.double(-2.5), # to be replaced in loop ?
124  etaMax = cms.double(2.5), # to be replaced in loop ?
125  ptMin = cms.double(2.0) # to be replaced in loop ?
126  )
127 
128 
131 
132  tmp = cms.SequencePlaceholder("tmp")
133  egammaSelectors = cms.Sequence(tmp) # no empty sequences allowed, start with dummy
134  egammaValidators= cms.Sequence(tmp) # same
135 
136  #loop over samples
137  for samplenum in range(len(samples.names)):
138 
139  # clone genparticles and select correct type
140  genpartname = "genpart"+samples.names[samplenum]
141  globals()[genpartname] = genp.clone()
142  setattr(globals()[genpartname],"pdgId",cms.vint32(samples.pdgid[samplenum]) ) # set pdgId
143  egammaSelectors *= globals()[genpartname] # add to sequence
144 
145  # clone generator fiducial region
146  fiducialname = "fiducial"+samples.names[samplenum]
147  globals()[fiducialname] = fiducial.clone()
148  setattr(globals()[fiducialname],"src",cms.InputTag(genpartname) ) # set input collection
149  egammaSelectors *= globals()[fiducialname] # add to sequence
150 
151  # loop over triggers for each sample
152  for trig in getattr(paths,samples.names[samplenum]):
153  trigname = trig + samples.names[samplenum]
154  #import appropriate config snippet
155  filename = "HLTriggerOffline.Egamma."+trig+"_cfi"
156  trigdef =__import__( filename )
157  import sys
158  globals()[trigname] = getattr(sys.modules[filename],trig).clone() # clone imported config
159  setattr(globals()[trigname],"cutcollection",cms.InputTag(fiducialname)) # set preselacted generator collection
160  setattr(globals()[trigname],"cutnum",cms.int32( samples.num[samplenum] )) # cut value for preselection
161  setattr(globals()[trigname],"pdgGen",cms.int32( samples.pdgid[samplenum])) #correct pdgId for MC matching
162  getattr(globals()[trigname],'triggerobject').setProcessName( lumiprocess[pathlumi[trig]] ) #set proper process name
163  for filterpset in getattr(globals()[trigname],'filters'):
164  getattr(filterpset,'HLTCollectionLabels').setProcessName( lumiprocess[pathlumi[trig]] )
165  for isocollections in getattr(filterpset,'IsoCollections'):
166  isocollections.setProcessName( lumiprocess[pathlumi[trig]])
167 
168  egammaValidators *= globals()[trigname] # add to sequence
169 
170 
171  egammaSelectors.remove(tmp) # remove the initial dummy
172  egammaValidators.remove(tmp)
173 
174  # selectors go into separate "prevalidation" sequence
175  egammaValidationSequence = cms.Sequence( egammaValidators )
176 
177 else:
178  #----------------------------------------------------------------------
179  # new method
180  #----------------------------------------------------------------------
181 
182  import sys, os
183 
184  # prefix for printouts
185  msgPrefix = "[" + os.path.basename(__file__) + "]"
186 
187  import HLTriggerOffline.Egamma.EgammaHLTValidationUtils as EgammaHLTValidationUtils
188 
189 
190  # maps from Egamma HLT path category to number of type and number of generated
191  # particles required for the histogramming
192  configData = {
193  "singleElectron": { "genPid" : 11, "numGenerated" : 1,},
194  "doubleElectron": { "genPid" : 11, "numGenerated" : 2 },
195  "singlePhoton": { "genPid" : 22, "numGenerated" : 1 },
196  "doublePhoton": { "genPid" : 22, "numGenerated" : 2 },
197  }
198 
199  #----------------------------------------
200  # generate generator level selection modules
201  #
202  # note that this is common between full and
203  # fast simulation
204  #----------------------------------------
205  egammaSelectors = []
206 
207  for hltPathCategory, thisCategoryData in six.iteritems(configData):
208  # all paths in the current category share the same
209  # generator level requirement
210  #
211  # add a sequence for this generator level requirement
212 
214  thisCategoryData['genPid'],
215  thisCategoryData['numGenerated'])
216 
217  # dirty hack: get all modules of this sequence and add them
218  # to globals() (which is not the same as calling globals() in makeGeneratedParticleAndFiducialVolumeFilter)
219  # so that they will be added to the process
220  for module in EgammaHLTValidationUtils.getModulesOfSequence(generatorRequirementSequence):
221  globals()[module.label_()] = module
222 
223  # avoid that this variable is added to the process object when importing this _cff
224  # (otherwise the last filter will appear with module name 'module' instead
225  # of the name given by us...)
226  del module
227 
228  egammaSelectors.append(generatorRequirementSequence)
229 
230  #----------------------------------------
231  # compose the DQM anlyser paths
232  #----------------------------------------
233 
234  egammaValidators = []
235  egammaValidatorsFS = []
236 
237  for isFastSim, validators in (
238  (False, egammaValidators),
239  (True, egammaValidatorsFS),
240  ):
241 
242  #--------------------
243  # a 'reference' process to take (and analyze) the HLT menu from
244  #--------------------
245  refProcess = cms.Process("REF")
246 
247  if isFastSim:
248  refProcess.load("FastSimulation.Configuration.HLT_GRun_cff")
249  else:
250  refProcess.load("HLTrigger.Configuration.HLT_GRun_cff")
251 
252  #--------------------
253 
254  pathsByCategory = EgammaHLTValidationUtils.findEgammaPaths(refProcess)
255 
256  for hltPathCategory, thisCategoryData in six.iteritems(configData):
257 
258  # get the HLT path objects for this category
259  paths = pathsByCategory[hltPathCategory]
260 
261  # fix: if there are no paths for some reason,
262  # provide some dummy objects which we can delete
263  # after the loop over the paths
264  path = None
265  dqmModule = None
266 
267  for path in paths:
268 
269  # name of the HLT path
270  pathName = path.label_()
271 
272  # we currently exclude a few 'problematic' paths (for which we
273  # don't have a full recipe how to produce a monitoring path
274  # for them).
275  #
276  # we exclude paths which contain EDFilters which we don't know
277  # how to handle in the DQM modules
278  moduleCXXtypes = EgammaHLTValidationUtils.getCXXTypesOfPath(refProcess,path)
279  # print >> sys.stderr,"module types:", moduleCXXtypes
280 
281  hasProblematicType = False
282 
283  for problematicType in [
284  # this list was collected empirically
285  'HLTEgammaTriggerFilterObjectWrapper',
286  'EgammaHLTPhotonTrackIsolationProducersRegional',
287  ]:
288 
289  if problematicType in moduleCXXtypes:
290 
291  hasProblematicType = True
292  break
293 
294  if hasProblematicType:
295  continue
296 
297 
298 
299  dqmModuleName = pathName
300  if isFastSim:
301  dqmModuleName = dqmModuleName + "FastSim"
302 
303  dqmModuleName = dqmModuleName + "_DQM"
304 
305  dqmModule = EgammaHLTValidationUtils.EgammaDQMModuleMaker(refProcess, pathName,
306  thisCategoryData['genPid'], # type of generated particle
307  thisCategoryData['numGenerated'] # number of generated particles
308  ).getResult()
309 
310  # add the module to the process object
311  globals()[dqmModuleName] = dqmModule
312 
313  # and to the sequence
314  validators.append(dqmModule)
315 
316  # end of loop over paths
317 
318  # if we don't do the following deletes, loading this configuration
319  # will pick these variables up and add it to the process object...
320  del path
321  del dqmModule
322 
323  # end of loop over analysis types (single electron, ...)
324 
325  #--------------------
326  # we don't need the MC HLT Menu path any more
327  del refProcess
328 
329  # end of loop over full/fast sim
330 
331  #--------------------
332 
333  # convert from list to sequence ('concatenate' them using '*')
334  import operator
335 
336  egammaSelectors = cms.Sequence(reduce(operator.mul, egammaSelectors))
337 
338  # selectors go into separate "prevalidation" sequence
339  egammaValidationSequence = cms.Sequence(reduce(operator.mul, egammaValidators))
340  egammaValidationSequenceFS = cms.Sequence(reduce(operator.mul, egammaValidatorsFS))
341 
342 
343  #--------------------
EgammaHLTValidationUtils.EgammaDQMModuleMaker
Definition: EgammaHLTValidationUtils.py:126
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
EgammaHLTValidationUtils.getCXXTypesOfPath
def getCXXTypesOfPath(process, path)
Definition: EgammaHLTValidationUtils.py:654
EgammaValidation_cff.dummy
Definition: EgammaValidation_cff.py:16
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
EgammaHLTValidationUtils.makeGeneratedParticleAndFiducialVolumeFilter
def makeGeneratedParticleAndFiducialVolumeFilter(process, pdgGen, requiredNumberOfGeneratedObjects)
Definition: EgammaHLTValidationUtils.py:50
EgammaHLTValidationUtils.findEgammaPaths
def findEgammaPaths(process)
Definition: EgammaHLTValidationUtils.py:560
EgammaHLTValidationUtils.getResult
def getResult(self)
Definition: EgammaHLTValidationUtils.py:537
dummy
Definition: DummySelector.h:38
EgammaHLTValidationUtils.getModulesOfSequence
def getModulesOfSequence(sequence)
Definition: EgammaHLTValidationUtils.py:679