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