Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-15 23:40:48

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 
0021 # Set L1 tracking algorithm:
0022 # 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
0023 # 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
0024 # 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
0025 # (Or legacy algos 'TMTT' or 'TRACKLET').
0026 L1TRKALGO = 'HYBRID'
0027 
0028 WRITE_DATA = False
0029 
0030 ############################################################
0031 # import standard configurations
0032 ############################################################
0033 
0034 process.load('Configuration.StandardSequences.Services_cff')
0035 process.load('Configuration.EventContent.EventContent_cff')
0036 process.load('Configuration.StandardSequences.MagneticField_cff')
0037 
0038 process.load('FWCore.MessageService.MessageLogger_cfi')
0039 process.MessageLogger.L1track = dict(limit = -1)
0040 process.MessageLogger.Tracklet = dict(limit = -1)
0041 process.MessageLogger.TrackTriggerHPH = dict(limit = -1)
0042 
0043 if GEOMETRY == "D88" or GEOMETRY == 'D98':
0044     print("using geometry " + GEOMETRY + " (tilted)")
0045     process.load('Configuration.Geometry.GeometryExtended2026' + GEOMETRY + 'Reco_cff')
0046     process.load('Configuration.Geometry.GeometryExtended2026' + GEOMETRY +'_cff')
0047 else:
0048     print("this is not a valid geometry!!!")
0049 
0050 process.load('Configuration.StandardSequences.EndOfProcess_cff')
0051 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0052 
0053 from Configuration.AlCa.GlobalTag import GlobalTag
0054 # Change needed to run with D98 geometry in recent CMSSW versions.
0055 #process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')
0056 process.GlobalTag = GlobalTag(process.GlobalTag, '133X_mcRun4_realistic_v1', '')
0057 
0058 
0059 ############################################################
0060 # input and output
0061 ############################################################
0062 
0063 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(100))
0064 
0065 #--- To use MCsamples scripts, defining functions get*data*() for easy MC access,
0066 #--- follow instructions in https://github.com/cms-L1TK/MCsamples
0067 
0068 #from MCsamples.Scripts.getCMSdata_cfi import *
0069 #from MCsamples.Scripts.getCMSlocaldata_cfi import *
0070 
0071 if GEOMETRY == "D98":
0072 
0073   # Read data from card files (defines getCMSdataFromCards()):
0074   #from MCsamples.RelVal_1400_D98.PU200_TTbar_14TeV_cfi import *
0075   #inputMC = getCMSdataFromCards()
0076 
0077   # Or read .root files from directory on local computer:
0078   #dirName = "$scratchmc/MCsamples1400_D98/RelVal/TTbar/PU0/"
0079   #inputMC=getCMSlocaldata(dirName)
0080 
0081   # Or read specified dataset (accesses CMS DB, so use this method only occasionally):
0082   #dataName="/RelValTTbar_14TeV/CMSSW_14_0_0_pre2-PU_133X_mcRun4_realistic_v1_STD_2026D98_PU200_RV229-v1/GEN-SIM-DIGI-RAW"
0083   #inputMC=getCMSdata(dataName)
0084 
0085   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"]
0086 
0087 elif GEOMETRY == "D88":
0088 
0089   # Read specified .root file:
0090   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"]
0091 
0092 else:
0093 
0094   print("this is not a valid geometry!!!")
0095 
0096 process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(*inputMC))
0097 
0098 #if GEOMETRY == "D76":
0099 #  # If reading old MC dataset, drop incompatible EDProducts.
0100 #  process.source.dropDescendantsOfDroppedBranches = cms.untracked.bool(False)
0101 #  process.source.inputCommands = cms.untracked.vstring()
0102 #  process.source.inputCommands.append('keep  *_*_*Level1TTTracks*_*')
0103 #  process.source.inputCommands.append('keep  *_*_*StubAccepted*_*')
0104 #  process.source.inputCommands.append('keep  *_*_*ClusterAccepted*_*')
0105 #  process.source.inputCommands.append('keep  *_*_*MergedTrackTruth*_*')
0106 #  process.source.inputCommands.append('keep  *_genParticles_*_*')
0107 
0108 # Use skipEvents to select particular single events for test vectors
0109 #process.source.skipEvents = cms.untracked.uint32(11)
0110 
0111 process.TFileService = cms.Service("TFileService", fileName = cms.string('L1TrkNtuple.root'), closeFileFast = cms.untracked.bool(True))
0112 process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True))
0113 
0114 
0115 ############################################################
0116 # L1 tracking: stubs / DTC emulation
0117 ############################################################
0118 
0119 process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
0120 process.load('L1Trigger.TrackerTFP.ProducerES_cff')
0121 process.load('L1Trigger.TrackerTFP.ProducerLayerEncoding_cff')
0122 
0123 # remake stubs?
0124 #from L1Trigger.TrackTrigger.TTStubAlgorithmRegister_cfi import *
0125 #process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff")
0126 
0127 #from SimTracker.TrackTriggerAssociation.TTClusterAssociation_cfi import *
0128 #TTClusterAssociatorFromPixelDigis.digiSimLinks = cms.InputTag("simSiPixelDigis","Tracker")
0129 
0130 #process.TTClusterStub = cms.Path(process.TrackTriggerClustersStubs)
0131 #process.TTClusterStubTruth = cms.Path(process.TrackTriggerAssociatorClustersStubs)
0132 
0133 
0134 # DTC emulation
0135 process.load('L1Trigger.TrackerDTC.ProducerED_cff')
0136 
0137 # load code that analyzes DTCStubs
0138 #process.load('L1Trigger.TrackerDTC.Analyzer_cff')
0139 
0140 # modify default cuts
0141 #process.TrackTriggerSetup.FrontEnd.BendCut = 5.0
0142 #process.TrackTriggerSetup.Hybrid.MinPt = 1.0
0143 
0144 process.dtc = cms.Path(process.TrackerDTCProducer)#*process.TrackerDTCAnalyzer)
0145 # Throw error if reading MC produced with different stub window sizes.
0146 process.TrackerDTCProducer.CheckHistory = True
0147 
0148 ############################################################
0149 # L1 tracking
0150 ############################################################
0151 
0152 process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
0153 
0154 # HYBRID: prompt tracking
0155 if (L1TRKALGO == 'HYBRID'):
0156     process.TTTracksEmulation = cms.Path(process.L1THybridTracks)
0157     process.TTTracksEmulationWithTruth = cms.Path(process.L1THybridTracksWithAssociators)
0158     NHELIXPAR = 4
0159     L1TRK_NAME  = "l1tTTTracksFromTrackletEmulation"
0160     L1TRK_LABEL = "Level1TTTracks"
0161     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0162 
0163 # HYBRID: extended tracking
0164 elif (L1TRKALGO == 'HYBRID_DISPLACED'):
0165     process.TTTracksEmulation = cms.Path(process.L1TExtendedHybridTracks)
0166     process.TTTracksEmulationWithTruth = cms.Path(process.L1TExtendedHybridTracksWithAssociators)
0167     NHELIXPAR = 5
0168     L1TRK_NAME  = "l1tTTTracksFromExtendedTrackletEmulation"
0169     L1TRK_LABEL = "Level1TTTracks"
0170     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigisExtended"
0171 
0172 # HYBRID_NEWKF: prompt tracking or reduced
0173 elif (L1TRKALGO == 'HYBRID_NEWKF' or L1TRKALGO == 'HYBRID_REDUCED'):
0174     process.load( 'L1Trigger.TrackFindingTracklet.Producer_cff' )
0175     NHELIXPAR = 4
0176     L1TRK_NAME  = process.TrackFindingTrackletProducer_params.LabelKFout.value()
0177     L1TRK_LABEL = process.TrackFindingTrackletProducer_params.BranchAcceptedTTTracks.value()
0178     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0179     process.TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag( cms.InputTag(L1TRK_NAME, L1TRK_LABEL) )
0180     process.HybridNewKF = cms.Sequence(process.L1THybridTracks + process.TrackFindingTrackletProducerTBout + process.TrackFindingTrackletProducerDRin + process.TrackFindingTrackletProducerDR + process.TrackFindingTrackletProducerKFin + process.TrackFindingTrackletProducerKF + process.TrackFindingTrackletProducerKFout)
0181     process.TTTracksEmulation = cms.Path(process.HybridNewKF)
0182     #process.TTTracksEmulationWithTruth = cms.Path(process.HybridNewKF +  process.TrackTriggerAssociatorTracks)
0183     # Optionally include code producing performance plots & end-of-job summary.
0184     process.load( 'SimTracker.TrackTriggerAssociation.StubAssociator_cff' )
0185     process.load( 'L1Trigger.TrackFindingTracklet.Analyzer_cff' )
0186     process.TTTracksEmulationWithTruth = cms.Path(process.HybridNewKF +  process.TrackTriggerAssociatorTracks + process.StubAssociator +  process.TrackFindingTrackletAnalyzerTracklet + process.TrackFindingTrackletAnalyzerTBout + process.TrackFindingTrackletAnalyzerDRin + process.TrackFindingTrackletAnalyzerDR + process.TrackFindingTrackletAnalyzerKFin + process.TrackFindingTrackletAnalyzerKF + process.TrackFindingTrackletAnalyzerKFout)
0187     from L1Trigger.TrackFindingTracklet.Customize_cff import *
0188     if (L1TRKALGO == 'HYBRID_NEWKF'):
0189         fwConfig( process )
0190     if (L1TRKALGO == 'HYBRID_REDUCED'):
0191         reducedConfig( process )
0192     # Needed by L1TrackNtupleMaker
0193     process.HitPatternHelperSetup.useNewKF = True
0194 
0195 # LEGACY ALGORITHM (EXPERTS ONLY): TRACKLET
0196 elif (L1TRKALGO == 'TRACKLET'):
0197     print("\n WARNING: This is not the baseline algorithm! Prefer HYBRID or HYBRID_DISPLACED!")
0198     print("\n To run the Tracklet-only algorithm, ensure you have commented out 'CXXFLAGS=-DUSEHYBRID' in BuildFile.xml & recompiled! \n")
0199     process.TTTracksEmulation = cms.Path(process.L1THybridTracks)
0200     process.TTTracksEmulationWithTruth = cms.Path(process.L1THybridTracksWithAssociators)
0201     from L1Trigger.TrackFindingTracklet.Customize_cff import *
0202     trackletConfig( process )
0203     NHELIXPAR = 4
0204     L1TRK_NAME  = "l1tTTTracksFromTrackletEmulation"
0205     L1TRK_LABEL = "Level1TTTracks"
0206     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0207 
0208 # LEGACY ALGORITHM (EXPERTS ONLY): TMTT
0209 elif (L1TRKALGO == 'TMTT'):
0210     print("\n WARNING: This is not the baseline algorithm! Prefer HYBRID or HYBRID_DISPLACED! \n")
0211     process.load("L1Trigger.TrackFindingTMTT.TMTrackProducer_Ultimate_cff")
0212     L1TRK_PROC  =  process.TMTrackProducer
0213     L1TRK_NAME  = "TMTrackProducer"
0214     L1TRK_LABEL = "TML1TracksKF4ParamsComb"
0215     L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigis"
0216     NHELIXPAR = 4
0217     L1TRK_PROC.EnableMCtruth = cms.bool(False) # Reduce CPU use by disabling internal histos.
0218     L1TRK_PROC.EnableHistos  = cms.bool(False)
0219     process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
0220     process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff")
0221     process.TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag( cms.InputTag(L1TRK_NAME, L1TRK_LABEL) )
0222     process.TTTracksEmulation = cms.Path(process.offlineBeamSpot*L1TRK_PROC)
0223     process.TTTracksEmulationWithTruth = cms.Path(process.offlineBeamSpot*L1TRK_PROC*process.TrackTriggerAssociatorTracks)
0224 
0225 else:
0226     print("ERROR: Unknown L1TRKALGO option")
0227     exit(1)
0228 
0229 
0230 # Define L1 track ntuple maker
0231 from L1Trigger.TrackFindingTracklet.L1TrackNtupleMaker_cfi import *
0232 process.L1TrackNtuple = L1TrackNtupleMaker.clone(
0233    L1Tk_nPar = NHELIXPAR, # use 4 or 5-parameter L1 tracking?
0234    L1TrackInputTag = (L1TRK_NAME, L1TRK_LABEL),         # TTTrack input
0235    MCTruthTrackInputTag = (L1TRUTH_NAME, L1TRK_LABEL),  # MCTruth input
0236 )
0237 
0238 process.ana = cms.Path(process.L1TrackNtuple)
0239 
0240 
0241 ############################################################
0242 # final schedule of what is to be run
0243 ############################################################
0244 
0245 # use this if you want to re-run the stub making
0246 #process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0247 
0248 # use this if cluster/stub associators not available
0249 # process.schedule = cms.Schedule(process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0250 
0251 # use this to only run tracking + track associator
0252 process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.ana)
0253 
0254 
0255 ############################################################
0256 # write output dataset?
0257 ############################################################
0258 
0259 if (WRITE_DATA):
0260   process.writeDataset = cms.OutputModule("PoolOutputModule",
0261       splitLevel = cms.untracked.int32(0),
0262       eventAutoFlushCompressedSize = cms.untracked.int32(5242880),
0263       outputCommands = process.RAWSIMEventContent.outputCommands,
0264       fileName = cms.untracked.string('output_dataset.root'), ## ADAPT IT ##
0265       dataset = cms.untracked.PSet(
0266           filterName = cms.untracked.string(''),
0267           dataTier = cms.untracked.string('GEN-SIM')
0268       )
0269   )
0270   process.writeDataset.outputCommands.append('keep  *TTTrack*_*_*_*')
0271   process.writeDataset.outputCommands.append('keep  *TTStub*_*_*_*')
0272 
0273   process.pd = cms.EndPath(process.writeDataset)
0274   process.schedule.append(process.pd)
0275 
0276 
0277