Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-03 00:12:26

0001 # N,B, DUE TO THE CHANGE IN STUB WINDOW SIZES WITH CMSSW 14_2_0_PRE2, THIS JOB HAS BEEN NODIFIED TO
0002 # RECREATE THE STUBS, WHICH IS NECESSARY WHEN RUNNING ON MONTE CARLO GENERATED WITH OLDER VERSIONS.
0003 
0004 ############################################################
0005 # define basic process
0006 ############################################################
0007 
0008 import FWCore.ParameterSet.Config as cms
0009 import FWCore.Utilities.FileUtils as FileUtils
0010 import os
0011 process = cms.Process("L1TrackNtuple")
0012 
0013 ############################################################
0014 # edit options here
0015 ############################################################
0016 
0017 # D88 was used for CMSSW_12_6 datasets, and D98 recommended for more recent ones.
0018 #GEOMETRY = "D88"
0019 #GEOMETRY = "D98"
0020 GEOMETRY = "D110"
0021 
0022 # Set L1 tracking algorithm:
0023 # 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
0024 # 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
0025 # 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
0026 # (Or legacy algos 'TMTT' or 'TRACKLET').
0027 L1TRKALGO = 'HYBRID'
0028 
0029 WRITE_DATA = False
0030 
0031 ############################################################
0032 # import standard configurations
0033 ############################################################
0034 
0035 process.load('Configuration.StandardSequences.Services_cff')
0036 process.load('Configuration.EventContent.EventContent_cff')
0037 process.load('Configuration.StandardSequences.MagneticField_cff')
0038 
0039 process.load('FWCore.MessageService.MessageLogger_cfi')
0040 process.MessageLogger.L1track = dict(limit = -1)
0041 process.MessageLogger.Tracklet = dict(limit = -1)
0042 process.MessageLogger.TrackTriggerHPH = dict(limit = -1)
0043 
0044 
0045 print("using geometry " + GEOMETRY + " (tilted)")
0046 process.load('Configuration.Geometry.GeometryExtendedRun4' + GEOMETRY + 'Reco_cff')
0047 process.load('Configuration.Geometry.GeometryExtendedRun4' + GEOMETRY +'_cff')
0048 process.load('Configuration.StandardSequences.EndOfProcess_cff')
0049 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0050 from Configuration.AlCa.GlobalTag import GlobalTag
0051 # Change needed to run with D98 geometry in recent CMSSW versions.
0052 if GEOMETRY == "D88" or GEOMETRY == 'D98':
0053     process.GlobalTag = GlobalTag(process.GlobalTag, '133X_mcRun4_realistic_v1', '')
0054 elif GEOMETRY == 'D110':
0055     process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')
0056 else:
0057     print("this is not a valid geometry!!!")
0058 
0059 process.load('Configuration.StandardSequences.EndOfProcess_cff')
0060 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0061 
0062 
0063 ############################################################
0064 # input and output
0065 ############################################################
0066 
0067 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1000))
0068 
0069 #--- To use MCsamples scripts, defining functions get*data*() for easy MC access,
0070 #--- follow instructions in https://github.com/cms-L1TK/MCsamples
0071 
0072 #from MCsamples.Scripts.getCMSdata_cfi import *
0073 #from MCsamples.Scripts.getCMSlocaldata_cfi import *
0074 
0075 if GEOMETRY == "D98":
0076 
0077   # Read data from card files (defines getCMSdataFromCards()):
0078   #from MCsamples.RelVal_1400_D98.PU200_TTbar_14TeV_cfi import *
0079   #inputMC = getCMSdataFromCards()
0080 
0081   # Or read .root files from directory on local computer:
0082   #dirName = "$scratchmc/MCsamples1400_D98/RelVal/TTbar/PU0/"
0083   #inputMC=getCMSlocaldata(dirName)
0084 
0085   # Or read specified dataset (accesses CMS DB, so use this method only occasionally):
0086   #dataName="/RelValTTbar_14TeV/CMSSW_14_0_0_pre2-PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/GEN-SIM-DIGI-RAW"
0087   #inputMC=getCMSdata(dataName)
0088 
0089   inputMC = [#"/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/0b2b0b0b-f312-48a8-9d46-ccbadc69bbfd.root"
0090     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/0b2b0b0b-f312-48a8-9d46-ccbadc69bbfd.root',
0091     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/0c3cb20d-8556-450d-b4f0-e5c754818f74.root',
0092     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/0eafa2b4-711a-43ec-be1c-7e564c294a9a.root',
0093     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1450b1bb-171e-495e-a767-68e2796d95c2.root',
0094     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/15498564-9cf0-4219-aab7-f97b3484b122.root',
0095     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1838a806-316b-4f53-9d22-5b3856019623.root',
0096     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1a34eb87-b9a3-47fb-b945-57e6f775fcac.root',
0097     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1add5b2e-19cb-4581-956d-271907d03b72.root',
0098     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1bed1837-ef65-4e07-a2ac-13c705b20fc1.root',
0099     '/store/relval/CMSSW_14_0_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/2580000/1d057884-72bd-4353-8375-ec4616c00a33.root'
0100   ]
0101 
0102 elif GEOMETRY == "D88":
0103 
0104   # Read specified .root file:
0105   inputMC = ["/store/mc/CMSSW_12_6_0/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_125X_mcRun4_realistic_v5_2026D88PU200RV183v2-v1/30000/0959f326-3f52-48d8-9fcf-65fc41de4e27.root"]
0106 
0107 elif GEOMETRY == "D110":
0108 
0109   # Read specified .root file:
0110   inputMC = ["/store/mc/Phase2Spring24DIGIRECOMiniAOD/TT_TuneCP5_14TeV-powheg-pythia8/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_140X_mcRun4_realistic_v4-v2/130000/00c7f40e-b44e-4eea-a86b-def8f7d82b0e.root"]
0111 
0112 else:
0113 
0114   print("this is not a valid geometry!!!")
0115 
0116 process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(*inputMC))
0117 
0118 #if GEOMETRY == "D76":
0119 #  # If reading old MC dataset, drop incompatible EDProducts.
0120 #  process.source.dropDescendantsOfDroppedBranches = cms.untracked.bool(False)
0121 #  process.source.inputCommands = cms.untracked.vstring()
0122 #  process.source.inputCommands.append('keep  *_*_*Level1TTTracks*_*')
0123 #  process.source.inputCommands.append('keep  *_*_*StubAccepted*_*')
0124 #  process.source.inputCommands.append('keep  *_*_*ClusterAccepted*_*')
0125 #  process.source.inputCommands.append('keep  *_*_*MergedTrackTruth*_*')
0126 #  process.source.inputCommands.append('keep  *_genParticles_*_*')
0127 
0128 # Use skipEvents to select particular single events for test vectors
0129 #process.source.skipEvents = cms.untracked.uint32(11)
0130 
0131 process.TFileService = cms.Service("TFileService", fileName = cms.string('L1TrkNtuple.root'), closeFileFast = cms.untracked.bool(True))
0132 process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True))
0133 
0134 
0135 ############################################################
0136 # L1 tracking: stubs / DTC emulation
0137 ############################################################
0138 
0139 process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
0140 
0141 # remake stubs?
0142 #from L1Trigger.TrackTrigger.TTStubAlgorithmRegister_cfi import *
0143 #process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff")
0144 
0145 #from SimTracker.TrackTriggerAssociation.TTClusterAssociation_cfi import *
0146 #TTClusterAssociatorFromPixelDigis.digiSimLinks = cms.InputTag("simSiPixelDigis","Tracker")
0147 
0148 #process.TTClusterStub = cms.Path(process.TrackTriggerClustersStubs)
0149 #process.TTClusterStubTruth = cms.Path(process.TrackTriggerAssociatorClustersStubs)
0150 
0151 
0152 # load code that associates stubs with mctruth
0153 process.load( 'SimTracker.TrackTriggerAssociation.StubAssociator_cff' )
0154 # DTC emulation
0155 process.load('L1Trigger.TrackerDTC.DTC_cff')
0156 
0157 # load code that analyzes DTCStubs
0158 process.load('L1Trigger.TrackerDTC.Analyzer_cff')
0159 
0160 # modify default cuts
0161 #process.TrackTriggerSetup.FrontEnd.BendCut = 5.0
0162 #process.TrackTriggerSetup.Hybrid.MinPt = 1.0
0163 
0164 process.dtc = cms.Path(process.StubAssociator + process.ProducerDTC + process.AnalyzerDTC)
0165 
0166 ############################################################
0167 # L1 tracking
0168 ############################################################
0169 
0170 process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
0171 
0172 # HYBRID: prompt tracking
0173 if (L1TRKALGO == 'HYBRID'):
0174     process.load( 'L1Trigger.TrackFindingTracklet.Analyzer_cff' )
0175     process.TTTracksEmulation = cms.Path(process.L1THybridTracks)
0176     process.TTTracksEmulationWithTruth = cms.Path(process.L1THybridTracksWithAssociators + process.AnalyzerTracklet)
0177     NHELIXPAR = 4
0178     L1TRK_NAME  = "l1tTTTracksFromTrackletEmulation"
0179     L1TRK_LABEL = "Level1TTTracks"
0180     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0181 
0182 # HYBRID: extended tracking
0183 elif (L1TRKALGO == 'HYBRID_DISPLACED'):
0184     process.TTTracksEmulation = cms.Path(process.L1TExtendedHybridTracks)
0185     process.TTTracksEmulationWithTruth = cms.Path(process.L1TExtendedHybridTracksWithAssociators)
0186     NHELIXPAR = 5
0187     L1TRK_NAME  = "l1tTTTracksFromExtendedTrackletEmulation"
0188     L1TRK_LABEL = "Level1TTTracks"
0189     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigisExtended"
0190 
0191 # HYBRID_NEWKF: prompt tracking or reduced
0192 elif (L1TRKALGO == 'HYBRID_NEWKF' or L1TRKALGO == 'HYBRID_REDUCED'):
0193     process.load( 'L1Trigger.TrackFindingTracklet.Producer_cff' )
0194     process.load( 'L1Trigger.TrackFindingTracklet.Analyzer_cff' )
0195     NHELIXPAR = 4
0196     L1TRK_NAME  = process.TrackFindingTrackletAnalyzer_params.OutputLabelTFP.value()
0197     L1TRK_LABEL = process.TrackFindingTrackletProducer_params.BranchTTTracks.value()
0198     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0199     process.TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag( cms.InputTag(L1TRK_NAME, L1TRK_LABEL) )
0200     process.HybridNewKF = cms.Sequence(process.L1THybridTracks + process.ProducerTM + process.ProducerDR + process.ProducerKF + process.ProducerTQ + process.ProducerTFP)
0201     process.TTTracksEmulation = cms.Path(process.HybridNewKF)
0202     #process.TTTracksEmulationWithTruth = cms.Path(process.HybridNewKF +  process.TrackTriggerAssociatorTracks)
0203     # Optionally include code producing performance plots & end-of-job summary.
0204     process.load( 'SimTracker.TrackTriggerAssociation.StubAssociator_cff' )
0205     process.TTTracksEmulationWithTruth = cms.Path(process.HybridNewKF +  process.TrackTriggerAssociatorTracks + process.StubAssociator +  process.AnalyzerTracklet + process.AnalyzerTM + process.AnalyzerDR + process.AnalyzerKF + process.AnalyzerTQ + process.AnalyzerTFP )
0206     from L1Trigger.TrackFindingTracklet.Customize_cff import *
0207     if (L1TRKALGO == 'HYBRID_NEWKF'):
0208         fwConfig( process )
0209     if (L1TRKALGO == 'HYBRID_REDUCED'):
0210         reducedConfig( process )
0211     # Needed by L1TrackNtupleMaker
0212     process.HitPatternHelperSetup.useNewKF = True
0213 
0214 # LEGACY ALGORITHM (EXPERTS ONLY): TRACKLET
0215 elif (L1TRKALGO == 'TRACKLET'):
0216     print("\n WARNING: This is not the baseline algorithm! Prefer HYBRID or HYBRID_DISPLACED!")
0217     print("\n To run the Tracklet-only algorithm, ensure you have commented out 'CXXFLAGS=-DUSEHYBRID' in BuildFile.xml & recompiled! \n")
0218     process.TTTracksEmulation = cms.Path(process.L1THybridTracks)
0219     process.TTTracksEmulationWithTruth = cms.Path(process.L1THybridTracksWithAssociators)
0220     from L1Trigger.TrackFindingTracklet.Customize_cff import *
0221     trackletConfig( process )
0222     NHELIXPAR = 4
0223     L1TRK_NAME  = "l1tTTTracksFromTrackletEmulation"
0224     L1TRK_LABEL = "Level1TTTracks"
0225     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0226 
0227 # LEGACY ALGORITHM (EXPERTS ONLY): TMTT
0228 elif (L1TRKALGO == 'TMTT'):
0229     print("\n WARNING: This is not the baseline algorithm! Prefer HYBRID or HYBRID_DISPLACED! \n")
0230     process.load("L1Trigger.TrackFindingTMTT.TMTrackProducer_Ultimate_cff")
0231     L1TRK_PROC  =  process.TMTrackProducer
0232     L1TRK_NAME  = "TMTrackProducer"
0233     L1TRK_LABEL = "TML1TracksKF4ParamsComb"
0234     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0235     NHELIXPAR = 4
0236     L1TRK_PROC.EnableMCtruth = cms.bool(False) # Reduce CPU use by disabling internal histos.
0237     L1TRK_PROC.EnableHistos  = cms.bool(False)
0238     process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
0239     process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff")
0240     process.TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag( cms.InputTag(L1TRK_NAME, L1TRK_LABEL) )
0241     process.TTTracksEmulation = cms.Path(process.offlineBeamSpot*L1TRK_PROC)
0242     process.TTTracksEmulationWithTruth = cms.Path(process.offlineBeamSpot*L1TRK_PROC*process.TrackTriggerAssociatorTracks)
0243 
0244 else:
0245     print("ERROR: Unknown L1TRKALGO option")
0246     exit(1)
0247 
0248 
0249 # Define L1 track ntuple maker
0250 from L1Trigger.TrackFindingTracklet.L1TrackNtupleMaker_cfi import *
0251 process.L1TrackNtuple = L1TrackNtupleMaker.clone(
0252    L1Tk_nPar = NHELIXPAR, # use 4 or 5-parameter L1 tracking?
0253    L1TrackInputTag = (L1TRK_NAME, L1TRK_LABEL),         # TTTrack input
0254    MCTruthTrackInputTag = (L1TRUTH_NAME, L1TRK_LABEL),  # MCTruth input
0255 )
0256 
0257 process.ana = cms.Path(process.L1TrackNtuple)
0258 
0259 
0260 ############################################################
0261 # final schedule of what is to be run
0262 ############################################################
0263 
0264 # use this if you want to re-run the stub making
0265 #process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0266 
0267 # use this if cluster/stub associators not available
0268 # process.schedule = cms.Schedule(process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0269 
0270 # use this to only run tracking + track associator
0271 process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0272 
0273 
0274 ############################################################
0275 # write output dataset?
0276 ############################################################
0277 
0278 if (WRITE_DATA):
0279   process.writeDataset = cms.OutputModule("PoolOutputModule",
0280       splitLevel = cms.untracked.int32(0),
0281       eventAutoFlushCompressedSize = cms.untracked.int32(5242880),
0282       outputCommands = process.RAWSIMEventContent.outputCommands,
0283       fileName = cms.untracked.string('output_dataset.root'), ## ADAPT IT ##
0284       dataset = cms.untracked.PSet(
0285           filterName = cms.untracked.string(''),
0286           dataTier = cms.untracked.string('GEN-SIM')
0287       )
0288   )
0289   process.writeDataset.outputCommands.append('keep  *TTTrack*_*_*_*')
0290   process.writeDataset.outputCommands.append('keep  *TTStub*_*_*_*')
0291 
0292   process.pd = cms.EndPath(process.writeDataset)
0293   process.schedule.append(process.pd)
0294 
0295 
0296