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 command line arguments of the form:
0007     testVectorCode_data.py nevents=-1
0008 The latter can be used to change parameters in crab.
0009 """
0010 
0011 job = 0 #job number
0012 njob = 1 #number of jobs
0013 nevents = 3564 #number of events
0014 rootout = False #whether to produce root file
0015 dump = False #dump python
0016 newXML = False #whether running with the new Grammar
0017 
0018 # ----------------
0019 # Argument parsing
0020 # ----------------
0021 if len(sys.argv) == 2 and ':' in sys.argv[1]:
0022     argv = sys.argv[1].split(':')
0023 else:
0024     argv = sys.argv[1:]
0025 
0026 for arg in argv:
0027     (k, v) = map(str.strip, arg.split('='))
0028     if k not in globals():
0029         raise "Unknown argument '%s'!" % (k,)
0030     if isinstance(globals()[k], bool):
0031         globals()[k] = v.lower() in ('y', 'yes', 'true', 't', '1')
0032     elif isinstance(globals()[k], int):
0033         globals()[k] = int(v)
0034     else:
0035         globals()[k] = v
0036 
0037 neventsPerJob = int(nevents/njob)
0038 skip = job * neventsPerJob
0039 
0040 if skip>4:
0041     skip = skip-4
0042     neventsPerJob = neventsPerJob+4
0043 
0044 # ------------------------------------------------------------
0045 # Set up Run 3 conditions to get the proper emulation sequence
0046 # ------------------------------------------------------------
0047 import FWCore.ParameterSet.Config as cms
0048 from Configuration.Eras.Era_Run3_cff import Run3
0049 process = cms.Process('L1TEMULATION', Run3)
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 # Message Logger output
0057 # ---------------------
0058 process.load('FWCore.MessageService.MessageLogger_cfi')
0059 
0060 # DEBUG
0061 process.load('L1Trigger/L1TGlobal/debug_messages_cfi')
0062 process.MessageLogger.l1t_debug.l1t.limit = cms.untracked.int32(100000)
0063 process.MessageLogger.categories.append('l1t|Global')
0064 # DEBUG
0065 #process.MessageLogger.debugModules = cms.untracked.vstring('simGtStage2Digis') 
0066 #process.MessageLogger.cerr.threshold = cms.untracked.string('DEBUG') 
0067 
0068 # ------------
0069 # Input source
0070 # ------------
0071 # Set the number of events
0072 process.maxEvents = cms.untracked.PSet(
0073     input = cms.untracked.int32(neventsPerJob)
0074     )
0075 
0076 # Set file: it needs to be a RAW format
0077 process.source = cms.Source("PoolSource",
0078     secondaryFileNames = cms.untracked.vstring(),
0079     fileNames = cms.untracked.vstring(
0080         "/store/data/Run2022G/EphemeralHLTPhysics0/RAW/v1/000/362/720/00000/36f350d4-8e8a-4e38-b399-77ad9bf351dc.root"
0081     ),
0082     skipEvents = cms.untracked.uint32(skip)
0083     )
0084 
0085 process.output =cms.OutputModule("PoolOutputModule",
0086         outputCommands = cms.untracked.vstring('keep *'),
0087     fileName = cms.untracked.string('testGlobalMCInputProducer_'+repr(job)+'.root')
0088     )
0089 
0090 process.options = cms.untracked.PSet(
0091     wantSummary = cms.bool(True)
0092 )
0093 
0094 # -----------------------------------------------
0095 # Additional output definition: TTree output file
0096 # -----------------------------------------------
0097 process.load("CommonTools.UtilAlgos.TFileService_cfi")
0098 process.TFileService.fileName = cms.string('l1t_histos.root')
0099 
0100 # ----------
0101 # Global Tag
0102 # ----------
0103 from Configuration.AlCa.GlobalTag import GlobalTag
0104 process.GlobalTag = GlobalTag(process.GlobalTag, '124X_dataRun3_Prompt_v4', '')
0105 
0106 # ----------------
0107 # Load the L1 menu
0108 # ----------------
0109 process.load('L1Trigger.L1TGlobal.GlobalParameters_cff')
0110 process.load("L1Trigger.L1TGlobal.TriggerMenu_cff")
0111 xmlMenu="L1Menu_Collisions2022_v1_4_0.xml"
0112 process.TriggerMenu.L1TriggerMenuFile = cms.string(xmlMenu)
0113 process.ESPreferL1TXML = cms.ESPrefer("L1TUtmTriggerMenuESProducer","TriggerMenu")
0114 
0115 process.dumpMenu = cms.EDAnalyzer("L1MenuViewer")
0116 # DEBUG: Information about names and types of algos parsed by the emulator from the menu
0117 #process.menuDumper = cms.EDAnalyzer("L1TUtmTriggerMenuDumper") 
0118 
0119 # -----------------------------------------
0120 # Load the GT inputs from the unpacker step
0121 # -----------------------------------------
0122 process.load('Configuration.StandardSequences.RawToDigi_cff')
0123 process.raw2digi_step = cms.Path(process.RawToDigi)
0124 
0125 process.dumpGT = cms.EDAnalyzer("l1t::GtInputDump",
0126                 egInputTag       = cms.InputTag("gtInput"),
0127         muInputTag       = cms.InputTag("gtInput"),
0128         muShowerInputTag = 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 # ------------------------
0139 # Fill External conditions
0140 # ------------------------
0141 process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0142 process.simGtExtFakeProd.bxFirst = cms.int32(-2)
0143 process.simGtExtFakeProd.bxLast = cms.int32(2)
0144 process.simGtExtFakeProd.setBptxAND   = cms.bool(True)
0145 process.simGtExtFakeProd.setBptxPlus  = cms.bool(True)
0146 process.simGtExtFakeProd.setBptxMinus = cms.bool(True)
0147 process.simGtExtFakeProd.setBptxOR    = cms.bool(True)
0148 
0149 # ----------------------------
0150 # Run the Stage 2 uGT emulator
0151 # ----------------------------
0152 process.load('L1Trigger.L1TGlobal.simGtStage2Digis_cfi')
0153 process.simGtStage2Digis.PrescaleSet = cms.uint32(1)
0154 process.simGtStage2Digis.ExtInputTag = cms.InputTag("simGtExtFakeProd")
0155 process.simGtStage2Digis.MuonInputTag = cms.InputTag("gtStage2Digis", "Muon")
0156 process.simGtStage2Digis.MuonShowerInputTag = cms.InputTag("gtStage2Digis", "MuonShower")
0157 process.simGtStage2Digis.EGammaInputTag = cms.InputTag("gtStage2Digis", "EGamma")
0158 process.simGtStage2Digis.TauInputTag = cms.InputTag("gtStage2Digis", "Tau")
0159 process.simGtStage2Digis.JetInputTag = cms.InputTag("gtStage2Digis", "Jet")
0160 process.simGtStage2Digis.EtSumInputTag = cms.InputTag("gtStage2Digis", "ETSum")
0161 process.simGtStage2Digis.EmulateBxInEvent = cms.int32(1)
0162 
0163 process.dumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0164                                       egInputTag       = cms.InputTag("gtStage2Digis", "EGamma"),
0165                               muInputTag       = cms.InputTag("gtStage2Digis", "Muon"),
0166                               muShowerInputTag = cms.InputTag("gtStage2Digis", "MuonShower"),
0167                               tauInputTag      = cms.InputTag("gtStage2Digis", "Tau"),
0168                                       jetInputTag      = cms.InputTag("gtStage2Digis", "Jet"),
0169                                       etsumInputTag    = cms.InputTag("gtStage2Digis", "ETSum"),
0170                                       uGtAlgInputTag   = cms.InputTag("simGtStage2Digis"),
0171                                       uGtExtInputTag   = cms.InputTag("simGtExtFakeProd"),
0172                                       uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0173                                       bxOffset       = cms.int32(skip),
0174                                       minBx          = cms.int32(-2),
0175                                       maxBx          = cms.int32(2),
0176                                       minBxVec       = cms.int32(0),
0177                                       maxBxVec       = cms.int32(0),
0178                                       dumpGTRecord   = cms.bool(True),
0179                                       dumpGTObjectMap= cms.bool(False),
0180                                       dumpTrigResults= cms.bool(False),
0181                                       dumpVectors    = cms.bool(True),
0182                                       tvFileName     = cms.string( ("TestVector_%03d.txt") % job ),
0183                                       tvVersion      = cms.int32(3),
0184                                       ReadPrescalesFromFile = cms.bool(True),
0185                                       psFileName     = cms.string( "prescale_L1TGlobal.csv" ),
0186                                       psColumn       = cms.int32(1),
0187                                       unprescaleL1Algos = cms.bool(False),
0188                                       unmaskL1Algos     = cms.bool(False)
0189          )
0190 
0191 process.load("L1Trigger.GlobalTriggerAnalyzer.l1GtTrigReport_cfi")
0192 process.l1GtTrigReport.L1GtRecordInputTag = "simGtStage2Digis"
0193 process.l1GtTrigReport.PrintVerbosity = 0 
0194 process.report = cms.Path(process.l1GtTrigReport)
0195 
0196 process.MessageLogger.categories.append("MuConditon")
0197 
0198 # -------------------------
0199 # Setup Digi to Raw to Digi
0200 # -------------------------
0201 process.load('EventFilter.L1TRawToDigi.gtStage2Raw_cfi')
0202 process.gtStage2Raw.GtInputTag = cms.InputTag("simGtStage2Digis")
0203 process.gtStage2Raw.ExtInputTag = cms.InputTag("simGtExtFakeProd")
0204 process.gtStage2Raw.EGammaInputTag = cms.InputTag("gtInput")
0205 process.gtStage2Raw.TauInputTag = cms.InputTag("gtInput")
0206 process.gtStage2Raw.JetInputTag = cms.InputTag("gtInput")
0207 process.gtStage2Raw.EtSumInputTag = cms.InputTag("gtInput")
0208 process.gtStage2Raw.MuonInputTag = cms.InputTag("gtInput")
0209 process.gtStage2Raw.MuonShowerInputTag = cms.InputTag("gtInput")
0210 
0211 process.load('EventFilter.L1TRawToDigi.gtStage2Digis_cfi')
0212 process.newGtStage2Digis = process.gtStage2Digis.clone()
0213 process.newGtStage2Digis.InputLabel = cms.InputTag('gtStage2Raw')
0214 # DEBUG 
0215 #process.newGtStage2Digis.debug = cms.untracked.bool(True) 
0216 
0217 process.dumpRaw = cms.EDAnalyzer(
0218     "DumpFEDRawDataProduct",
0219     label = cms.untracked.string("gtStage2Raw"),
0220     feds = cms.untracked.vint32 ( 1404 ),
0221     dumpPayload = cms.untracked.bool ( True )
0222 )
0223 
0224 process.newDumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0225                 egInputTag    = cms.InputTag("newGtStage2Digis","EGamma"),
0226         muInputTag    = cms.InputTag("newGtStage2Digis","Muon"),
0227         muShowerInputTag    = cms.InputTag("newGtStage2Digis","MuonShower"),
0228         tauInputTag   = cms.InputTag("newGtStage2Digis","Tau"),
0229         jetInputTag   = cms.InputTag("newGtStage2Digis","Jet"),
0230         etsumInputTag = cms.InputTag("newGtStage2Digis","EtSum"),
0231         uGtAlgInputTag = cms.InputTag("newGtStage2Digis"),
0232         uGtExtInputTag = cms.InputTag("newGtStage2Digis"),
0233         uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0234         bxOffset       = cms.int32(skip),
0235         minBx          = cms.int32(0),
0236         maxBx          = cms.int32(0),
0237         minBxVec       = cms.int32(0),
0238         maxBxVec       = cms.int32(0),
0239         dumpGTRecord   = cms.bool(True),
0240         dumpGTObjectMap= cms.bool(True),
0241                 dumpTrigResults= cms.bool(False),
0242         dumpVectors    = cms.bool(False),
0243         tvFileName     = cms.string( ("TestVector_%03d.txt") % job ),
0244                 ReadPrescalesFromFile = cms.bool(False),
0245                 psFileName     = cms.string( "prescale_L1TGlobal.csv" ),
0246                 psColumn       = cms.int32(1)
0247          )
0248 
0249 # -----------
0250 # GT analyzer
0251 # -----------
0252 process.l1tGlobalAnalyzer = cms.EDAnalyzer('L1TGlobalAnalyzer',
0253                                            doText = cms.untracked.bool(False),
0254                                            gmuToken = cms.InputTag("None"),
0255                                            dmxEGToken = cms.InputTag("None"),
0256                                            dmxTauToken = cms.InputTag("None"),
0257                                            dmxJetToken = cms.InputTag("None"),
0258                                            dmxEtSumToken = cms.InputTag("None"),
0259                                            muToken = cms.InputTag("gtStage2Digis", "Muon"),
0260                                            muShowerToken = cms.InputTag("gtStage2Digis", "MuonShower"),
0261                                            egToken = cms.InputTag("gtStage2Digis", "EGamma"),
0262                                            tauToken = cms.InputTag("gtStage2Digis", "Tau"),
0263                                            jetToken = cms.InputTag("gtStage2Digis", "Jet"),
0264                                            etSumToken = cms.InputTag("gtStage2Digis", "EtSum"),
0265                                            gtAlgToken = cms.InputTag("simGtStage2Digis"),
0266                                            emulDxAlgToken = cms.InputTag("None"),
0267                                            emulGtAlgToken = cms.InputTag("simGtStage2Digis")
0268 )
0269 
0270 # ------------------
0271 # Process definition
0272 # ------------------
0273 process.p1 = cms.Path(
0274     ## Input, emulation, dump of the results
0275     process.dumpMenu
0276     *process.RawToDigi 
0277     #*process.gtInput
0278     #*process.dumpGT
0279     *process.simGtExtFakeProd
0280     *process.simGtStage2Digis
0281     *process.dumpGTRecord
0282 
0283     ## Sequence for packing and unpacking uGT data
0284     #+process.gtStage2Raw
0285     #+process.dumpRaw
0286     #+process.newGtStage2Digis
0287     #+process.newDumpGTRecord
0288 
0289     ## Analysis/Dumping
0290     *process.l1tGlobalAnalyzer
0291     #*process.menuDumper # DEBUG -> to activate the menuDumper
0292     #*process.debug
0293     #*process.dumpED
0294     #*process.dumpES
0295     )
0296 
0297 # -------------------
0298 # Schedule definition
0299 # -------------------
0300 process.schedule = cms.Schedule(
0301     process.p1
0302 )
0303 #process.schedule.append(process.report)
0304 
0305 if rootout:
0306     process.outpath = cms.EndPath(process.output)
0307     process.schedule.append(process.outpath)
0308 
0309 # Spit out filter efficiency at the end
0310 process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
0311 
0312 # Options for multithreading
0313 #process.options.numberOfThreads = cms.untracked.uint32( 2 )
0314 #process.options.numberOfStreams = cms.untracked.uint32( 0 )
0315 
0316 if dump:
0317     outfile = open('dump_runGlobalFakeInputProducer_'+repr(job)+'.py','w')
0318     print(process.dumpPython(), file=outfile)
0319     outfile.close()