Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-27 04:18:03

0001 from __future__ import print_function
0002 #
0003 #  reEmul.py  configurable test of L1T re-emulation
0004 #
0005 #  Example Usage:
0006 #
0007 #     cmsRun reEmul.py                 : stage-2 re-emulation on 2015 zero-bias data
0008 #
0009 #     cmsRun reEmul.py era=stage1      : stage-1 re-emulation on 2015 zero-bias data
0010 #
0011 #     cmsRun reEmul.py era=stage2 output=mu_stage2.root input=/store/data/Run2015D/DoubleMuon/RAW/v1/000/260/627/00000/004EF961-6082-E511-BFB0-02163E011BC4.root max=10
0012 #                                      : stage-2 re-emulation on 2015 double muon data
0013 #
0014 #  Limitations:
0015 #
0016 #     - stage-1 re-emulation will complain about DT digi unpacking... harmless.  Will go away when we use GT for data + overrides for stage-1 emulation.
0017 #
0018 #     - stage-1 re-emulation does not put muons into the ntuple... will be fixed when legacy->upgrade converter is provided for muons.
0019 #
0020 
0021 import FWCore.ParameterSet.Config as cms
0022 import FWCore.ParameterSet.VarParsing as VarParsing
0023 from Configuration.Eras.Era_Run2_25ns_cff import Run2_25ns
0024 from Configuration.Eras.Era_Run2_2016_cff import Run2_2016
0025 from Configuration.Eras.Modifier_stage1L1Trigger_cff import stage1L1Trigger
0026 from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0027 import os
0028 import sys
0029 
0030 options = VarParsing.VarParsing ('analysis')
0031 
0032 options.register ('era',    'stage2',  VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string,  "The data taking Era: stage1 or stage2")
0033 options.register ('output', 'DEFAULT', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string,  "The output file name")
0034 options.register ('input',  '',        VarParsing.VarParsing.multiplicity.list,      VarParsing.VarParsing.varType.string,  "The input files")
0035 options.register ('max',    '',        VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,     "The maximum number of events to process")
0036 options.register ('skip',   '',        VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,     "The number of events to skip initially")
0037 
0038 ## options.input = '/store/data/Run2015D/ZeroBias/RAW/v1/000/260/627/00000/00A76FFA-0C82-E511-B441-02163E01450F.root'
0039 options.input = '/store/data/Run2015D/ZeroBias1/RAW/v1/000/256/843/00000/FE8AD1BB-D05E-E511-B3A7-02163E01276B.root'
0040 options.max  = 100 
0041 options.skip = 0 
0042 
0043 options.parseArguments()
0044 
0045 if (options.era == 'stage1'):
0046     print("INFO: runnings L1T Stage-1 (2015) Re-Emulation")
0047     process = cms.Process("L1TReEmulation", Run2_25ns)
0048 elif (options.era == 'stage2'):
0049     print("INFO: runnings L1T Stage-2 (2016) Re-Emulation")    
0050     process = cms.Process("L1TReEmulation", Run2_2016)
0051 else:
0052     print("ERROR: unknown era:  ", options.era, "\n")
0053     exit(0)
0054 
0055 if (options.output == 'DEFAULT'):
0056     tmp = cms.PSet(output = cms.string(""))
0057     stage1L1Trigger.toModify(tmp, output ='l1t_stage1.root')
0058     stage2L1Trigger.toModify(tmp, output ='l1t_stage2.root')
0059     options.output = tmp.output.value()
0060 print("INFO: output:  ", options.output)
0061 
0062 print("INFO: input:  ", options.input)
0063 print("INFO: max:  ", options.max)
0064 
0065 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0066 process.MessageLogger.cerr.FwkReport.reportEvery = cms.untracked.int32(50)
0067 process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(False))
0068 
0069 
0070 process.source = cms.Source(
0071     'PoolSource',
0072     fileNames = cms.untracked.vstring(options.input)
0073 )
0074 if options.skip > 0:
0075     process.source.skipEvents = cms.untracked.uint32(options.skip)
0076 
0077 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.max))
0078 
0079 # PostLS1 geometry used
0080 process.load('Configuration.Geometry.GeometryExtended2015Reco_cff')
0081 process.load('Configuration.Geometry.GeometryExtended2015_cff')
0082 ############################
0083 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0084 from Configuration.AlCa.GlobalTag import GlobalTag
0085 
0086 #   For stage-1, we are re-emulating L1T based on the conditions in the GT, so
0087 #   best for now to use MC GT, even when running over a data file, and just
0088 #   ignore the main DT TP emulator warnings...  (In future we'll override only
0089 #   L1T emulator related conditions, so you can use a data GT)
0090 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '')
0091 # Note:  For stage-2, all conditions are overriden by local config file.  Use data tag: 
0092 
0093 stage2L1Trigger.toReplaceWith(process.GlobalTag,
0094     #GlobalTag(process.GlobalTag, 'auto:run2_mc', '')
0095     GlobalTag(process.GlobalTag, 'auto:run2_data', '').clone(
0096     toGet = cms.VPSet(
0097         cms.PSet(record = cms.string("DTCCBConfigRcd"),
0098                  tag = cms.string("DTCCBConfig_NOSingleL_V05_mc"),
0099                  connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0100                  ),
0101 #        cms.PSet(record = cms.string("DTKeyedConfigListRcd"),
0102 #                 tag = cms.string("DTKeyedConfigContainer_NOSingleL_V05_mc"),
0103 #                 connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0104 #                 ),
0105         cms.PSet(record = cms.string("DTT0Rcd"),
0106                  tag = cms.string("DTt0_STARTUP_V02_mc"),
0107                  connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0108                  ),
0109         cms.PSet(record = cms.string("DTTPGParametersRcd"),
0110                  tag = cms.string("DTTPGParameters_V01_mc"),
0111                  connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0112                  ),
0113         )
0114 ))
0115 
0116 #### Sim L1 Emulator Sequence:
0117 process.load('Configuration.StandardSequences.RawToDigi_cff')
0118 #process.load('Configuration.StandardSequences.SimL1Emulator_cff')
0119 process.load('L1Trigger.Configuration.L1TReEmulateFromRAW_cff')
0120 process.dumpED = cms.EDAnalyzer("EventContentAnalyzer")
0121 process.dumpES = cms.EDAnalyzer("PrintEventSetupContent")
0122 
0123 
0124 
0125 
0126 
0127 import L1Trigger.L1TCommon.l1tSummaryStage1Digis_cfi
0128 import L1Trigger.L1TCommon.l1tSummaryStage2Digis_cf
0129 process.l1tSummaryA = L1Trigger.L1TCommon.l1tSummaryStage1Digis_cfi.l1tSummaryStage1Digis.clone()
0130 stage2L1Trigger.toReplaceWith(process.l1tSummaryA, L1Trigger.L1TCommon.l1tSummaryStage2Digis_cfi.l1tSummaryStage2Digis.clone())
0131 
0132 import L1Trigger.L1TCommon.l1tSummaryStage1SimDigis_cfi
0133 import L1Trigger.L1TCommon.l1tSummaryStage2SimDigis_cfi
0134 process.l1tSummaryB = L1Trigger.L1TCommon.l1tSummaryStage1SimDigis_cfi.l1tSummaryStage1SimDigis.clone()
0135 stage2L1Trigger.toReplaceWith(process.l1tSummaryB, L1Trigger.L1TCommon.l1tSummaryStage2SimDigis_cfi.l1tSummaryStage2SimDigis.clone())
0136 
0137 # Additional output definition
0138 # TTree output file
0139 process.load("CommonTools.UtilAlgos.TFileService_cfi")
0140 process.TFileService.fileName = cms.string(options.output)
0141 
0142 
0143 # enable debug message logging for our modules
0144 process.MessageLogger.L1TCaloEvents=dict()
0145 process.MessageLogger.L1TGlobalEvents=dict()
0146 process.MessageLogger.l1t=dict()
0147 process.MessageLogger.Global=dict()
0148 process.MessageLogger.suppressInfo = cms.untracked.vstring('Geometry', 'AfterSource')
0149 
0150 # gt analyzer
0151 process.l1tGlobalAnalyzer = cms.EDAnalyzer('L1TGlobalAnalyzer',
0152     doText = cms.untracked.bool(True),
0153     dmxEGToken = cms.InputTag("None"),
0154     dmxTauToken = cms.InputTag("None"),
0155     dmxJetToken = cms.InputTag("None"),
0156     dmxEtSumToken = cms.InputTag("None"),
0157     muToken = cms.InputTag("simGmtStage2Digis"),
0158     egToken = cms.InputTag("simCaloStage2Digis"),
0159     tauToken = cms.InputTag("simCaloStage2Digis"),
0160     jetToken = cms.InputTag("simCaloStage2Digis"),
0161     etSumToken = cms.InputTag("simCaloStage2Digis"),
0162     gtAlgToken = cms.InputTag("None"),
0163     emulDxAlgToken = cms.InputTag("simGlobalStage2Digis"),
0164     emulGtAlgToken = cms.InputTag("simGlobalStage2Digis")
0165 )
0166 
0167 process.l1EventTree = cms.EDAnalyzer("L1EventTreeProducer",
0168                                      hltSource            = cms.InputTag("TriggerResults::HLT"),
0169                                      puMCFile             = cms.untracked.string(""),
0170                                      puDataFile           = cms.untracked.string(""),
0171                                      puMCHist             = cms.untracked.string(""),
0172                                      puDataHist           = cms.untracked.string(""),
0173                                      
0174                                      useAvgVtx            = cms.untracked.bool(True),
0175                                      maxAllowedWeight     = cms.untracked.double(-1)                                     
0176 )
0177 
0178 # Stage-1 Ntuple will not contain muons, and might (investigating) miss some Taus.  (Work underway)
0179 process.l1UpgradeTree = cms.EDAnalyzer("L1UpgradeTreeProducer",
0180     egToken      = cms.untracked.InputTag("simCaloStage1FinalDigis"),
0181     tauTokens    = cms.untracked.VInputTag("simCaloStage1FinalDigis:rlxTaus","simCaloStage1FinalDigis:isoTaus"),
0182     jetToken     = cms.untracked.InputTag("simCaloStage1FinalDigis"),
0183     muonToken    = cms.untracked.InputTag("None"),
0184     sumToken     = cms.untracked.InputTag("simCaloStage1FinalDigis",""),
0185     maxL1Upgrade = cms.uint32(60)
0186 )
0187 stage2L1Trigger.toModify(process.l1UpgradeTree,
0188     egToken      = "simCaloStage2Digis",
0189     tauTokens    = ["simCaloStage2Digis"],
0190     jetToken     = "simCaloStage2Digis",
0191     muonToken    = "simGmtStage2Digis",
0192     sumToken     = "simCaloStage2Digis"
0193 )
0194 
0195 
0196 process.L1TSeq = cms.Sequence(   process.RawToDigi        
0197                                    + process.L1TReEmulateFromRAW
0198 #                                   + process.dumpED
0199 #                                   + process.dumpES
0200 #                                   + process.l1tSummaryA
0201 # Comment this next module to silence per event dump of L1T objects:
0202                                    + process.l1tSummaryB
0203 #                                   + process.l1tGlobalAnalyzer
0204                                    + process.l1UpgradeTree
0205                                    + process.l1EventTree                                 
0206 )
0207 
0208 process.L1TPath = cms.Path(process.L1TSeq)
0209 
0210 process.schedule = cms.Schedule(process.L1TPath)
0211 
0212 # Re-emulating, so don't unpack L1T output, might not even exist...
0213 # Also, remove uneeded unpackers for speed.
0214 stage2L1Trigger.toReplaceWith(process.L1TSeq, process.L1TSeq.copyAndExclude([
0215     process.gmtStage2Digis,
0216     process.caloStage2Digis,
0217     process.gtStage2Digis,
0218     process.siPixelDigis,
0219     process.siStripDigis,
0220     process.castorDigis,
0221     process.scalersRawToDigi,
0222     process.tcdsDigis
0223 ]))
0224 stage1L1Trigger.toReplaceWith(process.L1TSeq, process.L1TSeq.copyAndExclude([
0225     process.caloStage1Digis,
0226     process.caloStage1FinalDigis,
0227     process.gtDigis,
0228     process.siPixelDigis,
0229     process.siStripDigis,
0230     process.castorDigis,
0231     process.scalersRawToDigi,
0232     process.tcdsDigis
0233 ]))
0234 
0235 print(process.L1TSeq)
0236 print(process.L1TReEmulateFromRAW)
0237 #processDumpFile = open('config.dump', 'w')
0238 #print >> processDumpFile, process.dumpPython()
0239 
0240 
0241 #process.out = cms.OutputModule("PoolOutputModule", 
0242 #   fileName = cms.untracked.string("l1tbmtf.root")
0243 #)
0244 #process.output_step = cms.EndPath(process.out)
0245 #process.schedule.extend([process.output_step])