Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:10

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