Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:53

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