CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaValidation_cff.py
Go to the documentation of this file.
2 
3 # whether to use the old or newer (automatically adapting
4 # to the MC menu) method of configuring the monitoring
5 # modules for the HLT paths
6 use_new_method = False
7 
8 
9 if not use_new_method:
10  #----------------------------------------------------------------------
11  # traditional method of configuring the HLT paths
12  #----------------------------------------------------------------------
13 
14  class dummy:
15  pass
16 
17  samples=dummy()
18  paths=dummy()
19 
20  ##########################################################
21  # Define which preselections to run #
22  ##########################################################
23 
24  samples.names = ['Wenu',
25  'Zee',
26  'GammaJet',
27  'DiGamma']
28  samples.pdgid = [ 11,
29  11,
30  22,
31  22]
32  samples.num = [1,
33  2,
34  1,
35  2]
36 
37  #which triggers for which sample
38 
39  paths.Wenu = [#'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM',
40  #'HLT_Ele10_LW_L1RDQM',
41  #'HLT_Ele15_SW_L1RDQM',
42  #'HLT_Ele10_LW_EleId_L1RDQM',
43  #'HLT_Ele15_SiStrip_L1RDQM'
44  #'HLT_Ele10_SW_EleId_HT70U_L1R_v2_DQM',
45  #'HLT_Ele10_SW_HT100U_L1R_v2_DQM',
46  #'HLT_Ele10_SW_HT70U_L1R_v2_DQM',
47  #'HLT_Ele10_SW_L1R_v2_DQM',
48  #'HLT_Ele12_SW_TighterEleId_L1R_v2_DQM',
49  #'HLT_Ele17_SW_Isol_L1R_v2_DQM',
50  #'HLT_Ele17_SW_L1R_v2_DQM',
51  #'HLT_Ele17_SW_TighterEleIdIsol_L1R_v3_DQM',
52  #'HLT_Ele22_SW_L1R_v2_DQM',
53  #'HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2_DQM',
54  #'HLT_Ele22_SW_TighterEleId_L1R_v3_DQM',
55  #'HLT_Ele32_SW_TighterEleId_L1R_v2_DQM'
56  ]
57 
58  paths.Zee = paths.Wenu + [#'HLT_DoubleEle5_SW_L1RDQM'
59  #'HLT_DoubleEle17_SW_L1R_v1_DQM',
60  #'HLT_DoubleEle4_SW_eeRes_L1R_v2_DQM',
61  #'HLT_DoubleEle5_SW_Upsilon_L1R_v2_DQM',
62  #'HLT_DoubleEle8_SW_HT70U_L1R_v1_DQM'
63  ]
64 
65  paths.GammaJet = [#'HLT_Photon10_L1R_DQM',
66  #'HLT_Photon15_TrackIso_L1R_DQM',
67  #'HLT_Photon15_LooseEcalIso_L1R_DQM',
68  #'HLT_Photon20_Cleaned_L1R_DQM',
69  #'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM'
70  #'HLT_Photon10_Cleaned_L1R_DQM',
71  #'HLT_Photon110_NoHE_Cleaned_L1R_v1_DQM',
72  #'HLT_Photon20_Cleaned_L1R_DQM',
73  #'HLT_Photon20_NoHE_L1R_DQM',
74  #'HLT_Photon30_Cleaned_L1R_DQM',
75  #'HLT_Photon40_CaloId_Cleaned_L1R_v1_DQM',
76  #'HLT_Photon50_Cleaned_L1R_v1_DQM',
77  #'HLT_Photon50_NoHE_L1R_DQM',
78  #'HLT_Photon70_Cleaned_L1R_v1_DQM'
79  ]
80 
81  paths.DiGamma = [#'HLT_Photon10_L1R_DQM','HLT_DoublePhoton10_L1R_DQM'
82  #'HLT_DoublePhoton22_L1R_v1_DQM',
83  #'HLT_DoublePhoton5_CEP_L1R_v3_DQM'
84  ]
85 
86  pathlumi = { 'HLT_Ele17_SW_TighterEleIdIsol_L1RDQM': '8e29',
87  'HLT_Ele10_LW_L1RDQM':'8e29',
88  'HLT_Ele15_SW_L1RDQM':'1e31',
89  'HLT_Ele10_LW_EleId_L1RDQM':'8e29',
90  'HLT_Ele15_SiStrip_L1RDQM':'8e29',
91  'HLT_DoubleEle5_SW_L1RDQM':'8e29',
92  'HLT_Photon10_L1R_DQM':'8e29',
93  'HLT_Photon15_TrackIso_L1R_DQM':'8e29',
94  'HLT_Photon15_LooseEcalIso_L1R_DQM':'8e29',
95  'HLT_Photon20_Cleaned_L1R_DQM':'8e29',
96  'HLT_DoublePhoton10_L1R_DQM':'8e29',
97  'HLT_Photon25_L1R_DQM':'1e31',
98  'HLT_Photon25_LooseEcalIso_TrackIso_L1R_DQM':'1e31'}
99 
100  # add the new paths automatically
101  for path in paths.Wenu + paths.Zee + paths.GammaJet + paths.DiGamma:
102  pathlumi[path] = '8e29'
103 
104  lumiprocess = { '8e29':'HLT',
105  '1e31':'HLT'
106  }
107 
108 
109  ##########################################################
110  # produce generated paricles in acceptance #
111  ##########################################################
112 
113  genp = cms.EDFilter("PdgIdAndStatusCandViewSelector",
114  status = cms.vint32(3),
115  src = cms.InputTag("genParticles"),
116  pdgId = cms.vint32(11) # replaced in loop
117  )
118 
119  fiducial = cms.EDFilter("EtaPtMinCandViewSelector",
120  src = cms.InputTag("genp"),
121  etaMin = cms.double(-2.5), # to be replaced in loop ?
122  etaMax = cms.double(2.5), # to be replaced in loop ?
123  ptMin = cms.double(2.0) # to be replaced in loop ?
124  )
125 
126  ##########################################################
127  # loop over samples to create modules and sequence #
128  ##########################################################
129 
130  tmp = cms.SequencePlaceholder("tmp")
131  egammaSelectors = cms.Sequence(tmp) # no empty sequences allowed, start with dummy
132  egammaValidators= cms.Sequence(tmp) # same
133 
134  #loop over samples
135  for samplenum in range(len(samples.names)):
136 
137  # clone genparticles and select correct type
138  genpartname = "genpart"+samples.names[samplenum]
139  globals()[genpartname] = genp.clone()
140  setattr(globals()[genpartname],"pdgId",cms.vint32(samples.pdgid[samplenum]) ) # set pdgId
141  egammaSelectors *= globals()[genpartname] # add to sequence
142 
143  # clone generator fiducial region
144  fiducialname = "fiducial"+samples.names[samplenum]
145  globals()[fiducialname] = fiducial.clone()
146  setattr(globals()[fiducialname],"src",cms.InputTag(genpartname) ) # set input collection
147  egammaSelectors *= globals()[fiducialname] # add to sequence
148 
149  # loop over triggers for each sample
150  for trig in getattr(paths,samples.names[samplenum]):
151  trigname = trig + samples.names[samplenum]
152  #import appropriate config snippet
153  filename = "HLTriggerOffline.Egamma."+trig+"_cfi"
154  trigdef =__import__( filename )
155  import sys
156  globals()[trigname] = getattr(sys.modules[filename],trig).clone() # clone imported config
157  setattr(globals()[trigname],"cutcollection",cms.InputTag(fiducialname)) # set preselacted generator collection
158  setattr(globals()[trigname],"cutnum",cms.int32( samples.num[samplenum] )) # cut value for preselection
159  setattr(globals()[trigname],"pdgGen",cms.int32( samples.pdgid[samplenum])) #correct pdgId for MC matching
160  getattr(globals()[trigname],'triggerobject').setProcessName( lumiprocess[pathlumi[trig]] ) #set proper process name
161  for filterpset in getattr(globals()[trigname],'filters'):
162  getattr(filterpset,'HLTCollectionLabels').setProcessName( lumiprocess[pathlumi[trig]] )
163  for isocollections in getattr(filterpset,'IsoCollections'):
164  isocollections.setProcessName( lumiprocess[pathlumi[trig]])
165 
166  egammaValidators *= globals()[trigname] # add to sequence
167 
168 
169  egammaSelectors.remove(tmp) # remove the initial dummy
170  egammaValidators.remove(tmp)
171 
172  # selectors go into separate "prevalidation" sequence
173  egammaValidationSequence = cms.Sequence( egammaValidators )
174  egammaValidationSequenceFS = 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.iteritems():
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.iteritems():
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  ## print >> sys.stderr,msgPrefix, "SKIPPING PATH",pathName,"BECAUSE DON'T KNOW HOW TO HANDLE A MODULE WITH C++ TYPE",problematicType
290  hasProblematicType = True
291  break
292 
293  if hasProblematicType:
294  continue
295 
296  ## print >> sys.stderr,msgPrefix, "adding E/gamma HLT dqm module for path",pathName
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  #--------------------
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135