Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:46

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