Back to home page

Project CMSSW displayed by LXR

 
 

    


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