Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:13:43

0001 ################################################################################################
0002 # To run execute do
0003 # cmsRun tmtt_tf_analysis_cfg.py Events=50 inputMC=Samples/Muons/PU0.txt histFile=outputHistFile.root 
0004 # where the arguments take default values if you don't specify them. You can change defaults below.
0005 #################################################################################################
0006 
0007 import FWCore.ParameterSet.Config as cms
0008 import FWCore.Utilities.FileUtils as FileUtils
0009 import FWCore.ParameterSet.VarParsing as VarParsing
0010 import os
0011 
0012 process = cms.Process("Demo")
0013 
0014 GEOMETRY = "D76"
0015 
0016 if GEOMETRY == "D49": 
0017     print("using geometry " + GEOMETRY + " (tilted)")
0018     process.load('Configuration.Geometry.GeometryExtended2026D49Reco_cff')
0019     process.load('Configuration.Geometry.GeometryExtended2026D49_cff')
0020 elif GEOMETRY == "D76": 
0021     print("using geometry " + GEOMETRY + " (tilted)")
0022     process.load('Configuration.Geometry.GeometryExtended2026D76Reco_cff')
0023     process.load('Configuration.Geometry.GeometryExtended2026D76_cff')
0024 else:
0025     print("this is not a valid geometry!!!")
0026 
0027 process.load('Configuration.StandardSequences.MagneticField_cff')
0028 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0029 from Configuration.AlCa.GlobalTag import GlobalTag
0030 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')
0031 
0032 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0033 process.MessageLogger.L1track = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0034 
0035 options = VarParsing.VarParsing ('analysis')
0036 
0037 #--- Specify input MC
0038 
0039 #--- To use MCsamples scripts, defining functions get*data*() for easy MC access,
0040 #--- follow instructions in https://github.com/cms-L1TK/MCsamples
0041 
0042 #from MCsamples.Scripts.getCMSdata_cfi import *
0043 #from MCsamples.Scripts.getCMSlocaldata_cfi import *
0044 
0045 if GEOMETRY == "D49":
0046   inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200_rsb-v1/00000/00260a30-734a-4a3a-a4b0-f836ce5502c6.root"] 
0047 
0048 elif GEOMETRY == "D76":
0049   # Read data from card files (defines getCMSdataFromCards()):
0050   #from MCsamples.RelVal_1130_D76.PU200_TTbar_14TeV_cfi import *
0051   #inputMC = getCMSdataFromCards()
0052 
0053   # Or read .root files from directory on local computer:
0054   #dirName = "$myDir/whatever/"
0055   #inputMC=getCMSlocaldata(dirName)
0056 
0057   # Or read specified dataset (accesses CMS DB, so use this method only occasionally):
0058   #dataName="/RelValTTbar_14TeV/CMSSW_11_3_0_pre6-PU_113X_mcRun4_realistic_v6_2026D76PU200-v1/GEN-SIM-DIGI-RAW"
0059   #inputMC=getCMSdata(dataName)
0060 
0061   # Or read specified .root file:
0062   inputMC = ["/store/relval/CMSSW_11_3_0_pre6/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v6_2026D76PU200-v1/00000/00026541-6200-4eed-b6f8-d3a1fd720e9c.root"]
0063 
0064 else:
0065   print("this is not a valid geometry!!!")
0066 
0067 
0068 #--- Specify number of events to process.
0069 options.register('Events',100,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int,"Number of Events to analyze")
0070 
0071 #--- Specify name of output histogram file. (If name = '', then no histogram file will be produced).
0072 options.register('histFile','Hist.root',VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string,"Name of output histogram file")
0073 
0074 #--- Specify if stubs need to be (re)made, e.g. because they are not available in the input file
0075 options.register('makeStubs',0,VarParsing.VarParsing.multiplicity.singleton,VarParsing.VarParsing.varType.int,"Make stubs, and truth association, on the fly")
0076 
0077 #--- Specify whether to output a GEN-SIM-DIGI-RAW dataset containing the TMTT L1 tracks & associators.
0078 # (Warning: you may need to edit the associator python below to specify which track fitter you are using).
0079 options.register('outputDataset',0,VarParsing.VarParsing.multiplicity.singleton,VarParsing.VarParsing.varType.int,"Create GEN-SIM-DIGI-RAW dataset containing TMTT L1 tracks")
0080 
0081 options.parseArguments()
0082 
0083 #--- input and output
0084 
0085 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.Events) )
0086 
0087 process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(*inputMC))
0088 
0089 outputHistFile = options.histFile
0090 
0091 if outputHistFile != "":
0092   process.TFileService = cms.Service("TFileService", fileName = cms.string(outputHistFile))
0093 
0094 process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) )
0095 process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True))
0096 
0097 #--- Load code that produces our L1 tracks and makes corresponding histograms.
0098 #process.load('L1Trigger.TrackFindingTMTT.TMTrackProducer_cff')
0099 
0100 #--- Alternative cfg including improvements not yet in the firmware. Aimed at L1 trigger studies.
0101 process.load('L1Trigger.TrackFindingTMTT.TMTrackProducer_Ultimate_cff')
0102 #
0103 # Enable histogramming & use of MC truth (considerably increases CPU)
0104 process.TMTrackProducer.EnableMCtruth = True
0105 process.TMTrackProducer.EnableHistos  = True
0106 #
0107 #--- Optionally override default configuration parameters here (example given of how).
0108 
0109 #process.TMTrackProducer.TrackFitSettings.TrackFitters = [
0110 #                                "KF5ParamsComb",
0111 #                                "KF4ParamsComb"
0112 #                                "KF4ParamsCombHLS",
0113 #                                "ChiSquaredFit4",
0114 #                                "SimpleLR4"
0115 #                                ]
0116 
0117 # If the input samples contain stubs and the truth association, then you can just use the following path
0118 process.p = cms.Path(process.TMTrackProducer)
0119 
0120 # Optionally (re)make the stubs on the fly
0121 if options.makeStubs == 1:
0122         process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
0123         process.load('SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff')
0124         process.TTClusterAssociatorFromPixelDigis.digiSimLinks = cms.InputTag("simSiPixelDigis","Tracker")
0125 
0126         LOOSE_STUBS = False
0127 
0128         if (LOOSE_STUBS):
0129           # S.Viret's loose Dec. 2017 stub windows from commented out part of
0130           # L1Trigger/TrackTrigger/python/TTStubAlgorithmRegister_cfi.py in CMSSW 9.3.7
0131           # Optimised for electrons.
0132 
0133           process.TTStubAlgorithm_official_Phase2TrackerDigi_ = cms.ESProducer("TTStubAlgorithm_official_Phase2TrackerDigi_",
0134           zMatchingPS  = cms.bool(True),
0135           zMatching2S  = cms.bool(True),
0136           #Number of tilted rings per side in barrel layers (for tilted geom only)
0137           NTiltedRings = cms.vdouble( 0., 12., 12., 12., 0., 0., 0.), 
0138           BarrelCut    = cms.vdouble( 0, 2.0, 3, 4.5, 6, 6.5, 7.0),
0139           TiltedBarrelCutSet = cms.VPSet(
0140                cms.PSet( TiltedCut = cms.vdouble( 0 ) ),
0141                cms.PSet( TiltedCut = cms.vdouble( 0, 3, 3., 2.5, 3., 3., 2.5, 2.5, 2., 1.5, 1.5, 1, 1) ),
0142                cms.PSet( TiltedCut = cms.vdouble( 0, 4., 4, 4, 4, 4., 4., 4.5, 5, 4., 3.5, 3.5, 3) ),
0143                cms.PSet( TiltedCut = cms.vdouble( 0, 5, 5, 5, 5, 5, 5, 5.5, 5, 5, 5.5, 5.5, 5.5) ),
0144               ),
0145           EndcapCutSet = cms.VPSet(
0146                cms.PSet( EndcapCut = cms.vdouble( 0 ) ),
0147                cms.PSet( EndcapCut = cms.vdouble( 0, 1., 2.5, 2.5, 3.5, 5.5, 5.5, 6, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 7, 7) ),
0148                cms.PSet( EndcapCut = cms.vdouble( 0, 0.5, 2.5, 2.5, 3, 5, 6, 6, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 7, 7) ),
0149                cms.PSet( EndcapCut = cms.vdouble( 0, 1, 3., 4.5, 6., 6.5, 6.5, 6.5, 7, 7, 7, 7, 7) ),
0150                cms.PSet( EndcapCut = cms.vdouble( 0, 1., 2.5, 3.5, 6., 6.5, 6.5, 6.5, 6.5, 7, 7, 7, 7) ),
0151                cms.PSet( EndcapCut = cms.vdouble( 0, 0.5, 1.5, 3., 4.5, 6.5, 6.5, 7, 7, 7, 7, 7, 7) ),
0152               )
0153           )
0154 
0155         else:
0156           # S.Viret's July 2017 stub windows (tight) from commented out part of
0157           # L1Trigger/TrackTrigger/python/TTStubAlgorithmRegister_cfi.py in CMSSW 9.3.2
0158 
0159           process.TTStubAlgorithm_official_Phase2TrackerDigi_ = cms.ESProducer("TTStubAlgorithm_official_Phase2TrackerDigi_",
0160           zMatchingPS  = cms.bool(True),
0161           zMatching2S  = cms.bool(True),
0162           #Number of tilted rings per side in barrel layers (for tilted geom only)
0163           NTiltedRings = cms.vdouble( 0., 12., 12., 12., 0., 0., 0.), 
0164           BarrelCut = cms.vdouble( 0, 2.0, 2.0, 3.5, 4.5, 5.5, 6.5), #Use 0 as dummy to have direct access using DetId to the correct element 
0165 
0166           TiltedBarrelCutSet = cms.VPSet(
0167               cms.PSet( TiltedCut = cms.vdouble( 0 ) ),
0168               cms.PSet( TiltedCut = cms.vdouble( 0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2., 2., 1.5, 1.5, 1., 1.) ),
0169               cms.PSet( TiltedCut = cms.vdouble( 0, 3., 3., 3., 3., 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2, 2) ),
0170               cms.PSet( TiltedCut = cms.vdouble( 0, 4.5, 4.5, 4, 4, 4, 4, 3.5, 3.5, 3.5, 3, 3, 3) ),
0171               ),
0172           EndcapCutSet = cms.VPSet(
0173               cms.PSet( EndcapCut = cms.vdouble( 0 ) ),
0174               cms.PSet( EndcapCut = cms.vdouble( 0, 1, 1.5, 1.5, 2, 2, 2.5, 3, 3, 3.5, 4, 2.5, 3, 3.5, 4.5, 5.5) ),
0175               cms.PSet( EndcapCut = cms.vdouble( 0, 1, 1.5, 1.5, 2, 2, 2, 2.5, 3, 3, 3, 2, 3, 4, 5, 5.5) ),
0176               cms.PSet( EndcapCut = cms.vdouble( 0, 1.5, 1.5, 2, 2, 2.5, 2.5, 2.5, 3.5, 2.5, 5, 5.5, 6) ),
0177               cms.PSet( EndcapCut = cms.vdouble( 0, 1.0, 1.5, 1.5, 2, 2, 2, 2, 3, 3, 6, 6, 6.5) ),
0178               cms.PSet( EndcapCut = cms.vdouble( 0, 1.0, 1.5, 1.5, 1.5, 2, 2, 2, 3, 3, 6, 6, 6.5) ),
0179               )
0180           ) 
0181 
0182         process.p = cms.Path(process.TrackTriggerClustersStubs * process.TrackTriggerAssociatorClustersStubs * process.TMTrackProducer)
0183 
0184 # Optionally create output GEN-SIM-DIGI-RAW dataset containing TMTT L1 tracks & associators.
0185 if options.outputDataset == 1:
0186 
0187   # Associate TMTT L1 tracks to truth particles
0188   process.load('SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff')
0189   process.TTAssociatorTMTT = process.TTTrackAssociatorFromPixelDigis.clone(
0190 # Edit to specify which input L1 track collection to run associator on.
0191           TTTracks = cms.VInputTag(cms.InputTag("TMTrackProducer", 'TML1TracksKF4ParamsComb'))
0192 #          TTTracks = cms.VInputTag(cms.InputTag("TMTrackProducer", 'TML1TracksglobalLinearRegression'))
0193   )
0194   process.pa = cms.Path(process.TTAssociatorTMTT)
0195 
0196   # Write output dataset
0197   process.load('Configuration.EventContent.EventContent_cff')
0198 
0199   process.writeDataset = cms.OutputModule("PoolOutputModule",
0200       splitLevel = cms.untracked.int32(0),
0201       eventAutoFlushCompressedSize = cms.untracked.int32(5242880),
0202       outputCommands = process.RAWSIMEventContent.outputCommands,
0203       fileName = cms.untracked.string('output_dataset.root'), ## ADAPT IT ##
0204       dataset = cms.untracked.PSet(
0205           filterName = cms.untracked.string(''),
0206           dataTier = cms.untracked.string('GEN-SIM')
0207       )
0208   )
0209   # Include TMTT L1 tracks & associators + stubs.
0210   process.writeDataset.outputCommands.append('keep  *TTTrack*_*_*_*')
0211   process.writeDataset.outputCommands.append('keep  *TTStub*_*_*_*')
0212 
0213   process.pd = cms.EndPath(process.writeDataset)
0214   process.schedule = cms.Schedule(process.p, process.pa, process.pd)