Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-13 09:27:07

0001 #!/usr/bin/env python
0002 from __future__ import print_function
0003 import sys
0004 
0005 """
0006 The parameters can be changed by adding commandline arguments of the form
0007 ::
0008 
0009     runGlobalFakeInputProducer.py nevents=-1
0010 
0011 The latter can be used to change parameters in crab.
0012 """
0013 
0014 job = 0 #job number
0015 njob = 1 #number of jobs
0016 nevents = 3564 #number of events
0017 rootout = False #whether to produce root file
0018 dump = False #dump python
0019 newXML = False #whether running with the new Grammar
0020 
0021 # Argument parsing
0022 # vvv
0023 
0024 if len(sys.argv) > 1 and sys.argv[1].endswith('.py'):
0025     sys.argv.pop(0)
0026 if len(sys.argv) == 2 and ':' in sys.argv[1]:
0027     argv = sys.argv[1].split(':')
0028 else:
0029     argv = sys.argv[1:]
0030 
0031 for arg in argv:
0032     (k, v) = map(str.strip, arg.split('='))
0033     if k not in globals():
0034         raise "Unknown argument '%s'!" % (k,)
0035     if isinstance(globals()[k], bool):
0036         globals()[k] = v.lower() in ('y', 'yes', 'true', 't', '1')
0037     elif isinstance(globals()[k], int):
0038         globals()[k] = int(v)
0039     else:
0040         globals()[k] = v
0041 
0042 neventsPerJob = int(nevents/njob)
0043 skip = job * neventsPerJob
0044 
0045 if skip>4:
0046     skip = skip-4
0047     neventsPerJob = neventsPerJob+4
0048 
0049 import FWCore.ParameterSet.Config as cms
0050 
0051 process = cms.Process('L1TEMULATION')
0052 
0053 process.load('Configuration.StandardSequences.Services_cff')
0054 process.load('FWCore.MessageService.MessageLogger_cfi')
0055 process.load('Configuration/StandardSequences/FrontierConditions_GlobalTag_cff')
0056 
0057 
0058 # Select the Message Logger output you would like to see:
0059 #
0060 process.load('FWCore.MessageService.MessageLogger_cfi')
0061 #process.load('L1Trigger/L1TYellow/l1t_debug_messages_cfi')
0062 #process.load('L1Trigger/L1TYellow/l1t_info_messages_cfi')
0063 
0064 process.load('L1Trigger/L1TGlobal/debug_messages_cfi')
0065 process.MessageLogger.l1t_debug.l1t.limit = cms.untracked.int32(100000)
0066 
0067 process.MessageLogger.categories.append('l1t|Global')
0068 # DEBUG
0069 #process.MessageLogger.debugModules = cms.untracked.vstring('simGtStage2Digis') 
0070 #process.MessageLogger.cerr.threshold = cms.untracked.string('DEBUG') 
0071 
0072 # set the number of events
0073 process.maxEvents = cms.untracked.PSet(
0074     #input = cms.untracked.int32(10)
0075     input = cms.untracked.int32(neventsPerJob)
0076     )
0077 
0078 # Input source
0079 process.source = cms.Source("PoolSource",
0080     secondaryFileNames = cms.untracked.vstring(),
0081     fileNames = cms.untracked.vstring(
0082         # TTbar CMSSW_12X samples
0083         "/store/relval/CMSSW_12_3_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/122X_mcRun3_2021_realistic_v5-v1/2580000/04b2f8e0-57d6-449c-aa9f-a416c9926f31.root",
0084         "/store/relval/CMSSW_12_3_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/122X_mcRun3_2021_realistic_v5-v1/2580000/12bfbbc7-60fe-44c9-8f04-daa8c7b61406.root",
0085         "/store/relval/CMSSW_12_3_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/122X_mcRun3_2021_realistic_v5-v1/2580000/198e5a8c-8f06-4688-ae0d-5cc51b1eef46.root",
0086         "/store/relval/CMSSW_12_3_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/122X_mcRun3_2021_realistic_v5-v1/2580000/2e6c92bb-4997-4232-8475-04a668d8d163.root",
0087     ),
0088     skipEvents = cms.untracked.uint32(skip)
0089     )
0090 
0091 process.output =cms.OutputModule("PoolOutputModule",
0092         outputCommands = cms.untracked.vstring('keep *'),
0093     fileName = cms.untracked.string('testGlobalMCInputProducer_'+repr(job)+'.root')
0094     )
0095 
0096 process.options = cms.untracked.PSet(
0097     wantSummary = cms.bool(True)
0098 )
0099 
0100 
0101 # Additional output definition
0102 # TTree output file
0103 process.load("CommonTools.UtilAlgos.TFileService_cfi")
0104 process.TFileService.fileName = cms.string('l1t_histos.root')
0105 
0106 # Other statements
0107 from Configuration.AlCa.GlobalTag import GlobalTag
0108 process.GlobalTag = GlobalTag(process.GlobalTag, '123X_mcRun3_2021_realistic_v13', '')
0109 
0110 ## ## needed until prescales go into GlobalTag ########################
0111 ## from CondCore.DBCommon.CondDBSetup_cfi import CondDBSetup
0112 ## process.l1conddb = cms.ESSource("PoolDBESSource",
0113 ##        CondDBSetup,
0114 ##        connect = cms.string('frontier://FrontierPrep/CMS_CONDITIONS'),
0115 ##        toGet   = cms.VPSet(
0116 ##             cms.PSet(
0117 ##                  record = cms.string('L1TGlobalPrescalesVetosRcd'),
0118 ##                  tag = cms.string("L1TGlobalPrescalesVetos_passThrough_mc")
0119 ##             )
0120 ##        )
0121 ## )
0122 ## process.es_prefer_l1conddb = cms.ESPrefer( "PoolDBESSource","l1conddb")
0123 ## # done ##############################################################
0124 
0125 # Flag to switch between using MC particles and injecting individual particles
0126 useMCtoGT = True
0127 
0128 process.dumpGT = cms.EDAnalyzer("l1t::GtInputDump",
0129                 egInputTag    = cms.InputTag("gtInput"),
0130         muInputTag    = cms.InputTag("gtInput"),
0131         tauInputTag   = cms.InputTag("gtInput"),
0132         jetInputTag   = cms.InputTag("gtInput"),
0133         etsumInputTag = cms.InputTag("gtInput"),
0134         minBx         = cms.int32(0),
0135         maxBx         = cms.int32(0)
0136          )
0137 process.dumpED = cms.EDAnalyzer("EventContentAnalyzer")
0138 process.dumpES = cms.EDAnalyzer("PrintEventSetupContent")
0139 
0140 process.mcL1GTinput = cms.EDProducer("l1t::GenToInputProducer",
0141                                      bxFirst = cms.int32(-2),
0142                                      bxLast = cms.int32(2),
0143                      maxMuCand = cms.int32(8),
0144                      maxJetCand = cms.int32(12),
0145                      maxEGCand  = cms.int32(12),
0146                      maxTauCand = cms.int32(8),
0147                                      jetEtThreshold = cms.double(1),
0148                                      tauEtThreshold = cms.double(1),
0149                                      egEtThreshold  = cms.double(1),
0150                                      muEtThreshold  = cms.double(1),
0151                      emptyBxTrailer = cms.int32(5),
0152                      emptyBxEvt = cms.int32(neventsPerJob)
0153                                      )
0154 
0155 process.mcL1GTinput.maxMuCand = cms.int32(8)
0156 process.mcL1GTinput.maxJetCand = cms.int32(12)
0157 process.mcL1GTinput.maxEGCand  = cms.int32(12)
0158 process.mcL1GTinput.maxTauCand = cms.int32(8)
0159 
0160 # Fake the input
0161 process.fakeL1GTinput = cms.EDProducer("l1t::FakeInputProducer",
0162 
0163 # Note: There is no error checking on these parameters...you are responsible.
0164                        egParams = cms.untracked.PSet(
0165                    egBx    = cms.untracked.vint32(-2, -1,  0,  0,  1,  2),
0166                egHwPt  = cms.untracked.vint32(10, 20, 30, 61, 40, 50),
0167                egHwPhi = cms.untracked.vint32(11, 21, 31, 61, 41, 51),
0168                egHwEta = cms.untracked.vint32(12, 22, 32, 62, 42, 52),
0169                egIso   = cms.untracked.vint32( 0,  0,  1,  1,  0,  0)
0170                ),
0171 
0172                        muParams = cms.untracked.PSet(
0173                    muBx    = cms.untracked.vint32(-2, -1,  0,  0,  1,  2),
0174                muHwPt  = cms.untracked.vint32(5, 20, 30, 61, 40, 50),
0175                muHwPhi = cms.untracked.vint32(11, 21, 31, 61, 41, 51),
0176                muHwEta = cms.untracked.vint32(12, 22, 32, 62, 42, 52),
0177                muIso   = cms.untracked.vint32( 0,  0,  1,  1,  0,  0)
0178                ),
0179 
0180                        tauParams = cms.untracked.PSet(
0181                    tauBx    = cms.untracked.vint32(),
0182                tauHwPt  = cms.untracked.vint32(),
0183                tauHwPhi = cms.untracked.vint32(),
0184                tauHwEta = cms.untracked.vint32(),
0185                tauIso   = cms.untracked.vint32()
0186                ),
0187 
0188                        jetParams = cms.untracked.PSet(
0189                    jetBx    = cms.untracked.vint32(  0,   0,   2,   1,   1,   2),
0190                jetHwPt  = cms.untracked.vint32(100, 200, 130, 170,  85, 145),
0191                jetHwPhi = cms.untracked.vint32(  2,  67,  10,   3,  78,  10),
0192                jetHwEta = cms.untracked.vint32(  110,  -99,  11,   0,  17,  11)
0193                ),
0194 
0195                        etsumParams = cms.untracked.PSet(
0196                    etsumBx    = cms.untracked.vint32( -2, -1,   0,  1,  2),
0197                etsumHwPt  = cms.untracked.vint32(  2,  1, 204,  3,  4),
0198                etsumHwPhi = cms.untracked.vint32(  2,  1,  20,  3,  4)
0199                )
0200                     )
0201 
0202 ## Load our L1 menu
0203 process.load('L1Trigger.L1TGlobal.GlobalParameters_cff')
0204 
0205 process.load("L1Trigger.L1TGlobal.TriggerMenu_cff")
0206 
0207 xmlMenu="L1Menu_Collisions2022_v1_1_0.xml"
0208 process.TriggerMenu.L1TriggerMenuFile = cms.string(xmlMenu)
0209 process.ESPreferL1TXML = cms.ESPrefer("L1TUtmTriggerMenuESProducer","TriggerMenu")
0210 
0211 process.dumpMenu = cms.EDAnalyzer("L1MenuViewer")
0212 # DEBUG: Information about names and types of algos parsed by the emulator from the menu
0213 #process.menuDumper = cms.EDAnalyzer("L1TUtmTriggerMenuDumper") 
0214 
0215 ## Fill External conditions
0216 process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0217 process.simGtExtFakeProd.bxFirst = cms.int32(-2)
0218 process.simGtExtFakeProd.bxLast = cms.int32(2)
0219 process.simGtExtFakeProd.setBptxAND   = cms.bool(True)
0220 process.simGtExtFakeProd.setBptxPlus  = cms.bool(True)
0221 process.simGtExtFakeProd.setBptxMinus = cms.bool(True)
0222 process.simGtExtFakeProd.setBptxOR    = cms.bool(True)
0223 
0224 
0225 ## Run the Stage 2 uGT emulator
0226 process.load('L1Trigger.L1TGlobal.simGtStage2Digis_cfi')
0227 process.simGtStage2Digis.PrescaleSet = cms.uint32(1)
0228 process.simGtStage2Digis.ExtInputTag = cms.InputTag("simGtExtFakeProd")
0229 process.simGtStage2Digis.MuonInputTag = cms.InputTag("gtInput")
0230 process.simGtStage2Digis.EGammaInputTag = cms.InputTag("gtInput")
0231 process.simGtStage2Digis.TauInputTag = cms.InputTag("gtInput")
0232 process.simGtStage2Digis.JetInputTag = cms.InputTag("gtInput")
0233 process.simGtStage2Digis.EtSumInputTag = cms.InputTag("gtInput")
0234 process.simGtStage2Digis.EmulateBxInEvent = cms.int32(1)
0235 #process.simGtStage2Digis.Verbosity = cms.untracked.int32(1)
0236 #process.simGtStage2Digis.AlgorithmTriggersUnprescaled = cms.bool(True)
0237 #process.simGtStage2Digis.AlgorithmTriggersUnmasked = cms.bool(True)
0238 
0239 process.dumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0240                 egInputTag    = cms.InputTag("gtInput"),
0241         muInputTag    = cms.InputTag("gtInput"),
0242         tauInputTag   = cms.InputTag("gtInput"),
0243         jetInputTag   = cms.InputTag("gtInput"),
0244         etsumInputTag = cms.InputTag("gtInput"),
0245         uGtAlgInputTag = cms.InputTag("simGtStage2Digis"),
0246         uGtExtInputTag = cms.InputTag("simGtExtFakeProd"),
0247         uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0248         bxOffset       = cms.int32(skip),
0249         minBx          = cms.int32(-2),
0250         maxBx          = cms.int32(2),
0251         minBxVec       = cms.int32(0),
0252         maxBxVec       = cms.int32(0),
0253         dumpGTRecord   = cms.bool(True),
0254         dumpGTObjectMap= cms.bool(False),
0255                 dumpTrigResults= cms.bool(False),
0256         dumpVectors    = cms.bool(True),
0257         tvFileName     = cms.string( ("TestVector_%03d.txt") % job ),
0258         tvVersion      = cms.int32(3),
0259                 ReadPrescalesFromFile = cms.bool(True),
0260                 psFileName     = cms.string( "prescale_L1TGlobal.csv" ),
0261                 psColumn       = cms.int32(1),
0262         unprescaleL1Algos = cms.bool(False),
0263                 unmaskL1Algos     = cms.bool(False)
0264          )
0265 
0266 process.load("L1Trigger.GlobalTriggerAnalyzer.l1GtTrigReport_cfi")
0267 process.l1GtTrigReport.L1GtRecordInputTag = "simGtStage2Digis"
0268 process.l1GtTrigReport.PrintVerbosity = 2
0269 process.report = cms.Path(process.l1GtTrigReport)
0270 
0271 process.MessageLogger.categories.append("MuConditon")
0272 
0273 if useMCtoGT:
0274     process.gtInput = process.mcL1GTinput.clone()
0275 else:
0276     process.gtInput = process.fakeL1GTinput.clone()
0277 
0278 # Setup Digi to Raw to Digi
0279 process.load('EventFilter.L1TRawToDigi.gtStage2Raw_cfi')
0280 process.gtStage2Raw.GtInputTag = cms.InputTag("simGtStage2Digis")
0281 process.gtStage2Raw.ExtInputTag = cms.InputTag("simGtExtFakeProd")
0282 process.gtStage2Raw.EGammaInputTag = cms.InputTag("gtInput")
0283 process.gtStage2Raw.TauInputTag = cms.InputTag("gtInput")
0284 process.gtStage2Raw.JetInputTag = cms.InputTag("gtInput")
0285 process.gtStage2Raw.EtSumInputTag = cms.InputTag("gtInput")
0286 process.gtStage2Raw.MuonInputTag = cms.InputTag("gtInput")
0287 
0288 process.load('EventFilter.L1TRawToDigi.gtStage2Digis_cfi')
0289 process.newGtStage2Digis = process.gtStage2Digis.clone()
0290 process.newGtStage2Digis.InputLabel = cms.InputTag('gtStage2Raw')
0291 # DEBUG 
0292 #process.newGtStage2Digis.debug = cms.untracked.bool(True) 
0293 
0294 process.dumpRaw = cms.EDAnalyzer(
0295     "DumpFEDRawDataProduct",
0296     label = cms.untracked.string("gtStage2Raw"),
0297     feds = cms.untracked.vint32 ( 1404 ),
0298     dumpPayload = cms.untracked.bool ( True )
0299 )
0300 
0301 process.newDumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0302                 egInputTag    = cms.InputTag("newGtStage2Digis","EGamma"),
0303         muInputTag    = cms.InputTag("newGtStage2Digis","Muon"),
0304         tauInputTag   = cms.InputTag("newGtStage2Digis","Tau"),
0305         jetInputTag   = cms.InputTag("newGtStage2Digis","Jet"),
0306         etsumInputTag = cms.InputTag("newGtStage2Digis","EtSum"),
0307         uGtAlgInputTag = cms.InputTag("newGtStage2Digis"),
0308         uGtExtInputTag = cms.InputTag("newGtStage2Digis"),
0309         uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0310         bxOffset       = cms.int32(skip),
0311         minBx          = cms.int32(0),
0312         maxBx          = cms.int32(0),
0313         minBxVec       = cms.int32(0),
0314         maxBxVec       = cms.int32(0),
0315         dumpGTRecord   = cms.bool(True),
0316         dumpGTObjectMap= cms.bool(True),
0317                 dumpTrigResults= cms.bool(False),
0318         dumpVectors    = cms.bool(False),
0319         tvFileName     = cms.string( ("TestVector_%03d.txt") % job ),
0320                 ReadPrescalesFromFile = cms.bool(False),
0321                 psFileName     = cms.string( "prescale_L1TGlobal.csv" ),
0322                 psColumn       = cms.int32(1)
0323          )
0324 
0325 # gt analyzer
0326 process.l1tGlobalAnalyzer = cms.EDAnalyzer('L1TGlobalAnalyzer',
0327     doText = cms.untracked.bool(False),
0328     gmuToken = cms.InputTag("None"),
0329     dmxEGToken = cms.InputTag("None"),
0330     dmxTauToken = cms.InputTag("None"),
0331     dmxJetToken = cms.InputTag("None"),
0332     dmxEtSumToken = cms.InputTag("None"),
0333     muToken = cms.InputTag("gtInput"),
0334     egToken = cms.InputTag("gtInput"),
0335     tauToken = cms.InputTag("gtInput"),
0336     jetToken = cms.InputTag("gtInput"),
0337     etSumToken = cms.InputTag("gtInput"),
0338     gtAlgToken = cms.InputTag("simGtStage2Digis"),
0339     emulDxAlgToken = cms.InputTag("None"),
0340     emulGtAlgToken = cms.InputTag("simGtStage2Digis")
0341 )
0342 
0343 
0344 
0345 process.p1 = cms.Path(
0346 
0347 ## Generate input, emulate, dump results
0348     process.dumpMenu
0349     *process.gtInput
0350 #    *process.dumpGT
0351     *process.simGtExtFakeProd
0352     *process.simGtStage2Digis
0353     *process.dumpGTRecord
0354 
0355 ## Sequence for packing and unpacking uGT data
0356 #    +process.gtStage2Raw
0357 #    +process.dumpRaw
0358 #    +process.newGtStage2Digis
0359 #    +process.newDumpGTRecord
0360 
0361 ## Analysis/Dumping
0362     *process.l1tGlobalAnalyzer
0363 #    *process.menuDumper # DEBUG -> to activate the menuDumper
0364 #    *process.debug
0365 #    *process.dumpED
0366 #    *process.dumpES
0367     )
0368 
0369 process.schedule = cms.Schedule(
0370     process.p1
0371     )
0372 #process.schedule.append(process.report)
0373 if rootout:
0374     process.outpath = cms.EndPath(process.output)
0375     process.schedule.append(process.outpath)
0376 
0377 # Spit out filter efficiency at the end.
0378 process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
0379 
0380 # Options for multithreading
0381 #process.options.numberOfThreads = cms.untracked.uint32( 2 )
0382 #process.options.numberOfStreams = cms.untracked.uint32( 0 )
0383 
0384 if dump:
0385     outfile = open('dump_runGlobalFakeInputProducer_'+repr(job)+'.py','w')
0386     print(process.dumpPython(), file=outfile)
0387     outfile.close()