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 not hasattr(process, vfe):
84  setattr(process, vfe, self.vfe[vfe](process))
85  vfe_task.add(getattr(process, vfe))
86  if not hasattr(process, concentrator_name):
87  vfe_processor = getattr(process, vfe).ProcessorParameters.ProcessorName.value()
88  setattr(process, concentrator_name, self.concentrator[concentrator](process, vfe+':'+vfe_processor))
89  concentrator_task.add(getattr(process, concentrator_name))
90  if not hasattr(process, backend1_name):
91  concentrator_processor = getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value()
92  setattr(process, backend1_name, self.backend1[backend1](process, concentrator_name+':'+concentrator_processor))
93  backend1_task.add(getattr(process, backend1_name))
94  if not hasattr(process, backend2_name):
95  backend1_processor = getattr(process, backend1_name).ProcessorParameters.ProcessorName.value()
96  setattr(process, backend2_name, self.backend2[backend2](process, backend1_name+':'+backend1_processor))
97  backend2_task.add(getattr(process, backend2_name))
98  if selector!='' and not hasattr(process, selector_name):
99  backend2_processor = getattr(process, backend2_name).ProcessorParameters.ProcessorName.value()
100  setattr(process, selector_name, self.selector[selector](process, backend2_name+':'+backend2_processor))
101  selector_sequence *= getattr(process, selector_name)
102 
103  if selector=='':
104  ntuple_inputs = [
105  concentrator_name+':'+getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value(),
106  backend1_name+':'+getattr(process, backend1_name).ProcessorParameters.ProcessorName.value(),
107  backend2_name+':'+getattr(process, backend2_name).ProcessorParameters.ProcessorName.value()
108  ]
109  else:
110  ntuple_inputs = [
111  concentrator_name+':'+getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value(),
112  backend1_name+':'+getattr(process, backend1_name).ProcessorParameters.ProcessorName.value(),
113  selector_name]
114 
115  if ntuple!='' and not hasattr(process, ntuple_name):
116  setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
117  ntuple_sequence *= getattr(process, ntuple_name)
118  vfe_task.remove(tmp)
119  concentrator_task.remove(tmp)
120  backend1_task.remove(tmp)
121  backend2_task.remove(tmp)
122  selector_sequence.remove(tmpseq)
123  ntuple_sequence.remove(tmpseq)
124  process.globalReplace('hgcalVFE', vfe_task)
125  process.globalReplace('hgcalConcentrator', concentrator_task)
126  if 'HGCalBackendStage1Processor' in backend1_processor:
127  process.globalReplace('hgcalBackEndStage1', backend1_task)
128  process.globalReplace('hgcalBackEndStage2', backend2_task)
129  else:
130  process.globalReplace('hgcalBackEndLayer1', backend1_task)
131  process.globalReplace('hgcalBackEndLayer2', backend2_task)
132  process.globalReplace('hgcalTriggerSelector', selector_sequence)
133  process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
134  return process
135 
136  def create_truth_sequences(self, process):
137  if not hasattr(process, 'caloTruthCellsProducer'):
138  from L1Trigger.L1THGCalUtilities.caloTruthCellsProducer_cfi import caloTruthCellsProducer
139  process.load('L1Trigger.L1THGCalUtilities.caloTruthCells_cff')
140  process.truthCellsProd = cms.Task(caloTruthCellsProducer)
141  hgcalTriggerPrimitivesTask = cms.Task(process.hgcalVFE, process.truthCellsProd, process.hgcalBackEndLayer1, process.hgcalBackEndLayer2, process.hgcalTowerMap, process.hgcalTower)
142  process.hgcalTriggerPrimitivesTruth = cms.Sequence(hgcalTriggerPrimitivesTask)
143  if not hasattr(process, 'hgcalTriggerSelector'):
144  process.load('L1Trigger.L1THGCalUtilities.HGC3DClusterGenMatchSelector_cff')
145  tmp = cms.TaskPlaceholder("tmp")
146  tmpseq = cms.SequencePlaceholder("tmp")
147  vfe_task = cms.Task(tmp)
148  truth_prod_task = cms.Task(tmp)
149  backend1_task = cms.Task(tmp)
150  backend2_task = cms.Task(tmp)
151  selector_sequence = cms.Sequence(tmpseq)
152  ntuple_sequence = cms.Sequence(tmpseq)
153  for vfe,truth_prod,backend1,backend2,selector,ntuple in self.truth_chain:
154  truth_prod_name = '{0}{1}'.format(vfe, truth_prod)
155  backend1_name = truth_prod_name + '{0}'.format(backend1)
156  backend2_name = backend1_name + '{0}'.format(backend2)
157  selector_name = backend2_name + '{0}'.format(selector)
158  ntuple_name = selector_name + '{0}'.format(ntuple)
159  if selector=='':
160  if backend2=='':
161  if backend1=='':
162  ntuple_inputs = [
163  truth_prod_name,
164  truth_prod_name,
165  truth_prod_name
166  ]
167  else:
168  ntuple_inputs = [
169  truth_prod_name,
170  backend1_name+':HGCalBackendLayer1Processor2DClustering',
171  truth_prod_name
172  ]
173  else:
174  ntuple_inputs = [
175  truth_prod_name,
176  backend1_name+':HGCalBackendLayer1Processor2DClustering',
177  backend2_name+':HGCalBackendLayer2Processor3DClustering'
178  ]
179  else:
180  ntuple_inputs = [
181  truth_prod_name,
182  backend1_name+':HGCalBackendLayer1Processor2DClustering',
183  selector_name
184  ]
185 
186  if not hasattr(process, vfe):
187  setattr(process, vfe, self.vfe[vfe](process))
188  vfe_task.add(getattr(process, vfe))
189  if not hasattr(process, truth_prod_name):
190  setattr(process, truth_prod_name, self.truth_prod[truth_prod](process, vfe))
191  truth_prod_task.add(getattr(process, truth_prod_name))
192  if not hasattr(process, backend1_name):
193  setattr(process, backend1_name, self.backend1[backend1](process, truth_prod_name))
194  backend1_task.add(getattr(process, backend1_name))
195  if backend2!='' and not hasattr(process, backend2_name):
196  setattr(process, backend2_name, self.backend2[backend2](process, backend1_name))
197  backend2_task.add(getattr(process, backend2_name))
198  if selector!='' and not hasattr(process, selector_name):
199  setattr(process, selector_name, self.selector[selector](process, backend2_name))
200  selector_sequence *= getattr(process, selector_name)
201  if ntuple!='' and not hasattr(process, ntuple_name):
202  setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
203  ntuple_sequence *= getattr(process, ntuple_name)
204  vfe_task.remove(tmp)
205  truth_prod_task.remove(tmp)
206  backend1_task.remove(tmp)
207  backend2_task.remove(tmp)
208  selector_sequence.remove(tmpseq)
209  ntuple_sequence.remove(tmpseq)
210  process.globalReplace('hgcalVFE', vfe_task)
211  process.globalReplace('truthCellsProd', truth_prod_task)
212  process.globalReplace('hgcalBackEndLayer1', backend1_task)
213  process.globalReplace('hgcalBackEndLayer2', backend2_task)
214  process.globalReplace('hgcalTriggerSelector', selector_sequence)
215  process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
216  return process