Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:39

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 class HGCalTriggerChains:
0004     def __init__(self):
0005         self.vfe = {}
0006         self.concentrator = {}
0007         self.truth_prod = {}
0008         self.backend1 = {}
0009         self.backend2 = {}
0010         self.selector = {}
0011         self.ntuple = {}
0012         self.chain = []
0013         self.truth_chain = []
0014 
0015     def register_vfe(self, name, generator):
0016         self.vfe[name] = generator
0017 
0018     def register_concentrator(self, name, generator):
0019         self.concentrator[name] = generator
0020 
0021     def register_truth_prod(self, name, generator): # for truth-matched trigger cells
0022         self.truth_prod[name] = generator
0023 
0024     def register_backend1(self, name, generator):
0025         self.backend1[name] = generator
0026 
0027     def register_backend2(self, name, generator):
0028         self.backend2[name] = generator
0029 
0030     def register_selector(self, name, generator):
0031         self.selector[name] = generator
0032 
0033     def register_ntuple(self, name, generator):
0034         self.ntuple[name] = generator
0035 
0036     def register_chain(self, vfe, concentrator, backend1, backend2, selector='', ntuple=''):
0037         if not vfe in self.vfe:
0038             raise KeyError('{} not registered as VFE producer'.format(vfe))
0039         if not concentrator in self.concentrator:
0040             raise KeyError('{} not registered as concentrator producer'.format(concentrator))
0041         if not backend1 in self.backend1:
0042             raise KeyError('{} not registered as backend1 producer'.format(backend1))
0043         if not backend2 in self.backend2:
0044             raise KeyError('{} not registered as backend2 producer'.format(backend2))
0045         if selector!='' and not selector in self.selector:
0046             raise KeyError('{} not registered as selector'.format(selector))
0047         if ntuple!='' and not ntuple in self.ntuple:
0048             raise KeyError('{} not registered as ntuplizer'.format(ntuple))
0049         self.chain.append( (vfe, concentrator, backend1, backend2, selector, ntuple) )
0050 
0051     def register_truth_chain(self, vfe, truth_prod, backend1='', backend2='', selector='', ntuple=''):
0052         if not vfe in self.vfe:
0053             raise KeyError('{} not registered as VFE producer'.format(vfe))
0054         if not truth_prod in self.truth_prod:
0055             raise KeyError('{} not registered as truth producer'.format(truth_prod))
0056         if backend1!='' and not backend1 in self.backend1:
0057             raise KeyError('{} not registered as backend1 producer'.format(backend1))
0058         if backend2!='' and not backend2 in self.backend2:
0059             raise KeyError('{} not registered as backend2 producer'.format(backend2))
0060         if selector!='' and not selector in self.selector:
0061             raise KeyError('{} not registered as selector'.format(selector))
0062         if ntuple!='' and not ntuple in self.ntuple:
0063             raise KeyError('{} not registered as ntuplizer'.format(ntuple))
0064         self.truth_chain.append( (vfe, truth_prod, backend1, backend2, selector, ntuple) )
0065 
0066     def create_sequences(self, process):
0067         if not hasattr(process, 'hgcalTriggerSelector'):
0068             process.load('L1Trigger.L1THGCalUtilities.HGC3DClusterGenMatchSelector_cff')
0069         tmp = cms.TaskPlaceholder("tmp")
0070         tmpseq = cms.SequencePlaceholder("tmp")
0071         vfe_task = cms.Task(tmp)
0072         concentrator_task = cms.Task(tmp)
0073         backend1_task = cms.Task(tmp)
0074         backend2_task = cms.Task(tmp)
0075         selector_sequence = cms.Sequence(tmpseq)
0076         ntuple_sequence = cms.Sequence(tmpseq)
0077         for vfe,concentrator,backend1,backend2,selector,ntuple in self.chain:
0078             concentrator_name = '{0}{1}'.format(vfe, concentrator)
0079             backend1_name = '{0}{1}{2}'.format(vfe, concentrator, backend1)
0080             backend2_name = '{0}{1}{2}{3}'.format(vfe, concentrator, backend1, backend2)
0081             selector_name = '{0}{1}{2}{3}{4}'.format(vfe, concentrator, backend1, backend2, selector)
0082             ntuple_name = '{0}{1}{2}{3}{4}{5}'.format(vfe, concentrator, backend1, backend2, selector, ntuple)
0083             if not hasattr(process, vfe):
0084                 setattr(process, vfe, self.vfe[vfe](process))
0085                 vfe_task.add(getattr(process, vfe))
0086             if not hasattr(process, concentrator_name):
0087                 vfe_processor = getattr(process, vfe).ProcessorParameters.ProcessorName.value()
0088                 setattr(process, concentrator_name, self.concentrator[concentrator](process, vfe+':'+vfe_processor))
0089                 concentrator_task.add(getattr(process, concentrator_name))
0090             if not hasattr(process, backend1_name):
0091                 concentrator_processor = getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value()
0092                 setattr(process, backend1_name, self.backend1[backend1](process, concentrator_name+':'+concentrator_processor))
0093                 backend1_task.add(getattr(process, backend1_name))
0094             if not hasattr(process, backend2_name):
0095                 backend1_processor = getattr(process, backend1_name).ProcessorParameters.ProcessorName.value()
0096                 setattr(process, backend2_name, self.backend2[backend2](process, backend1_name+':'+backend1_processor))
0097                 backend2_task.add(getattr(process, backend2_name))
0098             if selector!='' and not hasattr(process, selector_name):
0099                 backend2_processor = getattr(process, backend2_name).ProcessorParameters.ProcessorName.value()
0100                 setattr(process, selector_name, self.selector[selector](process, backend2_name+':'+backend2_processor))
0101                 selector_sequence *= getattr(process, selector_name)
0102 
0103             if selector=='':
0104                 ntuple_inputs = [
0105                         concentrator_name+':'+getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value(),
0106                         backend1_name+':'+getattr(process, backend1_name).ProcessorParameters.ProcessorName.value(),
0107                         backend2_name+':'+getattr(process, backend2_name).ProcessorParameters.ProcessorName.value()
0108                         ]
0109             else:
0110                 ntuple_inputs = [
0111                         concentrator_name+':'+getattr(process, concentrator_name).ProcessorParameters.ProcessorName.value(),
0112                         backend1_name+':'+getattr(process, backend1_name).ProcessorParameters.ProcessorName.value(),
0113                         selector_name]
0114 
0115             if ntuple!='' and not hasattr(process, ntuple_name):
0116                 setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
0117                 ntuple_sequence *= getattr(process, ntuple_name)
0118         vfe_task.remove(tmp)
0119         concentrator_task.remove(tmp)
0120         backend1_task.remove(tmp)
0121         backend2_task.remove(tmp)
0122         selector_sequence.remove(tmpseq)
0123         ntuple_sequence.remove(tmpseq)
0124         process.globalReplace('hgcalVFE', vfe_task)
0125         process.globalReplace('hgcalConcentrator', concentrator_task)
0126         if 'HGCalBackendStage1Processor' in backend1_processor:
0127             process.globalReplace('hgcalBackEndStage1', backend1_task)
0128             process.globalReplace('hgcalBackEndStage2', backend2_task)
0129         else:
0130             process.globalReplace('hgcalBackEndLayer1', backend1_task)
0131             process.globalReplace('hgcalBackEndLayer2', backend2_task)
0132         process.globalReplace('hgcalTriggerSelector', selector_sequence)
0133         process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
0134         return process
0135 
0136     def create_truth_sequences(self, process):
0137         if not hasattr(process, 'caloTruthCellsProducer'):
0138             from L1Trigger.L1THGCalUtilities.caloTruthCellsProducer_cfi import caloTruthCellsProducer
0139             process.load('L1Trigger.L1THGCalUtilities.caloTruthCells_cff')
0140             process.truthCellsProd = cms.Task(caloTruthCellsProducer)
0141             hgcalTriggerPrimitivesTask = cms.Task(process.hgcalVFE, process.truthCellsProd, process.hgcalBackEndLayer1, process.hgcalBackEndLayer2, process.hgcalTowerMap, process.hgcalTower)
0142             process.hgcalTriggerPrimitivesTruth = cms.Sequence(hgcalTriggerPrimitivesTask)
0143         if not hasattr(process, 'hgcalTriggerSelector'):
0144             process.load('L1Trigger.L1THGCalUtilities.HGC3DClusterGenMatchSelector_cff')
0145         tmp = cms.TaskPlaceholder("tmp")
0146         tmpseq = cms.SequencePlaceholder("tmp")
0147         vfe_task = cms.Task(tmp)
0148         truth_prod_task = cms.Task(tmp)
0149         backend1_task = cms.Task(tmp)
0150         backend2_task = cms.Task(tmp)
0151         selector_sequence = cms.Sequence(tmpseq)
0152         ntuple_sequence = cms.Sequence(tmpseq)
0153         for vfe,truth_prod,backend1,backend2,selector,ntuple in self.truth_chain:
0154             truth_prod_name = '{0}{1}'.format(vfe, truth_prod)
0155             backend1_name = truth_prod_name + '{0}'.format(backend1)
0156             backend2_name = backend1_name + '{0}'.format(backend2)
0157             selector_name = backend2_name + '{0}'.format(selector)
0158             ntuple_name = selector_name + '{0}'.format(ntuple)
0159             if selector=='':
0160                 if backend2=='':
0161                     if backend1=='':
0162                         ntuple_inputs = [
0163                                 truth_prod_name,
0164                                 truth_prod_name,
0165                                 truth_prod_name
0166                                 ]
0167                     else:
0168                         ntuple_inputs = [
0169                                 truth_prod_name,
0170                                 backend1_name+':HGCalBackendLayer1Processor2DClustering',
0171                                 truth_prod_name
0172                                 ]
0173                 else:
0174                     ntuple_inputs = [
0175                             truth_prod_name,
0176                             backend1_name+':HGCalBackendLayer1Processor2DClustering',
0177                             backend2_name+':HGCalBackendLayer2Processor3DClustering'
0178                             ]
0179             else:
0180                 ntuple_inputs = [
0181                         truth_prod_name,
0182                         backend1_name+':HGCalBackendLayer1Processor2DClustering',
0183                         selector_name
0184                         ]
0185 
0186             if not hasattr(process, vfe):
0187                 setattr(process, vfe, self.vfe[vfe](process))
0188                 vfe_task.add(getattr(process, vfe))
0189             if not hasattr(process, truth_prod_name):
0190                 setattr(process, truth_prod_name, self.truth_prod[truth_prod](process, vfe))
0191                 truth_prod_task.add(getattr(process, truth_prod_name))
0192             if not hasattr(process, backend1_name):
0193                 setattr(process, backend1_name, self.backend1[backend1](process, truth_prod_name))
0194                 backend1_task.add(getattr(process, backend1_name))
0195             if backend2!='' and not hasattr(process, backend2_name):
0196                 setattr(process, backend2_name, self.backend2[backend2](process, backend1_name))
0197                 backend2_task.add(getattr(process, backend2_name))
0198             if selector!='' and not hasattr(process, selector_name):
0199                 setattr(process, selector_name, self.selector[selector](process, backend2_name))
0200                 selector_sequence *= getattr(process, selector_name)
0201             if ntuple!='' and not hasattr(process, ntuple_name):
0202                 setattr(process, ntuple_name, self.ntuple[ntuple](process, ntuple_inputs))
0203                 ntuple_sequence *= getattr(process, ntuple_name)
0204         vfe_task.remove(tmp)
0205         truth_prod_task.remove(tmp)
0206         backend1_task.remove(tmp)
0207         backend2_task.remove(tmp)
0208         selector_sequence.remove(tmpseq)
0209         ntuple_sequence.remove(tmpseq)
0210         process.globalReplace('hgcalVFE', vfe_task)
0211         process.globalReplace('truthCellsProd', truth_prod_task)
0212         process.globalReplace('hgcalBackEndLayer1', backend1_task)
0213         process.globalReplace('hgcalBackEndLayer2', backend2_task)
0214         process.globalReplace('hgcalTriggerSelector', selector_sequence)
0215         process.globalReplace('hgcalTriggerNtuples', ntuple_sequence)
0216         return process