Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-19 23:58:18

0001 #! /bin/env cmsRun
0002 
0003 '''
0004 cfg to produce ntuples for error scale calibration
0005 here doing refit of tracks and vertices using latest alignment 
0006 '''
0007 
0008 import FWCore.ParameterSet.Config as cms
0009 from fnmatch import fnmatch
0010 import FWCore.ParameterSet.VarParsing as VarParsing
0011 from pdb import set_trace
0012 
0013 process = cms.Process("PrimaryVertexResolution")
0014 
0015 ###################################################################
0016 def best_match(rcd):
0017 ###################################################################
0018     '''
0019     find out where to best match the input conditions
0020     '''
0021     print(rcd)
0022     for pattern, string in connection_map:
0023         print(pattern, fnmatch(rcd, pattern))
0024         if fnmatch(rcd, pattern):
0025             return string
0026 
0027 options = VarParsing.VarParsing("analysis")
0028 
0029 options.register ('outputRootFile',
0030                   "pvresolution_test.root",
0031                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0032                   VarParsing.VarParsing.varType.string,         # string, int, or float
0033                   "output root file")
0034 
0035 options.register ('records',
0036                   [],
0037                   VarParsing.VarParsing.multiplicity.list,       # singleton or list
0038                   VarParsing.VarParsing.varType.string,          # string, int, or float
0039                   "record:tag names to be used/changed from GT")
0040 
0041 options.register ('external',
0042                   [],
0043                   VarParsing.VarParsing.multiplicity.list,       # singleton or list
0044                   VarParsing.VarParsing.varType.string,          # string, int, or float
0045                   "record:fle.db picks the following record from this external file")
0046 
0047 options.register ('GlobalTag',
0048                   'auto:run2_data',
0049                   VarParsing.VarParsing.multiplicity.singleton,  # singleton or list
0050                   VarParsing.VarParsing.varType.string,          # string, int, or float
0051                   "Global Tag to be used")
0052 
0053 options.parseArguments()
0054 
0055 print("conditionGT       : ", options.GlobalTag)
0056 print("conditionOverwrite: ", options.records)
0057 print("external conditions:", options.external)
0058 print("outputFile        : ", options.outputRootFile)
0059 print("maxEvents         : ", options.maxEvents)
0060 
0061 process.load("FWCore.MessageService.MessageLogger_cfi")
0062 process.MessageLogger.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
0063 process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
0064         reportEvery = cms.untracked.int32(1000) # every 100th only
0065         #    limit = cms.untracked.int32(10)       # or limit to 10 printouts...
0066     ))
0067 
0068 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
0069 
0070 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0071 process.load("Configuration.StandardSequences.MagneticField_cff")
0072 process.load('Configuration.Geometry.GeometryRecoDB_cff')
0073 
0074 process.load('Configuration/StandardSequences/Services_cff')
0075 process.load('TrackingTools.TransientTrack.TransientTrackBuilder_cfi')
0076 
0077 process.source = cms.Source("PoolSource",
0078     fileNames = cms.untracked.vstring(
0079         '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/039/00000/4C851925-AF8D-E811-96A4-02163E010E90.root',
0080         '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/A8A78033-B18D-E811-9477-02163E019F55.root',
0081         '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/058/00000/6A45BA9D-F88D-E811-B907-FA163E600F07.root',
0082         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/B09C5228-B18D-E811-9271-FA163E573834.root',
0083         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/C28F8F68-B18D-E811-BC8A-FA163EE8669D.root',
0084         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/12BDA2F4-BC8D-E811-BEF2-02163E00C3F8.root',
0085         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/788386DF-BC8D-E811-AE14-FA163EC41EB1.root',
0086         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/608E8A35-B18D-E811-93ED-FA163E8674D5.root',
0087         # '/store/express/Run2018C/StreamExpressAlignment/ALCARECO/TkAlMinBias-Express-v1/000/320/040/00000/E03C67DD-BC8D-E811-BBF6-FA163EF274DA.root',
0088     )
0089 )
0090 
0091 ###################################################################
0092 # Tell the program where to find the conditons
0093 connection_map = [
0094     ('Tracker*', 'frontier://PromptProd/CMS_CONDITIONS'),
0095     ]
0096 
0097 if options.external:
0098     connection_map.extend(
0099         (i.split(':')[0], 'sqlite_file:%s' % i.split(':')[1]) for i in options.external
0100         )
0101 
0102 connection_map.sort(key=lambda x: -1*len(x[0]))
0103 
0104 ###################################################################
0105 # creat the map for the GT toGet
0106 records = []
0107 if options.records:
0108     for record in options.records:
0109         rcd, tag = tuple(record.split(':'))
0110         records.append(
0111             cms.PSet(
0112                 record = cms.string(rcd),
0113                 tag    = cms.string(tag),
0114                 connect = cms.string(best_match(rcd))
0115                 )
0116             )
0117 
0118 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
0119 
0120 from Configuration.AlCa.GlobalTag import GlobalTag
0121 process.GlobalTag = GlobalTag(process.GlobalTag, options.GlobalTag, '')
0122 process.GlobalTag.toGet = cms.VPSet(*records)
0123 #process.GlobalTag.DumpStat = cms.untracked.bool(True)
0124 
0125 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0126 # remove the following lines if you run on RECO files
0127 process.TrackRefitter.src = 'ALCARECOTkAlMinBias'
0128 process.TrackRefitter.NavigationSchool = ''
0129 
0130 ## PV refit
0131 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0132 
0133 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices 
0134 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0135 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("TrackRefitter") 
0136 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0137 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0138 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0139 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0 
0140 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0141 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0142 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0143 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2   
0144 
0145 ###################################################################
0146 # The trigger filter module
0147 ###################################################################
0148 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0149 process.HLTFilter = triggerResultsFilter.clone(
0150     #triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0151     triggerConditions = cms.vstring("HLT_HT*"),
0152     hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0153     l1tResults = cms.InputTag( "" ),
0154     throw = cms.bool(False)
0155 )
0156 ###################################################################
0157 # The analysis module
0158 ###################################################################
0159 process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0160                                     TkTag  = cms.InputTag('TrackRefitter'),
0161                                     isCosmics = cms.bool(False)
0162                                     )
0163 
0164 ###################################################################
0165 # The PV resolution module
0166 ###################################################################
0167 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0168                                                  storeNtuple         = cms.bool(True),
0169                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0170                                                  trackCollection     = cms.InputTag("TrackRefitter"),       
0171                                                  minVertexNdf        = cms.untracked.double(10.),
0172                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0173                                                  runControl = cms.untracked.bool(True),
0174                                                  runControlNumber = cms.untracked.vuint32(320040),
0175                                                  sumpTStartScale = cms.untracked.double(1.),
0176                                                  sumpTEndScale = cms.untracked.double(1000.),
0177                                                  nTrackBins = cms.untracked.double(60.),
0178                                                  nVtxBins = cms.untracked.double(40.)
0179                                                  )
0180 
0181 process.TFileService = cms.Service("TFileService",
0182                                    fileName = cms.string(options.outputRootFile),   
0183                                    closeFileFast = cms.untracked.bool(False)
0184                                    )
0185 
0186 process.p = cms.Path(process.HLTFilter                               +
0187                      process.offlineBeamSpot                         +
0188                      process.TrackRefitter                           +
0189                      process.offlinePrimaryVerticesFromRefittedTrks  +
0190                      process.PrimaryVertexResolution                 +
0191                      process.myanalysis
0192                      )
0193 
0194