Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-26 01:15:40

0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.ParameterSet.VarParsing as VarParsing
0003 
0004 process = cms.Process("TEST")
0005 
0006 options = VarParsing.VarParsing('standard')
0007 options.register('mode', 'trivial', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string,
0008                  'type of emulation')
0009 options.register('fedId', 0, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0010                  'emulated FED id')
0011 options.register('debug', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0012                  'debugging mode')
0013 options.register('dumpFRD', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0014                  'also dump the FEDRawData content')
0015 options.register('numCaptureBlocks', 1, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0016                  'number of capture blocks to emulate')
0017 options.register('numECONDs', -1, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0018                  'number of ECON-Ds to emulate')
0019 options.register('numChannelsPerERx', 37, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0020                  'number of channels enabled per ERx')
0021 options.register('numERxsPerECOND', 12, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0022                  'number of ERxs enabled per ECON-D')
0023 options.register('activeECONDs', [], VarParsing.VarParsing.multiplicity.list, VarParsing.VarParsing.varType.int,
0024                  'list of ECON-Ds enabled')
0025 options.register('ECONDsInPassthrough', [], VarParsing.VarParsing.multiplicity.list, VarParsing.VarParsing.varType.int,
0026                  'list of ECON-Ds in passthrough mode')
0027 options.register('ECONDsInCharacterisation', [], VarParsing.VarParsing.multiplicity.list, VarParsing.VarParsing.varType.int,
0028                  'list of ECON-Ds in characterisation mode')
0029 options.register('ECONDToTStatus', 3, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0030                  'default ToT status bits (aka TcTp bits) value to be emulated')
0031 options.register('randomActiveCaptureBlocks', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0032                  'randomly activate capture blocks on emulation')
0033 options.register('randomActiveECOND', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0034                  'randomly activate ECOn-Ds on emulation')
0035 options.register('storeOutput', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0036                  'also store the output into an EDM file')
0037 options.register('storeRAWOutput', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0038                  'also store the RAW output into a streamer file')
0039 options.register('storeEmulatorInfo', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,
0040                  'also store the emulator metadata')
0041 options.register('inputFiles',
0042                  'file:/eos/cms/store/group/dpg_hgcal/tb_hgcal/2023/labtest/module822/pedestal_run0.root',
0043                  VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string,
0044                  'input TB file')
0045 options.maxEvents = 1  # number of events to emulate
0046 options.output = 'output.root'  # output EDM file
0047 options.secondaryOutput = 'output.raw'  # output streamer file
0048 options.parseArguments()
0049 
0050 process.load('EventFilter.HGCalRawToDigi.hgcalEmulatedSlinkRawData_cfi')
0051 process.load('EventFilter.HGCalRawToDigi.hgcalDigis_cfi')
0052 
0053 process.load("FWCore.MessageService.MessageLogger_cfi")
0054 if options.debug:
0055     process.MessageLogger.cerr.threshold = "DEBUG"
0056     process.MessageLogger.debugModules = ["hgcalEmulatedSlinkRawData", "hgcalDigis"]
0057 
0058 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(options.maxEvents))
0059 process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
0060     hgcalEmulatedSlinkRawData = cms.PSet(initialSeed = cms.untracked.uint32(42))
0061 )
0062 
0063 process.source = cms.Source("EmptySource")
0064 
0065 # steer the emulator part
0066 process.hgcalEmulatedSlinkRawData.emulatorType = options.mode
0067 if process.hgcalEmulatedSlinkRawData.emulatorType == 'hgcmodule':
0068     process.hgcalEmulatedSlinkRawData.inputs = cms.untracked.vstring(options.inputFiles)
0069 process.hgcalEmulatedSlinkRawData.storeEmulatorInfo = bool(options.storeEmulatorInfo)
0070 
0071 # steer the number of capture blocks
0072 if options.randomActiveCaptureBlocks:
0073     from random import randint
0074     process.hgcalEmulatedSlinkRawData.slinkParams.numCaptureBlocks = randint(1, 50)  # randomise the number of capture blocks emulated
0075 else:
0076     process.hgcalEmulatedSlinkRawData.slinkParams.numCaptureBlocks = options.numCaptureBlocks
0077 print('S-link: number of capture blocks: {}'.format(
0078     process.hgcalEmulatedSlinkRawData.slinkParams.numCaptureBlocks.value()))
0079 
0080 # steer the number (and/or list) of ECON-Ds per capture block
0081 if options.numECONDs > 0:
0082     for i in range(options.numECONDs - len(process.hgcalEmulatedSlinkRawData.slinkParams.ECONDs)):
0083         process.hgcalEmulatedSlinkRawData.slinkParams.ECONDs.append(process.hgcalEmulatedSlinkRawData.slinkParams.ECONDs[0].clone())
0084     process.hgcalEmulatedSlinkRawData.slinkParams.checkECONDsLimits = False  # allows to mess with unconventional, high number
0085                                                                              # of ECON-Ds per capture block
0086 
0087 econd_id = 0
0088 for econd in process.hgcalEmulatedSlinkRawData.slinkParams.ECONDs:
0089     # must use 'cms.' python configuration types
0090     if options.randomActiveECOND:  # randomly turn on/off any ECON-D in capture block
0091         from random import getrandbits
0092         econd.active = cms.bool(bool(getrandbits(1)))
0093     else:  # use a fixed, user-steered list of ECON-Ds in capture block
0094         econd.active = cms.bool((econd_id in options.activeECONDs))
0095     econd.passthroughMode = cms.bool((econd_id in options.ECONDsInPassthrough))
0096     econd.characterisationMode = cms.bool((econd_id in options.ECONDsInCharacterisation))
0097     econd.enabledERxs = cms.vuint32([i for i in range(options.numERxsPerECOND)])
0098     econd.numChannelsPerERx = cms.uint32(options.numChannelsPerERx)
0099     econd.defaultToTStatus = cms.uint32(options.ECONDToTStatus)
0100     print('ECON-D {}: active? {}, enabled eRxs: {}, number of channels/eRx: {}, passthrough? {}, characterisation? {}'.format(
0101         econd_id, bool(econd.active),
0102         [i for i in econd.enabledERxs], econd.numChannelsPerERx.value(),
0103         bool(econd.passthroughMode), bool(econd.characterisationMode)))
0104     econd_id += 1
0105 
0106 # steer the unpacker
0107 process.hgcalDigis.src = cms.InputTag('hgcalEmulatedSlinkRawData')
0108 process.hgcalDigis.fedIds = cms.vuint32(options.fedId)
0109 process.hgcalDigis.maxCaptureBlock = process.hgcalEmulatedSlinkRawData.slinkParams.numCaptureBlocks
0110 process.hgcalDigis.numERxsInECOND = options.numERxsPerECOND
0111 process.hgcalDigis.captureBlockECONDMax = max(  # allows to mess with unconventional, high number of ECON-Ds per capture block
0112     process.hgcalDigis.captureBlockECONDMax,
0113     len([ec for ec in process.hgcalEmulatedSlinkRawData.slinkParams.ECONDs if ec.active]))
0114 
0115 process.p = cms.Path(process.hgcalEmulatedSlinkRawData * process.hgcalDigis)
0116 
0117 if options.dumpFRD:
0118     process.dump = cms.EDAnalyzer("DumpFEDRawDataProduct",
0119         label = cms.untracked.InputTag('hgcalEmulatedSlinkRawData'),
0120         feds = cms.untracked.vint32(options.fedId),
0121         dumpPayload = cms.untracked.bool(True)
0122     )
0123     process.p *= process.dump
0124 
0125 process.outpath = cms.EndPath()
0126 
0127 if options.storeOutput:
0128     process.output = cms.OutputModule("PoolOutputModule",
0129         fileName = cms.untracked.string(options.output),
0130         outputCommands = cms.untracked.vstring(
0131             'drop *',
0132             'keep *_hgcalEmulatedSlinkRawData_*_*',
0133             'keep *_hgcalDigis_*_*',
0134         )
0135     )
0136     process.outpath += process.output
0137 
0138 if options.storeRAWOutput:
0139     process.outputRAW = cms.OutputModule("FRDOutputModule",
0140         source = cms.InputTag('hgcalEmulatedSlinkRawData'),
0141         frdVersion = cms.untracked.uint32(6),
0142         frdFileVersion = cms.untracked.uint32(1),
0143         fileName = cms.untracked.string(options.secondaryOutput)
0144     )
0145     process.outpath += process.outputRAW