Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-09-12 10:09:55

0001 #!/usr/bin/env python
0002 import sys
0003 
0004 """
0005 Description: script used for offline validation of the Global Trigger firmware and emulator agreement
0006 (Author: Elisa Fontanesi)
0007 -----------------------------------------------------------------------------------------------------
0008 The parameters can be changed by adding command line arguments of the form:
0009     testVectorCode_data.py nevents=-1
0010 The latter can be used to change parameters in crab.
0011 Running on 3564 events (=one orbit) is recommended for test vector production for GT firmware validation.
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 # ----------------
0022 # Argument parsing
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 # ------------------------------------------------------------
0050 # Set up Run 3 conditions to get the proper emulation sequence
0051 # ------------------------------------------------------------
0052 import FWCore.ParameterSet.Config as cms
0053 from Configuration.Eras.Era_Run3_cff import Run3
0054 process = cms.Process('L1TEMULATION', Run3)
0055 
0056 process.load('Configuration.StandardSequences.Services_cff')
0057 process.load("Configuration.StandardSequences.Accelerators_cff")
0058 process.load('Configuration/StandardSequences/FrontierConditions_GlobalTag_cff')
0059 
0060 # ---------------------
0061 # Message Logger output
0062 # ---------------------
0063 process.load('FWCore.MessageService.MessageLogger_cfi')
0064 # DEBUG
0065 process.MessageLogger.debugModules = ["simGtStage2Digis"]
0066 process.MessageLogger.debugModules = ["l1t|Global"]
0067 process.MessageLogger.cerr = cms.untracked.PSet(
0068     threshold = cms.untracked.string('DEBUG')
0069     )
0070 
0071 # DEBUG
0072 process.MessageLogger.l1t_debug = cms.untracked.PSet()
0073 process.MessageLogger.l1t = cms.untracked.PSet(
0074     limit = cms.untracked.int32(100000),
0075 )
0076 
0077 
0078 # ------------
0079 # Input source
0080 # ------------
0081 # Set the number of events
0082 process.maxEvents = cms.untracked.PSet(
0083     input = cms.untracked.int32(neventsPerJob)
0084 )
0085 
0086 # Set file: it needs to be a RAW format
0087 process.source = cms.Source("PoolSource",
0088     secondaryFileNames = cms.untracked.vstring(),
0089     fileNames = cms.untracked.vstring(
0090         "/store/data/Run2024E/EphemeralHLTPhysics0/RAW/v1/000/381/065/00000/0041494e-c2c5-4008-a687-5a856740b2f9.root",
0091         "/store/data/Run2024E/EphemeralHLTPhysics0/RAW/v1/000/381/065/00000/00dc1cfe-994b-4e7a-9ea5-7883435a95e2.root",
0092         "/store/data/Run2024E/EphemeralHLTPhysics0/RAW/v1/000/381/065/00000/007244f0-fbac-480a-a8b4-d7d6fd31b01f.root",
0093         "/store/data/Run2024E/EphemeralHLTPhysics0/RAW/v1/000/381/065/00000/033842c3-61c6-43af-8e9f-d698bfd10282.root",
0094         #"/store/data/Run2023D/EphemeralHLTPhysics0/RAW/v1/000/369/870/00000/8daa24c0-6005-41a8-a4f1-bd75b5bdf7a2.root",
0095         #"/store/data/Run2023D/EphemeralHLTPhysics0/RAW/v1/000/369/870/00000/cbe27e9e-1471-4eda-b011-5b56739f88bd.root",
0096         #"/store/data/Run2023D/EphemeralHLTPhysics0/RAW/v1/000/369/870/00000/03978c75-76b5-4334-aa88-9fb938f2540e.root",
0097         #"/store/data/Run2023D/EphemeralHLTPhysics0/RAW/v1/000/369/870/00000/e822a72d-988a-4cb0-9e40-f7b90fdeb6fc.root",
0098     ),
0099     skipEvents = cms.untracked.uint32(skip)
0100     )
0101 
0102 process.output =cms.OutputModule("PoolOutputModule",
0103         outputCommands = cms.untracked.vstring('keep *'),
0104     fileName = cms.untracked.string('testGlobalMCInputProducer_'+repr(job)+'.root')
0105     )
0106 
0107 process.options = cms.untracked.PSet(
0108     wantSummary = cms.bool(True)
0109 )
0110 
0111 # -----------------------------------------------
0112 # Additional output definition: TTree output file
0113 # -----------------------------------------------
0114 process.load("CommonTools.UtilAlgos.TFileService_cfi")
0115 process.TFileService.fileName = cms.string('l1t_histos.root')
0116 
0117 # ----------
0118 # Global Tag
0119 # ----------
0120 from Configuration.AlCa.GlobalTag import GlobalTag
0121 process.GlobalTag = GlobalTag(process.GlobalTag, '124X_dataRun3_Prompt_v4', '')
0122 
0123 # ----------------
0124 # Load the L1 menu
0125 # ----------------
0126 process.load('L1Trigger.L1TGlobal.GlobalParameters_cff')
0127 process.load("L1Trigger.L1TGlobal.TriggerMenu_cff")
0128 xmlMenu="L1Menu_Collisions2024_v1_3_0.xml"
0129 process.TriggerMenu.L1TriggerMenuFile = cms.string(xmlMenu)
0130 process.ESPreferL1TXML = cms.ESPrefer("L1TUtmTriggerMenuESProducer","TriggerMenu")
0131 
0132 process.dumpMenu = cms.EDAnalyzer("L1MenuViewer")
0133 # DEBUG: Information about names and types of algos parsed by the emulator from the menu
0134 process.menuDumper = cms.EDAnalyzer("L1TUtmTriggerMenuDumper") 
0135 
0136 # -----------------------------------------
0137 # Load the GT inputs from the unpacker step
0138 # -----------------------------------------
0139 process.load('Configuration.StandardSequences.RawToDigi_cff')
0140 process.raw2digi_step = cms.Path(process.RawToDigi)
0141 
0142 process.dumpGT = cms.EDAnalyzer("l1t::GtInputDump",
0143                 egInputTag       = cms.InputTag("gtInput"),
0144         muInputTag       = cms.InputTag("gtInput"),
0145         muShowerInputTag = cms.InputTag("gtInput"),
0146         tauInputTag      = cms.InputTag("gtInput"),
0147         jetInputTag      = cms.InputTag("gtInput"),
0148         etsumInputTag    = cms.InputTag("gtInput"),
0149         minBx            = cms.int32(0),
0150         maxBx            = cms.int32(0)
0151          )
0152 process.dumpED = cms.EDAnalyzer("EventContentAnalyzer")
0153 process.dumpES = cms.EDAnalyzer("PrintEventSetupContent")
0154 
0155 # ------------------------
0156 # Fill External conditions
0157 # ------------------------
0158 process.load('L1Trigger.L1TGlobal.simGtExtFakeProd_cfi')
0159 process.simGtExtFakeProd.bxFirst      = cms.int32(-2)
0160 process.simGtExtFakeProd.bxLast       = cms.int32(2)
0161 process.simGtExtFakeProd.setBptxAND   = cms.bool(True)
0162 process.simGtExtFakeProd.setBptxPlus  = cms.bool(True)
0163 process.simGtExtFakeProd.setBptxMinus = cms.bool(True)
0164 process.simGtExtFakeProd.setBptxOR    = cms.bool(True)
0165 
0166 # ----------------------------
0167 # Run the Stage 2 uGT emulator
0168 # ----------------------------
0169 process.load('L1Trigger.L1TGlobal.simGtStage2Digis_cfi')
0170 process.simGtStage2Digis.PrescaleSet         = cms.uint32(1)
0171 process.simGtStage2Digis.ExtInputTag         = cms.InputTag("simGtExtFakeProd")
0172 process.simGtStage2Digis.MuonInputTag        = cms.InputTag("gtStage2Digis", "Muon")
0173 process.simGtStage2Digis.MuonShowerInputTag  = cms.InputTag("gtStage2Digis", "MuonShower")
0174 process.simGtStage2Digis.EGammaInputTag      = cms.InputTag("gtStage2Digis", "EGamma")
0175 process.simGtStage2Digis.TauInputTag         = cms.InputTag("gtStage2Digis", "Tau")
0176 process.simGtStage2Digis.JetInputTag         = cms.InputTag("gtStage2Digis", "Jet")
0177 process.simGtStage2Digis.EtSumInputTag       = cms.InputTag("gtStage2Digis", "EtSum")
0178 process.simGtStage2Digis.EtSumZdcInputTag    = cms.InputTag("l1tZDCEtSums")
0179 process.simGtStage2Digis.EmulateBxInEvent    = cms.int32(1)
0180 
0181 process.dumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0182                                       egInputTag       = cms.InputTag("gtStage2Digis", "EGamma"),
0183                               muInputTag       = cms.InputTag("gtStage2Digis", "Muon"),
0184                               muShowerInputTag = cms.InputTag("gtStage2Digis", "MuonShower"),
0185                               tauInputTag      = cms.InputTag("gtStage2Digis", "Tau"),
0186                                       jetInputTag      = cms.InputTag("gtStage2Digis", "Jet"),
0187                                       etsumInputTag    = cms.InputTag("gtStage2Digis", "EtSum"),
0188                                       uGtAlgInputTag   = cms.InputTag("simGtStage2Digis"),
0189                                       uGtExtInputTag   = cms.InputTag("simGtExtFakeProd"),
0190                                       uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0191                                       bxOffset       = cms.int32(skip),
0192                                       minBx          = cms.int32(-2),
0193                                       maxBx          = cms.int32(2),
0194                                       minBxVec       = cms.int32(0),
0195                                       maxBxVec       = cms.int32(0),
0196                                       dumpGTRecord   = cms.bool(True),
0197                                       dumpGTObjectMap= cms.bool(False),
0198                                       dumpTrigResults= cms.bool(False),
0199                                       dumpVectors    = cms.bool(True),
0200                                       tvFileName     = cms.string( ("TestVector_%03d.txt") % job ),
0201                                       tvVersion      = cms.int32(3),
0202                                       ReadPrescalesFromFile = cms.bool(True),
0203                                       psFileName     = cms.string( "prescale_L1TGlobal.csv" ),
0204                                       psColumn       = cms.int32(1),
0205                                       unprescaleL1Algos = cms.bool(False),
0206                                       unmaskL1Algos     = cms.bool(False)
0207          )
0208 
0209 process.load("L1Trigger.GlobalTriggerAnalyzer.l1GtTrigReport_cfi")
0210 process.l1GtTrigReport.L1GtRecordInputTag = "simGtStage2Digis"
0211 process.l1GtTrigReport.PrintVerbosity = 0 
0212 process.report = cms.Path(process.l1GtTrigReport)
0213 
0214 process.MessageLogger.debugModules = ["MuCondition"]
0215 
0216 # -------------------------
0217 # Setup Digi to Raw to Digi
0218 # -------------------------
0219 process.load('EventFilter.L1TRawToDigi.gtStage2Raw_cfi')
0220 
0221 process.gtStage2Raw.GtInputTag         = cms.InputTag("simGtStage2Digis")
0222 process.gtStage2Raw.ExtInputTag        = cms.InputTag("simGtExtFakeProd")
0223 process.gtStage2Raw.EGammaInputTag     = cms.InputTag("gtInput")
0224 process.gtStage2Raw.TauInputTag        = cms.InputTag("gtInput")
0225 process.gtStage2Raw.JetInputTag        = cms.InputTag("gtInput")
0226 process.gtStage2Raw.EtSumInputTag      = cms.InputTag("gtInput")
0227 process.gtStage2Raw.MuonInputTag       = cms.InputTag("gtInput")
0228 process.gtStage2Raw.MuonShowerInputTag = cms.InputTag("gtInput")
0229 
0230 process.load('EventFilter.L1TRawToDigi.gtStage2Digis_cfi')
0231 process.newGtStage2Digis               = process.gtStage2Digis.clone()
0232 process.newGtStage2Digis.InputLabel    = cms.InputTag('gtStage2Raw')
0233 # DEBUG 
0234 #process.newGtStage2Digis.debug = cms.untracked.bool(True) 
0235 
0236 process.dumpRaw = cms.EDAnalyzer(
0237     "DumpFEDRawDataProduct",
0238     label = cms.untracked.string("gtStage2Raw"),
0239     feds = cms.untracked.vint32 ( 1404 ),
0240     dumpPayload = cms.untracked.bool ( True )
0241 )
0242 
0243 process.newDumpGTRecord = cms.EDAnalyzer("l1t::GtRecordDump",
0244                 egInputTag       = cms.InputTag("newGtStage2Digis","EGamma"),
0245         muInputTag       = cms.InputTag("newGtStage2Digis","Muon"),
0246         muShowerInputTag = cms.InputTag("newGtStage2Digis","MuonShower"),
0247         tauInputTag      = cms.InputTag("newGtStage2Digis","Tau"),
0248         jetInputTag      = cms.InputTag("newGtStage2Digis","Jet"),
0249         etsumInputTag    = cms.InputTag("newGtStage2Digis","EtSum"),
0250         uGtAlgInputTag   = cms.InputTag("newGtStage2Digis"),
0251         uGtExtInputTag   = cms.InputTag("newGtStage2Digis"),
0252         uGtObjectMapInputTag = cms.InputTag("simGtStage2Digis"),
0253         bxOffset        = cms.int32(skip),
0254         minBx           = cms.int32(0),
0255         maxBx           = cms.int32(0),
0256         minBxVec        = cms.int32(0),
0257         maxBxVec        = cms.int32(0),
0258         dumpGTRecord    = cms.bool(True),
0259         dumpGTObjectMap = cms.bool(True),
0260                 dumpTrigResults = cms.bool(False),
0261         dumpVectors     = cms.bool(False),
0262         tvFileName      = cms.string( ("TestVector_%03d.txt") % job ),
0263                 ReadPrescalesFromFile = cms.bool(False),
0264                 psFileName      = cms.string( "prescale_L1TGlobal.csv" ),
0265                 psColumn        = cms.int32(1)
0266          )
0267 
0268 # -----------
0269 # GT analyzer
0270 # -----------
0271 process.l1tGlobalAnalyzer = cms.EDAnalyzer('L1TGlobalAnalyzer',
0272                                            doText         = cms.untracked.bool(False),
0273                                            gmuToken       = cms.InputTag("None"),
0274                                            dmxEGToken     = cms.InputTag("None"),
0275                                            dmxTauToken    = cms.InputTag("None"),
0276                                            dmxJetToken    = cms.InputTag("None"),
0277                                            dmxEtSumToken  = cms.InputTag("None"),
0278                                            muToken        = cms.InputTag("gtStage2Digis", "Muon"),
0279                                            muShowerToken  = cms.InputTag("gtStage2Digis", "MuonShower"),
0280                                            egToken        = cms.InputTag("gtStage2Digis", "EGamma"),
0281                                            tauToken       = cms.InputTag("gtStage2Digis", "Tau"),
0282                                            jetToken       = cms.InputTag("gtStage2Digis", "Jet"),
0283                                            etSumToken     = cms.InputTag("gtStage2Digis", "EtSum"),
0284                                            gtAlgToken     = cms.InputTag("simGtStage2Digis"),
0285                                            emulDxAlgToken = cms.InputTag("None"),
0286                                            emulGtAlgToken = cms.InputTag("simGtStage2Digis")
0287 )
0288 
0289 # ------------------
0290 # Process definition
0291 # ------------------
0292 process.p1 = cms.Path(
0293     ## Input, emulation, dump of the results
0294     process.dumpMenu
0295     *process.RawToDigi 
0296     #*process.gtInput
0297     #*process.dumpGT
0298     *process.simGtExtFakeProd
0299     *process.simGtStage2Digis
0300     *process.dumpGTRecord
0301 
0302     ## Sequence for packing and unpacking uGT data
0303     #+process.gtStage2Raw
0304     #+process.dumpRaw
0305     #+process.newGtStage2Digis
0306     #+process.newDumpGTRecord
0307 
0308     ## Analysis/Dumping
0309     *process.l1tGlobalAnalyzer
0310     #*process.menuDumper # DEBUG -> to activate the menuDumper
0311     #*process.debug
0312     #*process.dumpED
0313     #*process.dumpES
0314     )
0315 
0316 # -------------------
0317 # Schedule definition
0318 # -------------------
0319 process.schedule = cms.Schedule(
0320     process.p1
0321 )
0322 #process.schedule.append(process.report)
0323 
0324 if rootout:
0325     process.outpath = cms.EndPath(process.output)
0326     process.schedule.append(process.outpath)
0327 
0328 # Final summary of the efficiency
0329 process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
0330 
0331 # Options for multithreading
0332 #process.options.numberOfThreads = cms.untracked.uint32( 2 )
0333 #process.options.numberOfStreams = cms.untracked.uint32( 0 )
0334 
0335 if dump:
0336     outfile = open('dump_testVectorCode_data_'+repr(job)+'.py','w')
0337     print(process.dumpPython(), file=outfile)
0338     outfile.close()