Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-24 09:50:57

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