Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-12 23:01:44

0001 import FWCore.ParameterSet.Config as cms
0002 import re
0003 import itertools
0004 
0005 from FWCore.ParameterSet.MassReplace import massReplaceInputTag
0006 from HeterogeneousCore.AlpakaCore.functions import *
0007 from HLTrigger.Configuration.common import *
0008 
0009 ## PF HLT in Alpaka
0010 def customizeHLTforAlpakaParticleFlowClustering(process):
0011     '''Customization to introduce Particle Flow Reconstruction in Alpaka
0012     '''
0013     ## failsafe for fake menus
0014     if not hasattr(process, 'hltParticleFlowClusterHBHE'):
0015         return process
0016 
0017     for prod in producers_by_type(process, 'HCALRecHitSoAProducer@alpaka'):
0018         return process
0019 
0020     process.hltESSPFRecHitHCALParamsRecord = cms.ESSource('EmptyESSource',
0021         recordName = cms.string('PFRecHitHCALParamsRecord'),
0022         iovIsRunNotTime = cms.bool(True),
0023         firstValid = cms.vuint32(1)
0024     )
0025 
0026     process.hltESSPFRecHitHCALTopologyRecord = cms.ESSource('EmptyESSource',
0027         recordName = cms.string('PFRecHitHCALTopologyRecord'),
0028         iovIsRunNotTime = cms.bool(True),
0029         firstValid = cms.vuint32(1)
0030     )
0031 
0032     process.hltESSJobConfigurationGPURecord = cms.ESSource('EmptyESSource',
0033         recordName = cms.string('JobConfigurationGPURecord'),
0034         iovIsRunNotTime = cms.bool(True),
0035         firstValid = cms.vuint32(1)
0036     )
0037 
0038     process.hltHbheRecHitSoA = cms.EDProducer("HCALRecHitSoAProducer@alpaka",
0039         src = cms.InputTag("hltHbhereco"),
0040         synchronise = cms.untracked.bool(False),
0041         # autoselect the alpaka backend
0042         alpaka = cms.untracked.PSet(
0043             backend = cms.untracked.string('')
0044         )
0045     )
0046 
0047     process.hltESPPFRecHitHCALTopology = cms.ESProducer('PFRecHitHCALTopologyESProducer@alpaka',
0048         usePFThresholdsFromDB = cms.bool(True),
0049         appendToDataLabel = cms.string(''),
0050         # autoselect the alpaka backend
0051         alpaka = cms.untracked.PSet(
0052             backend = cms.untracked.string('')
0053         )
0054     )
0055 
0056     process.hltESPPFRecHitHCALParams = cms.ESProducer('PFRecHitHCALParamsESProducer@alpaka',
0057         energyThresholdsHB = cms.vdouble(0.1, 0.2, 0.3, 0.3),
0058         energyThresholdsHE = cms.vdouble(0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2),
0059         appendToDataLabel = cms.string(''),
0060         # autoselect the alpaka backend
0061         alpaka = cms.untracked.PSet(
0062             backend = cms.untracked.string('')
0063         )
0064     )
0065 
0066     process.hltParticleFlowRecHitHBHESoA = cms.EDProducer("PFRecHitSoAProducerHCAL@alpaka",
0067         producers = cms.VPSet(
0068             cms.PSet(
0069                 src = cms.InputTag("hltHbheRecHitSoA"),
0070                 params = cms.ESInputTag("hltESPPFRecHitHCALParams:"),
0071             )
0072         ),
0073         topology = cms.ESInputTag("hltESPPFRecHitHCALTopology:"),
0074         synchronise = cms.untracked.bool(False),
0075         # autoselect the alpaka backend
0076         alpaka = cms.untracked.PSet(
0077             backend = cms.untracked.string('')
0078         )
0079     )
0080 
0081     process.hltParticleFlowRecHitHBHE = cms.EDProducer("LegacyPFRecHitProducer",
0082         src = cms.InputTag("hltParticleFlowRecHitHBHESoA")
0083     )
0084 
0085     process.hltESPPFClusterParams = cms.ESProducer("PFClusterParamsESProducer@alpaka",
0086         seedFinder = cms.PSet(
0087             nNeighbours = cms.int32(4),
0088             thresholdsByDetector = cms.VPSet(
0089                 cms.PSet(
0090                     detector = cms.string('HCAL_BARREL1'),
0091                     seedingThreshold = cms.vdouble(0.125, 0.25, 0.35, 0.35),
0092                     seedingThresholdPt = cms.double(0)
0093                 ),
0094                 cms.PSet(
0095                     detector = cms.string('HCAL_ENDCAP'),
0096                     seedingThreshold = cms.vdouble(0.1375, 0.275, 0.275, 0.275, 0.275, 0.275, 0.275),
0097                     seedingThresholdPt = cms.double(0)
0098                 )
0099             )
0100         ),
0101         initialClusteringStep = cms.PSet(
0102             thresholdsByDetector = cms.VPSet(
0103                 cms.PSet(
0104                     detector = cms.string('HCAL_BARREL1'),
0105                     gatheringThreshold = cms.vdouble(0.1, 0.2, 0.3, 0.3)
0106                 ),
0107                 cms.PSet(
0108                     detector = cms.string('HCAL_ENDCAP'),
0109                     gatheringThreshold = cms.vdouble(0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2)
0110                 )
0111             )
0112         ),
0113         pfClusterBuilder = cms.PSet(
0114             maxIterations = cms.uint32(5),
0115             minFracTot = cms.double(1e-20),
0116             minFractionToKeep = cms.double(1e-07),
0117             excludeOtherSeeds = cms.bool(True),
0118             showerSigma = cms.double(10),
0119             stoppingTolerance = cms.double(1e-08),
0120             recHitEnergyNorms = cms.VPSet(
0121                 cms.PSet(
0122                     detector = cms.string('HCAL_BARREL1'),
0123                     recHitEnergyNorm = cms.vdouble(0.1, 0.2, 0.3, 0.3)
0124                 ),
0125                 cms.PSet(
0126                     detector = cms.string('HCAL_ENDCAP'),
0127                     recHitEnergyNorm = cms.vdouble(0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2)
0128                 )
0129             ),
0130             positionCalc = cms.PSet(
0131                 minFractionInCalc = cms.double(1e-09),
0132                 minAllowedNormalization = cms.double(1e-09)
0133             ),
0134             timeResolutionCalcBarrel = cms.PSet(
0135                 corrTermLowE = cms.double(0),
0136                 threshLowE = cms.double(6),
0137                 noiseTerm = cms.double(21.86),
0138                 constantTermLowE = cms.double(4.24),
0139                 noiseTermLowE = cms.double(8),
0140                 threshHighE = cms.double(15),
0141                 constantTerm = cms.double(2.82)
0142             ),
0143             timeResolutionCalcEndcap = cms.PSet(
0144                 corrTermLowE = cms.double(0),
0145                 threshLowE = cms.double(6),
0146                 noiseTerm = cms.double(21.86),
0147                 constantTermLowE = cms.double(4.24),
0148                 noiseTermLowE = cms.double(8),
0149                 threshHighE = cms.double(15),
0150                 constantTerm = cms.double(2.82)
0151             )
0152         ),
0153         # autoselect the alpaka backend
0154         alpaka = cms.untracked.PSet(
0155             backend = cms.untracked.string('')
0156         )
0157     )
0158 
0159     process.hltParticleFlowClusterHBHESoA = cms.EDProducer("PFClusterSoAProducer@alpaka",
0160         pfRecHits = cms.InputTag("hltParticleFlowRecHitHBHESoA"),
0161         topology = cms.ESInputTag("hltESPPFRecHitHCALTopology:"),
0162         pfClusterParams = cms.ESInputTag("hltESPPFClusterParams:"),
0163         synchronise = cms.bool(False),
0164         # autoselect the alpaka backend
0165         alpaka = cms.untracked.PSet(
0166             backend = cms.untracked.string('')
0167         )
0168     )
0169 
0170     process.hltParticleFlowClusterHBHE = cms.EDProducer("LegacyPFClusterProducer",
0171         src = cms.InputTag("hltParticleFlowClusterHBHESoA"),
0172         pfClusterBuilder = process.hltParticleFlowClusterHBHE.pfClusterBuilder,
0173         usePFThresholdsFromDB = cms.bool(True),
0174         recHitsSource = cms.InputTag("hltParticleFlowRecHitHBHE"),
0175         PFRecHitsLabelIn = cms.InputTag("hltParticleFlowRecHitHBHESoA")
0176     )
0177 
0178     process.HLTPFHcalClustering = cms.Sequence(
0179         process.hltHbheRecHitSoA +
0180         process.hltParticleFlowRecHitHBHESoA +
0181         process.hltParticleFlowRecHitHBHE +
0182         process.hltParticleFlowClusterHBHESoA +
0183         process.hltParticleFlowClusterHBHE +
0184         process.hltParticleFlowClusterHCAL
0185     )
0186 
0187     # Some Sequences contain all the modules of process.HLTPFHcalClustering Sequence instead of the Sequence itself
0188     # find these Sequences and replace all the modules with the Sequence
0189     def replaceItemsInSequence(process, seqNames, itemsToReplace, replacingSequence):
0190         for seqName in seqNames:
0191             if not hasattr(process, seqName):
0192                 continue
0193             seq = getattr(process, seqName)
0194             for item in itemsToReplace:
0195                 # remove items that will be replaced by replacingSequence
0196                 if (item != itemsToReplace[-1]):
0197                     seq.remove(item)
0198                 else:
0199                     # if last item, replace it with the Sequence
0200                     seq.replace(item, replacingSequence)
0201         return process
0202 
0203     process = replaceItemsInSequence(
0204         process, [
0205             'HLTParticleFlowSequence',
0206             'HLTParticleFlowSequenceForTaus',
0207             'HLTParticleFlowSequenceForDisplTaus',
0208             'HLTParticleFlowSequencePPOnAA',
0209             'HLTPixelOnlyParticleFlowSequence',
0210         ], [
0211             process.hltParticleFlowRecHitHBHE,
0212             process.hltParticleFlowClusterHBHE,
0213             process.hltParticleFlowClusterHCAL
0214         ],
0215         process.HLTPFHcalClustering
0216     )
0217 
0218     process.hltHbheRecHitSoACPUSerial = makeSerialClone(process.hltHbheRecHitSoA)
0219 
0220     process.hltParticleFlowRecHitHBHESoACPUSerial = makeSerialClone(process.hltParticleFlowRecHitHBHESoA)
0221     process.hltParticleFlowRecHitHBHESoACPUSerial.producers[0].src = 'hltHbheRecHitSoACPUSerial'
0222 
0223     process.hltParticleFlowRecHitHBHECPUOnly = process.hltParticleFlowRecHitHBHE.clone(
0224         src = 'hltParticleFlowRecHitHBHESoACPUSerial',
0225     )
0226 
0227     process.hltParticleFlowClusterHBHESoACPUSerial = makeSerialClone(process.hltParticleFlowClusterHBHESoA,
0228         pfRecHits = 'hltParticleFlowRecHitHBHESoACPUSerial',
0229     )
0230 
0231     process.hltParticleFlowClusterHBHECPUOnly = process.hltParticleFlowClusterHBHE.clone(
0232         src = 'hltParticleFlowClusterHBHESoACPUSerial',
0233         recHitsSource = 'hltParticleFlowRecHitHBHECPUOnly',
0234         PFRecHitsLabelIn = 'hltParticleFlowRecHitHBHESoACPUSerial',
0235     )
0236 
0237     process.HLTPFHcalClusteringCPUOnly = cms.Sequence(
0238         process.hltHbheRecHitSoACPUSerial +
0239         process.hltParticleFlowRecHitHBHESoACPUSerial +
0240         process.hltParticleFlowRecHitHBHECPUOnly +
0241         process.hltParticleFlowClusterHBHESoACPUSerial +
0242         process.hltParticleFlowClusterHBHECPUOnly +
0243         process.hltParticleFlowClusterHCALCPUOnly
0244     )
0245 
0246     process = replaceItemsInSequence(process, ['HLTParticleFlowCPUOnlySequence'],
0247         [process.hltParticleFlowRecHitHBHECPUOnly, process.hltParticleFlowClusterHBHECPUOnly, process.hltParticleFlowClusterHCALCPUOnly],
0248         process.HLTPFHcalClusteringCPUOnly)
0249 
0250     # modify EventContent of *DQMGPUvsCPU streams
0251     for hltOutModMatch in ['hltOutputDQMGPUvsCPU', 'hltOutputHIDQMGPUvsCPU']:
0252         if hasattr(process, hltOutModMatch):
0253             outMod = getattr(process, hltOutModMatch)
0254             outMod.outputCommands.extend([
0255                 'keep *_hltParticleFlowClusterHBHESoA_*_*',
0256                 'keep *_hltParticleFlowClusterHBHESoACPUSerial_*_*',
0257             ])
0258 
0259     # Add PF sequences to DQM_*HcalReconstruction_v Path
0260     for pathNameMatch in ['DQM_HcalReconstruction_v', 'DQM_HIHcalReconstruction_v']:
0261         dqmHcalRecoPathName = None
0262         for pathName in process.paths_():
0263             if pathName.startswith(pathNameMatch):
0264                 dqmHcalRecoPathName = pathName
0265                 break
0266         if dqmHcalRecoPathName == None:
0267             continue
0268         dqmHcalPath = getattr(process, dqmHcalRecoPathName)
0269         dqmHcalRecoPathIndex = dqmHcalPath.index(process.hltHcalConsumerGPU) + 1
0270         dqmHcalPath.insert(dqmHcalRecoPathIndex, process.HLTPFHcalClusteringCPUOnly)
0271         dqmHcalPath.insert(dqmHcalRecoPathIndex, process.HLTPFHcalClustering)
0272 
0273     return process
0274 
0275 
0276 ## Pixel HLT in Alpaka
0277 def customizeHLTforDQMGPUvsCPUPixel(process):
0278     '''Ad-hoc changes to test HLT config containing only DQM_PixelReconstruction_v and DQMGPUvsCPU stream
0279        only up to the Pixel Local Reconstruction
0280     '''
0281     dqmPixelRecoPathName = None
0282     for pathName in process.paths_():
0283         if pathName.startswith('DQM_PixelReconstruction_v'):
0284             dqmPixelRecoPathName = pathName
0285             break
0286 
0287     if dqmPixelRecoPathName == None:
0288         return process
0289 
0290     for prod in producers_by_type(process, 'SiPixelPhase1MonitorRecHitsSoAAlpaka'):
0291         return process
0292 
0293     # modify EventContent of DQMGPUvsCPU stream
0294     try:
0295         outCmds_new = [foo for foo in process.hltOutputDQMGPUvsCPU.outputCommands if 'Pixel' not in foo]
0296         outCmds_new += [
0297             'keep *Cluster*_hltSiPixelClusters_*_*',
0298             'keep *Cluster*_hltSiPixelClustersSerialSync_*_*',
0299             'keep *_hltSiPixelDigiErrors_*_*',
0300             'keep *_hltSiPixelDigiErrorsSerialSync_*_*',
0301             'keep *RecHit*_hltSiPixelRecHits_*_*',
0302             'keep *RecHit*_hltSiPixelRecHitsSerialSync_*_*',
0303             'keep *_hltPixelTracks_*_*',
0304             'keep *_hltPixelTracksSerialSync_*_*',
0305             'keep *_hltPixelVertices_*_*',
0306             'keep *_hltPixelVerticesSerialSync_*_*',
0307         ]
0308         process.hltOutputDQMGPUvsCPU.outputCommands = outCmds_new[:]
0309     except:
0310         pass
0311 
0312     # PixelRecHits: monitor of SerialSync product (Alpaka backend: 'serial_sync')
0313     process.hltPixelRecHitsSoAMonitorCPU = cms.EDProducer('SiPixelPhase1MonitorRecHitsSoAAlpaka',
0314         pixelHitsSrc = cms.InputTag('hltSiPixelRecHitsSoASerialSync'),
0315         TopFolderName = cms.string('SiPixelHeterogeneous/PixelRecHitsCPU')
0316     )
0317 
0318     # PixelRecHits: monitor of GPU product (Alpaka backend: '')
0319     process.hltPixelRecHitsSoAMonitorGPU = cms.EDProducer('SiPixelPhase1MonitorRecHitsSoAAlpaka',
0320         pixelHitsSrc = cms.InputTag('hltSiPixelRecHitsSoA'),
0321         TopFolderName = cms.string('SiPixelHeterogeneous/PixelRecHitsGPU')
0322     )
0323 
0324     # PixelRecHits: 'GPUvsCPU' comparisons
0325     process.hltPixelRecHitsSoACompareGPUvsCPU = cms.EDProducer('SiPixelPhase1CompareRecHitsSoAAlpaka',
0326         pixelHitsSrcHost = cms.InputTag('hltSiPixelRecHitsSoASerialSync'),
0327         pixelHitsSrcDevice = cms.InputTag('hltSiPixelRecHitsSoA'),
0328         topFolderName = cms.string('SiPixelHeterogeneous/PixelRecHitsCompareGPUvsCPU'),
0329         minD2cut = cms.double(1.0e-4)
0330     )
0331 
0332     process.hltPixelTracksSoAMonitorCPU = cms.EDProducer("SiPixelPhase1MonitorTrackSoAAlpaka",
0333         minQuality = cms.string('loose'),
0334         pixelTrackSrc = cms.InputTag('hltPixelTracksSoASerialSync'),
0335         topFolderName = cms.string('SiPixelHeterogeneous/PixelTrackCPU'),
0336         useQualityCut = cms.bool(True)
0337     )
0338 
0339     process.hltPixelTracksSoAMonitorGPU = cms.EDProducer("SiPixelPhase1MonitorTrackSoAAlpaka",
0340         minQuality = cms.string('loose'),
0341         pixelTrackSrc = cms.InputTag('hltPixelTracksSoA'),
0342         topFolderName = cms.string('SiPixelHeterogeneous/PixelTrackGPU'),
0343         useQualityCut = cms.bool(True)
0344     )
0345 
0346     process.hltPixelTracksSoACompareGPUvsCPU = cms.EDProducer("SiPixelPhase1CompareTrackSoAAlpaka",
0347         deltaR2cut = cms.double(0.04),
0348         minQuality = cms.string('loose'),
0349         pixelTrackSrcHost = cms.InputTag("hltPixelTracksSoASerialSync"),
0350         pixelTrackSrcDevice = cms.InputTag("hltPixelTracksSoA"),
0351         topFolderName = cms.string('SiPixelHeterogeneous/PixelTrackCompareGPUvsCPU'),
0352         useQualityCut = cms.bool(True)
0353     )
0354 
0355     process.hltPixelVertexSoAMonitorCPU = cms.EDProducer("SiPixelMonitorVertexSoAAlpaka",
0356         beamSpotSrc = cms.InputTag("hltOnlineBeamSpot"),
0357         pixelVertexSrc = cms.InputTag("hltPixelVerticesSoASerialSync"),
0358         topFolderName = cms.string('SiPixelHeterogeneous/PixelVertexCPU')
0359     )
0360 
0361     process.hltPixelVertexSoAMonitorGPU = cms.EDProducer("SiPixelMonitorVertexSoAAlpaka",
0362         beamSpotSrc = cms.InputTag("hltOnlineBeamSpot"),
0363         pixelVertexSrc = cms.InputTag("hltPixelVerticesSoA"),
0364         topFolderName = cms.string('SiPixelHeterogeneous/PixelVertexGPU')
0365     )
0366 
0367     process.hltPixelVertexSoACompareGPUvsCPU = cms.EDProducer("SiPixelCompareVertexSoAAlpaka",
0368         beamSpotSrc = cms.InputTag("hltOnlineBeamSpot"),
0369         dzCut = cms.double(1),
0370         pixelVertexSrcHost = cms.InputTag("hltPixelVerticesSoASerialSync"),
0371         pixelVertexSrcDevice = cms.InputTag("hltPixelVerticesSoA"),
0372         topFolderName = cms.string('SiPixelHeterogeneous/PixelVertexCompareGPUvsCPU')
0373     )
0374 
0375     process.HLTDQMPixelReconstruction = cms.Sequence(
0376         process.hltPixelRecHitsSoAMonitorCPU
0377       + process.hltPixelRecHitsSoAMonitorGPU
0378       + process.hltPixelRecHitsSoACompareGPUvsCPU
0379       + process.hltPixelTracksSoAMonitorCPU
0380       + process.hltPixelTracksSoAMonitorGPU
0381       + process.hltPixelTracksSoACompareGPUvsCPU
0382       + process.hltPixelVertexSoAMonitorCPU
0383       + process.hltPixelVertexSoAMonitorGPU
0384       + process.hltPixelVertexSoACompareGPUvsCPU
0385     )
0386 
0387     for delMod in ['hltPixelConsumerCPU', 'hltPixelConsumerGPU']:
0388         if hasattr(process, delMod):
0389             process.__delattr__(delMod)
0390 
0391     return process
0392 
0393 
0394 def customizeHLTforAlpakaPixelRecoLocal(process):
0395     '''Customisation to introduce the Local Pixel Reconstruction in Alpaka
0396     '''
0397 
0398     if not hasattr(process, 'HLTDoLocalPixelSequence'):
0399         return process
0400 
0401     for prod in producers_by_type(process, 'SiPixelRawToClusterPhase1@alpaka'):
0402         return process
0403 
0404     process.hltESPSiPixelCablingSoA = cms.ESProducer('SiPixelCablingSoAESProducer@alpaka',
0405         CablingMapLabel = cms.string(''),
0406         UseQualityInfo = cms.bool(False),
0407         appendToDataLabel = cms.string(''),
0408         alpaka = cms.untracked.PSet(
0409             backend = cms.untracked.string('')
0410         )
0411     )
0412 
0413     process.hltESPSiPixelGainCalibrationForHLTSoA = cms.ESProducer('SiPixelGainCalibrationForHLTSoAESProducer@alpaka',
0414         appendToDataLabel = cms.string(''),
0415         alpaka = cms.untracked.PSet(
0416             backend = cms.untracked.string('')
0417         )
0418     )
0419 
0420     process.hltESPPixelCPEFastParamsPhase1 = cms.ESProducer('PixelCPEFastParamsESProducerAlpakaPhase1@alpaka',
0421         appendToDataLabel = cms.string(''),
0422         alpaka = cms.untracked.PSet(
0423             backend = cms.untracked.string('')
0424         )
0425     )
0426 
0427     if hasattr(process, 'hltESPPixelCPEFast'):
0428         del process.hltESPPixelCPEFast
0429 
0430     # alpaka EDProducer
0431     # consumes
0432     #  - reco::BeamSpot
0433     # produces
0434     #  - BeamSpotDevice
0435     process.hltOnlineBeamSpotDevice = cms.EDProducer('BeamSpotDeviceProducer@alpaka',
0436         src = cms.InputTag('hltOnlineBeamSpot'),
0437         alpaka = cms.untracked.PSet(
0438             backend = cms.untracked.string('')
0439         )
0440     )
0441 
0442     if hasattr(process, 'hltOnlineBeamSpotToGPU'):
0443         # hltOnlineBeamSpotToGPU is currently still used in HIon menu,
0444         # remove it only if the relevant ConditionalTask of the HIon menu is not present
0445         # (this check mainly applies to the HLT combined table)
0446         if not (hasattr(process, 'HLTDoLocalPixelPPOnAATask') and process.HLTDoLocalPixelPPOnAATask.contains(process.hltOnlineBeamSpotToGPU)):
0447             del process.hltOnlineBeamSpotToGPU
0448 
0449     # alpaka EDProducer
0450     # consumes
0451     #  - FEDRawDataCollection
0452     # produces (* optional)
0453     #  - SiPixelClustersSoA
0454     #  - SiPixelDigisSoACollection
0455     #  - SiPixelDigiErrorsSoACollection *
0456     #  - SiPixelFormatterErrors *
0457     process.hltSiPixelClustersSoA = cms.EDProducer('SiPixelRawToClusterPhase1@alpaka',
0458         IncludeErrors = cms.bool(True),
0459         UseQualityInfo = cms.bool(False),
0460         clusterThreshold_layer1 = cms.int32(4000),
0461         clusterThreshold_otherLayers = cms.int32(4000),
0462         VCaltoElectronGain      = cms.double(1),  # all gains=1, pedestals=0
0463         VCaltoElectronGain_L1   = cms.double(1),
0464         VCaltoElectronOffset    = cms.double(0),
0465         VCaltoElectronOffset_L1 = cms.double(0),
0466         InputLabel = cms.InputTag('rawDataCollector'),
0467         Regions = cms.PSet(),
0468         CablingMapLabel = cms.string(''),
0469         # autoselect the alpaka backend
0470         alpaka = cms.untracked.PSet(
0471             backend = cms.untracked.string('')
0472         )
0473     )
0474 
0475     if hasattr(process, 'hltSiPixelClustersGPU'):
0476         del process.hltSiPixelClustersGPU
0477 
0478     process.hltSiPixelClusters = cms.EDProducer('SiPixelDigisClustersFromSoAAlpakaPhase1',
0479         src = cms.InputTag('hltSiPixelClustersSoA'),
0480         clusterThreshold_layer1 = cms.int32(4000),
0481         clusterThreshold_otherLayers = cms.int32(4000),
0482         produceDigis = cms.bool(False),
0483         storeDigis = cms.bool(False)
0484     )
0485 
0486     # used only in the PPRef menu for the legacy pixel track reconstruction
0487     process.hltSiPixelClustersCache = cms.EDProducer('SiPixelClusterShapeCacheProducer',
0488         src = cms.InputTag('hltSiPixelClusters'),
0489         onDemand = cms.bool(False)
0490     )
0491 
0492     # legacy EDProducer
0493     # consumes
0494     #  - SiPixelDigiErrorsHost
0495     #  - SiPixelFormatterErrors
0496     # produces
0497     #  - edm::DetSetVector<SiPixelRawDataError>
0498     #  - DetIdCollection
0499     #  - DetIdCollection, 'UserErrorModules'
0500     #  - edmNew::DetSetVector<PixelFEDChannel>
0501     process.hltSiPixelDigiErrors = cms.EDProducer('SiPixelDigiErrorsFromSoAAlpaka',
0502         digiErrorSoASrc = cms.InputTag('hltSiPixelClustersSoA'),
0503         fmtErrorsSoASrc = cms.InputTag('hltSiPixelClustersSoA'),
0504         CablingMapLabel = cms.string(''),
0505         UsePhase1 = cms.bool(True),
0506         ErrorList = cms.vint32(29),
0507         UserErrorList = cms.vint32(40)
0508     )
0509 
0510     if hasattr(process, 'hltSiPixelDigisSoA'):
0511         del process.hltSiPixelDigisSoA
0512     if hasattr(process, 'hltSiPixelDigiErrorsSoA'):
0513         del process.hltSiPixelDigiErrorsSoA
0514 
0515     # alpaka EDProducer
0516     # consumes
0517     #  - BeamSpotDevice
0518     #  - SiPixelClustersSoA
0519     #  - SiPixelDigisSoACollection
0520     # produces
0521     #  - TrackingRecHitsSoACollection<TrackerTraits>
0522     process.hltSiPixelRecHitsSoA = cms.EDProducer('SiPixelRecHitAlpakaPhase1@alpaka',
0523         beamSpot = cms.InputTag('hltOnlineBeamSpotDevice'),
0524         src = cms.InputTag('hltSiPixelClustersSoA'),
0525         CPE = cms.string('PixelCPEFastParams'),
0526         # autoselect the alpaka backend
0527         alpaka = cms.untracked.PSet(
0528             backend = cms.untracked.string('')
0529         )
0530     )
0531 
0532     if hasattr(process, 'hltSiPixelRecHitsGPU'):
0533         del process.hltSiPixelRecHitsGPU
0534     if hasattr(process, 'hltSiPixelRecHitsFromGPU'):
0535         del process.hltSiPixelRecHitsFromGPU
0536     if hasattr(process, 'hltSiPixelRecHitsSoAFromGPU'):
0537         del process.hltSiPixelRecHitsSoAFromGPU
0538 
0539     process.hltSiPixelRecHits = cms.EDProducer('SiPixelRecHitFromSoAAlpakaPhase1',
0540         pixelRecHitSrc = cms.InputTag('hltSiPixelRecHitsSoA'),
0541         src = cms.InputTag('hltSiPixelClusters'),
0542     )
0543 
0544     ###
0545     ### Sequence: Pixel Local Reconstruction
0546     ###
0547     process.HLTDoLocalPixelSequence = cms.Sequence(
0548         process.hltOnlineBeamSpotDevice +
0549         process.hltSiPixelClustersSoA +
0550         process.hltSiPixelClusters +
0551         process.hltSiPixelDigiErrors +    # renamed from hltSiPixelDigis
0552         process.hltSiPixelRecHitsSoA +
0553         process.hltSiPixelRecHits
0554     )
0555 
0556     # The module hltSiPixelClustersCache is only used in the PRef menu.
0557     # Previously, it being included in the GRun menu had no effect
0558     # because it was included in a ConditionalTask, which meant that
0559     # it was not executed in the GRun menu, since no other modules
0560     # in any Path of that menu were consuming it.
0561     # Since this customisation effectively replaces ConditionalTasks in the HLT menus with Sequences,
0562     # leaving hltSiPixelClustersCache in a Sequence of the GRun menu would lead to it being unnecessarily executed.
0563     # On the other hand, hltSiPixelClustersCache must be kept in the PRef menu,
0564     # as the latter does have reconstruction modules which consume it.
0565     # The solution implemented here is
0566     # (a) not to include hltSiPixelClustersCache in the Sequence HLTDoLocalPixelSequence used in the GRun menu, and
0567     # (b) include hltSiPixelClustersCache in a separate Sequence to be used only as part of the PRef menu.
0568     if hasattr(process, 'HLTPixelClusterSplittingForPFPPRefForDmeson') \
0569         and not hasattr(process, 'HLTDoLocalPixelSequenceForPFPPRefForDmeson') \
0570         and process.HLTPixelClusterSplittingForPFPPRefForDmeson.contains(process.HLTDoLocalPixelSequence):
0571 
0572         process.HLTDoLocalPixelSequenceForPFPPRefForDmeson = cms.Sequence(
0573             process.HLTDoLocalPixelSequence +
0574             process.hltSiPixelClustersCache
0575         )
0576 
0577         process.HLTPixelClusterSplittingForPFPPRefForDmeson.insert(
0578             process.HLTPixelClusterSplittingForPFPPRefForDmeson.index(process.HLTDoLocalPixelSequence),
0579             process.HLTDoLocalPixelSequenceForPFPPRefForDmeson
0580         )
0581 
0582     # remove HLTDoLocalPixelTask (not needed anymore)
0583     if hasattr(process, 'HLTDoLocalPixelTask'):
0584         del process.HLTDoLocalPixelTask
0585 
0586     ###
0587     ### SerialSync version of Pixel Local Reconstruction
0588     ###
0589     process.hltOnlineBeamSpotDeviceSerialSync = makeSerialClone(process.hltOnlineBeamSpotDevice)
0590 
0591     process.hltSiPixelClustersSoASerialSync = makeSerialClone(process.hltSiPixelClustersSoA)
0592 
0593     process.hltSiPixelClustersSerialSync = process.hltSiPixelClusters.clone(
0594         src = 'hltSiPixelClustersSoASerialSync'
0595     )
0596 
0597     process.hltSiPixelDigiErrorsSerialSync = process.hltSiPixelDigiErrors.clone(
0598         digiErrorSoASrc = 'hltSiPixelClustersSoASerialSync',
0599         fmtErrorsSoASrc = 'hltSiPixelClustersSoASerialSync',
0600     )
0601 
0602     process.hltSiPixelRecHitsSoASerialSync = makeSerialClone(process.hltSiPixelRecHitsSoA,
0603         beamSpot = 'hltOnlineBeamSpotDeviceSerialSync',
0604         src = 'hltSiPixelClustersSoASerialSync',
0605     )
0606 
0607     process.hltSiPixelRecHitsSerialSync = process.hltSiPixelRecHits.clone(
0608         pixelRecHitSrc = 'hltSiPixelRecHitsSoASerialSync',
0609         src = 'hltSiPixelClustersSerialSync',
0610     )
0611 
0612     process.HLTDoLocalPixelCPUOnlySequence = cms.Sequence(
0613         process.hltOnlineBeamSpotDeviceSerialSync +
0614         process.hltSiPixelClustersSoASerialSync +
0615         process.hltSiPixelClustersSerialSync +
0616         process.hltSiPixelDigiErrorsSerialSync +
0617         process.hltSiPixelRecHitsSoASerialSync +
0618         process.hltSiPixelRecHitsSerialSync
0619     )
0620 
0621     if hasattr(process, 'HLTDoLocalPixelCPUOnlyTask'):
0622         del process.HLTDoLocalPixelCPUOnlyTask
0623 
0624     if hasattr(process, 'hltMeasurementTrackerEventCPUOnly'):
0625         process.hltMeasurementTrackerEventCPUOnly.pixelClusterProducer = "hltSiPixelClustersSerialSync"
0626         process.hltMeasurementTrackerEventCPUOnly.inactivePixelDetectorLabels = ["hltSiPixelDigiErrorsSerialSync"]
0627         process.hltMeasurementTrackerEventCPUOnly.badPixelFEDChannelCollectionLabels = ["hltSiPixelDigiErrorsSerialSync"]
0628 
0629     if hasattr(process, 'hltDoubletRecoveryClustersRefRemovalCPUOnly'):
0630         process.hltDoubletRecoveryClustersRefRemovalCPUOnly.pixelClusters = "hltSiPixelClustersSerialSync"
0631 
0632     if hasattr(process, 'hltDoubletRecoveryPFlowPixelClusterCheckCPUOnly'):
0633         process.hltDoubletRecoveryPFlowPixelClusterCheckCPUOnly.PixelClusterCollectionLabel = "hltSiPixelClustersSerialSync"
0634 
0635     if hasattr(process, 'hltDoubletRecoveryPixelLayersAndRegionsCPUOnly'):
0636         process.hltDoubletRecoveryPixelLayersAndRegionsCPUOnly.inactivePixelDetectorLabels = ['hltSiPixelDigiErrorsSerialSync']
0637         process.hltDoubletRecoveryPixelLayersAndRegionsCPUOnly.badPixelFEDChannelCollectionLabels = ['hltSiPixelDigiErrorsSerialSync']
0638         process.hltDoubletRecoveryPixelLayersAndRegionsCPUOnly.BPix.HitProducer = "hltSiPixelRecHitsSerialSync"
0639         process.hltDoubletRecoveryPixelLayersAndRegionsCPUOnly.FPix.HitProducer = "hltSiPixelRecHitsSerialSync"
0640 
0641     if hasattr(process, 'hltIter3IterL3FromL1MuonClustersRefRemovalCPUOnly'):
0642         process.hltIter3IterL3FromL1MuonClustersRefRemovalCPUOnly.pixelClusters = "hltSiPixelClustersSerialSync"
0643 
0644     if hasattr(process, 'hltIter3IterL3FromL1MuonPixelClusterCheckCPUOnly'):
0645         process.hltIter3IterL3FromL1MuonPixelClusterCheckCPUOnly.PixelClusterCollectionLabel = "hltSiPixelClustersSerialSync"
0646 
0647     if hasattr(process, 'hltIter3IterL3FromL1MuonPixelLayersAndRegionsCPUOnly'):
0648         process.hltIter3IterL3FromL1MuonPixelLayersAndRegionsCPUOnly.inactivePixelDetectorLabels = ['hltSiPixelDigiErrorsSerialSync']
0649         process.hltIter3IterL3FromL1MuonPixelLayersAndRegionsCPUOnly.badPixelFEDChannelCollectionLabels = ['hltSiPixelDigiErrorsSerialSync']
0650         process.hltIter3IterL3FromL1MuonPixelLayersAndRegionsCPUOnly.BPix.HitProducer = "hltSiPixelRecHitsSerialSync"
0651         process.hltIter3IterL3FromL1MuonPixelLayersAndRegionsCPUOnly.FPix.HitProducer = "hltSiPixelRecHitsSerialSync"
0652 
0653     for modLabel in [
0654         'hltDoubletRecoveryPixelLayersAndRegions',
0655         'hltFullIter6PixelTrackingRegionSeedLayersBPPRef',
0656         'hltIter3IterL3FromL1MuonPixelLayersAndRegions',
0657         'hltMeasurementTrackerEvent',
0658     ]:
0659         if hasattr(process, modLabel):
0660             mod = getattr(process, modLabel)
0661             mod.inactivePixelDetectorLabels = ['hltSiPixelDigiErrors']
0662             mod.badPixelFEDChannelCollectionLabels = ['hltSiPixelDigiErrors']
0663 
0664     return process
0665 
0666 
0667 def customizeHLTforAlpakaPixelRecoTracking(process):
0668     '''Customisation to introduce the Pixel-Track Reconstruction in Alpaka
0669     '''
0670 
0671     if not hasattr(process, 'HLTRecoPixelTracksSequence'):
0672         return process
0673 
0674     for prod in producers_by_type(process, 'CAHitNtupletAlpakaPhase1@alpaka'):
0675         return process
0676 
0677     # alpaka EDProducer
0678     # consumes
0679     #  - TrackingRecHitsSoACollection<TrackerTraits>
0680     # produces
0681     #  - TkSoADevice
0682     process.hltPixelTracksSoA = cms.EDProducer('CAHitNtupletAlpakaPhase1@alpaka',
0683         pixelRecHitSrc = cms.InputTag('hltSiPixelRecHitsSoA'),
0684         CPE = cms.string('PixelCPEFastParams'),
0685         ptmin = cms.double(0.9),
0686         CAThetaCutBarrel = cms.double(0.002),
0687         CAThetaCutForward = cms.double(0.003),
0688         hardCurvCut = cms.double(0.0328407225),
0689         dcaCutInnerTriplet = cms.double(0.15),
0690         dcaCutOuterTriplet = cms.double(0.25),
0691         earlyFishbone = cms.bool(True),
0692         lateFishbone = cms.bool(False),
0693         fillStatistics = cms.bool(False),
0694         minHitsPerNtuplet = cms.uint32(3),
0695         phiCuts = cms.vint32(
0696             522, 730, 730, 522, 626,
0697             626, 522, 522, 626, 626,
0698             626, 522, 522, 522, 522,
0699             522, 522, 522, 522
0700         ),
0701         maxNumberOfDoublets = cms.uint32(524288),
0702         minHitsForSharingCut = cms.uint32(10),
0703         fitNas4 = cms.bool(False),
0704         doClusterCut = cms.bool(True),
0705         doZ0Cut = cms.bool(True),
0706         doPtCut = cms.bool(True),
0707         useRiemannFit = cms.bool(False),
0708         doSharedHitCut = cms.bool(True),
0709         dupPassThrough = cms.bool(False),
0710         useSimpleTripletCleaner = cms.bool(True),
0711         idealConditions = cms.bool(False),
0712         includeJumpingForwardDoublets = cms.bool(True),
0713         trackQualityCuts = cms.PSet(
0714             chi2MaxPt = cms.double(10),
0715             chi2Coeff = cms.vdouble(0.9, 1.8),
0716             chi2Scale = cms.double(8),
0717             tripletMinPt = cms.double(0.5),
0718             tripletMaxTip = cms.double(0.3),
0719             tripletMaxZip = cms.double(12),
0720             quadrupletMinPt = cms.double(0.3),
0721             quadrupletMaxTip = cms.double(0.5),
0722             quadrupletMaxZip = cms.double(12)
0723         ),
0724         # autoselect the alpaka backend
0725         alpaka = cms.untracked.PSet(
0726             backend = cms.untracked.string('')
0727         )
0728     )
0729 
0730     if hasattr(process, 'hltL2TauTagNNProducer'):
0731         process.hltL2TauTagNNProducer = cms.EDProducer("L2TauNNProducerAlpaka", **process.hltL2TauTagNNProducer.parameters_())
0732 
0733     process.hltPixelTracksSoASerialSync = makeSerialClone(process.hltPixelTracksSoA,
0734         pixelRecHitSrc = 'hltSiPixelRecHitsSoASerialSync'
0735     )
0736 
0737     process.hltPixelTracks = cms.EDProducer("PixelTrackProducerFromSoAAlpakaPhase1",
0738         beamSpot = cms.InputTag("hltOnlineBeamSpot"),
0739         minNumberOfHits = cms.int32(0),
0740         minQuality = cms.string('loose'),
0741         pixelRecHitLegacySrc = cms.InputTag("hltSiPixelRecHits"),
0742         trackSrc = cms.InputTag("hltPixelTracksSoA")
0743     )
0744 
0745     if hasattr(process, 'hltPixelTracksCPU'):
0746         del process.hltPixelTracksCPU
0747     if hasattr(process, 'hltPixelTracksCPUOnly'):
0748         del process.hltPixelTracksCPUOnly
0749     if hasattr(process, 'hltPixelTracksFromGPU'):
0750         del process.hltPixelTracksFromGPU
0751     if hasattr(process, 'hltPixelTracksGPU'):
0752         del process.hltPixelTracksGPU
0753 
0754     process.hltPixelTracksSerialSync = process.hltPixelTracks.clone(
0755         pixelRecHitLegacySrc = cms.InputTag("hltSiPixelRecHitsSerialSync"),
0756         trackSrc = cms.InputTag("hltPixelTracksSoASerialSync")
0757     )
0758 
0759     process.HLTRecoPixelTracksSequence = cms.Sequence(
0760         process.hltPixelTracksSoA +
0761         process.hltPixelTracks
0762     )
0763 
0764     if hasattr(process, 'HLTRecoPixelTracksTask'):
0765         del process.HLTRecoPixelTracksTask
0766 
0767     process.HLTRecoPixelTracksSerialSyncSequence = cms.Sequence(
0768         process.hltPixelTracksSoASerialSync +
0769         process.hltPixelTracksSerialSync
0770     )
0771 
0772     if hasattr(process, 'HLTRecoPixelTracksCPUOnlyTask'):
0773         del process.HLTRecoPixelTracksCPUOnlyTask
0774 
0775     process.hltPixelTracksInRegionL2CPUOnly.tracks = "hltPixelTracksSerialSync"
0776 
0777     process.hltPixelTracksInRegionL1CPUOnly.tracks = "hltPixelTracksSerialSync"
0778 
0779     process.hltIter0PFLowPixelSeedsFromPixelTracksCPUOnly.InputCollection = "hltPixelTracksSerialSync"
0780 
0781     return process
0782 
0783 
0784 def customizeHLTforAlpakaPixelRecoVertexing(process):
0785     '''Customisation to introduce the Pixel-Vertex Reconstruction in Alpaka
0786     '''
0787 
0788     if not hasattr(process, 'HLTRecopixelvertexingSequence'):
0789         return process
0790 
0791     # do not apply the customisation if the menu is already using the alpaka pixel reconstruction
0792     for prod in producers_by_type(process, 'PixelVertexProducerAlpakaPhase1@alpaka'):
0793         return process
0794 
0795     # alpaka EDProducer
0796     # consumes
0797     #  - TkSoADevice
0798     # produces
0799     #  - ZVertexDevice
0800     process.hltPixelVerticesSoA = cms.EDProducer('PixelVertexProducerAlpakaPhase1@alpaka',
0801         oneKernel = cms.bool(True),
0802         useDensity = cms.bool(True),
0803         useDBSCAN = cms.bool(False),
0804         useIterative = cms.bool(False),
0805         minT = cms.int32(2),
0806         eps = cms.double(0.07),
0807         errmax = cms.double(0.01),
0808         chi2max = cms.double(9),
0809         PtMin = cms.double(0.5),
0810         PtMax = cms.double(75),
0811         pixelTrackSrc = cms.InputTag('hltPixelTracksSoA'),
0812         # autoselect the alpaka backend
0813         alpaka = cms.untracked.PSet(
0814             backend = cms.untracked.string('')
0815         )
0816     )
0817 
0818     process.hltPixelVerticesSoASerialSync = makeSerialClone(process.hltPixelVerticesSoA,
0819         pixelTrackSrc = 'hltPixelTracksSoASerialSync'
0820     )
0821 
0822     process.hltPixelVertices = cms.EDProducer("PixelVertexProducerFromSoAAlpaka",
0823         TrackCollection = cms.InputTag("hltPixelTracks"),
0824         beamSpot = cms.InputTag("hltOnlineBeamSpot"),
0825         src = cms.InputTag("hltPixelVerticesSoA")
0826     )
0827 
0828     process.hltPixelVerticesSerialSync = process.hltPixelVertices.clone(
0829         TrackCollection = cms.InputTag("hltPixelTracksSerialSync"),
0830         src = cms.InputTag("hltPixelVerticesSoASerialSync")
0831     )
0832 
0833     if hasattr(process, 'hltPixelVerticesCPU'):
0834         del process.hltPixelVerticesCPU
0835     if hasattr(process, 'hltPixelVerticesCPUOnly'):
0836         del process.hltPixelVerticesCPUOnly
0837     if hasattr(process, 'hltPixelVerticesFromGPU'):
0838         del process.hltPixelVerticesFromGPU
0839     if hasattr(process, 'hltPixelVerticesGPU'):
0840         del process.hltPixelVerticesGPU
0841 
0842     ## failsafe for fake menus
0843     if not hasattr(process, 'hltTrimmedPixelVertices'):
0844         return process
0845 
0846     process.HLTRecopixelvertexingSequence = cms.Sequence(
0847         process.HLTRecoPixelTracksSequence +
0848         process.hltPixelVerticesSoA +
0849         process.hltPixelVertices +
0850         process.hltTrimmedPixelVertices
0851     )
0852 
0853     if hasattr(process, 'HLTRecopixelvertexingTask'):
0854         del process.HLTRecopixelvertexingTask
0855 
0856     process.HLTRecopixelvertexingCPUOnlySequence = cms.Sequence(
0857         process.HLTRecoPixelTracksSerialSyncSequence +
0858         process.hltPixelVerticesSoASerialSync +
0859         process.hltPixelVerticesSerialSync +
0860         process.hltTrimmedPixelVerticesCPUOnly
0861     )
0862 
0863     if hasattr(process, 'HLTRecopixelvertexingCPUOnlyTask'):
0864         del process.HLTRecopixelvertexingCPUOnlyTask
0865 
0866     process.hltTrimmedPixelVerticesCPUOnly.src = 'hltPixelVerticesSerialSync'
0867     process.hltParticleFlowCPUOnly.vertexCollection = 'hltPixelVerticesSerialSync'
0868     process.hltAK4PFJetsCPUOnly.srcPVs = 'hltPixelVerticesSerialSync'
0869 
0870     return process
0871 
0872 
0873 def customizeHLTforAlpakaPixelReco(process):
0874     '''Customisation to introduce the Pixel Local+Track+Vertex Reconstruction in Alpaka
0875     '''
0876     process = customizeHLTforAlpakaPixelRecoLocal(process)
0877     process = customizeHLTforAlpakaPixelRecoTracking(process)
0878     process = customizeHLTforAlpakaPixelRecoVertexing(process)
0879     process = customizeHLTforDQMGPUvsCPUPixel(process)
0880 
0881     return process
0882 
0883 
0884 ## ECAL HLT in Alpaka
0885 def customizeHLTforAlpakaEcalLocalReco(process):
0886 
0887     if not hasattr(process, 'hltEcalDigisGPU'):
0888         return process
0889 
0890     for prod in producers_by_type(process, 'EcalRawToDigiPortable@alpaka'):
0891         return process
0892 
0893     # remove existing ECAL GPU-related ES modules
0894     for foo in [foo for foo in process.es_producers_() if ('ecal' in foo and 'GPU' in foo)]:
0895         process.__delattr__(foo)
0896 
0897     for foo in [foo for foo in process.es_sources_() if ('ecal' in foo and 'GPU' in foo)]:
0898         process.__delattr__(foo)
0899 
0900     # redefine ECAL local reconstruction sequence
0901     process.hltEcalDigisPortableSoA = cms.EDProducer("EcalRawToDigiPortable@alpaka",
0902         FEDs = process.hltEcalDigisGPU.FEDs,
0903         InputLabel = process.hltEcalDigisGPU.InputLabel,
0904         digisLabelEB = process.hltEcalDigisGPU.digisLabelEB,
0905         digisLabelEE = process.hltEcalDigisGPU.digisLabelEE,
0906         maxChannelsEB = process.hltEcalDigisGPU.maxChannelsEB,
0907         maxChannelsEE = process.hltEcalDigisGPU.maxChannelsEE,
0908         # autoselect the alpaka backend
0909         alpaka = cms.untracked.PSet(
0910             backend = cms.untracked.string('')
0911         )
0912     )
0913 
0914     from EventFilter.EcalRawToDigi.ecalElectronicsMappingHostESProducer_cfi import ecalElectronicsMappingHostESProducer as _ecalElectronicsMappingHostESProducer
0915     process.ecalElectronicsMappingHostESProducer = _ecalElectronicsMappingHostESProducer.clone()
0916 
0917     process.hltEcalDigis = cms.EDProducer("EcalDigisFromPortableProducer",
0918         digisInLabelEB = cms.InputTag('hltEcalDigisPortableSoA', 'ebDigis'),
0919         digisInLabelEE = cms.InputTag('hltEcalDigisPortableSoA', 'eeDigis'),
0920         digisOutLabelEB = cms.string("ebDigis"),
0921         digisOutLabelEE = cms.string("eeDigis"),
0922         produceDummyIntegrityCollections = cms.bool(False)
0923     )
0924 
0925     process.hltEcalUncalibRecHitPortableSoA = cms.EDProducer("EcalUncalibRecHitProducerPortable@alpaka",
0926         EBtimeConstantTerm = process.hltEcalUncalibRecHitGPU.EBtimeConstantTerm,
0927         EBtimeFitLimits_Lower = process.hltEcalUncalibRecHitGPU.EBtimeFitLimits_Lower,
0928         EBtimeFitLimits_Upper = process.hltEcalUncalibRecHitGPU.EBtimeFitLimits_Upper,
0929         EBtimeNconst = process.hltEcalUncalibRecHitGPU.EBtimeNconst,
0930         EEtimeConstantTerm = process.hltEcalUncalibRecHitGPU.EEtimeConstantTerm,
0931         EEtimeFitLimits_Lower = process.hltEcalUncalibRecHitGPU.EEtimeFitLimits_Lower,
0932         EEtimeFitLimits_Upper = process.hltEcalUncalibRecHitGPU.EEtimeFitLimits_Upper,
0933         EEtimeNconst = process.hltEcalUncalibRecHitGPU.EEtimeNconst,
0934         amplitudeThresholdEB = process.hltEcalUncalibRecHitGPU.amplitudeThresholdEB,
0935         amplitudeThresholdEE = process.hltEcalUncalibRecHitGPU.amplitudeThresholdEE,
0936         digisLabelEB = cms.InputTag("hltEcalDigisPortableSoA", "ebDigis"),
0937         digisLabelEE = cms.InputTag("hltEcalDigisPortableSoA", "eeDigis"),
0938         kernelMinimizeThreads = process.hltEcalUncalibRecHitGPU.kernelMinimizeThreads,
0939         outOfTimeThresholdGain12mEB = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain12mEB,
0940         outOfTimeThresholdGain12mEE = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain12mEE,
0941         outOfTimeThresholdGain12pEB = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain12pEB,
0942         outOfTimeThresholdGain12pEE = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain12pEE,
0943         outOfTimeThresholdGain61mEB = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain61mEB,
0944         outOfTimeThresholdGain61mEE = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain61mEE,
0945         outOfTimeThresholdGain61pEB = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain61pEB,
0946         outOfTimeThresholdGain61pEE = process.hltEcalUncalibRecHitGPU.outOfTimeThresholdGain61pEE,
0947         recHitsLabelEB = process.hltEcalUncalibRecHitGPU.recHitsLabelEB,
0948         recHitsLabelEE = process.hltEcalUncalibRecHitGPU.recHitsLabelEE,
0949         shouldRunTimingComputation = process.hltEcalUncalibRecHitGPU.shouldRunTimingComputation,
0950         # autoselect the alpaka backend
0951         alpaka = cms.untracked.PSet(
0952             backend = cms.untracked.string('')
0953         )
0954     )
0955 
0956     if hasattr(process, 'hltEcalUncalibRecHitGPU'):
0957         del process.hltEcalUncalibRecHitGPU
0958 
0959     process.ecalMultifitParametersSource = cms.ESSource("EmptyESSource",
0960         firstValid = cms.vuint32(1),
0961         iovIsRunNotTime = cms.bool(True),
0962         recordName = cms.string('EcalMultifitParametersRcd')
0963     )
0964 
0965     from RecoLocalCalo.EcalRecProducers.ecalMultifitConditionsHostESProducer_cfi import ecalMultifitConditionsHostESProducer as _ecalMultifitConditionsHostESProducer
0966     process.ecalMultifitConditionsHostESProducer = _ecalMultifitConditionsHostESProducer.clone()
0967 
0968     from RecoLocalCalo.EcalRecProducers.ecalMultifitParametersHostESProducer_cfi import ecalMultifitParametersHostESProducer as _ecalMultifitParametersHostESProducer
0969     process.ecalMultifitParametersHostESProducer = _ecalMultifitParametersHostESProducer.clone()
0970 
0971     process.hltEcalUncalibRecHit = cms.EDProducer("EcalUncalibRecHitSoAToLegacy",
0972         isPhase2 = process.hltEcalUncalibRecHitFromSoA.isPhase2,
0973         recHitsLabelCPUEB = process.hltEcalUncalibRecHitFromSoA.recHitsLabelCPUEB,
0974         recHitsLabelCPUEE = process.hltEcalUncalibRecHitFromSoA.recHitsLabelCPUEE,
0975         uncalibRecHitsPortableEB = cms.InputTag("hltEcalUncalibRecHitPortableSoA", "EcalUncalibRecHitsEB"),
0976         uncalibRecHitsPortableEE = cms.InputTag("hltEcalUncalibRecHitPortableSoA", "EcalUncalibRecHitsEE")
0977     )
0978 
0979     if hasattr(process, 'hltEcalUncalibRecHitSoA'):
0980         delattr(process, 'hltEcalUncalibRecHitSoA')
0981 
0982     process.hltEcalDetIdToBeRecovered = cms.EDProducer("EcalDetIdToBeRecoveredProducer",
0983         integrityBlockSizeErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityBlockSizeErrors'),
0984         integrityTTIdErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityTTIdErrors'),
0985 
0986         ebIntegrityGainErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityGainErrors'),
0987         eeIntegrityGainErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityGainErrors'),
0988 
0989         ebIntegrityGainSwitchErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityGainSwitchErrors'),
0990         eeIntegrityGainSwitchErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityGainSwitchErrors'),
0991 
0992         ebIntegrityChIdErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityChIdErrors'),
0993         eeIntegrityChIdErrors = cms.InputTag('hltEcalDigisLegacy', 'EcalIntegrityChIdErrors'),
0994 
0995         ebSrFlagCollection = cms.InputTag("hltEcalDigisLegacy"),
0996         eeSrFlagCollection = cms.InputTag("hltEcalDigisLegacy"),
0997 
0998         ebDetIdToBeRecovered = cms.string("ebDetId"),
0999         eeDetIdToBeRecovered = cms.string("eeDetId"),
1000 
1001         ebFEToBeRecovered = cms.string("ebFE"),
1002         eeFEToBeRecovered = cms.string("eeFE"),
1003     )
1004 
1005     process.hltEcalRecHit.triggerPrimitiveDigiCollection = 'hltEcalDigisLegacy:EcalTriggerPrimitives'
1006 
1007     process.HLTDoFullUnpackingEgammaEcalWithoutPreshowerSequence = cms.Sequence(
1008         process.hltEcalDigisLegacy +
1009         process.hltEcalDigisPortableSoA +
1010         process.hltEcalDigis +          # conversion of PortableSoA to legacy format
1011         process.hltEcalUncalibRecHitPortableSoA +
1012         process.hltEcalUncalibRecHit +  # conversion of PortableSoA to legacy format
1013         process.hltEcalDetIdToBeRecovered +
1014         process.hltEcalRecHit
1015     )
1016 
1017     process.HLTPreshowerSequence = cms.Sequence(process.hltEcalPreshowerDigis + process.hltEcalPreshowerRecHit)
1018 
1019     process.HLTDoFullUnpackingEgammaEcalSequence = cms.Sequence(
1020         process.HLTDoFullUnpackingEgammaEcalWithoutPreshowerSequence +
1021         process.HLTPreshowerSequence
1022     )
1023 
1024     process.HLTDoFullUnpackingEgammaEcalMFSequence = cms.Sequence(process.HLTDoFullUnpackingEgammaEcalSequence)
1025 
1026     process.hltEcalDigisCPUSerialSoA = makeSerialClone(process.hltEcalDigisPortableSoA)
1027 
1028     process.hltEcalDigisCPUSerial = process.hltEcalDigis.clone(
1029         digisInLabelEB = 'hltEcalDigisCPUSerialSoA:ebDigis',
1030         digisInLabelEE = 'hltEcalDigisCPUSerialSoA:eeDigis',
1031     )
1032 
1033     process.hltEcalUncalibRecHitCPUSerialSoA = makeSerialClone(process.hltEcalUncalibRecHitPortableSoA,
1034         digisLabelEB = "hltEcalDigisCPUSerialSoA:ebDigis",
1035         digisLabelEE = "hltEcalDigisCPUSerialSoA:eeDigis",
1036     )
1037 
1038     process.hltEcalUncalibRecHitCPUSerial = process.hltEcalUncalibRecHit.clone(
1039         uncalibRecHitsPortableEB = "hltEcalUncalibRecHitCPUSerialSoA:EcalUncalibRecHitsEB",
1040         uncalibRecHitsPortableEE = "hltEcalUncalibRecHitCPUSerialSoA:EcalUncalibRecHitsEE",
1041     )
1042 
1043     process.hltEcalRecHitCPUOnly = process.hltEcalRecHit.clone(
1044         EBuncalibRecHitCollection = 'hltEcalUncalibRecHitCPUSerial:EcalUncalibRecHitsEB',
1045         EEuncalibRecHitCollection = 'hltEcalUncalibRecHitCPUSerial:EcalUncalibRecHitsEE',
1046     )
1047 
1048     process.HLTDoFullUnpackingEgammaEcalWithoutPreshowerCPUOnlySequence = cms.Sequence(
1049         process.hltEcalDigisLegacy +
1050         process.hltEcalDigisCPUSerialSoA +
1051         process.hltEcalDigisCPUSerial + # conversion of CPUSerialSoA to legacy format
1052         process.hltEcalUncalibRecHitCPUSerialSoA +
1053         process.hltEcalUncalibRecHitCPUSerial + # conversion of CPUSerialSoA to legacy format
1054         process.hltEcalDetIdToBeRecovered +
1055         process.hltEcalRecHitCPUOnly
1056     )
1057 
1058     for prod in producers_by_type(process, 'HLTRechitsToDigis'):
1059         prod.srFlagsIn = 'hltEcalDigisLegacy'
1060 
1061     for prod in producers_by_type(process, 'CorrectedECALPFClusterProducer'):
1062         try:
1063             prod.energyCorrector.ebSrFlagLabel = 'hltEcalDigisLegacy'
1064             prod.energyCorrector.eeSrFlagLabel = 'hltEcalDigisLegacy'
1065         except:
1066             pass
1067 
1068     for pathNameMatch in ['DQM_EcalReconstruction_v', 'DQM_HIEcalReconstruction_v']:
1069         dqmEcalRecoPathName = None
1070         for pathName in process.paths_():
1071             if pathName.startswith(pathNameMatch):
1072                 dqmEcalRecoPath = getattr(process, pathName)
1073                 dqmEcalRecoPath.insert(dqmEcalRecoPath.index(process.HLTEndSequence), getattr(process, 'HLTDoFullUnpackingEgammaEcalWithoutPreshowerCPUOnlySequence'))
1074                 for delmod in ['hltEcalConsumerCPU', 'hltEcalConsumerGPU']:
1075                     if hasattr(process, delmod):
1076                         process.__delattr__(delmod)
1077 
1078     for hltOutModMatch in ['hltOutputDQMGPUvsCPU', 'hltOutputHIDQMGPUvsCPU']:
1079         if hasattr(process, hltOutModMatch):
1080             outMod = getattr(process, hltOutModMatch)
1081             outCmds_new = [foo for foo in outMod.outputCommands if 'Ecal' not in foo]
1082             outCmds_new += [
1083                 'keep *_hltEcalDigis_*_*',
1084                 'keep *_hltEcalDigisCPUSerial_*_*',
1085                 'keep *_hltEcalUncalibRecHit_*_*',
1086                 'keep *_hltEcalUncalibRecHitCPUSerial_*_*',
1087             ]
1088             outMod.outputCommands = outCmds_new[:]
1089 
1090     return process
1091 
1092 
1093 def customizeHLTforAlpakaStatus(process):
1094 
1095     if not hasattr(process, 'statusOnGPU'):
1096         return process
1097 
1098     process.hltBackend = cms.EDProducer('AlpakaBackendProducer@alpaka')
1099 
1100     insert_modules_before(process, process.statusOnGPU, process.hltBackend)
1101 
1102     del process.statusOnGPU
1103 
1104     process.hltStatusOnGPUFilter = cms.EDFilter('AlpakaBackendFilter',
1105         producer = cms.InputTag('hltBackend', 'backend'),
1106         backends = cms.vstring('CudaAsync', 'ROCmAsync')
1107     )
1108 
1109     insert_modules_before(process, process.statusOnGPUFilter, process.hltStatusOnGPUFilter)
1110     insert_modules_before(process, ~process.statusOnGPUFilter, ~process.hltStatusOnGPUFilter)
1111 
1112     del process.statusOnGPUFilter
1113 
1114     return process
1115 
1116 
1117 def _replace_object(process, target, obj):
1118     for container in itertools.chain(
1119         process.sequences_().values(),
1120         process.paths_().values(),
1121         process.endpaths_().values()
1122     ):
1123         if target.label() in [bar for foo,bar in container.directDependencies()]:
1124             try:
1125                 position = container.index(target)
1126                 container.insert(position, obj)
1127                 container.remove(target)
1128             except ValueError:
1129                 container.associate(obj)
1130                 container.remove(target)
1131 
1132     for container in itertools.chain(
1133         process.tasks_().values(),
1134         process.conditionaltasks_().values(),
1135     ):
1136         if target.label() in [bar for foo,bar in container.directDependencies()]:
1137             container.add(obj)
1138             container.remove(target)
1139 
1140     return process
1141 
1142 def _rename_edmodule(process, oldModuleLabel, newModuleLabel, typeBlackList):
1143     if not hasattr(process, oldModuleLabel) or hasattr(process, newModuleLabel) or oldModuleLabel == newModuleLabel:
1144         return process
1145     oldObj = getattr(process, oldModuleLabel)
1146     if oldObj.type_() in typeBlackList:
1147         return process
1148     setattr(process, newModuleLabel, oldObj.clone())
1149     newObj = getattr(process, newModuleLabel)
1150     process = _replace_object(process, oldObj, newObj)
1151     process.__delattr__(oldModuleLabel)
1152     process = massReplaceInputTag(process, oldModuleLabel, newModuleLabel, False, True, False)
1153     for outputModuleLabel in process.outputModules_():
1154         outputModule = getattr(process, outputModuleLabel)
1155         if not hasattr(outputModule, 'outputCommands'):
1156             continue
1157         for outputCmdIdx, outputCmd in enumerate(outputModule.outputCommands):
1158             outputModule.outputCommands[outputCmdIdx] = outputCmd.replace(f'_{oldModuleLabel}_', f'_{newModuleLabel}_')
1159     return process
1160 
1161 def _rename_edmodules(process, matchExpr, oldStr, newStr, typeBlackList):
1162     for moduleDict in [process.producers_(), process.filters_(), process.analyzers_()]:
1163         moduleLabels = list(moduleDict.keys())
1164         for moduleLabel in moduleLabels:
1165             if bool(re.match(matchExpr, moduleLabel)):
1166                 moduleLabelNew = moduleLabel.replace(oldStr, '') + newStr
1167                 process = _rename_edmodule(process, moduleLabel, moduleLabelNew, typeBlackList)
1168     return process
1169 
1170 def _rename_container(process, oldContainerLabel, newContainerLabel):
1171     if not hasattr(process, oldContainerLabel) or hasattr(process, newContainerLabel) or oldContainerLabel == newContainerLabel:
1172         return process
1173     oldObj = getattr(process, oldContainerLabel)
1174     setattr(process, newContainerLabel, oldObj.copy())
1175     newObj = getattr(process, newContainerLabel)
1176     process = _replace_object(process, oldObj, newObj)
1177     process.__delattr__(oldContainerLabel)
1178     return process
1179 
1180 def _rename_containers(process, matchExpr, oldStr, newStr):
1181     for containerName in itertools.chain(
1182         process.sequences_().keys(),
1183         process.tasks_().keys(),
1184         process.conditionaltasks_().keys()
1185     ):
1186         if bool(re.match(matchExpr, containerName)):
1187             containerNameNew = containerName.replace(oldStr, '') + newStr
1188             process = _rename_container(process, containerName, containerNameNew)
1189     return process
1190 
1191 def customizeHLTforAlpakaRename(process):
1192     # mass renaming of EDModules and Sequences:
1193     # if the label matches matchRegex, remove oldStr and append newStr
1194     for matchRegex, oldStr, newStr in [
1195         [".*Portable.*", "Portable", ""],
1196         [".*SerialSync.*", "SerialSync", "SerialSync"],
1197         [".*CPUSerial.*", "CPUSerial", "SerialSync"],
1198         [".*CPUOnly.*", "CPUOnly", "SerialSync"],
1199     ]:
1200         process = _rename_edmodules(process, matchRegex, oldStr, newStr, ['HLTPrescaler'])
1201         process = _rename_containers(process, matchRegex, oldStr, newStr)
1202 
1203     return process
1204 
1205 
1206 def customizeHLTforAlpaka(process):
1207     process.load('Configuration.StandardSequences.Accelerators_cff')
1208 
1209     process = customizeHLTforAlpakaStatus(process)
1210     process = customizeHLTforAlpakaPixelReco(process)
1211     process = customizeHLTforAlpakaEcalLocalReco(process)
1212     process = customizeHLTforAlpakaParticleFlowClustering(process)
1213     process = customizeHLTforAlpakaRename(process)
1214 
1215     return process