CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hgcalTriggerChains.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4  def __init__(self):
5  self.vfe = {}
6  self.concentrator = {}
7  self.truth_prod = {}
8  self.backend1 = {}
9  self.backend2 = {}
10  self.selector = {}
11  self.ntuple = {}
12  self.chain = []
13  self.truth_chain = []
14 
15  def register_vfe(self, name, generator):
16  self.vfe[name] = generator
17 
18  def register_concentrator(self, name, generator):
19  self.concentrator[name] = generator
20 
21  def register_truth_prod(self, name, generator): # for truth-matched trigger cells
22  self.truth_prod[name] = generator
23 
24  def register_backend1(self, name, generator):
25  self.backend1[name] = generator
26 
27  def register_backend2(self, name, generator):
28  self.backend2[name] = generator
29 
30  def register_selector(self, name, generator):
31  self.selector[name] = generator
32 
33  def register_ntuple(self, name, generator):
34  self.ntuple[name] = generator
35 
36  def register_chain(self, vfe, concentrator, backend1, backend2, selector='', ntuple=''):
37  if not vfe in self.vfe:
38  raise KeyError('{} not registered as VFE producer'.format(vfe))
39  if not concentrator in self.concentrator:
40  raise KeyError('{} not registered as concentrator producer'.format(concentrator))
41  if not backend1 in self.backend1:
42  raise KeyError('{} not registered as backend1 producer'.format(backend1))
43  if not backend2 in self.backend2:
44  raise KeyError('{} not registered as backend2 producer'.format(backend2))
45  if selector!='' and not selector in self.selector:
46  raise KeyError('{} not registered as selector'.format(selector))
47  if ntuple!='' and not ntuple in self.ntuple:
48  raise KeyError('{} not registered as ntuplizer'.format(ntuple))
49  self.chain.append( (vfe, concentrator, backend1, backend2, selector, ntuple) )
50 
51  def register_truth_chain(self, vfe, truth_prod, backend1='', backend2='', selector='', ntuple=''):
52  if not vfe in self.vfe:
53  raise KeyError('{} not registered as VFE producer'.format(vfe))
54  if not truth_prod in self.truth_prod:
55  raise KeyError('{} not registered as truth producer'.format(truth_prod))
56  if backend1!='' and not backend1 in self.backend1:
57  raise KeyError('{} not registered as backend1 producer'.format(backend1))
58  if backend2!='' and not backend2 in self.backend2:
59  raise KeyError('{} not registered as backend2 producer'.format(backend2))
60  if selector!='' and not selector in self.selector:
61  raise KeyError('{} not registered as selector'.format(selector))
62  if ntuple!='' and not ntuple in self.ntuple:
63  raise KeyError('{} not registered as ntuplizer'.format(ntuple))
64  self.truth_chain.append( (vfe, truth_prod, backend1, backend2, selector, ntuple) )
65 
66  def create_sequences(self, process):
67  if not hasattr(process, 'hgcalTriggerSelector'):
68  process.load('L1Trigger.L1THGCalUtilities.HGC3DClusterGenMatchSelector_cff')
69  tmp = cms.TaskPlaceholder("tmp")
70  tmpseq = cms.SequencePlaceholder("tmp")
71  vfe_task = cms.Task(tmp)
72  concentrator_task = cms.Task(tmp)
73  backend1_task = cms.Task(tmp)
74  backend2_task = cms.Task(tmp)
75  selector_sequence = cms.Sequence(tmpseq)
76  ntuple_sequence = cms.Sequence(tmpseq)
77  for vfe,concentrator,backend1,backend2,selector,ntuple in self.chain:
78  concentrator_name = '{0}{1}'.format(vfe, concentrator)
79  backend1_name = '{0}{1}{2}'.format(vfe, concentrator, backend1)
80  backend2_name = '{0}{1}{2}{3}'.format(vfe, concentrator, backend1, backend2)
81  selector_name = '{0}{1}{2}{3}{4}'.format(vfe, concentrator, backend1, backend2, selector)
82  ntuple_name = '{0}{1}{2}{3}{4}{5}'.format(vfe, concentrator, backend1, backend2, selector, ntuple)
83  if selector=='':
84  ntuple_inputs = [
85  concentrator_name+':HGCalConcentratorProcessorSelection',
86  backend1_name+':HGCalBackendLayer1Processor2DClustering',
87  backend2_name+':HGCalBackendLayer2Processor3DClustering'
88  ]
89  else:
90  ntuple_inputs = [
91  concentrator_name+':HGCalConcentratorProcessorSelection',
92  backend1_name+':HGCalBackendLayer1Processor2DClustering',
93  selector_name]
94  if not hasattr(process, vfe):
95  setattr(process, vfe, self.vfe[vfe](process))
96  vfe_task.add(getattr(process, vfe))
97  if not hasattr(process, concentrator_name):
98  setattr(process, concentrator_name, self.concentrator[concentrator](process, vfe))
99  concentrator_task.add(getattr(process, concentrator_name))
100  if not hasattr(process, backend1_name):
101  setattr(process, backend1_name, self.backend1[backend1](process, concentrator_name))
102  backend1_task.add(getattr(process, backend1_name))
103  if not hasattr(process, backend2_name):
104  setattr(process, backend2_name, self.backend2[backend2](process, backend1_name))
105  backend2_task.add(getattr(process, backend2_name))
106  if selector!='' and not hasattr(process, selector_name):
107  setattr(process, selector_name, self.selector[selector](process, backend2_name))
108  selector_sequence *= getattr(process, selector_name)
109  if ntuple!='' and not hasattr(process, ntuple_name):
110  setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
111  ntuple_sequence *= getattr(process, ntuple_name)
112  vfe_task.remove(tmp)
113  concentrator_task.remove(tmp)
114  backend1_task.remove(tmp)
115  backend2_task.remove(tmp)
116  selector_sequence.remove(tmpseq)
117  ntuple_sequence.remove(tmpseq)
118  process.globalReplace('hgcalVFE', vfe_task)
119  process.globalReplace('hgcalConcentrator', concentrator_task)
120  process.globalReplace('hgcalBackEndLayer1', backend1_task)
121  process.globalReplace('hgcalBackEndLayer2', backend2_task)
122  process.globalReplace('hgcalTriggerSelector', selector_sequence)
123  process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
124  return process
125 
126  def create_truth_sequences(self, process):
127  if not hasattr(process, 'caloTruthCellsProducer'):
128  from L1Trigger.L1THGCalUtilities.caloTruthCellsProducer_cfi import caloTruthCellsProducer
129  process.load('L1Trigger.L1THGCalUtilities.caloTruthCells_cff')
130  process.truthCellsProd = cms.Task(caloTruthCellsProducer)
131  hgcalTriggerPrimitivesTask = cms.Task(process.hgcalVFE, process.truthCellsProd, process.hgcalBackEndLayer1, process.hgcalBackEndLayer2, process.hgcalTowerMap, process.hgcalTower)
132  process.hgcalTriggerPrimitivesTruth = cms.Sequence(hgcalTriggerPrimitivesTask)
133  if not hasattr(process, 'hgcalTriggerSelector'):
134  process.load('L1Trigger.L1THGCalUtilities.HGC3DClusterGenMatchSelector_cff')
135  tmp = cms.TaskPlaceholder("tmp")
136  tmpseq = cms.SequencePlaceholder("tmp")
137  vfe_task = cms.Task(tmp)
138  truth_prod_task = cms.Task(tmp)
139  backend1_task = cms.Task(tmp)
140  backend2_task = cms.Task(tmp)
141  selector_sequence = cms.Sequence(tmpseq)
142  ntuple_sequence = cms.Sequence(tmpseq)
143  for vfe,truth_prod,backend1,backend2,selector,ntuple in self.truth_chain:
144  truth_prod_name = '{0}{1}'.format(vfe, truth_prod)
145  backend1_name = truth_prod_name + '{0}'.format(backend1)
146  backend2_name = backend1_name + '{0}'.format(backend2)
147  selector_name = backend2_name + '{0}'.format(selector)
148  ntuple_name = selector_name + '{0}'.format(ntuple)
149  if selector=='':
150  if backend2=='':
151  if backend1=='':
152  ntuple_inputs = [
153  truth_prod_name,
154  truth_prod_name,
155  truth_prod_name
156  ]
157  else:
158  ntuple_inputs = [
159  truth_prod_name,
160  backend1_name+':HGCalBackendLayer1Processor2DClustering',
161  truth_prod_name
162  ]
163  else:
164  ntuple_inputs = [
165  truth_prod_name,
166  backend1_name+':HGCalBackendLayer1Processor2DClustering',
167  backend2_name+':HGCalBackendLayer2Processor3DClustering'
168  ]
169  else:
170  ntuple_inputs = [
171  truth_prod_name,
172  backend1_name+':HGCalBackendLayer1Processor2DClustering',
173  selector_name
174  ]
175 
176  if not hasattr(process, vfe):
177  setattr(process, vfe, self.vfe[vfe](process))
178  vfe_task.add(getattr(process, vfe))
179  if not hasattr(process, truth_prod_name):
180  setattr(process, truth_prod_name, self.truth_prod[truth_prod](process, vfe))
181  truth_prod_task.add(getattr(process, truth_prod_name))
182  if not hasattr(process, backend1_name):
183  setattr(process, backend1_name, self.backend1[backend1](process, truth_prod_name))
184  backend1_task.add(getattr(process, backend1_name))
185  if backend2!='' and not hasattr(process, backend2_name):
186  setattr(process, backend2_name, self.backend2[backend2](process, backend1_name))
187  backend2_task.add(getattr(process, backend2_name))
188  if selector!='' and not hasattr(process, selector_name):
189  setattr(process, selector_name, self.selector[selector](process, backend2_name))
190  selector_sequence *= getattr(process, selector_name)
191  if ntuple!='' and not hasattr(process, ntuple_name):
192  setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
193  ntuple_sequence *= getattr(process, ntuple_name)
194  vfe_task.remove(tmp)
195  truth_prod_task.remove(tmp)
196  backend1_task.remove(tmp)
197  backend2_task.remove(tmp)
198  selector_sequence.remove(tmpseq)
199  ntuple_sequence.remove(tmpseq)
200  process.globalReplace('hgcalVFE', vfe_task)
201  process.globalReplace('truthCellsProd', truth_prod_task)
202  process.globalReplace('hgcalBackEndLayer1', backend1_task)
203  process.globalReplace('hgcalBackEndLayer2', backend2_task)
204  process.globalReplace('hgcalTriggerSelector', selector_sequence)
205  process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
206  return process